akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include<ext/pb_ds/hash_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long LL;
typedef unsigned long long uLL;
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
LL z = 1;
int read(){
	int x, f = 1;
	char ch;
	while(ch = getchar(), ch < '0' || ch > '9') if(ch == '-') f = -1;
	x = ch - '0';
	while(ch = getchar(), ch >= '0' && ch <= '9') x = x * 10 + ch - 48;
	return x * f;
}
int ksm(int a, int b, int p){
	int s = 1;
	while(b){
		if(b & 1) s = z * s * a % p;
		a = z * a * a % p;
		b >>= 1;
	}
	return s;
}
LL ans;
int main(){
	int i, j, n, m;
	n = read(); m = read();
	j = n / m;
	ans += z * j * j * j;
	if(m % 2 == 0) j = n * 2 / m - n / m;
	else j = 0;
	ans += z * j * j * j;
	printf("%lld", ans);
	return 0;
}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  ll l, r;
  cin >> l >> r;
  ll ans = INF;
  for (ll i = l; i < l + 2100 && i < r; i++) {
    for (ll j = i + 1; j < l + 2100 && j <= r; j++) {
      ans = min(ans, ((i % 2019) * (j % 2019)) % 2019);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
ll gcd(ll a, ll b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}

ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
int main() {
  ll A, B, C, D;
  cin >> A >> B >> C >> D, A--;
  ll num1 = B - B / C - B / D + B / lcm(C, D);
  ll num2 = A - A / C - A / D + A / lcm(C, D);
  cout << num1 - num2 << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    cin>>s;
    string past="",now="";
    int count=0;
    for (int i=0;i<s.size();i++) {
        if (i==0) {
            past+=s[i];
            count++;
        } else {
            now+=s[i];
            if (past!=now) {
                past=now;
                count++;
                now="";
            }
        }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 3668
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> P;
typedef long long int ll;
typedef pair<ll,ll> LLP;
#define INF 1000000007

#define ARRAY_MAX 1005


int cnt[ARRAY_MAX];

int main(){

    int a,b;
    while(cin >> a >> b,a){
        
        REP(i,ARRAY_MAX){
            cnt[i] = 0;
        }
        int maxi = -1;
        int odd = 0;
        maxi = max(maxi,max(a,b));
        a--;
        b--;
        cnt[a]++;
        cnt[b]++;
        while(cin >> a >> b,a){
            maxi = max(maxi,max(a,b));
            a--;
            b--;
            cnt[a]++;
            cnt[b]++;
        }
        REP(i,maxi){
            if(cnt[i] % 2 == 1){
                odd++;
            }
        }
        if(odd <= 2 && cnt[0]%2 == 1 && cnt[1]%2 == 1){
            cout << "OK" << endl;
        }else{
            cout << "NG" << endl;
        }
    }

    


    return 0;
}


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

int main () {
  int N , M , C ;
  cin >> N >> M >> C ;
  int line[M] ;
  for(int i = 0 ; i < M ; i++ ) cin >> line[i] ;
  int ans = 0 ;
  for(int i = 0 ; i < N ; i++ ) {
    int pre = 0 ;
    for(int j = 0 ; j < M ; j++ ){
      int a ;
      cin >> a ;
      pre += a * line[j] ;
    }
    if((pre + C )> 0 ) ans ++ ;
  }
  cout << ans << endl ;
}

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

using ll = long long;
const int INF = 0x3f3f3f3f;
const int MAX_N = 3008;

int N;
ll A[MAX_N];
ll dp[MAX_N][MAX_N];

void solve()
{
	memset(dp, 0, sizeof(dp));
	for(int i=0; i<N; ++i) dp[i][i]=A[i];
	for(int len=2; len<=N; ++len)for(int i=0; i+len<=N;++i){
		int j = i+len-1;
		dp[i][j] = max(A[i]+min(dp[i+1][j-1], dp[i+2][j]), A[j]+min(dp[i][j-2], dp[i+1][j-1]));
	}
	cout << 2*dp[0][N-1]-accumulate(A, A+N, 0LL) << endl;
}

int main()
{
	cin >> N;
	for(int i=0;i<N;++i)cin >> A[i];
	solve();
	return 0;
}

Measured memory_bytes: 71040
// Sky's the limit :)
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    int T = 1; 
    // cin >> T; 
    while (T--) {
        int n;
        cin >> n;
        int ans = 0;
        for(int i = 1; i <= n; i++) {
            int x;
            cin >> x;
            if(i % 2 == 1 && x % 2 == 1)
                ans++;
        }
        cout << ans << '\n';
        
    }
    
    return 0;
}



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

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

int main(void){
  int w, h, x, y;
  cin >> w >> h >> x >> y;
  
  double ans = (double)w*h / 2;
  int num = (w==x*2 && h==y*2) ? 1 : 0;
  printf("%.10f %d\n", ans, num);
  return 0;
}


Measured memory_bytes: 256
# row = [int(x) for x in input().rstrip().split(" ")]
# n = int(input().rstrip())
# s = input().rstrip()

def resolve():
    import sys
    input = sys.stdin.readline
    s = input().rstrip()
    t = input().rstrip()

    for i in range(100):
        rotated = s[i:] + s[:i]
        if rotated == t:
            print("Yes")
            return

    print("No")

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 61788
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
    int n, tmp; cin >> n;
    vector<int> num;
    for (int i = 0; i < n; ++i) {
        cin >> tmp;
        num.push_back(tmp);
    }

    int o;
    while (true) {
        for (int i = 0; i < n; ++i) {
            if (num[i] % 2) {
                cout << o << endl;
                return 0;
            }
            num[i] /= 2;
        }
        o++;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX = 200000;

int main() {
  int R[MAX], n;

  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> R[i];
  }

  int maxv = -2000000000;
  int minv = R[0];

  for (int i = 1; i < n; ++i) {
    maxv = max(maxv, R[i] - minv);
    minv = min(minv, R[i]);
  }

  cout << maxv << endl;

  return 0;
}



Measured memory_bytes: 3880
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int N;
  cin >> N;
  vector<pair<ll, ll>> bt(N);
  vector<ll> cnt(N, 0);
  for (int i = 0; i < N; i++) {
    ll a, b;
    cin >> a >> b;
    a %= b;
    bt[i] = make_pair(a, b);
  }

  ll ans = 0, sum = 0;
  for (int i = N - 1; i >= 0; i--) {
    ll a = bt[i].first, b = bt[i].second;
    if (a) {
      sum += b - a;
      ans += b - a;
    }
    if (i != 0) {
      bt[i - 1].first += sum;
      bt[i - 1].first %= bt[i - 1].second;
    }
  }

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

Measured memory_bytes: 2560
//Multiple of 2 and N
#include <iostream>
using namespace std;

#include <bits/stdc++.h>
using namespace std;

/*
正数Nに対して素数か判定する。
has_divisorは自身以外の約数を持つか？
    Nを、iからNまでの整数で割れるかをみる。
    i>=2(実質3)からとなる。
is_primeは素数判定
*/
bool has_divisor(int N, int i) {
  if (i == N) {
    return false;
  }
  if (N % i == 0) {
    return true;
  }
  return has_divisor(N, i + 1);
}

bool is_prime(int N) {
  if (N == 1) {
    return false;
  }
  else if (N == 2) {
    return true;
  }
  else {
    return !has_divisor(N, 2);
  }
}

int main() {
    int N;
    cin>>N;
    bool prime=is_prime(N);
    if(N==2)    cout<<2<<endl;
    else if(prime)   cout<<2*N<<endl;
    else        cout<<( N%2 ? 2*N:N)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	char a[2],b[2];
	scanf("%s%s",a,b);
	if(a[0] == 'H'){printf("%c\n",b[0]);}
	else{
		if(b[0] == 'H'){printf("D\n");}else{printf("H\n");}
	}
	return 0;
}

Measured memory_bytes: 128
import java.util.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] a = new long[3 * n];
		for (int i = 0; i < 3 * n; i++) {
			a[i] = sc.nextLong();
		}
		Arrays.sort(a);
		long sum = 0;
		int count = 0;
		for (int i = 3 * n - 2; count < n; i -= 2) {
			sum += a[i];
			count++;
		}
		System.out.println(sum);
 	}
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)

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

