akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[a]; if (a != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)///
int n, m;
int dfs(vvi &dp, const vi &c, const vi &x, int i,int j) {
	if (i == n)return 0;
	if (dp[i][j] != -1)return dp[i][j];
	int ret = INF;
	REP(k, m) {
		int tmp = j + c[k];
		if (tmp > 255)tmp = 255;
		if (tmp < 0)tmp = 0;
		ret = min(ret, (tmp - x[i])*(tmp - x[i]) + dfs(dp, c, x, i + 1, tmp));
	}
	return dp[i][j] = ret;
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	while (1) {
	
		cin >> n >> m;
		if (!n)break;
		vi c(m), x(n);
		REP(i, m)cin >> c[i];
		REP(i, n)cin >> x[i];
		vvi dp(n, vi(256, -1));
		cout << dfs(dp, c, x, 0, 128) << endl;
	}
	return 0;
}

Measured memory_bytes: 25744
import java.util.*;


public class Main {
	public static int dfs(int p, int q, int a, int n, int num, int den, int k, int cur){
		if(p * den == q * num){
			return 1;
		}
		if(k == n || p * den < q * num){
			return 0;
		}
		int ret = 0;
		
		for(int i = cur; i * den <= a; i++){
			ret += dfs(p,q,a,n,num*i+den,i*den,k+1,i);
		}
		
		return ret;
	}
	
	public static void main(String[] args) {
		try {
			Scanner sc = new Scanner(System.in);
			while(true){
				int p = sc.nextInt(), q = sc.nextInt(), a = sc.nextInt(), n = sc.nextInt();

				if(p == 0 && q == 0 && a == 0 && n == 0){
					sc.close();
					break;
				}
				System.out.println(dfs(p,q,a,n,0,1,0,1));
			}
			sc.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 23592
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  int N,T,c,t,mn=1000;
  int f=0;
  cin>>N>>T;
  for(int i=0;i<N;i++){
    cin>>c>>t;
    if(t<=T){
      mn=min(mn,c);
      f=1;
    }
  }
  if(f) cout<<mn<<endl;
  else cout<<"TLE"<<endl;
  return 0;

}


Measured memory_bytes: 256
#include <iostream>

int main(int argc, const char * argv[]) {
    int x, y;
    for ( ; std::cin >> x >> y && !(x == 0 && y == 0); ) {
        if (x < y) {
            std::cout << x << " " << y << std::endl;
        } else {
            std::cout << y << " " << x << std::endl;
        }
    }
    return 0;
}

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

int main() {
    int r,c;
    cin >> r >> c;
    vector<vector<int>> a(r+1,vector<int>(c+1,0));
    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++) {
            cin >> a[i][j];
            a[i][c] += a[i][j];
        }
    }
    for (int j = 0; j < c+1; j++) {
        for (int i = 0; i < r; i++) {
            a[r][j] += a[i][j];
        }
    }
    for (int i = 0; i < r+1; i++) {
        for (int j = 0; j < c+1; j++) {
            cout << a[i][j];
            if (j==c) {
                cout << endl;
            }else{
                cout << ' ';
            }
        }
    }
    
    return 0;
}



Measured memory_bytes: 3184
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
#define INF 999999999
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vpii> vvpii;

int main() {
  int a;
  while (cin >> a, a) {
    int b[a], c[a - 1];
    rep(i, a) cin >> b[i];
    sort(b, b + a);
    rep(i, a - 1) c[i] = b[i + 1] - b[i];
    cout << *min_element(c, c + a - 1) << endl;
  }
  return 0;
}

Measured memory_bytes: 3008
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()

ans = N // 1000
ans2 = N - (ans*1000)

if ans2 == 0:
    print(0)
else:
    print(1000-ans2)

Measured memory_bytes: 61728
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>

using namespace std;

