akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int[] n = in.nextIntArray(3);
            int min = Integer.MAX_VALUE;
            for (int i = 0; i < 3; i++)
                for (int j = 0; j < 3; j++)
                    if (i != j)
                        min = Math.min(n[i] + n[j], min);
            out.println(min);
        }

    }

    static class FastScanner {
        private InputStream in;
        private byte[] buffer = new byte[1024];
        private int bufPointer;
        private int bufLength;

        public FastScanner(InputStream in) {
            this.in = in;
            this.bufPointer = 0;
            this.bufLength = 0;
        }

        private int readByte() {
            if (bufPointer >= bufLength) {
                if (bufLength == -1)
                    throw new InputMismatchException();

                bufPointer = 0;
                try {
                    bufLength = in.read(buffer);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (bufLength <= 0)
                    return -1;
            }
            return buffer[bufPointer++];
        }

        private static boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public int nextInt() {
            int n = 0;

            int b = readByte();
            while (isSpaceChar(b))
                b = readByte();

            boolean minus = (b == '-');
            if (minus)
                b = readByte();

            while (b >= '0' && b <= '9') {
                n *= 10;
                n += b - '0';
                b = readByte();
            }

            if (!isSpaceChar(b))
                throw new NumberFormatException();

            return minus ? -n : n;
        }

        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

    }
}



Measured memory_bytes: 22740
#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
#define ALL(a) a.begin(), a.end()
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<int, int> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
ll sm[200005];


int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    ll ans=0;
    ll tol=0;
    rep(i,n){
        cin >> a[i];
        tol+=a[i];
        if(i!=0){
            sm[i]=sm[i-1]+a[i];
            sm[i]%=mod;
        }else{
            sm[i]=a[0];
        }
    }
    rep2(i,n-1){
        ll temp=a[i]*(sm[i-1])%mod;
        ans+=temp;
        ans%=mod;
    }
    ans%=mod;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 6388
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}
int main() {
    ll n, m; cin >> n >> m;
    ll mod = 1000000007;
    int a[100003]; INITA(a, 0, 100003, 0);

    REP(i, m) {
        int tmp; cin >> tmp;
        a[tmp] = 1;
    }

    int dp[100003]; INITA(dp, 0, 100003, 0);
    dp[n] = 1;
    FORD(i, n-1, 0) {
        if (a[i] == 1) {
            continue;
        }
        dp[i] = 0;
        dp[i] += dp[i+1];
        dp[i] += dp[i+2];
        dp[i] %= mod;
    }
    cout << dp[0] << endl;
    return 0;
}

Measured memory_bytes: 4452
n,m = gets.split.map!(&:to_i)

mod = 10 ** 9 + 7
max = n > m ? n : m
fac = [1]
1.upto(max) {|i| fac << fac.last * i % mod}

x = (n-m).abs
if  x > 1
    puts 0
else
    ans = fac[n] * fac[m] % mod
    puts x == 1 ? ans : ans * 2 % mod
end

