akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/ruby
s=gets.chomp
$<.drop(1).each{|l|
	x=l.split
	case x[0]
		when 'print'; puts s[x[1].to_i..x[2].to_i]
		when 'reverse'; s[x[1].to_i..x[2].to_i]=s[x[1].to_i..x[2].to_i].reverse
		when 'replace'; s[x[1].to_i..x[2].to_i]=x[3]
	end
}

Measured memory_bytes: 6156
def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x % y)

k = int(input())

ans=0
for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            ans += gcd(gcd(a, b), c)
            
print(ans)

Measured memory_bytes: 76900
#include <stdio.h>
#define MAX 100000
int x,te,A[MAX];

int par(int A[],int p,int r){
    int i,j;
    x=A[r];
    i=p-1;
    for(j=p;j<r;j++){
        if(A[j]<=x){
            i=i+1;
            te=A[i];
            A[i]=A[j];
            A[j]=te;
    }           
    }
            te=A[i+1];
            A[i+1]=A[r];
            A[r]=te;
           
    return i+1;
}
int main(){
    int i,n,k;
    
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&A[i]);
    }
    k=par(A,0,n-1);
    for(i=0;i<k;i++){
        printf("%d ",A[i]);
    }
    printf("[%d] ",A[k]);
    for(i=k+1;i<n-1;i++){
        printf("%d ",A[i]);
    }
    printf("%d\n",A[n-1]);
    return 0;
}


Measured memory_bytes: 2084
#!/usr/bin/env python

from collections import deque, defaultdict
import itertools as ite
import sys
import math
import decimal

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

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

ans = sum(B)
for i in range(N - 1):
    if A[i] + 1 == A[i + 1]:
        ans += C[A[i] - 1]

print ans

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair


int main() {
  int n, k;
  cin >> n >> k;
  vl a(n);
  rep (i, n) {
    cin >> a[i];
  }
  vl sum(n + 1);
  rep1 (i, n) {
    sum[i] = sum[i - 1] + a[i - 1];
  }
  ll ma = 0;
  vl b;
  for (int i = 0; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      b.push_back(sum[j] - sum[i]);
    }
  }
  sort(all(b));
  int m = b.size();
  vector<bool> can(m, true);
  ll mask = 1LL << 40;
  ll ans = 0;
  while (mask > 0) {
    int cnt = 0;
    rep (i, m) {
      if (can[i] && (mask & b[i])) {
        cnt++;
      }
    }
    if (cnt >= k) {
      ans += mask;
      rep (i, m) {
        if (!(mask & b[i])) {
          can[i] = false;
        }
      }
    }
    mask >>= 1;
  }
  cout << ans << endl;
  
}


Measured memory_bytes: 6388
#include<bits/stdc++.h>
/*	#include <boost/math/common_factor.hpp>  boost::math::lcm(10,20) ---> use it to find lcm. fill_n(&ans[0][0],n*m,0);*/
using namespace std;
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;
// #define int long long 
#define PI pair<int , int >
#define mpr make_pair
#define ff first
#define ss second
#define endl "\n"
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define FO(i,a,b) for(int i = (int)a;i < (int)b;++i)
#define FE(i,a,b) for(int i = (int)a;i <= (int)b;++i)
const int MOD = 1e9+7;
const int MAXN = 1e5+3;
const int inf = 2e9;
int max(int a,int b){	if(a > b)return a; else return b; }
int min(int a, int b){	if(a < b)return a; else return b; }
int dx[] = {1,-1,0,0};
int dy[] = {0,0,-1,1};
bool cmp(PI p1,PI p2){
	if(p1.ff < p2.ff)return true;	// You should not be writing p1.ss <= p2.ss !!!
	else if(p1.ff == p2.ff){ if(p1.ss < p2.ss)return true; return false; }
	return false;
}
/*		1. Take all the inputs
		4. Whenever you do multiplication and division in the same line, beware.
*/
void solve(){
	// int main  or  int32_t main ...
	int n;
	cin >> n;
	int h[n];
	FO(i,0,n)cin >> h[i];
	
	int ans[n];
	ans[0] = 0;
	ans[1] = abs(h[1] - h[0]);
	FO(i,2,n){
		ans[i] = min( abs(h[i]-h[i-2]) + ans[i-2],abs(h[i] - h[i-1]) + ans[i-1]);
	}
	cout << ans[n-1] << endl;
}
/*	memset() can be used to set all values as 0 or -1 for integer data types.*/

int main(){
	IO;
	#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	#endif // ONLINE_JUDGE
	// std::cout << std::setprecision(15); std::cout << std::fixed;
	int t; t = 1;
	// cin >> t;
	while(t--){ solve(); }
	return 0;
}


Measured memory_bytes: 1024
//
//  main.cpp
//
 
#include <algorithm>
#include <array>
#include <assert.h>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
 
template<typename T>
vector<T> make_vec_nd(T init, size_t size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, size_t size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a-1;i>=b;i--)

struct Mod {
	static ll BASE;
	ll value = 0;
	static ll residue(ll value) { return (value % BASE + BASE) % BASE; }
	Mod()
	: value(0) {}
	Mod(ll value)
	: value(residue(value)) {}
	Mod operator+(const Mod& rhs) const { return Mod(value + rhs.value); }
	void operator+=(const Mod& rhs) { *this = *this + rhs; }
	Mod operator-(const Mod& rhs) const { return Mod(value - rhs.value); }
	Mod operator-() const { return Mod(-value); }
	void operator-=(const Mod& rhs) { *this = *this - rhs; }
	Mod operator*(const Mod& rhs) const { return Mod(value * rhs.value); }
	void operator*=(const Mod& rhs) { *this = *this * rhs; }
};
ll Mod::BASE = 1000000007;

