akhauriyash/Code-Regression huggingface dataset:
if __name__ == "__main__":
	maxn = 1000000
	plist = [False if i%2==0 or i%3==0 or i%5==0 else True for i in range(maxn)]

	plist[0] = plist[1] = False
	plist[2] = plist[3] = plist[5] = True

	for chki in range(3, maxn, 2):
		for j in range(chki**2, maxn, chki):
			plist[j] = False

	while True:
		try:
			#start = time.time()
			inn = int(raw_input())
			print plist[0:inn+1].count(True)
			#print plist
			#print plist.count(True)
			#print plist[0:10].count(True)
			#print plist[0:100000].count(True)
			#print plist[0:1000000].count(True)

			#elapsedTime = time.time() -start
			#print elapsedTime
		except:
			break

Measured memory_bytes: 43880
N,K = map(int, input().split())
S = input()
Ans = 0
max = N - 1

for i in range(N-1):
  if S[i] == S[i+1]:
    Ans = Ans + 1

Ans = Ans + 2 * K
if Ans >= max:
  Ans = max

print(Ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,n) for(int i=a;i<n;i++)

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tiii;

const int INF=1<<30;
const ll LINF = 1e18+5;

int main() {
    int A1, A2, A3;
    cin >> A1 >> A2 >> A3;
    if(A1+A2+A3>=22) cout << "bust" << endl;
    else cout << "win" << endl;
    return 0;
}

Measured memory_bytes: 764
#!/usr/bin/ruby
# -*- coding: utf-8 -*-
=begin
Volume0-0000
Submit [Old Version]
PCK 2003
=end
class Main

  def initialize
    1.upto(9) {|i|
      1.upto(9) {|j|
        printf("%dx%d=%d\n", i, j, i*j)
      }
    }
  end

end


if $0 == __FILE__ then
  Main.new
end

Measured memory_bytes: 8544
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;

int main(){
    string s; cin >> s;
    int ans = 999;
    for (int i = 0; i <= (s.size() - 3); i++) {
        int a = (s[i] - '0')* 100 + (s[i+1] - '0') * 10 + (s[i+2] - '0');       
        ans = min(ans, abs(a - 753));
    }
    cout << ans << endl;
} 

Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep(i,n) FOR(i,0,n-1)
#define ll long long
#define MOD 998244353
#define MAXN  100005
#define P pair<int,int>