Measured memory_bytes: 2684
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
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 (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    double ans = 0;
    rep(i, n){
        ans += 1./a[i];
    }

    cout << decimal << 1./ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
 
  int A, B;
  int ans = 0;

  cin >> A >> B;

  while(B > A){
	B -= (A - 1);
	ans++;
  }

  if(B != 1){
	ans++;
  }

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


Measured memory_bytes: 256
h,w=map(int,input().split())
l=[]
ll=[[1,0],[-1,0],[0,-1],[0,1],[1,1],[-1,1],[1,-1],[-1,-1]]
ans=[[0]*w for i in range(h)]
s=set()
for i in range(h):
    tmp=input()
    l.append(tmp)
    for j in range(w):
        if tmp[j]=="#":
            ans[i][j]="#"
            for x,y in ll:
                if 0<=i+x<h and 0<=j+y<w:
                    if ans[i+x][j+y]!="#":
                         ans[i+x][j+y]+=1
for i in range(h):
    tmp=""
    for j in range(w):
        tmp+=str(ans[i][j])
    print(tmp)


Measured memory_bytes: 3064
s = input()

pos = s.find('B')
while pos > -1:
    if pos == 0:
        s = s[1:]
    elif pos == len(s) - 1:
        s = s[0:pos - 1]
    else:
        s = s[0:pos - 1] + s[pos + 1:]
    pos = s.find('B')
print(s)

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-
"""
Created on Sun May 19 21:06:16 2019

@author: Yamazaki Kenichi
"""

N, K = map(int,input().split())
S = input()

t = {'A':'a','B':'b','C':'c'}

print(S[:K-1] + t[S[K-1]] + S[K:])


Measured memory_bytes: 3060
from operator import itemgetter
import sys

n = int(input())

ABs = [list(map(int, input().split())) for i in range(n)]

ABs.sort(key=itemgetter(1))
# print(ABs)

cnt = 0
for i in range(n):
    cnt += ABs[i][0]
    if cnt > ABs[i][1]:
        print('No')
        sys.exit()

print('Yes')

    


Measured memory_bytes: 53732
def main():

    N, K = map(int, input().split())
    a = list(map(int, input().split()))
    dp = [[0]*(K+1) for i in range(N+1)]
    import collections
    dp[0][K] = 1
    mod = 10**9 + 7
    # dp[i][j] i人目まで配って、残りがj個の方法の数
    for i in range(1, N+1):
        tmp = 0
        q = collections.deque()
        for j in range(K, -1, -1):
            while(q):
                if q[0][0] > j:
                    t = q.popleft()
                    tmp -= t[1]
                else:
                    break
            if dp[i-1][j]:
                tmp += dp[i-1][j]
                q.append((max(j - a[i-1], 0), dp[i-1][j]))
            tmp %= mod
            dp[i][j] = tmp

    print(dp[-1][0])


main()


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

template<typename T>
struct BinaryIndexedTree{
private:
  int n;
  T *data;

public:
  BinaryIndexedTree(int n = 0) : n(n){
    data = new T[n + 1];
    for(int i = 0; i <= n; i++) data[i] = 0;
  }

  bool add(int index, T x = 1){
    if(index < 0 || n <= index) return false;
    for(index++; index <= n; index += index & -index){
      data[index] += x;
    }
    return true;
  }

  T sum(int index){
    if(index < 0) index = 0;
    else if(index >= n) index = n - 1;

    T x = 0;
    for(index++; index; index -= index & -index){
      x += data[index];
    }
    return x;
  }

  ~BinaryIndexedTree(){
    delete [] data;
  }
};


using namespace std;

int main(){
  int N, K;
  cin >> N >> K;
  
  if(K >= 500){
    for(int i = 0; i < N - 1; i++) cout << N << ' ';
    cout << N << endl;
  }else{
    vector<int> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    for(int k = 0; k < K; k++){
      vector<int> B(N + 1, 0);
      for(int i = 0; i < N; i++){
        B[max(i - A[i], 0)]++;
        B[min(i + A[i] + 1, N)]--;
      }
      A[0] = B[0];
      for(int i = 1; i < N; i++){
        B[i] += B[i - 1];
        A[i] = B[i];
      }
    }
    
    for(int i = 0; i < N - 1; i++){
      cout << A[i] << ' ';
    }
    cout << A[N - 1] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 4840
from functools import *
@lru_cache(maxsize=None)
def solve(L,R):
  if L > R: return 0
  if L == 1: return 1 + solve(2, R)
  return solve(L//2,(R-1)//2) + solve((L+1)//2,R//2) + solve((L+1)//2,(R-1)//2)
print(solve(*map(int,input().split()))%(10**9+7))

Measured memory_bytes: 38384
N = int(input())
S = [int(input()) for i in range(N)]
T = list(filter(lambda x: x % 10 > 0, S))
res = sum(S)
if res % 10 == 0:
    if len(T) == 0:
        res = 0
    else:
        res -= min(T)

print(res)


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

int main() {
  int D, G;
  cin >> D >> G;
  vector<int> p(D);
  vector<int> c(D);
  for (int i = 0; i < D; ++i) cin >> p.at(i) >> c.at(i);
  
  int ans = 1000000000;
  for (int bit = 0; bit < (1 << D); ++bit) {
    vector<int> B(D, 0);
    for (int i = 0; i < D; ++i) {
      if (bit & (1 << i)) B.at(i) = 1;
    }
    
    int question = 0;
    int point = 0;
    
    for (int i = 0; i < D; ++i) {
      if (B.at(i) == 1) {
        question += p.at(i);
        point += 100 * (i + 1) * p.at(i) + c.at(i);
      }
    }
    
    int k = D - 1;
    while (point < G && 0 <= k) {
      if (B.at(k) == 0) {
        int c = min((G - point) / 100 / (k + 1), p.at(k) - 1);
        point += 100 * (k + 1) * c;
        question += c;
      }
      --k;
    }
    
    if (question < ans && point >= G) ans = question;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;            //

int main(void)
{
    int N, A;
    cin >> N >> A;

    cout << N * N - A << endl;
    return (0);
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
  char ha[1<<21],k[256];
int main(int argc,char *argv[]){
  int flg;
  int val,s,t;
  char c;
  k['T'] = 1;
  k['G'] = 2;
  k['C'] = 3;
  k['A'] = 4;
    
  scanf("%d", &val);
  getchar();
  while (val--) {
    s = 0;
    t = 1;
    flg = ( c = getchar() ) == 'i';
    while ( ( c = getchar() ) != ' ' );
    while ( ( c = k[getchar()] ) != 0 ) {
      s += c * t;
      t *= 4;
    }
    if (flg) ha[s] = 1; else puts( ha[s] ? "yes" : "no" );
  }
  return 0;
}

Measured memory_bytes: 3040
#include <stdio.h>
int solve(int ,int);

int A[20],n;
int main() {
  int i,j,q,m[200],t;
  scanf("%d",&n );
  for (i = 0; i < n; i++) {
    scanf("%d",&A[i] );
  }
  scanf("%d",&q);
  for (i = 0; i < q; i++) {
    scanf("%d",&m[i]);
  }
  for (i = 0; i < q; i++) {
  t= solve(0,m[i]);
  if (t ==1) {
    printf("yes\n");
  }

  if (t ==0) {
    printf("no\n");
  }

}
  return 0;
}
int solve(int i,int m){
  int res=0;
   if (m == 0)
   return 1;
   if (i >= n)
  return 0;
  if (solve(i + 1, m - A[i]) == 1 || solve(i + 1, m) == 1)
  res = 1;
  // res = solve(i + 1, m - A[i]);
  return res;
}

Measured memory_bytes: 580
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>

using namespace std;

template<class T> void ReadInteger(T & x) {
    x = 0;
    int f = 1, ch = getchar();
    while(ch < '0' || ch > '9') {
        if(ch == '-') f = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9') {
        x = x * 10 - '0' + ch;
        ch = getchar();
    }
    x *= f;
}

typedef long long LL;

const LL inf = 1LL << 60;
int N;
int head[205], ecnt;
queue< pair<int, int> > q;

struct edge {
    int to, nex;
};
edge G[205];
inline void addedge(int u, int v) {
    G[ecnt] = (edge) {v, head[u]};
    head[u] = ecnt++;
    G[ecnt] = (edge) {u, head[v]};
    head[v] = ecnt++;
}

int dep[205], anc[205], d;
void DFS(int u, int step) {
    dep[u] = step;
    if(step > dep[d]) d = u;
    for(int i = head[u]; ~ i; i = G[i].nex) {
        int v = G[i].to;
        if(v != anc[u]) {
            anc[v] = u;
            DFS(v, step + 1);
        }
    }
}

int cnt[205], vis[205];
LL BFS(int st, int f) {
    if(!st) return inf;
    if(f && !anc[st]) return inf;
    memset(cnt, 0, sizeof(cnt));
    memset(vis, 0, sizeof(vis));
    q.push(make_pair(st, 1)), cnt[1]++, vis[st] = 1;
    if(f) q.push(make_pair(anc[st], 1)), cnt[1]++, vis[ anc[st] ] = 1;
    while(!q.empty()) {
        int u = q.front().first;
        int d = q.front().second;
        vis[u] = 1;
        q.pop();
        int deg = 0;
        for(int i = head[u]; ~ i; i = G[i].nex) {
            int v = G[i].to;
            if(!vis[v]) {
                q.push(make_pair(v, d + 1));
                deg++;
            }
        }
        cnt[d + 1] = max(cnt[d + 1], deg);
    }
    /*cout << "DEBUG " << st << ' ' << anc[st] << endl;*/
    long long res = 1;
    for(int i = 1; i <= N; i++) if(cnt[i]) {
        /*cout << i << ' ' << cnt[i] << endl;*/
        res *= cnt[i];
        if(i > (dep[d] + 1) / 2) return inf;
    }
    return res;
}

void Solve() {
    DFS(1, 1);
    memset(anc, 0, sizeof(anc));
    DFS(d, 1);
    long long ans = inf;
    for(int i = 1; i <= N; i++) ans = min(ans, BFS(i, 0));
    for(int i = 1; i <= N; i++) ans = min(ans, BFS(i, 1));
    printf("%d %lld\n", (dep[d] + 1) >> 1, ans);
}
int main() {
    ReadInteger(N);
    memset(head, -1, sizeof(head));
    for(int i = 1; i < N; i++) {
        int u, v;
        ReadInteger(u);
        ReadInteger(v);
        addedge(u, v);
    }
    Solve();
    return 0;
}

Measured memory_bytes: 256
n = int(input())
x = range(n)
P =[]
s = 0
for _ in x:P += [[int(i) for i in input().split()]]
P+=[P[0]]
for j in x:s += P[j][0]*P[j+1][1] - P[j][1]*P[j+1][0]
print(s*0.5)

Measured memory_bytes: 7732
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <vector>
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstring>
#include <queue>

using namespace std;

const double PI = 3.14159265358979;


const vector<int>* fibon_seq(int size) {

	static vector<int> elems;
	for (int i = elems.size(); i <= size; i++) {
		if (i == 0 || i == 1)
			elems.push_back(1);
		else
			elems.push_back(elems[i - 1] + elems[i - 2]);
	}
	return &elems;
}




int main() {

	int n; cin >> n;
	vector<int>  res = *fibon_seq(n);

	cout << res[n] << endl;

	return 0;
}



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

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))

typedef struct{
    int priority;
    double value;
}data;

//昇順
int asc(const void* a, const void* b){
    return *(int*)a-*(int*)b;
}

//降順
int desc(const void* a, const void* b){
    return *(int*)b-*(int*)a;
}

int main(void){
    int r;
    scanf("%d",&r);


    int ans=r*r;
    printf("%d\n",ans);

    return 0;
}

Measured memory_bytes: 128
# coding: utf-8
# Your code here!
N=int(input())


say=[]
for _ in range(N):
    temp=[-1]*N
    A=int(input())
    for __ in range(A):
        x,y=map(int,input().split())
        temp[x-1]=y
    say.append(temp)

#print(say)

ans=0
for i in range(2**N):
    katei=list(str(bin(i))[2:])
    katei=list(map(int,katei))
    katei=[0]*(N-len(katei))+katei
    #print(katei)
    
    flag=True
    for num in range(N):
        if katei[num]==1:
            for num2 in range(N):
                if (say[num][num2]==0 and katei[num2]==1) or (say[num][num2]==1 and katei[num2]==0):
                    flag=False
    if flag:
        ans=max(ans,sum(katei))
    
print(ans)


Measured memory_bytes: 3064
#include<stdio.h>

int main()
{
  int N;
  int a[201];
  int i;
  int t=0;
  int s=1;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&a[i]);
  }
  while(s==1){
    for(i=0;i<N;i++){
      if(a[i]%2!=0) s=0;
      if(a[i]%2==0) a[i]/=2;
    }
    t++;
  }
  printf("%d",t-1);
}


Measured memory_bytes: 1696
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <functional>
#include <utility>
#include <stdio.h>
#define ll long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define F first
#define S second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int n;
int a[100010];
bool b[100010];
int main()
{
	cin >>n;
	for (int i=0;i<n;i++) cin >>a[i];
	for (int i=n-2;i>=0;i--)
	{
		if (a[i]>a[i+1])
		{
			a[i]--;
			b[i]=1;
		}
	}
	for (int i=0;i<n-1;i++)
	{
		if (a[i]>a[i+1])
		{
			cout <<"No";
			return 0;
		}
	}
	cout <<"Yes";
	return 0;
} 

Measured memory_bytes: 768
L,R = map(int,input().split())

total = 2019

if R-L >= 2019:
  print(0)
  exit()

for l in range(L,R):
  for r in range(L+1,R+1):
    if l*r%2019 == 0:
      print(0)
      exit()
    else:
      total = min(total,l*r%2019)
    
print(total)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n) for(ll i=0;i<(n);++i)
#define REPR(i,n) for(ll i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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 (a > b) { a = b; return 1; } return 0; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    ll n,k; cin>>n>>k;
    k--;
    vector<int> a(n);
    rep(i,n) cin>>a[i],--a[i];
    int cur = 0;
    int cnt = 0;
    vector<int> r(400033);
    vector<int> t(n);
    while (cnt < 400000) {
        r[cnt] = a[cur];
        cur = a[cur];
        cnt++;
    }
    
    if (k < 400033ll) {
        cout << r[k]+1 << '\n';
        return 0;
    }

    int c = 0;
    int idx = 0;
    rep(i,400033) {
        t[r[i]]++;
        if (t[r[i]] > 1) {
            c = r[i];
            idx = i;
            break;
        }
    }

    int s = 0;
    int sidx = 0;
    for (int i = idx-1; i >= 0; --i) {
        if (r[i]==c) {
            sidx = i;
            break;
        }
    }

    ll seg = idx-sidx;
    k -= sidx;
    ll sho = k/seg;
    ll yo = k%seg;

    cout << r[sidx+yo]+1 << '\n';   

    return 0;
}

Measured memory_bytes: 6408
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+9+7;
ll n,m,l;
string s,t;
ll d[200010],dp[550][550];

int main(){
  t = "";
  rep(i,0,3){
    cin >> s;
    t += s[i];
  }
  print(t);
  return 0;
}

Measured memory_bytes: 764
#include<stdio.h>
int main(void)
{
	int a,b,c,d;
	scanf("%d %d %d",&a,&b,&c);
	if(a>b){
		d=a;
		a=b;
		b=d;
	}
	if(b>c){
		d=b;
		b=c;
		c=d;
	}
	if(a>b){
		d=a;
		a=b;
		b=d;
	}
	printf("%d %d %d\n",a,b,c);
	
	return 0;
}

Measured memory_bytes: 596
mod = 10 ** 9 + 7

s = input()
L = int(s, 2)

lg = len(s)

dp = [[0] * 2 for _ in range(lg + 1)]
dp[0][0] = 1
# dp[何文字目][以下未確定0/以下確定1] = パターン数

for i in range(lg):
    if (L >> (lg - 1 - i)) & 1:
        dp[i + 1][0] += dp[i][0] * 2
        dp[i + 1][0] %= mod
        # 1を選択

        dp[i + 1][1] += dp[i][0]
        # 0を選択して以下確定

        dp[i + 1][1] += dp[i][1] * 3
        # 1選択*2 + 0選択

        dp[i + 1][1] %= mod
    else:
        dp[i + 1][0] += dp[i][0]
        dp[i + 1][0] %= mod
        # 0を選択

        dp[i + 1][1] += dp[i][1] * 3
        # 0選択*2 + 1選択
        dp[i + 1][1] %= mod

print((dp[lg][0] + dp[lg][1]) % mod)
# print(dp)


Measured memory_bytes: 55132
use std::io::Read;
use std::cmp::min;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let a: usize = iterator.next().unwrap().parse().unwrap();
    let b: usize = iterator.next().unwrap().parse().unwrap();
    let x: Vec<usize> = (0..n).map(|_| iterator.next().unwrap().parse().unwrap()).collect();

    let mut ans = 0;
    for i in 1..n {
        ans += min((x[i] - x[i - 1]) * a,b);
    }
    return ans.to_string();
}


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

