akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<cmath>
#include<random>
#include<set>
#include<queue>

using namespace std;

long long dp[3][100100] = {};
const long long INF = 1LL << 60;
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979

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

/**
* @fn
* 最大値を取ります.Vector<int>を渡すこと.
*/
long long int imax(vector<int> a) {
	int MAX = -10000000;
	for (int i = 0; i < a.size(); i++) {
		if (MAX < a.at(i)) MAX = a.at(i);
	}
	return MAX;
}

/**
* @fn
* 最小値を取ります.Vector<int>を渡すこと.
*/
long long int imin(vector<int> a) {
	int MIN = 1000000000;
	for (int i = 0; i < a.size(); i++) {
		if (MIN > a.at(i)) MIN = a.at(i);
	}
	return MIN;
}

/**
* @fn
* 自然数について、桁数を求める
*/
Int getDigit(Int num) {
	return (Int)(log10(num)) + 1;
}


int get2Digit(Int num) {
	int cnt = 0;
	while (num > 0) {
		if (num % 2 != 0) {
			return cnt;
		}
		cnt++;
		num /= 2;
	}
}

long long int absmin(vector<int> a, long long int b) {
	int mini = 100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (mini > abs(a.at(i) - b)) {
			mini = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}


long long int absmax(vector<int> a, long long int b) {
	int max = -100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (max < abs(a.at(i) - b)) {
			max = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}

int gcd(int a, int b)
{
	if (a < b) swap(a, b);
	if (b < 1) return -1;
	if (a % b == 0) return b;
	return gcd(b, a % b);
}

void haerobatya(int start, int end, char level) {
	if (start > end) swap(start, end);
	for (int i = start; i <= end; i++) {
		if (i < 100) {
			cout << "https://atcoder.jp/contests/abc0" << i << "/tasks/abc0" << i << "_" << level << endl;
		}
		else {
			cout << "https://atcoder.jp/contests/abc" << i << "/tasks/abc" << i << "_" << level << endl;
		}
	}
}

long long int cntmod(long long int warareru, long long int mod) {
	long long int i = 0;
	for (i = 0; true; i++) {
		if (warareru % mod == 0 && warareru >= mod) {
			warareru /= mod;
		}
		else {
			return i;
		}
	}
}

void ansYes(bool a) {
	if (a == true) cout << "Yes" << endl;
	else cout << "No" << endl;
}

void ansYES(bool a) {
	if (a == true) cout << "YES" << endl;
	else cout << "NO" << endl;
}


Int euclidean_gcd(Int a, Int b) {
	while (true) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}

typedef pair<int, int> pai;


//ここまでライブラリ
//ここから本文

int main() {
	int a, b, t;
	cin >> a >> b >> t;
	cout << t / a * b << endl;
}


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

int main() {
  
  int H, W;
  cin >> H >> W;
  
  string a, b, c;
  
  string null = "....................................................";
  
  for (int i = 1; i <= H; i++) {
    
    // (i-1)行、i行、(i+1)行の情報を取り出す
    
    if (H == 1) {
      a = null;
      cin >> b;
      b = "." + b + ".";
      c = null;
    }
    
    else {
    
      if (i == 1) {
        a = null;
        cin >> b >> c;
        b = "." + b + ".";
        c = "." + c + ".";
      }
    
      else if (i == H) {
        a = b;
        b = c;
        c = null;
      }
    
      else {
        a = b;
        b = c;
        cin >> c;
        c = "." + c + ".";
      }
    
    }
    
    string B = b;
    
    for (int j = 1; j <= W; j++){
      
      // Bのj番目を書き換える
      
      char x = B.at(j);
      
      if (x == '.') {
        
        int counter = 0;
        
        if (a.at(j-1) == '#') counter++;
        if (a.at(j) == '#') counter++;
        if (a.at(j+1) == '#') counter++;
        if (b.at(j-1) == '#') counter++;
        if (b.at(j+1) == '#') counter++;
        if (c.at(j-1) == '#') counter++;
        if (c.at(j) == '#') counter++;
        if (c.at(j+1) == '#') counter++;
        
        char y;
        y = '0' + counter;
        B.at(j) = y;
        
      }
      
    }
    
    string d = B.erase(0,1);
    string e = d.erase(W,1);
    
    cout << e << endl;
    
  }
  
}

Measured memory_bytes: 256
import Data.List

a1 = [4,6,9,11]

main = do
  [x,y] <- map read . words <$> getLine
  putStrLn $ solve x y

solve :: Int -> Int -> String
solve x y
  | tt x == tt y = "Yes"
  | otherwise = "No"

tt :: Int -> Int
tt 2 = 0
tt x
  | t == Nothing = 2
  | otherwise = 1
    where t = find (x==) a1





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

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define N 5010
#define INF 1000000000000000000LL
int n;
PII a[N];
ll f[N][2], g[N][2];

bool cmp(PII x, PII y) {
	return x.fi + x.se < y.fi + y.se;
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i ++)
		cin >> a[i].fi >> a[i].se;
	sort(a, a+n, cmp);
	reverse(a, a+n);
	// g = last
	for (int i = 0; i < n; i ++) f[i][0] = f[i][1] = INF;
	f[0][0] = 0;
	
	// n odd: has middle
	// n even: no middle
	for (int i = 0; i < n; i ++) {
		memcpy(g, f, sizeof f);
		for (int j = 0; j < n; j ++) f[j][0] = f[j][1] = INF;
		if (n%2 == 0) {
			for (int j = 0; j <= n/2; j ++) {
				// left
				if (j+1 <= n/2) {
					f[j+1][0] = min(f[j+1][0], g[j][0] + a[i].se + (ll)(a[i].fi + a[i].se)*j);
				}
				// right
				if (i-j+1 <= n/2) {
					f[j][0] = min(f[j][0], g[j][0] + a[i].fi + (ll)(a[i].fi + a[i].se)*(i-j));
				}
			}
		} else {
			for (int j = 0; j <= n/2; j ++) {
				// left
				if (j+1 <= n/2) {
					f[j+1][0] = min(f[j+1][0], g[j][0] + a[i].se + (ll)(a[i].fi + a[i].se)*j);
					f[j+1][1] = min(f[j+1][1], g[j][1] + a[i].se + (ll)(a[i].fi + a[i].se)*j);
				}
				// right
				if (i-j+1 <= n/2) {
					f[j][0] = min(f[j][0], g[j][0] + a[i].fi + (ll)(a[i].fi + a[i].se)*(i-j));
					f[j][1] = min(f[j][1], g[j][1] + a[i].fi + (ll)(a[i].fi + a[i].se)*(i-j));
				}
				// middle
				f[j][1] = min(f[j][1], g[j][0] + (ll)a[i].fi * (n/2) + (ll)a[i].se * (n/2));
			}
		}
	}
	
	cout << f[n/2][n%2] << endl;
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<map>

using namespace std;

string sa[200];

int main()
{
    char before = ' ';

    int N;
    cin >> N;

    string s = "";

    for(int i= 0;i < N; i++)
    {
        cin >> s;

        if(before == ' ')
        {
            before = s[0];
        }

        if(before != s[0])
        {
            cout << "No" << endl;
            return 0;
        }
        else
        {
            for(int h = 0; h < i; h++)
            {
                if(sa[h] == s)
                {
                    cout << "No" << endl;
                    return 0;  
                }
            }
            sa[i] = s;
            before = s[s.size() - 1];
        }
    }

    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 256
//ALDS1_5_C Recursion / Divide and Conquer - Koch Curve
#include <cstdio>
#include <cmath>

using namespace std;

struct Point
{
    double x;
    double y;
    Point(){}
    Point(int x1, int y1){
        x = x1;
        y = y1;
    }
    void print()
    {
        printf("%.8f %.8f\n",x,y);
    }

};

void kock(int n,Point p1, Point p2)
{
    if(n==0)
    {
        return;
    }

    Point s,t,u;
    double unit = M_PI / 180.0;
    s.x = (2*p1.x + p2.x)/3.0;
    s.y = (2*p1.y + p2.y)/3.0;
    t.x = (p1.x + 2*p2.x)/3.0;
    t.y = (p1.y + 2*p2.y)/3.0;
    u.x = (t.x-s.x)*cos(60.0*unit) - (t.y-s.y)*sin(60.0*unit) + s.x;
    u.y = (t.x-s.x)*sin(60.0*unit) + (t.y-s.y)*cos(60.0*unit) + s.y;

    kock(n-1,p1,s);
    s.print();
    kock(n-1,s,u);
    u.print();
    kock(n-1,u,t);
    t.print();
    kock(n-1,t,p2);
}

int main(void)
{
    int n;
    scanf("%d",&n);
    Point p1(0,0),p2(100,0);
    p1.print();
    kock(n,p1,p2);
    p2.print();
    return 0;
}


Measured memory_bytes: 2708
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <functional>
#include <queue>
//#include <stack>
#include <climits>
#include <map>
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
#define all(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
using namespace std;
typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> P;

ll n,k;

int main(){
    cin >> n >> k;
    ll res=0;
    if(k%2==1){
        res += (n/k)*(n/k)*(n/k);
    }else{
        res += (n/k)*(n/k)*(n/k);
        res += ((n+k/2)/k)*((n+k/2)/k)*((n+k/2)/k);
    }
    put(res);
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    
    int a,b,c;
    cin >>a>>b>>c;
    
    if(a > b){
        swap (a,b);
    }
    if(b > c){
        swap (b,c);
    }
    if(a > b){
        swap (a,b);
    }
    cout <<a<<" "<<b<<" "<<c<<endl;
}



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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;};
void qmod(ll &a,ll b){a=(a*b)%MOD;};
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x, ll y, ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}   


int main(){
  ll i,j,o;
  ll result=0,buf=0,buf1=0,buf2=0,buf3=0,buf4=0;
  bool judge = true;
  ll r,g;cin>>r>>g;
  cout<<2*g-r<<endl;


  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
	char c;
	cin >> c;
	cout << (char) (c+1) << endl;
	
	return 0;
}

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

using namespace std;

int main(){
    string s;
    cin >> s;
    string s2;
    for(int i = 0; i + 1 < s.size(); i++){
        if(s.substr(i, 2) == "BC"){
            i++;
            s2 += "D";
        }else{
            s2 += s[i];
        }
    }
    long long ans = 0, a = 0;
    for(int i = 0; i < s2.size(); i++){
        if(s2[i] == 'B' || s2[i] == 'C'){
            a = 0;
        }else if(s2[i] == 'D'){
            if(a){
                ans += a;
            }
        }else{
            a++;
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 776
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef pair<int, int> ii;


int main(){
  int N;cin>>N;
  vll A;
  for (int i=0;i<N;++i){
    ll a;cin>>a;A.push_back(a);
  }

  int cnt=0;
  int zero_flag=0;
  for (int i=0;i<N;++i){
    if(A[i]<0){cnt++;}
    if(A[i]==0){zero_flag=1;}
  }

  ll ans=0;
  for (int i=0;i<N;++i){
    ans+=abs(A[i]);
  }

  if(cnt%2==0|| zero_flag==1){
    cout << ans << endl;
    return 0;
  }

  ll abs_min=1e9;
  for (int i=0;i<N;++i){
    abs_min=min(abs_min, abs(A[i]));
  }
  cout << ans-2*abs_min << endl;
  return 0;
}

Measured memory_bytes: 1400
def inN():
    return int(input())
def inL():
    return list(map(int,input().split()))
def inNL(n):
    return [input().split() for i in range(n)]

f = inN()
if f >= 1800:
    print(1)
elif f >= 1600:
    print(2)
elif f >= 1400:
    print(3)
elif f >= 1200:
    print(4)
elif f >= 1000:
    print(5)
elif f >= 800:
    print(6)
elif f >= 600:
    print(7)
elif f >= 400:
    print(8)

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

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

    if (d == 0 && n < 100)
    {
        cout << n;
    }
    else if (d == 0 && n == 100)
    {
        cout << 101;
    }
    else if (d == 1 && n < 100)
    {
        cout << n * 100;
    }
    else if (d == 1 && n == 100)
    {
        cout << 10100;
    }
    else if (d == 2 && n < 100)
    {
        cout << n*100*100;
    }
    else if (d == 2 && n == 100) {
        cout << 1010000;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ms(x,y) memset(x, y, sizeof(x))
#define lowbit(x) ((x)&(-x))
#define sqr(x) ((x)*(x))
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

const LL MOD = 1e9+7;


LL qpow(LL a, LL b) {
    LL ret = 1;
    while(b) {
        if(b & 1) ret = ret * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return ret;
}

void run_case() {
    int n; cin >> n;
    vector<LL> a(n), inv(n);
    vector<int> idx(1e6+5);
    for(auto &x: a) cin >> x;
    for(int i = 0; i < n; ++i) {
        inv[i] = qpow(a[i], MOD-2);
        for(int j = 2; j*j <= a[i]; ++j) {
            int cnt = 0;
            while(a[i] % j == 0) {
                cnt++;
                a[i] /= j;
            }
            idx[j] = max(idx[j], cnt);
        }
        if(a[i] > 1) idx[a[i]] = max(idx[a[i]], 1);
    }
    LL lcm = 1;
    for(int i = 1; i <= 1e6; ++i) (lcm = (lcm * qpow(i, idx[i]))% MOD) %= MOD;
    LL ans = 0;
    for(int i = 0; i < n; ++i) {
        (ans += 1LL*lcm*inv[i] + MOD) %= MOD;
    }
    cout << (ans + MOD) % MOD;
}


int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cout.flags(ios::fixed);cout.precision(9);
    //int t; cin >> t;
    //while(t--)
    run_case();
    cout.flush();
    return 0;
}

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

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

  vector<int> num(100100);
  vector<int> odd(100100);
  vector<int> even(100100);

  //int num[100100]={};//,odd[100100]={},even[100100]={};

  for(int i=0;i<n;i++){
    cin >> num[i];
  }

  
  for(int l=0;l<n;l++) {
    int k=num[l];
    //cout << *even << endl;
    if(l%2==0) even[k]=even[k]+1;
    else odd[k]=odd[k]+1;
  }
  int odma=0,odmanum=0,evma=0,evmanum=0,odsec=0,evsec=0;

  for(int i=0;i<100001;i++){
    if(odma<odd[i]) {
      odma=odd[i];
      odmanum=i;
    }
    if(evma<even[i]){
      evma=even[i];
      evmanum=i;
    }
    //cout << odmanum << " " << evmanum << endl;
  }
  if(odmanum==evmanum){
    for(int i=0;i<100001;i++){
      if(i==odmanum) continue;
      
      if(odsec<odd[i]) odsec=odd[i];
      if(evsec<even[i]) evsec=even[i];
    }
    cout << n-max(odsec+evma,evsec+odma) << endl;
  }
    
  else{
    cout << (n/2-odma)+(n/2-evma) << endl;
  }
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    int N; cin >> N;
    string s[2];
    for(int i=0; i<2; i++) cin >> s[i];

    int mod = 1000000007;
    ll ans = 1;

    //1行前のタイプを格納する
    char pre_type;
    //checkする行のindexを格納する
    int pos;

    //0行目のタイプを見る
    if(s[0][0] == s[1][0]){
        ans *= 3;
        pre_type = 'A';
        pos = 1;
    }
    else{
        ans *= 6;
        pre_type = 'B';
        pos = 2;
    }

    //1~N-1行目までを見て、タイプに応じて場合の数を乗じていく
    while(pos < N){
        //タイプで場合分け
        if(s[0][pos] == s[1][pos]){
            if(pre_type == 'A') ans = (ans*2)%mod;
            else ans = (ans*1)%mod;
            pre_type = 'A';
            pos++;
        }
        else{
            if(pre_type == 'A') ans = (ans*2)%mod;
            else ans = (ans*3)%mod;
            pre_type = 'B';
            pos += 2;
        }
    }

    cout << ans << endl;
}

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

using namespace std;

typedef long long ll;

int main()
{
    int n,m,ans=0;
    cin >> n >> m;
    string s;
    for(int i=n; i<=m; i++)
    {
        s=to_string(i);
        if(s[0]==s[4]&&s[1]==s[3])
            ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  ll N;
  cin >> N;
  vector<ll> a(N+2);
  ll sum = 0;
  for(int i=1;i<=N;i++){
    cin >> a[i];
  }
  for(int i=1;i<=N+1;i++){
    sum += abs(a[i] - a[i-1]);
  }
  for(int i=1;i<=N;i++){
    ll now = sum - abs(a[i] - a[i-1]) - abs(a[i] - a[i+1]) + abs(a[i-1] - a[i+1]);
    cout << now << endl;
  }
  return 0;
}

Measured memory_bytes: 2048
#include <iostream>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
using namespace __gnu_pbds;

typedef tree<pair<long long int,long long int>,null_type,less<pair<long long int,long long int> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

void go()
{
    int ans=0;
    for(int i=0;i<5;i++)
    {
        int p;
        cin>>p;
        if(p == 0)
            ans=i+1;
    }
    cout<<ans;
}
int main()
{
    FIO;
    //int t;
    //cin>>t;
    //while(t--)
    go();
    return 0;
}



Measured memory_bytes: 3636
import java.util.Scanner;

// (1) ??????A????????°???????????????C????????°??§????????°???n???????????????(Scanner)
// (2) ??????A????????°???????????????B????????°??§????????°???m???????????????
// (3) ??????B????????°???????????????C????????°??§????????°???l???????????????
// (4) ??????A???????¬??????????([n] [m])?????¨?????????
// (5) ??????B???????¬??????????([m] [l])?????¨?????????
// (6) ??????C???????¬??????????([n] [l])?????¨?????????
// (7) n?????°???????????\?????????????????????
	// (7.1) m?????°???????????\?????????????????????
		// (7.1.1) ??°??????????????????
		// (7.1.2) ?????????????????°????????????A???????¬?????????????????´???????
// (8) m?????°???????????\?????????????????????
	//(8.1) l?????°???????????\?????????????????????
		// (8.1.1) ??°??????????????????
		// (8.1.2) ?????????????????°????????????B???????¬?????????????????´???????
// (9) ??????C????????°n?????°(i)???????????\?????????????????????
	// (9.1) ??????C????????°l?????°(j)???????????\?????????????????????
		// (9.1.1) ??????A??¨??????B??????????????????????????°m(k)???????????\?????????????????????
			// (9.1.1.1) ?????°productResult????????????A??¨??????B???????¬?????????????????´?????????°???????????????????????????????????£??\??????
			// (9.1.1.2) ??????C???productResult???????????????(+=)
		// (9.1.2) ?£???????¨???????????????¨?????????
		// (9.1.3) j == l??????????????????????????????
		// (9.1.4) ???????????\??????
	// (9.2) ???????????????
// (10) ???????????????
// (11) Scanner?????????????????????

public class Main {

	public static void main(String[] args) {
		int n = 0;
		int m = 0;
		int l = 0;

		Scanner scan = new Scanner(System.in);

		n = scan.nextInt();
		m = scan.nextInt();
		l = scan.nextInt();

		int[] [] matrixA = new int[n] [m];
		int[] [] matrixB = new int[m] [l];
		long[] [] matrixC = new long[n] [l];

		for (int i = 0; i < n; i++){
			for (int j = 0; j < m; j++){
				int numA = scan.nextInt();
				matrixA[i] [j] = numA;
			}
		}
		for (int i = 0; i < m; i++){
			for (int j = 0; j < l; j++){
				int numB = scan.nextInt();
				matrixB[i] [j] = numB;
			}
		}

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < l; j++) {
				for (int k = 0; k < m; k++) {
					int productResult = (matrixA[i] [k]) * (matrixB[k] [j]);
					matrixC [i] [j] += productResult;
				}
				System.out.print(matrixC[i] [j]);
				if (j == l - 1) {
					break;
				}
				System.out.print(" ");
			}
			System.out.println();
		}
		scan.close();
	}
}

Measured memory_bytes: 53608
// #include<bits/stdc++.h>
// using namespace std;
 
// typedef vector <int> vi;
// typedef pair< int ,int > pii;
// #define all(v) v.begin(),v.end()
// #define PB push_back
// #define T(val) while(val--)
// #define FIN for(i=0;i<n;i++)
// #define FIS for(i=0;i<s.length();i++)
// #define AIN for(i=0;i<n;i++){cin>>a[i];}
// #define F(i,k,n) for(i=k;i<n;i++)
// #define FG(i,k,n,x) for(i=k;i<n;i+=x)
// #define YES cout<<"YES\n"; 
// #define NO cout<<"NO\n"; 
// #define ll long long
// #define MOD 1000000007
// #define deb(x) cout << #x << "=" << x << endl;
// #define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl;
// #define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
// //sort(arr, arr+n, greater<int>()); For sorting in reverse order

// int solve(){
//   int i,n,m;
//   cin>>n>>m;
//   vector < int > DG[n],UG[n];
//   int x,y,z;
//   F(i,0,m){
//     cin>>x>>y>>z;
//     if(x==0){
//       UG[x].PB(y);
//       UG[y].PB(x);
//     }
//     if(x==1){
//       DG[x].PB(y);
//     }
//   }
//   iscyclic()
//   return 0;
// }
// int main(){
// fast
//   int t;
//   cin>>t;
//   T(t){
//     solve();
//   }
//   return 0;
// }
// cin>>t;

#include<bits/stdc++.h>
using namespace std;
 
typedef vector <int> vi;
typedef pair< int ,int > pii;
#define all(v) v.begin(),v.end()
#define PB push_back
#define T(val) while(val--)
#define FIN for(i=0;i<n;i++)
#define FIS for(i=0;i<s.length();i++)
#define AIN for(i=0;i<n;i++){cin>>a[i];}
#define F(i,k,n) for(i=k;i<n;i++)
#define FG(i,k,n,x) for(i=k;i<n;i+=x)
#define YES cout<<"YES\n"; 
#define NO cout<<"NO\n"; 
#define ll long long
#define MOD 1000000007
#define deb(x) cout << #x << "=" << x << endl;
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//sort(arr, arr+n, greater<int>()); For sorting in reverse order 
 
int solve(){
  int n;
  cin>>n;
  int a[n][3],i;
  for(i=0;i<n;i++){
    cin>>a[i][0]>>a[i][1]>>a[i][2];
  }
  ll dp[n][3];
  // dp[0][0]=a[0][0],dp[0][1]=a[0][1],dp[0][2]=a[0][2];
  dp[0][0] = 0, dp[0][1] = 0, dp[0][2] = 0;
  for(i=1;i<n;i++){
    dp[i][0] = max(dp[i-1][1]+a[i-1][1],dp[i-1][2]+a[i-1][2]);
    dp[i][1] = max(dp[i-1][0]+a[i-1][0],dp[i-1][2]+a[i-1][2]);
    dp[i][2] = max(dp[i-1][1]+a[i-1][1],dp[i-1][0]+a[i-1][0]);
  }
  i=n-1;
  ll ans=-1e9;
  ans=max(dp[i][0]+a[i][0],max(dp[i][1]+a[i][1],dp[i][2]+a[i][2]));
  cout<<ans<<"\n";
  return 0;
}
int main(){
fast
  int t=1;
  // cin>>t; 
  T(t){
    solve();
  }
  return 0;
}

Measured memory_bytes: 7140
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
#include <map>
#include <queue>
using namespace std;
using ll = long long;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[100001];
//char str[1010][1010];
//typedef pair<ll,ll> A;
//vector<A> pc;
//int ABS(int a){return max(a,-a);}
int rw[200001],lb[200001],lw[200001],rb[200001];
int main() {
  int n;
  string s;
  cin>>n>>s;
  lb[0]=0;lw[0]=0;
  rw[n-1]=0;rb[n-1]=0;
  for(int i=1;i<n;i++){
    if(s[i-1]=='#') {
      lb[i]=lb[i-1]+1;
      lw[i]=lw[i-1];
    }
    else {
      lb[i]=lb[i-1];
      lw[i]=lw[i-1]+1;
    }
  }
  for(int i=n-2;i>=0;i--){
    if(s[i+1]=='#') {
      rw[i]=rw[i+1];
      rb[i]=rb[i+1]+1;
    }
    else {
      rw[i]=rw[i+1]+1;
      rb[i]=rb[i+1];
    }
  }
  if(lw[n-1]==n-1&&s[n-1]=='.'){
    cout<<0;
    return 0;
  }
  if(lb[n-1]==n-1&&s[n-1]=='#'){
    cout<<0;
    return 0;
  }
  int ans=2000000;
  int tmp;
  for(int i=0;i<n;i++){
    if(s[i]=='#'){
      tmp=lb[i]+rw[i];
      if(rw[i]!=0&&rb[i]==0&&lw[i]==0) tmp=min(tmp,min(rw[i],lb[i]+1));
      else if(rw[i]!=0&&lb[i]==0) tmp=min(tmp,rw[i]);
      else if(rw[i]==0) tmp=min(tmp,min(lb[i],lw[i]));
      ans=min(ans,tmp);
    }
  }
  //cout<<s[6]<<lb[6]<<rw[6]<<lw[6]<<endl;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3716
#include <iostream>
#include <vector>
#include <algorithm>
#include <sstream>
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef pair<int, int> P;
typedef pair<int, bool> Q;

int main()
{
	string str = "";
	while (getline (cin, str ) && str != "0" ){
		stringstream ssn (str );
		int n;
		ssn >> n;	
		vector<P> score (n);		
		for (int i = 0; i < n; i++ ){
			
			getline (cin, str );
			stringstream ss (str );
			ss >> score[i].second;
			int m;
			vector<int> p;
			while (ss >> m ){			
				p.push_back (m );
			} // end while
			int s[21] = {0};
			int size = p.size();
			int k = 0;
			for (int j = 0; j < size; j++ ){
				s[k] = p[j];
				if (p[j] == 10 ){
					if (k % 2 == 0 && k < 18 ){
						k++;
					}
				} // end if
				k++;
			} // end for

			vector <Q> g(10);
			for (int j = 0; j < 10; j++ ){
				if (j != 9 ){		
					g[j].first = s[2*j] + s[2*j+1];
					if (s[2*j] == 10 ){
						g[j].second = true;
					}// end if
				}else{
					g[j].first = s[2*j] + s[2*j+1] + s[2*j+2];
				} // end if
			} // end for
			int sum = 0;
			for (int j = 0; j < 10; j++ ){
				int pos = 0;	
				pos += g[j].first;
				if (j != 9 && g[j].first == 10 ){
					if (g[j].second ){
						pos += (g[j+1].second ? 10 + s[2*(j+2)] : s[2*(j+1)] + s[2*(j+1)+1]);
					}else{
						pos += s[2*(j+1)];
					} // end if
				} // end if
				sum += pos;
			} // end for
			score[i].first = -sum;

		} // end for
		sort (ALL (score ) );
		for (int i = 0; i < n; i++ ){
			cout << score[i].second << ' ' << -score[i].first << endl;
		} // end for
	} // end loop
		
	return 0;
}

Measured memory_bytes: 0
n = int(input())
s = input()
alps = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
number = 0
ans = str()

for i in range(len(s)):
  alp = s[i]
  for j in range(26):
    if alps[j] == alp:
      number = (j + n) % 26
      ans += alps[number]
      
print(ans)


Measured memory_bytes: 3060
import collections
h,w,n=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
L=[]
for i in range(n):
  for j in range(3):
    for k in range(3):
      if 0<l[i][0]-j<h-1 and 0<l[i][1]-k<w-1:
        L.append((l[i][0]-j-1)*10**9+l[i][1]-k-1)
L=collections.Counter(L)
L2=list(L.values())
ans=[0 for i in range(10)]
for i in range(len(L2)):
  ans[L2[i]]+=1
ans[0]=(h-2)*(w-2)-len(L2)
for i in range(10):
  print(ans[i])

Measured memory_bytes: 137164
N = int(input())
S = []
for _ in range(N):
    S.append(input())
    
import collections
c = collections.Counter(S)
most = c.most_common()
answerlist = [most[0][0]]
i = 0
if len(most) > 1:
    while most[i][1] == most[i+1][1]:
        answerlist.append(most[i+1][0])
        i += 1
        if i == len(most)-1:
            break
sortanswer = sorted(answerlist)
for i in range(len(sortanswer)):
    print(sortanswer[i])

Measured memory_bytes: 49264
N, x, *a = map(int, open(0).read().split())
ans = 0

if a[0] > x:
    ans += a[0] - x
    a[0] = x

for i in range(N - 1):
    d = sum(a[i:i + 2]) - x
    if d > 0:
        ans += d
        a[i + 1] -= d
    
print(ans)

Measured memory_bytes: 14092
loop do
    n, q = gets.split.map &:to_i
    break if n == 0
    era = {}
    n.times do
        name, y, e = gets.split
        y, e = y.to_i, e.to_i
        era[name] =(e - y + 1 .. e)
    end 

    q.times do
        y = gets.to_i
        puts 'Unknown' if era.all? do |name, range|
            if range === y
                puts [name, y - range.first + 1] * ' ' 
                next false
            end
            next true
        end
    end 
end

Measured memory_bytes: 8832
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

typedef long long int ll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)

const ll MOD = 1000000007;

using namespace std;

int M[101][101];
int a[10001];

int main()
{
	int H, W, N;
	cin >> H >> W >> N;
	REP(i, N)
	{
		cin >> a[i];
	}

	int index = 0;
	REP(h, H)
	{
		REP(w, W)
		{
			while (a[index] == 0)
			{
				index++;
			}
			M[h][w] = index + 1;
			a[index]--;
		}
	}
	REP(h, H)
	{
		if (h % 2 == 1)
		{
			reverse(begin(M[h]), begin(M[h]) + W);
		}
		REP(w, W)
		{
			cout << M[h][w] << " ";
		}
		cout << endl;
	}
	return 0;
}

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

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

    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'B') {
            if (!ans.empty()) {
                ans.pop_back();
            }
        } else {
            ans.push_back(s[i]);
        }
    }

    cout << ans << endl;

    return 0;
}

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