int main() {
	ll N;
	cin >> N;
	vector<ll> T(N);
	vector<ll> A(N);
	rep(i,0,N) {
		cin >> T[i];
	}
	rep(i,0,N) {
		cin >> A[i];
	}
	vector<bool> T_fixed(N, false);
	vector<bool> A_fixed(N, false);
	rep(i,0,N) {
		if (i == 0 || T[i-1] < T[i]) {
			T_fixed[i] = true;
		}
		if (i == N-1 || A[i] > A[i+1]) {
			A_fixed[i] = true;
		}
	}
	Mod ans = 1;
	rep(i,0,N) {
		if (A_fixed[i]) {
			if (A[i] > T[i]) {
				cout << 0 << endl;
				return 0;
			}
		}
		if (T_fixed[i]) {
			if (A[i] < T[i]) {
				cout << 0 << endl;
				return 0;
			}
		}
		if (!A_fixed[i] && !T_fixed[i])
			ans *= min(A[i], T[i]);
	}
	cout << ans.value << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
using namespace std;

void solve(){
  int n, m; cin >> n >> m;
  vector<vector<int> > v(n);
  for(int i = 0; i < m; i++){
    int u, x; cin >> u >> x;
    v[u].push_back(x);
    v[x].push_back(u);
  }
  queue<int> q;
  vector<int> c(n, 0);
  int t = 1;
  for(int j = 0; j < n; j++){
    if(c[j] == 0){
      q.push(j);
      c[j] = t;
      while(q.size() != 0){
        int x = q.front();
        q.pop();
        for(int i = 0; i < v[x].size(); i++){
          if(c[v[x][i]] == 0){
            q.push(v[x][i]);
            c[v[x][i]] = t;
          }
        }
      }
    }
    t++;
  }
  int qu; cin >> qu;
  vector<string> ans(qu);
  for(int i = 0; i < qu; i++){
    int a, b; cin >> a >> b;
    if(c[a] == c[b]) ans[i] = "yes";
    else ans[i] = "no";
  }
  for(int i = 0; i < qu; i++){
    cout << ans[i] << endl;
  }
  return;
}

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



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

int main(void) {
    int N,M;
    int a,b;

    cin >> N >> M;
    vector<int> road(N,0);
    for(int i=0;i<M;i++) {
        cin >> a >> b;
        road[a-1]++;
        road[b-1]++;
    }    
    
    for(int i=0;i<N;i++) {
        cout << road[i] << "\n";
    }

    return 0;
}


Measured memory_bytes: 256
S = input()
T = input()
 
lenS = len(S)
lenT = len(T)
 
lcs = [[0 for i in range(lenT + 1)] for j in range(lenS + 1)]
 
for i in range(lenS):
  for j in range(lenT):
    if S[i] == T[j]:
      lcs[i + 1][j + 1] = lcs[i][j] + 1
    else:
      lcs[i + 1][j + 1] = max(lcs[i + 1][j], lcs[i][j + 1])
#for i in range(lenS + 1):
#  print(lcs[i])

i, j = lenS, lenT
answer = ""
while i != 0 and j != 0:
  if lcs[i - 1][j] == lcs[i][j] - 1:
    if lcs[i][j - 1] == lcs[i][j] - 1:
      answer += S[i - 1]
      i -= 1
    j -= 1
  else:
    i -= 1
  #print(i, j, lcs[i][j], answer)
print(answer[::-1])

Measured memory_bytes: 119772
function Main(input){
var row = input.split("\n")[1].split(" ");
var count = 0;
for(i=0;i<=(row.length-2);i++){
  var a = new Number(row[i-1])<new Number(row[i]);
  var b = new Number(row[i])<new Number(row[i+1]);
  var c = new Number(row[i-1])>new Number(row[i]);
  var d = new Number(row[i])>new Number(row[i+1]);
  if(a===true&&b===true ||
     c===true&&d===true){
       count +=1;
     }
}
console.log(count);
}
  Main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 7500
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        int d = sc.nextInt();
        // 添字0は使わない
        int Hei[] = new int[h * w + 1];
        int Wid[] = new int[h * w + 1];
        int a[][] = new int[h][w];
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                a[i][j] = sc.nextInt();
                Hei[a[i][j]] = i + 1;
                Wid[a[i][j]] = j + 1;
            }
        }
        int dis[] = new int[h * w + 1];
        for (int i = 0; i < d + 1; i++) {
            dis[i] = 0;
        }
        for (int i = d + 1; i < h * w + 1; i++) {
            dis[i] = dis[i - d] + Math.abs(Hei[i] - Hei[i - d]) + Math.abs(Wid[i] - Wid[i - d]);
        }
        int q = sc.nextInt();
        int le[] = new int[q];
        int ri[] = new int[q];

        for (int i = 0; i < q; i++) {
            le[i] = sc.nextInt();
            ri[i] = sc.nextInt();
        }
        for (int i = 0; i < q; i++) {
            int ans = dis[ri[i]] - dis[le[i]];
            System.out.println(ans);
        }
    }
}

Measured memory_bytes: 96036
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) long long((x).size())
#define OUT(x) cout << (x) << endl
typedef long long ll;
typedef vector<ll> V;
typedef vector<vector<ll>> VV;
typedef pair<ll, ll> P;
typedef map<string, ll> M;
typedef unordered_map<ll, ll> HM;
typedef set<ll> S;
typedef multiset<ll> MS;
typedef queue<ll> Q;

int main(){
    ll n; cin>>n;
    ll a[n];
    pair<ll ,ll> b[n];
    for(ll i=0; i<n; i++){
        cin>>a[i];
        ll tmp; cin>>tmp;
        b[i] = make_pair(tmp, i);
    }
    sort(b, b+n);
    ll acu = 0;
    for(auto p : b){
        acu += a[p.second];
        if(acu > p.first){
            OUT("No");
            return 0;
        }
    }
    OUT("Yes");
}

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

static const int N = 100;

int main(){
  int M[N][N];
  int n, u, k, v;

  cin >> n;

  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j ++){
      M[i][j] = 0;
    }
  }
  for(int i = 0; i < n; i++){
    cin >> u >> k;
    u--;
    for(int j = 0; j < k; j++){
      cin >> v;
      v--;
      M[u][v] = 1;
    }
  }

  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      if( j ) cout << " ";
      cout << M[i][j];
    }
    cout << endl;
  }

  return 0;
}



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

struct P {
    int a, b, c, d;
};

vector<int> A;
vector<P> p;
int r;