int main() {
  int h,w;
  cin >> h >> w;
  char s[100][100];
  
  for(int i = 0; i < h; i++) {
    for(int j = 0; j < w; j++)
      cin >> s[i][j];
  }
  
  for(int i = 0; i < h; i++) {
    for(int j = 0; j < w; j++) {
      if(s[i][j] == '#') {
        if(i-1 >= 0 & s[i-1][j] == '#') continue;
        else if(j-1 >= 0 & s[i][j-1] == '#') continue;
        else if(j+1 < w & s[i][j+1] == '#') continue;
        else if(i+1 < h & s[i+1][j] == '#') continue;
        else {
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 3528
def main():
    n=int(input())
    s=input()
    r,g,b=[],[],[]
    if n<=3:
        print(0)
    else:
        for i in range(n):
            if s[i]=="R":
                r.append(i)
            elif s[i]=="G":
                g.append(i)
            else:
                b.append(i)
        ans=len(r)*len(g)*len(b)
        for i in range(len(r)):
            for j in range(len(g)):
                if (r[i]+g[j])%2==0 and s[(r[i]+g[j])//2]=="B":
                        ans-=1
        for i in range(len(g)):
            for j in range(len(b)):
                if (g[i]+b[j])%2==0 and s[(g[i]+b[j])//2]=="R":
                        ans-=1
        for i in range(len(r)):
            for j in range(len(b)):
                if (r[i]+b[j])%2==0 and s[(r[i]+b[j])//2]=="G":
                        ans-=1
        print(ans)
if __name__=="__main__":
    main()

Measured memory_bytes: 9332
N=int(input())
List = list(map(int, input().split()))
trial = 0
res = 0
for i in range(N-1):
  if List[i+1] <= List[i]:
    trial += 1
  else:
    res = max(res,trial)
    trial = 0
res = max(res,trial)
print(res)

Measured memory_bytes: 20464
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <sstream>
#include <istream>
#include <iomanip>
#include <typeinfo>
#include <stack>

using namespace std;
typedef long long ll;
string N;

int main(){
    
    cin >> N;
    vector<int > L(N.length());

    int i = 0;
    for(i = 0; i < N.length(); i++){
        L[i] = stoi(N.substr(i,1));
    }
    L.push_back(1145141919);

    if(N.length() == 1){
        cout << N << endl;
        return 0;
    }

    int ans = 0;
    int f = 0;
    for(i = 0; i < N.length(); i++){
        if(L[i] < 9){
            for(int j = i + 1; j < N.length(); j++){
                if(L[j] != 9){
                    ans += L[i] - 1;
                    f = 1;
                    break;
                }
            }
            if(f != 1){
                ans += L[i];
            }
            ans += (N.length() - (i + 1)) * 9;
            break;
        }else if(L[i] == 9){
            if(L[i+1] < 9){
                ans += L[i] - 1;
                ans += (N.length() - (i + 1)) * 9;
                break;
            }else{
                ans += 9;
            }
        }
    }

    cout << ans << endl;

    

} 

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(void) {
	int i, n = 0, len, palindrome;
	char s[101];

	while (scanf(" %100s ", s) != EOF) {
		len = strlen(s);
		palindrome = 1;
		for (i = 0; i < len; i++) {
			if (s[i] != s[len - i - 1]) {
				palindrome = 0;
				break;
			}
		}
		n += palindrome;
	}
	printf("%d\n", n);
	return 0;
}

Measured memory_bytes: 544
// ABC 148-B
// 2019.12.22 bal4u

#include <stdio.h>
#include <string.h>

char S[105], T[105];

int main()
{
	int i, N;
	
	scanf("%d%s%s", &N, S, T);
	for (i = 0; i < N; ++i) {
		putchar(S[i]), putchar(T[i]);
	}
	putchar('\n');
	return 0;
}


Measured memory_bytes: 128
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int ans = 3;
        if(a==b && b==c)
            ans = 1;
        else if(a==b || b==c || a==c)
            ans = 2;

        System.out.println(ans);
    }
}

Measured memory_bytes: 21588
#include<bits/stdc++.h>
using namespace std;
 
int mincost(int n ,vector<int>&height)
{
     vector<int>dp(n,0);
     for(int i =1;i<n;i++)
     {    if(i==1)dp[i] = dp[i-1]+abs(height[i]-height[i-1]);
       else
       dp[i] = min(dp[i-1]+abs(height[i]-height[i-1]),dp[i-2]+abs(height[i]-height[i-2]));
     }
    return dp[n-1];
}
int main(){
    int n ;
  cin>>n;
  vector<int>height(n);
  for(int i=0;i<n;i++)
  {  cin>>height[i];
  }
  cout<<mincost(n,height)<<endl;
  
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstring>
using namespace std;
char s[110][110];
int main() {
    int h , w;
    cin >> h >> w;
    for(int i = 1 ; i <= h ; i++) {
        cin >> (s[i] + 1);
    }
    for(int i = 0 ; i <= h + 1 ; i++) {
        for(int j = 0 ; j <= w + 1 ; j++) {
            if(i == 0 || j == 0 || i == h + 1 || j == w + 1)
                cout << '#';
            else
                cout << s[i][j];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int main(){
  int n,m;
  cin >> n >> m;
  ll sukunai = min(n,m);
  ll ooi = max(n,m);
  if (sukunai == 1){
    if(ooi == 1){
      cout << 1;
      return 0;
    }
    if(ooi == 2){
      cout << 0;
      return 0;
    }
    
    cout << ooi - 2;
    return 0;
  }
  
  ll ans = (sukunai - 2) * (ooi - 2);
  cout << ans;
  
  return 0;
}

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

int main(){
  int K, N; cin >> K >> N;
  vector<int> A(N+1);
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  A[N]=K+A[0];
  int m=0;
  for(int i=0;i<N;i++){
     m=max(m,A[i+1]-A[i]);
  }
  cout << K-m << endl;
  return 0;
}

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

int main(){
  int N;
  cin >> N;
  
  int d[110];
  
  for(int i=0;i<N;++i)
    cin >> d[i];
    
  int n[110]={0};
  
  for(int i=0;i<N;++i)
    n[d[i]]++;
  
  int t=0;
  for(int i=0;i<=100;++i){
    if(n[i]>0)
      ++t;
  }
  cout << t << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = sc.nextInt();
			if (n == 0)
				break;
			int sum = 0;
			int max = 0;
			int min = 1000;
			for (int i = 0; i < n; i++) {
				int point = sc.nextInt();
				sum += point;
				max = Math.max(point, max);
				min = Math.min(point, min);
			}
			int result = (sum - max - min) / (n - 2);
			System.out.println(result);
		}
		sc.close();
	}
}

Measured memory_bytes: 20948
n = gets.to_i
h = gets.split.map(&:to_i)
(1...(n - 1)).each do |i|
  h[i] -= 1 if h[i] > h[i + 1] || h[i] - h[i - 1] > 0
  if (h[i - 1] > h[i]) || (h[i] > h[i + 1])
    puts 'No'
    exit
  end
end
puts 'Yes'


Measured memory_bytes: 8580
N,m = gets.chomp.split.map(&:to_i)
map = []
N.times do
  map.push(gets.chomp.split.map(&:to_i))
end
map.sort! {|a,b| a[0] <=> b[0]}

cost = 0
map.each do |item|
  if m > item[1]
    cost += item[0] * item[1]
    m -= item[1]
  else
    cost += item[0] * m 
    puts cost
    exit
  end
end


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

int a,s;int k=0;
  cin>>a>>s;
  int sum=0;
  int d[10000];
  for (int i=0;i<a;i++)
  {cin>>d[i];
   
  }
  for (int i=0;i<a;i++)
  {
     sum+=d[i];
      if(sum<=s)
       { k++;
        }
   else 
       break;}
  cout<<k+1;
    











return 0;}

Measured memory_bytes: 256
mod = 10**9+7
H,W = map(int,input().split())
maze = [list(input()) for _ in range(H)]
dp = [[0]*W for _ in range(H)]
dp[0][0]=1

for i in range(H):
    for j in range(W):
        if i+1<H and maze[i+1][j]==".":
            dp[i+1][j] += dp[i][j]%mod
        if j+1<W and maze[i][j+1]==".":
            dp[i][j+1] += dp[i][j]%mod
            
print(dp[H-1][W-1]%mod)

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

int main()
{
while(true){	
		int H,W,k=0;
		cin>>H>>W;
		if(H==0&&W==0) break;
		while (k<H)
		{	
			for(int i=0;i<W;i++){
				if(k%2==1&&i%2==1||k%2==0&&i%2==0)cout<<"#";
				else cout<<".";
			}
			cout<<endl;
			k++;
		}
		cout<<endl;
	}
   return 0;
}


Measured memory_bytes: 3052
#include <cstdio>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <map>
using namespace std;
const int N = 1e5+5;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
int n, ans;
pair<int, int> p[N];
int main()
{
    n = read(); 
    for(int i = 1; i <= n; ++i) p[i].first = read(), p[i].second = i&1;
    sort(p+1, p+1+n);
    for(int i = 2; i <= n; i += 2) ans += p[i].second;
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 896
N = int(input())
a = list(map(int, input().split()))
m = 10**18
M = -10**18
m_idx = -1
M_idx = -1

for i in range(N):
    if a[i]<m:
        m = a[i]
        m_idx = i
    
    if a[i]>M:
        M = a[i]
        M_idx = i
        
ope = []

if abs(m)<=abs(M):
    for i in range(N):
        ope.append((M_idx, i))
    
    for i in range(N-1):
        ope.append((i, i+1))
else:
    for i in range(N):
        ope.append((m_idx, i))
    
    for i in range(N-1, 0, -1):
        ope.append((i, i-1))
    
print(len(ope))

for x, y in ope:
    print(x+1, y+1)

Measured memory_bytes: 62020
#include <stdio.h>

int main(void){
    int a,b,c,d,i;
    scanf("%d %d %d %d",&a,&b,&c,&d);

    for(i=0;i<300;i++){
        c=c-b;
        if(c<=0){
            printf("Yes");
            break;
        }
        a=a-d;
        if(a<=0){
            printf("No");
            break;
        }

    }
    return 0;

}

Measured memory_bytes: 1720
# 1って書かれたM個と2って書かれたN個があるよって感じのncr
# 「N+M個のうちM個のうち2個」だとわけがわからんので別の方法を考える。
# 全体から奇数になるやつを引けばいいかもしれない ncr(N+M,2)-ncr(N, 1)-ncr(M, 1) = ncr(N+M, 2)-(N*M)

n, m = map(int, input().split())


def ncr(n, r):
    res = 1
    for i in range(1, r + 1):
        res = res * (n - i + 1) // i
    return res


print(ncr(n + m, 2) - n * m)


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

int main(){
  int n,ans=0;
  cin>>n;
  
  vector<int> button;
  button.emplace_back(0);
  rep(i,0,n){
    int tmp=0;
    cin>>tmp;
    button.emplace_back(tmp);
  }

  int i=1;
  do{
    int tmp=i;
    ans++;
    i=button[i];
    button[tmp]=0;
    if(i==0){ans=0;break;}
  }while(i!=2);
  
  if(ans!=0){cout<<ans<<endl;}
  else{cout<<-1<<endl;}

  return 0;

}

Measured memory_bytes: 892
s = list(input())
t = list(input())
l = min(len(s),len(t))
if len(s)>len(t):
    x = 1
elif len(s)<len(t):
    x = 2
else:
    x = 0
for i in range(l):
    print(s[i],end = "")
    print(t[i],end = "")
if x == 1:
    print(s[-1])
elif x == 2:
    print(t[-1])

Measured memory_bytes: 9116
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <bitset>
#include <stack>
#include <deque>
using namespace std;
typedef pair<int, int> pii;
typedef long long LL;

int main() {
    int N, A, B;
    scanf("%d %d %d", &N, &A, &B);
    int ans = 0;
    if (A + B >= N) ans = (A + B) - N;
    printf("%d %d\n", min(A, B), ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL mod=1e9+7;
const int maxn=2e5+10;
const LL inf=1e18;
int a[maxn];
int main()
{
    int m,n;
    cin>>n>>m;
    int sum=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];sum+=a[i];
    }
    int x=0;
    for(int i=1;i<=n;i++){
        if(a[i]*4*m>=sum){
            x++;
        }
    }
    if(x>=m){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int n, m[100], i, j, c;
	while (cin >> n && n)
	{
		c = 0;
		for (i = 0; i < n; i++)
			cin >> m[i];
		for (i = 0; i < n; i++)
		{
			for (j = 0; j < n-1; j++)
			{
				if (m[j] > m[j+1])
				{
					swap(m[j], m[j+1]);
					c++;
				}
			}
		}
		cout << c << endl;
	}
}

Measured memory_bytes: 0
from collections import Counter
from math import factorial as F

N,A,B = map(int,input().split())

V = sorted(list(map(int,input().split())),reverse=True)

C = Counter(V)

#最低A個を獲得したときの平均測定
SUM = 0
LN = [0,0]
for i in range(A):
    if V[i] == LN[0]:
        LN[1] += 1
    else:
        LN[0] = V[i]
        LN[1] = 1
    SUM += V[i]
    
AVE = SUM/A

comb = 0
n = C[LN[0]]
if LN[1] == A: #AVEと同じものを取る
    for r in range(A,min(n,B)+1):
        comb += F(n) // (F(n-r)*F(r))
else:
    comb = F(n) // (F(n-LN[1])*F(LN[1]))
    
print("{0:.6f}".format(AVE))
print(comb)

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

ll dp[3100][3100][5];
ll value[3100][3100];

int main(){
  int r,c,k;
  cin >> r >> c >> k;
  memset(value,0,sizeof(value));
  for(int i=0;i<k;++i){
    ll R,C,V;
    cin >> R >> C >> V;
    value[R][C]=V;
  }

  for(int i=0;i<=r;++i){
    for(int j=0;j<=c;++j){
      for(int k=0;k<=3;++k){
        if(i-1>=0){
          dp[i][j][0]=max(dp[i][j][0],dp[i-1][j][k]);
          dp[i][j][1]=max(dp[i][j][1],dp[i-1][j][k]+value[i][j]);
        }

        if(j-1>=0){
          dp[i][j][k]=max(dp[i][j][k],dp[i][j-1][k]);
          if(k-1>=0){
            dp[i][j][k]=max(dp[i][j][k],dp[i][j-1][k-1]+value[i][j]);
          }
        }
      }
    }
  }

  ll ans=0;
  for(int i=0;i<=3;++i)ans=max(ans,dp[r][c][i]);


  cout << ans << endl;
  return 0;

}


Measured memory_bytes: 442060
s = input()
ns = s.replace("x","")
l = len(ns)

if ns[:l//2] == ns[l-1:(l+1)//2-1:-1]:
    ans = 0
    left = 0
    right = len(s) - 1
    while left <= right:
        if s[left] != s[right]:
            if s[left] == "x":
                right += 1
            else:
                left -= 1
            ans += 1
        left += 1
        right -= 1
else:
    ans = -1

print(ans)

Measured memory_bytes: 3316
#include <stdio.h>

int euclid(int a, int b);

int main(void) {
	int a, b;
	int gcd, lcm;

	while(scanf("%d", &a) != EOF) {
		scanf("%d", &b);
		gcd = euclid(a, b);
		lcm = a/gcd*b;

		printf("%d %d\n", gcd, lcm);
	}

	return 0;
}

int euclid(int a, int b) {
	int x, y;
	while(b > 0) {
		x = b;
		y = a%b;
		a = x;
		b = y;
	}
	return a;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long int X,K,D;
	cin >> X >> K >> D;
	long long int answer=0;
	X=abs(X);
	if(X/D>=K){
		answer=abs(X-K*D);
	}
	else if(X/D<K){
		int value=(X/D);
		if((K-value)%2==0){
			answer=abs((X-(value)*D));
		}
		else{
			answer=abs((X-(value+1)*D));
		}
	}
	cout << answer << endl;
}

Measured memory_bytes: 3624
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if (a < b) {
		cout << "a < b" << endl;
	}
	if (a > b) {
		cout << "a > b" << endl;
	}
	if (a == b) {
		cout << "a == b" << endl;
	}
	return 0;
}


Measured memory_bytes: 3080
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

int main() {

	int H, W, h, w;
	cin >> H >> W >> h >> w;

	cout << (H - h) * (W - w) << "\n";
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    string S; cin >> S;
    if (S == "ABC") {
        cout << "ARC" << endl;
    } else {
        cout << "ABC" << endl;
    }
    return 0;
}

Measured memory_bytes: 3592
s=[]
for i in input().split():
 n=len(s)-1
 if i=='+':s.append(s[n-1]+s[n]);s.pop(n-1);s.pop(n-1)
 elif i=='-':s.append(s[n-1]-s[n]);s.pop(n-1);s.pop(n-1)
 elif i=='*':s.append(s[n-1]*s[n]);s.pop(n-1);s.pop(n-1)
 elif i=='/':s.append(s[n-1]/s[n]);s.pop(n-1);s.pop(n-1)
 else:s.append(int(i))
print(*s)


Measured memory_bytes: 5600
#include <stdio.h>
char str[101];
int c[26],b=1;
int main() {
	scanf("%s",str);
	for(int i=0;str[i]!='\0';i++)
		c[str[i]-'a']++;
	for(int i=0;i<26;i++)
		if(c[i]%2) b=0;
	if(b) printf("Yes\n");
	else printf("No\n");
	return 0; 
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//List<String> list=new ArrayList<String>(Arrays.asList(s.split("")));
		//List<String> list=new ArrayList<String>();
		//int[] array = new int[1000000000*2];
		int n = sc.nextInt();
		int r = sc.nextInt();
		if(n>=10) {
			System.out.println(r);
		}
		else {
			int a = r+100*(10-n);
			System.out.println(a);
		}
	}
}

Measured memory_bytes: 21460
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll h, n; cin >> h >> n;
    vector<pair<ll, ll>> ab(n);
    rep(i, n) cin >> ab[i].first >> ab[i].second;

    // モンスターの体力をi減らすために消費する魔力の最小値
    vector<ll> dp(h+1, INFLL/2); dp[0] = 0;

    for(long long i=0; i<n; i++){
        for(long long j=0; j<=h; j++){
            dp[min(j+ab[i].first, h)] = min(dp[min(j+ab[i].first, h)], dp[j] + ab[i].second);
        }
    }
    cout << dp[h] << endl;
}

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

ll N, Q, A[100000], X[100000];
ll sum[100001], se[100001], so[100001];

bool check(ll x, ll a, ll b) {
  if (!(0 <= a && a < N)) return true;
  if (!(0 <= b && b < N)) return false;
  if (abs(A[b] - x) < abs(A[a] - x)) return true;
  if (abs(A[b] - x) == abs(A[a] - x)) return b < a;
  return false;
}

ll solve(ll x) {
  ll l = 1, h = N + 1;
  while (h - l > 1) {
    ll m = (l + h) / 2;
    ll p = (m + 1) / 2;
    ll q = m / 2;
    if (check(x, N - m, N - p)) h = m;
    else l = m;
  }
  return (sum[N] - sum[N - (l + 1) / 2]) + (N % 2 == 0 ? so[N - l] : se[N - l]);
}

int main(void) {
  cin >> N >> Q;
  REP(i, 0, N) cin >> A[i];
  REP(i, 0, Q) cin >> X[i];

  REP(i, 0, N) sum[i + 1] = sum[i] + A[i];
  REP(i, 0, N) se[i + 1] = se[i] + (i % 2 == 0 ? A[i] : 0);
  REP(i, 0, N) so[i + 1] = so[i] + (i % 2 == 1 ? A[i] : 0);

  REP(i, 0, Q) cout << solve(X[i]) << endl;
}

Measured memory_bytes: 5632
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>

bool pairCompare(const std::pair<int,int>& firstElof, const std::pair<int,int>& secondElof)
{
    return firstElof.second < secondElof.second;
}

int main(int argc, char** argv)
{
    int N;
    std::cin >> N;
    std::vector<std::pair<int,int>> T;

    for(int i=0;i<N;i++)
    {
        int A,B;
        std::cin >> A;
        std::cin >> B;
        std::pair<int,int> t;
        t.first = A;        
        t.second = B;
        T.push_back(t);        
    }
    std::sort(T.begin(),T.end(), pairCompare);

    bool ret = true;
    int sumA=0;
    for(int i=0; i<N;i++)
    {
        sumA += T[i].first;
        if(sumA>T[i].second){ret = false; break;}
    }
    if(ret){std::cout << "Yes";}
    else{std::cout << "No";}
    
    
    return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define itn int
#define gI gi

using namespace std;

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + (c ^ 48), c = getchar();
	return f * x;
}

string s;

int main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	getline(cin, s);
	int len = s.size();
	for (int i = 0; i < len; i+=1)
	{
		if (s[i] == s[i + 1]) {printf("%d %d\n", i + 1, i + 1 + 1); return 0;}
		if (s[i] == s[i + 2]) {printf("%d %d\n", i + 1, i + 2 + 1); return 0;}
	}
	puts("-1 -1");
	return 0;
}


Measured memory_bytes: 512
import sys

class Fenwick_Tree:
    def __init__(self, n):
        self._n = n
        self.data = [0] * n
    
    def add(self, p, x):
        assert 0 <= p < self._n
        p += 1
        while p <= self._n:
            self.data[p - 1] += x
            p += p & -p
    
    def sum(self, l, r):
        assert 0 <= l <= r <= self._n
        return self._sum(r) - self._sum(l)
    
    def _sum(self, r):
        s = 0
        while r > 0:
            s += self.data[r - 1]
            r -= r & -r
        return s


def main():
    input = sys.stdin.readline
    n, q = map(int, input().split())
    fw = Fenwick_Tree(n)
    for i, a in enumerate(map(int, input().split())): fw.add(i, a)
    for _ in range(q):
        t, a, b = map(int, input().split())
        if t == 0:
            fw.add(a, b)
        else:
            print(fw.sum(a, b))

if __name__ == "__main__":
    main()




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

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

ll lcm(ll a, ll b) {
  return a * b / gcd(a, b);
}

int main() {
    ll A, B, C, D;
  cin >> A >> B >> C >> D;
  ll na, nb;
  na = (A-1) - (A-1)/C - (A-1)/D + (A-1)/(lcm(C, D));
  nb = B - B/C - B/D + B/(lcm(C, D));
  
  cout << nb - na << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
import bisect
import numpy as np
import math
from collections import deque
from collections import defaultdict
from math import gcd

X, N = map(int, input().split())
P = list(map(int, input().split()))

for d in range(X+1):
    for s in [-1, 1]:
        ans = X + d * s
        if P.count(ans) == 0:
            print(ans)
            exit(0)



Measured memory_bytes: 26944
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

// code
// ------------------------------------------------
int main() {

  int d,n;
  cin >> d >> n;
  unsigned long long ans;

  ans = pow(100,d);


  if(n != 100)
  {
    ans = ans * n;
  }
  else
  {
    ans = ans * (n + 1);
  }
  

  cout << ans << endl;


  return 0;
}
// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


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

// ##### 本誌に書けなかったダイクストラ法の実装です #####

// 隣接リストでは相手の頂点番号だけ持っておけばよかったので、
// vector<vector<int>> で大丈夫だった、今回は辺の重みも
// 保持する必要があるので、データ構造 edge を用意する
// pair でもできるが、わかりやすいのはこっち？
struct edge{
    int to, cost;
};

const int INF = 999999999;

// startからの最短経路をすべての頂点に対して求める
vector<int> dijkstra(vector<vector<edge>> &G, int start){
    vector<int> dist(G.size(), INF);
    using pi = pair<int, int>;
    // 自動的にソートしておいてくれるqueueであるpriority_queueを使う
    // costが小さい順に並ぶようにする
    // pair(その時点での最短経路, 頂点番号)
    priority_queue<pi, vector<pi>, greater<pi>> que;
    dist[start] = 0;
    que.push(make_pair(dist[start], start));
    while(!que.empty()){
        int cost = que.top().first;
        int idx = que.top().second;
        que.pop();
        if(dist[idx] < cost) continue;
        for(edge e: G[idx]){   // vector<edge> G[idx]の中身を順に取り出しeに入れる
            if(dist[e.to] <= cost+e.cost) continue;
            dist[e.to] = cost+e.cost;
            que.push(make_pair(dist[e.to], e.to));
        }
    }
    return dist;
}

int main(){
    int n, m, r;
    cin >> n >> m >> r;
    vector<vector<edge>> G(n);
    for(int i=0; i<m; i++){
        int s,t,d;
        cin >> s >> t >> d;
        G[s].push_back((edge){t,d});
    }
    vector<int> ans = dijkstra(G, r);
    for(int i=0; i<n; i++){
        if(ans[i] == INF) cout << "INF" << endl;
        else cout << ans[i] << endl;
    }

}




Measured memory_bytes: 13096
// Created by sz
#include <bits/stdc++.h>
using namespace std;

int N,M, X[100005], L[100005];

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin>>N>>M;
    for(int i = 0 ; i<M; i++)cin>>X[i];
    
    sort(X, X+M);
    
    for(int i = 0; i< M-1; i++)L[i] = X[i+1] - X[i];
    
    sort(L,L+M-1);
    
    int res = 0;
    for(int i =0; i<M-1-(N-1);i++)res+=L[i];
    cout<<res<<endl;
    
    
    return 0;
}



Measured memory_bytes: 1024
import java.util.Scanner;


class Main{

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

	int n,A,B,C,D;
	n = in.nextInt();

	int[][] WRY = new int[n][1];
	for(int i=0;i<n;i++)WRY[i][0]=0;

	for(int i=0;i<n*(n-1)/2;i++){
	    A = in.nextInt();
	    B = in.nextInt();
	    C = in.nextInt();
	    D = in.nextInt();
	    if(C > D){
		WRY[A-1][0]+=3;
	    }
	    else if(D > C){
		WRY[B-1][0]+=3;
	    }
	    else {
		WRY[A-1][0]++;
		WRY[B-1][0]++;
	    }

	}
       
	int ookii=0;
	int tiisai=0;
	int onazi=0;

	for(int i=0;i<n;i++){
	    for(int j=0;j<n;j++){
		if(WRY[i][0]>WRY[j][0] && i != j)tiisai++;
		else if(WRY[i][0]<WRY[j][0] && i != j)ookii++;
		else if(WRY[i][0] == WRY[j][0] && i!=j)onazi++;
	    }
	    if(tiisai == 0){
		System.out.println(n-onazi);
	    }else if(ookii == 0){
		System.out.println(1);
	    }else{
	    System.out.println((n-onazi)-tiisai);	  
	    }  
	    onazi=0;
	    ookii=0;
	    tiisai=0;

	}



    }


}

Measured memory_bytes: 0
#include <cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;
#define LL long long
#define INF 1e18
#define MAXN 100002
int n,m,s,t,u,v;
LL a,b,f=1e15,ans[MAXN];
struct Graph
{
	int cnt,head[MAXN],vis[MAXN];
	LL dis[MAXN];
	struct Edge{int next,to;LL dis;}edge[MAXN*2];
	queue<int> q;
	void addedge(int from,int to,LL dis)//在struct定义本质不变
	{
		edge[++cnt].next=head[from];
		edge[cnt].to=to;
		edge[cnt].dis=dis;
		head[from]=cnt;
	}
	void spfa(int s)
	{
		for(int i=1;i<=n;i++)
			dis[i]=INF;
		memset(vis,0,sizeof(vis));
		q.push(s);
		vis[s]=1;
		dis[s]=0;
		while(!q.empty())
		{
			int x=q.front();
			q.pop();
			vis[x]=0;
			for(int i=head[x];i!=0;i=edge[i].next)
			{
				int to=edge[i].to;
				if(dis[to]>(dis[x]+edge[i].dis))
				{
					dis[to]=dis[x]+edge[i].dis;
					if(!vis[to])
						q.push(to),vis[to]=1;
				}
			}
		}
	}
}g1,g2;
int main()
{
	scanf("%d%d%d%d",&n,&m,&s,&t);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d%lld%lld",&u,&v,&a,&b);
		g1.addedge(u,v,a);g1.addedge(v,u,a);
		g2.addedge(v,u,b);g2.addedge(u,v,b);
	}
	g1.spfa(s);
	g2.spfa(t);
	ans[n+1]=INF;
	for(int i=n;i>=1;i--)
		ans[i]=min(ans[i+1],g1.dis[i]+g2.dis[i]);
	for(int i=1;i<=n;i++)
		printf("%lld\n",f-ans[i]);
}

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

int main()
{
  int x,y,r=1;/* ?????°?????£?¨? */
  scanf("%d%d",&x,&y);/* ?????°???????´? */
  if(x<1 || y >1000000000){/* ??¶?´? */
    exit(0);/* ?????°?????£??????????????´??????????????°????????????????????? */
  }
  r = x % y;
  while(r!=0){
    x = y;
    y = r;
    r = x % y;
  }/* ?????????????????????????????? */
  printf("%d\n",y);/* ?????§??¬?´???°?????¨??? */

  return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
//#include <unistd.h>
//#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll inf = 2147483647;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const ld pi = 3.14159265358;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}

ll fac[510000], finv[510000], inv[510000];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < 510000; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logN)
ll modpow(ll n,ll m,ll MOD){
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}

//printf("%.10f\n", N);
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/

//    cout << fixed << setprecision(15);

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N,W;
    cin >> N >> W;
    vector<ll> val(N);
    vector<ll> wei(N);
    rep(i,N){
        cin >> val[i] >> wei[i];
    }
    vector<vector<ll>> memo(105,vector<ll>(10005));
    rep(i,N){
        rep(j,W + 1){
            if(j >= wei[i]){
                memo[i + 1][j] = max(memo[i][j],memo[i + 1][j - wei[i]] + val[i]);
            }
            else memo[i + 1][j] = memo[i][j];
        }
    }
    cout << memo[N][W] << endl;
}


Measured memory_bytes: 11092
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
 
#define pb push_back
#define mk make_pair
#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define sf(a) scanf("%d",&a);
#define sfl(a) scanf("%lld",&a);
#define TEST int test; cin >> test;while(test--)
#define ii pair<int,int>
#define iil pair<ll,ll>
#define loop(i,a,b) for(int i = a ; i < b ; i++)
#define INF 2147483647
 
 
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const double pi = acos(-1.0);
 
 
ll gcd(ll a, ll b)
{
    if(b==0) return a;
    a%=b;
    return gcd(b,a);
}
 
 
ll mod(ll a, ll b)
{
    ll c = a % b;
    if (c < 0)
        c += b;
    return c;
}
ll power(ll x, unsigned long long y)
{
    int res = 1;     // Initialize result
 
    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x);
 
        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x);  // Change x to x^2
    }
    return res;
}
int isPrime[5000000] ;
vector< vector<ll> > pf(1000000), pr(1000000);
void sieve(int n)
{
    for(int i = 2 ; i*i <= n ; i++)
    {
        if(!isPrime[i])
        {
            // v.pb(i);
            for(int j = i+i ; j <= n; j = j + i)
            {
                isPrime[j] = 1;
                pf[j].pb(i);
            }
        }
    }
    return;
}
const int n = 1e6;
ll cn[n+10], cn1[n+10];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    string s,t;
    cin >> s >> t;
    int l  = s.size();
    if( s == t.substr(0,l)) cout << "Yes" << endl;
    else cout << "No" << endl;
 
    return 0;
 
 
 
}

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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int d;
  while (cin >> d) {
    int ans = 0;
    for (int i = d; i <= 600 - d; i += d) {
      ans += d * i * i;
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 3080
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int sleep[];
        sleep = new int[N];
        int tmp = 0;
        boolean hantei = true;
        for (int i = 0; N > i; i++) {
            int A = sc.nextInt();
            sleep[i] = A;
        }
        while (hantei) {
            for (int j = 0; N > j; j++) {
                if (sleep[j] % 2 == 0) {
                    sleep[j] = sleep[j] / 2;
                } else {
                    hantei = false;
                    break;

                }
            }
            if (hantei == true) {
                tmp++;
            }
        }
        System.out.println(tmp);
    }
}

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

