akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <unordered_map>
#define Debug 0
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

Int mod_pow(Int x, Int n) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % MOD; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % MOD;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}

//最大公約数
template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

//最小公倍数
template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

int calc(int y, int m, int d) {
    int ret = 0;
    
    const int days_normal = 20*5+19*5;
    const int days_aho = 20*10;

    ret += (y-1)/3 * days_aho;
    ret += (y-1)/3 * days_normal * 2;
    ret += (y-1)%3 * days_normal;
    if (y%3) {
        ret += (m-1)/2 * 39;
        ret += (m-1)%2 * 20;
        ret += d;
    } else {
        ret += (m-1)*20;
        ret += d;
    }
    return ret;
}

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

    int N; cin >> N;
    vector<int> ans(N);
    for (int i = 0; i < N; i++) {
        int y, m, d; cin >> y >> m >> d;
        ans[i] = (calc(1000, 1, 1) - calc(y, m, d));
    }
    for (int i = 0; i < N; i++) {
        cout << ans[i] << endl;
    }
}





Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
int main(){
	long n,k;
	cin>>n>>k;
	long sum=0;
	if(k==0){
	    cout<<n*n;
	    return 0;
	}
	for(int i=k+1; i<=n; i++){
	    sum+=(n/i)*(i-k);
	    if(n%i>=k)
	        sum+=(n%i-k+1);
	}
	cout<<sum;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
typedef long double ld;
#define fr first
#define sc second
#define pb push_back
const ll mod = 998244353;
const int N = 1e6+205;
void solve(){
	int x,y,z; 
	cin>>x>>y>>z;
	x-=z;
	int ans = x/(y+z);
	cout<<ans<<endl;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1; 
//	cin>>t; 
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

int main()
{
	enum { NOTHING, EAST, WEST, NORTH, SOUTH };
	string str = "";

	while (getline (cin, str ) ){

		int h, w;
		stringstream ssn(str);
		ssn >> h >> w;

		if (h == 0 && w == 0){
			break;
		} // end if

		vector<vector <int> > m (h, vector <int> (w, 0 ) );
		vector<vector <bool> > v (h, vector <bool> (w, false ) );
		int i,j;

		for (i = 0; i < h; ++i ){

			getline (cin, str );

			for (j = 0; j < w; ++j ){
				char c = str[j];
				switch (c){
					case '.': m[i][j] = NOTHING; break;
					case '^': m[i][j] = NORTH; break;
					case '>': m[i][j] = EAST; break;
					case 'v': m[i][j] = SOUTH; break;
					case '<': m[i][j] = WEST; break;
				} // end switch
			} // end for
		} // end for

		int currx = 0;
		int curry = 0;

		while (!v[curry][currx] && m[curry][currx] != NOTHING ){

 			v[curry][currx] = true;
			int d = m[curry][currx];

			switch (d){
				case NORTH: --curry; break;
				case SOUTH: ++curry; break;
				case EAST:  ++currx; break;
				case WEST:  --currx; break;
			} // end switch
		} // end while

		if (!v[curry][currx]){
			cout << currx << ' ' << curry << endl;
		}else{
			cout << "LOOP" << endl;
		} // end if

	} // end loop

	return 0;
}

Measured memory_bytes: 0
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>  
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000000000000000000000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
long long power(long long a,long long now) {
	long long ans = 1;
	while (now != 0) {
		if (now % 2 == 1) {
			ans *= a;
			ans %= MOD;
		}
		now /= 2;
		a *= a;
		a %= MOD;
	}
	return ans;
}
long long inv(long long a) {
	return power(a, MOD - 2);
}
long long permutation(long long a, long long b) {
	long long ans = 1;
	for (long long i = 0; i < b; ++i) {
		ans *= (a - i);
		ans %= MOD;
	}
	return ans;
}
long long combination(long long a, long long b) {
	long long ans = 1;
	for (long long i = 0; i < b; ++i) {
		ans *= (a - i);
		ans %= MOD;
		ans *= inv(i + 1);
		ans %= MOD;
	}
	return ans;
}
long long dp[1001][1001];
long long solve(long long a, long long b) {
	if (b == 1) return 1;
	if (a < 0) return 0;
	if (a == 0) return 1;
	if (dp[a][b]) return dp[a][b];
	return dp[a][b] = (solve(a,b-1) + solve(a-b,b)) % MOD;
}
int main() {
	long long n, k;
	cin >> n >> k;
	cout << solve(n-k, k) << endl;

	return 0;
}



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

using namespace std;


typedef long long ll;
#define rep(i,m,n) for(ll i=m;i<n;i++)

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

 ll n;
  cin >> n;
  
  ll sq= int(sqrt(double(n)))+1;

  ll res=n;

  for(ll i=sq;i>=1;i--){
   if(n%i==0) {
res=min(res,i+n/i-2);
break;
}
}
 cout << res << endl;

}


Measured memory_bytes: 256
import bisect
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a.sort()
c.sort()
ans=0
for i in b:
    ai=bisect.bisect_left(a,i)
    ci=bisect.bisect_right(c,i)
    ans+=ai*(n-ci)
print(ans)

Measured memory_bytes: 23232
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int a,b;cin >> a >> b;
	cout << a*b << '\n';
}