const int MOD = 1000000007;

struct mint {
  int n;
  mint(int n_ = 0) : n(n_) {}
};
mint operator-(mint a) { return -a.n + MOD * (a.n != 0); }
mint operator+(mint a, mint b) {
  int x = a.n + b.n;
  return x - (x >= MOD) * MOD;
}
mint operator-(mint a, mint b) {
  int x = a.n - b.n;
  return x + (x < 0) * MOD;
}
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }
istream &operator>>(istream &i, mint &a) { return i >> a.n; }
ostream &operator<<(ostream &o, mint a) { return o << a.n; }

vector<mint> F_{1, 1}, R_{1, 1}, I_{0, 1};

void check_fact(int n) {
  for (int i = I_.size(); i <= n; i++) {
    I_.push_back(I_[MOD % i] * (MOD - MOD / i));
    F_.push_back(F_[i - 1] * i);
    R_.push_back(R_[i - 1] * I_[i]);
  }
}

mint I(int n) {
  check_fact(abs(n));
  return n >= 0 ? I_[n] : -I_[n];
}
mint F(int n) {
  check_fact(n);
  return n < 0 ? 0 : F_[n];
}
mint R(int n) {
  check_fact(n);
  return n < 0 ? 0 : R_[n];
}
mint C(int n, int r) { return F(n) * R(n - r) * R(r); }
mint P(int n, int r) { return F(n) * R(n - r); }
mint H(int n, int r) { return n == 0 ? (r == 0) : C(n + r - 1, r); }

int main() {
  ll N, K, Q;
  int i;
  cin >> N >> K >> Q;
  vector<int> A(N);
  vector<int> a(Q);
  rep(i, Q) cin >> a[i];

  for (i = 0; i < N; i++) {
    A[i] = K - Q;
  }

  for (i = 0; i < Q; i++) {
    A[a[i]-1]++;
  }

  for (i = 0; i < N; i++) {
    cout << (A[i] > 0 ? "Yes" : "No") << endl;
  }
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <set>
using namespace std;

int main() {
	set<int> hist;
	int s; cin >> s;
	int i = 1;
	int old = s;
	hist.insert(s);
	i++;

	do {
		if(old % 2 == 0) {
			hist.insert(old);
			old = old / 2;
		} else {
			hist.insert(old);
			old = 3 * old + 1;
		}
		i++;
	} while(hist.count(old) == 0);
	cout << --i << endl;
}


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

int main(){
    int c[3][3];
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin >> c[i][j];
        }
    }
    int a = c[0][0] - c[0][1];
    int b = c[1][0] - c[1][1];
    int d = c[2][0] - c[2][1];
    int e = c[0][1] - c[0][2];
    int f = c[1][1] - c[1][2];
    int g = c[2][1] - c[2][2];
    if((a==b && b==d) && (e == f && f == g)) {
        cout << "Yes\n";
    }else {
        cout <<"No\n";
    }


    return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    L, R, d = map(int, readline().split())
    ans = R//d - L//d
    if L%d==0:
        ans += 1
    print(ans)

if __name__ == '__main__':
    main()


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

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

	if((n % 500) <= a ){
		cout <<"Yes\n";
	}
	else if(n==a)
		cout << "Yes\n";
	else if(a==0 && n > 0)
		cout <<"No\n";
	else 
		cout << "No\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <cmath>
