akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
typedef long long ll;

int main(){
    ll n;cin >> n;
    ll k;cin >> k;
    ll a[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    ll ans = 0;
    bool sw = false;
    for(int i=39;i>=0;i--){
        int count1 = 0;
        int count0 = 0;
        for(int j=0;j<n;j++){
            if(((a[j] >> i)&1) == 1 ){
                count1 ++;
            }
            else{
                count0 ++;
            }
        }
        //cout << "i=" << i << "count1=" << count1 << "count0=" << count0 << endl;
        if(!sw){
            if(count1 >= count0 && ((k >> i)&1) == 0){
                ans = ans <<1;
            }
            else if(count0 > count1 && ((k >> i)&1) == 1){
                ans = ans << 1;
                ans += 1;
            }
            else if(count1 >= count0 && ((k >> i)&1) == 1){
                ans = ans << 1;
                sw = true;
            }
            else{
                ans = ans << 1;
            }
        }
        else{
            if(count1 >= count0){
                ans = ans << 1;
            }
            else{
                ans = ans << 1;
                ans ++;
            }
        }
    }
    //cout << "ans = " << ans << endl;
    ll sum = 0;
    for(int i=0;i<n;i++){
        sum += ans^a[i];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.*;
import java.io.*;

public class Main {
		public static void main(String[] args) throws IOException {
		
		// 入出力高速化 java.io.* とthrows IOExceptionを忘れずに
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		Long N = Long.parseLong(br.readLine());
		
		N+=1;
		String S = N.toString();
		long ans = 9*(S.length()-1) + (S.charAt(0)-'0' -1);
		
        System.out.println(ans);
    }
}

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

int main() {
  std::string str;
  std::cin >> str;
  
  int n_pat = 8;
  for (int pat=0; pat<n_pat; pat++) {
    int tmp = (str[0] - '0');
    std::string expr = str.substr(0, 1);
    for (int i=0; i<3; i++) {
      if ((pat >> i) & 1) {
        tmp += (str[i+1] - '0');
        expr += "+" + str.substr(i+1, 1);
      } else {
        tmp -= (str[i+1] - '0');
        expr += "-" + str.substr(i+1, 1);
      }
    }
    if (tmp == 7) {
      std::cout << expr << "=7" << std::endl;
      return 0;
    }
  }
  
  return 1;
}


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

using namespace std;
typedef long long ll;


ll MSB(ll N){
  ll k = (ll)log2l(N);
  return k;
}

main(){
  ll n, k; cin >> n >> k;
  ll arr[n];
  for(int i=0;i<n;++i) cin >> arr[i];
  vector<ll> subs;
  for(int i=0;i<n;++i){
    ll sum = 0;
    for(int j=i;j<n;++j){
      sum += arr[j];
      subs.push_back(sum);
    }
  }
  ll p = 40;
  ll ans = 0;
  while(p>=0){
    ll cont = 0;
    ans += (1ll<<p);
    for(int i=0;i<subs.size();++i){
      if((subs[i] & ans)==ans) cont++;
    }
    if(cont < k) ans -= (1ll<<p);
    p--;
  }
  cout << ans << endl;
}

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

int main(void){
    int a, b;
    cin>>a>>b;
    int ans=a-(b*2);
    if(a<=b*2) ans=0;
    cout<<ans<<endl;
}

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

using namespace std;

int gcd(int a, int b) {
  int tmp;
  if (a < b) {
    tmp = a;
    a = b;
    b = tmp;
  }

  int r = -1;
  while (r != 0) {
    r = a % b;
    a = b;
    b = r;
  }

  return a;
}

int ans(deque<int> vs) {
  if (vs.size() == 1) {
    return vs[0];
  }

  int ans = gcd(vs[0], vs[1]);

  // pop_front 2 times
  vs.pop_front();
  vs.pop_front();

  while (!vs.empty()) {
    ans = gcd(ans, vs[0]);
    vs.pop_front();
  }

  return ans;
}

int main(int argc, char const* argv[])
{
  int n, x;

  cin >> n >> x;

  deque<int> vs;
  int v;

  while (n--) {
    cin >> v;
    vs.push_back(abs(v - x));
    // cout << "v: " << v << endl;
  }

  cout << ans(vs) << endl;

  return 0;
}

Measured memory_bytes: 1024
W,H,N=[int(x) for x in input().split()]
S=[[0,0],[W,H]]
for _ in range(N):
  x,y,a=[int(x) for x in input().split()]
  if a==1:
    S[0][0]=max(S[0][0],x)
  elif a==2:
    S[1][0]=min(S[1][0],x)
  elif a==3:
    S[0][1]=max(S[0][1],y)
  else:
    S[1][1]=min(S[1][1],y)
print(max(0,S[1][0]-S[0][0])*max(0,S[1][1]-S[0][1]))

Measured memory_bytes: 3064
n, m = map(int, input().split())
xy = [0] * m
for i in range(m):
    x, y = map(int, input().split())
    xy[i] = (x, y)
red = [0] * n
red[0] = 1
num = [1] * n

for i in range(m):
    moveFrom = xy[i][0] - 1
    moveTo   = xy[i][1] - 1
    if red[moveFrom] == 1 and num[moveFrom] == 1:
        red[moveFrom] = 0
        red[moveTo] = 1
    elif red[moveFrom] == 1:
        red[moveTo] = 1
    num[moveFrom] -= 1
    num[moveTo] += 1

ans = 0
for i in red:
    if i == 1:
        ans += 1
print(ans)


Measured memory_bytes: 17956
#include "iostream"
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a+b>c+d){
    cout<<"Left"<<endl;
  }
  else if(c+d>a+b){
    cout<<"Right"<<endl;
  }
  else{
    cout<<"Balanced"<<endl;
  }
}


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


int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b;
    string s;
    cin >> s;
    for(a=0;a<s.length();++a) cout << "x" ;
	return 0;
}

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