const int MAX = 100005;
long long A[MAX];

long long solve(long long s, long long cnt, int n) {
    for (int i = 1; i < n; i++) {
        if (s * (s + A[i]) >= 0) {
            cnt += abs(s + A[i]) + 1;
            if (s > 0) s = -1;
            else s = 1;
        } else {
            s += A[i];
        }
    }
    return cnt;
}

int main() {
    int n;
    long long s, t, x, y, ans;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%lld", &A[i]);

    x = y = 0;
    s = A[0];
    if (s > 0) {
        t = -1;
        y = A[0] + 1;
    } else if (s < 0) {
        t = 1;
        y = -A[0] + 1;
    } else if (s == 0) {
        s = 1;
        x = 1;
        t = -1;
        y = 1;
    }
    x = solve(s, x, n);
    y = solve(t, y, n);
    ans = min(x, y);
    printf("%lld\n", ans);

    return 0;
}

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

#define all(v) begin(v), end(v)
#define endl '\n';
#define int long long
#define pii pair<int, int>

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

    int a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;

    if (v > w && abs(a - b) <= t * (v - w)) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    } 

}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
int main()
{
    int n,sum=0;
    cin>>n;
    int arr[n+1],arr1[n+1];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    for(int i=0;i<n;i++)
    {
        cin>>arr1[i];
    }
    for(int i=0;i<n;i++)
    {
        if(arr[i]>arr1[i])
        {
            sum=sum+(arr[i]-arr1[i]);
        }
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 3596
n = int(input())
lst = [0] * 10005
for x in range(1, 100):
    for y in range(1, 100):
        for z in range(1, 100):
            m = x**2 + y ** 2 + z ** 2 + x*y + y*z + x*z
            if m<10001:
                lst[m] += 1
            else:
                break
for i in range(1, n+1):
    print(lst[i])

Measured memory_bytes: 9368
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b>=c && a<=c) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)
typedef long long ll;
const ll INF = 1LL<<60;
const ll MOD = 1000000007;

