A:
void solve(){
string s;
cin>>s;
for(char &c:s) if(c>='A'&&c<='Z') c=c-'A'+'a';
if(s=="yes") cout<<"accept";
else cout<<"wrong answer";
}
B:
void solve(){
int n=read();
Write(n);
for(int i=n;i>=2;i--){
ll v=1;int cnt=0;
while(true){
v*=i;cnt++;
if(v>=n) break;
}
if(v==n) printf("=%d^%d\n",i,cnt);
}
}
C:
map<int,int>cnt;
ll ans[maxn];
int a[maxn];
void solve(){
int n=read();
for(int i=1;i<=n;i++) a[i]=read();
for(int i=1;i<=n;i++){
ans[i]=ans[i-1]+cnt[a[i]];
cnt[a[i]]++;
}
for(int i=1;i<=n;i++) Write(ans[i],' ');
}
D:
int a[3][3];
void solve(){
ll cnt=0;
for(int i=0;i<2;i++)
for(int j=0;j<2;j++) a[i][j]=read();
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
int Mn=min(a[i][j],a[i^1][j]);
a[i][j]-=Mn,a[i^1][j]-=Mn;
cnt+=Mn;
Mn=min(a[i][j],a[i][j^1]);
a[i][j]-=Mn,a[i][j^1]-=Mn;
cnt+=Mn;
}
}
printf(cnt&1?"kou\n":"yukari\n");
}
E:
constexpr int N = 1e5 + 5;
char s[N], t[N];
int cnt[26], id[26], pid[N];
void solve(){
scanf("%s", s + 1); int n = strlen(s + 1);
for (int i = 1; i <= n; i ++) cnt[s[i] - 'a'] ++;
for (int i = 0; i < 26; i ++) if (cnt[i] * 2 > n) return puts("-1"), void();
iota(id, id + 26, 0);
sort(id, id + 26, [&](int i, int j) { return cnt[i] > cnt[j]; });
for (int i = 0, cur = 0; i < 26; i ++)
for (int j = 1; j <= n; j ++)
if (s[j] - 'a' == id[i]) pid[++ cur] = j;
// for (int i = 1; i <= n; i ++) cout << pid[i] << ' '; cout << endl;
int cur = n;
while (cnt[id[0]]) t[pid[cur --]] = id[0] + 'a', cnt[id[0]] --;
for (int i = 25; i > 0; i --)
while (cnt[id[i]]) t[pid[cur --]] = id[i] + 'a', cnt[id[i]] --;
puts(t + 1);
return ;
}
F:
const int N=1e5+10;
const double eps=1e-10;
int T=1,n,m,ans,q;
int fa[N],dis[N],vis[N];
vector<int> v[N];
void dfs(int x,int p){
fa[x]=p;
for(auto t: v[x]){
if(t==p) continue ;
dfs(t,x);
}
return ;
}
void calc(int x,int p){
for(auto t: v[x]){
if(vis[t] || t==p) continue ;
dis[t]=dis[x]+1;
ans+=dis[t];
calc(t,x);
}
return ;
}
void solve(){
n=read(),q=read();
for(int i=1;i<n;i++){
int x=read(),y=read();
v[x].push_back(y);
v[y].push_back(x);
}
int x=read(),y=read();
dfs(x,0);
for(int i=y;;i=fa[i]){
vis[i]=1;
if(i==x) break ;
}
for(int i=y;;i=fa[i]){
calc(i,fa[i]);
if(i==x) break;
}
printf("%lld",ans);
return ;
}
G:
const int maxn=1e5+5;
int Fa[maxn][20],dep[maxn],siz[maxn],head[maxn],ver[maxn<<1],nxt[maxn<<1],tot,cnt,n,q;
ll f[maxn];
void add_edge(int u,int v){
ver[++tot]=v,nxt[tot]=head[u],head[u]=tot;
}
void dfs1(int x,int fa){
dep[x]=dep[fa]+1;f[1]+=dep[x];siz[x]=1;
for(int i=head[x];i;i=nxt[i]){
int y=ver[i];
if(y==fa) continue;
Fa[y][0]=x;
for(int j=1;(1<<j)<=n;j++)
Fa[y][j]=Fa[Fa[y][j-1]][j-1];
dfs1(y,x);siz[x]+=siz[y];
}
}
void dfs2(int x,int fa){
for(int i=head[x];i;i=nxt[i]){
int y=ver[i];
if(y==fa) continue;
f[y]=f[x]-siz[y]+n-siz[y];
dfs2(y,x);
}
}
int lca(int x,int y){
if(dep[x]<dep[y]) swap(x,y);
for(int i=19;i>=0;i--)
if(dep[Fa[x][i]]>=dep[y]) x=Fa[x][i];
if(x==y) return x;
for(int i=19;i>=0;i--)
if(Fa[x][i]!=Fa[y][i])
x=Fa[x][i],y=Fa[y][i];
return Fa[x][0];
}
void solve(){
n=read(),q=read();
for(int i=1;i<n;i++){
int u=read(),v=read();
add_edge(u,v);
add_edge(v,u);
}
dep[0]=-1;
dfs1(1,0);
dfs2(1,0);
while(q--){
int x=read(),y=read();
int dis=dep[x]+dep[y]-2*dep[lca(x,y)];
Write((f[x]+f[y]-1ll*dis*n)/2);
}
}