#include <algorithm>
using namespace std;
typedef complex<double> C;
#define EPS (1e-6)

int n;
C c[301];

void solve() {
  for(int i=0;i<n;i++)
  cin>>c[i].real()>>c[i].imag();
  
  int res = 1;
  for (int i = 0; i < n; i += 1) {
    for (int j = i+1; j < n; j += 1) {
      C v = c[j] - c[i];
      double absv = abs(v);
      if (absv > 2.0 + EPS) continue;
      // _
      C m = c[i] + (v / 2.0);
      // ~ÜÅÌ£
      double dist = sqrt(1.0 - absv * absv / 4.0);
      // PÊ@üxNg
      C unv  = (v * C(0, 1)) / absv;
      // S
      C nv = unv * dist;
      for (int k = 0; k < 2; k += 1) {          
        int cnt = 0;
        nv *= -1;
        C tc = m + nv;
        for (int l = 0; l < n; l += 1) {
          if (abs(tc - c[l]) < 1.0 + EPS) cnt++;
        }
        res = max(res, cnt);
      }
    }
  }
  cout<<res<<endl;
}

int main (int argc, char const* argv[]) {
  while (cin>>n, n) {
    solve();
  }
  return 0;
}

Measured memory_bytes: 980
'use strict'
let input = require("fs").readFileSync("/dev/stdin", "utf8");
// 必要な変数に定義する
input = input.trim().split('\n');
let info = input.shift();
let N = info.split(" ")[0]*1;
let X = info.split(" ")[1];
// 配列要素を数値に変換
let arr = input.map(x=> x*1);
let min = Math.min(...arr);
// とりあえず1つずつ要素を足したもの
let sum = arr.reduce((x,a)=> {return a+x})
// 残りで一番量が少なくて済むドーナッツに割り当てる
let ans = N + Math.floor((X - sum)/min);
console.log(ans);

Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int a[100010];
vector<int> v[100010];
int main(){
    int n;
    while(cin>>n){
        ll ans=1, mod=1e9+7;
        int mx=0;
        for(int i=0; i<n; ++i){
            scanf("%d",a+i);
            v[a[i]].push_back(i);
            mx=max(mx, a[i]);
        }
        for(int i=0; i+1<=mx; ++i){
            if(v[i+1].size()>3||v[i].size()>3)
                ans=0;
            for(int j=0; j<v[i+1].size(); ++j){
                ll tmp=0;
                for(int k=0;k<v[i].size(); ++k){
                    if(v[i][k]>v[i+1][j])
                        break;
                    ++tmp;
                }
                tmp-=j;
                ans*=tmp;
                ans%=mod;
            }
        }
        ll sx=6, th=3;
        if(v[0].size()>=2){
            ans*=sx;
        }
        else if(v[0].size()==1){
            ans*=th;
        }
        if(v[0].size()>3){
            ans=0;
        }
        ans%=mod;
        if(ans<0){
            ans+=mod;
        }
        cout<<ans<<endl;
    }
  return 0;
}




Measured memory_bytes: 6144
import std.stdio, std.conv, std.string, std.range, std.algorithm, std.array,
  std.functional, std.container, std.typecons;

void main() {
  int N = readln.chomp.to!int;
  int[] d = readln.split.to!(int[]);

  int ans = 0;
  foreach(i; 0..N) {
    foreach(j; (1+i)..N) {
      ans += d[i] * d[j];
    }
  }
  ans.writeln;
}


Measured memory_bytes: 256
def main():
    N, K = map(int, input().split())
    R, S, P = map(int, input().split())
    T = input()

    score = {'r': P, 's': R, 'p': S}

    ret = 0
    for r in range(K):
        i = r
        p = ''
        while i < N:
            if T[i] == p:
                p = ''
            else:
                ret += score[T[i]]
                p = T[i]
            i += K
    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
def knapsack(N,W,w,v):
    dp = [[0]*(W+1) for _ in range(N)]
    
    for i in range(N):
        for j in range(W+1):
            if j-w[i]>=0:
                dp[i][j] = max(dp[i-1][j],v[i]+ dp[i-1][j-w[i]])
            else:
                dp[i][j] = dp[i-1][j]
    
    return dp[N-1][W]

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

print(knapsack(N,W,w,v))

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

inline void swap(int *a, int *b){ int t = *a; *a = *b; *b = t; }

int main()
{
  int a, b;
  while (1)
  {
    cin >> a >> b;
    if ((a == 0) && (b == 0)) return 0;
    if (a > b) swap(&a, &b);
    cout << a << ' ' << b << endl;
  }
}

Measured memory_bytes: 1160
n, d = map(int, input().split())
x = [[int(i) for i in input().split()] for _ in range(n)]

s = []
for i in range(len(x)):
    for j in range(i + 1, len(x)):
        a = 0
        for y, z in zip(x[i], x[j]):
            a += (y - z) ** 2
        s.append(a)

ans = 0
for si in s:
    for i in range(400):
        if i ** 2 == si:
            ans += 1

print(ans)

Measured memory_bytes: 3064
S = input()
T = input()

res = float('inf')
nt = len(T)
ns = len(S)
for i in range(ns-nt+1):
    count = 0
    for j in range(nt):
        if T[j] != S[i+j]:
            count +=1 
    res = min(res, count)
print(res)

Measured memory_bytes: 9116
#include<iostream>
#include<functional>
#include<vector>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<algorithm>
#include<map>
#include<bitset>
using namespace std;
using ll =long long;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(i) i.begin(),i.end()
template<typename T=ll>
using v =vector<T>;
template<typename T=ll>
using vv = vector<v<T>>;
template<typename T=ll,typename U=ll> using p = pair<T,U>;
const ll INF = (ll)1e9;
const ll MOD = INF+7;
template<typename T> T chmin(T &a,T b){a=min(a,b);}
template<typename T> T chmax(T &a,T b){a=max(a,b);}

