akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(a, b) << " " << max(0,a+b-n) << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

int main() {
    int n, t; cin >> n >> t;
    int cheep = INF;
    map<int, int> mp;
    rep(i, n) {
        int x; cin >> x;
        if (x<cheep) {
            cheep = x;
        } else {
            mp[-(x-cheep)]++;
        }
    }
    // for(const auto& m: mp) debug(m.fi, m.se);
    for(const auto& m: mp) {
        cout << m.second << endl;
        return 0;
    }
}

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

int main()
{
    string s, t;
    cin >> s >> t;

    s = s + s;
    int l = t.size();
    for (int i = 0; i < l; i++) {
        if (s.substr(i, l) == t)
            return cout << "Yes" << endl, 0;
    }
    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n,m;
  cin>>n>>m;
  vector<int> vec(n);
  for (int i=1;i<=n;i++){
  cin>>vec.at(i-1);
  }
  int sum=0;
  for (int i=1;i<=n;i++){
    sum +=vec.at(i-1);
  }
  int count=0;
  for (int i=1;i<=n;i++) {
    if (vec.at(i-1)*4*m>=sum){
      count++;
    }
  }
  if (count>=m) {
    cout<<"Yes"<<endl;
  } else {
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int mod = (1 ? 1e9+7 : 998244353);



int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	ll a, b, c, d, e, f, g, T;
	char z;
	cin >> z;
	z++;
	cout << z << endl;
}




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

using namespace std;

int main(){
    int w,h,x,y,r;
    cin >> w >> h >> x >> y >> r;
    
    if(x+r>w||x-r<0||y+r>h||y-r<0){
        cout << "No" << endl;
        return 0;
    }
    
    cout << "Yes" << endl;
    
    return 0;
}


Measured memory_bytes: 3092
<?php

fscanf(STDIN, "%d %d %d", $a, $b, $c);
printf("%s%s", compare($a, $b, $c), PHP_EOL);

function compare($a, $b, $c){
    if($a < $b && $a < $c){
        if($b < $c){
            return "Yes";
        }
        return "No";
    }
    return "No";
}

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

using namespace std;

const int NMAX = 2e5 +10;
typedef long long ll;
int a[NMAX];
int main(int argc, char const *argv[])
{
	int n;
	scanf("%d",&n);
	map<int,int>mp;
	for(register int i = 1;i <= n;i++)
		scanf("%d",a+i),mp[a[i]+i]++;
	ll ans = 0;
	for(register int i = 1;i <= n;i++)
		ans += mp[i-a[i]];
	printf("%lld\n",ans );
	return 0;
}

Measured memory_bytes: 21468
/*
      author : nishi5451
      created: 11.08.2020 22:37:25
*/

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


int main(){
    int k,x;
    cin >> k >> x;
    if(k*500 >= x) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int D = 60;
const int MAX_N = 200005;
int to[D][MAX_N];

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

	string str,s1;
	cin >> str;

	s1 = "...";

	if (str.size() > k) {
		str = str.substr(0, k) + s1;
	}

	cout << str;
}


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

int main() {
  int h, w, d, q;
  scanf("%d %d %d", &h, &w, &d);
  vector<pair<int, int>> c(h * w + 1);
  vector<vector<int>> m(d, vector<int>(1));
  for(int i = 0; i < h; i++) {
    for(int j = 0; j < w; j++) {
      int a;
      scanf("%d", &a);
      c[a] = {i, j};
    }
  }
  for(int i = 0; i < d; i++) {
    for(int j = i + 1 + d; j <= h * w; j += d) {
      int nm = m[i].back();
      nm +=
          abs(c[j].first - c[j - d].first) + abs(c[j].second - c[j - d].second);
      m[i].push_back(nm);
    }
  }
  scanf("%d", &q);
  vector<int> o(q);
  for(int i = 0; i < q; i++) {
    int l, r;
    scanf("%d %d", &l, &r);
    o[i] = m[(l - 1) % d][(r - 1) / d] - m[(l - 1) % d][(l - 1) / d];
  }
  for(int i = 0; i < q; i++) printf("%d\n", o[i]);
}

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

public class Main {
    private static final int MOD = 1_000_000_007;
    private static final String YES = "Yes";
    private static final String NO = "No";

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] A = new int[N];
        int[] B = new int[N];
        for (int i=0; i<N; i++) {
            A[i] = sc.nextInt();
            B[i] = sc.nextInt();
        }

        System.out.println(solve(N, A, B) ? YES : NO);
    }

    private static boolean solve(int N, int[] A, int[] B) {
        Job[] job = new Job[N];
        for (int i=0; i<N; i++) {
            job[i] = new Job(A[i], B[i]);
        }

        Arrays.sort(job, (o1, o2) -> o1.B - o2.B);

        int time = 0;
        for (int i=0; i<N; i++) {
            if (time <= job[i].B - job[i].A) {
                time += job[i].A;
            } else {
                return false;
            }
        }

        return true;
    }

    public static class Job {
        public int A;
        public int B;
        public Job(int a, int b) {
            this.A = a;
            this.B = b;
        }
    }
}

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

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    vector<unsigned long> A(N);
    copy_n(istream_iterator<unsigned long>(cin), N, A.begin());
    vector<unsigned long> pw;
    unsigned long x{0}, o{0};
    for(const auto& i : A){
        x ^= i;
        o |= i;
    }
    for(unsigned long i = 60; i--; )if(((~x & o) >> i) & 1)pw.push_back(i);
    for(auto& i : A)i &= ~x;
    unsigned long a{0};
    for(const auto& i : pw){
        auto it = partition(A.begin(), A.end(), [&i](auto a){return ~(a >> i) & 1;});
        auto t = A.back();
        if((t >> i) & 1){
            A.pop_back();
            if(a < (a ^ t))a ^= t;
            if(A.empty())break;
            for(auto& j : A)if((j >> i) & 1)j ^= t;
        }
    }
    cout << x + (a * 2) << endl;
    return 0;
}