inline ll add(ll x, ll y) {return (x+y)%MOD;}
inline ll mul(ll x, ll y) {return (x*y)%MOD;}
inline ll sub(ll x, ll y) {
    ll res = x - y;
    if(res < 0) res += MOD;
    return res;
}

int main(){
    int H; int N; cin >> H >> N;
    vector<int> a(N),b(N);
    REP(i,N) {
        cin >> a[i] >> b[i];
    }
    vector<vector<int>> dp(N+1,vector<int>(10001,1<<29)); dp[0][0]=0;
    REP(i,N)REP(j,10001) {
        dp[i+1][j] = min(dp[i][j],dp[i][max(0,j-a[i])]+b[i]);
		dp[i+1][j] = min(dp[i+1][j],dp[i+1][max(0,j-a[i])]+b[i]);

    }
    cout << dp[N][H] << endl;
    return 0;
}

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

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

    int k,x; cin >> k >> x;
    for(int i = x-k+1; i < x+k; ++i) cout << i << "\n";
}

Measured memory_bytes: 256
S = input()
T = input()
S = S[::-1]
T = T[::-1]

ans = "UNRESTORABLE"[::-1]
if len(S) >= len(T) :
    if T in S :
        ans = S
    else :
        for i in range(len(S)-len(T)+1) :
            S_ = S[i:i+len(T)]
            #print(S_)
            for j in range(len(T)) :
                if S_[j] == "?" :
                    continue
                if S_[j] != T[j] :
                    break
            else :
                ans = S[:i] + T + S[i+len(T):]
                break