void dfs(int i, int m) {
    for (int j = 0; j <= m; j++) {
        A[i] = j;
        if (i == 0) {
            int s = 0;
            for (const auto &[a, b, c, d] : p) {
                if (A[b] - A[a] == c) s += d;
            }
            r = max(r, s);
        } else {
            dfs(i - 1, j);
        }
    }
}

int main() {
    int n, m, q;
    cin >> n >> m >> q;

    A.resize(n);
    p.resize(q);
    r = 0;

    for (auto &[a, b, c, d] : p) {
        cin >> a >> b >> c >> d;
        a--; b--;
    }

    dfs(n - 1, m - 1);

    cout << r << endl;

    return 0;
}

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

int main () {
    int K, S;
    scanf("%d %d", &K, &S);

    int res = 0;
    for(int a = 0; a<=K; a++) {
        for(int b = 0; b<=K; b++) {
            int c = S - (a+b);
            if(a+b+c == S && c <= K && c >= 0) res++;
        }
    }
    printf("%d", res);
}

Measured memory_bytes: 256
x, n = map(int, input().split())
a = set(list(map(int, input().split())))
ans_d = 10000
ans = -1
for i in range(-100,1000):
    if abs(x - i) < ans_d and i not in a:
        ans = i
        ans_d = abs(x - i)
print(ans)


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

int main(){
    long long N, stock, yen  = 1000, input;
    vector<int> A;
    cin>>N;

    for(int i=0; i<N;i++){
        cin>>input;
        A.push_back(input);
    }
    for(int i=0; i<N;i++){
        stock = 0;
        if(A[i] < A[i+1])
            stock = yen/A[i];
        yen += (A[i+1] - A[i])*stock;
    }
    cout<<yen<<endl;

    return 0;
}


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

#define mp make_pair
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define inf INT_MAX
#define MOD 1000000007
#define fori(i,n) for(int i=0;i<(int)n;++i)
#define forri(i,n) for(int i=n-1;i>=0;--i)
#define forii(i,start,end) for(int i=start;i<end;++i)
#define MEM(a,b) memset(a,(b),sizeof(a))
#define sizearr(arr) sizeof(arr)/sizeof(arr[0])
#define LEN(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define ll long long
#define pll pair<long long,long long>
#define pii pair<int,int>
#define reset(arr, val) fori(i, MAX) arr[i] = val;

#define print(var) cout << var << endl;
#define ENDL cout << endl;
#define coutarr(arr) for(auto a:arr)print(a); ENDL;
#define coutpii(arr) for(pii a:arr)cout << '(' << a.fi << ',' << a.se << ") "; ENDL;
#define cinvec(arr, n) fori(i, n) {int tmp; cin >> tmp; arr.pb(tmp);}
#define cinarr(arr, n) fori(i, n) {int tmp; cin >> tmp; arr[i]=tmp ;}

const int MAX = 1e5 + 5;

int st[4*MAX]; //segtree
int arr[MAX]; //linear array elmt of segtree

int strule(int a, int b){
	return a + b;
}

int getMid(int s, int e){
	return s+(e-s)/2;
}

int buildst(int start, int end, int cur){
	// basis
	if (start == end){
		st[cur] = arr[start];
		return st[cur];
	}

	// reccurence
	int mid = getMid(start, end);
	st[cur] = strule(buildst(start, mid, 2*cur+1), buildst(mid+1, end, 2*cur+2));
}

int find(int ss, int se, int qs, int qe, int cur){
	// all segment inside
	if (qs <= ss && qe >= se){
		return st[cur];
	}

	// all segment outside
	if (se < qs || ss > qe){
		return 0;
	}

	// some segment inside
	int mid = getMid(ss, se);
	return strule(find(ss, mid, qs, qe, 2*cur+1), find(mid+1, se, qs, qe, 2*cur+2));
}

void update(int ss, int se, int index, int val, int cur){
	if(ss == se){
		arr[index] += val;
		st[cur] += val;
	} else {
		int mid = getMid(ss, se);
		if(ss <= index && index <= mid) update(ss, mid, index, val, 2*cur+1);
		else update(mid+1, se, index, val, 2*cur+2);
		st[cur] = strule(st[2*cur+1], st[2*cur+2]);
	}
}

// buildst(0, n-1, 0);
// find(0, n-1, start, end, 0);
// update(0, n-1, node, val, 0);

int main(){
	int n, q; cin >> n >> q;
	reset(arr, 0);
	buildst(0, n, 0);

	fori(i, q){
		int com, a, b; cin >> com >> a >> b;
		if (com) cout << find(0, n-1, a-1, b-1, 0) << endl;
		else update(0, n-1, a-1, b, 0);
		// fori(i, 4*n){
		// 	cout << st[i] << " " ;
		// } ENDL;
	}
	
	return 0;	
}