Measured memory_bytes: 3652
#include<iostream>
#include<string>
#include<stack>
using namespace std;

bool isParen(char c){
  return c == '(' || c == ')' || c == '[' || c == ']';
}
bool leftParen(char c){
  return c == '(' || c == '[';
}
bool rightParen(char c){
  return c == ')' || c == ']';
}
char matchParen(char c){
  if(c == '(')return ')';
  if(c == '[')return ']';
  return '_';
}
bool check(string& s){
  stack<char> stack;
  for(char c:s){
    if(leftParen(c)){
      stack.push(c);
    }else if(rightParen(c)){
      if(stack.empty())return false;
      if(c != matchParen(stack.top()))return false;
      stack.pop();
    }
  }
  return stack.empty();
}
int main(){
  while(true){
    string s;
    getline(cin,s);
    if(s == ".")break;
    cout << (check(s) ? "yes" : "no") << endl;
  }
}

Measured memory_bytes: 1180
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;

bool *f;

int main(){
	int n;
	while(cin>>n){
		f=new bool[n+1];
		for(int i=0;i<n;i++) f[i]=false;
		f[0]=true;
		f[1]=true;
		int l=sqrt(n);
		for(int i=2;i<=l;i++){
			for(int j=2;j*i<=n;j++){
				f[j*i]=true;
			}
		}
		int cnt=0;
		for(int i=0;i<=n;i++) if(!f[i])cnt++;
		cout<<cnt<<endl;
		delete []f;
	}
}