int main(){
  int N, T;
  cin >> N >> T;
  vector<vector<int>> vec(N,vector<int>(2));
  for(int i=0; i<N; i++){
    for(int j=0; j<2; j++){
      cin >> vec.at(i).at(j);
    }
  }
  int cost = 10000;
  int ans  = 10000;
  
  for(int k=0; k<N; k++){
    if(vec.at(k).at(1) <= T){
      cost = min(cost, vec.at(k).at(0));
    }
  }
  if(cost == 10000){
    cout << "TLE" << endl;
  }
  else{
    cout << cost << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n; cin >> n;
  	int a[n];
  	for (int i = 0; i < n; i++)
      	cin >> a[i];
  	sort(a, a + n);
  	int ans = 0;
  	for (int i = 0; i < n - 1; i++)
      	ans += a[i];
  	ans += a[n-1] / 2;
  	cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
using namespace std;
struct node
{
	int id,num;
};
bool operator <(node a,node b)
{
	return a.num<b.num;
}
priority_queue<node> q;
int n,i,j,k,a[2005],d[2005],e[2005][2005],cnt[2005],mn[2005],p[2005];
bool v[2005][2005],vis[2005];
int find(int x)
{
	return !p[x]?x:p[x]=find(p[x]);
}
int gcd(int a,int b)
{
	if(!b)
		return a;
	return gcd(b,a%b);
}
bool cmp(int i,int j)
{
	return a[i]<a[j];
}
void dfs(int x)
{
	vis[x]=true;
	for(int y=1;y<=cnt[x];++y)
		if(!v[x][e[x][y]])
		{
			v[x][e[x][y]]=v[e[x][y]][x]=true;
			++d[e[x][y]];
		}
		else
			e[x][y]=0;
	for(int y=1;y<=cnt[x];++y)
		if(e[x][y]&&!vis[e[x][y]])
			dfs(e[x][y]);
}
int main()
{
	scanf("%d",&n);
	for(i=1;i<=n;++i)
		scanf("%d",a+i);
	for(i=1;i<=n;++i)
		for(j=i+1;j<=n;++j)
			if(gcd(a[i],a[j])>1)
			{
				e[i][++cnt[i]]=j;
				e[j][++cnt[j]]=i;
				if(find(i)!=find(j))
					p[find(i)]=find(j);
			}
	for(i=1;i<=n;++i)
		sort(e[i]+1,e[i]+1+cnt[i],cmp);
	for(i=1;i<=n;++i)
		if(!mn[find(i)]||a[i]<a[mn[find(i)]])
			mn[find(i)]=i;
	for(i=1;i<=n;++i)
		if(mn[find(i)]==i)
			dfs(i);
	for(i=1;i<=n;++i)
		if(d[i]==0)
			q.push((node){i,a[i]});
	while(!q.empty())
	{
		i=q.top().id;
		printf("%d ",a[i]);
		q.pop();
		for(j=1;j<=cnt[i];++j)
		if(e[i][j])
		{
			--d[e[i][j]];
			if(d[e[i][j]]==0)
				q.push((node){e[i][j],a[e[i][j]]});
		}
	}
	return 0;
}


Measured memory_bytes: 19968
import heapq

Q = int(input())

A_left = [] #最大を取り出すのでminus queueにする
A_right = [] #最小を取り出す
A_middle = 0
A_size = 0
MIN_SCORE = 0
for i in range(Q):
    q = input()
    if q[0]=="1": #更新
        dummy,a,b = map(int,q.split())
        A_size+=1
        sabun = 0
        if A_size==1: #初期設定
            A_middle = a
            sabun = 0
        elif A_size%2==0: #偶数処理
            if a <= A_middle:
                sabun = A_middle - a
                heapq.heappush(A_left,a*(-1))
                heapq.heappush(A_right,A_middle)
            else:
                sabun = a - A_middle
                heapq.heappush(A_left,A_middle*(-1))
                heapq.heappush(A_right,a)
            A_middle = 0 #デバッグ用
        else: #奇数処理
            if a<A_left[0]*(-1):
                sabun = A_left[0]*(-1) - a
                A_middle = heapq.heappop(A_left)*(-1)
                heapq.heappush(A_left,a*(-1))
            elif a>A_right[0]:
                sabun = a - A_right[0]
                A_middle = heapq.heappop(A_right)
                heapq.heappush(A_right,a)
            else:
                sabun = 0
                A_middle = a
        MIN_SCORE += sabun + b if A_size>1 else b
    elif q[0]=="2":
        if A_size%2==0:
            print(A_left[0]*(-1),MIN_SCORE)
        else:
            print(A_middle,MIN_SCORE)

Measured memory_bytes: 11064
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
int main(){
	int c11,c12,c13,c21,c22,c23,c31,c32,c33;
	cin>>c11>>c12>>c13>>c21>>c22>>c23>>c31>>c32>>c33;
	cout<<(c21-c11==c22-c12&&c22-c12==c23-c13&&c31-c11==c32-c12&&c32-c12==c33-c13?"Yes":"No")<<endl;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

func main() {
	var S string
	var zero, one float64
	var r float64
	s := bufio.NewScanner(os.Stdin)
	b := make([]byte, 1000000)
	s.Buffer(b, 1000000)
	s.Scan()
	S = s.Text()
	for _, v := range S {
		if v == '0' {
			zero++
		} else {
			one++
		}

	}
	r = math.Min(zero, one) * 2
	fmt.Println(r)
}

Measured memory_bytes: 896
#include<iostream>
#include<vector>
#include<algorithm>
#define INF (1<<21)
using namespace std;

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

  vector<int> p(105);
  int m[105][105];

  for(int i = 1; i <= n; i++){
    cin >> p[i-1] >> p[i];
    m[i][i] = 0;
  }

  for(int i = 2; i <= n; i++){
    for(int j = 1; j <= n-i+1; j++){
      int x = i + j - 1;
      m[j][x] = INF;

      for(int k = j; k <= x-1; k++){
	m[j][x] = min(m[j][x], m[j][k]+m[k+1][x] + p[j-1]*p[k]*p[x]);
      }
    }
  }

  cout << m[1][n] << endl;

  return 0;

}



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

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

	if ( s[0] == s[1] && s[1] == s[2] ){
		cout << "Yes" << endl;
	}
	else if ( s[1] == s[2] && s[2] == s[3] ){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
}



Measured memory_bytes: 256
//============================================================================
// Name        : AOJ.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <algorithm>

using namespace std;
typedef long long ll;
int w,h,c;
ll d[1001]={};

int main() {
	int n;
	cin>>n;
	ll p[3];
	for(int i=0;i<n;++i){
		cin>>p[0]>>p[1]>>p[2];
		sort(p,p+3);
		d[i]=p[0]+10000*p[1]+100000000*p[2];
	}
	sort(d,d+n);
	int total=0;
	for(int i=1;i<n;++i){
		if(d[i]==d[i-1])++total;
	}
	cout<<total<<endl;
	return 0;
}

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

bool compare(pair<string, pair<int, int>> a, pair<string, pair<int, int>> b) {
    if(a.first == b.first) {
        return a.second.first > b.second.first;
    } else {
        return a.first < b.first;
    }
}
    

int main() {
    int n;
    cin >> n;
    string s[n];
    int P[n];
    vector<pair<string, pair<int, int>>> p(n);

    for(int i = 0; i < n; i++) {
        cin >> s[i];
        cin >> P[i];
        p[i] = make_pair(s[i], make_pair(P[i], i+1));
    }

    sort(p.begin(), p.end(), compare);

    for(int i = 0; i < n; i++) {
        cout << p[i].second.second << endl;
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                   \
  ifstream in("abc167/abc167_e.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v) \
rep(l, v.size()) { cout << v[l] << " "; } \
cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18+100;
const int MOD = 998244353;

/**
 * 繰り返し自乗法
 * http://satanic0258.hatenablog.com/entry/2016/04/29/004730
 */
ll powMod(ll n, ll p, const int mod = MOD) {
  if (p == 0) return 1;
  if (p % 2 == 0) {
    ll t = powMod(n, p / 2);
    return t * t % MOD;
  } else {
    return n * powMod(n, p - 1) % MOD;
  }
}

ll fact[200010];
ll invfact[200010];

/** nCr の O(1)版.
 * N ~ 10^5 ならこちらのほうが早い
 * nCk≡n! * (k!)^M−2 * ((n−k)!)^M−2 (modM)
 */
ll combMod(int n, int p) { 
  ll ret = fact[n] * invfact[p] % MOD;
  ret = ret * invfact[n - p] % MOD;
  return ret;
}


int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N, M, K;
  cin >> N >> M >> K;
 
  // 階乗テーブルの初期化
  fact[0] = 1;
  invfact[0] = 1;
  repi(i, 1, N + 1) {
    fact[i] = fact[i - 1] * i % MOD;
    invfact[i] = invfact[i - 1] * powMod(i, MOD - 2) % MOD;
  }

  ll ans = 0;
  rep(i, K + 1) {
    ll color = M * powMod(M - 1, N - i - 1) % MOD;
    ll place = combMod(N - 1, i);
    ans += color * place % MOD;
    ans %= MOD;
  }

  cout << ans << endl;
}

Measured memory_bytes: 6732
i=gets.to_i
d=[]
o=0
n=0
while o<i*3
  case gets.chomp
  when "HIT"
    if d.size==3
      d.shift
      n+=1
    end

    d.push(1)
  when "OUT"
    o+=1

    if o%3==0
      puts n
      n=0
      d=[]
    end
  when "HOMERUN"
    n+=d.size+1
    d=[]
  end
end

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

bool is_acceptable(int a, int b) {
  for (int i = 0; i <= 20; ++i) {
    int x = (a >> i) & 1;
    int y = (b >> i) & 1;
    if (x == 1 and y == 1) return false;
  }
  return true;
}

int main() {
  int n;
  std::cin >> n;
  std::vector<int> a(n);
  for (int ni = 0; ni < n; ++ni) std::cin >> a[ni];
  long long ans = 0;
  int total = 0;
  int right = 0;
  for (int left = 0; left < n; ++left) {
    while (right < n) {
      if (is_acceptable(total, a[right])) {
        total += a[right];
        ++right;
      } else {
        break;
      }
    }
    ans += right - left;
    total -= a[left];
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		for(;;){
			int H =  sc.nextInt();
		    int W =  sc.nextInt();
		    int n = 0;
		    int a = 0;     //??¶??°??????
		    if(W%2==1)a=1; //?\???°??????
		    if(H==0 && W==0) break;
		    for(int i=0; i<H; i++){
		    	for(int j=0; j<W; j++){
		    		if(n%2==0){
		    			System.out.print("#");
		    		}else{
		    			System.out.print(".");
		    		}
		    		n++;
		    	}
		    	System.out.println();
			    if(a==0)n++;
		    }
	    	System.out.println();
		}
	}
}

Measured memory_bytes: 35708
# >>> numba compile >>>
def numba_compile(numba_config):
    import os, sys
    if sys.argv[-1] == "ONLINE_JUDGE":
        from numba import njit
        from numba.pycc import CC
        cc = CC("my_module")
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature)(func)
            cc.export(func.__name__, signature)(func)
        cc.compile()
        exit()
    elif os.name == "posix":
        exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}")
        for func, _ in numba_config:
            globals()[func.__name__] = vars()[func.__name__]
    else:
        from numba import njit
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature, cache=True)(func)
        print("compiled!", file=sys.stderr)
# <<< numba compile <<<

import sys
import numpy as np

mod = 998244353
def solve(N, K, LR):
    dp = np.zeros(N+1, dtype=np.int64)
    cum = np.zeros(N+1, dtype=np.int64)
    dp[1] = 1
    cum[1] = 1
    for i in range(2, N+1):
        d = 0
        for idx_LR in range(K):
            l, r = LR[idx_LR]
            ll = max(0, i - l)
            rr = max(0, i - r - 1)
            d += cum[ll] - cum[rr]
        d %= mod
        dp[i] = d
        cum[i] = (cum[i-1] + d) % mod
    return dp[N]

numba_compile([
    [solve, "i8(i8,i8,i8[:,:])"],
])

def main():
    N, K = map(int, sys.stdin.buffer.readline().split())
    LR = np.array(sys.stdin.buffer.read().split(), dtype=np.int64).reshape(K, 2)
    ans = solve(N, K, LR)
    print(ans)

main()


Measured memory_bytes: 29992
#include <cstdio>

int main(int argc, char *argv[]) {
	
	while (true) {
		int player1[4];
		int player2[4];
		int hit = 0, blow = 0;
		
		if (EOF == fscanf(stdin, "%d %d %d %d\n",
			 &player1[0], &player1[1], &player1[2], &player1[3])) {
			break;
		}
		fscanf(stdin, "%d %d %d %d\n", &player2[0], &player2[1],
			&player2[2], &player2[3]);
		
		for (int i = 0; i < 4; i++) {
			// hit
			if (player1[i] == player2[i]) {
				hit++;
			}
			// blow
			for (int j = 0; j < 4; j++) {
				if (i != j) {
					if (player1[i] == player2[j]) {
						blow++;
					}
				}
			}
		}
		printf("%d %d\n", hit, blow);
	}
	return 0;
}

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

int main(){
  int x; cin >>x;
  if(x) cout << 0 << endl;
  else cout << 1 << endl;
  return 0;
}

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

int main(){
    const long long x = 1000000007;
    int n, count=0;
    long long m, a=2, pro=1;
    vector<int> p;
    cin >> n >> m;
    while(m>1){
        if(m%a == 0){
            count++;
            m /= a;
        } 
        else {
            if(count!=0){
                p.push_back(count);
            } 
            count=0;
            a++;
        }
    }
    if(count!=0) p.push_back(count);
    int psize=p.size();
    for(int i=0; i<psize; i++){
        int z = p.at(i) + n - 1, y = p.at(i);
        long long com[z+1][y+1];
        for(int j=1; j<=z; j++) com[j][0]=1;
        for(int j=1; j<=z && j<=y; j++) com[j][j]=1;
        for(int j=1; j<z; j++){
            for(int k=0; k<j && k+1<=y; k++){
                com[j+1][k+1] = (com[j][k+1] + com[j][k]) % x;
            }
        }
        pro = pro * com[z][y]% x;
    }
    cout << pro << endl;
}

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

int f[20][20];
int v[1<<16];

struct State
{
	int cost,item;
	State(int c, int i)
	{
		cost=c; item=i;
	}
	bool operator<(const State& s) const
	{
		return cost>s.cost;
	}
};

int main()
{
	int N;
	while(cin >> N, N)
	{
		for(int s=0; s<N; s++)
		{
			cin >> f[s][N];
			for(int i=0; i<N; i++)
			{
				cin >> f[s][i];
			}
		}

		memset(v, 0, sizeof(v));
		priority_queue<State> q;
		q.push(State(0,0));
		while(!q.empty())
		{
			State t=q.top(); q.pop();

			if(t.item == (1<<N)-1)
			{
				cout << t.cost << endl;
				break;
			}

			if(v[t.item]) continue;
			v[t.item] = 1;

			for(int s=0; s<N; s++)
			{
				if(t.item&(1<<s)) continue;

				int nc = f[s][N];
				for(int i=0; i<N; i++)
				{
					if(t.item&(1<<i))
					{
						nc = min(nc, f[s][i]);
					}
				}
				q.push(State(t.cost+nc, t.item|(1<<s)));
			}
		}
	}
}	

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

int main() {
  int k;
  int a, b;
  
  cin >> k;
  cin >> a >> b;
  
  int kx, i;
  kx = k;
  i = 0;
  
  while(kx < a){
    i++;
    kx = k * i;
  }
  
  if (kx <= b ) {
    cout << "OK" << endl;
  } else {
    cout << "NG" << endl;
  }
}

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

int main()
{
	int n, cnt = 0;
	string s;
	cin >> n >> s;
	
	for (int i = 0; i < n; ++i)
	{
		if (s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C')
		{
			cnt++;
		}
	}
	cout << cnt << endl;
	
	return 0;
}


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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	ll h, w;

	cin >> h >> w;

	vector<string> v(h + 2, "");

	REP(i, w + 2) {
		v[0] = v[0] + ".";
		v[h + 1] = v[h + 1] + ".";
	}

	REP(i, h) {
		string s;
		cin >> s;
		s = "." + s + ".";
		v[i + 1] = s;
	}

	REP(i, h) {
		REP(j, w) {
			if (v[i + 1][j + 1] == '#') {
				if (v[i][j + 1] == '.' && v[i + 2][j + 1] == '.' && v[i + 1][j] == '.' && v[i + 1][j + 2] == '.') {
					cout << "No" << endl;
					return 0;
				}
			}
		}
	}

	cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll N, K;
  cin>>N>>K;
  ll A[N];
  ll sum = 0;
  for(int i=0;i<N;++i) {
    cin>>A[i];
    sum += A[i];
  }
  vector<ll> yaku;
  for(ll i=1;i*i<=sum;++i) {
    if(sum%i==0) {
      yaku.push_back(i);
      if(i!=sum/i) yaku.push_back(sum/i);
    }
  }
  ll ans = 1;
  for(int i=0;i<yaku.size();++i) {
    vector<int> arr1, arr2;
    for(int j=0;j<N;++j) arr1.push_back(A[j]%yaku[i]);
    sort(arr1.begin(), arr1.end());
    for(int j=0;j<N;++j) arr2.push_back(yaku[i]-arr1[j]);
    for(int j=N-2;j>=0;--j) arr2[j] += arr2[j+1];
    int tmp = 0;
    for(int j=0;j<N-1;++j) {
      tmp += arr1[j];
      if(tmp==arr2[j+1]) {
        if(tmp<=K) ans = max(ans, yaku[i]);
        break;
      }
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3652
#include<iostream>
#include<bits/stdc++.h>
#define mod 1000000007
#define int long long
#define pii pair<int,int>
#define pb(x) push_back(x)
#define lbound lower_bound
#define ubound upper_bound
#define gcd(a,b) __gcd(a,b)
#define all(v) v.begin(),v.end()
#define bits(x) __builtin_popcountll(x)
#define heap_min priority_queue<int,vector<int>,greater<int>>
#define heap_max priority_queue<int>
#define precision(x) cout << setprecision(x) << fixed;
#define printv(v) for(auto p : v) cout << p << " ";
#define printa(a,n) for(int i = 0 ; i < n ; i++) cout << a[i] << " "; 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

int32_t main()
{
   fast;
   #ifndef ONLINE_JUDGE
   freopen("goodluckin.txt","r",stdin);
   freopen("goodluckout.txt","w",stdout);
   #endif
   int a,b,c,k;
   cin >> a >> b >> c >> k;
   while(b<=a){
      b = b*2;
      k--;
   }
   while(c<=b){
    c = c*2;
    k--;
   }
   if(k>=0){
    cout << "Yes";
   }
   else{
    cout << "No";
   }
   
}


Measured memory_bytes: 3656
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    int X =sc.nextInt();
    int N =sc.nextInt();
    int P[] =new int[N];
    int R[] =new int[N];
    int Q[] =new int[100];
    int x=0;
    Q[0]=1;
    for(int j=1;j<100;j++){
      Q[j]=2;}
    for(int i=0;i<N;i++){
      P[i]=sc.nextInt();
      R[i]=Math.abs(P[i]-X);
      Q[R[i]]=Q[R[i]]-1;}
    for(int k=0;k<100;k++){
      if(Q[k]==2){System.out.println(X-k);System.exit(0);}
      if(Q[k]==1){
        for(int l=0;l<N;l++){
          if(P[l]==X+k){x=x+1;}}
        if(x==0){System.out.println(X+k);System.exit(0);}
        else{System.out.println(X-k);System.exit(0);}
      }
    }
  }
}
          
        


Measured memory_bytes: 35584
#include <iostream>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli> > mat;
typedef vector<vector<bool> > matb;
typedef vector<string> vst;
typedef pair<lli,lli> pll;
typedef pair<double,double> pdd;

template<class T>
class bit : public vector<T> {
private:
    lli n;
public:
    bit():vector<T>(){}
    bit(lli n):vector<T>(n+1,0){
        this->n = n;
    }
    T sum(lli i){
        T s = 0;
        for(;i > 0;i -= i & -i) s += this->at(i);
        return s;
    }
    void add(lli i,T x){
        for(;i <= n;i += i & -i) this->at(i) += x;
    }
};

bit<lli> b;
lli n,q;
lli com,x,y;

int main(){
    cin >> n >> q;
    b = bit<lli>(n);
    for(lli i = 0;i < q;i++){
        cin >> com >> x >> y;
        if(com == 0){
            b.add(x,y);
        }else if(com == 1){
            cout << b.sum(y) - b.sum(x-1) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3560
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
#include <stack>
#include <cctype>
#include <cmath>
#include <bitset>

using namespace std;

/* typedef */
typedef long long ll;

/* constant */
const int INF = 1 << 30;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;

/* global variables */

/* function */

/* main */
int main(){

    bitset<64> bs(0);
    int m, q, op, x, y;
    cin >> m;
    vector<bitset<64>> mask_vec(m, bs);
    for (int i = 0; i < m; i++) {
        cin >> x;
        for (int j = 0; j < x; j++) {
            cin >> y;
            mask_vec[i].set(y);
        }
    }
    cin >> q;
    bitset<64> tmp;
    for (int i = 0; i < q; i++) {
        cin >> op >> x;
        switch(op) {
            case 0:  // test(x): Print 1 if i-th flag is ON, otherwise 0
                cout << bs.test(x) << '\n';
                break;
            case 1:  // set(m): Set flags specified by mask m to ON
                bs |= mask_vec[x];
                break;
            case 2:  // clear(i): Set flags specified by mask m to OFF
                bs &= ~mask_vec[x];
                break;
            case 3:  // flip(i): Inverse flags specified by mask m
                bs ^= mask_vec[x];
                break;
            case 4:  //  all: Print 1 if all flags 
                     //   specified by mask m are ON, otherwise 0
                cout << ((bs & mask_vec[x]) == mask_vec[x]) << '\n';
                break;
            case 5:  // any: Print 1 if at least one flag 
                     // specigied by mask m is ON, otherwise 0
                cout << (bs & mask_vec[x]).any() << '\n';
               break;
            case 6:  // none: Print 1 if all flags 
                     // specified by mask m are OFF, otherwise 0
                cout << (bs & mask_vec[x]).none() << '\n';
                break;
            case 7:  // count: Print the number of ON flags
                     // specified by mask m
                cout << (bs & mask_vec[x]).count() << '\n';
                break;
            case 8:  // val: Print the decimal value of the state
                cout << (bs & mask_vec[x]).to_ullong() << '\n';
                break;
        }
    }


}




Measured memory_bytes: 3104
# coding: utf-8

# In[6]:


import numpy as np


# In[85]:


s = int(input())


# In[87]:


a = np.array([])
a = np.append(a, s)
count = 1

while True:
    count += 1
    if a[-1] % 2 == 0:
        a = np.append(a, a[-1]/2)
    else:
        a = np.append(a, a[-1]*3 + 1)
    
    if (a[-1] == a[:-1]).any():
        print(count)
        break



Measured memory_bytes: 12420
//C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#define rp(i,a,b) for(int (i)=(int)(a);i<(int)(b);++i)
using namespace std;
typedef pair<int,int> P;
char a[10][10];
int X,Y;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
bool flag=true;
bool dfs(int x,int y){
    a[x][y]='.';
    rp(i,0,2){
        int nx=x+dx[i],ny=y+dy[i];
        if(0<=nx and nx<X and 0<=ny and ny<Y and a[nx][ny]=='#'){
            return dfs(nx,ny);

        }
    }
    return false;
    /*
    rp(i,2,4){
        int nx=x+dx[i],ny=y+dy[i];
        if(0<=nx and nx<X and 0<=ny and ny<Y and a[nx][ny]=='#'){
            flag=false;

        }
    }
    */
        
}
int main(){
    cin>>Y>>X;
    rp(i,0,Y){rp(j,0,X) cin>>a[j][i];};
    //rp(i,0,Y){rp(j,0,X) cout<<a[j][i];cout<<endl;};
    dfs(0,0);
    rp(i,0,Y){
        rp(j,0,X){if(a[j][i]=='#')flag=false;
        } 
    };
    if(flag)cout<<"Possible"<<endl;
    else cout<<"Impossible"<<endl;
    return 0;
};


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<ll, ll> pll;
typedef long double ldouble;
typedef pair<double, double> pdd;

int K = 38;
int N = K * (K - 1) + 1;

int A[2020][44];

void solve() {
	for(int i=1;i<=K;i++) A[1][i] = i;
	for(int i=2;i<=N;i++) {
		int x = (i - 2) / (K - 1) + 1;
		A[i][1] = x;
	}
	int temp = K;
	for(int i=2;i<=K;i++) {
		for(int j=2;j<=K;j++) A[i][j] = ++temp;
	}
	rep(a, K-1) rep(b, K-1) {
		int val = a * (K - 1) + b + K + 1;
		rep(c, K) {
			A[c*(K-1) + (a * c + b) % (K - 1) + K + 1][a+2] = val;
		}
	}
	printf("%d %d\n", N, K);
	for(int i=1;i<=N;i++) { for(int j=1;j<=K;j++) printf("%d ", A[i][j]); puts(""); }
}

int main(){
	int Tc = 1; // scanf("%d\n", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		solve();
	}
	return 0;
}


Measured memory_bytes: 768
#include<iostream>
#include<string>
using namespace std;
string s;
int main() {
	cin >> s;
	if (s.size() < 8)cout << s;
	else {
		bool b = false;
		for (int i = 0; i < s.size(); i++) {
			if (i >= s.size() - 7)cout << s[i];
			else {
				int a = 0, I = 0, z = 0, u = 0, n = 0, y = 0;
				for (int j = 0; j < 8; j++) {
					if (s[i + j] == 'A')a++;
					else if (s[i + j] == 'I')I++;
					else if (s[i + j] == 'D')z++;
					else if (s[i + j] == 'U')u++;
					else if (s[i + j] == 'N')n++;
					else if (s[i + j] == 'Y')y++;
				}
				if (a == 2 && I == 1 && z == 1 && u == 1 && n == 2 && y == 1) {
					cout << "AIZUNYAN";
					i += 7;
					b = true;
				}
				else {
					b = false;
					cout << s[i];
				}
			}
		}
	}
	cout << endl;
}

Measured memory_bytes: 3204
n=int(input())
l=list(map(int,input().split()))
l_c=[0]
c=1
for i in range(1,n):
    if l[i]==l[i-1]:
        l_c.append(c)
    c+=1
l_c.append(c)
if len(l_c)<5:
    print(n)
else:
    ans=-1
    for i in range(len(l_c)-3):
        ans=max(ans,l_c[i+3]-l_c[i])
    print(ans)


Measured memory_bytes: 8224
#include <stdio.h>

int num[3][3000];
int result[3][3000];
int i=0;
int a,b,k;
//int w,h,x,y,r;

int compare(){
 if(num[1][k]<=num[2][k]){
    result[1][k]=num[1][k];
    result[2][k]=num[2][k];
  }
 else{
    result[1][k]=num[2][k];
    result[2][k]=num[1][k];
  }
}

int main(void) {
  while(scanf("%d %d",&a,&b) && a!=0 || b!=0){
  num[1][i]=a;
  num[2][i]=b;
  i++;
}

for(k=0;k<i;k++){
  compare();
  printf("%d %d\n",result[1][k],result[2][k]);
  //printf("%d %d\n",num[1][k],num[2][k]);
}
	//return 0;

}



Measured memory_bytes: 2044
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n)  FOR(i, 0, n)
#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
    int n, k; cin >> n >> k;
    string s; cin >> s;
    REP(i, n) {
        if (i == k - 1) s[i] = s[i] + 0x20;
    }
    cout << s << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN=2000;
bool b[MAXN+10];
int a[MAXN+10];
int c[MAXN+10];
LL f[MAXN+10][MAXN+10][2][2];
LL mi[MAXN+10];
const LL kcz=924844033;
int main() {
    int n,k;
    cin>>n>>k;
    int m=0;
    memset(b,true,sizeof(b));
    for(int i=1; i<=n; ++i) {
        if (b[i]) {
            for(int j=i; j<=n; j+=k) {
                b[j]=false;
                a[++m]=j;
            }
        }
    }
    f[0][0][0][0]=1;
    a[0]=-100000; a[n+1]=100000;
    for(int i=1; i<=n+1; ++i) {
        if (a[i]-a[i-1]==k) c[i]=1;
        else c[i]=0;
    }
    for(int i=1; i<=n; ++i) {
        f[i][0][0][0]=1;
        for(int j=1; j<=i; ++j) {
            f[i][j][0][0]=(f[i-1][j][0][0]+f[i-1][j][1][0]+c[i]*f[i-1][j-1][0][0])%kcz;
            f[i][j][0][1]=c[i+1]*(f[i-1][j-1][1][0]+f[i-1][j-1][0][0])%kcz;
            f[i][j][1][0]=(f[i-1][j][0][1]+f[i-1][j][1][1]+c[i]*f[i-1][j-1][0][1])%kcz;
            f[i][j][1][1]=c[i+1]*(f[i-1][j-1][1][1]+f[i-1][j-1][0][1])%kcz;
        }
    }
    mi[0]=1;
    for(int i=1; i<=n; ++i) {
        mi[i]=(mi[i-1]*i)%kcz;
    }
    LL ans=0;
    for(int i=0; i<=n; ++i) {
        LL x=f[n][i][0][0]+f[n][i][0][1]+f[n][i][1][0]+f[n][i][1][1];
        LL t=x*mi[n-i]%kcz;
        if (i%2==1)
            ans=(ans+kcz-t)%kcz;
        else
            ans=(ans+t)%kcz;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 124032
using System;
class Program
{
	static void Main()
	{
	string[] input = Console.ReadLine().Split(' ');//Splitで区切り文字を指定して複数個受け取る。
	long x = long.Parse(input[0]);
	long y = long.Parse(input[1]);
	int answer = 1;
      
      while(true)
      {
      	if(x*2<=y)
      	{
        	x*=2;
            answer++;
      	}else break;
      }
      
      
	Console.WriteLine(answer);//WriteLineをWriteとすると、改行なしで出力。
	}
}

Measured memory_bytes: 13140
n=int(input())
s=[input() for _ in range(n)]
m=sum([1 for i in s if i[0]=='M'])
a=sum([1 for i in s if i[0]=='A'])
r=sum([1 for i in s if i[0]=='R'])
c=sum([1 for i in s if i[0]=='C'])
h=sum([1 for i in s if i[0]=='H'])
print(m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+a*c*h+r*c*h)

Measured memory_bytes: 88864
// SeeAlso: 

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 100000
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define debug(x) cout<<#x<<": "<<x<<endl
#define debig_vec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) rep(i, h) { rep(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> inline void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> inline void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
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; }

const long long INF = 1LL<<60;

int main() {
    ll n;
    cin >> n;
    vector<ll> a;
    rep(i, n) {
        ll t;
        cin >> t;
        a.push_back(t);
    }
    sort(a.begin(), a.end());
    vector<bool> checked(1000000, true);

    if (a[0]==1) {
        if (n>1&&a[1]==1) {
            print(0);
        } else {
            print(1);
        }
        return 0;
    }

    ll ans = 0;
    rep(i, n) {
        if (i>0 && a[i-1]==a[i]) continue;

        ll target = a[i];
        if (checked[target] && !(i+1<n && a[i]==a[i+1])) {
            ans++;
        }
        while(target<=1000000) {
            checked[target] = false;
            target += a[i];
        }
    }

    print(ans);
    return 0;
}


Measured memory_bytes: 5352
#include<bits/stdc++.h>
using namespace std;
#define int long  long
#define double long double
int t,a;
signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    t=1;
  //  cin>>t;
    while(t--)
    {
        cin>>a;
        cout<<a+a*a+a*a*a<<endl;
    }
}


Measured memory_bytes: 3632
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    S = input().replace("LR", "L R")
    S = S.split()
    ans = []
    for s in S:
        N = len(s)
        tmp = [0] * N
        cnt = 0
        for i in range(N):
            if s[i] == "R":
                cnt += 1
            else:
                break
        tmp[i] += cnt // 2
        tmp[i - 1] += (cnt + 1) // 2

        cnt = N - cnt
        tmp[i] += (cnt + 1) // 2
        tmp[i - 1] += cnt // 2

        ans += tmp

    print(*ans, sep=" ")


if __name__ == "__main__":
    main()


Measured memory_bytes: 9392
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
const int N=1000005;
int n,m;
int fa[N],dis[N];
int finds(int x) {
  if(x==fa[x]) return x;
  int ret=fa[x];
  fa[x]=finds(fa[x]);
  dis[x]+=dis[ret];
  return fa[x];
}
int main() {
  scanf("%d%d",&n,&m);
  for (int i=1;i<=n;++i) fa[i]=i;
  for (int i=1;i<=m;++i) {
    int x,y,d;
    scanf("%d%d%d",&x,&y,&d);
    int fx=finds(x),fy=finds(y);
    if(fx==fy && (dis[x]-dis[y])!=d) {
      puts("No");
      return 0;
    }
    if(fx!=fy) {
      fa[fx]=fy;
      dis[fx]=-dis[x]+dis[y]+d;
    }
  }
  puts("Yes");
  return 0;
}


Measured memory_bytes: 4552
import java.util.Scanner;

public 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 x = sc.nextInt();
		int ans = 0;
		for (int i = 0; i <= a; i++) {
			for (int j = 0; j <= b; j++) {
				for (int k = 0; k <= c; k++) {
					int t = 500 * i + 100 * j + 50 * k;
					if (t == x)
						ans++;
				}
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef complex<double> comp;
const ll INF=1e9+7;
const ll MOD=998244353;
const int MAX=200010;

template< class T >
struct BIT
{
  vector< T > data;

  BIT(int sz)
  {
    data.assign(++sz, 0);
  }

  T sum(int k)
  {
    T ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return (ret);
  }

  void add(int k, T x)
  {
    for(++k; k < data.size(); k += k & -k) data[k] += x;
  }
};

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;cin>>n;
    BIT<ll> bit(n);
    ll q;cin>>q;
    rep(i,n){
        ll a;cin>>a;
        bit.add(i,a);
    }
    rep(i,q){
        ll a,b,x;cin>>a>>b>>x;
        if(a==0){
            bit.add(b,x);
        }else{
            ll res=bit.sum(x-1);
            if(b)res-=bit.sum(b-1);
            cout<<res<<endl;
        }
    }
}

Measured memory_bytes: 8252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60; //intじゃ扱えないことに注意！
#define mod 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++) //範囲外参照とループの初期化に注意！

int main() {
  int N,M;
  int s[M],c[M];
  cin >> N >> M;
  rep(i,M) cin >> s[i] >> c[i];

  vector<bool> can(1000,true);
  if(N == 1){
    for(int i = 10; i <= 999; i++){
      can[i] = false;
    }
    for(int i = 0; i <= 9; i++){
      for(int j = 0; j < M; j++){
        if(i != c[j]) can[i] = false; 
      }
    }
  }
  if(N == 2){
    for(int i = 0; i <= 9; i++){
      can[i] = false;
    }
    for(int i = 100; i <= 999; i++){
      can[i] = false;
    }
    for(int i = 10; i <= 99; i++){
      for(int j = 0; j < M; j++){
        if(s[j] == 1){
          int a = i /10;
          if(a != c[j]) can[i] = false;
        }
        if(s[j] == 2){
          int a = i % 10;
          if(a != c[j]) can[i] = false;
        }
      }
    }
  }
  if(N == 3){
    for(int i = 0; i <= 99; i++){
      can[i] = false;
    }
    for(int i = 100; i <= 999; i++){
      for(int j = 0; j < M; j++){
        if(s[j] == 1){
          int a = i / 100;
          if(a != c[j]) can[i] = false;
        }
        if(s[j] == 2){
          int a = i % 100 /10;
          if(a != c[j]) can[i] = false;
        }
        if(s[j] == 3){
          int a = i % 10;
          if(a != c[j]) can[i] = false;
        }
      }
    }
  }

  bool flag = false;
  for(int i = 0; i < 1000; i++){
    if(can[i]){
      flag = true; 
      cout << i << endl;
      break;
    }
  }
  if(!flag) cout << -1 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s,t;
  	cin>>s>>t;
  	vector<char>vec(0);
  	for(int i=0;i<t.size();i++){
    	vec.push_back(t.at(i));
    }
  	for(int i=0;i<s.size();i++){
    	vec.push_back(s.at(i));
    }
  	for(int i=0;i<vec.size();i++){
    	cout<<vec.at(i);
    }
  	

}

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

int main()
{
    multiset<int> s;
    int q;
    cin >> q;
    while (q--)
    {
        int x, y;
        cin >> x >> y;
        if (x == 0)
        {
            s.insert(y);
            cout << s.size() << endl;
        }
        if (x == 1)
        {
            cout << s.count(y) << endl;
        }
        if (x == 2)
        {
            s.erase(y);
        }
        if (x == 3)
        {
            int z;
            cin >> z;
            for (auto it = s.lower_bound(y); it != s.upper_bound(z); it++)
            {
                cout << *it << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 12332
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#define INF 0x3f3f3f3f
#define MOD 1000000007
using namespace std;

int main(){
	int A,B;
	scanf("%d%d",&A,&B);
	if(A!=1 && B!=1){
		if(A>B) printf("Alice\n");
		else if(B>A) printf("Bob\n");
		else printf("Draw\n");
	}
	else {
		if(A==1 && B!=1) printf("Alice\n");
		if(B==1 && A!=1) printf("Bob\n");
		if(A==1 && B==1) printf("Draw\n");
	}

	return 0;
}

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

#define M 1000000007
#define maxn 500005

using namespace std;
typedef long long ll;

int n, m;

int norm(int a) {
  if (a >= M) return a - M;
  if (a < 0) return a + M;
  return a;
}

int mul(int a, int b) {
  return norm(int(ll(a) * ll(b) % M));
}

int power(int a, int b) {
  if (b == 0) return 1;
  if (b&1) return mul(power(a, b - 1), a);
  int t = power(a, b / 2);
  return mul(t, t);
}

int gt[maxn], igt[maxn];

void precalc(){
  int n = 5e5;

  gt[0] = 1;
  for (int i = 1; i <= n; ++i)
    gt[i] = mul(gt[i - 1], i);

  igt[n] = power(gt[n], M - 2);

  for (int i = n - 1; i >= 0; --i)
    igt[i] = mul(igt[i + 1], i + 1);
}

int C(int n, int k) {
  return mul(mul(gt[n], igt[k]), igt[n - k]);
}


int main(){
  #define TASK "ABC"
 // freopen(TASK".inp", "r", stdin); freopen(TASK".out", "w", stdout);
  ios_base::sync_with_stdio(0);

  precalc();

  cin >> n >> m;

  int ans = 0;

  for (int i = 0; i <= n; ++i) {
    int sign = (i&1 ? -1 : 1);
    int ret = mul(mul(C(n, i), gt[i]), C(m, i));
    int cur = mul(mul(C(m - i, n - i), gt[n - i]), mul(C(m - i, n - i), gt[n - i]));

    ret = mul(ret, cur);

    ans = norm(ans + mul(sign, ret));
  }

  cout << ans;

  return 0;
}


Measured memory_bytes: 7556
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

const int N = 100005;
const int mod = (int) 1e9 + 7;

int n, k;
int fact[N];
int inver[N];
int arr[N];

inline void add(int &a, int b) {
  a += b;
  if (a >= mod) a -= mod;
}

inline void sub(int &a, int b) {
  a -= b;
  if (a < 0) a += mod;
}

inline int mul(int a, int b) {
  return (int) ((long long) a * b % mod);
}

inline int fp(int a, long long b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}

inline int inv(int x) {
  return fp(x, mod - 2);
}

int comb(int n, int k) {
  if (n <= 0 || k > n) return 0;
  int ans = mul(fact[n], inver[k]);
  ans = mul(ans, inver[n - k]);
  return ans;
}

int main() {
  fact[0] = 1;
  inver[0] = 1;
  for (int i = 1; i < N; i++) {
    fact[i] = mul(fact[i - 1], i);
    inver[i] = inv(fact[i]);
  }
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr, arr + n);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    sub(ans, mul(arr[i], comb(n - i - 1, k - 1)));
    add(ans, mul(arr[i], comb(i, k - 1)));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1408
#include<iostream>
using namespace std;
#define ll long long 
#define w 1000000007
int n;
char s[100],t[100];
ll a=1;
bool b,c;

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

  for(int i=0;i<n;i++){
    if(s[i]==t[i]){
      if(!b&&!c)
        a*=3;
      if(b)
        a*=2;
      if(c)
        a*=1;
      a%=w;
      b=true;
      c=false;
    }
    if(s[i]==s[i+1]&&t[i]==t[i+1]){
      if(!b&&!c)
        a*=6;
      if(b)
        a*=2;
      if(c)
        a*=3;
      a%=w;
      b=false;
      c=true;
    }
  }

  cout<<a<<endl;

  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

  int x, a, b;
  cin >> x >> a >> b;

  int ans = x;
  ans = x - a;

  while (b <= ans) {
    ans = ans - b;
  }

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


Measured memory_bytes: 256
def main():

    X, K, D = map(int, input().split())

    if X == 0:
        if K % 2 == 0: return 0
        else: return D
    else:
        X = abs(X)
        if X >= D*K:
            return X - D*K
        else:
            n = X // D
            l = X % D
            if (K - n) % 2 == 0:
                return l
            else:
                return D-l


if __name__ == '__main__':
    print(main())

Measured memory_bytes: 61836