Measured memory_bytes: 1152
def is_palindrome(s):
    h = len(s) // 2
    if len(s) % 2 == 0:
        if s[:h] == s[:h-1:-1]:
            return True
    else:
        if s[:h] == s[len(s):h:-1]:
            return True

s = input()
if is_palindrome(s) and is_palindrome(s[:(len(s)-1)//2]) and is_palindrome(s[(len(s)+3)//2-1:]):
    print('Yes')
else:
    print('No')

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
typedef long long LL;

void test_case(){
    
}

int main() {
    fastio
    LL n;
    cin >> n;
    LL a, b;
    cin >> a >> b;
    LL diff = abs(a-b) - 1;
    if(a == b){
        cout<<0<<endl;
    }
    else if(diff%2 == 1){
        diff = diff/2; diff++;
        cout<<diff<<endl;
    }
    else{
        LL c, d;
        c = min(a,b);
        d = max(a,b);
        if((c-1) <= (n-d)){
            if(diff != 0){
                diff--;
                diff = diff/2; diff++;
            }
            diff += (c);
            cout<<diff<<endl;
        }
        else{
            if(diff != 0){
                diff--;
                diff = diff/2; diff++;
            }
            diff += (n-d) + 1;
            cout<<diff<<endl;
        }
        // cout<<abs(a-b)<<endl;
    }
    
    
    
	return 0;
}






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

int main() {
    int n;
    string s;
    cin >> n >> s;
    ll r = 0, g = 0, b = 0;

    for(auto c:s) {
        if(c == 'R') ++r;
        else if(c == 'G') ++g;
        else ++b;
    } 
    
    ll total = r * g * b;
   
    int sub = 0;
    rep(i, n){
        for(int j = i+1; j < n; ++j){
            if(s[i] == s[j]) continue;            
            int k = 2*j - i;
            if(k >= n) continue;
            if(s[i] == s[k] || s[j] == s[k]) continue;
            
            ++sub;
            // cout << i << ' ' << j << ' ' << k << endl;
        }
    }
    cout << total - sub << endl;

    
}

Measured memory_bytes: 3600
n, k = map(int, input().split())
x = list(map(int, input().split()))
count = 1
machi = 0
machi_list = [0]
next_machi = x[machi] - 1
machi_dict = [0] * n
machi_dict[0] = 1
while True:
    if machi_dict[next_machi] == 1:
        break
    count += 1
    machi_dict[next_machi] = 1
    machi_list.append(next_machi)
    machi = next_machi
    next_machi = x[machi] - 1
z = 0
for i in range(0, count):
    if machi_list[i] == next_machi:
        z = i
        break
loop_machi_list = machi_list[z:]
if k < z:
    machi = machi_list[k] + 1
    print(machi)
else:
    k = k - z
    machi = loop_machi_list[k % len(loop_machi_list)] + 1
    print(machi)

Measured memory_bytes: 32384
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong(), b = sc.nextLong();
		sc.close();
		String ans[] = { "Positive", "Negative", "Zero" };
		int an = 0;
		long tmp = a * b;
		if (tmp <= 0)
			an = 2;
		else {
			if (a < 0) {
				tmp = b - a + 1;
				if (tmp % 2 != 0)
					an = 1;
			}
		}
		System.out.println(ans[an]);
	}

}


Measured memory_bytes: 22740
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
  
