akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define mod 1000000007
#define INF 1000000000

#define eb emplace_back
#define len(x) ((int)(x).size())
#define log(x) cout << (x) << endl;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)

using ll = long long;
using vi = vector<int>;


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

	vi s;
	ll r1=1, r2=1, a;

	s = {n, m};
	rep (i, n+m) r1 = (r1%mod * s[i&1]--%mod) % mod;

	s = {m, n};
	rep (i, n+m) r2 = (r2%mod * s[i&1]--%mod) % mod;

	a = (r1 + r2) % mod;

	log(a)

	return 0;
}


Measured memory_bytes: 256
#pragma region header
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr int inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a / gcd(a, b) * b ;
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion

signed main() {
    int n;cin >> n;
    vi v(n);
    int count = 1;
    rep(i, n) {
        cin >> v[i];
        if(!(v[i]&1))count*=2;
    }
    cout << (int)pow(3,n)-count << endl;
    return 0;
}

Measured memory_bytes: 3980
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def solve(inp):
    S = inp.readline().strip()

    if S[0] == S[1] == S[2]:
        return "No"
    else:
        return "Yes"


def main():
    import sys
    result = solve(sys.stdin)
    if result is not None and result != '':
        print(result)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define makei(N) int N; cin >> N;
#define makel(N) ll N; cin >> N;
#define makes(s) string s; cin >> s;
#define maked(d) double d; cin >> d;
#define makev(v, N) vi v(N); rep(N)cin >> v[i];
#define mod 1000000007
#define re return 0
#define distance(x1,y1,x2,y2) sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));

using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

void yn(bool b) {
	if (b)say("Yes");
	else say("No");
}

void YN(bool b) {
	if (b)say("YES");
	else say("NO");
}

template<typename T>
void maxi(T &a, T b) {
	a = max(a, b);
}

template<typename T>
void mini(T &a, T b) {
	a = min(a, b);
}

void exact_say(double x) {
	cout << setprecision(numeric_limits<double>::max_digits10) << x << endl;
}

int main() {
	makei(n);
	int m = 55555;
	vb v;
	vi ans;
	rep(m + 1)v.push_back(true);
	FOR(i, 2, m + 1) {
		if (v[i]) {
			if (i % 5 == 1)ans.push_back(i);
			for (int j = i; j <= m; j += i)v[j] = false;
		}
	}
	rep(n) {
		cout << " " << ans[i];
	}
	cout << endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
s = True
count = 0
while(s):
    for i in range(n):
        if a[i]%2 == 0:
            a[i] = int(a[i]/2)
        else:
            s = False
            break
    count += 1
print(count-1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    int K,A,B;
    cin >>K>>A>>B;
    if(A%K==0||B%K==0){
        cout<<"OK"<<endl;
        return 0;
    }
    if(A/K<B/K){
        cout<<"OK"<<endl;
        return 0;
    }
    cout <<"NG"<<endl;
    
    return 0;
}

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

using namespace std ;

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

const int MAX = 1e5 + 10 ;

vector< vector<int> >dist ;
vector< vector<char> >grid ;
vector< set<int> >sr , sc ;
int n , m , k ;

void bfs(int srcx , int srcy)
{
	dist = vector< vector<int> >(n+1 , vector<int>(m+1)) ;
	for(int i = 0 ; i < n ; ++i)
	{
		for(int j = 0 ; j < m ; ++j)
			dist[i][j] = 1e9 ;
	}
	vector<int>v ;
	set<int>::iterator it ;
	queue< pair<int , int> >q ;
	q.push({srcx , srcy}) ;
	dist[srcx][srcy] = 0 ;
	sr[srcx].erase(srcy) ;
	sc[srcy].erase(srcx) ;
	while(!q.empty())
	{
		pair<int , int>p = q.front() ;
		q.pop() ;
		int x = p.first , y = p.second ;
		int a = -1e9 ;
		if(sr[x].size())
			a = *sr[x].rbegin() ;
		if(a > y)
		{
			if(v.size())
				v.clear() ;
			it = sr[x].lower_bound(y) ;
			for(it ; it != sr[x].end() ; ++it)
			{
				if((*it) > y+k || grid[x][(*it)] == '@')
					break ;
				v.push_back((*it)) ;
			}
			for(auto &j : v)
			{
				if(x == 2 && j == 0)
					cout<<"HERE\n" ;
				dist[x][j] = dist[x][y] + 1 ;
				sr[x].erase(j) ;
				sc[j].erase(x) ;
				q.push({x , j}) ;
			}
		}
		a = 1e9 ;
		if(sr[x].size())
			a = *sr[x].begin() ;
		if(a < y)
		{
			if(v.size())
				v.clear() ;
			it = sr[x].lower_bound(y) ;
			it-- ;
			for(it ; ; --it)
			{
				if((*it) < y-k || grid[x][(*it)] == '@')
					break ;
				v.push_back((*it)) ;
				if(it == sr[x].begin())
					break ;
			}
			for(auto &j : v)
			{
				dist[x][j] = dist[x][y] + 1 ;
				sr[x].erase(j) ;
				sc[j].erase(x) ;
				q.push({x , j}) ;
			}
		}
		a = -1e9 ;
		if(sc[y].size())
			a = *sc[y].rbegin() ;
		if(a > x)
		{
			if(v.size())
				v.clear() ;
			it = sc[y].lower_bound(x) ;
			for(it ; it != sc[y].end() ; ++it)
			{
				if((*it) > x+k || grid[(*it)][y] == '@')
					break ;
				v.push_back((*it)) ;
			}
			for(auto &j : v)
			{
				dist[j][y] = dist[x][y] + 1 ;
				sr[j].erase(y) ;
				sc[y].erase(j) ;
				q.push({j , y}) ;
			}
		}
		a = 1e9 ;
		if(sc[y].size())
			a = *sc[y].begin() ;
		if(a < x)
		{
			if(v.size())
				v.clear() ;
			it = sc[y].lower_bound(x) ;
			it-- ;
			for(it ; ; --it)
			{
				if((*it) < x-k || grid[(*it)][y] == '@')
					break ;
				v.push_back((*it)) ;
				if(it == sc[y].begin())
					break ;
			}
			for(auto &j : v)
			{
				dist[j][y] = dist[x][y] + 1 ;
				sr[j].erase(y) ;
				sc[y].erase(j) ;
				q.push({j , y}) ;
			}	
		}
	}
}

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n>>m>>k ;
	int x1 , y1 , x2 , y2 ;
	cin>>x1>>y1>>x2>>y2 ;
	x1-- , y1-- , x2-- , y2-- ;
	grid = vector< vector<char> >(n+1 , vector<char>(m+1)) ;
	sr = vector< set<int> >(n+1) ;
	sc = vector< set<int> >(m+1) ;
	for(int i = 0 ; i < n ; ++i)
	{
		for(int j = 0 ; j < m ; ++j)
		{
			cin>>grid[i][j] ;
			sr[i].insert(j) ;
			sc[j].insert(i) ;
		}
	}
	bfs(x1 , y1) ;
	if(dist[x2][y2] == 1e9)
		dist[x2][y2] = -1 ;
	return cout<<dist[x2][y2]<<"\n" , 0 ;
}		