#define inf 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,P> PP;

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

template< typename T >
struct FordFulkerson {

	struct FlowEdge {
		int to;
		T cap,rev;
		FlowEdge() {}
		FlowEdge(int to,T cap,T rev):to(to),cap(cap),rev(rev) {}
	};

	vector< vector<FlowEdge> > G;
	vector<int> used;

	FordFulkerson() {}
	FordFulkerson(int n) {
		G.resize(n);
		used.resize(n);
	}

	void add_edge(int from,int to,T cap,int type) {
		G[from].emplace_back(to,cap,(int)G[to].size());
		if(type==0) G[to].emplace_back(from,0,(int)G[from].size()-1);
		else G[to].emplace_back(from,cap,(int)G[from].size()-1);
	}

	T dfs(int v,const int t,T flow) {
		if(v==t) return flow;
		used[v]=1;
		for(auto &e:G[v]) {
				if(!used[e.to]&&e.cap>0) {
				T d=dfs(e.to,t,min(flow,e.cap));
				if(d>0) {
					e.cap-=d;
					G[e.to][e.rev].cap+=d;
					return d;
				}
			}
		}
		return 0;
	}

	T max_flow(int s,int t,T lim) {
		T flow=0;
		while(true) {
			fill(ALL(used),false);
			T d=dfs(s,t,inf);
			if(d==0) return flow;
			flow+=d;
		}
		return flow;
	}