ans = ans.replace("?","a")
ans = ans[::-1]
print(ans)


Measured memory_bytes: 3064
from math import log2
import heapq as hq
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
c = Counter(a)
a = [-a[i] for i in range(n)]
hq.heapify(a)
ans = 0
while a:
  x = hq.heappop(a)
  x = -x
  if c[x]>0:
    y = 2**(int(log2(x))+1)
    if x*2 == y:
      ans += c[x]//2
      c[x] = c[x]%2
    else:
      if c[y-x]>0:
        ans += 1
        c[x] -= 1
        c[y-x] -= 1
print(ans)

Measured memory_bytes: 33432
import math

divisor=[1]
stack=[]
#eiclidean algorithm
A,B=map(int,input().split())
p=max(A,B)
q=min(A,B)
int2=0
gcd=0
while True:
    int2=p%q
    if int2==0:
        gcd=q
        break
    else:
        p=q
        q=int2

if gcd!=1:
    stack.append(gcd)
    
for i in range(2,math.ceil(math.sqrt(gcd))+1):
    if gcd%i==0:
        p=gcd//i
        stack.append(p)
        for x in divisor:
            if i%x==0 and x!=1:
                break
        else:
            divisor+=[i]

while len(stack)!=0:
    p=stack.pop()
    for x in divisor:
        if p%x==0 and x!=1:
            break
    else:
        divisor+=[p]


