akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

vector<int>E[300000];
int d[300000],D[300000];
int ans[300000];
int Max=0;

void dfs(int v,int p){
	if(p!=-1)d[v]=(d[p]+1)%2,D[v]=d[p]+1,Max=max(Max,D[v]);
	for(int u:E[v]){
		if(u==p)continue;
		dfs(u,v);
	}
}

int main(){
	int n;cin>>n;
	rep(i,n-1){
		int a,b;scanf("%d%d",&a,&b);a--;b--;
		E[a].push_back(b);
		E[b].push_back(a);
	}
	dfs(0,-1);
	if(Max<=1){
		rep(i,n){
			if(i)printf(" ");
			printf("%d",i+1);
		}
		puts("");return 0;
	}
	int A=0,B=0;
	rep(i,n){
		if(d[i]==0)A++;
		else B++;
	}
	int cnt[3]{};
	for(int i=1;i<=n;i++){
		cnt[i%3]++;
	}
	int e=A-cnt[1],f=B-cnt[2];
	bool rev=false;
	if(e<0||f<0||e+f>cnt[0]){
		e=A-cnt[2],f=B-cnt[1];
		rev=true;
		if(e<0||f<0||e+f>cnt[0]){
			if(A<=cnt[0]){
				int C[3]{3,1,2};
				int rem=cnt[0]-A;
				rep(i,n){
					if(d[i]==0){
						ans[i]=C[0];C[0]+=3;
					}
					else{
						if(rem>0){
							rem--;
							ans[i]=C[0];C[0]+=3;
						}
						else if(C[1]<=n){
							ans[i]=C[1];C[1]+=3;
						}
						else{
							ans[i]=C[2];C[2]+=3;
						}
					}
				}
				rep(i,n){
					if(i)printf(" ");
					printf("%d",ans[i]);
				}
				puts("");
				return 0;
			}
			else if(B<=cnt[0]){
				int C[3]{3,1,2};
				int rem=cnt[0]-B;
				rep(i,n){
					if(d[i]==1){
						ans[i]=C[0];C[0]+=3;
					}
					else{
						if(rem>0){
							rem--;
							ans[i]=C[0];C[0]+=3;
						}
						else if(C[1]<=n){
							ans[i]=C[1];C[1]+=3;
						}
						else{
							ans[i]=C[2];C[2]+=3;
						}
					}
				}
				rep(i,n){
					if(i)printf(" ");
					printf("%d",ans[i]);
				}
				puts("");
				return 0;
			}
			abort();
		}
	}
	int C[3]{3,1,2};
	if(rev)swap(C[1],C[2]);
	rep(i,n){
		if(d[i]==0){
			if(e>0){
				e--;
				ans[i]=C[0];
				C[0]+=3;
			}
			else{
				ans[i]=C[1];
				C[1]+=3;
			}
		}
		else{
			if(f>0){
				f--;
				ans[i]=C[0];
				C[0]+=3;
			}
			else{
				ans[i]=C[2];
				C[2]+=3;
			}
		}
	}
	rep(i,n){
		if(i)printf(" ");
		printf("%d",ans[i]);
	}
	puts("");
}
/*
9
1 2
1 3
1 4
1 5
1 6
1 7
7 8
8 9
*/

Measured memory_bytes: 22784
"""Counting Sort."""

def countingSort(A, n):
    """Sort the elements of list A with Counting Sort algorithm.

    n is the length of A.
    The elements of A are intergers between 0 and 10000, inclusive.
    B is the output list where the sorted elements will be arranged.
    
    Print the elements of B in a line separated by a space character.
    """

    C = [0 for i in range(10001)]

    for i in A:
        C[i] += 1

    for i in range(1, 10001):
        C[i] += C[i - 1]

    B = [0 for i in range(n + 1)]
    
    for i in reversed(A):
        B[C[i]] = i
        C[i] -= 1

    print(*B[1:])


import sys

n = int(sys.stdin.readline())

A = list(map(int, sys.stdin.readline().split()))

countingSort(A, n)

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

using namespace std;
using namespace std;
#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const ll inf = 1e9+7;
const ll mod = 1e9+7;

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

    cout<<n*(n-1)/2<<endl;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void){
  int n,a=100000;

  cin >> n;
  while(n--){
    a=a*5/100+a;
    if(a%1000){
      a/=1000;
      a=a*1000+1000;
    }
  }
  cout << a << endl;

  return 0;
}

Measured memory_bytes: 1156
use proconio::marker::Usize1;
fn main() {
    proconio::input! {
        h: usize,
        w: usize,
        d: usize,
        a: [[Usize1;w];h],
        q: usize,
        lr: [(Usize1,Usize1);q],
    }
    let n=h*w;
    let mut p=vec![(0,0);n];
    for i in 0..h {
        for j in 0..w {
            p[a[i][j]]=(i,j);
        }
    }
    let m=n.next_power_of_two().trailing_zeros()as usize+1;
    let mut s=vec![vec![0;n];m];
    for i in 0..n-d {
        let (x1,y1)=p[i];
        let (x2,y2)=p[i+d];
        s[0][i]=x1.max(x2)-x1.min(x2)+y1.max(y2)-y1.min(y2);
    }
    for i in 0..m-1 {
        let d=d*(1<<i);
        for k in 0..n-d.min(n) {
            s[i+1][k]=s[i][k]+s[i][k+d];
        }
    }
    for (l,r) in lr {
        let k=(r-l)/d;
        let mut x=l;
        let mut t=0;
        for i in (0..m).rev() {
            if k>>i&1==1 {
                t+=s[i][x];
                x+=d*(1<<i);
            }
        }
        println!("{}",t);
    }
}