	T max_flow(int s,int t) {
		return max_flow(s,t,inf);
	}
};

int h,w;
string fld;
bool E[100][100];
P S,T;

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

	cin>>h>>w;
	FordFulkerson<ll> F(h+w+2);
	REP(i,h) {
		cin>>fld;
		REP(j,w) {
			if(fld[j]=='S') {
				F.add_edge(h+w,i+w,inf,0);
				F.add_edge(h+w,j,inf,0);
				S=P(i,j);
			}
			else if(fld[j]=='T') {
				F.add_edge(i+w,h+w+1,inf,0);
				F.add_edge(j,h+w+1,inf,0);
				T=P(i,j);
			}
			else if(fld[j]=='o') {
				E[i][j]=true;
			}
		}
	}
	REP(i,h) {
		REP(j,w) {
			if(E[i][j]) {
				F.add_edge(i+w,j,1,1);
			}
		}
	}
	if(S.fi==T.fi||S.se==T.se) {
		cout<<-1<<endl;
		return 0;
	}
	cout<<F.max_flow(h+w,h+w+1)<<endl;

	return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
static const int mod=998244353;
static const int MAX=2e5+1;
ll fact[MAX];

ll mod_pow(ll a, ll n, ll p){
  ll res=1;
  while(n>0){
    if(n&1){
      res=(res*a)%p;
    }
    a=(a*a)%p;
    n/=2;
  }
  return res;
}