Measured memory_bytes: 2004
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main(void){
    string s;
    cin >> s;
    if(s[0] == s[1]){
        cout << "Bad" << endl;
    }else if(s[1] == s[2]){
        cout << "Bad" << endl;
    }else if(s[2] == s[3]){
        cout << "Bad" << endl;
    }else{
        cout << "Good" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    int n;
    cin >> n;
    cout << 800 * n - 200 * (n / 15) << endl;
    return 0;
}

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

int main() {
  char a, b, c, d;
  cin >> a >> b >> c >> d;

  int n1 = 10 * (a - '0') + (b - '0');
  int n2 = 10 * (c - '0') + (d - '0');

  if (n1 >= 1 && n1 <= 12) {
    if (n2 >= 1 && n2 <= 12) {
      cout << "AMBIGUOUS" << endl;
    } else {
      cout << "MMYY" << endl;
    }
  } else {
    if (n2 >= 1 && n2 <= 12) {
      cout << "YYMM" << endl;
    } else {
      cout << "NA" << endl;
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define mod 1000000007
bool compare(pair<lli,lli> p1,pair<lli,lli> p2)
{
    if(p1.first==p2.first)
    {
        return p1.second <p2.second;
    }
    return p1.first < p2.first;
}
lli max(lli a,lli b)
{
   if(a>b)
   {
       return a;
   }
   return b;
}

lli power(lli x,lli n)
{
    lli res=1;
    while(n>0)
    {
        if(n%2==1)
        {
            res=(res*x);
        }
        x=(x*x);
        n=n/2;
    }

    return  res;

}


int main()
{
    string str;
        cin>>str;
        lli ans=0;
        map<lli,lli> m;
        lli i=str.length()-1;
        lli p=1;
        m[0]++;
        lli t=0;
        while(i>=0)
        {
            t+=p*(str[i]-'0');
            t%=2019;
            //cout<<t<<"\n";
            ans+=m[t];
            m[t]++;
            p=p*10;
            p=p%2019;
            i--;
        }
        cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 3744
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long

using namespace std;

int main() {
	int N, K;
	cin >> N >> K;

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

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

	int ans = 0;
	for (int ii = 0; ii < K; ++ii){
		ans += p[ii];
	}

	cout << ans << "\n";

	return 0;
}


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


int main(void){
    int n; cin >> n;
    vector<int> A(n),B(n); 
    for(int i=0; i<n; i++){
        int a; cin >> a;
        A[i]=a; B[i]=a;
    }

    long long ans1=0, ans2=0;
    long long sum=0;
    for(int i=0; i<n; i++){
        sum+=A[i];
        if(i%2==0){
            if(sum<=0){
                A[i]+=1-sum;
                ans1+=1-sum;
                sum=1;
            }
        }
        else{
            if(sum>=0){
                A[i]-=sum+1;
                ans1+=sum+1;
                sum=-1;
            }
        }
    }

    sum=0;
    for(int i=0; i<n; i++){
        sum+=B[i];
        if(i%2==1){
            if(sum<=0){
                B[i]+=1-sum;
                ans2+=1-sum;
                sum=1;
            }
        }
        else{
            if(sum>=0){
                B[i]-=sum+1;
                ans2+=sum+1;
                sum=-1;
            }
        }
    }

    if(ans1<ans2) cout << ans1 << endl;
    else cout << ans2 << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> a(M), b(M);
  rep(i, M) cin >> a[i] >> b[i];
  
  int count;
  rep(i, N) {
    count=0;
  	rep(j,M) {
      if (a[j]==i+1) count++;
      if (b[j]==i+1) count++;
    }
    cout << count << endl;
  }
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T> bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    string S, T;
    cin >> S >> T;
    int ans = 0;
    REP(i, 3) {
        if (S[i] == T[i]) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Vector {
    double x, y;

    public Vector(double x, double y) {
        this.x = x;
        this.y = y;
    }

    @Override
    public String toString() {
        return
                (Math.abs(this.x) < 0000.1 ? "0.00000000" : this.x) +
                        " " +
                        (Math.abs(this.y) < 0000.1 ? "0.00000000" : this.y);
    }

    public Vector unit(Vector that) {
        return new Vector((that.x - this.x) / 3, (that.y - this.y) / 3);
    }

    public Vector plus(Vector that) {
        return new Vector(this.x + that.x, this.y + that.y);
    }

    public Vector rotate(double radians) {
        return new Vector(
                this.x * Math.cos(radians) - this.y * Math.sin(radians),
                this.x * Math.sin(radians) + this.y * Math.cos(radians)
        );
    }
}

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Vector left = new Vector(0, 0);
        Vector right = new Vector(100, 0);
        System.out.println(left.toString());
        printKochPoints(
                left,
                right,
                0,
                n
        );
        System.out.println(right.toString());
    }

    static void printKochPoints(Vector l, Vector r, int i, int n) {
        if (i >= n) {
            return;
        }

        Vector unit = l.unit(r);

        Vector p1 = l.plus(unit);
        Vector p1p2 = unit.rotate(Math.PI / 3);
        Vector p2 = p1.plus(p1p2);
        Vector lp3 = unit.rotate(Math.PI);
        Vector p3 = r.plus(lp3);

        printKochPoints(l, p1, i + 1, n);
        System.out.println(p1.toString());
        printKochPoints(p1, p2, i + 1, n);
        System.out.println(p2.toString());
        printKochPoints(p2, p3, i + 1, n);
        System.out.println(p3.toString());
        printKochPoints(p3, r, i + 1, n);
    }
}


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

#define ll long long
#define pb push_back
#define mp make_pair


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

	// #ifndef ONLINE_JUDGE
 //    // for getting input from input.txt
 //    freopen("input.txt", "r+", stdin);
 //    // for writing output to output.txt
 //    freopen("output.txt", "w+", stdout);
	// #endif

    string a,b;
    cin >> a >> b;
    int n = a.length();
    int m = b.length();

    int dp[n+1][m+1];

    for(int i=0;i<=n;i++) {
    	dp[i][0] = 0;
    }
    for(int i=0;i<=m;i++) {
    	dp[0][i] = 0;
    }
    for(int i=1;i<=n;i++) {
    	for(int j=1;j<=m;j++) {
    		if(a[i-1] == b[j-1]) {
    			dp[i][j] = dp[i-1][j-1] + 1;
    		}
    		else {
    			dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
    		}
    	}
    }

    // for(int i=0;i<=n;i++) {
    // 	for(int j=0;j<=m;j++) {
    // 		cout << dp[i][j] << " ";
    // 	}
    // 	cout << '\n';
    // }

    // cout << dp[n][m] << '\n';

    string c = "";
    while(n > 0 and m > 0) {
    	// cout << n << " " << m << '\n';
    	if(a[n-1] == b[m-1]) {
    		c = a[n-1] + c;
    		m--;
    		n--;
    		// continue;
    	}
    	else if(dp[n-1][m] > dp[n][m-1]) {
    		n--;
    		// continue;
    	}
    	else {
    		m--;
    		// continue;
    	}
    }
    cout << c;
}

Measured memory_bytes: 35456
import std.container;
import std.range;
import std.algorithm;
import std.array;
import std.string;
import std.conv;
import std.stdio;
import std.container;

void main() {
	auto n = readln.chomp.to!int;
	auto l = readln.chomp.split(' ').map!(to!int).array;
	long count;

	foreach (i;0..n - 2) {
		foreach (j;i + 1..n - 1) {
			foreach (k;j + 1..n) {
				auto large = max(l[i], l[j], l[k]);
				auto small = min(l[i], l[j], l[k]);
				auto middle = cast(int)(cast(long)l[i] + l[j] + l[k] - large - small);

				if (large != middle && middle != small && large < small + middle) {
					++count;
				}
			}
		}
	}

	count.writeln;
}


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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* na, Arg1&& arg1, Args&&... args) {
  const char* c = strchr(na + 1, ',');
  cerr.write(na, c - na) << " : " << arg1 << " , ";
  __f(c + 1, args...);
}
#define endl "\n"
typedef long long LL;
const int mod = 1e9 + 7;
const int inf = 1e9;
const LL INF = 1e18;
const int N = 1e5 + 5;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};

int r, c;
string s[ 25 ];
int id[ 25 ][ 25 ];
int cost[ 500 ];
vector <int> graph[ N ];

int bfs(int s, int e) {
  for (int i = 0; i <= 400; i++) cost[i] = -1;
  queue <int> Q;
  cost[s] = 0;
  Q.push(s);
  while (!Q.empty()) {
    int f = Q.front(); Q.pop();
    for (auto x : graph[f]) {
      if (cost[x] == -1 || cost[x] > cost[f] + 1) {
        cost[x] = cost[f] + 1, Q.push(x);
      }
    }
  }
  return cost[e];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    freopen("input.txt", "r", stdin);
  #endif // LOCAL
  cin >> r >> c;
  for (int i = 0; i < r; i++) cin >> s[i];
  int mx = 0, ID = 0;
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      if (s[i][j] == '.') {
        id[i][j] = ++ID;
      }
    }
  }
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      if (s[i][j] == '.') {
        for (int k = 0; k < 4; k++) {
          int nx = i + dx[k], ny = j + dy[k];
          if (nx >= 0 && ny >= 0 && nx < r && ny < c && s[nx][ny] != '#') {
            graph[id[i][j]].push_back(id[nx][ny]);
            graph[id[nx][ny]].push_back(id[i][j]);
            //cout << id[i][j] << " " << id[nx][ny] << endl;
          }
        }
      }
    }
  }
  for (int i = 1; i <= ID; i++) {
    for (int j = 1; j <= ID; j++) {
      //cout << i << " " << j << " " << bfs(i, j) << endl;
      mx = max(mx, bfs(i, j));
    }
  }
  cout << mx << endl;
  return 0;
}