print(len(divisor))

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<set>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

int H, W, K;
int color = 1;
vector<vector<int>>ans;
vector<string> c;

void solve(P h, P w) {
    if(ans[h.first][w.first] != 0) return;
    vector<P>pos;
    for(int i = h.first; i < h.second; ++i) {
        for(int j = w.first; j < w.second; ++j) {
            if(c[i][j] == '#')
                pos.pb(mp(i, j));
        }
    }
    if(pos.size() == 1) {
        for(int i = h.first; i < h.second; ++i) {
            for(int j = w.first; j < w.second; ++j) {
                ans[i][j] = color;
            }
        }
        ++color;
        return;
    }
    else {
        if(pos[0].first == pos[1].first) {
            solve(h, mp(w.first, pos[0].second + 1));
            solve(h, mp(pos[0].second + 1, w.second));
        }else {
            solve(mp(h.first, pos[0].first + 1), w);
            solve(mp(pos[0].first + 1, h.second), w);
        }
    }
}

int main() {
    cin >> H >> W >> K;
    c.resize(H);
    rep(i, H) {
        cin >> c[i];
    }
    ans.resize(H, vector<int>(W, 0));
    solve(mp(0, H), mp(0, W));
    rep(i, H) {
        rep(j, W) {
            cout << ans[i][j] << ' ';
        }
        cout << endl;
    }
}


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