ll mod_inverse(ll a, ll p){
  return mod_pow(a, p-2, p);
}

ll combi(ll n, ll r){
  return fact[n]*mod_inverse((fact[r]*fact[n-r])%mod, mod);
}

int main(){
  ll n, m, k;
  cin>>n>>m>>k;
  ll ans=0;
  fact[0]=1;
  for(int i=1; i<=n; ++i){
    fact[i]=(i*fact[i-1])%mod;
  }
  for(int i=n-k-1; i<n; ++i){
    int dummy=0;
    dummy=combi(n-1, i)%mod;
    dummy=(dummy*m)%mod;
    dummy=(dummy*mod_pow(m-1, i, mod))%mod;
    ans=(ans+dummy)%mod;
  }
  cout<<ans<<endl;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void solve() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    vector<ll> ans(N + 20, 0);

    ll all = 0;
    rep(i, N) {
        all ^= A[i];
    }

    rep(i, N) {
        ll a1 = A[i];
        ans[i] = all ^ a1;
    }

    rep(i, N) {
        cout << ans[i] << ' ';
    }
    cout << '\n';
}

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


Measured memory_bytes: 6292
//Never stop trying
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

typedef string str;
typedef long long ll;
#define int ll
typedef double db;
typedef long double ld;

typedef pair<int,int> pi;
#define fi first
#define se second

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;