Measured memory_bytes: 2688
#!/usr/bin/env python3


def key(n):
    m = n % 10
    if m == 0:
        return 10
    else:
        return m


def kiriage(n):
    m = n % 10
    if m == 0:
        return n
    else:
        return n + 10 - m


def solv(a, b, c, d, e):
    times = sorted([a, b, c, d, e], key=key)
    ans = times[0]
    for t in times[1:]:
        ans += kiriage(t)
    return ans


if __name__ == '__main__':

    a = int(input())
    b = int(input())
    c = int(input())
    d = int(input())
    e = int(input())

    ans = solv(a, b, c, d, e)

    print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <deque>
#include <string>
#include <vector>
#include <queue>
#include <cstdio>
#include <stack>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <cstdio>
#include <cmath>
#include<list>
#include <cstdlib>
using namespace std;
typedef long long ll;
const int maxn = 1e7 + 8;
#define MOD 1046527
int n;
char H[maxn][15];

int getChar(char ch)
{
    return ch -'A' + 1;
}
ll getValue(char t[])
{
    int len = strlen(t);
    ll sum = 0, p = 1, i;
    for(i = 0; i < len;  ++i){
        sum += p * getChar(t[i]);
        p *= 5;
    }
    return sum;
}
ll h1(ll k)
{
    return k % MOD;
}
ll h2(ll k)
{
    return 1 + (k % (MOD - 1));
}
int solve_insert(char c[])
{
    ll key,i,h;
    key = getValue(c);
    i = 0;
    while(true)
    {
        h = (h1(key) + i * h2(key)) % MOD;
        if(strcmp(H[h],c) == 0) return 1;
        else if(strlen(H[h]) == 0){
            strcpy(H[h],c);
            return 0;
        }
        i++;
    }
}
int solve_find(char c[])
{
    ll key, i, h;
    i = 0;
    key = getValue(c);
    while(true)
    {
        h = (h1(key) + i * h2(key)) % MOD;
        if(strcmp(H[h],c) == 0) return 1;
        else if(strlen(H[h]) == 0){
            return 0;
        }
        i++;
    }
}
int main()
{
    scanf("%d",&n);
    char s[15],t[15];
    for(int i = 0; i < n; ++i){
        scanf("%s%s",s,t);
        if(s[0] == 'i'){
            solve_insert(t);
        }else{
            if(solve_find(t))printf("yes\n");
            else printf("no\n");
        }
    }
    return 0;
}

Measured memory_bytes: 18472
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
ll mod = 1e9 + 7;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

ll sum(ll l, ll r) {
  return (l + r) * (r - l + 1) / 2;
}

int main() {
  int n, k;
  cin >> n >> k;

  mint ans = 0;
  for (int i = k; i <= n + 1; i++) {
    ll l = sum(0, i - 1), r = sum(n - i + 1, n);
    ans += r - l + 1;
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3560
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))

ans = []
for i in range(n-k):
    if (a[i] < a[i+k]):
        ans.append("Yes")
    else:
        ans.append("No")

for i in range(len(ans)):
    print(ans[i])