void a(){
    string s,t; 
    cin >> s >> t;
    if(s==t.substr(0,t.size()-1)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

void b(){
    ll a,b,c,k; 
    cin >> a >> b >> c >> k;
    ll count=0;

  	rep(i,a){
      	if(k<=0) break;
        k--;
        count++;
    }
  
    rep(i,b){
      	if(k<=0) break;
        k--;
    }
  
    rep(i,c){
      	if(k<=0) break;
        k--;
        count--;
    }

  	cout << count << endl;

}

void c(){
    ll N,M,X; cin >> N >> M >> X;
    auto C = v<>(N,0); 
    auto A = vv<>(N,v<>(M,0));
    rep(i,N) {
        cin >> C[i];
        rep(j,M) cin >> A[i][j];
    }
    ll _min = INF;
    rep(i,1<<N){
        cout << bitset<3>(i) << ":";
        for(ll ii=0;(1<<ii)<i;i++){
            if((i>>ii)&1) cout << ii<<" ";
        }
        cout << endl;
        
    }
    cout << _min << endl;
}

void d(){
    ll N,K; cin >> N >> K;
    auto A = v<>(N,0);
  	auto B = v<bool>(N,false);
	auto C = v<p<>>();
  	rep(i,N) {
        cin >> A[i];
        A[i]--;
    }
    auto s = p<>(0,A[0]);
  	ll i = 0;
    while(K){
      	if(B[s.first])break; 
        B[s.first]=true;
      	C.push_back(s);
      	s.first = A[s.first];
      	s.second = A[s.first];
      	K--;
      	i++;
    }
  	if(!K) cout << s.first + 1 << endl;
    else{
        auto it = find(C.begin(),C.end(),s);
        auto off = it-C.begin();
        cout << C[off+K%(C.size()-off)].first + 1 << endl;
    } 
}

int main(){
    d();
    return 0;
}


Measured memory_bytes: 9056
def solve(i, m)
	return true if m == 0
	return false if i >= $n
	return solve(i + 1, m) || solve(i + 1, m - $a[i])
end

$n = gets.to_i
$a = gets.split.map &:to_i
q = gets.to_i
m = gets.split.map &:to_i

m.each do |val|
	if solve(0, val)
		puts "yes"
	else 
		puts "no"
	end
end

Measured memory_bytes: 8620
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(long long i=0;i<(n);++i)
#define Fr(i,n) for(long long i=1;i<=(n);++i)
#define ifr(i,n) for(long long i=(n)-1;i>=0;--i)
#define iFr(i,n) for(long long i=(n);i>0;--i)
using Graph = vector<vector<int>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  fr(i,5){
    int a;
    cin>>a;
    if(a==0){
      cout<<i+1;
    }
  }
}

Measured memory_bytes: 3608
#include <stdio.h>
int main()
{
  int i,j,n,m,d,count=0;

  scanf("%d",&m);
  scanf("%d",&d);

  for(i=4;i<=m;i++)
    {
      for(j=2;j<=i/2;j++)
	{
	  if(i%j==0 && i/j>=2 && i/j<=9)
	    {
	      if((10*j+i/j)<=d)
		{
		  count++;
		  
		}
	      
	    }
	  
	}
    }
  

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



  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int n,m;
main()
{
	while(cin>>n>>m,n)
	{
		vector<int>a,b;
		for(int i=0;i<n;i++)
		{
			int s;cin>>s;a.push_back(s);
		}
		for(int i=0;i<m;i++)
		{
			int s;cin>>s;b.push_back(s);
		}
		sort(a.begin(),a.end());sort(b.begin(),b.end());
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				if(a[i]==b[j])
				{
					b[j]=0;
					break;
				}
			}
		}
		int ans=0;
		for(int i=0;i<n;i++)ans+=a[i];
		for(int i=0;i<m;i++)ans+=b[i];
		cout<<ans<<endl;
	}
}



Measured memory_bytes: 3128
#include <bits/stdc++.h>
        using namespace std;
        #define int long long
const int MAX = 1000001;
const int MOD = 1000000007;
   
        signed main() {
           int h,n;
           cin>>h>>n;
           int a;
           for(int i=0;i<n;i++){
               cin>>a;
               h-=a;
           }
           if(h<=0)cout<<"Yes";
           else cout<<"No";
           return 0;

        }


Measured memory_bytes: 256
#include <iostream>
#define A 1
#define B 2
#define C 3
using namespace std;