#define pb push_back
#define eb emplace_back
#define pf push_front

#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define endl "\n"

const int MOD = 1e9+7; //998244353
const ll INF = 1e18;
const int nx[4]={0,0,1,-1}, ny[4]={1,-1,0,0}; //right left down up

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

int32_t main(){
   boost;
   IO();
	
	str s; cin>>s;
	int ans=0;
	int cnt=0;
	for(int i=0; i<3; i++){
		if(s[i]=='R') cnt++;
		else cnt=0;
		ans=max(ans,cnt);
	}

	cout << ans << endl;

   return 0;
}



Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <chrono>
#include <random>

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	int m, d;
	std::cin >> m >> d;
	int ans = 0;
	for(int i = 2; i * 10 <= d && i < 10; i++) {
		for(int j = 2; i * 10 + j <= d && j < 10; j++) {
			if(i * j <= m) {
				ans++;
			}
		}
	}
	std::cout << ans << std::endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
 
using namespace std;
 
using ll = long long;
 
int main(){
  string S, T;
  cin >> S;
  cin >> T;
  int ans = 0;
  for(int i = 0; i < 3; ++i){
    if(S[i] == T[i]) ++ans;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.array, std.algorithm, std.range;
import std.math;

void main()
{
    foreach(_;0..readln().chomp().to!int())
    {
        auto m = readln().split().map!(to!real);
        immutable xa=m[0], ya=m[1], ra=m[2], xb=m[3], yb=m[4], rb=m[5];
        immutable d = hypot(xa-xb,ya-yb);
        if(ra>rb+d) writeln(2);
        else if(ra+d<rb) writeln(-2);
        else if(ra+rb<d) writeln(0);
        else writeln(1);
    }
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int n; cin >> n;
  int cnt = 0;
  for(int i = 0; i < n; ++i){
    int x; cin >> x;
    if(i%2 == 0)cnt += (x%2==1);
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3628
#include<stdio.h>
#define N 100000
#define Q 50000

int main(){
  int n,S[N],q,T[Q],i,left,right,count=0,mid;

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

  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&T[i]);
  }


  for(i=0;i<q;i++){ /*key T[]*/
    left=0;
    right=n;
    while(left<right){
      mid = (left + right)/2;
      if(T[i]==S[mid]){
	count++;
	break;
      }else if(T[i]<S[mid]){
	right=mid;
      }else{
	left=mid+1;
      }
    }
  }

  printf("%d\n",count);

  return 0;
}
  



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

/* {{{ */
#define PI(N) ((M_PI * (N)) / 180) //角度をラジアンに変換する
#define CL(N) (cout << (N) << endl)
#define DCT(N) (cout << "debug " << (N) << endl)
#define REP(i, N) for (int i = 0; i < (N); i++)
/* }}} */

int main()
{
    int a, b;
    char s;

    cin >> a >> s >> b;

    s == '+' ? CL(a + b) : CL(a - b);

    return (0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = 1001002003004005006ll;
const int inf = 1001001001;
const int mod = 1000000007;

int n;
vector<int> g[10];
vector<bool> vi(10);
int ans = 0;

void dfs(int s, int cnt = 1) {
	if (cnt == n) {
		ans++;
	}
	vi[s] = true;
	for (auto& c : g[s]) {
		if (vi[c]) continue;
		vi[c] = true;
		dfs(c, cnt + 1);
		vi[c] = false;
	}
	return;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int m;
	cin >> n >> m;
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a].emplace_back(b);
		g[b].emplace_back(a);
	}
	dfs(0);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3652
n = int(input())
v = list(map(int, input().split()))
ev = [0]*(max(v)+1)
od = [0]*(max(v)+1)
for i in range(n):
    if i % 2 == 0:
        ev[v[i]-1] += 1
    else:
        od[v[i] - 1] += 1
e = sorted(ev)
o = sorted(od)
if ev.index(e[-1]) == od.index(o[-1]) and e[-2] != e[-1] and o[-2] != o[-1]:
    print(n-max(e[-1]+o[-2], e[-2]+o[-1]))
else:
    print(n-e[-1]-o[-1])


Measured memory_bytes: 14052
/*
  AUTHOR:SOURABH
  CREATED:27:08:20
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ordered_set tree<pll , null_type, less< pll >, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define W while
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x) for(i=x;i>=0;i--)
#define fit(it,s) for(it=s.begin();it!=s.end();it++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define mod 1000000007
#define MAX 100005
#define M 32

using namespace std;
using namespace __gnu_pbds;


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    //freopen("input.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    ll t,n,m,i,j,sum,ans;
    string s,tt;
    t=1;
    //cin>>t;
    W(t--)
    {
        cin>>s>>tt;
        n=s.length(),m=tt.length();
        ans=1e5;
        fs(i,m-1,n)
        {
            sum=0;
            fs(j,i+1-m,i+1)
            {
                if(s[j]!=tt[j-(i+1-m)])
                    sum++;
            }
            ans=min(ans,sum);
        }
        cout<<ans;
    }
    return 0;
}




Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
 
using ll = long long;
using pll = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define sz(x) ((x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
const double PI = acos(-1);
const int mod = 1e9+7;
const long long INF = (1LL << 60);
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(ll a, ll b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmax(T &a, const T &b){ if(a < b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(a > b){ a=b; return 1; } return 0; }

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

  ll n, m, x;
  cin >> n >> m >> x;
  vector<ll> c(n);
  ll a[n][m];
  rep(i, 0, n){
    cin >> c[i];
    rep(j, 0, m) cin >> a[i][j];
  }

  ll ans = INF;
  for (ll bit = 0; bit < (1<<n); ++bit) {
    vector<ll> cnt(m, 0);
    ll money = 0;
    for (ll i = 0; i < n; ++i) {
      if (bit & (1<<i)) {
        money += c[i];
        for(ll j = 0; j < m; j++){
          cnt[j] += a[i][j];
        }
      }
    }

    //cout << money << endl;
    //rep(i, 0, m) cout << cnt[i] << ' ';
    //cout << endl;

    bool ok = true;
    rep(i, 0, m){
      if(cnt[i] < x) ok = false;
    }
    if(ok){
      chmin(ans, money);
    }
  }
  if(ans == INF) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

// GCD,LCMを求める関数
ll gcd(ll a,ll b){
	if(a%b==0) return(b);
	else return(gcd(b,a%b));
}
ll lcm(ll a, ll b){
	return a*b/gcd(a,b);
}

signed main(){
  int n; cin>>n;
  VI t(n), a(n);
  rep(i,n) cin>>t[i]>>a[i];
  ll u = 1, v = 1;
  rep(i,n){
    ll x = u/t[i], y = v/a[i];
    if(u%t[i]) x++; if(v%a[i]) y++;
    ll z = max(x,y);
    u = z*t[i]; v = z*a[i];
  }
  cout << u+v << endl;


  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <string>

using namespace std;


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

	int len = 1;
	long long m = 26;
	while (1) {
		if (n <= m) {
			n--;

			string s;
			while (n > 0) {
				s += (n % 26) + 'a';
				n /= 26;
			}
			reverse(s.begin(), s.end());
			string ans = string(len - s.size(), 'a') + s;
			cout << ans << endl;
			return 0;
		}

		n -= m;
		m *= 26;
		len++;
	}

	return 0;
}


Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
#define inf 100000000
vector<int> g[100001];
int L[100001],R[100001],id[100001],n,k;
bool ans=1;
void solve(int v=0,int p=-1){
    L[v]=-inf-1;
    R[v]=inf+1;
    if(id[v]!=-1)
        L[v]=R[v]=id[v];
    for(int i=0;i<g[v].size();i++){
        int to=g[v][i];
        if(to!=p){
            solve(to,v);
            if(L[to]<-inf/2)
                continue;
            if(L[v]<-inf/2){
                L[v]=L[to]-1;
                R[v]=R[to]+1;
            }
            else{
                if(abs(L[to])%2==abs(L[v])%2){
                    ans=0;
                    return;
                }
                L[v]=max(L[to]-1,L[v]);
                R[v]=min(R[to]+1,R[v]);
            }
        }
    }
    if(L[v]>R[v])
        ans=0;
}
void make(int v=0,int p=-1){
    if(v==0 && id[v]==-1)
        id[v]=L[v];
    for(int i=0;i<g[v].size();i++){
        int to=g[v][i];
        if(to!=p){
            if(id[to]==-1){
                if(L[to]<=id[v]-1 && id[v]-1<=R[to])
                    id[to]=id[v]-1;
                else
                    id[to]=id[v]+1;
            }
            make(to,v);
        }
    }
}
int main(){
    memset(id,-1,sizeof(id));
    cin>>n;
    for(int i=0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        a--,b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    cin>>k;
    for(int i=0;i<k;i++){
        int x,y;
        cin>>x>>y;
        x--;
        id[x]=y;        
    }
    solve();
    if(!ans){
        puts("No");
        return 0;
    }
    make();
    puts("Yes");
    for(int i=0;i<n;i++)
        cout<<id[i]<<endl;
    return 0;
}

Measured memory_bytes: 15360
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        var sc = new Scanner();
        int n = sc.NextInt();
        int k = sc.NextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) h[i] = sc.NextInt();
        Array.Sort(h);
        int ans = 1000000001;
        for (int i = 0; i < n - k　+ 1; i++)
        {
        	int d = h[i + k - 1] - h[i];
        	if (d < ans) ans = d;
        }
        Console.WriteLine(ans);
    }
}

class Scanner
{
    int index = -1;
    string[] buf;

    public Scanner()
    {
    }

    public int NextInt()
    {
        CheckNext();
        return int.Parse(buf[index++]);
    }
        
    public long NextLong()
    {
    	CheckNext();
    	return long.Parse(buf[index++]);
    }

    public string NextString()
    {
        CheckNext();
        return buf[index++];
    }

    private void CheckNext()
    {
        if (index >= 0 && index < buf.Length) return;

        buf = Console.ReadLine().Split(' ');
        index = 0;
    }
}

Measured memory_bytes: 15440
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<algorithm> // sort
#include<map> // pair
#include<cmath>
#include<cstring>
#include<set>
using namespace std;
using ll = long long;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
const ll mod = 1e9+7;
const int INF = 1e9;
const ll INFLONG = 1e18;
// vector<vector<ll>> vec(100000,vector<ll>(3,0));

int main(){
  ll n;
  ll tmp1,tmp2;
  cin >> n;
  ll ans=-1;
  REP(i,n,1000){
    tmp1 = i / 10 % 10;
    tmp2 = i / 100;
    if(i % 10 == tmp1 && tmp1 == tmp2){
      ans = i;
      break;
    }
  }
  cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20);
#define int long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) _overload(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload(__VA_ARGS__, revi, _rev)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
void in(){}
template<typename F, typename... R>
bool in(F& f, R&... r){
    if(cin >> f){in(r...);return true;}
    else return false;
}
#define out(x) cout << (x)
#define space() cout << " "
#define indent() cout << '\n'
void print(){}
template<typename F, typename... R>
void print(F f, R... r){out(f), indent(), print(r...);}
#define debughead(x) cerr << "Line " << __LINE__ << ": " << #x << ": "
#define debugout(x) cerr << (x) << " "
#define debugindent() cerr << '\n'
#define debug(x) debughead(x), debugout(x), debugindent()
const int INF = 1e18, MOD = 1e9 + 7;
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}
bool isPrime(int n){
    rep(i, 2, sqrt(n) + 1){
        if(i > 3){
            i++;
        }
        if(!(n % i)){
            return false;
        }
    }
    return true;
}
main(){
    INCANT;
    int q, l, r, tmp, res = 0;
    string s;
    int v[111111] = {};
    vector<vector<int>> g;
    for(int i = 3; i < 111111; i += 2){
        v[i] = v[i - 2];
        if(isPrime(i) && isPrime(i / 2 + 1)){
            v[i]++;
        }
    }
    in(q);
    tmp = 111111 - q;
    while(q--){
        in(l, r);
        print(v[r] - v[max(0LL, l - 2)]);
    }
    while(tmp--){
        debug(v[r] - v[max(0LL, l - 2)]);
    }
}


Measured memory_bytes: 1536
import java.util.*;

class Main {
  public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
    while (scanner.hasNext()) {
      int n = scanner.nextInt();
      if (n == 0) {
        break;
      }
      int c0 = 0;
      int c1 = 0;
      int c2 = 0;
      int c3 = 0;
      int c4 = 0;
      int c5 = 0;
      int c6 = 0;
      for (int ii = 0; ii < n; ii++) {
        int a = scanner.nextInt();
        if (a < 10) {
          c0++;
        } else if (a < 20) {
          c1++;
        } else if (a < 30) {
          c2++;
        } else if (a < 40) {
          c3++;
        } else if (a < 50) {
          c4++;
        } else if (a < 60) {
          c5++;
        } else {
          c6++;
        }
      }
      System.out.printf("%d\n%d\n%d\n%d\n%d\n%d\n%d\n", c0, c1, c2, c3, c4, c5, c6);
    }
  }
}

Measured memory_bytes: 210348
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) {

        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);

        String str1 = null;

        try {
            str1 = br.readLine();
            String strN[] = str1.split(" +");

            int intA = Integer.parseInt(strN[0]);
            int intB = Integer.parseInt(strN[1]);
            int intC = Integer.parseInt(strN[2]);

            br.close();

            if (intA == intB && intA == intC) {
            	System.out.println("Yes");
            } else {
            	System.out.println("No");
            }




        } catch (IOException e) {

        }


    }

}

Measured memory_bytes: 21460
#include <iostream>
using namespace std;
 
int main() {
     
    while(true){
        int n,m,a;
        cin >> n >> m >> a;
        if(n==0&&m==0&&a==0){
                break;
        }
         
        int amida[101][1001]={{0}};
         
        for(int i=0;i<m;i++){
            int h=0,p=0,q=0;
            cin >> h >> p >> q;
            amida[p][h]=1;
        }
         
        for(int j=1000;j>0;j--){
            if(amida[a][j]==1) a++; //????????????
            else if(amida[a-1][j]==1) a--; //???
        }
         
        cout << a << endl;
    }
     
    return 0;
}

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

int main() {
  int n;
  cin>>n;
  int cnt=0;
  for (int i = 1; i <= n; ++i) {
    int p;
    cin>>p;
    if (i-p) cnt++;
  }
  puts(cnt==2||cnt==0?"YES":"NO");
}


Measured memory_bytes: 256