Measured memory_bytes: 157616
#include<iostream>
#include<vector>
#include<string>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<numeric>
#include<iomanip>
using namespace std;

typedef long long LL;
const int MOD = 1e9+7;

double dfs(int n,int x,int y,int z,vector<vector<vector<double>>> &dp,vector<vector<vector<int>>> &vis){
	if(vis[x][y][z]) return dp[x][y][z];
	if((x+y+z)==0) return 0.0;
	dp[x][y][z] = 1.0;
	vis[x][y][z] = 1;
	if(x){
		dp[x][y][z]+=1.0*x/n * dfs(n,x-1,y,z,dp,vis);
	}
	if(y){
		dp[x][y][z]+=1.0*y/n * dfs(n,x+1,y-1,z,dp,vis);
	}
	if(z){
		dp[x][y][z]+=1.0*z/n * dfs(n,x,y+1,z-1,dp,vis);
	}
	dp[x][y][z]*=1.0*n/(x+y+z);
	return dp[x][y][z];
}

void solve(){
	int n;
	cin>>n;
	vector<int> nums(n);
	for(int i=0;i<n;i++) cin>>nums[i];
	vector<int> t(3,0);
	for(auto &item:nums){t[item-1]++;}
	vector<vector<vector<double>>> dp(n+1,vector<vector<double>>(n+1,vector<double>(n+1)));
	vector<vector<vector<int>>> vis(n+1,vector<vector<int>>(n+1,vector<int>(n+1)));
	cout<<setprecision(10)<<dfs(n,t[0],t[1],t[2],dp,vis)<<endl;
}