int64_t mod=1e9+7;
vector<int64_t> inv;

int64_t modpow(int64_t a,int64_t n){
  int64_t res=1;
  while(n>0){
    if(n&1){
      res*=a;
      res%=mod;
    }
    a*=a;
    a%=mod;
    n>>=1;
  }
  return res;
}

int64_t modinv(int64_t a){
  return modpow(a,mod-2);
}

int64_t comb(int64_t n,int64_t r){
  int64_t res=1;
  for(int i=1;i<=r;i++){
    res*=((n-i+1)*inv.at(i))%mod;
    res%=mod;
  }
  return res;
}
// int64_t comb(int64_t n,int64_t r){
//   if(r==0){
//     return 1;
//   }
//   return (((n-r+1)*modinv(r))%mod*comb(n,r-1))%mod;
// }

int main(){
  int64_t n,a,b;
  cin >> n >> a >> b;
  inv.resize(b+1);
  for(int i=1;i<=b;i++){
    inv.at(i)=modinv(i);
  }
  int64_t ans=0;
  ans=modpow(2,n)-1;
  ans-=comb(n,a);
  ans%=mod;
  if(ans<0){
    ans+=mod;
  }
  ans-=comb(n,b);
  ans%=mod;
  if(ans<0){
    ans+=mod;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
s = input()
odd = []
even = []
for i in range(len(s)):
    if i % 2 == 0:
        even.append(s[i])
    else:
        odd.append(s[i])

ans = even.count('0') + odd.count('1')
if ans > even.count('1') + odd.count('0'):
    ans = even.count('1') + odd.count('0')

print(ans)

Measured memory_bytes: 4052
N = gets.chomp.to_i
edges = gets.chomp.split(' ').map(&:to_i)

if N < 3 then
    puts 0
    exit
end

ans = 0

edges.combination(3).to_a.each do |threeEdges|
    next if threeEdges.size != threeEdges.uniq.size
    if threeEdges[0] + threeEdges[1] > threeEdges[2] && threeEdges[0] + threeEdges[2] > threeEdges[1] && threeEdges[1] + threeEdges[2] > threeEdges[0] then
        ans += 1
    end
end

puts ans

Measured memory_bytes: 29716