int main(){
    int n;
    string s,t,ans="";
    cin >> n;
    cin >> s >> t;
    for(int i=0;i<n;i++){
        char s1,t1;
        s1 = s.at(i);
        t1 = t.at(i);
        //cout << s1 << " " << t1 << endl;
        ans += s1;
        ans += t1;
        //cout << "ans(" << i <<")=" << ans << endl;
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 256
from math import gcd

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]


def main():
    n = int(input())
    al = list(map(int, input().split()))
    als = [0]*(10**6+1)
    for a in al:
        als[a] += 1

    ps = primes(10**6)
    for p in ps:
        cnt = 0
        for i in range(p,10**6+1,p):
            cnt += als[i]
        if cnt >= 2:
            break
    else:
        print('pairwise coprime')
        exit() 

    c_gcd = al[0]
    for a in al[1:]:
        c_gcd = gcd(c_gcd,a)
    
    if c_gcd == 1:
        print('setwise coprime')
    else:
        print('not coprime')


    # no_flag = False
    # for a in al:
    #     for p in ps:
    #         if a%p == 0:
    #             if p in pset:
    #                 no_flag = True
    #                 break
    #             else:
    #                 pset.add(p)
    #     if no_flag:
    #         break
    # else:
    #     print('pairwise coprime')
    #     exit()

    # pset = set()
    # for p in ps:
    #     if al[0]%p == 0:
    #         pset.add(p)

    # for a in al[1:]:
    #     apset = set()
    #     for p in ps:
    #         if a%p == 0:
    #             apset.add(p)
    #     pset = pset&apset
    #     if len(pset) == 0:
    #         print('setwise coprime')
    #         break
    # else:
    #     print('not coprime')



if __name__ == "__main__":
    main()

Measured memory_bytes: 197276
#include <bits/stdc++.h>
using Int = int64_t;
using UInt = uint64_t;
using C = std::complex<double>;
#define rep(i, n) for(Int i = 0; i < (Int)(n); ++i)
#define guard(x) if( not (x) ) continue;
#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif

int main() {
   Int n;
   std::cin >> n;
   std::vector<std::vector<Int>> xss(n);
   rep(i,n) {
      xss[i].resize(10);
      rep(k,10) {
         std::cin >> xss[i][k];
      }
   }
   std::vector<std::vector<Int>> yss(n);
   rep(i,n) {
      yss[i].resize(11);
      rep(k,11) {
         std::cin >> yss[i][k];
      }
   }
   Int inf = (Int)1 << 53;
   Int res = -inf;
   rep(i,1<<10) {
      guard( i != 0 );
      std::vector<Int> zs(n);
      rep(k,10) {
         if( i & 1<<k ) {
            rep(j,n) {
               if( xss[j][k] == 1 ) {
                  zs[j] += 1;
               }
            }
         }
      }
      Int t = 0;
      rep(k,n) {
         t += yss[k][zs[k]];
      }
      res = std::max(res, t);
   }
   printf("%ld\n", res);
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 998244353;
const ll INF = 4611686018427387903;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main(){
	ll n; cin >> n;
	ll ans=0;
	for(int i=2;i<=sqrt(n);i++){
		if(n%i==0){
			int c=0, p=1;
			while(n%i==0){
				n/=i;
				c++;
				if(c==p){
					ans++;
					p++;
					c=0;
				}
			}
		}
	}
	if(n!=1) ans++;
	cout << ans << endl;
}


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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n,m,x;
  cin >> n>>m>>x;
  int toll;
  int left=0,right=0;
  rep(i,m) {
    cin >> toll;
    if(toll<x) left++;
    else right++;
  }
  cout << min(left, right) << endl;  
}


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

int main(){
  int n;
  cin >> n;
  
  int A[n];
  for(int i=0; i<n; i++){
    cin >> A[i];
  }
  
  int a, b, r, o=A[0];
  
  for(int i=0; i<n-1; i++){
    a=o;
    b=A[i+1];
    while (true){
      r=a%b;
      if (r==0) break;
      a = b; b = r;
    }
    o = min(a, b);
  }
  cout << o << endl;
}

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

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n)　for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}