Measured memory_bytes: 4504
#Union Find
class union_find:
    #初期化
    #根なら-size,子なら親の頂点
    # par = [-1]*N
    def __init__(self, N):
        self.par = [-1]*N

    #xの根を求める
    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    #xとyの属する集合の併合
    def unite(self, x,y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return False
        else:
            #sizeの大きいほうがx
            if self.par[x] > self.par[y]:
                x,y = y,x
            self.par[x] += self.par[y]
            self.par[y] = x
            return True

    #xとyが同じ集合に属するかの判定
    def same(self, x,y):
        return self.find(x) == self.find(y)

    #xが属する集合の個数
    def size(self, x):
        return -self.par[self.find(x)]

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


uf1 = union_find(N)
for _ in range(K):
    p, q = map(int, input().split())
    p -= 1
    q -= 1
    uf1.unite(p, q)

uf2 = union_find(N)
for _ in range(L):
    r, s = map(int, input().split())
    r -= 1
    s -= 1
    uf2.unite(r, s)

pairs = [(uf1.find(i), uf2.find(i)) for i in range(N)]
from collections import Counter

cnt = Counter(pairs)
res = [cnt[pair] for pair in pairs]
print(*res)

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

using vs = vector<string>;
using vi = vector<int>;

int main()
{
    ios_base::sync_with_stdio(0);

    int h, w; cin >> h >> w;

    vs q(h);

    for(int i = 0; i < h; i++) cin >> q[i];

    vi v(26);

    for(int i = 0; i < h; i++)
    for(int j = 0; j < w; j++)
    {
        char c = q[i][j] - 'a';

        v[c]++;
    }

    vi y;

    for(int i = 0; i < h; i++)
    for(int j = 0; j < w; j++)
    {
        int ri = h - 1 - i;
        int rj = w - 1 - j;

        if(ri < i || rj < j) continue;

        int x = 1;

        if(i != ri) x *= 2;
        if(j != rj) x *= 2;

        y.push_back(x);
    }

    sort(begin(y), end(y));

    int ny = y.size();

    for(int i = ny - 1; i >= 0; i--)
    {
        int fl = 0;
        for(int x = y[i]; !fl && x; x /= 2)
        for(int j = 0; !fl && j < 26; j++) if(v[j] % x == 0 && v[j] >= y[i])
        {
            v[j] -= y[i];
            fl = 1;
        }

        if(!fl)
        {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]

n,ma,mb=map(int,input().split())
abc=[list(map(int,input().split())) for i in range(n)]
dp=[[[float('inf')]*(400+1) for i in range(400+1)] for j in range(n+1)]
dp[0][0][0]=0
for i in range(n):
    a,b,c=abc[i]
    for j in range(400):
        for k in range(400):
            if dp[i][j][k]!=float('inf'):
                dp[i+1][j+a][k+b]=min(dp[i+1][j+a][k+b],dp[i][j][k]+c)
                dp[i+1][j][k]=min(dp[i+1][j][k],dp[i][j][k])
ans=float('inf')
now=[ma,mb]
while 1:
    a,b=now
    ans=min(ans,dp[n][a][b])
    if a+ma>400 or b+mb>400:
        break
    now=[a+ma,b+mb]
if ans==float('inf'):
    print(-1)
else:
    print(ans)

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

using namespace std;

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

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(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 CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int n;
char s[52][125];
int t[52];
char x[125];

int main(){
    scanf("%d", &n);
    REP(i,n)scanf("%s%d",s[i],t+i);
    scanf("%s",x);
    int ans = 0;
    bool flag = false;
    REP(i,n){
        if(flag)ans += t[i];
        if(strcmp(s[i], x) == 0){
            flag = true;
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
def main():
    a, b, c, k = map(int, input().split())

    if k % 2 == 1:
        print(b - a)
    else:
        print(a - b)


'''
    for i in range(k):
        temp_a = a
        temp_b = b
        temp_c = c

        a = temp_b + temp_c
        b = temp_a + temp_c
        c = temp_a + temp_b

    answer = a - b
    if answer > 10**18:
        print('Unfair')
    else:
        print(answer)
'''

if __name__ == '__main__':
    main()

Measured memory_bytes: 61856
#include "bits/stdc++.h"
#define rep(i,n) for(ll i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define d_5 100000
#define d9_7 1000000007
#define vll vector<vector<long long>>
#define vl vector<long long>
#define vi vector<int>
#define vii vector<vector<int>>
#define pb push_back
#define pf push_front
int main(void){
  ll n,m;
  cin>>n>>m;
  vl x(n);
  vl y(m);
  rep(i,n){
    cin>>x[i];
  }
  rep(i,m){
    cin>>y[i];
  }
  ll tmp;
  ll sum1=0;
  vl sumx(n,0);
  vl sumy(m,0);
  sumx[0]=x[0];
  rep(i,n-1){
    sumx[i+1]=sumx[i]+x[i+1];
  }
  sumy[0]=y[0];
  rep(i,m-1){
    sumy[i+1]=sumy[i]+y[i+1];
  }
  rep(i,n-1){
    /*sum1*=2;
    sum1%=d9_7;*/
    sum1+=((x[i+1]*(i+1)-sumx[i]))%d9_7;
    sum1%=d9_7;
  }
  ll sum2=0;
  rep(i,m-1){
    /*sum2*=2;
    sum2%=d9_7;*/
    sum2+=((y[i+1]*(i+1)-sumy[i]))%d9_7;
    sum2%=d9_7;
  }
  cout<<((sum1*sum2)%d9_7)<<endl;
  return 0;
}

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

int main(void)
{
  int h[100],w[100];
  int k=0;
  do{
    k = k+1;
    cin >> h[k] >> w[k];
  }while(h[k] != 0 && w[k] != 0);

  k=1;
  while(h[k] != 0 && w[k] != 0){
    for(int i=1; i<=h[k]; i++){
      for(int j=1; j<=w[k]; j++){
        if(i==1 || i==h[k] || j==1 || j==w[k])
          cout << "#";
        else
          cout << ".";
      };
      cout << endl;
    };
    k = k+1;
    cout << endl;
  }

  return 0;
}

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

typedef struct {
    char *name[2];
    int time;
} Process;

typedef struct {
    Process *processes;
    int size;
    unsigned int head;
    unsigned int tail;
} ProcessQueue;

int getIndex(int index, int buffersize) {
    if(index >= buffersize)
        return index % buffersize;
    return index;
}

void enqueue(ProcessQueue *PQueue, Process process)
{
    if(PQueue->tail >= PQueue->size) {
        PQueue->processes[PQueue->tail++ % PQueue->size] = process;
        return;
    }
    PQueue->processes[PQueue->tail++] = process;
}

Process dequeue(ProcessQueue *PQueue)
{
    if(PQueue->head >= PQueue->size) {
        return PQueue->processes[PQueue->head++ % PQueue->size];
    }
    return PQueue->processes[PQueue->head++];
}

int main(void) 
{
    int i, n, q, eltime = 0;
    Process process;
    ProcessQueue PQueue;

    scanf("%d", &n);
    scanf("%d", &q);
    PQueue.processes = malloc(sizeof(Process) * n);
    PQueue.size = n;
    PQueue.head = PQueue.tail = 0;
    for(i = 0; i < n; i++) {
        scanf("%s", process.name);
        scanf("%d", &process.time);
        enqueue(&PQueue, process); 
    }
    while(PQueue.head != PQueue.tail) {
        process = dequeue(&PQueue);
        if(process.time > q) {
           process.time -= q; 
           eltime += q;
           enqueue(&PQueue, process);
        } else {
           eltime += process.time; 
           printf("%s %d\n", process.name, eltime);
        }
    }


    return 0;
}

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

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, x, t;
    cin >> n >> x >> t;

    cout << int(ceil(n / float(x)) * t);
    return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin() x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin() x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n; cin >> n;
	ll maxi=0, ans=0;
	rep(i, n){
		ll h; cin >> h;
		if (h >= maxi) ans++;
		maxi = max(maxi, h);
	}
	cout << ans << "\n";
	return 0;
}

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

#define ll long long
#define db double
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define tr(ds, it) for(auto it=ds.begin(); it!=ds.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef priority_queue <int> pq;
typedef vector< long long > vi;
typedef pair<long long, long long> ii;

const ll mod = 1000000007;
ll po(ll k, ll n ){ 
      if(n==1) return k%mod;
      else{
        ll a=po(k,n/2)%mod;
        if(n%2==0) return (a*a)%mod;
        else return (((a*a)%mod)*k)%mod;
      }
}


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // #ifndef ONLINE_JUDGE
  // freopen("input.txt", "r" , stdin);
  // freopen("output.txt", "w" , stdout);
  // #endif
  int t=1;
  //cin >> t;
  while(t--){
    int n;
    cin >> n;
    int x;
    ll s=0, y=0;
    rep(i,n){
      cin >> x;
      s+=x;
      y+=x*x;
    }
    cout << (s*s-y)/2 << endl;

  }

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main (void){
char a,b,c,s;
  scanf("%c%c%c",&a,&b,&c);
  if(a==b&&b==c&&b=='R'){s=3;}
  else if((a==b)&&b=='R'||(b=='R'&&b==c)){s=2;}
  else if(a=='R'||b=='R'||c=='R'){s=1;}
  else {s=0;}
  printf("%d\n",s);
}

Measured memory_bytes: 1668
use std::io::{Read, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    let mut iter = input.split_whitespace();

    loop {
        let a: i32 = iter.next().unwrap().parse().unwrap();
        let op: char = iter.next().unwrap().as_bytes()[0] as char;
        let b: i32 = iter.next().unwrap().parse().unwrap();
        let ans = match op {
            '+' => a+b,
            '-' => a-b,
            '*' => a*b,
            '/' => a/b,
            _ => break,
        };
        out.write_fmt(format_args!("{}\n", ans)).unwrap()
    }
}



Measured memory_bytes: 5036
#include "bits/stdc++.h"
#include<unordered_map>
#pragma warning(disable:4996)
using namespace std;

double eps(1e-9);

vector<pair<double, double>>obs;

bool check(double jumpdis, double dx,double dy){
	for (int i = 0; i < obs.size(); ++i) {
		double dis = obs[i].first;
		while (dis > jumpdis)dis -= jumpdis;
		if (abs(dis) < eps || abs(dis - jumpdis) < eps)return false;
		double aatime = dis / dx;
		double finy = dy*aatime - aatime*aatime * 1 / 2.0;
		if (finy < obs[i].second)return false;
	}
	return true;
}

int main() {
	double D;
	int  N, B; cin >> D >> N >> B;
	for (int i = 0; i < N; ++i) {
		double p, h; cin >> p >> h;
		obs.push_back(make_pair(p, h));
	}

	double ans = 1e15;

	for (int jumpnum = 1; jumpnum <= B+1; ++jumpnum) {
		double jumpdis = D / jumpnum;

		double mindy = 0.000001;
		double maxdy = 1e9;
		while (mindy < maxdy - 1e-9) {
			const double middy = (mindy + maxdy)/2;
			const double jumptime = middy / 1.0 * 2;
			const double dx = jumpdis / jumptime;
			if (check(jumpdis,dx,middy)) {
				maxdy = middy;
			}
			else {
				mindy = middy;
			}
		}
		{
			const double jumptime = mindy / 1.0 * 2;
			const double dx = jumpdis / jumptime;
			const double nans(sqrt(dx*dx + mindy*mindy));
			int a = 1;
		}
		{
			double nminy = mindy;
			double nmaxy = 1e9;
			while (nminy < nmaxy - 1e-9) {
				const double middy0 = (nminy + 2*nmaxy) / 3;
				const double jumptime0 = middy0 / 1.0 * 2;
				const double dx0 = jumpdis / jumptime0;
				const double midans0 = sqrt(middy0*middy0 + dx0*dx0);
				const double middy1 = (2*nminy + nmaxy) / 3;
				const double jumptime1 = middy1 / 1.0 * 2;
				const double dx1 = jumpdis / jumptime1;
				const double midans1 = sqrt(middy1*middy1 + dx1*dx1);
				if (midans0<midans1) {
					nminy = middy1;
				}
				else {
					nmaxy = middy0;
				}
			}
			mindy = nminy;
		}
		const double jumptime = mindy / 1.0 * 2;
		const double dx = jumpdis / jumptime;
		const double nans(sqrt(dx*dx + mindy*mindy));
		ans = min(nans, ans);
	}
	cout <<fixed<<setprecision(22)<< ans << endl;
	return 0;
}

Measured memory_bytes: 3276
#include <stdio.h>

int main() {
	int start = 1, n, t, x = 0;
	scanf("%d", &n);
	scanf("%d", &t);
	
	for(int i = 0; i < (n-x); i++) {
		while(start < t) {
			if(x >= n) {
				break;
			}
			start *= 2;
			x++;
		}
		if(x >= n) {
			break;
		}
		start += t;
	}
	printf("%d", start);
	
	return 0;
}

Measured memory_bytes: 1724
#![allow(unused_imports)]
#![allow(non_snake_case, unused)]

use std::cmp::*;
use std::collections::*;
use std::ops::*;

// https://atcoder.jp/contests/hokudai-hitachi2019-1/submissions/10518254

macro_rules! eprint {
	($($t:tt)*) => {{
		use ::std::io::Write;
		let _ = write!(::std::io::stderr(), $($t)*);
	}};
}
macro_rules! eprintln {
	() => { eprintln!(""); };
	($($t:tt)*) => {{
		use ::std::io::Write;
		let _ = writeln!(::std::io::stderr(), $($t)*);
	}};
}
macro_rules! dbg {
	($v:expr) => {{
		let val = $v;
		eprintln!("[{}:{}] {} = {:?}", file!(), line!(), stringify!($v), val);
		val
	}}
}

macro_rules! mat {
	($($e:expr),*) => { Vec::from(vec![$($e),*]) };
	($($e:expr,)*) => { Vec::from(vec![$($e),*]) };
	($e:expr; $d:expr) => { Vec::from(vec![$e; $d]) };
	($e:expr; $d:expr $(; $ds:expr)+) => { Vec::from(vec![mat![$e $(; $ds)*]; $d]) };
}

macro_rules! ok {
	($a:ident$([$i:expr])*.$f:ident()$(@$t:ident)*) => {
		$a$([$i])*.$f($($t),*)
	};
	($a:ident$([$i:expr])*.$f:ident($e:expr$(,$es:expr)*)$(@$t:ident)*) => { {
		let t = $e;
		ok!($a$([$i])*.$f($($es),*)$(@$t)*@t)
	} };
}

pub fn readln() -> String {
	let mut line = String::new();
	::std::io::stdin().read_line(&mut line).unwrap_or_else(|e| panic!("{}", e));
	line
}

macro_rules! read {
	($($t:tt),*; $n:expr) => {{
		let stdin = ::std::io::stdin();
		let ret = ::std::io::BufRead::lines(stdin.lock()).take($n).map(|line| {
			let line = line.unwrap();
			let mut it = line.split_whitespace();
			_read!(it; $($t),*)
		}).collect::<Vec<_>>();
		ret
	}};
	($($t:tt),*) => {{
		let line = readln();
		let mut it = line.split_whitespace();
		_read!(it; $($t),*)
	}};
}

macro_rules! _read {
	($it:ident; [char]) => {
		_read!($it; String).chars().collect::<Vec<_>>()
	};
	($it:ident; [u8]) => {
		Vec::from(_read!($it; String).into_bytes())
	};
	($it:ident; usize1) => {
		$it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1
	};
	($it:ident; [usize1]) => {
		$it.map(|s| s.parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1).collect::<Vec<_>>()
	};
	($it:ident; [$t:ty]) => {
		$it.map(|s| s.parse::<$t>().unwrap_or_else(|e| panic!("{}", e))).collect::<Vec<_>>()
	};
	($it:ident; $t:ty) => {
		$it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<$t>().unwrap_or_else(|e| panic!("{}", e))
	};
	($it:ident; $($t:tt),+) => {
		($(_read!($it; $t)),*)
	};
}

pub fn main() {
	let _ = ::std::thread::Builder::new().name("run".to_string()).stack_size(32 * 1024 * 1024).spawn(run).unwrap().join();
}

const MOD: usize = 1_000_000_007;
const INF: i64 = std::i64::MAX/2;

fn solve() {
    let (n,m) = read!(usize,usize);
    let mut ans = vec![];
    if n%2==1 {
        for i in 0..m {
            ans.push((i+1,n-i));
        }
    }
    else {
        for i in 0..m {
            let l = i+1;
            let mut r = n-i;
            let dist = r-l-1;
            if dist*2<n {
                r -= 1;
            }
            ans.push((l,r));
        }
    }
    for (x,y) in ans {
        println!("{} {}", x, y);
    }

}

fn run() {
    solve();
}


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

template <class T> using V = vector<T>;
template <class S, class T> using P = pair<S, T>;
template <class... T> using TP = tuple<T...>;

using ll = long long;
using db = double;
using ldb = long db;
using str = string;
using vll = V<ll>;
using vvll = V<V<ll>>;
using pll = P<ll,ll>;
using tpll = TP<ll,ll,ll>;
using vpll =V<pll>;
using vst = V<str>;
using vch = V<char>;

#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(b);i>(ll)(a);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) __lcm(a,b)
#define co(a) cout<<a<<endl
#define ci(a) cin>>a
#define pb(a) push_back(a)
#define pob pop_back()
#define mp make_pair
#define mt make_tuple
#define pbmp(a,b) push_back(mp(a,b))
#define subs(a,b) substr(a,b)
#define cfs(a) cout<<fixed<<setprecision(a)
#define INF 1e16
#define mod 1e9+7
//vvll v(n,vll(m)) n行m列
//A.erase(A.begin()+i) 配列Aのi番目を消せる
//std::binary_search(v.bgn,v.en,a);
//abs(a,b)   pow(a,n)  to_string  stoll
//auto Iter=lower_bound(v.bgn,v.en,a);
//lower//upper  co(*Iter)co(Iter-v.bgn);

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void Comuse() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
#define comuse Comuse()
ll combi(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  ll n;
  cin>>n;
  vll v(n+1),ve(n);
  FOR(i,0,n+1){
    cin>>v[i];
  }
  FOR(i,0,n){
    cin>>ve[i];
  }
  ll ans=0;
  for(ll i=n-1;i>=0;i--){
    if(v[i+1]>=ve[i]){
      ans+=ve[i];
      ve[i]=0;
      //co(ans);
    }
    if(v[i+1]<ve[i]){
      ans+=v[i+1];
      ve[i]-=v[i+1];
      //co(ans);
      if(v[i]>=ve[i]){
        ans+=ve[i];
        v[i]-=ve[i];
        ve[i]=0;
        //co(ans);
      }
      if(v[i]<ve[i]){
        ans+=v[i];
        v[i]=0;
        //co(ans);
      }
    }
    //co(ans);
  }
  co(ans);
}


Measured memory_bytes: 1792
#include <stdio.h>
int F[45];

//メモ化再帰
int fibonacci(int n){
  if(n==0 || n==1){
    F[n]=1;
    return 1;
  }
  if(F[n]!=-1)
    return F[n];
  F[n]=fibonacci(n-1)+fibonacci(n-2);
  return F[n];
}

int main(){
  int n,i;
  scanf("%d",&n);
  //initialization
  for(i=0;i<=n;i++)
    F[i]=-1;
  
  printf("%d\n",fibonacci(n));
  return 0;
}


Measured memory_bytes: 2104
M = 10 ** 6 + 1
N = int(input())
A = list(map(int, input().split()))

A.sort()
numbers = range(M)
not_divisible = [True] * (M)

result = 0
for i in range(N):
    target = A[i]
    if not_divisible[target]:
        if i+1 <= N-1 and A[i+1] == A[i]:
            pass
        else:
            result += 1
        for j in range(target, M, target):
            not_divisible[j] = False
print(result)


Measured memory_bytes: 32368
num=input()
a=[]
for i in range(num):
    p=input()
    a.append(p)
ans=a[0]-1
a.pop(0)
nowprice=2
for custom in a:
    if (custom>nowprice):
        if custom % (nowprice)==0:
            ans += custom / (nowprice )-1
        else:
            ans+=custom/(nowprice)
    if (custom==nowprice):
        nowprice+=1
print ans

Measured memory_bytes: 9092
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Cin(type, x) type x; cin >> x;
#define Cins(type, n, xs) vector<type> xs(n); For(i, n) cin >> xs[i];
#define Cout(val) cout << (val) << "\n";
#define Range(container) container.begin(), container.end()
using namespace std;
using ll = long long;

int main(void){
    Cin(int, n);
    Cin(int, t);
    Cin(int, a);
    Cins(int, n, h);
    
    int ansi = -1, anss = 1e7;
    For(i, n){
        int m = abs(1000*t - h[i]*6 - 1000*a);
        if(m < anss) ansi = i, anss = m;
    }
    Cout(ansi + 1);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i, n) for(int i = 1; i <= (n); i ++)
#define out(x) cerr << #x << " = " << x << "\n"
#define type(x) __typeof((x).begin())
#define foreach(it, x) for(type(x) it = (x).begin(); it != (x).end(); ++ it)
using namespace std;
// by piano
template<typename tp> inline void read(tp &x) {
  x = 0; char c = getchar(); bool f = 0;
  for(; c < '0' || c > '9'; f |= (c == '-'), c = getchar());
  for(; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
  if(f) x = -x;
}
template<typename tp> inline void arr(tp *a, int n) {
  for(int i = 1; i <= n; i ++)
    cout << a[i] << " ";
  puts("");
}
int a, b, c;
#define MP make_pair
map<pair<int, pair<int, int> >, int> mp;
main(void) {
  read(a); read(b); read(c);
  int sum = a + b + c;
  if(a == b && b == c && a % 2 == 0)
    return cout << "-1\n", 0;
  if(a & 1 || b & 1 || c & 1) {
    cout << 0 << "\n";
    return 0;
  }
  for(int i = 1;; ++ i) {
    a = (sum - a) / 2;
    b = (sum - b) / 2;
    c = (sum - c) / 2;
    if(a & 1 || b & 1 || c & 1) {
      cout << i << "\n";
      return 0;
    }
  }
  cout << "-1\n";
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N;
  cin >> N;
  vector<ll> x(N), y(N);
  ll A = 1, B = 1;
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> y[i];
    ll mul = max(ceill((long double)A / x[i]), ceil((long double)B / y[i]));
    A = mul * x[i];
    B = mul * y[i];
  }
  cout << A + B << endl;
  return 0;
}

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

int pow2(int l){
    if(l>0){
        return 2*pow2(l-1);
    }
    return 1;
}

vector<bool> inttobool(int n,int l){
    vector<bool> rep;
    for(int i=0;i<l;i++){
        rep.push_back(n%2);
        n/=2;
    }
    return rep;
}

int main(){
    int D,G;
    cin>>D>>G;
    G/=100;
    vector<int> p(D+1),c(D+1);
    for(int i=1;i<=D;i++){
        cin>>p.at(i)>>c.at(i);
        c.at(i)/=100;
    }
    int ans=10000;
    for(int i=0;i<pow2(D);i++){
        vector<bool> maxornot=inttobool(i,D);
        int numofpbm=0;
        int sum=0;
        int x=0;
        for(int j=1;j<=D;j++){
            if(maxornot.at(j-1)){
                numofpbm+=p.at(j);
                sum+=j*p.at(j)+c.at(j);
            }
            else{
                x=j;
            }
        }
        if(G<=sum+x*(p.at(x)-1)){
            for(int k=0;k<p.at(x);k++){
                if(G<=sum+x*k){
                    numofpbm+=k;
                    break;
                }
            }
            ans=min(ans,numofpbm);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using P=pair<int,int>;
int n;
int x[100000],l[100000];
void in(void){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>x[i]>>l[i];
  }
}
P p[100000];
int leadS(void){
  for(int i=0;i<n;i++){
    p[i]=P(x[i]+l[i],x[i]-l[i]);
  }
  sort(p,p+n);
  int num=-1000000000;
  int ans=0;
  for(int i=0;i<n;i++){
    if(num<=p[i].second){
      ++ans;
      num=p[i].first;
    }
  }
  return ans;
}
int main(void){
  in();
  int ans=leadS();
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 5192
import java.util.Scanner;
public class Main {
@SuppressWarnings("resource")
public static void main(String[] args) {
	Scanner sc =new Scanner(System.in);
	int N=sc.nextInt();
	int M=sc.nextInt();

	if(N==M) {
		System.out.println("Yes");
	}else {
		System.out.println("No");
	}
}
}

Measured memory_bytes: 21972
#include <stdio.h>
#include <string.h>

int main(){

  int i, j, ans;
  char s[200010];

  scanf("%s", s);
  i=0;
  j=strlen(s);

  while(1){
    if(s[i]=='A') break;
    i++;
  }
  while(1){
    if(s[j]=='Z') break;
    j--;
  }
  ans=j-i+1;
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);;
		
		String s = sc.next();
		char []c = s.toCharArray();
		
		int p = s.length();
		int N = (int)Math.pow(2, p-1);
		long ans = 0;
		long tmp = c[0] - '0';
		
		for(int i = 0; i < N ; i++) {
			for(int j = 0; j < p-1; j++) {
				if(((1 & i >> j) == 1)){
					ans += tmp;
					tmp = c[j+1] - '0';
				}
				if((1 & i >> j) == 0 ){
					tmp = tmp * 10;
					tmp += c[j+1] - '0';
				}
			}
			ans += tmp;
			tmp = c[0] - '0';
		}
		System.out.println(ans);
					  
		  }
	}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long

typedef int Weight;
struct Edge{
    int from, to;
    Weight weight;
    int rev;     // ネットワークフロー時の逆辺
    Edge(int from, int to, Weight weight) :
        from(from), to(to), weight(weight) { }
    Edge(int from, int to, Weight weight, int rev) :
        from(from), to(to), weight(weight), rev(rev){ }
};
bool operator < (const Edge &a, const Edge &b){
    if(a.weight != b.weight) return a.weight > b.weight;
    if(a.from != b.from) return a.from > b.from;
    return  a.to > b.to;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;

void addFlowEdge(Graph &g, int a, int b, Weight c){
    g[a].push_back(Edge(a, b, c, g[b].size()));
    g[b].push_back(Edge(b, a, 0, g[a].size() - 1));
}
void addUndirectedEdge(Graph &g, int a, int b, Weight c){
    g[a].push_back(Edge(a, b, c, g[b].size()));
    g[b].push_back(Edge(b, a, c, g[a].size() - 1));
}

struct UnionFind{
    vector<int> parent, rank;
    UnionFind(int n){ parent = vector<int>(n, -1); rank = vector<int>(n, 0); }
    int find(int x){
        if(parent[x] == -1) return x;
        else return (parent[x] = find(parent[x]));
    }
    bool unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return false;
        if(rank[x] < rank[y])
            parent[x] = y;
        else
            parent[y] = x;
        if(rank[x] == rank[y])
            ++rank[x];
        return true;
    }
    bool same(int x, int y){
        return find(x) == find(y);
    }
};

pair<Weight, Edges> kruskal_e(Edges &edges, int n){
    sort(ALL(edges)); reverse(ALL(edges));  //a < b <-> a.weight > b.weight
    int sz = edges.size();

    UnionFind uf(n);
    Weight total = 0;
    Edges F;
    for(int i = 0; i < sz; ++i){
        if(uf.unite(edges[i].from, edges[i].to)){
            total = total + edges[i].weight;
            F.push_back(edges[i]);
        }
    }
    return make_pair(total, F);
}
pair<Weight, Edges> kruskal_g(const Graph &g){
    int n = g.size();
    vector<Edge> edges;
    for(int i = 0; i < n; ++i) edges.insert(edges.end(), ALL(g[i]));
    return kruskal_e(edges, n);
}

signed main(){
	int N;
	cin >> N;
	vector<int> x(N), y(N);
	vector<pair<int,int>> xp(N), yp(N);
	for(int i = 0; i < N; ++i) {
		cin >> x[i] >> y[i];
		xp[i] = make_pair(x[i], i);
		yp[i] = make_pair(y[i], i);
	}
	sort(ALL(xp));
	sort(ALL(yp));
	Edges es;
	for(int i = 0; i < N - 1; ++i) {
		es.push_back(Edge(xp[i].second, xp[i+1].second, xp[i+1].first - xp[i].first));
		es.push_back(Edge(yp[i].second, yp[i+1].second, yp[i+1].first - yp[i].first));
	}
	auto res = kruskal_e(es, N);
	cout << res.first << endl;
	return 0;
}


Measured memory_bytes: 22504
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i,s,n) for(int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(){
    int n;
    cin >> n;
    int a[n];
    int count = 0;
    rep(i, n) { 
        cin >> a[i];
        if(a[i] % 2 == 0)
            count++;
    }
    cout << pow(3, n) - pow(2, count) << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(void){
    int A,B,C,D;
    cin>>A>>B>>C>>D;
    int x=A+B,y=C+D;
    if(x>y){
        cout<<"Left"<<endl;
    }
    else if(x==y){
        cout<<"Balanced"<<endl;
    }
    else {
        cout<<"Right"<<endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void){
int n;
  scanf("%d",&n);
  char s[n][4];
   for(int i=0;i<n;i++){
			scanf("%s",s[i]);
   }
  int ac=0,wa=0,tle=0,re=0;
  for(int i=0;i<n;i++){
	if(strcmp(s[i],"AC")==0)ac++;
    if(!strcmp(s[i],"WA"))wa++;
    if(!strcmp(s[i],"TLE"))tle++;
       if(!strcmp(s[i],"RE"))re++;
          }
  
         printf("AC x %d\n",ac);
           printf("WA x %d\n",wa);
           printf("TLE x %d\n",tle);
           printf("RE x %d\n",re);
          return 0;
          }

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int mod = 1e9+7;

long long binpow(long long b, long long e) {
  if (!e) return 1;
  if (e&1) return b*binpow(b, e-1)%mod;
  return binpow(b*b%mod, e/2);
}

int C(int n, int k) {
  long long res = 1;
  for (int i = n-k+1; i <= n; ++i) {
    (res *= i) %= mod;
  }
  for (int i = 2; i <= k; ++i) {
    (res *= binpow(i, mod-2)) %= mod;
  }
  return res;
}

void solve() {
  int x, y; scanf("%d%d", &x, &y);
  if ((x+y)%3) {
    puts("0");
    return;
  }
  int r = (x+y)/3;
  int c = x-r;
  if (c < 0) {
    puts("0");
    return;
  }
  printf("%d", C(r, c));
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007;


signed main() {
 int n,a,b;
 cin>>n>>a>>b;
 if(n<a+b-1||n>a*b){
   cout<<-1;
   return 0;
 }
 if(b==1){
   for(int i=1;i<=n;i++)cout<<i<<' ';
   return 0;
 }
  if(a==1){
   for(int i=1;i<=n;i++)cout<<n+1-i<<' ';
   return 0;
 }
  int k=(n-a)/(b-1),t=(n-a)%(b-1);
  for(int i=0;i<k;i++){
    for(int j=b;j>0;j--)cout<<i*b+j<<' ';
  }
  if(n!=a*b){
  for(int i=t+1;i>0;i--)cout<<k*b+i<<' ';
  for(int i=a-k-1;i>0;i--)cout<<n+1-i<<' ';}
  return 0;
}


Measured memory_bytes: 2176