Measured memory_bytes: 19268
n=int(input())
w=[input() for i in range(n)]
a=0
for i in range(1,n):  
  if w[i-1][-1] == w[i][0]:
    if w[i] not in w[:i]:
      a=a
    else:
      a+=1
  else:
    a+=1
if a==0:print("Yes")
else:print("No")

Measured memory_bytes: 3064
n = int(input())
a = list(map(int, input().split()))
ans = 0
minus_count = 0
for i in range(len(a)):
    if a[i] < 0:
        minus_count += 1

if minus_count%2 == 0 or 0 in a:
    for i in range(len(a)):
        ans += abs(a[i])
else:
    for i in range(len(a)):
        ans += abs(a[i])
    a = [e for e in a if e != 0]
    a.sort(key=abs)
    ans -= abs(a[0])*2
print(ans)


Measured memory_bytes: 14468
#include <iostream>
using namespace std;
int calc(int cur, int n, int count, int sum, int goal) {
  if (cur > n) {
    return 0;
  }
  if (count >= 3) {
    return 0;
  }
  if (goal-sum < cur) {
    return 0;
  }
  if (goal-sum == cur) {
    if (count == 2) {
      return 1;
    } else {
      return 0;
    }
  }

  return calc(cur+1, n, count+1, sum+cur, goal) + calc(cur+1, n, count, sum, goal);
}

int main() {
  int n, x;
  bool loop = true;
  while (loop) {
    cin >> n >> x;
    if ((n == 0) && (x == 0)) {
      loop = false;
    } else {
      cout << calc(1, n, 0, 0, x) << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1164
n =int(input())

c=[]
s=[]
f=[]
r=[0]*n

for i in range(n-1):
    add=list(map(int,input().split()))
    c.append(add[0])
    s.append(add[1])
    f.append(add[2])
    
for i in range(n-1):
    r[i]=s[i]+c[i]
    for j in range(n-i-2):
        if r[i] < s[i+j+1]:
            wa = s[i+j+1]-r[i]
        elif (r[i]-s[i+j+1])%f[i+j+1] ==0:
            wa=0
        else:
            wa = f[i+j+1]-((r[i]-s[i+j+1])%f[i+j+1])
        r[i] += wa+c[i+j+1]
        
        
print('\n'.join([str(r) for r in r]))

Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;

class Dice{

private:

public:

  int num[6];

  void roll(char c){
    int b;
    if(c == 'S'){
      b = num[0];
      num[0] = num[4];
      num[4] = num[5];
      num[5] = num[1];
      num[1] = b;
    }
    if(c == 'W'){
      b = num[0];
      num[0] = num[2];
      num[2] = num[5];
      num[5] = num[3];
      num[3] = b;
    }
    if(c == 'N'){
      b = num[0];
      num[0] = num[1];
      num[1] = num[5];
      num[5] = num[4];
      num[4] = b;
    }
    if(c == 'E'){
      b = num[0];
      num[0] = num[3];
      num[3] = num[5];
      num[5] = num[2];
      num[2] = b;
    }
  }
};

bool isSame(Dice d1, Dice d2){
  int top = d1.num[0], front = d1.num[1];
  if(d2.num[2] == front || d2.num[3] == front) d2.roll('W');
  int cnt = 0;
  while(d2.num[1] != front){
    d2.roll('S');
    if(++cnt == 4) return false;
  }
  cnt = 0;
  while(d2.num[0] != top){
    d2.roll('W');
    if(++cnt == 4) return false;
  }
  for(int i=2;i<6;i++){
    if(d1.num[i] != d2.num[i]){
      return false;
    }
  }
  return true;
}

bool isAllDiff(vector <Dice> d, int n){
  for(int i=0;i<n-1;i++){
    for(int j=i+1;j<n;j++){
      if(isSame(d[i], d[j])){
	return false;
      }
    }
  }
  return true;
}

int main(){
  vector <Dice> vec;
  Dice d;
  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    for(int j=0;j<6;j++){
      cin >> d.num[j];
    }
    vec.push_back(d);
  }

  if(isAllDiff(vec, n)) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}



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


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

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
#include <stdio.h>

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

    int num[5];
    for(int i = 0; i < 5; i++){
        num[i] = 0;
    }

    char name[11];
    for(int i = 0; i < N; i++){
        scanf("%s", name);
        switch(name[0]){
            case 'M':
                num[0]++;
                break;
            case 'A':
                num[1]++;
                break;
            case 'R':
                num[2]++;
                break;
            case 'C':
                num[3]++;
                break;
            case 'H':
                num[4]++;
                break;
        }
    }
    
    long int sum = 0;
    for(int i = 0; i < 3; i++){
        for(int j = i + 1; j < 4; j++){
            for(int k = j + 1; k < 5; k++){
                sum += num[i] * num[j] * num[k];
            }
        }
    }

    printf("%lu\n", sum);
    return 0;
}


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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


int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    
    int A, B;
    cin >> A >> B;

    if(A<= 8 && B <= 8){
        cout << "Yay!" << endl;
    }else{
        cout << ":(" << endl;
    }

    return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    int ans = 0;
    for(int i=0;i<n;i++){
        if(i%2==0){
            ans += a[i];
        }
        else{
            ans -= a[i];
        }
    }
    cout << ans << endl;
}

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