int main()
{
    int n,a,b;
    cin >> n >> a >> b;
    if((b-a)%2 == 0)cout << "Alice" << endl;
    else cout << "Borys" << endl;  
}

Measured memory_bytes: 256
#include <iostream>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;

int main()
{
	double x1,y1,x2,y2;
	scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
	printf("%4lf\n",sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)));
	return 0;
	
}

Measured memory_bytes: 3200
import java.util.Scanner;
import java.util.Arrays;

public class Main {

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        int N=sc.nextInt();
        int K=sc.nextInt();
        if(N%K==0){
        System.out.println("0");
        }else{
            System.out.println("1");
        }
    }
}

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

int main()
{
	int n;
	cin >> n;
	string str;
	str.resize(n);
	for (int i = 0; i < n; i++) {
		cin >> str[i];
	}

	for(int i=0;;i++){
		if (str.find(to_string(i)) == -1) {
			cout << i << endl;
			break;
		}
	}

    return 0;
}

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

using namespace std;

#define pii pair < int, int >
#define fr first
#define sc second
#define mk make_pair

const int N = (int)2e5 + 7;

int n;
pii a[N];
int ans[N];

main() {    
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i].fr);
		a[i].sc = i;
	}
	sort(a + 1, a + n + 1);
	int mid1, mid2;
	mid1 = a[n / 2].fr;
	mid2 = a[n / 2 + 1].fr;
	int asd;
	for (int i = 1; i <= n; i++) {
		if (i <= n / 2) {
			asd = mid2;
		} else {
			asd = mid1;
		}
		ans[a[i].sc] = asd;
	}
	for (int i = 1; i <= n; i++) {
		printf("%d\n", ans[i]);
	}
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int_fast32_t i = 0; i < ((int_fast32_t)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int_fast32_t i = 1; i <= ((int_fast32_t)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int_fast32_t i = ((int_fast32_t)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int_fast32_t i = ((int_fast32_t)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;  // 2次元配列
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
//    cout << fixed << setprecision(15);

    i32 n, a, overs = 0; cin >> n;
    vi group(8);
    rep(i,n) {
        cin >> a;
        if(a < 400) ++group[0];
        else if(a < 800) ++group[1];
        else if(a < 1200) ++group[2];
        else if(a < 1600) ++group[3];
        else if(a < 2000) ++group[4];
        else if(a < 2400) ++group[5];
        else if(a < 2800) ++group[6];
        else if(a < 3200) ++group[7];
        else ++overs;
    }
    i32 cnt = 0;
    for(auto p : group) {
        if(p != 0) ++cnt;
    }
    cout << max((i32)1, cnt) << ' ';
    cout << cnt + overs << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 9223372036854775807;
const ll mininf = -9223372036854775807;
const ll nax = 2e5 + 5;

ll n, arr[nax], x, freq[nax], total, bl[nax], save, ans, before;
 
int main(){
	cin >> n;
	for (ll i = 0; i < n; i++){
		cin >> arr[i];
		freq[arr[i]]++;
	}
	for (ll i = 0; i < n; i++){
		if (bl[arr[i]] == 0){
			bl[arr[i]] = 1;
			save = freq[arr[i]] - 1;
			ans = save * (save + 1) / 2;
			total += ans;
		}
	}
	for (ll i = 0; i < n; i++){
		save = freq[arr[i]] - 1;
		ans = save * (save + 1) / 2;
		before = ans;
		save = freq[arr[i]] - 2;
		ans = save * (save + 1) / 2;
		cout << total - (before - ans) << '\n';
	}
}


Measured memory_bytes: 6272
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>
#include<map>

using namespace std;

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>

typedef vector<int> vec;
typedef vector<vec> mat;

const ll mod = 1000000007;

int main(){
    int n, u, v;
    cin >> n >> u >> v;
    u--; v--;
    vector<vector<int> > e(n);
    rep(i, n-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        e[a].push_back(b);
        e[b].push_back(a);
    }
    vector<int> du(n, -1), dv(n, -1);
    du[u] = 0; dv[v] = 0;
    queue<P> que_u, que_v;
    que_u.push(P(u, 0));
    que_v.push(P(v, 0));
    while(que_u.size() > 0){
        P p = que_u.front();
        que_u.pop();
        int s = p.first;
        int d = p.second;
        rep(i, e[s].size()){
            if(du[e[s][i]] != -1) continue;
            du[e[s][i]] = d + 1;
            que_u.push(P(e[s][i], d+1));
        }
    }
    while(que_v.size() > 0){
        P p = que_v.front();
        que_v.pop();
        int s = p.first;
        int d = p.second;
        rep(i, e[s].size()){
            if(dv[e[s][i]] != -1) continue;
            dv[e[s][i]] = d + 1;
            que_v.push(P(e[s][i], d+1));
        }
    }
    int ans = 0;
    rep(i, n){
        if(du[i] < dv[i]){
            ans = max(ans, dv[i]);
        }
    }
    // rep(i, n){
    //     cout << du[i] << " " ;
    // }cout << endl;
    // rep(i, n){
    //     cout << dv[i] << " " ;
    // }cout << endl;
    cout << ans - 1 << endl;

}

Measured memory_bytes: 9756
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(non_snake_case, unused_variables)]
fn main() {
    input!{
        N: i32,
        a: [f64; N],
    }
    let m = (a.iter().fold(0., |sum, &x| sum + x)/N as f64).round() as i32;
    println!("{}", a.iter().fold(0, |sum, &x| sum+(x as i32 - m)*(x as i32 - m)));
}

Measured memory_bytes: 4352
n = int(input())
t = list(map(int,input().split(" ")))
dic1 = {}
dic2 = {}
for i in range(n):
    v = t[i]
    if i % 2 == 1:
        if v in dic1:
            dic1[v] += 1
        else:
            dic1[v] = 1
    else:
        if v in dic2:
            dic2[v] += 1
        else:
            dic2[v] = 1


a = list(dic1.items())
b = list(dic2.items())
a.sort(key=lambda x:x[1])
b.sort(key=lambda x:x[1]) 

if a[-1][0] != b[-1][0]:
    m1 = a[-1][1]
    m2 = b[-1][1]

elif len(a) == 1 and len(b) == 1:
    m1 = a[-1][1]
    m2 = 0

elif  len(a) == 1:
    m1 = a[-1][1]
    m2 = b[-2][1]

elif len(b) == 1:
    m1 = a[-2][1]
    m2 = b[-1][1]

else:
    m = [ a[-1][1],a[-2][1],b[-2][1]]
    m.sort()
    m1 = m[-1]
    m2 = m[-2]

print(n - m1 - m2)

Measured memory_bytes: 62828
N=int(input())

for i in range(1,3501):
    for j in range(i,3501):
        if 4*i*j-N*i-N*j<=0:
            continue
        k=(N*i*j)/(4*i*j-N*i-N*j)
        if k>0 and k-(N*i*j)//(4*i*j-N*i-N*j)==0:
            print(i,j,int(k))
            exit()


                    
                    
                    

    




    
    
        



Measured memory_bytes: 40924
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner((System.in));
		int N = sc.nextInt();
		int K = sc.nextInt();
		int ans = 1;
		
		for (int i = 0; i < N; i++) {
			if (ans + K < ans * 2) {
				ans += K;
			} else {
				ans = ans * 2;
			}
		}
		
		System.out.println(ans);

		sc.close();
	}
}

Measured memory_bytes: 22608
#include<stdio.h>
#include<math.h>

struct Point { double x, y; };

void koch(int n, Point a, Point b) {
	if (n == 0) return;
	Point s, t, u;
	double th = M_PI * 60.0 / 180.0;

	s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
	s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
	t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
	t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
	u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
	u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

	koch(n - 1, a, s);
	printf("%.8f %.8f\n", s.x, s.y);
	koch(n - 1, s, u);
	printf("%.8f %.8f\n", u.x, u.y);
	koch(n - 1, u, t);
	printf("%.8f %.8f\n", t.x, t.y);
	koch(n - 1, t, b);
}

int main() {
	Point a, b;
	int n;

	scanf("%d", &n);

	a.x = 0;
	a.y = 0;
	b.x = 100;
	b.y = 0;

	printf("%.8f %.8f\n", a.x, a.y);
	koch(n, a, b);
	printf("%.8f %.8f\n", b.x, b.y);

	return 0;
}


Measured memory_bytes: 2732
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cctype>
#include <algorithm>
using namespace std;
typedef long long lint;
#define cout cerr
#define ni (next_num<int>())
template<class T>inline T next_num(){
	T i=0;char c;
	while(!isdigit(c=getchar())&&c!='-');
	bool flag=c=='-';
	flag?c=getchar():0;
	while(i=i*10-'0'+c,isdigit(c=getchar()));
	return flag?-i:i;
}
template<class T1,class T2>inline void apmax(T1 &a,const T2 &b){if(a<b)a=b;}
template<class T1,class T2>inline void apmin(T1 &a,const T2 &b){if(b<a)a=b;}
const int N=100010;
struct Node{
	int x,d;
	inline friend bool operator < (const Node &a,const Node &b){
		return a.d<b.d;
	}
}lst[N<<1];
int n,m,ls=0;
inline bool onedge(int x,int y){
	return x==0||x==n||y==0||y==m;
}
inline int makeid(int x,int y){
	if(x==0){
		return y;
	}else if(y==m){
		return x+m;
	}else if(x==n){
		return m+n+m-y;
	}else if(y==0){
		return m+n+m+n-x;
	}else assert(false);
}
int stk[N],ss=0;
int main(){
	n=ni,m=ni;
	for(int tot=ni;tot--;){
		int x1=ni,y1=ni,x2=ni,y2=ni;
		if(onedge(x1,y1)&&onedge(x2,y2)){
			int id=ls;
			lst[++ls]=(Node){id,makeid(x1,y1)};
			lst[++ls]=(Node){id,makeid(x2,y2)};
		}
	}
	sort(lst+1,lst+ls+1);
	for(int i=1;i<=ls;i++){
		if(ss&&stk[ss-1]==lst[i].x){
			ss--;
		}else{
			stk[ss++]=lst[i].x;
		}
	}
	puts(ss?"NO":"YES");
	return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#ifdef _DEBUG_
	#define debug(...) printf(__VA_ARGS__)
#else
	#define debug(...) (void)0
#endif
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
 
const int N_MAX = 1e5 + 10;
int arr[N_MAX];
bool used[N_MAX];
VI rev[N_MAX];
 
set<int> cyc;
int n, k, ans;
 
int dfs(const int &u) {
	int ret = 1;
	for(int v : rev[u]) {
		if(cyc.find(v) != cyc.end())
			continue;
		ret = max(ret, dfs(v)+1);
	}
	if(ret == k && arr[u] != 1) {
		ans ++;
		ret = 0;
	}
	return ret;
}
 
int weight[N_MAX];
 
int main() {
	scanf("%d%d", &n, &k);
	for(int i = 1; i <= n; i++) {
		scanf("%d", arr + i);
		rev[arr[i]].PB(i);
	}
	ans = (arr[1] == 1) ? 0 : 1;
	arr[1] = 1;
 
	for(int i = 1; i <= n; i++) {
		debug("#%d: start ans%d\n", i, ans);
		if(used[i])
			continue;
		int x = i;
		set<int> pass;
		while(!used[x]) {
			pass.insert(x);
			used[x] = true;
			x = arr[x];
		}
		if(pass.find(x) == pass.end())
			continue;
		int cnt = 0;
		cyc.clear();
		bool flag = false;
		for(int i = x; i != x || !flag; i = arr[i]) {
			flag = true;
			cnt++;
			cyc.insert(i);
		}
		debug("#%d cnt: %d\n", i, cnt);
		flag = false;
		for(int i = x; i != x || !flag; i = arr[i]) {
			flag = true;
			weight[i] = dfs(i);
		}
		if(i == 1)
			continue;
		flag = false;
		int st = x;
		for(int i = arr[x]; i != x; i = arr[i]) {
			if(weight[i] < weight[st])
				st = i;
		}
		int acu = weight[st];
		for(int i = arr[st]; i != st; i = arr[i]) {
			if(!weight[i]) {
				continue;
				acu = 0;
			} else {
				acu = max(acu+1, weight[i]);
				if(acu >= k) {
					ans ++;
					acu = 0;
				}
			}
		}
	}
	
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 17024