signed main(){
	
	int n; cin >> n;
	int prex = 0,prey=0,pret=0;
	
	rep(loop,n)
	{
		int t,x,y;cin>>t>>x>>y;
		
		int dist = abs(x-prex) + abs(y-prey);
		if(dist % 2 != (t-pret)%2 or dist > t)
		{
			cout << "No" << endl;
			return 0;
		}
		
		
	}
	
	
	cout << "Yes" << endl;
	
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 1
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR
#endif



//改造
typedef long long int ll;
using namespace std;


//ここから編集する

int main() {
//    int q,h,s,d;
    ll n;
    ll price[4];
    bool use[4];
    use[0] = true;
    cin >> price[0] >> price[1] >> price[2] >> price[3] >> n;
    for (int i = 0; i < 3; i++) {
        if (price[i] * 2 <= price[i + 1]) {
            use[i + 1] = false;
            price[i + 1] = price[i] * 2;
        } else {
            use[i + 1] = true;
        }
    }
    ll N = 4 * n;
    ll sum = 0;
    for(int i = 3; i >= 0; i--){
        if(use[i]){
            sum += ((N / (ll)pow(2,i)) * price[i] );
            N %= (ll)pow(2,i);
        }
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 384
#include<cstdio>
char s[111][111];
int main(){
	int n = 100, A, B;
	scanf("%d%d",&A,&B);
	printf("%d %d\n",n,n);
	for(int i=0; i<n; i++)
		for(int j=0; j<n; j++)
			s[i][j] = i<n/2 ? '.': '#';
	--A;
	--B;
	for(int i=1; i<n/2 && B>0; i+=2)
		for(int j=1; j<n-1 && B>0; j+=2)
			s[i][j] = '#', B--;
	for(int i=n/2+1; i<n-1 && A>0; i+=2)
		for(int j=1; j<n-1 && A>0; j+=2)
			s[i][j] = '.', A--;
	for(int i=0; i<n; i++)
		puts(s[i]);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define el '\n'
typedef long long ll;

int main() {
  ll a, b;
  cin >> a >> b;
  a--;
  ll tes = (a+4)%4;
  if (tes == 1) a = 1;
  else if (tes == 2) a++;
  else if (tes == 3) a = 0;
  tes = (b+4)%4;
  if (tes == 1) b = 1;
  else if (tes == 2) b++;
  else if (tes == 3) b = 0; 
  cout << (a^b) << el;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<map>
using namespace std;
typedef long long int ll;

int main(){
    ll N;
    cin >> N;

    vector<int> d(N);
    for(int i = 0; i < N; i++){
        cin >> d[i];
    }

    sort(d.begin(), d.end());

    cout << (d[N/2] - d[N/2 - 1]) << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18

using namespace std;

int main(void){
  ll n;
  cin >> n;
  
  set<pair<ll, ll>> s;
  for (int i = 0; i < n; i++){
    ll x, y;
    cin >> x >> y;
    
    s.insert(make_pair(x, y));
  }

  ll ans = INF;
  for (auto i : s){
    for (auto j : s){
      if (i == j)
        continue;

      ll num = 0;
      ll p = i.first - j.first;
      ll q = i.second - j.second;
      for (auto k : s){
        if (s.find(make_pair(k.first - p, k.second - q)) != s.end())
          num++;
      }

      ans = min(ans, n - num);
    }
  }
  
  cout << (ans == INF ? 1 : ans) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <list>
using namespace std;
   
int main(){
	int N;
	cin >> N;
	list<int> array_b;
	string ans = "";
	for(int i = 0; i < N; i++){
		int array_a;
		cin >> array_a;
		if(i % 2 == 0){
			array_b.push_back(array_a);
		}else{
			array_b.push_front(array_a);
		}
	}
	if(N % 2 == 0){
		for(int i = 0; i < N; i++){
			ans += to_string(array_b.front()) + " ";
			array_b.pop_front();
		}
	}else{
		for(int i = 0; i < N; i++){
			ans += to_string(array_b.back()) + " ";
			array_b.pop_back();
		}
	}
	ans.pop_back();
	cout << ans << endl;
}

Measured memory_bytes: 10500
program main

 implicit none
 integer::n,x,t,kaisuu,i,answer,ans

 read*,n,x,t

kaisuu=0
 do i=1,n
  ans=n-x*i
  kaisuu=kaisuu+1
  if(ans<=0) then
   exit
  end if
 end do

 answer=t*kaisuu

 print*,answer

end program main

Measured memory_bytes: 2664
#include <iostream>
#include <string>

int main(){
    int n;
    std::string s;
    std::cin >> n >>s;
    
    int Ans=0;
    
    for(int i=0;i<n-2;++i){
        if(s[i]=='A'){
            if(s[i+1]=='B'){
                if(s[i+2]=='C'){
                    Ans++;
                }
            }
        }
    }
    
    std::cout << Ans << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;
typedef long long ll;

int main(){
  ll N, tmp, minimum = -1, pivot = 0;
  vector<ll> cap;
  cin >> N;
  for (int i=0; i<5; i++){
    cin >> tmp;
    cap.push_back(tmp);
    if (minimum > tmp || minimum < 0){
      pivot = i;
      minimum = tmp;
    }
  }
  cout << (N % cap[pivot] == 0 ? N / cap[pivot] : N / cap[pivot] + 1) + 4 << endl;
  return 0;
}



Measured memory_bytes: 256
// {{{
// vim:filetype=cpp foldmethod=marker foldmarker={{{,}}}
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <climits>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define ALL(A)		(A).begin(),(A).end()
#define DUMP(A)    cout<<#A<<"="<<(A)<< endl
#define SIZE(A)    (int)((A).size())
#define MP  make_pair
#define PB  push_back
using namespace std;
typedef long long ll;

int vx[]={1,0,-1,0},vy[]={0,1,0,-1};
// }}}

int field[1000][1000];
int dp[1000][1000];
int main(){
    for(;;){
        int H,W,N;
        scanf("%d%d%d",&H,&W,&N);
        if(H==0&&W==0&&N==0) break;
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                scanf("%d",&field[i][j]);
            }
        }
        dp[0][0]=N-1;
        for(int i=1;i<H;i++){
            if(field[i-1][0]==0) dp[i][0]=(dp[i-1][0]+1)/2;
            else dp[i][0]=dp[i-1][0]/2;
        }
        for(int i=1;i<W;i++){
            if(field[0][i-1]==1) dp[0][i]=(dp[0][i-1]+1)/2;
            else dp[0][i]=dp[0][i-1]/2;
        }
        for(int i=1;i<H;i++){
            for(int j=1;j<W;j++){
                dp[i][j]=0;
                if(field[i-1][j]==0) dp[i][j]+=(dp[i-1][j]+1)/2;
                else dp[i][j]+=dp[i-1][j]/2;
                if(field[i][j-1]==1) dp[i][j]+=(dp[i][j-1]+1)/2;
                else dp[i][j]+=dp[i][j-1]/2;
            }
        }
        int nx=0,ny=0;
        while(nx<H&&ny<W){
            if((dp[nx][ny]+field[nx][ny])%2==1) ny++;
            else nx++;
        }
        printf("%d %d\n",nx+1,ny+1);
    }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define ll long long
#define mod 838627288460106
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

int main()
{
  fast_io
    ll a,b,j;
    double ans;
    cin>>a>>b;
    ans=(a+b)/2.0;

    cout<<round(ans)<<endl;
    return 0;
}





Measured memory_bytes: 3696
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstdio>
#include <queue>
#include <list>
using namespace std;

vector<int> a(100);

int fibonacci(int n){
  if(n == 0 || n == 1){
    return 1;
  }
  if(a[n] != 0)
    return a[n];
  else
    return a[n] = fibonacci(n-2) + fibonacci(n-1);
}

int main(void){
  int n;
  cin >> n;

  cout << fibonacci(n) << endl;

  return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int r;
    cin >> r;

    cout << 3 * r * r << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>

#define rep(i, s, n) for(int i = s; i < n; ++i)
#define rrep(i, n) for(int i = n - 1; i > -1; --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
const long long INF = 1000000000;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    ll k, n;
    cin >> k >> n;
    vector<ll> a(n);
    rep(i, 0, n){
        cin >> a[i];
    }
    ll diff = abs(k - a[a.size() - 1] + a[0]);
    rep(i, 0, n - 1){
        if(diff < a[i + 1] - a[i]) diff = a[i + 1] - a[i];
    }
    cout << k - diff << endl;
}


Measured memory_bytes: 1792
# D - String Formation
import sys
from collections import deque

readline = sys.stdin.readline
readlines = sys.stdin.readlines


def main():
    S = readline().rstrip()
    _ = readline()
    queries = readlines()
    queue = deque(S)
    to_beginning, to_end = queue.appendleft, queue.append
    is_reversed = 0
    for query in queries:
        if query[0] == "1":
            to_beginning, to_end = to_end, to_beginning
            is_reversed ^= 1
            continue
        com, c = query[2], query[4]
        if com == "1":
            to_beginning(c)
        else:
            to_end(c)
    ans = "".join(queue) if not is_reversed else "".join(reversed(queue))
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 21224
#include <iostream>
#include <iomanip>
#include <cstring>
#include <algorithm> 
#include <math.h>
#include <queue>
#include <functional>
#include <map>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1000000007;
const ll INF = 100000;

int dw[4] = { 1, 0, -1, 0 };
int dh[4] = { 0, 1, 0, -1 };
int cnt;
int h, w;
char s[55][55];
int sa, sb, ga, gb;
int d[55][55];

int bfs(){
    queue<P> que;
    for (int i = 1; i <= h; i++){
        for (int j = 1; j <= w; j++){
            d[i][j] = INF;
        }
    }

    que.push(P(sa, sb));
    d[sa][sb] = 0;

    while (que.size() != 0){
        P p = que.front(); que.pop();
        if (p.first == ga && p.second == gb) break;

        for (int i = 0; i < 4; i++){

            int na = p.first + dh[i];
            int nb = p.second + dw[i];

            if (1 <= na && na <= h && 1 <= nb && nb <= w && s[na][nb] == '.' && d[na][nb] == INF){
                que.push(P(na, nb));
                d[na][nb] = d[p.first][p.second] + 1;
            }
        }
    }

    
    return d[ga][gb];
}




int main(void){
    cin >> h >> w;
    cnt = 0;
    sa = sb = 1;
    ga = h; gb = w;
    for (int i = 1; i <= h; i++){
        for (int j = 1; j <= w; j++){
            cin >> s[i][j];
            if (!(i == sa && j == sb)&& s[i][j] == '.') cnt++;
        }
    }

    int ret = bfs();
    if (ret == INF) cout << -1 << endl;
    else cout << cnt - ret << endl;  
   
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>

#define p pair<int,int>
using namespace std;

int n;
vector<vector<p >> graph;
vector<vector<int>> dis;

void dijkstra(int s) {
    priority_queue<p, vector<p >, greater<>> que;
    dis = vector<vector<int>>(n + 1, vector<int>(3, 1145141919));
    dis[s][0] = 0;
    que.push(p(s, 0));

    while (!que.empty()) {
        p now = que.top();
        que.pop();
        int nowv = now.first;
        int nowmod = now.second % 3;

        if (dis[nowv][nowmod] < now.second)continue;

        for (auto next:graph[nowv]) {
            if (dis[next.first][(nowmod + 1) % 3] > dis[nowv][nowmod] + next.second) {
                dis[next.first][(nowmod + 1) % 3] = dis[nowv][nowmod] + next.second;
                que.push(p(next.first, dis[next.first][(nowmod + 1) % 3]));
            }
        }
    }
}

int main() {
    int m;
    cin >> n >> m;
    graph = vector<vector<p >>(n + 1);
    for (int i = 0; i < m; i++) {
        int from, to;
        cin >> from >> to;
        graph[from].push_back(p(to, 1));
    }

    int start, end;
    cin >> start >> end;
    dijkstra(start);

    cout << (dis[end][0] == 1145141919 ? -1 : dis[end][0] / 3) << endl;
    return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define int long long
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

vector<int> init(int size){
  vector<int> par(size,-1);
  return par;
}

int root(int x, vector<int>& par){
  if(par[x] < 0){
    return x;
  }else{
    return par[x] = root(par[x],par);
  }
}

bool same(int x, int y, vector<int>& par){
  return root(x, par) == root(y, par);
}

void unite(int x, int y, vector<int>& par){
  x = root(x, par), y = root(y, par);
  if(same(x,y, par))return;
  par[x] += par[y];
  par[y] = x;
}

int size(int x, vector<int>& par){
  return -par[root(x, par)];
}

int pow(int x, int n){
  if(n == 0)return 1;
  if(n % 2 == 0)return pow(x * x % MOD, n/2);
  else return x * pow(x, n-1) % MOD;
}

vector< int > divisor(int n) {
  vector< int > ret;
  for(int i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret),greater<int>());
  return (ret);
}
int n,q;
vector<int> g[210000];
vector<int> ans(210000,0);

void dfs(int v, int pre){
  //cout << v << " " << pre << endl;
  rep(i,g[v].size()){
    if(g[v][i] == pre)continue;
    ans[g[v][i]] += ans[v];
    dfs(g[v][i], v);
  }
}

  int c[26][110000];

signed main(){
  string s,t;cin>>s>>t;
  rep(i,s.length()){
    c[s[i]-'a'][i]++;
  }
  rep(i,26){
    rep(j,s.length()){
      c[i][j+1] += c[i][j]; 
    }
  }
  int ans = 0,pre = -1;
  int *itr1;int *itr2;int *preitr;
  rep(i,t.length()){
    int ch = t[i]-'a';int k;
    if(pre < 0){
      k = 1;
    }else{
      k = c[ch][pre] + 1;
    }
    itr1 = lower_bound(c[ch]+pre+1, c[ch]+s.length(), k);
    itr2 = lower_bound(c[ch],c[ch]+pre+1,1);
    if(itr1 != c[ch]+s.length()){
      pre = distance(c[ch], itr1);
      preitr = itr1;
    }else if(itr2 != c[ch]+pre+1){
      pre = distance(c[ch], itr2);
      preitr = itr2;
      ans++;
    }else{
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans*s.length() + distance(c[(t[t.length()-1])-'a'],preitr) + 1 << endl;
}


Measured memory_bytes: 29312
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 09/08/20 03:55:25
// -----------------------------------

#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using ll = long long;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);

  int n,m; cin>>n>>m;
  vector<atcoder::modint998244353> A(n),B(m);
  for (int i = 0; i < n; i++) {
    int a; cin>>a;
    A[i] = a;
  }
  for (int i = 0; i < m; i++) {
    int b; cin >> b;
    B[i] = b;
  }
  auto C = atcoder::convolution(A, B);
  for (int i = 0; i < n+m-1; i++)
    cout << C[i].val() << " ";
  cout << endl;

  return 0;
}


Measured memory_bytes: 19048
#include <bits/stdc++.h>
#define ll long long
#define ls id << 1
#define rs id << 1 | 1
#define mem(array, value, size, type) memset(array, value, ((size) + 5) * sizeof(type))
#define memarray(array, value) memset(array, value, sizeof(array))
#define pb(x) push_back(x)
#define st(x) (1LL << (x))
#define pii pair<int, int>
#define mp(a, b) make_pair((a), (b))
#define Flush fflush(stdout)
using namespace std;
const int N = 500050;
const int inf = 0x3f3f3f3f;
const ll llinf = 0x3f3f3f3f3f3f;
const ll mod = 998244353LL;
clock_t TIME_START, TIME_END;
void program_end()
{
#ifdef ONLINE
    printf("\nTime used: %.6lf(s)\n", ((double)TIME_END - TIME_START) / CLOCKS_PER_SEC);
    system("pause");
#endif
}
int n;
struct students
{
    int id;
    int order;
} a[N];

void solve()
{
    cin>>n;
    for (int i = 1; i <= n;++i)
    {
        cin >> a[i].order;
        a[i].id = i;
    }
    sort(a + 1, a + n + 1, [&](students A, students B) {
        return A.order < B.order;
    });
    for (int i = 1; i <= n;++i)
    {
        printf("%d ", a[i].id);
    }
}

int main()
{
    TIME_START = clock();
    int Test = 1;
    // cin >> Test;
    while (Test--)
        solve();
    TIME_END = clock();
    program_end();
    return 0;
}

Measured memory_bytes: 4416
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF 2e9
#define LINF 1e18
#define mod 1e9+7
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> P;


int main() {
    int n; cin >> n;
    string s; cin >> s;

    rep(i,sz(s)) {
        s[i]=s[i]+n;
        if (s[i]>'Z') s[i] -= 26;
    }

    rep(i,sz(s)) {
        cout << s[i];
    }

    cout << endl;

}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>
#include <array>
#include <chrono>
#include <random>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
#define VAR(type, ...)type __VA_ARGS__;Scan(__VA_ARGS__);
template<typename T> void Scan(T& t) { std::cin >> t; }
template<typename First, typename...Rest>void Scan(First& first, Rest&...rest) { std::cin >> first; Scan(rest...); }
#define OUT(d) std::cout<<d;
#define FOUT(n, d) std::cout<<std::fixed<<std::setprecision(n)<<d;
#define SOUT(n, c, d) std::cout<<std::setw(n)<<std::setfill(c)<<d;
#define SP std::cout<<" ";
#define TAB std::cout<<"\t";
#define BR std::cout<<"\n";
#define ENDL std::cout<<std::endl;
#define FLUSH std::cout<<std::flush;
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define MAT(type, c, m, n) std::vector<std::vector<type>> c(m, std::vector<type>(n));for(auto& r:c)for(auto& i:r)std::cin>>i;
#define ALL(a) (a).begin(),(a).end()
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)
#define PAIR std::pair<int, int>
#define IN(a, x, b) (a<=x && x<=b)
#define IN2(a0, y, a1, b0, x, b1) (a0<=y && y<a1 && b0<=x && x<b1)
#define SHOW(d) {std::cout << #d << "\t:" << d << "\n";}
#define SHOWVECTOR(v) {std::cout << #v << "\t:";for(const auto& i : v){std::cout << i << " ";}std::cout << "\n";}
#define SHOWVECTOR2(v) {std::cout << #v << "\t:\n";for(const auto& i : v){for(const auto& j : i){std::cout << j << " ";}std::cout << "\n";}}
#define SHOWPAIRVECTOR2(v) {std::cout << #v << "\t:\n";for(const auto& i : v){for(const auto& j : i){std::cout<<'('<<j.first<<", "<<j.second<<") ";}std::cout << "\n";}}
#define SHOWPAIRVECTOR(v) {for(const auto& i:v){std::cout<<'('<<i.first<<", "<<i.second<<") ";}std::cout<<"\n";}
#define CHECKTIME(state) {auto start=std::chrono::system_clock::now();state();auto end=std::chrono::system_clock::now();auto res=std::chrono::duration_cast<std::chrono::nanoseconds>(end-start).count();std::cerr<<"[Time:"<<res<<"ns  ("<<res/(1.0e9)<<"s)]\n";}

//#define int ll
using ll = long long;
constexpr int INFINT = 1 << 30;
constexpr ll INFLL = 1LL << 60;
constexpr double EPS = 0.0000001;
constexpr int MOD = 1000000007;

int num[100005];
bool red[100005];

signed main() {
	INIT;
	VAR(int, n, m);
	REP(i, n) {
		num[i] = 1;
		red[i] = false;
	}
	red[0] = true;
	REP(i, m) {
		VAR(int, x, y);
		--x; --y;
		if (red[x]) {
			red[y] = true;
		}
		--num[x];
		++num[y];
		if (num[x] == 0) {
			red[x] = false;
		}
	}
	int ans = 0;
	REP(i, n) {
		if (red[i]) ++ans;
	}
	OUT(ans)BR;
	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long,long long>
using namespace std;

int n;

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n;
    cout << (n+1)/2;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
const int Q=(1<<11)+1;
int cnt[Q],a[Q];
inline int mul(int a,int b)
{return 1LL*a*b%MOD;}
inline int add(int a,int b)
{a+=b;return a>=MOD?a-MOD:a;}
int main()
{
	int n,k,c0=0,c1=0;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]),++cnt[a[i]];
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			if(a[i]>a[j])++c0;
	for(int i=1;i<=2000;i++)cnt[i]+=cnt[i-1];
	for(int i=1;i<=n;i++)c1+=cnt[a[i]-1];
	printf("%d\n",add(mul(c0,k),mul(c1,1LL*k*(k-1)/2%MOD)));
	return 0;
}

Measured memory_bytes: 256
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a[ohara], b, c, d, tmp, m, h, w, x, y, sum[ohara], k, q;
ll f[ohara], fr[ohara], dat[ohara];

ll mod_pow(ll xx, ll nn, ll mod) {
  ll ret = 1;
  while (nn > 0) {
    if (nn & 1) ret = ret * xx % mod;
    xx = xx * xx % mod;
    nn >>= 1;
  }
  return ret;
}

ll ncr(ll nn, ll r) {
  if (nn < r) return 0;
  return f[nn] * fr[r] % MOD * fr[nn - r] % MOD;
}

int main(void) {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> k;
  rep(i, n) cin >> a[i];
  sort(a, a + n);
  rep(i, n) sum[i] = a[i];
  rrep(i, 1, n) sum[i] += sum[i - 1];
  f[0] = 1;
  rrep(i, 1, n + 3) { f[i] = f[i - 1] * i % MOD; }
  fr[n + 2] = mod_pow(f[n + 2], MOD - 2, MOD);
  rrrep(i, n + 1, 0) { fr[i] = fr[i + 1] * (i + 1) % MOD; }

  rep(i, n) {
    ll cost = sum[n - 1];
    if (i >= 1) cost -= sum[i - 1];
    cost -= sum[n - i - 1];
    cost %= MOD;
    dat[i] = cost;
  }

  rrep(i, k - 1, n) {
    ll cost;
    cost = ncr(i - 1, k - 2);
    cost *= (dat[i]);
    cost %= MOD;
    ans += cost;
    ans %= MOD;
  }
  Cout(ans);
  return 0;
}


Measured memory_bytes: 13312
#include <bits/stdc++.h>

using namespace std;

int main() {
string s;
cin >> s;
int l = s.length();
bool ac = true;
if (s[0] != 'A') ac = false;
if (s[l-1] == 'C' || s[1] == 'C') ac = false;
int cnt = 0;
for (int i = 2; i<=l-2; ++i) cnt += s[i] == 'C';
if (cnt != 1) ac = false;
cnt = 0;
for (int i = 1; i < l; ++i) if (s[i] >= 'A' && s[i] <= 'Z') cnt++;
if (cnt != 1) ac = false;

cout << (ac ? "AC" : "WA") << "\n";
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int N, S;
pair <int, long long> A[100005];
int V[100005];
void Read()
{
    cin >> N >> S;
    for(int i = 1; i <= N; i++)
    {
        cin >> A[i].first >> A[i].second;
    }
}
inline int mod(int x)
{
    return max(x, -x);
}
void Solve()
{
    int left = 1, right = N,cnt = 0;
    while(left <= right)
    {
        if(S > A[right].first)
        {
            for(int j = left; j <= right; j++)
                V[++cnt] = A[j].first;
            break;
        }
        if(S < A[left].first)
        {
            for(int j = right; j >= left; j--)
                V[++cnt] = A[j].first;
            break;
        }
        if(A[left].second >= A[right].second)
        {
            V[++cnt] = A[right].first;
            A[left].second += A[right].second;
            --right;
        }
        else
        {
            V[++cnt] = A[left].first;
            A[right].second += A[left].second;
            ++left;
        }

    }
    long long ans = 0;
    V[++cnt] = S;
    for(int i = cnt; i >= 2; i--)
    {
        ans += mod(V[i] - V[i - 1]);
    }
    cout << ans << '\n';
}
int main()
{
    Read();
    Solve();
    return 0;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using ll= long long;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define ALL(x) x.begin(),x.end()

#define INF (ll)1e9 //10^9:∞
#define LLINF (ll)1e12
#define MOD (ll)(1e9+7) //10^9+7:合同式の法
#define PI 3.141592653589
#define PB push_back
#define F first
#define S second
#define __MAGIC__ ios::sync_with_stdio(false);cin.tie(nullptr);

#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

#define Graph vector<vector<int>>
#define PII pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VPII vector<pair<int,int>>

#define DDD fixed<<setprecision(10)
#define endl "\n"

using namespace std;
/*..................DEFINE GLOBAL VARIABLES...................*/


/*.....................DEFINE FUNCTIONS ......................*/



/*.........................kemkemG0...........................*/
signed main() {
	__MAGIC__


	int x;
	cin>>x;
	if(x==1)cout<<0<<endl;
	else cout<<1<<endl;

	



	

		return 0;
}


Measured memory_bytes: 3608
package main

import (
	"bufio"
	"fmt"
	basicIO "io"
	"os"
	"strconv"
	"strings"
)

func main() {
	protagonist(os.Stdin, os.Stdout)
}

func protagonist(r basicIO.Reader, w basicIO.Writer) {
	io := NewIO(r, w)
	N, _ := io.nextInt()
	s := io.nextString()

	R := strings.Count(s, "R")
	B := N - R
	if B < R {
		io.PutString("Yes")
	} else {
		io.PutString("No")
	}
}

type IO struct {
	Scanner *bufio.Scanner
	Writer  basicIO.Writer
}

func NewIO(r basicIO.Reader, w basicIO.Writer) *IO {
	s := bufio.NewScanner(r)
	s.Split(bufio.ScanWords)
	return &IO{
		Scanner: s,
		Writer:  w,
	}
}

func (io *IO) nextString() string {
	io.Scanner.Scan()
	return io.Scanner.Text()
}

func (io *IO) nextInt() (int, error) {
	io.Scanner.Scan()
	i, err := strconv.Atoi(io.Scanner.Text())
	return i, err
}

func (io *IO) PutInt(v int) {
	fmt.Fprintf(io.Writer, "%d\n", v)
}

func (io *IO) PutString(s string) {
	fmt.Fprintf(io.Writer, "%s\n", s)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second

ll n,cnt,ans,a,b,c,d,tmp[4],tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);

    cin>>a>>b>>c;
    tmp[0]=a,tmp[1]=b,tmp[2]=c;
    sort(tmp,tmp+3);
    reverse(tmp,tmp+3);
    tmp[0]*=10;
    Cout(tmp[0]+tmp[1]+tmp[2]);
    return 0;
}


Measured memory_bytes: 256
import collections
N = int(input())
S = {}
for i in range(N):
    value = input()
    if value not in S:
        S[value] = 1
    else:
        S[value] += 1
S_largest = max(S.values())
S_sorted = sorted(S.items(), key=lambda x:x[1], reverse=True)
ans = []
for i in range(len(S_sorted)):
    if S_sorted[i][1] == S_largest:
        ans.append(S_sorted[i][0])
    else:
        break
ans_sorted = sorted(ans)
for a in ans_sorted:
    print(a)


Measured memory_bytes: 50228
#include<bits/stdc++.h>
#define pi 3.141592653589793238
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define MOD 1000000007
#define INF 999999999999999999 
#define pb push_back
#define ff first
#define ss second
 
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
 
 
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;
    
    //cin >> T;
    while (T--) {
        ll x;
        cin >> x;
        cout << (x == 0) << endl;
    }
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
using namespace std;
int main(){
    int a, b, m;
    cin >> a >> b >> m;
    int as[a];
    int bs[b];
    int i, j;
    int a_min = 1000000, b_min = 1000000;
    for(i=0; i<a; i++){
        cin >> as[i];
        if(as[i] < a_min) a_min = as[i];
    }
    for(i=0; i<b; i++){
        cin >> bs[i];
        if(bs[i] < b_min) b_min = bs[i];
    }
    int min_cost = a_min + b_min;
    int x, y, c;
    for(i=0; i<m; i++){
        cin >> x >> y >> c;
        int cost = as[x-1] + bs[y-1] - c;
        if(min_cost > cost) min_cost = cost;
    }
    cout << min_cost << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;
int n;
int v[22];
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>v[i];
    }
    int maxx=v[1],ans=0;
    for(int i=1;i<=n;i++)
    {
        if(maxx<=v[i])
        {
            ans++;
            maxx=v[i];
        }
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;

#define dbg(a)  cerr << __LINE__ << ": " << #a << " = " << a << '\n'

template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }

typedef long long ll;

const int mod = 1e9+7;

ll nodOfFact(int n){
  vector<int> isp(n+1, 1);
  for (int i = 2; i*i <= n; ++i){
    if(isp[i]){
      for (int j = i*i; j <= n; j+=i){
        isp[j]=0;
      }
    }
  }

  vector<int> primes;
  for (int i = 2; i <= n; ++i){
    if(isp[i]){
      primes.push_back(i);
    }
  }

  ll ret = 1;
  for(auto& u: primes){
    ll p = u;
    int e = 0;
    while(p<=n){
      e += n/p;
      p *= u;
    }
    ret *= (e+1);
    ret %= mod;
  }
  return ret;

}

int main(){
  ios::sync_with_stdio(0), cin.tie(0);
  int n;  cin >> n;
  cout << nodOfFact(n) << "\n";
  return 0;
}

Measured memory_bytes: 3668
#include<iostream>
using namespace std;

int main(){
    double n,c = 0;
    cin>>n;
    for(int i =1;i<=n;i++){
        //cout<<i<<endl;
        if(i%2 != 0){
            c += 1;
        }
    }
    double a = c/n;

    cout<<a<<endl;
    //cout<<"tamesi"<<endl;
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
import collections
n = int(input())
lst = list(map(int,input().split()))
odd = [0]*(n//2)
even = [0]*(n//2)
leng = 0
for i in range(n//2):
    odd[i]=lst[leng]
    leng+=1
    even[i]=lst[leng]
    leng+=1
o1 = collections.Counter(odd).most_common()[0]
e1 = collections.Counter(even).most_common()[0]
if o1[0] != e1[0]:
    ans = n - (o1[1] + e1[1])
else:
    try:
        o2 = collections.Counter(odd).most_common()[1]
    except:
        o2 = [0,0]
    try:
        e2 = collections.Counter(even).most_common()[1]
    except:
        e2 = [1,0]
    ans = n - max(o1[1]+e2[1],o2[1]+e1[1])

print(ans)

Measured memory_bytes: 17500
import collections, os, re


n = int(input())

words = set()
last = ''

ans = True

for i in range(n):
    s = input()
    if (i > 0 and last[-1] != s[0]) or s in words:
        ans = False

    words.add(s)


    last = s

print('{}'.format('Yes' if ans else 'No'))


Measured memory_bytes: 3444
#include <cstdio>
#include <vector>
#include <stack>
#include <iostream>
#include <string>
#include <tuple>
#include <random>
#include <map>
#include <queue>
#include <set>
#include <complex>
#include <algorithm>
#include <cassert>
#include <iterator>
#include <numeric>
#include <cmath>
#include <stdio.h>
#include <functional>

using namespace std;
using ll = long long;
using ld = double;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll, ll>;
const ll INF = 1e17;
const ld eps = 1e-10;
const ll MOD = 1e9 + 7;

const double pi = acos(-1.0);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N;
	cin >> N;
	vector<ll> v(N);
	for (int i = 0;i < N;i++) {
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	ll big = v.back();
	ll mini = *v.begin();
	v.pop_back();
	vector<P> ans;
	for (int i = 1;i < v.size();i++) {
		if (v[i] >= 0) {
			ans.push_back(P(mini, v[i]));
			mini -= v[i];
		}
		else {
			ans.push_back(P(big, v[i]));
			big -= v[i];
		}
	}
	cout << big - mini << endl;
	for (int i = 0;i < ans.size();i++) {
		cout << ans[i].first << " " << ans[i].second << endl;
	}
	cout << big << " " << mini << endl;
	return 0;
}






Measured memory_bytes: 4336
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>

using std::vector;
using std::map;
using std::string;
using std::pair;
using std::cin;
using std::cout;

// @author: pashka

int main() {
    std::ios::sync_with_stdio(false);

    int n;
    cin >> n;
    int a = 0, b = 0, c = 0;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if (x % 4 == 0) {
            a++;
        } else if (x % 2 == 0) {
            b++;
        } else {
            c++;
        }
    }
    cout << ((a >= c || b == 0 && a >= c - 1) ? "Yes" : "No");

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define maxn 100005
using namespace std;
typedef long long ll;

vector<int>G[maxn];
int step1[maxn],step2[maxn];
int vis1[maxn],vis2[maxn];
int n,s1,s2,u,v;

void bfs(int k){
    if(k==s1){
        queue<int>q;
        q.push(k);
        step1[k]=0;
        vis1[k]=1;
        while(!q.empty()){
          int a=q.front();
          q.pop();
          for(int b:G[a]){
             if(!vis1[b]) {
                step1[b]=step1[a]+1;
                //cout<<b<<" "<<step1[b]<<endl;
                vis1[b]=1;
                q.push(b);
          }
        }
      }
    }
    else if(k==s2){
        queue<int>q;
        q.push(k);
        step2[k]=0;
        vis2[k]=1;
        while(!q.empty()){
          int a=q.front();
          q.pop();
          for(int b:G[a]){
            if(!vis2[b]) {
                step2[b]=step2[a]+1;
                //cout<<b<<" "<<step2[b]<<endl;
                vis2[b]=1;
                q.push(b);
            }
         }
      }
   }
}

int main(){
    memset(vis1,0,sizeof(vis1));
    memset(vis2,0,sizeof(vis2));
    memset(step1,0,sizeof(step1));
    memset(step2,0,sizeof(step2));
    cin>>n>>s1>>s2;
    for(int i=0;i<n-1;i++){
        scanf("%d%d",&u,&v);
        G[u].push_back(v);
        G[v].push_back(u);
    }
    bfs(s1);
    bfs(s2);
    int ans=0;
    for(int i=1;i<=n;i++){
        if(step1[i]<step2[i]) ans=max(ans,step2[i]);
        //cout<<step1[i]<<" "<<step2[i]<<" "<<ans<<endl;
    }
    cout<<ans-1;
  return 0;
}
/*
5 1 3
1 2
2 3
2 4
4 5
*/


Measured memory_bytes: 7424
import java.util.*;

import static java.lang.System.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();

        int[] a = new int[N];
        for (int i = 0; i < N; i++) a[i] = sc.nextInt();

        // 配列の順番は関係ない。左からKづつ操作していく回数と同じ
        // （実際は、1が含まれるK順列から、左右に適用していく）
        out.println((int)(Math.ceil((double)(N-1)/(K-1))));
    }
}


Measured memory_bytes: 53524
#include <bits/stdc++.h>

typedef long long ll;

const int N = 105;

char s[N];
int k, n, tot, len[N];
ll ans;

int main()
{
	bool is = 1;
	scanf("%s%d", s + 1, &k); n = strlen(s + 1);
	for (int i = 1; i <= n; i++) if (s[i] != s[1]) is = 0;
	if (is) return std::cout << 1ll * n * k / 2 << std::endl, 0;
	for (int i = 1, c = 1; i <= n; i++)
		if (s[i] != s[i + 1]) len[++tot] = c, c = 1; else c++;
	if (s[1] != s[n])
	{
		for (int i = 1; i <= tot; i++) ans += len[i] >> 1;
		return std::cout << ans * k << std::endl, 0;
	}
	for (int i = 2; i < tot; i++) ans += len[i] >> 1; ans *= k;
	return std::cout << ans + 1ll * (k - 1) * (len[1] + len[tot] >> 1)
		+ (len[1] >> 1) + (len[tot] >> 1) << std::endl, 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>

using namespace std;

string a,b,ans;
int mem[3005][3005];

int go(int x,int y)
{
	if(x>=a.size()||y>=b.size()) return 0;
	if(mem[x][y]!=-1) return mem[x][y];
	if(a[x]==b[y]) return mem[x][y]=go(x+1,y+1)+1;
	return mem[x][y]=max(go(x+1,y),go(x,y+1));
}

void build(int x,int y)
{
	if(x>=a.size()||y>=b.size()) return;
	if(a[x]==b[y]){ans+=a[x]; build(x+1,y+1); return;}
	if(mem[x][y]==go(x+1,y))
	{
		build(x+1,y); return;
	}
	build(x,y+1);
}

int main()
{
	cin >> a >> b;
	memset(mem,-1,sizeof mem);
	go(0,0);
	build(0,0);
	cout << ans << endl;
}

Measured memory_bytes: 35840
#include <bits/stdc++.h>
using namespace std;

int main(){
  string s;cin >> s;
  int ans =0;
  int count =0;
  for(int i=0; i<s.size(); i++){
    char c = s.at(i);
    if(c=='A'||c=='C'||c=='G'||c=='T')count++;
    else count=0;
    ans = max(ans,count);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;


public class Main {


//	final int MOD = 1000000007;

//	public static int min = 3000000;

	public static void main(String[] args) {

		int ans = 0;
		Scanner sc = new Scanner(System.in);
		boolean f = false;

//		long k = sc.nextLong();
		int x = sc.nextInt();
		int n = sc.nextInt();

		int[] a = new int[n];
		ArrayList<Integer> list = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			int t = sc.nextInt();
			a[i] = t;
			list.add(t);
		}

		//-------------------------------------------------------------------------------------
		int tmp = 10000;
		for(int i = -1000; i <= 1000; i++) {
			if(list.contains(i))
				continue;
			if(tmp == Math.abs(x - i)) {
				if(ans > i) {
					ans = i;
					tmp = Math.abs(x - i);
				}
			} else if(tmp > Math.abs(x - i)) {
				ans = i;
				tmp = Math.abs(x - i);
			}
		}

		//-------------------------------------------------------------------------------------

//		if(f) {
//			System.out.println("Yes");
//		} else {
//			System.out.println("No");
//		}

		System.out.println(ans);

		sc.close();
	}



}

Measured memory_bytes: 36556
#include <stdio.h>

void sort(int *a, int n) {
    for (int i = 0; i < n - 1; i++) {
        for (int j = i + 1; j > 0 && a[j - 1] > a[j]; j--) {
            int tmp = a[j - 1];
            a[j - 1] = a[j];
            a[j] = tmp;
        }
    }
}

int main(void) {
    int n, x;
    int a[100];
    int sum;

    scanf("%d%d", &n, &x);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }

    sort(a, n);

    sum = 0;
    for (int i = 0; i < n; i++) {
        if (sum + a[i] < x) {
            sum += a[i];
        }
        else if (sum + a[i] == x) {
            printf("%d\n", i + 1);
            return 0;
        }
        else {
            printf("%d\n", i);
            return 0;
        }
    }

    printf("%d\n", n - 1);

    return 0;
}


Measured memory_bytes: 128
// Created by ...
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'

#define vll vector< ll >
#define M 100000
#define MD 1000000007
#define pb push_back
#define rep(i,a,b) for(ll i = a; i <= b; ++i)
#define fo(i,a,b) for(int i = a; i<= b; ++i)
#define pii pair<ll,ll> 
#define vec(a) vector<a >
#define all(a) a.begin(),a.end()
#define se second
#define fi first
#define inf 0xffffffff
#define inchar getchar_unlocked
#define outchar(x) putchar_unlocked(x)
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

using namespace std;
using ll = long long;
ll md=MD;

ll exp(ll a,ll b){ll r=1ll;while(b>0){if(b&1){r=r*(a%md);r=(r+md)%md;}b>>=1;a=(a%md)*(a%md);a=(a+md)%md;}return (r+md)%md;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll Min(ll a,ll b){if(a<b)return a; return b;}
ll Max(ll a,ll b){if(a>b)return a; return b;}
int32_t main() {
    IOS;

        string s; cin>>s;
        if(s[1]=='B')s[1]='R'; else s[1]='B';
        cout<<s;
        



        cout<<'\n';
    return 0;
}

Measured memory_bytes: 3608