int main()
{
    int A, B;
    cin >> A >> B;
    int a = A + B;
    int b = A - B;
    int c = A * B;
    int ans;
    if (a >= b && a >= c)
    {
        ans = a;
    }
    else if (b >= a && b >= c)
    {
        ans = b;
    }
    else if (c >= a && c >= b)
    {
        ans = c;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
d = {}
for n in range(N):
    a, b = map(int, input().split())
    d[a] = d.get(a, 0) + b

keys = list(d.keys())
keys.sort()

cnt = 0
for k in keys:
    cnt += d[k]
    if cnt >= K:
        print(k)
        exit()
print(keys[-1])


Measured memory_bytes: 10588
s=input()
g=0
p=0
ans=0
for i in range(len(s)):
    if s[i]=="g":
        if g>=(p+1):
            p+=1
            ans+=1
        else:
            g+=1
    else:
        if g>=(p+1):
            p+=1
        else:
            g+=1
            ans-=1
print(ans)

Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <functional>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;

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

    int n;
    cin >> n;

    vector<int> a(n * 3);
    for (int i = 0; i < n * 3; i++) {
        cin >> a[i];
    }

    vector<int64_t> sum(n + 1);

    {
        priority_queue<int, vector<int>, greater<>> q(a.begin(), a.begin() + n);
        int64_t s = 0;
        for (int i = 0; i < n; i++) {
            s += a[i];
        }
        sum[0] = s;
        for (int k = n; k < n * 2; k++) {
            if (a[k] > q.top()) {
                s += a[k] - q.top();
                q.pop();
                q.push(a[k]);
            }
            sum[k - n + 1] = s;
        }
    }

    {
        priority_queue<int> q(a.end() - n, a.end());
        int64_t s = 0;
        for (int i = n * 2; i < n * 3; i++) {
            s += a[i];
        }
        int64_t r = sum[n] - s;
        for (int k = n * 2 - 1; k >= n; k--) {
            if (a[k] < q.top()) {
                s += a[k] - q.top();
                q.pop();
                q.push(a[k]);
            }
            r = max(r, sum[k - n] - s);
        }
        cout << r << endl;
    }


    return 0;
}

Measured memory_bytes: 2560
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    A = LI()

    A.sort()
    print(A[-1] - A[0])

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 10132
N, M = map(int, input().split())
x = []

for i in range(M):
    x.append(list(map(int, input().split()))+[i])

x.sort()
y = []
prv_p = -1
idx = 1
for xx in x:
    if prv_p != xx[0]:
        prv_p = xx[0]
        idx = 1
    y.append([xx[-1],'{0:06d}{1:06d}'.format(xx[0], idx)])
    idx += 1

y.sort()
for yy in y:
    print(yy[1])


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

int main(void){
    long int H, N;
    cin >> H >> N;
    long int A[110000];
    long int count = 0;
    for(int i=0; i<N; i++){
        cin >> A[i];
        count += A[i];
    }
    if(count >= H){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let a: usize = iter.next().unwrap().parse().unwrap();
    let b: usize = iter.next().unwrap().parse().unwrap();

    let ans = if a == b {
        a*2
    }
    else {
        std::cmp::max(a, b)*2 - 1
    };

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


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

int main()
{
	int N, l, r, ans = 0;

	cin >> N;

	for (int i = 0; i < N; i++) {
		cin >> l >> r;
		if (l == r) {
			ans++;
		}

		else {
			ans += r - l + 1;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
S=input()
a=[0]*(len(S)+1)
for i in range(len(S)):
    if S[i]=="<":
        a[i+1]=max(a[i+1],a[i]+1)
for i in range(len(S)-1,-1,-1):
    if S[i]==">":
        a[i]=max(a[i],a[i+1]+1)
print(sum(a))

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

int main(){
	ios_base::sync_with_stdio(false), cin.tie(nullptr);
	string s;
	cin >> s;
	int k;
	cin >> k;
	reverse(s.begin(), s.end());
	s += '0';
	int cur = 0;
	while(true){
		if(s[cur] == '9'){
			s[cur] = '0';
			cur++;
		} else {
			s[cur] ++;
			break;
		}
	}
	int n = (int)s.size();

	long long ans = 0;
	for(int d = 0; d < n; d++){
		int nz = 0;
		for(int e = d+1; e < n; e++){
			if(s[e] != '0') nz++;
		}
		for(char v = '0'; v < s[d]; v++){
			// less digits
			int nzz = nz + (v != '0');
			if(nzz > k) continue;
			int need = k - nzz;
			long long cur = 1;
			for(int i = 0; i < need; i++) cur *= 9;
			for(int i = 0; i < need; i++){
				cur *= (d - i);
				cur /= (i + 1);
			}
			ans += cur;
		}
	}
	cout << ans << '\n';
}

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

int main()
{
  double b;
  while(cin >> b)
    {
      double a = b;
      b *= 2; 
      a += b;
      b /= 3; 
      a += b;
      b *= 2; 
      a += b;
      b /= 3; 
      a += b;
      b *= 2; 
      a += b;
      b /= 3; 
      a += b;
      b *= 2; 
      a += b;
      b /= 3; 
      a += b;
      b *= 2; 
      a += b;
      printf("%.8f\n", a);

      if(b>10)break;
    }
  return 0;
}

Measured memory_bytes: 1232
N = int(input())
B = list(map(int,input().split()))

A = []
A.append(B[0])
for i in range(N-2):
    if B[i] < B[i+1]:
        A.append(B[i])
    else:
        A.append(B[i+1])
A.append(B[N-2])

print(sum(A))

Measured memory_bytes: 9088
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>

using namespace std;
long long int gcd(long long int a,long long int b){
    if(a<b){
        long long int tmp = a;
        a=b;
        b=tmp;
    }
    long long int r = a%b;
    if(r==0){
        return b;
    }else{
        return gcd(b,r);
    }
}


int main(void){
    int T;
    cin >> T;
    for(int inkya=0;inkya<T;inkya++){
        long long int A,B,C,D;
        cin >> A >> B >> C >> D;
     
        if(D<B){cout << "No\n";continue;}
        if(A<B){cout << "No\n";continue;}
        
        long long int gcdBD=gcd(B,D);
        long long int n=(A-C)/B;
        
        long long int sita = A-(n+1)*B;
        long long int m=(C-sita)/gcdBD;
        
        long long int gs = sita + (m+1)*gcdBD;
        
//        cout << gcdBD << n << sita << m << gs;
        
        if(gs < B){cout << "No\n";continue;}
        cout << "Yes\n";
    }
    return 0;
}

Measured memory_bytes: 256
from collections import deque

K = int(input())

dq = deque()
for x in range(1, 10):
    dq.append(x)

idx = 1
while idx < K:
    x = dq.popleft()
    idx += 1

    r = x % 10

    if r > 0:
        nx = (x * 10) + (r - 1)
        dq.append(nx)

    nx = (x * 10) + (r)
    dq.append(nx)

    if r < 9:
        nx = (x * 10) + (r + 1)
        dq.append(nx)

ans = dq.popleft()
print(ans)


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

int main(){
    string s;
    cin >>s;
    if(s=="hi"||s=="hihi"||s=="hihihi"||s=="hihihihi"||s=="hihihihihi"){    cout << "Yes"<<endl;}else{    cout << "No"<<endl;}

    return 0;
}

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

int main(){
    int n,ans=0;
    cin>>n;
    vector<string> s(n);
    for(int i=0; i<n; i++) cin>>s[i];
    sort(s.begin(),s.end());
    for(int i=0; i<n; i++) {
        if(s[i] != s[i+1]) ans++;
    }
    cout<<ans;
}

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

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

  int N;
  cin >> N;
  vector<int> X(N), Y(N), H(N);
  for (int i = 0; i < N; i++) cin >> X.at(i) >> Y.at(i) >> H.at(i);

  for (int y = 0; y <= 100; y++) {
    for (int x = 0; x <= 100; x++) {
      int h = 0;
      for (int i = 0; i < N; i++) {
        if (H.at(i)) {
          int tmp = H.at(i) + abs(X.at(i) - x) + abs(Y.at(i) - y);
          if (!h) h = tmp;
          else if (h != tmp) goto NG;
        }
      }
      for (int i = 0; i < N; i++) {
        if (!H.at(i)) {
          if (h > abs(X.at(i) - x) + abs(Y.at(i) - y)) goto NG;
        }
      }
      cout << x << " " << y << " " << h << endl;
      return 0;
      NG:;
    }
  }
}


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

#define EHAB_FAWZY_FCI_AaRnoB ios::sync_with_stdio(NULL); cin.tie(NULL);
#define popcnt(x) __builtin_popcount(x)
#define compination(x) ((x*(x-1))/2)
#define all(x) x.begin() , x.end()
#define ll long long
#define ld long double
#define vii vector  <ll>
#define sii set     <ll>
#define vch vector  <char>
#define mii map     <ll,ll>
#define pii pair    <ll,ll>
#define PI 3.141592654

using namespace std;

const int mod = 998244353;
const int MAX = 100009;

ll arr[ MAX ],x,q,a,b,cnt;
bool visted[ MAX ];

int main()
{
    for ( int i = 1; i < MAX; i++ )
        arr[i] = 1;

    visted[1] = 1;
    cin >> x >> q;
    while ( q-- )
    {
        cin >> a >> b;

        if      ( visted[a] == true && arr[a] == 1 )
            visted[a] = false , visted[b] = true;
        else if ( visted[a] == true )
            visted[b] = true;

        arr[a]--; arr[b]++;
    }
    for ( int i = 1; i <= x; i++ )
        visted[i] == true ? cnt++ : 0;

    cout << cnt;
    return 0;
}



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

int main() {
	long long N;
	long long Y;
	long long a=1000,b=5000,c=10000;
	bool flag = true;
	cin >> N >> Y;
	long long i,j;
	for(i=0;i<N+1;i++){
	    for(j=0;j<N-i+1;j++){
	        if(a*i + b*j + c*(N-i-j) == Y){
	            cout << N-i-j << " " << j << " " << i << endl;
	            flag = false;
	            break;
	        }
	    }
	    if(!flag)break;
	}
	if(flag){
	    cout << "-1 -1 -1" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <limits.h>
#include <cstring>
#include <tuple>
#include <cassert>
#include <numeric>
using namespace std;
// type alias
typedef long long LL;
typedef vector < int > VI;
typedef unordered_map < int, int > MAPII;
typedef unordered_set < int > SETI;
typedef pair< int , int > II;
typedef tuple< int, int, int > III;
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// minmax
#define SMAX(a,b) a = max(a,b)
#define SMIN(a,b) a = min(a,b)
// debug cerr
#define TRACE true
#define dump(x) if(TRACE) { cerr << #x << " = " << (x) << endl; }
#define dump2(x,y) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << endl; }
#define dump3(x,y,z) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << endl; }
#define dump4(x,y,z,a) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << ", " << #a << " = " << (a) << endl; }
#define dumpAR(ar) if(TRACE) { FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }

/*
 
 8/7/2018
 
 23:45-
 
 */

// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG x.cpp && ./a.out
const int MAX_N=1e5+1;
int N,C;
LL A[MAX_N];
vector<II> X[30];
void solve() {
  REP(i,C)sort(X[i].begin(),X[i].end());
  map<int,int> imos;
  REP(c,C) {
    int M=SZ(X[c]);
    REP(i,M-1) {
      if(X[c][i].second==X[c][i+1].first) {
        X[c][i+1].first=X[c][i].first;
      } else {
        imos[X[c][i].first-1]++;
        imos[X[c][i].second]--;
      }
    }
    if(M>0) {
      imos[X[c][M-1].first-1]++;
      imos[X[c][M-1].second]--;
    }
  }
  int res=0,cur=0;
  FORR(kvp,imos) cur+=kvp.second,SMAX(res,cur);
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  cin>>N>>C;
  REP(i,N) {
    int s,t,c; cin>>s>>t>>c;
    s*=2,t*=2,--c;
    X[c].emplace_back(s,t);
  }
  solve();
  return 0;
}


Measured memory_bytes: 7424
#include <bits/stdc++.h>
#include<iostream>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>

#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define rrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--)

#define fi first
#define se second

using namespace std;

using ll = long long;
using v_int = vector<int>;
using v2_int = vector<v_int>;
using v_ll = vector<ll>;
using v2_ll = vector<v_ll>;
using v_string = vector<string>;
using v_bool = vector<bool>;
using v2_bool = vector<v_bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

const double PI = 3.1415926535897932;
const int INF = (int)2e9;
const ll LINF = (ll)2e18;
const ll MOD = 1000000007;
const int dc[8] = {1, -1, 0,  0, 1, -1,  1, -1};
const int dr[8] = {0,  0, 1, -1, 1,  1, -1, -1};

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p) {
    return o << "{" << p.first << "," << p.second << "}";
}
template<typename T> inline
istream& operator>>(istream &is, vector<T> &vec) {
    for(auto &v : vec) { is >> v; }
    return is;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &vec) {
    for(auto &v : vec) { os << v << ",";}
    return os;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<vector<T> > &mat) {
    for(auto &row : mat) { os << row << endl; }
    return os;
}

template<typename T> inline
void chmin(T &a, T b) { a = min(a, b); }
template<typename T> inline
void chmax(T &a, T b) { a = max(a, b); }

int main(void)
{
    int n;
    cin >> n;
    int ans = 1;
    rep(i,3) {
        ans *= n;
    }
    cout << ans << endl;
    return 0;
} /*atcoder*/



Measured memory_bytes: 3568
def read_input():
    s = input().strip()
    return s

def submit():
    s = read_input()
    rev_s = s[::-1]

    targets = ['dream', 'dreamer', 'erase', 'eraser']
    rev_targets = [t[::-1] for t in targets]

    while True:
        if not rev_s:
            print('YES')
            return

        for t in rev_targets:
            if rev_s.startswith(t):
                rev_s = rev_s[len(t):]
                break
        else:
            print('NO')
            return

if __name__ == '__main__':
    submit()


Measured memory_bytes: 134244
#include <iostream>
#include <cmath>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;

ll euclid(ll a, ll b)
{
    while (b != 0)
    {
        ll c = b;
        b = a % b;
        a = c;
    }
    return a;
}
int main()
{
    ll n;
    cin >> n;
    vector<ll> v(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    ll result = v[0];
    for (int i = 1; i < n; i++)
    {
        result = euclid(result, v[i]);
        if (result == 1)
        {
            cout << 1;
            return 0;
        }
    }
    cout << result;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <iomanip>
#include <assert.h>
#include <string>
#include <algorithm>

using namespace std;
class dice{
	
public:	
	int a[7];
	dice(){ for (int i = 1; i <= 6; ++i) a[i] = i + 1; }
	void set(int i, int n){ assert(1<=i && i<=6); a[i] = n; }
	void rot(char ch){
		assert(ch=='W' || ch=='N' || ch=='S' || ch=='E');
		int tmp = a[1];
		switch (ch)
		{
		case 'W':
			a[1] = a[3]; a[3] = a[6]; a[6] = a[4]; a[4] = tmp;
			break;
		case 'E':
			a[1] = a[4]; a[4] = a[6]; a[6] = a[3]; a[3] = tmp;
			break;
		case 'N':
			a[1] = a[2]; a[2] = a[6]; a[6] = a[5]; a[5] = tmp;
			break;
		case 'S':
			a[1] = a[5]; a[5] = a[6]; a[6] = a[2]; a[2] = tmp;
			break;
		}
	}
	int top(){ return a[1]; }
	int south(){ return a[2]; }
	int west(){ return a[4]; }
	int east(){ return a[3]; }
	int north(){ return a[5]; }
	int bottom(){ return a[6]; }
	friend bool operator==(dice d1, dice d2){
		if (d1.top() == d2.top() &&
			d1.south() == d2.south() &&
			d1.north() == d2.north() &&
			d1.east() == d2.east() &&
			d1.west() == d2.west() &&
			d1.bottom() == d2.bottom()
			) return true;
		return false;
	}
};
bool isTrue(dice D1, dice D2){
	for (int k = 0; k < 4; ++k){
		for (int i = 0; i < 4; ++i){
			for (int j = 0; j < 4; ++j){
				if (D1 == D2) return true;
				D1.rot('W');
			}
			D1.rot('N');
		}
		D1.rot('W');
	}
	return false;
}
int main(){
	dice D1,D2;
	int a[6], b[6];
	for (int i = 0; i < 6; ++i){ cin >> a[i]; D1.set(i + 1, a[i]); }
	for (int i = 0; i < 6; ++i){ cin >> b[i]; D2.set(i + 1, b[i]); }

	if (isTrue(D1, D2)) cout << "Yes\n"; else cout << "No\n";
}

Measured memory_bytes: 1124
#include<iostream>
#include<sstream>
#include<vector>
#include<string>
#include<algorithm>
#include<unordered_map>
using namespace std;

int main(){
  int N;
  cin>>N;
  vector<string> s(N);
  for(int i=0; i<N; i++){
    cin>>s[i];
    sort( s[i].begin(),s[i].end() );
  }
  unordered_map<string,unsigned long long> umap;
  for(int i=0;i<N; i++){
    if(umap.count(s[i])==0){
      umap[s[i]]=1;
    }else{
      umap[s[i]]++;
    }
  }
  unsigned long long ans = 0;
  unsigned long long buf;
  for(auto itr = umap.begin(); itr != umap.end(); itr++){
    buf=itr->second;
    ans += (unsigned long long)(buf*(buf-1)/2);
  }
  cout << ans << endl;
  return 0; 
}


Measured memory_bytes: 17700
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6+5 , M = 998244353, OO = 0x3f3f3f3f;
typedef long long ll;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);
const double Pii = 3.14159265359;
int n, m, mxk, X1, Y1, X2, Y2;
bool grid[N];
int dis[N];
char ch;
int cr[] = {-1, 1, 0, 0};
int cc[] = {0, 0, -1, 1};

bool valid(int nr, int nc)
{
    return (nr >= 0 && nr < n && nc >= 0 && nc < m);
}

void BFS1(int X1, int Y1)
{
    memset(dis, OO, sizeof dis);
    dis[X1*m+Y1] = 0;
    queue<pair<int, int>> q;
    q.push({X1, Y1});
    while(!q.empty())
    {
        pair<int, int> pu = q.front();
        q.pop();
        for(int k=0; k<4; ++k)
        {
            int kused = 0;
            bool ok = 1;
            int nr = pu.first;
            int nc = pu.second;
            while(kused < mxk && ok)
            {
                nr += cr[k];
                nc += cc[k];
                if(valid(nr, nc) && grid[nr*m+nc] && dis[nr*m+nc] >= dis[pu.first*m+pu.second]+1)
                {
                    if(dis[nr*m+nc] > dis[pu.first*m+pu.second] + 1)
                    {
                        q.push({nr, nc});
                        dis[nr*m+nc] = dis[pu.first*m+pu.second] + 1;
                    }
                    kused++;
                }
                else ok = 0;
            }
        }
    }
}



int main()
{
    FIO
    cin >> n >> m >> mxk >> X1 >> Y1 >> X2 >> Y2;
    X1--; Y1--; X2--; Y2--;
    for(int i=0; i<n; ++i)
    {
        for(int j=0; j<m; ++j)
        {
            cin >> ch;
            if(ch == '.') grid[i*m+j] = 1;
            else grid[i*m+j] = 0;
        }
    }
    BFS1(X1, Y1);
    /*
    for(int i=0; i<n; ++i)
    {
        for(int j=0; j<m; ++j) cout << dis[i*m+j] << " ";
        cout << endl;
    }
    */

    if(dis[X2*m+Y2] == OO) cout << -1 << endl;
    else cout << dis[X2*m+Y2] << endl;
    return 0;
}


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

int n,m,dp[5][10010];
string a;
bool ans;

int main()
{
	int i;
	cin>>a;
	for(i=0;i<a.size();i++)
	{
		if(a[i]==',') cout<<' ';
		else cout<<a[i];
	}
}

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


int main() {
	int arr []={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	
	int caseNum;
	cin>>caseNum;
	cout<<arr[caseNum-1];
	return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    string S;
    cin >> S;

    ll cnt = 0, sum = 0;
    REP(i,0,SZ(S)) {
        if(S[i] == 'W') {
            sum += i - cnt;
            ++cnt;
        }
    }
    PR(sum);

    return 0;
}

/*



*/

Measured memory_bytes: 3728
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
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; }
typedef pair <ll,ll> P;

int main()
{
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i, N) {
        cin >> A[i];
        if (A[i] == K) {
            print("POSSIBLE");
            return 0;
        }
    }
    sort(all(A));
    ll g = A[0];
    rep(i, N-1) {
        g = gcd(g, A[i+1]);
    }
    if (A.back() - g < K) {
        print("IMPOSSIBLE");
        return 0;
    }
    if (K % g == 0) {
        print("POSSIBLE");
    } else {
        print("IMPOSSIBLE");
    }
    return 0;
}

Measured memory_bytes: 1024
n, k, q = map(int, input().split(' '))

a = []
for i in range(q):
    a.append(int(input()))

if k > q:
    for i in range(n):
        print('Yes')
else:
    right = [k - q for i in range(n)]
    for i in range(q):
        right[a[i] - 1] += 1
    
    for i in range(n):
        if right[i] > 0:
            print('Yes')
        else:
            print('No')

Measured memory_bytes: 11768
import java.util.*;
import java.math.*;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入
		int n = sc.nextInt();
		int countA = 0;
		int countB = 0;
		int countPair = 0;
		int countAB=0;

		for(int i=0;i<n;i++){
			String s = sc.next();
			boolean headIsB = s.startsWith("B");
			boolean tailIsA = s.endsWith("A");
			
				// System.out.println("countAB "+countAB);
			if(headIsB){
				countB++;
			}
			if(tailIsA){
				countA++;
			}
			if(headIsB&&tailIsA){
				countPair++;
			}
			int indexAB = s.indexOf("AB");
			// if(indexAB ==-1){
			// 	continue;
			// }

			while(indexAB>=0){
				countAB++;
				if(s.length()<=2){
					break;
				}
				s = s.substring(indexAB+2);
				indexAB = s.indexOf("AB");
				// System.out.println("s "+s);
				// System.out.println("indexAB "+indexAB);
			}

			// System.out.println(i+" "+ countAB);

		}

		countAB += Math.min(countA,countB);
		// System.out.println(countAB);
		// System.out.println(countA);
		// System.out.println(countB);
		// System.out.println(countPair);

			if(countPair!=0 && countPair == countB && countPair==countA){
				countAB--;
			}	
		

		System.out.println(countAB);
 
	}
}


Measured memory_bytes: 30784
n = gets.chomp.to_i
hash = Hash.new(0)
n.times do
    s = gets.chomp
    if hash.include?(s)
        hash[s] += 1
    else
        hash[s] = 1
    end
end
hash_kai =  hash.sort_by{|i,j| j }
arr = []
count = 0
value = hash_kai[-1]
value = value[-1]
while true
    if hash_kai != []
    key_value = hash_kai.pop
    else
        break
    end
    if key_value != []
        if value == key_value[-1]
        arr << key_value[0]
        else
            break
        end
    else
        break
    end
    count += 1
end
arr = arr.sort
arr.each {|i| puts i}

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

#define itn int
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())

using namespace std;

inline int nxt() {
	int x;
	scanf("%d", &x);
	return x;
}

int main() {
	string s;
	cin >> s;
	int ans = accumulate(all(s), (int)0) - (int)s.size() * '0';
	for (int i = (int)s.length() - 1; i >= 0; --i) {
		if (s[i] > '0') {
			--s[i];
			ans = max(ans, accumulate(all(s), (int)0) - (int)s.size() * '0');
		}
		s[i] = '9';
	}

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

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(i, a) for(auto& i: a)
using namespace std;
const int INF = INT_MAX >> 2;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
int n, ma, mb;
int dp[40][401][401];

int main() {
    rep(i, 0, 40) rep(j, 0, 401) rep(k, 0, 401) dp[i][j][k] = INF;
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> ma >> mb;
    vector<array<int, 3>> v(n);
    trav(i, v) {
        cin >> i[0] >> i[1] >> i[2];
    }
    dp[0][v[0][0]][v[0][1]] = v[0][2];
    dp[0][0][0] = 0;
    rep(i, 1, n) {
        rep(j, 0, 401) rep(k, 0, 401) dp[i][j][k] = dp[i-1][j][k];
        rep(j, 0, 401) {
            if(j < v[i][0]) continue;
            rep(k, 0, 401) {
                if(k < v[i][1]) continue;
                dp[i][j][k] = min(dp[i][j][k], dp[i-1][j - v[i][0]][k - v[i][1]] + v[i][2]);
            
            }
        }
    }
    // rep(i, 0, n) {
    //     rep(j, 0, 7) {
    //         rep(k, 0, 7) {
    //             debug(i, j, k, dp[i][j][k]);
    //         }
    //     }
    // }
    int ans = INF;
    for(int i = 1; ; ++i) {
        int ta = ma * i;
        int tb = mb * i;
        if(ta > 400 or tb > 400) break;
        ans = min(ans, dp[n-1][ta][tb]);
    }
    if(ans == INF) ans = -1;
    cout << ans;
    return 0;
}

Measured memory_bytes: 25344
x, k, d = map(int, input().split())

if abs(x) // d < k:
    if (k - abs(x) // d) % 2 == 0:
        print(abs(x) - abs(x) // d * d)
    elif (k - abs(x) // d) % 2 == 1:
        print(min(abs(abs(x) - (abs(x) // d - 1) * d),
                  abs(abs(x) - (abs(x) // d + 1) * d))
              )
elif abs(x) // d >= k:
    print(abs(x) - k*d)


Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define PRINT(V) for (auto v : (V)) cout << v << " "

int main()
{
    ll a, b, c, k; cin >> a >> b >> c >> k;
    
    ll ans = 0;
    if (a + b < k) {
        ans = 2*a + b - k;
    }else if (a < k){
        ans = a;
    }else{
        ans = k;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3556
#include<cstdio>
#include<algorithm>
typedef long long ll;
using namespace std;

int main() {
	ll a, b, c;

	scanf("%lld%lld%lld", &a, &b, &c);

	if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0) printf("0\n");
	else {
		if (a>c) swap(a, c);
		if (b>c) swap(b, c);
		printf("%lld\n", a*b);
	}
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(void){
    
    int a, b;
    cin >> a >> b;
    
    int seki = a * b;
    if(seki % 2 == 0){
        cout << "Even" << endl;
    }
    else{
        cout << "Odd" << endl;
    }
    
}

Measured memory_bytes: 3092
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<bitset>
//#define DEBUG
const int size=7368791;
using namespace std;
int main(){
  
  int m,n;
  bool saku[size+1];
  while(cin>>m>>n && (m || n)){
    for(int i=0;i<size+1;i++) saku[i]=false;
    for(int i=m;n>0;i++){
#ifdef DEBUG
      cout<<"n:"<<n<<endl;
#endif
      if(!saku[i]){
	saku[i]=true;
	for(int j=2;j<=size/i;j++)
	  saku[i*j]=true;
	n--;
      }
    }

#ifdef DEBUG
    for(int i=m;i<21;i++) cout<<i<<":"<<saku[i]<<endl;
#endif
    
    for(int i=m;i<size+1;i++)
    if(!saku[i]){ cout<<i<<endl; break; }
  }
  
  return 0;
}



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

int main() {
  int x, y;
  cin >> x >> y;
  int ans = 0;
  if (x <= 3) ans += (4-x) * 100000;
  if (y <= 3) ans += (4-y) * 100000;
  if (x == 1 && y == 1) ans += 400000;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define inf 123456789012345678
#define ll long long
#define C 1000006ll
using namespace std;

ll ans=inf,n,s;

ll f(ll ba,ll ne) {

  if(ba>ne) return ne;
  return f(ba,ne/ba)+(ne%ba);

}

int main() {

  scanf("%lld %lld",&n,&s);
  for(int i=2;i<=C;i++) {
    ll res=f(i,n);
    if(res==s) {
      ans=i;
      break ;
    }
  }
  for(int i=1;i<=min(C,s);i++) {
    ll rem=s-i;
    ll fn=n-rem;
    if(fn%i==0 && fn/i>i && fn/i>rem) {
      ans=min(ans,fn/i);
    }
  }
  if(n==s) ans=min(ans,n+1);
  if(ans==inf) printf("-1");
  else printf("%lld",ans);

}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
using namespace std;
 
int N, K, H[100100], D[100100];
int main()
{
	scanf("%d %d", &N, &K);
 
	for (int i=1;i<=N;i++) scanf("%d", &H[i]);
	for (int i=2;i<=N;i++){
		D[i] = D[i-1] + abs(H[i-1]-H[i]);
		for (int k=2;k<=K;k++){
			if (i > k && D[i] > D[i-k] + abs(H[i-k]-H[i]))
				D[i] = D[i-k] + abs(H[i-k]-H[i]);
		}
	}
	printf("%d\n", D[N]);
 
	return 0;
}

Measured memory_bytes: 2496
#include<bits/stdc++.h>
using namespace std;
#define max(a,b) (a<b?b:a)
#define abs(x) (x<0?(-x):x)
#define F(i,L,R) for (int i = L; i < R; i++)
#define FE(i,L,R) for (int i = L; i <= R; i++)
#define RF(i,L,R) for (int i = L; i > R; i--)
#define RFE(i,L,R) for (int i = L; i >= R; i--)
#define getI(a) scanf("%d", &a)
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define VgetI(n) int (n); scanf("%d",&(n))
#define VgetII(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))
#define ll long long
#define INF 2000000000
#define nINF -2000000000
#define MOD 1e9+7
#define PI 3.1415926535897932384626
bool cmp(int a,int b){
	return a>b;
}
int main(){
	int n,k;
	while(~getII(n,k)){
		int arr[n],ans=INF;
		F(i,0,n) getI(arr[i]);
		sort(arr,arr+n,cmp);
		F(i,0,n-k+1) if(arr[i]-arr[i+k-1]<ans) ans=arr[i]-arr[i+k-1];
		printf("%d\n",ans);
	}
}


Measured memory_bytes: 640
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
#define out(s) cout<<s<<endl;
#define Reverse(x) reverse(all(x));
#define Sort(x) sort(all(x));
#define pb(s) push_back(s);
#define sp " " 
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(lli i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    cout << std::fixed << std::setprecision(10);
    lli s;
    cin>>s;
    set<lli> rec;
    while (!rec.count(s)){ 
        rec.insert(s);
        (s%2==0?s/=2:s=3*s+1);
    }
    out(rec.size()+1);
}

Measured memory_bytes: 3632
def main():
  N, T = (int(_) for _ in input().split())
  t = [int(_) for _ in input().split()]
  ret = T
  for i in range(N-1):
    if t[i+1] < t[i] + T:
      ret += t[i+1] - t[i]
    else:
      ret += T
  print(ret)
  return

if __name__ == '__main__':
  main()

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

using namespace std;

int main()
{
  
  long n;cin>>n;
  while(n>0){
  if(n%10==7) {
  cout<<"Yes\n"; break;
  } 
    n=n/10;
  }
  if(n==0) cout<<"No\n";
return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
#define deb(x) cout << #x": " << (x) << endl;

const int N = 1e3;
const lli INF = 1e18;
const lli MOD = 1e9+7;

vi m;
vi primes(1,2);
vector<vector<ld>>nk;
void sieve(){
	m = vi(N+1,0);
	for(int i = 4; i<N; i+=2)m[i]=1;
	for(int i = 3; i*i<=N; i+=2)if(!m[i])for(int j = i*i; j<N; j+=i)m[j]=1;
	for(int i = 3; i<N; i+=2)if(!m[i])primes.pb(i);
}

void pascal(){
	nk =vector<vector<ld>>(N,vector<ld>(N,0.0));
	fore(i,0,N)nk[i][0]=nk[i][i]=1.0;
	fore(i,1,N)fore(j,1,i)nk[i][j]=nk[i-1][j-1]+nk[i-1][j];
}

lli gcd(lli a, lli b){return (b?gcd(b,a%b):a);}

lli lcm(lli a, lli b){
	if(a<b)swap(a,b);
	lli c = gcd(a,b);
	a/=c;
	return a*b;
}

int popcount(lli x) { return __builtin_popcountll(x); }

lli poww(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = res * a;
		a = a*a;
		b/=2;
	}
	return res;
}

lli powm(lli a, lli b, lli mod = MOD){
	lli res =1;
	while(b){
		if(b&1) res = (res * a)%mod;
		a = (a*a)%mod;
		b/=2;
	}
	return res;
}

bool isPrime(lli x){
	if(x==1)return 0;
	for(auto i:primes){
		if(i*i>x)return 1;
		if(x%i==0)return 0;
	}
	return 1;
}

// ---- コーディングはここから！ ('-')7


int main(){_
	lli n,k; cin>>n>>k;
	vl v(n);
	fore(i,0,n)cin>>v[i];
	sort(all(v),greater<lli>());
	lli L = 1, R=v[0],last=R;
	auto f=[&](lli mid){
		lli r = 0;
		fore(i,0,n){
			if(v[i]<=mid)break;
			r+=(v[i]/mid);
			if(v[i]%mid==0)r--;
		}
		return r<=k;
	};
	while(L<=R){
		lli mid = (L+R)/2;
		if(f(mid))R=mid-1,last=mid;
		else L = mid+1;
	}
	cout<<last<<ENDL;

}


Measured memory_bytes: 4780