Measured memory_bytes: 31684
#include <iostream>
#include <string>
using namespace std;
int main() {
  	string s;
  	cin >> s;
  	int l = s.length();
  	int count = 0;
    for( int i = 0; i < l/2; i++ ){
      if(s[i] != s[l-i-1] ){
        s[l-i-1] = s[i];
        count++;
      }
    }
  	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define F first
#define S second


typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;

int main() {
	int n;
	cin >> n;
	VI a(n); rep(i, n)a[i] = i + 1;
	do {
		rep(i, n) {
			cout << a[i];
			printf(i == n - 1 ? "\n" : " ");
		}
	} while (next_permutation(all(a)));
}


Measured memory_bytes: 3232
#include <bits/stdc++.h>
#define INF (int)1e9
#define endl "\n"
#define ll long long
#define ull unsigned long long

using namespace std;

int main()
{
    string s;
    cin >> s;
    string rev = s;
    reverse(rev.begin(), rev.end());

    string curr = s;
    string other = rev;

    vector<string> sel(2);
    sel[0] = curr;
    sel[1] = other;
    int q;
    cin >> q;

    int i = 0;

    while (q--)
    {
        int a;
        cin >> a;
        if (a == 1)
        {
            i = 1 - i;
        }
        else
        {
            int t;
            char c;
            cin >> t >> c;

            if (t == 1)
            {
                sel[i].insert(sel[i].begin(), c);
                sel[1 - i] += c;
            }
            else
            {
                sel[i] += c;
                sel[1 - i].insert(sel[1 - i].begin(), c);
            }
        }
    }
    cout << sel[i] << endl;
}

Measured memory_bytes: 1528
///supercalifragilisticexpialidocious.
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <cctype>
#include <ctime>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <utility>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <list>
#include <bitset>
#include <complex>
using namespace std;
#define f first
//#define s second
#define PB pop_back 
#define pb push_back
#define mp make_pair
#define int long long
#define y1 y_golabi
#define sz(s) (int)s.size()
#define seper(n) setprecision(n)
#define all(v) v.begin(),v.end()
#define mem(a,b) memset(a,b,sizeof a)
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
typedef long long ll; 
typedef map<int , int> mii;
typedef pair<int , int> pii; 
typedef map<string , int> msi;
typedef pair<int , string> pis; 
typedef pair<int , pair<int , int> > piii;
int mn = 1e10 , cnt;
string s , t , str;
bool is_Same(string s)
{
	for(int i = 0 ; i < sz(s) ; i ++)
		if(s[i] != s[0])
			return false;
	return true;
}
int32_t main()
{
	cin >> str;
	for(char ch = 'a' ; ch <= 'z' ; ch ++)
	{
		t = "" , s = str , cnt = 0;
		while(!is_Same(s))
		{
			t.clear();
			for(int i = 0 ; i < sz(s) - 1 ; i ++)
				if(s[i] == ch or s[i + 1] == ch)
					t += ch;
				else
					t += s[i];
			s = t , cnt ++;
		}
		mn = min(mn , cnt);
	}
	return cout << mn << endl , 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n, a, ans int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a)
		if i%2 == 0 && a%2 == 1 {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1772
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;


int main() {
    ll X, K, D;
    cin >> X >> K >> D;
    X = abs(X);
    ll cnt = X / D;
    
    if (K <= cnt) {
        rep(i, K) X -= D;
        cout << X << endl;
    } else {
        if ((K - cnt) % 2 == 0) cout << X % D << endl;
        else cout << abs(X % D - D) << endl;
    }
}

Measured memory_bytes: 3612
import bisect

n,k = map(int,input().split())
A = sorted([int(i) for i in input().split()])

inm = bisect.bisect_left(A,0)
inp = bisect.bisect_right(A,0)
mi = [-x for x in A[:inm]]
mi = mi[::-1]
pl = A[inp:]
zero = inp-inm
numm = inm
nump = n-inp

def shaku(x,l):
    count = 0
    ma = len(l)
    ri = ma-1
    for i in range(ma):
        while ri >= 0 and l[ri]*l[i] > x:
            ri -= 1
        count += max(ri-i,0)
        
    return count 

def search(x):
    count = 0
    if x >= 0:
        count += zero*(n-zero)+numm*nump+(zero*(zero-1))//2
        count += shaku(x,pl)
        count += shaku(x,mi)
            
        return count
    else:
        ri = 0
        for i in pl[::-1]:
            while ri < numm and i*mi[ri] < -x:
                ri += 1
            count += numm-ri
        return count

left = -10**18-1
right = 10**18+1
while right > left+1:
    mid = (left+right)//2
    a = search(mid)
    
    if a >= k:
        right = mid
    else:
        left = mid
print(right)


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

int main()
{
    int l,r,d,x,p,i;
    cin>>l>>r>>d;
    x=0,i=0;
    for(i=l;i<=r;i++)
    {
        if(i%d==0)
        {
            x=x+1;
        }

    }
     cout<<x;


    return 0;

}


Measured memory_bytes: 3576
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn main() {
    let n: usize = read_line().trim().parse().unwrap();
    let a = read_line();
    let a = a.as_bytes();
    let b = read_line();
    let b = b.as_bytes();
    let c = read_line();
    let c = c.as_bytes();

    let mut ans = 0;
    for i in 0..n {
        if a[i] != b[i] && b[i]!= c[i] && c[i] != a[i] {
            ans += 2;
        } else if a[i]!=b[i] || b[i]!= c[i] {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
let () =
  Scanf.scanf "%d\n" @@ fun n ->
  let t = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun d -> d in
  Scanf.scanf "%d\n" @@ fun m ->
  let arr = Array.init m @@ fun _ -> Scanf.scanf "%d %d\n" @@ fun p x -> (p,x) in
  let sum = Array.fold_left (+) 0 t in
  Array.iter (fun (p,x) -> Printf.printf "%d\n" (sum - (t.(p-1)-x))) arr

Measured memory_bytes: 3812
#設定
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)

#ライブラリインポート
from collections import defaultdict
answer = 0
#入力受け取り
def getlist():
	return list(map(int, input().split()))

INF = float("inf")
class Graph(object):
	def __init__(self):
		self.graph = defaultdict(list)

	def __len__(self):
		return len(self.graph)

	def add_edge(self, a, b):
		self.graph[a].append(b)

	def get_nodes(self):
		return self.graph.keys()


def DFS(G, visit, W, Wlist, node, K):
	for i in G.graph[node]:
		if visit[i] != "Yes":
			visit[i] = "Yes"
			DFS(G, visit, W, Wlist, i, K)
			Wlist[node].append(W[i] + 1)

	val = 0
	for i in Wlist[node]:
		if i == K and node != 0:
			global answer
			answer += 1
		else:
			val = max(val, i)
	W[node] = val

#処理内容
def main():
	N, K = getlist()
	a = getlist()
	G = Graph()
	for i in range(1, N):
		G.add_edge(i, a[i] - 1)
		G.add_edge(a[i] - 1, i)
	ans = 0
	if a[0] != 1:
		ans += 1
	if K == 1:
		for i in range(1, N):
			if a[i] != 1:
				ans += 1
		print(ans)
		return

	#DFS
	W = [0] * N
	Wlist = [[] for i in range(N)]
	visit = ["No"] * N
	visit[0] = "Yes"
	
	DFS(G, visit, W, Wlist, 0, K)
	print(ans + answer)


if __name__ == '__main__':
	main()

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

typedef long long LL;  
using namespace std;

#define fillchar(a, x) memset(a, x, sizeof(a))
#define MP make_pair
#define PB push_back
#define endl '\n'

const LL M = (LL)1e9+7;

int main()
{
//ios_base::sync_with_stdio(0); 
	cout.precision(15);
	cout.setf(ios::fixed);

	LL n;

	cin >> n;

	vector <LL> v(n),pre(n);


	for(LL i=0;i<n;i++)
			cin >> v[i] ;

	sort(v.begin(),v.end());
	
	for(LL i=0;i<n;i++)
		{	
			if(i==0) pre[0] = v[0];
			else pre[i] = pre[i-1] + v[i]; 
		}

	LL ans = 1;	

	for(LL i=n-2;i>=0;i--)
		{
			if(pre[i]*2<v[i+1])
				break;

			// cout<<pre[i]<<' '<<v[i+1]<<endl;	

			ans++;		
		}

	cout << ans << endl;	
}


Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b && a == c)cout << "1" << endl;
	else if (a == b || a == c || b == c)cout << "2" << endl;
	else cout << "3" << endl;
  }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
typedef pair<int,int> P;
typedef long long ll;
const int INF = 1001001001;
const ll INFL = 1e17;
const int MOD = 1e9+7;


int main(){
    int h,w;
    cin >> h >> w;
    int sy,sx,gy,gx;
    cin >> sy >> sx >> gy >> gx;
    --sy; --sx; --gy; --gx;
    vector<string> str;
    rep(i,h){
        string t;
        cin >> t;
        str.push_back(t);
    }
    vector<vector<int>> dist(h,vector<int>(w,INF));
    deque<P> que;
    dist[sy][sx] = 0;
    vector<int> dx{1,-1,0,0};
    vector<int> dy{0,0,1,-1};
    que.push_front({sx,sy});
    while(!que.empty()){
        int x = que.front().first;
        int y = que.front().second;
        que.pop_front();
        rep(i,4){
            int ix = x+dx[i], iy = y+dy[i];
            if(ix<0 || ix>=w || iy<0 || iy>=h) continue;
            if(dist[iy][ix] <= dist[y][x] || str[iy][ix]=='#') continue;
            dist[iy][ix] = dist[y][x];
            que.push_front({ix,iy});
        }
        for(int i=-2; i<=2; i++){
            for(int j=-2; j<=2; j++){
                int ix = x+i, iy=y+j;
                if(ix<0 || ix>=w || iy<0 || iy>=h) continue;
                if(dist[iy][ix] <= dist[y][x]+1 || str[iy][ix]=='#') continue;
                dist[iy][ix] = dist[y][x] + 1;
                que.push_back({ix,iy});
            }
        }
    }
    if(dist[gy][gx]==INF) dist[gy][gx] = -1;
    cout << dist[gy][gx] << endl;
    return 0;
}

Measured memory_bytes: 8564
#include <iostream>

int main()
{
	int  a = 1, N, K;
	std::cin >> N >> K;
	for (int i = 0;i < N;i++) {
		if (a * 2 <= a + K) {
			a = a * 2;
		}
		else {
			a = a + K;
		}

	}
	std::cout << a << std::endl;
    return 0;
}

Measured memory_bytes: 256
using System;

class Program
{

    static void Main(string[] args)
    {
        //縦4横13の配列すべてに0をいれて初期化
        int[,] Card = new int[4, 13];
        for (int j = 0; j < 4; j++)
        {
            for (int i = 0; i < 13; i++)
            {
                Card[j, i] = 0;
            }
        }
        int n = int.Parse(Console.ReadLine());
        //あったカードの場所に'\0'を代入
        for (int x = 0; x < n; x++)
        {
            String[] HaveCard = Console.ReadLine().Split(' ');
            int i = int.Parse(HaveCard[1]);
            i = i - 1;
            if (HaveCard[0]=="S")
                Card[0, i] = 20;
            else if (HaveCard[0]=="H")
                Card[1, i] = 20;
            else if (HaveCard[0]=="C")
                Card[2, i] = 20;
            else if (HaveCard[0]=="D")
                Card[3, i] = 20;
        }
        for (int j = 0; j < 4; j++)
        {
            for (int i = 0; i < 13; i++)
            {
                int ans = Card[j, i];
                if (ans == 0)
                {
                    if (j == 0)
                        Console.WriteLine("S" + " " + (i + 1));
                    else if (j == 1)
                        Console.WriteLine("H" + " " + (i + 1));
                    else if (j == 2)
                        Console.WriteLine("C" + " " + (i + 1));
                    else if (j == 3)
                        Console.WriteLine("D" + " " + (i + 1));
                }

            }
        }
    }
}


Measured memory_bytes: 17908
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.AGC_Challenge
{
    class _018_B
    {
        static void Main(string[] args)
        {
            Method(args);
            ReadLine();
        }

        static void Method(string[] args)
        {
            int[] nm = ReadInts();
            int n = nm[0];
            int m = nm[1];
            int[][] array = new int[n][];
            for(int i = 0; i < n; i++)
            {
                array[i] = ReadInts();
                for (int j = 0; j < array[i].Length; j++) array[i][j]--;
            }

            int bottom = 0;
            int top = n;
            while (bottom + 1 < top)
            {
                int mid = (bottom + top) / 2;

                bool[] used = new bool[m];
                bool can = true;
                while (true)
                {
                    int[] cnt = new int[m];
                    for(int i = 0; i < n; i++)
                    {
                        for(int j = 0; j < m; j++)
                        {
                            if (used[array[i][j]]) continue;

                            cnt[array[i][j]]++;
                            break;
                        }
                    }

                    if (cnt.Sum() < n)
                    {
                        can = false;
                        break;
                    }

                    if (cnt.Max() <= mid)
                    {
                        can = true;
                        break;
                    }

                    used[Array.IndexOf(cnt, cnt.Max())] = true;
                }

                if (can)
                {
                    top = mid;
                }
                else
                {
                    bottom = mid;
                }
            }

            WriteLine(top);
        }

        private static string Read() { return ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 17616
sum = input()

if len(sum) < 3:
    print('0')
else:
    last_2_digit = sum[-2:]
    upper_digit = sum[:-2]

    if last_2_digit == '00':
        print('1')
    else:
        required_num = (int(last_2_digit) - 1) // 5 + 1
        # print(upper_digit, last_2_digit, required_num)
        if int(upper_digit) >= required_num:
            print('1')
        else:
            print('0')


Measured memory_bytes: 3060
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long
#define ms(a,b) memset(a,b,sizeof(a))
using namespace std;

const int MAXN = 1e2 + 100;
const int INF = 0x3FFFFFFF;
const ll MOD = 1e9+7;

int color[MAXN][MAXN];
int a[MAXN * MAXN];

int main()
{
    int r, c;
    cin >> r >> c;
    //int pro = r * c;
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    int index = 1;
    int cnt = a[1];
    int num = 1;
    for(int i = 1; i <= r; i++)
    {
        for(int j = 1; j <= c; j++)
        {
            if(!cnt)
            {
//                if(index + 1 > n)
//                {
//                    for(int q = 1; q <= r; q++)
//                    {
//                        for(int k = 1; k <= c - 1; k++)
//                        {
//                            cout << color[q][k] << " ";
//                        }
//                        cout << color[q][c] << endl;
//                    }
//                    return 0;
//                }
//                else
//                {
                    cnt = a[++index];
                    num++;
//                    color[i][j] = num;
//                    cnt--;
//                }
            }
//            else
//            {
                color[i][j] = num;
                cnt--;
//            }
//            cout << index << endl;
        }
    }
    for(int q = 1; q <= r; q++)
    {
        if(q % 2)
        {
            //cout << "--" << endl;
            for(int k = 1; k <= c - 1; k++)
            {
                cout << color[q][k] << " ";
            }
            cout << color[q][c] << endl;
        }
        else
        {
            //cout << n << endl;
            for(int k = c; k >= 2; k--)
            {
                cout << color[q][k] << " ";
            }
            cout << color[q][1] << endl;
        }
    }
    return 0;
}


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

int main(int argc, char* argv[]) {
  int N, T, A;
  std::cin >> N >> T >> A;
  float f_current_best_temp = 10000000000.0;
  int best_idx = -1;
  for(int i = 0; i < N; i++) {
    int H;
    std::cin >> H;
    float f_current_temp = float(T) - float(H) * 0.006;
    if (std::abs(A-f_current_best_temp) > std::abs(A-f_current_temp)) {
      f_current_best_temp = f_current_temp;
      best_idx = i+1;
    }
  }
  std::cout << best_idx << std::endl;
  return 0;
}

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

int main() {
    int d;
    cin >> d;

    if(d == 25) {
        cout << "Christmas" <<endl;
    }
    if(d == 24) {
        cout << "Christmas Eve" <<endl;
    }
    if (d == 23) {
        cout << "Christmas Eve Eve" <<endl;
    }
    if (d == 22) {
        cout  <<"Christmas Eve Eve Eve" <<endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
int x[1000]; 
int main()
{
	int n,m,s,e;
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		scanf("%d%d",&s,&e);
		x[s]++;
		x[e]++;
	}
	for(int i=1;i<=n;i++)
		printf("%d\n",x[i]);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int dist[2][150000];
int N;
int u[2];
vector<int> paths[105000];

void dfs(int index, int now, int from) {
    //cerr << index << " " << now << " " << dist[index][now] << endl;
    for(auto to : paths[now]) {
        if(to == from) continue;
        dist[index][to] = dist[index][now] + 1;
        dfs(index, to, now);
    }
}
int ans;

void search(int now, int timer) {
    if(dist[0][now] >= dist[1][now]) {
        chmax(ans, dist[1][now]);
        return;
    }
    if(paths[now].size() == 1) {
        cerr << now << endl;
        chmax(ans, dist[1][now] - 1);
    }
    for(auto to : paths[now]) {
        if(dist[0][to] < dist[0][now]) continue;
        search(to, timer + 1);
    }
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    for(int i = 0; i < 2; i++) cin >> u[i];
    for(int i = 1; i <= N - 1; i++) {
        int a, b;
        cin >> a >> b;
        paths[a].push_back(b);
        paths[b].push_back(a);
    }
    dfs(0, u[0], -1);
    dfs(1, u[1], -1);
    for(int i = 1; i <= N; i++) {
    }
    search(u[0], 0);
    /*
    int ans = 0;
    for(int i = 1; i <= N; i++) {
        //cerr << dist[0][i] << " " << dist[1][i] << endl;
        //if(dist[0][i] >= dist[1][i]) continue;
        if(paths[i].size() == 1) continue;
        int now = dist[1][i];
        //if((dist[1][i] - dist[0][i]) % 2 == 1) now--;
        //cerr << i << endl;
        chmax(ans, now);
    }
    cout << ans << endl;
    */
   cout << ans << endl;
    return 0;
}


Measured memory_bytes: 13056
#include<iostream>
#include<string>
using namespace std;
int main(){
    string str;
    int sum=0;
    while(getline(cin,str)){
        sum=0;
        if(str=="0")
            break;
        for(int i=0;i<str.size();i++)
            sum+=str[i]-48;
        cout<<sum<<endl;
    }

    return 0;
}



Measured memory_bytes: 3140
#include<iostream>
using namespace std;
int main(){
  int N,Y; cin>>N>>Y;
  Y/=1000;
  for(int i=0;i<=N;i++){
    if(10*i>Y) break;
    for(int j=0;i+j<=N;j++){
      int k=N-i-j;
      if(10*i+5*j+k==Y){
        cout<<i<<' '<<j<<' '<<k<<endl;
        return 0;
      }
    }
  }
  cout<<"-1 -1 -1"<<endl;
  return 0;
}
        

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <iomanip>
#include <cmath>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
template<class T> inline void chmin(T& a, T b) {if (a>b) a=b; }
template<class T> inline void chmax(T& a, T b) {if (a<b) a=b; }
inline void print() { cout << endl; }
template <class Head, class... Tail> inline void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " "; print(forward<Tail>(tail)...);}
template <class T> inline void print(vector<T>& vec) { for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " "; } cout << endl;}
template <class T> inline void print(vector<vector<T>>& df) { for (auto& vec : df) { print(vec); }}
typedef long long ll;
const ll LINF = 1e18;
const int INF = 1e9;


int main() { 
    int A, B;
    cin >> A >> B;

    for(int i=1; i<=3; i++) {
        if ( (A*B*i) %2 == 1) {
            print("Yes");
            return 0;
        }

    }
    print("No");
    
    return 0;
}

Measured memory_bytes: 256
import itertools

N=int(input())
P=int("".join(input().split()))
Q=int("".join(input().split()))
A=[]
for i in range(N):
    A.append(str(i+1))
B=list(itertools.permutations(A))

k=0
while int("".join(B[k]))!=P:
    k+=1
j=0
while int("".join(B[j]))!=Q:
    j+=1
print(abs(k-j))


Measured memory_bytes: 8052
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7


#############
# Main Code #
#############

def rand_letter(size):
    ascii_original='programing'
    digits_original='01'

    digits='0123456789'
    ascii_lowercase='abcdefghijklmnopqrstuvwxyz'
    ascii_uppercase='ABCDEFGHIJKLMNOPQRSTUVWXYZ'

    # 好きなものを使ってね
    psuedo = ascii_original

    return ''.join([random.choice(psuedo) for i in range(size)])


S = input()
N_S = len(S)
T = input()
N_T = len(T)

dict_s = defaultdict(int)
dict_order = defaultdict(list)
for i in range(N_S):
    dict_s[S[i]] += 1
    dict_order[S[i]].append(i + 1)

dict_t = defaultdict(int)
for i in range(N_T):
    dict_t[T[i]] += 1

flag = True
for i in dict_t:
    if dict_s[i] == 0:
        flag = False
        break

if not flag:
    print(-1)
    exit()

now = dict_order[T[0]][0]
ans = [dict_order[T[0]][0]]

for i in range(1, N_T):
    index = bisect_right(dict_order[T[i]], now)
    if index == len(dict_order[T[i]]):
        now = dict_order[T[i]][0]
    else:
        now = dict_order[T[i]][index]
    ans.append(now)

cnt = 0
for i in range(1, N_T):
    if ans[i] <= ans[i - 1]:
        cnt += 1
print(cnt * N_S + ans[-1])

Measured memory_bytes: 72920