int main() {
  int x, y;
  int a, b;
  cin >> x >> y;
  if (x == 2) {
    a = A;
  } else if (x == 4 || x == 6 || x == 9 || x == 11) {
    a = B;
  } else {
    a = C;
  }

  if (y == 2) {
    b = A;
  } else if (y == 4 || y == 6 || y == 9 || y == 11) {
    b = B;
  } else {
    b = C;
  }

  if (a == b) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

int main(void) {
	
	int a,b,k;
	cin >>a >>b >>k;
	
	int i,war[100],cn=0;
	for (i=100 ; i>0 ; i--) {
		if (a%i==0 && b%i==0) {
			war[cn]=i;
			cn++;
		}
	}
	
	cout <<war[k-1] <<endl;
	
	return 0;
}

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

using namespace std;

int a[2005];

int main(){
    int tmp = 0;
    int n,x,y;
    cin >> n >> x >> y;
    for (int i = 1 ;i <= n;i++){
        for (int j = i + 1;j <=n;j++){
            a[min(abs(j-i),abs(i-x)+abs(j-y)+1)]++;
        }
    }


    for (int i = 1;i <n;i++){
        cout << a[i] << endl;
    }

    return 0;
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

class RMQ{
private:
	int32 n;
	vector<int64> node, lazy;
	vector<bool> lazyFlag;
public:
	RMQ(vector<int64> v){
		int sz = v.size();
		n = 1; while(n < sz) n *= 2;
		node.resize(2*n-1, INF_LL);
		lazy.resize(2*n-1, 0);
		lazyFlag.resize(2*n-1, false);
		for(int32 i = 0;i < sz;i++) node[i+n-1] = v[i];
		for(int32 i = n-2;i >= 0;i--) node[i] = min(node[2*i+1], node[2*i+2]);
	}

	void eval(int32 k, int32 l, int32 r){
		if(lazyFlag[k]){
			node[k] = lazy[k];
			if(r-l > 1){
				lazy[2*k+1] = lazy[k];
				lazy[2*k+2] = lazy[k];
				lazyFlag[2*k+1] = lazyFlag[2*k+2] = true;
			}
			lazy[k] = 0;
			lazyFlag[k] = false;
		}
	}

	void update(int32 a, int32 b, int64 x, int32 k=0, int32 l=0, int32 r=-1){
		if(r < 0) r = n;
		eval(k, l, r);
		if(b <= l || r <= a) return;

		if(a <= l && r <= b){
			lazy[k] = x;
			lazyFlag[k] = true;
			eval(k, l, r);
		}else{
			update(a, b, x, k*2+1, l, (l+r)/2);
			update(a, b, x, k*2+2, (l+r)/2, r);
			node[k] = min(node[k*2+1], node[k*2+2]);
		}
	}

	int64 query(int32 a, int32 b, int32 k=0, int32 l=0, int32 r=-1){
		if(r < 0) r = n;
		eval(k, l, r);

		if(b <= l || r <= a) return INF_LL;
		if(a <= l && r <= b) return node[k];

		return min(query(a, b, k*2+1, l, (l+r)/2), query(a, b, k*2+2, (l+r)/2, r));
	}
};

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int32 N, M, Q;
	cin >> N >> M >> Q;
	using tup = tuple<int64, int32, int32, int32>;
	vector<tup> q;
	REP(i, M){
		int64 d, a, b;
		cin >> d >> a >> b;
		q.push_back(tup(d, 1, a, b));
	}
	REP(i, Q){
		int64 d, a, b;
		cin >> d >> a >> b;
		q.push_back(tup(d, -i, a, b));
	}
	sort(all(q));
	RMQ rmq(vector<int64>(2*N+1, 0));
	vector<string> res(Q);
	REP(i, q.size()){
		int64 d, t, a, b;
		tie(d, t, a, b) = q[i];
		if(t <= 0){
			if(rmq.query(a*2, b*2+1) != 0){
				res[-t] = "Yes";
			}else{
				res[-t] = "No";
			}
		}else{
			rmq.update(a*2, b*2+1, 1);
		}
	}
	REP(i, res.size())
		cout << res[i] << endl;
	return 0;
}



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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define pb push_back
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}


int N,M,orig,dest;

vector<int>lis[111111];

const int INF=1001001001;
vector<int>dp[111111];