int main()
{
  int n;
  cin >> n;
  vector<pair<int, int>> p(n);
  for (int i = 0; i < n; i++)
    cin >> p[i].first >> p[i].second;
  sort(p.begin(), p.end());
  
  double ans = 0;
  do{
    for (int i = 0; i < n - 1; i++)
    {
      ans += sqrt(pow(p[i].first - p[i + 1].first, 2.0) + pow(p[i].second - p[i + 1].second, 2.0));
    }
  }while (next_permutation(p.begin(), p.end()));
  
  int d = 1;
  for (int i = 1; i <= n; i++)
    d *= i;
  cout << fixed << setprecision(10) << ans / d << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
int A;
int B;
int C;
scanf("%d",&A);
scanf("%d",&B);
scanf("%d",&C);
if(A>=B && A>=C){
  
        printf("%d",(10*A)+B+C);
    
}else if(B>=A && B>=C){
  printf("%d",(10*B)+A+C);
}else if(C>=B && C>=A){
  printf("%d",(10*C)+B+A);
}
     
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main(){
    char a[100],b[100];int i,j;
    scanf("%c%c%c",&a[0],&a[1],&a[2]);
    getchar();
    scanf("%c%c%c",&b[0],&b[1],&b[2]);
    if(a[0]==b[2]&&a[1]==b[1]&&a[2]==b[0])
        printf("YES");
    else
        printf("NO");
    return 0;
    }


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <array>
#include <cmath>
using namespace std;

int main()
{
    int num;
    cin >> num;
    int box[100];
    for(int i=0;i<num;i++){
        cin >> box[i];
    }
    int current[110][210];
    for(int i=0;i<num;i++){
        for(int j=0;j<=200;j++){
            current[i][j] = (box[i]-(j-100))*(box[i]-(j-100));
        }
    }
    int ans = 999999999;
    for(int i=0;i<=200;i++){
        int sum=0;
        for(int j=0;j<num;j++){
            sum += current[j][i];
        }
        if(sum<ans){
            ans = sum;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <stdlib.h>
using namespace std;

int main(void){
    int x,y;
    while (1){
        cin >> x >> y;
        if (x == 0 && y == 0) return 0;
        if (x < y)
        {
            cout << x << " " << y << endl;
        }
        else cout << y << " " << x << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
int main()
{
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    if(((a-b)<=d&&(b-c)<=d&&(a-b)>=-d&&(b-c)>=-d)||((a-c)<=d&&(a-c)>=-d))
    printf("Yes\n");
    else
        printf("No\n");
}

Measured memory_bytes: 1612
from sys import stdin
from sys import setrecursionlimit
from collections import Counter, deque, defaultdict
from bisect import bisect_left
setrecursionlimit(1000000)

INF = int(1e10)
MOD = int(1e9 + 7)

def input():
    return stdin.readline()[:-1]


def main():
    from builtins import int, map
    A, B, C, D = map(int, input().split())
    count = 0
    while True:
        C -= B
        if C <= 0:
            print("Yes")
            exit()
        A -= D
        if A <= 0:
            print("No")
            exit()


if __name__ == '__main__':
    main()

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

using namespace std;

#define topper top //XDDDDDDD

#define mp make_pair
#define pb push_back
#define db(x) cerr << #x << " == " <<  x << endl;
#define _ << " " <<

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;

const long double EPS = 1e-9;
const int N=1e5+5;
const int MOD=1e9+7;
const int INF=0x3f3f3f3f;

ll x, y;

int main(){
  scanf("%lld %lld", &x, &y);
  if(x % y == 0) printf("-1\n");
  else printf("%lld\n", x*(y-1));

	return 0;
}



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

int students[10001][800] = {};
int numlogin[10001] = {};
int sum[10001][800]={};

int main(){

  while(1){
    int N,M,r;
    cin >> N >> M;
    if(!N and !M) break;
    cin >> r;

    memset(students,0,sizeof(students));
    memset(numlogin,0,sizeof(numlogin));
    memset(sum,0,sizeof(sum));

    // ?¨????
    for(int i=0; i<r; i++){ // 1000
      int t,n,m,s;
      cin >> t >> n >> m >> s;
      t -= 540;
      if(s == 0) { // ?????°??¢??????
	numlogin[m]--;
	if(numlogin[m] == 0){
	  for(int i=t-1; students[m][i] != 1 and t>=0; i--){ // 1000
	    students[m][i] = 1;
	  }
	}
      }
      else{ // ?????°??????
	numlogin[m]++;
	if(numlogin[m] == 1)
	  students[m][t] = 1;
      }
    }

    // ?´???????
    for(int i=1; i<=M; i++){ // 100000
      for(int j=1; j<=720; j++){ // 1000
	sum[i][j] = sum[i][j-1] + students[i][j]; 
      }
    }

    // ??????
    int  q;
    cin >> q;
    for(int i=0; i<q; i++){
      int ts,te,id;
      cin >> ts >> te >> id;
      ts -= 540;
      te -= 540;
      cout << sum[id][te-1] - sum[id][ts] + students[id][ts] << endl;
    }
  }
}

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

int main()
{
	int n,k;
	cin >> n >> k;
	vector<int> a(n);
	for (int q = 0; q < n; q++)
	{
		cin >> a[q];
	}
	bool dp[k+1];
	for (int q = 0; q <= k; q++)
	{
		dp[q] = false;
		for (int w = 0; w < n && q-a[w] >= 0; w++)
		{
			if (!dp[q-a[w]])
			{
				dp[q] = true;
				break;
			}
		}
	}
	if (dp[k])
	{
		cout << "First\n";
	}
	else
	{
		cout << "Second\n";
	}
	return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		String str = sc.next();

		int left = 0;
		int addTop = 0;
		for(int i = 0; i < n; i++){
			char c = str.charAt(i);

			if(c == '('){
				left++;
			}
			else {
				if(left == 0){
					addTop++;
				}
				else{
					left--;
				}
			}
		}

		for(int i = 0; i < addTop; i++){
			str = '(' + str;
		}

		for(int i = 0; i < left; i++){
			str += ')';
		}

		System.out.println(str);
	}

}



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

int main() {
	int N;
	cin >> N;
	string ans;
	do {
		if (0 < N) ans += to_string(N % 2);
		else {
			ans += to_string(-N % 2);
			N--;
		}
	} while (N /= -2);
	reverse(ans.begin(), ans.end());
	cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long int
#define ull unsigned long long int
#define getFaster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define rev(i,n,init) for(int i=n;i>=init;i--)
#define MAXN 1200005
#define MOD 1000000007
#define f first
#define s second
#define endl '\n'
#define pii pair<int,int>
#define precise cout<<fixed<<setprecision(6)
using namespace std;
const double PI = atan(1.0)*4;
const int64_t INF=100000000000000003;
const int32_t LOG=21;
const int BIG=pow(2,20);
int arr[300005];
int cnt[300005];
int bounds[300005];
vector<int> v;
int find(int x)
{
   int l=0,r=v.size()-1;
   int ans=v.size();
   while(l<=r)
   {
      int mid=(l+r)>>1;
      if(v[mid]<x)
      {
         l=mid+1;
      }
      else
      {
         ans=min(ans,mid);
         r=mid-1;
      }  
   }
   return ans-1; 
}
int pref[300005];
int32_t main(){
         getFaster;
         int n;
         cin>>n;
         rep(i,1,n+1)
         {
           cin>>arr[i];
           cnt[arr[i]]++;
         }
         rep(i,1,n+1)
         {
           if(cnt[i]!=0)v.push_back(cnt[i]);
         }
         sort(v.begin(),v.end());
         rep(i,1,n+1)
         {
             int x=find(i);
             bounds[i]=x;
         }
         pref[0]=v[0];
         rep(i,1,v.size())pref[i]=pref[i-1]+v[i];
         rep(k,1,n+1)
         {
             int l=1,r=n/k;
             int ans=0;
             while(l<=r)
             {
                int mid=(l+r)>>1;
                int cur=bounds[mid];
                int val=v.size()-cur-1;
                if(cur!=-1)val+=(pref[cur]/mid);
                if(val>=k){ans=max(ans,mid);l=mid+1;}
                else r=mid-1;
             }
             cout<<ans<<endl; 
         }
         return 0;
}

Measured memory_bytes: 14316
#include<stdio.h>
#include<map>
#include<queue>
#include<algorithm>
#include<string>
using namespace std;
#define maxn 10
struct my
{
    int tu[10];
    int space;
    int  ans;
    bool operator <(const my &p)const{
    for (int i=0;i<9;i++)
        {
            if(tu[i]==p.tu[i]) continue;
        return tu[i]>p.tu[i];
        }
        return false ;
    }
};
bool is(my s)
{
    for (int i=0;i<9;i++)
        if(s.tu[i]!=(i+1)) return false;
    return true;
}
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};
//char dir[]={'u','l','d','r'};
int bfs(my s)
{
    queue<my>Q;
    map<my,bool>V;
    s.ans=0;
    Q.push(s);
    V[s]=true;
    my u,v;

    while(!Q.empty())
    {
        u=Q.front();
        Q.pop();
        if(is(u)) return u.ans;
        int sx=u.space/3;
        int sy=u.space%3;
        for (int i=0;i<4;i++)
        {
            int tx=sx+dx[i];
            int ty=sy+dy[i];
            if(tx<0||ty<0||tx>=3||ty>=3) continue;
            v=u;
            swap(v.tu[u.space],v.tu[tx*3+ty]);
            v.space=tx*3+ty;
            if(!V[v])
            {
                V[v]=true;
                v.ans++;
                Q.push(v);
            }
        }
    }
}
int main()
{
    my in;
    for (int i=0;i<9;i++)
    {
        scanf("%d",&in.tu[i]);
        if(in.tu[i]==0){
            in.space=i;
            in.tu[i]=9;
        }
    }
    int sum=bfs(in);
    printf("%d\n",sum);
    return 0;
}

Measured memory_bytes: 20196
#!/usr/bin/env python3
import sys


def solve(A: int, B: int):
    if A <= B*2:
        print(0)
    else:
        print(A-B*2)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(void) {
	int a, b;
	cin >> a >> b;
	int sum = a;
	if (b == 1) { cout << 0 << endl; return 0; }
	for (int i = 1;; i++) {
		if (sum >= b) {
			cout << i << endl;
			break;
		}
		sum += (a - 1);
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <queue>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct TEMP_OMAZINAI_ { TEMP_OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } TEMP__omazinai_instance__;
#define INF ((1LL<<61) + (1<<29))
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
ll my_gcd(ll a, ll b) { return b ? my_gcd(b, a%b) : a; };
void TEMP_INPUT_IMPL_() {};
template <class T, class... Args> void TEMP_INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; TEMP_INPUT_IMPL_(args...); }
void TEMP_OUTPUT_IMPL_() {};
template <class T, class... Args> void TEMP_OUTPUT_IMPL_(T dest, Args... args) { cout << dest << (sizeof...(Args) ? " " : ""); TEMP_OUTPUT_IMPL_(args...); }
#define in(type, ...) type __VA_ARGS__; TEMP_INPUT_IMPL_(__VA_ARGS__)
#define in_v(type, name, cnt) vector<type> name(cnt); loop(i, cnt) cin >> name[i];
#define sort_v(v) std::sort(v.begin(), v.end())
#define unique_v(v) v.erase(std::unique(v.begin(), v.end()), v.end()) //必ずソート後に実行
#define out(...) (TEMP_OUTPUT_IMPL_(__VA_ARGS__), std::cout<<std::endl)
#define set_fix(x) ((std::cerr<<std::fixed<<std::setprecision(x)),(std::cout<<std::fixed<<std::setprecision(x)))
//小さい方に寄る
#define space_op(x, y, a, b, c) ([](auto x_, auto y_, auto a_, auto b_, auto c_){if(x_<y_)return a_;if(x_>y_)return c_;return b_;}(x,y,a,b,c))
#define space_out(x, y, a, b, c) out(space_op(x, y, a, b, c))

// ^^^ Template ^^^ //


int main() {
	in(ll, N, K);
	in_v(ll, A, N);
	sort_v(A);
	ll Am = A.back();
	ll Ag = A.back();
	loop(i, N - 1)
		Ag = my_gcd(Ag, A[i]);
	cerr << "gcd = " << Ag << endl;
	cout << (K % Ag || K > Am ? "IMPOSSIBLE" : "POSSIBLE") << endl;
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  re0 x=0,f=1;rec c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
inline void read(rel &x){
  x=0;re0 f=1;rec c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  x=f?x:-x;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return pc(48);
  if (x<0) x=-x,pc('-');
  re0 bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  }
inline char fuhao(){
  rec c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;

int main(){
string a,b;
cin>>a>>b;
for (re0 i=0;i<=999;++i){
  if (i*i==stol(a+b)) return puts("Yes"),0; 
  }puts("No");
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)


void solve(long long N, long long M){
    if(N*N <= M){
        for(ll i= N; i*i <= M; i++){
            if(M% i == 0){
                cout << M/i << endl;
                return;
            }
        }
    }
    ll ans = 0;
    for(ll i=1; i<= M/N; i++){
        if(M%i == 0){
            ans = max(ans, i);
        }
    }
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    solve(N, M);
    return 0;
}


Measured memory_bytes: 256
import sys
from itertools import permutations
input = sys.stdin.readline
N, M = map(int,input().rstrip().split())
node = []
for _ in range(M):
  a,b = map(int,input().rstrip().split())
  node.append((a,b))
  node.append((b,a))
ans = 0
for p in permutations(range(1,N+1)):
  flag = True
  if p[0] != 1:
    continue
  for i in range(N-1):
    if (p[i],p[i+1]) not in node:
      flag = False
  if flag:
    ans += 1
print(ans)

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e19;
//const int INF=(1<<30);


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

  int ans=0;
  ans += (x / 500) * 1000;
  x %= 500;
  ans += (x/5)*5;

  cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,from,n) for(int i = from; i < n; i++)
#define mreps(i,from,n) for(int i = from; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
typedef long long ll;
typedef pair<ll, ll> P;
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; }
ll MOD = 1000000007;

void solve()
{	
	string s; cin >> s;
	int n = sz(s);
	vector<int> r(n);
	int x = 1;
	rep(i, n)
	{
		r[i] = x;
		x *= 10;
		x %= 13;
	}
	vector<vector<ll>> dp(n+1,vector<ll>(13, 0));
	dp[0][0] = 1;
	rep(i, n)
	{
		rep(j, 13)
		{
			if(s[i] == '?')
			{
				rep(k, 10)
				{
					int next = (j + k * r[n-(1+i)]) % 13;
					dp[i + 1][next] += dp[i][j]; 
				}
			}
			else
			{
				int next = (j + (int)(s[i]-'0') * r[n-(1+i)]) % 13;
				dp[i + 1][next] += dp[i][j];
			}
		}
		rep(j, 13)dp[i+1][j] %= MOD;
	}
	cout << dp[n][5] << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 14032
#include<cstdio> 
#include<algorithm>
#include<cstring>
#include<cmath>
#include<set>
#include<map>
using namespace std;
#define fo(i,j,k) for(i=j;i<=k;i++)
#define fd(i,j,k) for(i=j;i>=k;i--)
#define cmax(a,b) (a=(a>b)?a:b)
#define cmin(a,b) (a=(a<b)?a:b)
typedef long long ll;
const int N=1e6+5,M=2e6+5,mo=1e9+7;
ll i,n,m,a[N],d[N],f[N],x;
int main()
{
    scanf("%lld %lld",&n,a);
    fo(i,1,n)
    {
        scanf("%lld",d+i);
        a[i]=min(a[i-1],abs(a[i-1]-d[i]));
    }
    f[n+1]=1;
    fd(i,n,1)
    {
        f[i]=f[i+1];
        if (d[i]<f[i]*2) f[i]+=d[i];
    }
    scanf("%lld",&m);
    fo(i,1,m)
    {
        scanf("%lld",&x);
        if (a[x-1]>=f[x+1]) printf("YES\n");
        else printf("NO\n");
    }
}


Measured memory_bytes: 18304
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

class Combination {
public:
    vector <ll> fac, inv, fiv;

    Combination(int N) : fac(N + 1), inv(N + 1), fiv(N + 1) {
        fac[0] = inv[0] = fiv[0] = fac[1] = inv[1] = fiv[1] = 1;
        for (ll i = 2; i <= N; i++) {
            fac[i] = fac[i - 1] * i % MOD; // n!
            inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD; // n^-1
            fiv[i] = fiv[i - 1] * inv[i] % MOD; // (n!)^-1
        }
    }

    ll C(ll n, ll k) {
        if (k < 0 || n < k) return 0;
        return fac[n] * fiv[k] % MOD * fiv[n - k] % MOD;
    }

    ll P(ll n, ll k) {
        if (k < 0 || n < k) return 0;
        return fac[n] * fiv[n - k] % MOD;
    }

    ll H(ll n, ll k) {
        if (n == 0 && k == 0) return 1;
        return C(n + k - 1, k - 1);
    }
};

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

    int n;
    cin >> n;

    vector <ll> c(n);
    for (int i = 0; i < n; i++) cin >> c[i];

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

    Combination com(200005);

    vector <ll> two(n * 2, 1);
    for (int i = 1; i < 2 * n; i++) {
        two[i] = two[i - 1] * 2 % MOD;
    }

    ll tmp = 1;
    ll ans = 0;
    for (int i = n - 1; i >= 0; i--) {
        ll hoge = c[i] * 2 % MOD * two[n + i - 1] % MOD;
        ans = (ans + hoge * tmp % MOD) % MOD;
        tmp = (2 * tmp + two[n - i - 1]) % MOD;
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 9600
X, N = map(int, input().split())#
p = map(int, input().split())
p = list(p)
tmp = X
Y = X
tmp1 = 0
tmp2 = 0
if X not in p:
  tmp1 = X
for i in range(N):
  if X not in p:
    tmp1 = X
  else:
    X = X + 1
  if Y not in p:
    tmp2 = Y
  else:
    Y = Y - 1
if abs(tmp1 - tmp) >= abs(tmp2 - tmp):
  print(tmp2)
else:
  print(tmp1)
  

Measured memory_bytes: 9196
#include<bits/stdc++.h>
        using namespace std;
        #define int long long

        

        int32_t main()
        
        {

                #ifndef ONLINE_JUDGE
                freopen("input.txt", "r", stdin);
                freopen("output.txt", "w", stdout);
                #endif

                    
                int s,w;

                cin>>s>>w;

                if(w>=s)
                    cout<<"unsafe";

                else   
                    cout<<"safe";

               




        }


Measured memory_bytes: 3632
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	@SuppressWarnings("unused")
	public static void main(String[] args) throws IOException {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt(); // 県の個数
		int m = in.nextInt(); // 市の個数

		// 県、年でソート
		PriorityQueue<City> city = new PriorityQueue<>(m, new Comparator<City>() {
			@Override
			public int compare(City o1, City o2) {
				if ( o1.pref != o2.pref ) {		// 県でソート
					return o1.pref - o2.pref;
				} else {						// 同じ県の時は年でソート
					return o1.year - o2.year;
				}
			}
		});
		for ( int id = 1; id <= m; id++ ) {
			city.add(new City(id, in.nextInt(), in.nextInt()));
		}

		// 県ごとに年でナンバー付けしてidでソート
		String citycode[] = new String[m + 1];
		int p = 0;
		int num = 0;
		while ( city.size() > 0 ) {
			City c = city.poll();
			// 新出の県の場合
			if ( p != c.pref ) {
				p = c.pref;
				num = 1;
			} else {
				num++;
			}
			citycode[c.id] = String.format("%06d%06d", c.pref, num);
			// System.out.println("id:" + c.id + " pref:" + c.pref + " year:" + c.year);
		}

		PrintWriter pw = new PrintWriter(System.out);
		for ( int i = 1; i<=m; i++ ) {
			pw.println(citycode[i]);
		}
		pw.flush();
		in.close();
	}
}

class City {
	int	id		= 0;
	int	pref	= 0;
	int	year	= 0;
	public City(int id, int pref, int year) {
		this.id = id;
		this.pref = pref;
		this.year = year;
	}
}


Measured memory_bytes: 137252
#include <algorithm>
#include <iostream>
#include <vector>

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;
}

vector<vector<int>> friends;
vector<vector<int>> blocks;

void solve(const int cur, const int current_turn, vector<int> &acc, vector<int> &visited, const int N) {
    if (visited[cur] > 0) return;
    visited[cur] = current_turn;
    acc.push_back(cur);
    for (auto &next : friends[cur]) {
        if (visited[next] == 0) {
            solve(next, current_turn, acc, visited, N);
        }
    }
}

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

    friends.resize(N);
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        friends[a].push_back(b);
        friends[b].push_back(a);
    }

    blocks.resize(N);
    for (int i = 0; i < K; i++) {
        int c, d;
        cin >> c >> d;
        c--;
        d--;
        blocks[c].push_back(d);
        blocks[d].push_back(c);
    }

    vector<int> ans(N, 0);
    vector<int> visited(N, 0);
    int current_turn = 0;
    for (int i = 0; i < N; i++) {
        if (visited[i] == 0) {
            current_turn++;
            vector<int> visited_vs;
            solve(i, current_turn, visited_vs, visited, N);
            for (auto &v : visited_vs) {
                ans[v] = (int) visited_vs.size();
            }
        }
    }

    for (int i = 0; i < N; i++) {
        ans[i]--; // remove myself
        ans[i] -= friends[i].size(); // already friends
        for (auto &v : blocks[i]) {
            if (visited[v] == visited[i]) {
                ans[i]--;
            }
        }
    }

    cout << ans[0];
    for (int i = 1; i < N; i++) {
        cout << " " << ans[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 14020
#include <bits/stdc++.h>
using namespace std;
 
int main() {

  int N,A;
  cin >> N >> A;
 
  if (N/500 == 0) {
    cout << "Yes" << endl;
  }
  
  else if(N%500 > A){
    cout << "No" << endl;
  }
  
  else{
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using loop = int;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(loop (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(loop (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(loop (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(loop (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    string s; cin >> s;
    map<char, bool> m;
    each(c, s)m[c] = true;
    
    if (s.length() < 26) {
        FOR(i, 0, 26)if (!m[char('a' + i)]) {
            cout << s << char('a' + i) << "\n";
            break;
        }
    }
    else {
        rFOR(i, 0, 26) {
            FOR(j, s[i] - 'a', 26)if (!m[char('a' + j)]) {
                s.back() = char('a' + j);
                cout << s << "\n";
                return 0;
            }
            m[s.back()] = false;
            s.pop_back();
        }
        cout << "-1\n";
    }
}

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

typedef pair<int,int> P;

int main(){
    bool ok = true;
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i){
        int x;
        cin >> x;
        if (x%2 == 0){
            if (x%3 != 0 && x%5 != 0){
                ok = false;
            }
        }
    }
    if (ok) cout << "APPROVED" << "\n";
    else cout << "DENIED" << "\n";
}

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

const int inf = 1e9;
const ll linf = 1e18;

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

    string s, t; cin >> s >> t;
    cout << t << s << endl;
    return 0;
}

Measured memory_bytes: 256
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
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;}
template<class T>inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T>inline T lcm(T a,T b){return a*b/gcd(b,a%b);}

int N,i,a,b,ans,cnt,t;
vector<int> A,B;
inline void solve(){
  IN(N);
  A.resize(N);
  INS(i,N,A);
  while(true){
    sort(ALL(A));
    B.pb(A[0]);
    FOR(i,1,N){
      t=A[i]%A[0];
      if(t){
        B.pb(t);
      }
    }
    if(B.size()==1){
      ans=B[0];
      break;
    }
    cnt=0;
    REP(i,B.size()){
      if(B[i]==0)cnt++;
      else {
        ans=B[i];
      }
    }
    if(cnt==N-1)break;
    A=B;
    B.clear();
  }
  OUT(ans);



}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


Measured memory_bytes: 1276
#include<stdio.h>
int main(){
  int unused __attribute__((unused));
  long long N, K, t;
  unused = scanf("%lld %lld", &N, &K);

  t = N%K;
  if(t < (K-t)) printf("%lld", t);
  else printf("%lld", K-t);

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int i,j,k,a,n;
char s[200200];
long long r;
int main() {
  scanf("%s",s);
  n=strlen(s);
  for (i=0; i<n; i++) if (s[i]=='A') {
    for (j=i; j<n && s[j]=='A'; j++);
    a+=j-i;
    for (k=j; k+1<n && s[k]=='B' && s[k+1]=='C'; k+=2);
    if (k>j) {
      r+=a*((k-j)/2LL);
      i=k-1;
    } else {
      a=0; i=j;
    }
  } else a=0;
  printf("%lld\n",r);
  return 0;
}


Measured memory_bytes: 384
# 参考：https://atcoder.jp/contests/dp/submissions/5316523

n, W = map(int, input().split())
w, v = [0] * n, [0] * n
for i in range(n):
    w[i], v[i] = map(int, input().split())

import numpy as np

ndp = np.zeros(W + 1, dtype=np.int64)

# print(ndp)

for w, v in zip(w, v):
    #    print(w,v,ndp[:-w] + v)
    #    print(w,v,ndp[w:])
    np.maximum(ndp[:-w] + v, ndp[w:], out=ndp[w:])
#    print(w,v,ndp)

print(ndp[-1])


Measured memory_bytes: 14680
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
using ll = long long;
using VL=vector<ll>;

#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++)
const int INF =  999999999;

int dp[(1<<15)+10][16],n,m;
int d[17][17];

int rec(int S,int v){
  if(dp[S][v]>=0){
    return dp[S][v];
  }

  if(S==(1<<n)-1 && v==0){
    return dp[S][v]=0;
  }

  int res=INF;
  REP(u,n){
    if(!((S>>u)&1)){
      //uに移動する。
      res=min(res,rec(S | (1<<u),u)+d[v][u]);
    }
  }
  return dp[S][v]=res;
}

int main(){
  cin>>n>>m;
  REP(i,n){
    REP(j,n){
      d[i][j]=INF;
    }
  }
  int s,t,r;
  REP(i,m){
    cin >>s>>t>> r;
    d[s][t]=r;
  }
  memset(dp,-1,sizeof(dp));
  int ans=rec(0,0);
  if(ans>=INF){
    cout <<"-1"<<endl;
  }
  else cout<<ans<<endl;
}



Measured memory_bytes: 5152
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define all(vec) vec.begin(),vec.end()

signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
 
	int N;
	cin >> N;
	int ans;
	cin>>ans;
	for (int index = 0; index < N-1; index++) {
		int tmp;
		cin >> tmp;
		ans = __gcd(ans, tmp);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int compare_int(const void *a, const void *b){return *(int*)a - *(int*)b;}

int main(void){
	int N,K,i;
	scanf("%d %d",&N,&K);
	int A[200001]={},c=0;
	for(i=0;i<N;i++){
		int tmp;
		scanf("%d",&tmp);
		A[tmp]++;
		if(A[tmp] == 1) c++;
	}
	qsort(A, sizeof(A)/sizeof(int), sizeof(int), compare_int);
	int ans=0;
	
	while(c>K){
		ans += A[200001-c];
		c--;
	}
	
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define forn(x, n)              for (int x = 0; x < n; x++)
#define forr(x, n)              for (int x = n; x >= 0; x--)
#define fore(x, a, b, c)        for (int x = a; x <= b; x += c)
#define forre(x, a, b, c)       for (int x = a; x >= b; x -= c)
#define clr                     cin.ignore(numeric_limits<streamsize>::max(), '\n')
#define all(container)          (container).begin(), (container).end()
#define rall(container)         (container).rbegin(), (container).rend()
#define FILL(x, val)            memset(x, val, sizeof(x))
#define pb                      push_back
#define eb                      emplace_back
#define fi                      first
#define se                      second
#define mod                     (int)1000000007
#define INF                     (int)0x3f3f3f3f

using namespace std;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }  

typedef long long ll; 
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int a,b,m;cin>>a>>b>>m;
    vector<int> A(a);    
    vector<int> B(b);
    int ans=INF;
    forn(i,a)
        cin>>A[i];
    forn(i,b)
        cin>>B[i];
    forn(i,m){
        int x,y,c;
        cin>>x>>y>>c;
        --x,--y;
        uin(ans,A[x]+B[y]-c);
    }
    uin(ans,*min_element(all(A))+*min_element(all(B)));
    cout<<ans<<'\n';
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


constexpr lint mod = 1e9 + 7;
inline lint emod(lint a, lint p = mod) { return (a % p + p) % p; }
inline lint invm(lint a, lint p = mod) { a %= p; return a == 1 ? 1 : -p / a * invm(p % a) % p; }

V<lint> fact, ifact;
void init_table(int n) {
  fact.assign(n + 1, 1), ifact.assign(n + 1, 1);
  for (int i = 2; i < n + 1; ++i) fact[i] = i * fact[i - 1] % mod;
  ifact[n] = invm(fact[n]);
  for (int i = n; i > 2; --i) ifact[i - 1] = i * ifact[i] % mod;
}

lint comb(lint n, lint r) {
  if (r < 0 or r > n) return 0;
  return fact[n] * ifact[r] % mod * ifact[n - r] % mod;
}

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  lint n, k; cin >> n >> k;
  if (n > k) return cout << 0 << '\n', 0;
  init_table(k);
  cout << emod(comb(k, n)) << '\n';
}


Measured memory_bytes: 3228
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <cctype>  // std::islower(), std::isupper(), std::tolower, std::toupper
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()
 
typedef long long ll;
 
int main (void) {
 
  int A, B; std::cin >> A >> B;
  std::cout << std::max( {A+B, A-B, A*B } ) << std::endl;
 
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<utility>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,m,n) for(ll i=m;i<n;i++)
#define REPR(i,n) for(ll i=n;i>=0;i--)
#define FORR(i,n,m) for(ll i=n;i>=m;i--)

int main(){
    string c[3];
    REP(i,3){cin >> c[i];}
    cout << c[0][0] << c[1][1] << c[2][2] << endl;
    return 0;
}

Measured memory_bytes: 256