int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int T = 1;
	// cin>>T;
	while(T--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 326400
#include <iostream>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <cstdlib>
#include <cmath>
#define rep(i,n) for(int i=0;i<(n);i++)
#define EPS 1e-12

using namespace std;

char sr[15];
int v[105];
double r[105];

double calc_expect (int n )
{
	double sum = accumulate (r, r+n, 0.0 );
	double res = 0.0;

	if (fabs (1.-sum ) < EPS ){
		rep (i, n ) res += v[i]*r[i];
	}else{
		rep (i, n ) res += v[i]*r[i]/sum;
	} // end if
	
	return res;
}

int main()
{
	int cnt;
	scanf ("%d", &cnt );
	double child_expect = 0.0;
	double curr = 0.0;

	while (cnt--){
		int n, m;
		scanf ("%d %d", &n, &m );
		memset (v, 0, sizeof (v ) );
		memset (r, 0.0, sizeof (r ) );
		rep (i, m ){
			scanf ("%d %s", &v[i], sr );
			r[i] = atof (sr );			
		} // end rep
		curr = calc_expect (m );
		child_expect = max (child_expect, curr );
	} // end while

	int p, q;
	scanf ("%d %d", &p, &q );
	double parent_expect = 0.0;
	memset (v, 0, sizeof (v ) );
	memset (r, 0.0, sizeof (r ) );

	rep (i, q ){
		scanf ("%d %s", &v[i], sr );
		r[i] = atof (sr );
	} // end rep
	parent_expect = calc_expect (q );

	if (child_expect > parent_expect + 0.0000001 ){
		printf ("YES\n");
	}else{
		printf ("NO\n");
	} // end if

	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;
public class Main{
public static void main(String[] args){
int a,b,c,rtn;
Scanner sc=new Scanner(System.in);
a=sc.nextInt();
b=sc.nextInt();
c=sc.nextInt();
if(a>b){
if(a>c)rtn=b+c;
else rtn=a+b;
}else{
if(b>c)rtn=a+c;
else rtn=a+b;
}
System.out.println(rtn);
}
}

Measured memory_bytes: 23764
#include<stdio.h>
int main(void)
{
	int W, H, x, y ,r =0;
	
	scanf("%d %d %d %d %d",&W ,&H ,&x ,&y ,&r);
	if((r>x)||((x+r)>W)||(r>y)||((y+r)>H)){
		printf("No\n");
	}else{
		printf("Yes\n");
	}
	
	return 0;
}


Measured memory_bytes: 2128
#include "bits/stdc++.h"
using namespace std;
#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 ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<double> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<VS> VSS;  
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;  //ll とdoubleは違う
// cout << << endl;
// cin >> ;
int main(){
    double a,b,c=0,d=0,n,m1,n2,m2,min=100000,k=0,ans=0;
    string s,s2;
    cin >> a >> b;
    if(b/10>=1&&b/10<=9)
        c = a*100+b;
    else if (b/100==1)
        c = a*1000+b;
    else c = a*10+b;
    if (ceil(sqrt(c)) == floor(sqrt(c))){
        cout << "Yes" <<endl; 
    }
    else cout << "No" <<endl; 
    return 0;
}


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

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

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

  for (int i = -119; i <= 118; ++i) {
    for (int j = -119; j <= 118; ++j) {
      if (std::pow(i, 5) - std::pow(j, 5) == x) {
        std::cout << i << ' ' << j << '\n';
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 4036
#include <bits/stdc++.h>
using namespace std;
#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 ALL(v) v.begin(), v.end()
#define downque(que) priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
typedef vector<vector<int>> Matrix;
const int MOD = 1e9 + 7;
const int MAX = 1e7;
const int INF = numeric_limits<int>::max();


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

  cout << n/2+n%2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC return 0;
using namespace std;
int st(0), dr(1e9), mid;
long double a, b, res(-1), p1(0.08), p2(0.1);
int main() {
    DAU
    cin >> a >> b;
    while (st <= dr) {
        mid = (st + dr) / 2;
        if (mid * p1 >= a && mid * p2 >= b)
            res = mid, dr = mid - 1;
        else st = mid + 1;
    }
    if (res * p1 - a >= 1 || res * p2 - b >= 1)
        cout << "-1";
    else cout << res;
    PLEC
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

bool v[1005][1005][1005];
int main() {
  int x,y,z,k;
  cin >> x >> y >> z >> k;
  vector<ll> a(x),b(y),c(z);
  rep(i,x) cin >> a[i];
  rep(i,y) cin >> b[i];
  rep(i,z) cin >> c[i];
  sort(a.rbegin(),a.rend());
  sort(b.rbegin(),b.rend());
  sort(c.rbegin(),c.rend());

  priority_queue<tuple<ll,int,int,int>> q;
  auto push = [&](int n,int m,int l){
    if(v[n][m][l]) return;
    v[n][m][l] = true;
    q.emplace(a[n]+b[m]+c[l],n,m,l);
  };
  push(0,0,0);
  rep(i,k){
    ll ans; int ai,bi,ci;
    tie(ans,ai,bi,ci) = q.top(); q.pop();
    cout << ans << endl;
    if(ai<x-1) push(ai+1,bi,ci);
    if(bi<y-1) push(ai,bi+1,ci);
    if(ci<z-1) push(ai,bi,ci+1);
  }  
}

Measured memory_bytes: 612736
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

vector<int> eT;

void es( int n ){
	for( int i = 0; i < n; ++i ) eT.push_back(i);
}

int wurzel( int x ){
	if( eT.at(x) == x ){
		return x;
	} else {
		return eT.at(x) = wurzel( eT.at(x) );
	}
}

void verbinden( int x, int y ){
	x = wurzel(x);
	y = wurzel(y);
	if( x == y ) return;
	eT.at(x) = y;
}

bool gleich( int x, int y ){
	return wurzel(x) == wurzel(y);
}

bool meow[100010];

int main(){
	int n, m;
	cin >> n >> m;
	es(n);
	for( int i = 0; i < m; ++i ){
		int x, y, z; cin >> x >> y >> z; --x; --y; --z;
		verbinden(x, y);
	}
	for( int i = 0; i < n; ++i ){
		meow[wurzel(i)] = true;
	}
	int ans = 0;
	for( int i = 0; i < n; ++i ){
		if( meow[i] ) ++ans;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1272
h, w = map(int, input().split())

arr_all = []
arr_del = []
for i in range(h):
    arr_w = input()
    if list(set(arr_w)) == ["."]:
        continue
    else:
        arr_all.append(arr_w)
        arr_del.append([])


d = []

for i in range(w):
    for j in range(len(arr_all)):
        if arr_all[j][i] == ".":
            if j == w - 1:
                break
            else:
                continue
        else:
            d.append(i)
            break

for j in range(len(arr_all)):
    for i in d:
        arr_del[j] += arr_all[j][i]


for i in range(len(arr_all)):
    print(''.join(arr_del[i]))

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

int main(){
    int h, w, hsel, wsel, var, hol, rem;
    cin >> h >> w >> hsel >> wsel;
    /*ここから計算*/
    var = hsel * w;
    hol = wsel * h;
    rem = hsel * wsel;

    cout << (h * w)-(var + hol - rem) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

#define N_MAX 500

int list[N_MAX][N_MAX];
int isinvited[N_MAX];

int n, m;

int answer(){
	int i, a = 0;
	for (i = 1; i < n; i++) {
		if (isinvited[i]) a++;
	}

	return printf("%d\n", a);
}

int solve(){
	int i, j;
	int result[N_MAX] = {0};

	for (i = 0; i < n; i++) {
		if (isinvited[i]) {
			for (j = 0; j < n; j++) {
				if (list[i][j]) result[j] = 1;
			}
		}
	}

	for (i = 0; i < n; i++) {
		isinvited[i] = result[i];
		// fprintf(stderr, "[%d] %d ", i, isinvited[i]);
	}
	// fprintf(stderr, "\n");

	return 0;
}

int mn(void){
	int i, j;

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

	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			list[i][j] = ((i == j) ? 1 : 0);
		}
		isinvited[i] = 0;
	}


	while (m--) {
		int l, r;
		scanf("%d%d", &l, &r);
		l--;
		r--;
		list[l][r] = list[r][l] = 1;
	}

	// fprintf(stderr, "Line %d\n", __LINE__);

	isinvited[0] = 1;

	solve();
	solve();

	answer();

	return 0;
}


int main(void){
	while (scanf("%d%d", &n, &m), (n || m)) {
		mn();
	}

	return 0;
}

Measured memory_bytes: 1576
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val array = readLine()!!.split(' ').map { it.toInt() }
    var count = 0
    for (i in 1.until(n - 1)) {
        val c1 = array[i - 1] < array[i] && array[i] < array[i + 1]
        val c2 = array[i - 1] > array[i] && array[i] > array[i + 1]
        if (c1 || c2) count++
    }
    println(count)
}

Measured memory_bytes: 36452
sa=raw_input()
sb=raw_input()
sc=raw_input()

def draw(curr):
    global sa, sb, sc
    if curr == 'a' and len(sa) > 0:
        curr=sa[0]
        sa=sa[1:]
        draw(curr)
    elif curr == 'a' and len(sa) == 0:
        print 'A'
    elif curr == 'b' and len(sb) > 0:
        curr = sb[0]
        sb = sb[1:]
        draw(curr)
    elif curr == 'b' and len(sb) == 0:
        print 'B'
    elif curr == 'c' and len(sc) > 0:
        curr = sc[0]
        sc = sc[1:]
        draw(curr)
    elif curr == 'c' and len(sc) == 0:
        print 'C'


curr=sa[0] if len(sa) > 0 else ''
if curr == '':
    print 'A'
sa=sa[1:]
draw(curr)

Measured memory_bytes: 2820
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
bool dp[1010][53][53][4];
int dir[1010];
int g[52][52];
int dx[]={0,1,-1,0};
int dy[]={1,0,0,-1};
char in[5];
int main(){
	int n,sx,sy,t;
	scanf("%d%d%d%d",&n,&sx,&sy,&t);
	for(int i=0;i<n;i++){
		int x1,x2,y1,y2;scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
		if(x1>x2)swap(x1,x2);
		if(y1>y2)swap(y1,y2);
		if(x1==x2){
			for(int j=y1;j<y2;j++){
				g[x1][j]|=1;
				g[x1][j+1]|=8;
			}
		}else{
			for(int j=x1;j<x2;j++){
				g[j][y1]|=2;
				g[j+1][y1]|=4;
			}
		}
	}
	for(int i=0;i<1010;i++)dir[i]=-1;
	int now=0;
	for(int i=0;i<t;i++){
		int d;scanf("%d%s",&d,in);
		now+=d;
		if(in[0]=='N')dir[now]=0;
		if(in[0]=='E')dir[now]=1;
		if(in[0]=='W')dir[now]=2;
		if(in[0]=='S')dir[now]=3;
	}
	for(int i=0;i<4;i++)dp[0][sx][sy][i]=1;
	for(int i=0;i<now;i++){
		for(int j=0;j<52;j++)for(int k=0;k<52;k++)for(int l=0;l<4;l++){
			if(!dp[i][j][k][l])continue;
		//	printf("%d %d %d %d\n",i,j,k,l);
			for(int p=0;p<4;p++){
				if((g[j][k]&(1<<p))==0)continue;
				if(l+p==3)continue;
				if(~dir[i]&&p!=dir[i]&&l!=dir[i])continue;
				dp[i+1][j+dx[p]][k+dy[p]][p]=1;
			}
		}
	}
	for(int i=0;i<52;i++)for(int j=0;j<52;j++){
		bool ok=false;
		for(int k=0;k<4;k++){
			if(k==dir[now]||(k+dir[now]!=3&&(g[i][j]&(1<<dir[now])))){
				if(dp[now][i][j][k])ok=true;
			}
		}
		if(ok)printf("%d %d\n",i,j);
	}
}

Measured memory_bytes: 8812
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

#define NMAX 2000
#define MOD 1000000007
#define INF 2000000000

#define MIN(a, b) (a < b ? a : b)
#define MAX(a, b) (a > b ? a : b)

using namespace std;

int n;
int arr[50];

bool IsSorted(int* arr, int n)
{
	for (int i = 0; i < n - 1; i++)
		if (arr[i] > arr[i + 1])
			return false;
	return true;
}

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

	if (IsSorted(arr, n))
	{
		cout << "YES\n";
		return 0;
	}
	for(int i = 0; i < n - 1; i++)
		for (int j = i + 1; j < n; j++)
		{
			swap(arr[i], arr[j]);
			if (IsSorted(arr, n))
			{
				cout << "YES\n";
				return 0;
			}
			swap(arr[i], arr[j]);
		}
	cout << "NO\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
#include <string>
#include <stdlib.h>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<fstream>
#include<typeinfo>
#define ll long long
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define I insert
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define repi(i,a,b)  for(ll i=a;i<b;i++)
#define repj(j, a, b) for (ll j = a; j < b;j++)
#define vi vector<int>
#define pii pair<int, int>
#define vpii vector< pii >
#define mod 1000000007
#define lim 100001
 
using namespace std;
ll factorial(ll n){return (n==1 || n==0) ? 1: n * factorial(n - 1); }
int max3(int a,int b,int c){ return max(a, max(c, b));}
int gcd(int a,int b){if(a==0){return b;}else{return gcd(b % a, a);}}
ll power(ll a, ll n){if(n==1) return a; else if(n==0) return 1; else{ ll r = power(a, n / 2); if(n%2==0) return r * r; else return r * a * r;}}
ll nCr(ll n, ll r) { return ((factorial(n)) / (factorial(n - r) * factorial(r))); }
void dfs(vector< vector<int > >& v,vi& check,int start){check[start - 1] = 1;repj(j, 0, v[start-1].size()){if(!check[v[start-1][j]-1]){dfs(v, check, v[start - 1][j]);}}}
bool isPrime(ll n) { if (n <= 1) return false;if (n <= 3)return true; if (n % 2 == 0 || n % 3 == 0)return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; }
//works under 2 till 1e12
 
int i, j;
 
int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   int n;
   cin>>n;
   ll num = 0;
   ll arr[n];
   for(int i=0;i<n;i++){
       cin>>arr[i];
       num^=arr[i];
   }
   for(int i=0;i<n;i++){
       ll ans = num^arr[i];
       cout<<ans<<" ";
   }
   return 0;
}



Measured memory_bytes: 5176
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a: String = read();
    let b: String = read();

    let x: f32 = format!("{}{}", a, b).parse::<f32>().unwrap();

    if x.sqrt() == x.sqrt().ceil() {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
L,R = map(int,input().split())
if R-L+1 >= 2019:
    print(0)
else:
    ans = 2018
    for i in range(L,R+1):
        for j in range(i+1,R+1):
            ans = min(ans,(i*j)%2019)
    print(ans)

Measured memory_bytes: 2940
#!/usr/bin/env python3
import sys

MOD = 2  # type: int


def solve(N: int, A: "List[int]"):
    ans = 0
    while not any([a & 1 for a in A]):
        for i in range(len(A)):
            A[i] //= 2
        ans += 1
    print(ans)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
X,N = map(int,input().split())
if N == 0:
    print(X)
    exit()
else:
    M = list(map(int,input().split()))
    up = X
    down = X
    ans = []
    while ans == [] :
        if up in M and down in M:
            up += 1
            down -= 1
        elif down in M:
            ans.append(up)
        else:
            ans.append(down)
    print(min(ans))

Measured memory_bytes: 9200
H, W = gets.split(' ').map(&:to_i)
N = gets.to_i
a = gets.split(' ').map(&:to_i)

l = []
a.each_with_index do |ai, index|
  ai.times { l << index + 1 }
end

c = []
H.times do |i|
  c[i] = []
  W.times do |j|
    if i % 2 == 0
      c[i][j] = l.shift
    else
      c[i][W-1-j] = l.shift
    end
  end
  print c[i].join(' ')
  print "\n"
end

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

int main(){
    int x,y,z;
    cin >> x >> y >> z;
    int haba=x-z;
    int ans=0;
    ans += haba/(y+z);
    cout << ans << endl;
    
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000

ll dp[415][415];

void solve_abc_d() {
	ll n, m, x, k;
	ll ma, mb;
	cin >> n >> ma >> mb;

	V a(n), b(n), c(n);
	rep(i, n) {
		cin >> a[i] >> b[i] >> c[i];
	}

	rep(i, 415)rep(j, 415) {
		dp[i][j] = INF;
	}

	dp[0][0] = 0;
	rep(i, n) {
		rrep(j, 10 * n, 0)rrep(k, 10 * n, 0) {
			dp[j + a[i]][k + b[i]] = min(dp[j + a[i]][k + b[i]], dp[j][k] + c[i]);
		}
	}

	ll na = ma;
	ll nb = mb;
	ll ans = INF;
	while(1){
		if ((na >= 415) || (nb >= 415)) {
			break;
		}
		if (dp[na][nb] != INF) {
			ans = min(ans, dp[na][nb]);
		}
		na += ma;
		nb += mb;
	}

	if (ans == INF) ans = -1;

	cout << ans << "\n";
}

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//cout << fixed;
	//cout << setprecision(7);

	solve_abc_d();

	return 0;
}


Measured memory_bytes: 1664
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String str = sc.next();
		char check, bCheck;
		int Count = 0;
		bCheck = str.charAt(0);
		for(int i = 1; i < N; i++) {
			check = str.charAt(i);
			if(check != bCheck) {
				Count++;
			}
			bCheck = check;
		}
		System.out.println(Count+1);
	}
}

Measured memory_bytes: 24612
N = int(input())
l = ['3','5','7']

def dfs(s):
    if int(s)>N:
        return 0
    res = sum([dfs(s+c) for c in l])
    if all([1 if c in s else 0 for c in l]):
        res += 1
    return res

print(dfs('0'))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
int main(){
    ll n; cin >> n;
    if(n == 0 || n % 2 != 0){
        cout << 0 << endl;
        return 0;
    }
    ll ans = 0;
    ll num = 10LL;
    while(num <= n){
        ans += n / num;
        num *= 5LL;
    }
    cout << ans << endl;
}

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

typedef long long int ll;

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main(){
  int N;
  cin >> N;
  vector<ll> T(N),A(N);
 
  ll t = 1,a = 1;
  for(int i = 0; i < N; i++){
    cin >> T.at(i) >> A.at(i);
    ll x = t / T.at(i);
    ll y = a / A.at(i);
    
    if(t%T.at(i) != 0) x++;
    if(a%A.at(i) != 0) y++;
    
    ll co = max(x,y);
    
    t = co * T.at(i);
    a = co * A.at(i);
  }
  
  cout << t + a << endl;
}
  
  

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <numeric>
#include <stdio.h>
#include <cmath>
#include <queue>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <deque>
#include <bitset>
#include <cstring>
#include <sstream>
#include <complex>

#define f first
#define s second
#define ll long long
#define ld double
#define pb push_back
#define all(x) x.begin(),x.end()
#define mp make_pair
#define y0 eto
#define y1 mezhdy
#define y2 nami
#define left extermination
#define right dismemberment
 
using namespace std;
 
double start_moment = 0;
double get_runtime() { return 1.0*clock()/CLOCKS_PER_SEC; }
void reset_timer() { start_moment = get_runtime(); }
double timer_time() { return get_runtime() - start_moment; }
void runtime(){cout<<fixed<<setprecision(5)<<get_runtime()<<'\n';}
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
template <class T>void read(vector<T> &a,ll n){T x; a.clear();for(ll i=0;i<n;i++){cin>>x;a.pb(x);}}
template <class T>void write(vector<T> &a){for(T x : a) cout<<x<<' ';cout<<'\n';}



int main()
{
    ios_base::sync_with_stdio(0);
//    freopen("INPUT.txt","r",stdin);
//    freopen("OUTPUT.txt", "w", stdout);
    
    int  n,x,t;
    cin>>n>>x>>t;
    cout<<(n+x-1)/x*t<<endl;
    
  

}


Measured memory_bytes: 3192
#pragma region head
    #include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    using vi = vector<int>;
    using vll = vector<ll>;
    using pi = pair<int, int>;
    using pll = pair<ll,ll>;
    template <class T> using vv = vector<vector<T>>;
    #define rep(i,n) for(int i = 0; i < (int)(n); i++)
    #define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
    #define rrep(i,n) for(int i = (int)(n)-1; i >= 0; i--)
    #define rrepi(i,a,b) for(int i = (int)(b)-1; i >= (int)(a); i--)
    #define all(x) (x).begin(), (x).end()
    #define bit(n) (1LL<<(n))
    const int INF = 1002003004;
    const ll LINF = 1002003004005006007ll;
    struct preprocess{preprocess()
    {cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}}____;
#pragma endregion head

#pragma region library
#pragma endregion library

int main(){
    int n; cin >> n;
    vi a(n); rep(i,n) cin >> a[i];
    ll xr = 0, tot = 0;
    int l = 0, r = 0;
    ll ans = 0;
    while(l<n){
        while(r<n && (xr^a[r]) == (tot+a[r])){
            xr^=a[r]; tot += a[r];
            r++;
        }
        ans += r - l;
        xr^=a[l]; tot -= a[l];
        l++;
    }
    cout << ans << '\n';
    
}

Measured memory_bytes: 3968
#include<iostream>
using namespace std;
 
int main(){
	string s1,s2;
 	cin>>s1>>s2;
  	int count=0;
  	for(int i=0;i<s1.size();i++)
    	if(s1[i]!=s2[i]) count++;
  	
  	cout<<count<<endl;
	return 0; 
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL) x=x->left;
  return x;
}

Node treeMaximum(Node x){
  while(x->right!=NIL) x=x->right;
  return x;
}

Node treeSearch(Node u, int k){
  while(u!=NIL && k!=u->key){
    if(k<u->key) u=u->left;
    else u=u->right;
  }
  return u;
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right!=NIL) return treeSuccessor(x->right);
  y=x->parent;
  while(y!=NIL && x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left==NIL || z->right==NIL) y=z;
  else y=treeSuccessor(z);
  if(y->left!=NIL) x=y->left;
  else x=y->right;
  if(x!=NIL) x->parent=y->parent;
  if(y->parent==NIL) root=x;
  else if(y==y->parent->left) y->parent->left=x;
  else y->parent->right=x;
  if(y!=z) z->key=y->key;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key<x->key) x=x->left;
    else x=x->right;
  }
  z->parent=y;
  if(y==NIL) root=z;
  else if(z->key<y->key) y->left=z;
  else y->right=z;
}