vector<tuple<int,int,int>>ev[222222];
vector<int>latte[222222];
signed main(){
    cin>>N>>M>>orig>>dest;
    orig--;dest--;

    lis[orig].pb(0);

    latte[0].pb(orig);
    rep(i,M){
        int a,b,t,c;
        scanf("%lld%lld%lld%lld",&a,&b,&t,&c);
        a--;b--;
        latte[t].pb(a);
        latte[t+c].pb(b);

        lis[a].pb(t);
        lis[b].pb(t+c);
        ev[t].pb(make_tuple(a,b,c));
    }

    rep(i,N){
        sort(all(lis[i]));
        lis[i].erase(unique(all(lis[i])),lis[i].end());
    }

    rep(i,N){
        dp[i]=vint(lis[i].size(),INF);
    }
    dp[orig][0]=0;
    for(int t=0;t<222222;t++){
        for(auto w:latte[t]){
            int k=lower_bound(all(lis[w]),t)-lis[w].begin();
            if(k+1!=lis[w].size()){
                chmin(dp[w][k+1],dp[w][k]+lis[w][k+1]-lis[w][k]);
            }
        }

        for(auto &w:ev[t]){
            int a,b,c;
            tie(a,b,c)=w;

            int k=lower_bound(all(lis[a]),t)-lis[a].begin();
            int l=lower_bound(all(lis[b]),t+c)-lis[b].begin();
            chmin(dp[b][l],dp[a][k]);
        }
    }

    int ans=INF;
    rep(i,lis[dest].size())chmin(ans,dp[dest][i]);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 41796
#define D(x) cout << #x " = " << x << endl
#define DD(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define DDD(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl
#define DV(v) for (auto __macro_vi : v){ cout << __macro_vi << " ";} cout << endl;
#define DA(a, n) for (int __macro_i = 0; __macro_i < n; ++__macro_i) { cout << a[__macro_i] << " "; } cout << endl;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>

using namespace std;

int n;

vector<vector<int>> g;
vector<vector<int>> memo;
const int MOD = 1000000007;

int recv(int node, bool black, int prev = -1) {
    if (memo[node][black ? 0 : 1] != -1) return memo[node][black ? 0 : 1];
    int ans = 1;
    for (auto adj : g[node]) {
        if (adj == prev) continue;
        int tmp = 0;
        if (!black) {
            tmp += (recv(adj, true, node)) % MOD;
        }
        tmp += (recv(adj, false, node)) % MOD;
        ans = ((long long)ans * tmp) % MOD;
    }
    // DDD(node, black, ans);
    memo[node][black ? 0 : 1] = ans;
    return ans;
}

int main()
{
    cin >> n;
    g = vector<vector<int>>(n, vector<int>());
    memo = vector<vector<int>>(n, vector<int>(2, -1));
    REP(i, n - 1) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    // for(auto row : g) {
    //     cout << "a";DV(row);
    // }
    cout << (recv(0, true) + recv(0, false)) % MOD << endl;
}


Measured memory_bytes: 18176
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int r = 1;
    for (int b = 2; b < x; b++) {
        int t = b;
        for (int t = b * b; t <= x; t *= b) {
            r = max(r, t);
        }
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

bool Contains(
    int width, int height,
    int x, int y, int radius
)
{
    if ( x < radius ) return false;
    if ( y < radius ) return false;
    if ( x + radius > width ) return false;
    if ( y + radius > height ) return false;
    return true;
}

int main()
{
    int width, height, x, y, radius;
    std::cin >> width >> height >> x >> y >> radius;

    const bool contains = Contains( width, height, x, y, radius );
    std::cout
        << ( contains ? "Yes" : "No" )
        << std::endl;
    return 0;
}

Measured memory_bytes: 1160
A, B, Q = gets.chomp.split.map(&:to_i)
Inf = 10**12
as = 0.upto(A-1).map{|i| gets.to_i}
as.unshift(-Inf); as.push(Inf)
bs = 0.upto(B-1).map{|i| gets.to_i}
bs.unshift(-Inf); bs.push(Inf)
xs = 0.upto(Q-1).map{|i| gets.to_i}

ans = Array.new(Q)
xs.each do |x|
  ai = as.bsearch_index{|a| x < a}
  wa = as[ai-1]; ea = as[ai]
  bi = bs.bsearch_index{|b| x < b}
  wb = bs[bi-1]; eb = bs[bi]
  ans_ww = x - [wa, wb].min
  ans_we = [(x - wa) + (eb - wa), (x - wb) + (ea - wb)].min
  ans_ee = [ea, eb].max - x
  ans_ew = [(ea - x) + (ea - wb), (eb - x) + (eb - wa)].min
  ans = [ans_ww, ans_we, ans_ee, ans_ew].min
  puts ans
end

Measured memory_bytes: 6836
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto D = readln.chomp.to!int;
    switch (D) {
        case 22:
            writeln("Christmas Eve Eve Eve");
            break;
        case 23:
            writeln("Christmas Eve Eve");
            break;
        case 24:
            writeln("Christmas Eve");
            break;
        case 25:
            writeln("Christmas");
            break;
        default:
    }
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <memory.h>



using namespace std;
static const double EPS = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a,0,sizeof(a))
#define minus(a) memset(a,0xff,sizeof(a))
#define chmax(a,b) a=min((a),(b))
#define chmin(a,b) a=max((a),(b))


#define MOD 1000000007

typedef pair<int,int>P;
#define INF (1<<29)
 
struct edge { 
	int from, to; 
	edge (int from, int to){
		this->from=from; this->to=to;
	}
};
 
int V,E;
typedef vector<edge> edges;
vector<edges> G;

ll n, a, b;
ll h[100005];
ll work[100005];

bool check(ll m) {
	rep(i, n) {
		work[i] = h[i] - b*m;
	}
	ll cnt = 0;
	rep(i, n) {
		if (work[i] > 0) {
			cnt += (work[i] + (a - b - 1)) / (a - b);
		}

	}
	if (cnt > m)
		return false;
	else
		return true;
}

int main(){
	scanf("%lld %lld %lld ", &n, &a, &b);
	rep(i, n) {
		scanf("%lld ", &h[i]);
	}
	ll l = -1, r = 1000000005;
	ll mid;
	while (r - l > 1) {
		mid = (l + r) / 2;

		if (check(mid)) {
			r = mid;
		}
		else {
			l = mid;
		}
		
	}
	cout << r << endl;
	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<math.h>
#include <algorithm>
using namespace std;

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

        int ichi = 0, zero=0,  ans=-1;

        for(int i = 0; i < s.size(); i++){
                /* 010101 */
                if( i % 2 == 0 && s[i] != '0') zero++;
                if( i % 2 == 1 && s[i] != '1') zero++;
                if( i % 2 == 0 && s[i] != '1') ichi++;
                if( i % 2 == 1 && s[i] != '0') ichi++;
        }

        if(ichi > zero){
                if(zero != 0) ans = zero;
                else ans = 0;
        } else if(ichi == 0){
                ans = 0;
        } else {
                ans = ichi;
        }


        cout << ans << endl;
}

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

int check_digit(string s){
  int sum = 0;
  for(int i=1;i<=(int)s.size();i++){
    int q = i+1;
    if(i>6) q = i-5;
    sum += (int)(s[11-i]-'0') * q;
  }
  sum %= 11;


  int ans = 11 - sum;
  if(sum <= 1) ans = 0;
  return ans;
}

int main(){
  int n=12;
  string s;
  cin >> s;

  int pos = 0;
  for(int i=0;i<n;i++){
    if(s[i] == '?') pos = i;
  }

  if(pos == 11){
    cout << check_digit(s.substr(0,11)) << endl;
  }else{
    vector<int> ans;
    for(int i=0;i<10;i++){
      s[pos] = '0'+i;
      if(check_digit(s.substr(0,11))+'0' == s[11]){
	ans.push_back(i);
      }
    }

    if(ans.size()>1){
      cout << "MULTIPLE" << endl;
    }else{
      cout << ans[0] << endl;
    }
  }
}

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

#define INF 1000000000
#define MOD 1000000007

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

int main(){
    int N;
    cin >> N;
    
    if(N == 1){
        cout << "Hello World" << endl;
    } else {
        int A, B;
        cin >> A >> B;
        cout << A + B << endl;
    }
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(all(v),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  while(cin >> n){
    string s = "";
    rep(i,10){
      if(n & (1 << i)){
        s += to_string(1<<i)+ " ";
      }
    }
    s.resize(s.size()-1);
    cout << s <<endl;
  }
  return 0;
}

Measured memory_bytes: 3220
#import math
#input()
n=int(input())
#map(int,input().split())
#list(map(int,input().split()))
#[input() for _ in range()]

ans = 0
for i in range(1,n+1):
    if (i%3 != 0) and (i%5 != 0):
        ans += i
print(ans)

Measured memory_bytes: 9068
a, b, c, d = map(int, input().split())
ok = True
for i in range(1000):
    if (i % 2 == 0):
        c -= b
        if (c <= 0):
            break
    else:
        a -= d
        if (a <= 0):
            ok = False
            break
if (ok):
    print('Yes')
else:
    print('No')


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

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T,typename U>bool chmin(T& a,const U& b){return a>b?(a=b,1):0;}
template<typename T,typename U>bool chmax(T& a,const U& b){return a<b?(a=b,1):0;}

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

bool solve(const vector<vector<tuple<int,int>>>& g)
{
	int n=g.size();

	constexpr int UNKNOWN=1.1e9;
	vi xs(n,UNKNOWN);

	rep(i,n) if(xs[i]==UNKNOWN){
		queue<tuple<int,int>> q;
		q.emplace(i,0);
		while(q.size()){
			int u,x; tie(u,x)=q.front(); q.pop();
			if(xs[u]!=UNKNOWN){
				if(xs[u]!=x)
					return false;
				else
					continue;
			}
			xs[u]=x;
			for(auto e:g[u]){
				int v,d; tie(v,d)=e;
				q.emplace(v,x+d);
			}
		}
	}
	return true;
}

int main()
{
	#ifndef _GLIBCXX_DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	constexpr char endl='\n';
	#endif

	for(int n,m;cin>>n>>m&&n|m;){
		vector<vector<tuple<int,int>>> g(n);
		rep(i,m){
			int l,r,d; cin>>l>>r>>d; l--,r--;
			g[l].emplace_back(r,d);
			g[r].emplace_back(l,-d);
		}
		cout<<(solve(g)?"Yes":"No")<<endl;
	}
}


Measured memory_bytes: 11252
# -*- coding: utf-8 -*-
import sys
import collections

def main():
	N, A, B, C = map(int, input().split(" "))
	ls = []
	for _ in range(N):
		tmp = int(input())
		ls.append(tmp)
	
	ptn = []
	for i in range(4**N):
		tmp = []
		for j in range(N):
			tmp.append(i >> (j*2) & 3)
		ptn.append(tmp)
	
	gattai = 0
	mp = -1
	for i, val in enumerate(ptn):
		a_count = 0
		b_count = 0
		c_count = 0
		a_ni = 0
		b_ni = 0
		c_ni = 0
		for j, vol in enumerate(val):
			if vol == 1:
				a_ni += ls[j]
				a_count += 1
			if vol == 2:
				b_ni += ls[j]
				b_count += 1
			if vol == 3:
				c_ni += ls[j]
				c_count += 1
		
		if a_count == 0 or b_count == 0 or c_count == 0:
			continue
		mp_tmp = abs(a_ni - A) + abs(b_ni - B) + abs(c_ni - C) + ((a_count + b_count + c_count -3) * 10)
		if mp == -1 or mp > mp_tmp:
			mp = mp_tmp
			#print("{} {} {}".format(a_count , b_count , c_count))
			
	print(mp)
	
	
if __name__ == "__main__":
	main()
	

Measured memory_bytes: 13044
#include<iostream>
using namespace std;
int main(){
	int row[2],order[10],memo[10][2],n;
	cin >>n;
	for(int i=0; i<n; i++){
		for(int l=0; l<10; l++){
			cin >>order[l];
		}
		row[0] = order[0];
		row[1] = 0;
		int x = 0,l;
		for(l=1; l<10; l++){
			if(row[0]<order[l] && row[1]>order[l]){row[0] = order[l];}
			else if(row[0]>order[l] && row[1]<order[l]){row[1] = order[l];}
			else if(row[0]<order[l] && row[1]<order[l]){
				memo[x][0] = row[0];
				memo[x][1] = l;
				row[0] = order[l];
				x++;
			}
			else if(row[0]>order[l] && row[1]>order[l]){
				if(x == 0){cout <<"NO"<<endl;break;}
				else{
					x--;
					row[0] = memo[x][2];
					l = memo[x][1];
					row[1] = order[l];
				}
			}
		}
		if(l == 10){cout <<"YES"<<endl;}
	}
	return 0;
}

Measured memory_bytes: 0
n, q = map(int, input().split())
A = [[] for i in range(n)]
while q:
    q -= 1
    op = input().split()
    if op[0] == '0':
        A[int(op[1])].append(op[2])
    elif op[0] == '1':
        print(*A[int(op[1])])
    else:
        A[int(op[1])].clear()


Measured memory_bytes: 42524
#include<bits/stdc++.h>
typedef long long ll;
typedef double ld;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PRECISION std::cout << std::fixed << std::setprecision(20);
  
using namespace std;
 
const ll inf = 1e9;
const ll N = 305;
const ll bits = 21;
const ll mod = 1e9+7;
const ld pi = 3.14159265358979323846;
 
ld dp[N][N][N],e[N][N][N];

int main(){
    FASTIO;
    PRECISION;

    ll n,temp;
    cin>>n;
    vector<ll>cnt(4,0);

    for(int i=0;i<n;i++){
        cin>>temp;
        cnt[temp]++;
    }

    dp[cnt[1]][cnt[2]][cnt[3]] = 1;

    for(int c=n;c>=0;c--){
        for(int b=n;b>=0;b--){
            for(int a=n;a>=0;a--){
                if(a==0 && b==0 && c==0) continue;
                if(a+b+c>n) continue;

                ld pw = (ld) (n - (a + b + c) )/n;
                ld ew = (ld) pw / (1-pw) + 1;
                e[a][b][c] += ew * dp[a][b][c];

                if(a!=0){
                    ld  pc = (ld) a / (a+b+c);
                    dp[a-1][b][c]+=dp[a][b][c] * pc;
                    e[a-1][b][c] +=e[a][b][c]*pc;
                }


                if(b!=0){
                    ld  pc = (ld) b / (a+b+c);
                    dp[a+1][b-1][c]+=dp[a][b][c] * pc;
                    e[a+1][b-1][c] += e[a][b][c]*pc;
                }


                if(c!=0){
                    ld  pc = (ld) c / (a+b+c);
                    dp[a][b+1][c-1]+=dp[a][b][c] * pc;
                    e[a][b+1][c-1]+=e[a][b][c]*pc;
                }
            }
        }
    }


    // ld ans = e[0][0][0];
    cout<<e[0][0][0]<<"\n";

}

Measured memory_bytes: 438528
// AOJ 0301: Baton Relay Game
// 2017.10.31 bal4u@uu
// 2017.11.25

#include <stdio.h>

typedef struct _T { struct _T *pre, *nxt; char f; } T;
T tbl[200002];
char buf[800000], *p;

int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

int main()
{
	int n, m, a, q, i;
	T *cur, *pre, *nxt;

	fgets(p=buf, 30, stdin), n = getint(), p++, m = getint(), p++, q = getint();

	cur = tbl+1, pre = cur-1, nxt = cur+1;
	for (i = 1; i <= n; i++) {
		cur->nxt = nxt, cur->pre = pre, cur->f = 1;
		cur++, pre++, nxt++;
	}
	tbl[1].pre = tbl+n, tbl[n].nxt = tbl+1;

	fgets(p=buf, sizeof(buf), stdin);

	cur = tbl+1;
	for (i = 0; i < m; i++) {
		a = getint(), p++;
		if (a & 1) while (a--) cur = cur->pre;
		else       while (a--) cur = cur->nxt;
		cur->f = 0;
		pre = cur->pre, nxt = cur->nxt;
		pre->nxt = nxt, nxt->pre = pre;
		cur = nxt;
	}

	fgets(p=buf, sizeof(buf), stdin);
	while (q--) putchar('0'+tbl[getint()+1].f), p++, putchar('\n');
	return 0;
}

Measured memory_bytes: 6808
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <map>

using namespace std;

#define unomap unordered_map
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define itr iterator
#define rtr reverse_iterator

typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;

typedef set<int> si;
typedef set<pi> spi;

typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pi> vpi;

typedef vector<vb> vmb;
typedef vector<vi> vmi;
typedef vector<si> vsi;
typedef vector<vpi> vmpi;
typedef vector<spi> vspi;

inline int readInt()       {char c;while(c=getchar(),c<'0'||c>'9');bool sign=(c=='-');if(sign)c=getchar();int n=c-'0';while(c=getchar(),!(c<'0'||c>'9'))n=10*n+c-'0';return(sign)?-n:n;}
inline int readLong()      {char c;while(c=getchar(),c<'0'||c>'9');bool sign=(c=='-');if(sign)c=getchar();ll  n=c-'0';while(c=getchar(),!(c<'0'||c>'9'))n=10*n+c-'0';return(sign)?-n:n;}
inline void getInt(int& n) {char c;while(c=getchar(),c<'0'||c>'9');bool sign=(c=='-');if(sign)c=getchar();    n=c-'0';while(c=getchar(),!(c<'0'||c>'9'))n=n*10+(c-'0');   if(sign)n=-n;}
inline void getLong(ll& n) {char c;while(c=getchar(),c<'0'||c>'9');bool sign=(c=='-');if(sign)c=getchar();    n=c-'0';while(c=getchar(),!(c<'0'||c>'9'))n=n*10+(c-'0');   if(sign)n=-n;}

int query()
{



    return 0;
}

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

    vi a(n + 1);
    for (int i = 1; i <= n; ++i)
        cin >> a[i];

    vi dp(n + 1, 0);
    dp[0] = dp[1] = 0;
    for (int i = 2; i <= n; ++i)
    {
        dp[i] = dp[i - 1] + abs(a[i] - a[i - 1]);
        if (i > 2)
           dp[i] = min(dp[i], dp[i - 2] + abs(a[i] - a[i - 2]));
    }

    cout << dp[n];
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
using namespace std;
int main()
{
    int a,b,c,k=INT_MAX;
    bool tf=0;
    cin>>a>>b>>c;
    int sum=a;
    while(sum<147483647)
    {
        if(sum%b!=c%b)
        {sum+=a;tf=false;}
        else {tf=true;break;}
    }
    if(tf)
    cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//
ll e[2005];
int main() {
    init();
    ll N, X, Y;
    cin >> N >> X >> Y;

    ll d = Y - X - 1;
    repe(i,1,N){
        if(i<=X){
            repe(j,i+1,X+1){
                e[j - i]++;
            }
            repe(j,X+1, Y){
                ll m = min(X - i + 1 + Y - j, j - i);
                e[m]++;
            }
            repe(j,max(Y,i+1),N+1){
                e[j - i - d]++;
            }
        }
        else if(i<=Y){
            repe(j,i+1, N+1){
                ll m = min(i - X + 1 + abs(Y - j), j - i);
                e[m]++;
            }
        }
        else {
            repe(j,max(Y,i+1),N+1){
                e[j - i]++;
            }
        }
    }

    repe(i, 1, N) cout << e[i] << "\n";
}

Measured memory_bytes: 256
#import<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL i,j,k,m,n,t,a[200040];
string s="0",v;
main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>v;
	s+=v;
	n=s.size();
	for(i=n;i--;)
	{
		if(s[i]<53||s[i]==53&&s[i-1]<53)t+=s[i]-48;
		else
		{
			t+=58-s[i];
			for(j=i-1;s[j]>56;j--)s[j]=48;
			s[j]++;
		}
		s[i]=48;
		//cout<<s<<' '<<t<<endl;
	}
	cout<<t;
}

Measured memory_bytes: 2332