void inorder(Node u){
  if(u==NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u==NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 20444
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n,a,b;
    cin >> n >> a >> b;

    cout << min(a * n, b) << endl;
   
}


Measured memory_bytes: 256
x, y = map(int, input().split())

def gcd(x, y):
    while x != y:
        if x > y:
            x = x % y
            if x == 0:
                return y
        elif y > x:
            y = y % x
            if y == 0:
                return x
    return x

print(gcd(x, y))



Measured memory_bytes: 5600
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint A, B, C, D; cin >> A >> B >> C >> D;
    string res;
    if (A + B > C + D) res = "Left";
    else if (A + B == C + D) res = "Balanced";
    else res = "Right";
    cout << res << "\n";
}

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

using namespace std;

int main()
{
    string s,t;

    cin>>s>>t;

    int i,j,k=1;

    j=s.size();

    for(i=0;i<j;i++)
    {
        if(s[i]==t[i])
            k=1;
        else
        {
            k=0;break;
        }
    }

     if(k)//t.find(s)!=std::string::npos)
     {
         cout<<"Yes\n";

     }

     else

        cout<<"No\n";


    return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
auto f(int n){if(n%2)return 3*n+1; else return n/2;}
signed main(){
    int s; cin>> s;
    map<int,int>mp;
    mp[s] = 1; int val = s;
    int cnt = 1;
    while(true){
        val = f(val);
        if(mp[val]++)return cout << cnt + 1 << endl,0;
        cnt++;
    }
}




Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

int main(){
    int n,k; cin >> n >> k;
    int ans = 1;
    while(n > k){
        n -= k;
        n++;
        ans++;
    }
    cout << ans << endl;
}

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

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

int main(void) {
    string S;
    ll count = 0;
    cin >> S;
    for(auto &c: S) {
        if(c == '+') count++;
        else count--;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

int main(void) {
    int A, B, C, K;
    cin >> A >> B >> C >> K;

    if (K <= A) {
        cout << K << endl;
    } else if (K <= (A + B)) {
        cout << A << endl;
    } else {
        cout << A - (K - (A + B)) << endl;
    }

    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

class RMQ {
  vector<long long> data;

public:
  static const long long INF = 100000000000;
  int n;
  RMQ(int _) {
    n = _;
    data.resize(n * 4);
    for (int i = 0; i < n * 4; i++)
      data[i] = INF;
  }
  void update(int index, long long val) {
    int i = index + n - 1;
    data[i] = val;
    while (i > 0) {
      i = (i - 1) / 2;
      data[i] = min(data[i * 2 + 1], data[i * 2 + 2]);
    }
  }
  // [a, b)
  long long query(int a, int b, int k, int l, int r) {
    if (a < 0)
      return 0;
    if (r <= a || b <= l)
      return INF;
    if (a <= l && r <= b)
      return data[k];
    else
      return min(query(a, b, k * 2 + 1, l, (l + r) / 2),
                 query(a, b, k * 2 + 2, (r + l) / 2, r));
  }
  long long query(int a, int b) { return query(a, b, 0, 0, n); }
};

template <typename T> class tRMQ {
  vector<T> data;
  T unit;

public:
  int n;
  function<T(const T &, const T &)> f;
  tRMQ(int _, T u, function<T(T, T)> bi) {
    unit = u;
    f = bi;
    n = 1;
    while (n < _) {
      n <<= 1;
    }
    data.resize(n * 4);
    for (int i = 0; i < n * 4; i++)
      data[i] = unit;
  }
  tRMQ(vector<T> &v, T u, function<T(T, T)> bi) {
    unit = u;
    f = bi;
    n = 1;
    while (n < v.size())
      n <<= 1;
    data.resize(n * 2 + 1);
    for (int i = 0; i < n + 1; i++) {
      if (i < v.size())
        data[i + n] = v[i];
      else
        data[i + n] = u;
    }
    for (int i = n - 1; i >= 0; i--) {
      data[i] = f(data[i * 2 + 1], data[i * 2 + 2]);
    }
  }
  void update(int index, T val) {
    int i = index + n - 1;
    data[i] = val;
    while (i > 0) {
      i = (i - 1) / 2;
      data[i] = f(data[i * 2 + 1], data[i * 2 + 2]);
    }
  }
  // [a, b)
  T query(int a, int b, int k, int l, int r) {
    if (a < 0 || r <= a || b <= l)
      return unit;
    if (a <= l && r <= b)
      return data[k];
    else
      return f(query(a, b, k * 2 + 1, l, (l + r) / 2),
               query(a, b, k * 2 + 2, (r + l) / 2, r));
  }
  T query(int a, int b) { return query(a, b, 0, 0, n); }
};

tRMQ<ll> minrmq(int n) {
  return tRMQ<ll>(n, 10000000000000000LL, [](ll r, ll l) { return min(l, r); });
}
tRMQ<ll> maxrmq(int n) {
  return tRMQ<ll>(n, -10000000000000000LL,
                  [](ll r, ll l) { return max(l, r); });
}
tRMQ<ll> sumrmq(int n) {
  return tRMQ<ll>(n, 0, [](ll l, ll r) { return l + r; });
}

int main() {
  int n, q;
  cin >> n >> q;
  vector<ll> v(n);
  for (int i = 0; i < n; i++)
    v[i] = (1LL << 31) - 1LL;
  tRMQ<ll> rmq(v, (1LL << 31) - 1LL, [](ll l, ll r) { return min(l, r); });
  int c, l, r;
  for (int i = 0; i < q; i++) {
    cin >> c >> l >> r;
    if (c) {
      cout << rmq.query(l, r + 1) << endl;
    } else {
      rmq.update(l, r);
    }
  }

  return 0;
}


Measured memory_bytes: 5744
#include <iostream>
#include <stdio.h>
#include <cstring>
using namespace std;

int main()
{
  char str1[100], str2[100], str3[200];
  scanf("%s %s", str1, str2);

  strcpy(str3, str1);
  strcat(str3, str1);
    
  if(strstr(str3, str2) == NULL)
  {
    printf("No\n");
  }
  else
  {
    printf("Yes\n");
  }

  return 0;
}


Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define foi(i,a,n) for(int i=a;i<n;i++)
#define el "\n"
const int INF = 2e9+5;
void solve(){
	int n;cin>>n;
  	vector<vector<int>> a(n, vector<int>(3,0));
  	rep(i,n){
    	int x,y,z;cin>>x>>y>>z;
      	if(i==0){
          a[0][0]=x,a[0][1]=y,a[0][2]=z;
          continue;
        }
		a[i][0]=max(a[i-1][1],a[i-1][2])+x;
      	a[i][1]=max(a[i-1][0],a[i-1][2])+y;
      	a[i][2]=max(a[i-1][1],a[i-1][0])+z;
    }
  	cout<<max(a[n-1][0],max(a[n-1][1],a[n-1][2]))<<el;
}

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

Measured memory_bytes: 8792
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 1000000000;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	int a, b;
	cin >> a >> b;
	cout << max(a - 2 * b, 0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(long long i = 0; i < (long long)(N); i++)
#define repr(i,N) for(long long i = (long long)(N) - 1; i >= 0; i--)
#define rep1(i,N) for(long long i = 1; i <= (long long)(N) ; i++)
#define repr1(i,N) for(long long i = (N) ; (long long)(i) > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; template<class T = ll> using V = vector<T>;
using vi = V<int>; using vl = V<>; using vvi = V< V<int> >;
constexpr int inf = 1001001001; constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,N) do { cerr << #v << " = "; array_out(v , N);cout << endl;} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif

#define in2(N,s,t) rep(i,N){in(s[i] , t[i]);}
#define in3(N,s,t,u) rep(i,N){in(s[i] , t[i] , u[i]);}
using vd = V<double>; using vs = V<string>; using vvl = V< V<> >;
template<typename T>using heap = priority_queue< T , V<T> , greater<T> >;

using P = pair<int,int>; using vp = V<P>;
constexpr int MOD = /** 1000000007; //*/ 998244353;
//////////////////

void solve(){
  ini(N);
  vl a(N); in(a);
  ll ans = 0;
  if(N == 1) die(a[0] / 2);
  rep(i , N - 1){
    if(a[i + 1] == 0){
      ans += a[i] / 2;
      a[i] -= a[i] / 2 * 2;
    }
    else{
      ll cur = (a[i] + a[i + 1]) / 2;
      ans += cur;
      a[i + 1] = a[i] + a[i + 1] - cur * 2;
      a[i] = 0;
    }
  }
  out(ans);
}

Measured memory_bytes: 1024