akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const int INF = 1000000000;

int n, m, k[150], x[150][150], d[150][150];

int dp[150][150][100];

int dijkstra() {
  for (int i = 0; i < n; i++) for (int j = 0; j <= 10; j++) for (int k = 0; k <= m; k++) dp[i][j][k] = INF;
  for (int i = 0; i < k[0]; i++) dp[0][i][m] = 0;
  if (m != 0) for (int i = 0; i < k[1]; i++) dp[1][i][m-1] = 0;
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < k[i]; j++) {
      for (int r = 0; r < k[i - 1]; r++)
        for (int s = 0; s <= m; s++)
          dp[i][j][s] = min(dp[i][j][s],
                            dp[i-1][r][s] + (d[i][j] + d[i-1][r]) * abs(x[i][j] - x[i-1][r]));
      if (i == 1) continue;
      for (int r = 0; r < k[i - 2]; r++)
        for (int s = 0; s < m; s++)
          dp[i][j][s] = min(dp[i][j][s],
                            dp[i-2][r][s+1] + (d[i][j] + d[i-2][r]) * abs(x[i][j] - x[i-2][r]));
    }
  }
  int ans = INF;
  for (int i = 0; i < k[n-1]; i++) for (int j = 0; j <= m; j++) ans = min(ans, dp[n-1][i][j]);
  for (int i = 0; i < k[n-2]; i++) for (int j = 1; j <= m; j++) ans = min(ans, dp[n-2][i][j]);
  return ans;
}

int main() {
  while (1) {
    scanf("%d%d", &n, &m);
    if (n == 0) break;
    for (int i = 0; i < n; i++) {
      scanf("%d", &k[i]);
      for (int j = 0; j < k[i]; j++) scanf("%d%d", &x[i][j], &d[i][j]), x[i][j]--;
    }
    printf("%d\n", dijkstra());
  }
}



Measured memory_bytes: 3988
import math
A, B = list(map(int, input().split()))

Ans = (B // 2 + B % 2 - ((A - 1) // 2 + (A - 1) % 2)) % 2
cnt = 1
while True:
  p = pow(2, cnt)
  if p > B:
    break
  ma = (A - 1) % (p * 2)
  a = max(0, 1 + ma - p)

  mb = B % (p * 2)
  b = max(0, 1 + mb - p)

  t = abs(b - a)
  if t % 2 == 1:
    Ans += p
  cnt += 1
print(Ans)


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <unordered_set>
#include <set>
using namespace std;

#define MOD (int)(1e9+7)

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

	vector<int>B(3);

	long long ans = 1;
	for (int i = 0; i < N; i++)
	{
		int index = -1;
		int cnt = 0;
		for (int j = 0; j < 3; j++)
		{
			if(B[j] == A[i])
			{
				cnt++;
				index = j;
			}
		}

		ans *= cnt;
		ans %= MOD;

		if(index == -1)break;

		B[index]++;
	}

	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = -1*((1LL<<63)+1);
const int inf = -1*((1<<31)+1);

using namespace std;
ll C[51][51];
void comb_table(int N){
	for(int i=0;i<=N;++i){
		for(int j=0;j<=i;++j){
			if(j==0 or j==i){
				C[i][j]=1LL;
			}else{
				C[i][j]=(C[i-1][j-1]+C[i-1][j]);
			} 
		}
	}
}

ll COM(int n,int k){
	return C[n][k];
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N,A,B;
	cin >> N >> A >> B;
	comb_table(N);
	vector<ll> v(N);
	rep(i,N)cin >> v[i];
	sort(v.rbegin(),v.rend());
	double ave = 0;
	rep(i,A)ave+=v[i];
	ave/=A;
	cout << fixed << setprecision(10) << ave << endl;
	if(v[0] != v[A-1]){
		int ic = 0;
		int sum= 0;
		rep(i,A)if(v[A-1]==v[i])ic++;
		rep(i,N)if(v[A-1]==v[i])sum++;
		cout << COM(sum,ic) << endl;
	}else{
		int sum = 0;
		rep(i,N)if(v[A-1]==v[i])sum++;
		long long ans = 0;
		for(int i=A;i<=B;i++){
			ans += COM(sum,i);
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 256
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define sz size()

const double EPS = 1e-10;
const int INF = 100000000;



int main(){
    
    int a,b;
    while(cin>>a>>b){
        if(a<b)swap(a,b);
        while(b!=0){
            a=a%b;
            swap(a,b);
        }
        cout<<a<<endl;
    }

    
    return 0;
}

Measured memory_bytes: 1160
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
	int N;
	scanf("%d", &N);
	char S[N];
	for (int i = 0; i < N; ++i) scanf(" %c", &S[i]);
	if (N % 2) {
		printf("No");
		return 0;
	}
	for (int i = 0; i < N / 2; ++i) {
		if (S[i] != S[N / 2 + i]) {
			printf("No");
			return 0;
		}
	}
	printf("Yes");
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <climits>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>

#define DIV 1000000007

using namespace std;

long long N;
vector<long long>A;
vector<long long>B;
int main(){
	cin >> N;
	for(int i = 0; i < N; i++){
		long long tmp;
		cin >> tmp;
		A.push_back(tmp);
		B.push_back(tmp);
	}
	sort(B.begin(), B.end());
	long long ret = 0;

	for(int i = 0; i < N; i++){
		long long idx = i;
		long long tar = A[i];
		long long sortidx = lower_bound(B.begin(), B.end(), tar) - B.begin();
		if(sortidx % 2 != idx % 2){
			ret++;
		}
	}
	cout << ret/2 + (ret%2) << endl;

}


Measured memory_bytes: 2544
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.container;

void main()
{
	foreach (line; stdin.byLine) {
		auto x = line.chomp.split.map!(to!int);
		foreach_reverse (i; 1..max(x[0], x[1])+1) {
			if (x[0] % i == 0 && x[1] % i == 0) {
				i.writeln;
				break;
			}
		}
	}
}

Measured memory_bytes: 1064
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long>vll;
typedef pair<int,int> pi;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  int a, b, n, s, f;
  bool ok = true;
  
  cin >> a >> b >> n;
  for(int i = 0; i < n; i++){
    cin >> s >> f;
    if(s < b && f > a) ok = false;
  }
  cout << (ok?0:1) << endl;
  return 0;
}



Measured memory_bytes: 3096
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main(){
  string a, b;
  cin >> a >> b;

  for(int i = 0 ; i <= a.size() - b.size() ; i++ ){
    bool flag = false;
    for(int j = 0 ; j < b.size() ; j++ ){
      if(a[i + j] != b[j] && b[j] != '_') flag = true;
    }
    if(!flag){
      cout << "Yes" << endl;
      exit(0);
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 1184
#include <iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn = 1000010;
const long long mod = 1e9 + 7;
ll A[maxn];	//A[i]表示i的阶乘
ll B[maxn];	//B[i]表示i的阶乘关于mod的逆元
using namespace std;

ll pow_mod(ll a, ll b)
{
	ll ret = 1;
	while (b)
	{
		if (b & 1) ret = ret * a%mod;
		b >>= 1;
		a = a * a%mod;
	}
	return ret;
}

void Init()
{
	A[0] = 1;
	for (int i = 1; i <= maxn; i++)
		A[i] = (A[i - 1] * i) % mod;
	for (int i = maxn; i >= 0; i--)
		B[i] = pow_mod(A[i], mod - 2);
}

ll C(ll n, ll m) {
	if (n < m)
		return 0;
	return (A[n] * B[m] % mod)*B[n - m] % mod;
}

ll count_ways(ll a, ll b, ll c, ll d) {
	ll tot = (c - a) + (d - b);
	ll down = (c - a);
	ll ret = C(tot, down);
	return ret;
}

int main()
{
	Init();
	ll h, w, a, b;
	cin >> h >> w >> a >> b;
	ll tot = count_ways(1, 1, h, w);
	for (ll i = 1; i <= b; i++) {
		ll tmp = count_ways(1, 1, h - a, i)*count_ways(h - a + 1, i, h, w) % mod;
		while (tot < tmp) tot += mod;//防止出现负数
		tot = (tot - tmp) % mod;
	}
	cout << tot;
	return 0;
}

Measured memory_bytes: 19312
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define sqr(x) ((x)*(x))
#define mp make_pair
#define uint unsigned
#define PI pair<int,int>
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){
	int x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
	write(a); puts("");
}
inline int rnd(int x){
	return rand()%x;
}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=4005,mod=1000000007;
int n,m,k,dp[N][N],ans;
inline void add(int &a,int b){
	a=a+b>=mod?a+b-mod:a+b;
}
signed main(){
	n=read(); m=read(); k=read(); swap(n,m);
	int jb=k-1;
	dp[0][0]=1; dp[0][1]=-1;
	for(int i=0;i<(n+m-1)/(k-1);i++){
		for(int j=0;j<=n&&j<=i*(k-1);j++){
			if(j)add(dp[i][j],dp[i][j-1]);
			add(dp[i+1][j],dp[i][j]);
			add(dp[i+1][j+k],mod-dp[i][j]);
			if(j+((n-j)%jb==0?jb:(n-j)%jb)<=n&&(i+1)*jb-(j+((n-j)%jb==0?jb:(n-j)%jb))<m)ans=(ans+dp[i][j])%mod;
			//cout<<dp[i][j]<<" "<<i<<" "<<j<<" "<<(i+1)*jb-(j+(n-j)%jb)<<endl;
		}
	}
	cout<<(ans+mod)%mod<<endl;
}

Measured memory_bytes: 61056
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<int, int>
#define debug(x) cout << #x << ": " << x << '\n'

using namespace std;
using ll = long long;

const int  mod = 1e9+7;
int N;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  cin >> N;
  int ans = 0;
  for(int i=1; i<=N; i++) {
    if (i%2 == 0) continue;
    int cnt = 0;
    for(int j=1; j<=i; j++) {
      if (i%j == 0) {
        cnt++;
      }
    }
    if (cnt == 8) {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
N = int(input())
A = [int(x) for x in input().split()]

# Common divisor
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)


def gcd_wrapper(x, y):
    if x >= y:
        return gcd(x, y)
    else:
        return gcd(y, x)

if N == 2:
    print(max(A))
    exit()
if N == 3:
    x1 = gcd_wrapper(A[0], A[1])
    x2 = gcd_wrapper(A[1], A[2])
    x3 = gcd_wrapper(A[0], A[2])
    print(max([x1, x2, x3]))
    exit()
A = sorted(A)
A.reverse()
init_results = []
for k, g in enumerate(A[0:3]):
    for h in A[k+1:4]:
        init_results.append(gcd_wrapper(g, h))
if max(init_results) == 1:
    print(1)
    exit()
stop_flag = 0
x = max(init_results)
final_result = set()
final_result.add(x)
for i in A:
    tmp = gcd_wrapper(x, i)
    if tmp == 1:
        stop_flag += 1
    else:
        x = tmp
        final_result.add(tmp)
if stop_flag >= 2:
    print(1)
else:
    sorted_final_result = sorted(list(final_result))
    if len(sorted_final_result) == 1:
        print(sorted_final_result[0])
        exit()
    divable = []
    for j in A:
        if j % sorted_final_result[1] != 0:
            divable.append(1)
    if sum(divable) > 1:
        print(sorted_final_result[0])
    else:
        print(sorted_final_result[1])


Measured memory_bytes: 14584
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <queue>
#include <complex>

#define INF 100000000
#define EPS 1e-9

using namespace std;

typedef long long ll; 

#define MAX_W 50
#define MAX_H 50

int W, H;
int c[MAX_H][MAX_W];

vector<int> ans_list;

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

void solve(int x, int y){
  
  c[y][x] = 0;
  
  for(int i = 0; i < 8; i++){
    int nx = x + dx[i];
    int ny = y + dy[i];
    if(nx >= 0 && nx < W && ny >= 0 && ny < H && c[ny][nx] == 1)
      solve(nx, ny);
  }

}

int main(){
  
  while(true){
    
    cin >> W >> H;
    if(W == 0 && H == 0)
      break;

    for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
	cin >> c[i][j];
      }
    }

    int ans = 0;
    for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
	if(c[i][j] == 1){
	  ans++;
	  solve(j,i);
	}
      }
    }
    
    ans_list.push_back(ans);

  }

  for(int i = 0; i < ans_list.size(); i++){
    cout << ans_list[i] << endl;
  }
  
  return 0;
  
}

Measured memory_bytes: 1288
#include <stdio.h>
#include <vector>
typedef long long ll;
using namespace std;


int main(void) {
  ll i, j, k, n;
  scanf("%lld", &n);
  ll b[n], cnt[n];
  bool flg[n];
  for(i = 0; i < n; ++i) {
    scanf("%lld", &b[i]);
    cnt[i] = i + 1;
    if(b[i] > i + 1) {
      printf("-1");
      return 0;
    }
    flg[i] = true;
  }
  vector<ll> ans;
  for(k = 0; k < n; ++k) {
    for(i = n - 1; i >= 0; --i) if(flg[i]) {
      if(cnt[i] == b[i]) {
        ans.push_back(b[i]), flg[i] = false;
        for(j = i; j < n; ++j) cnt[j]--;
        break;
      }
    }
  }
  for(i = n - 1; i >= 0; --i) printf("%lld\n", ans[i]);
  return 0;
}

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

using namespace std;

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

typedef int _loop_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 DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

struct info{
    int a,b,dist;
    info(int _a,int _b){
        a = _a;
        b = _b;
        dist = b-a;
    }
};

bool compare(const info &a, const info &b)
{
    //return a.dist < b.dist;
    if(a.b < b.b)
        return true;
    else if(a.b > b.b)
        return false;
    else
        return a.a < b.a;
}

int main() {
    //int ans = 0;
    int n,m;
    vi a, b;
    cin>>n>>m;
    a.resize(m);
    b.resize(m);
    REP(i,m)
        cin>>a[i]>>b[i];

    vector<info> infos;
    REP(i,m)
        infos.emplace_back(info(a[i],b[i]));
    sort(ALL(infos),compare);

    vi brokenbridge; //brokenbridge<->brokenbridge-1の間の橋を落とす

    REP(i,m){
        bool broke;
        broke = false;
        //cout<<infos[i].a<<" "<<infos[i].b<<endl;
        REP(j, brokenbridge.size()){
            //cout<<brokenbridge[j]<<" > "<<(infos[i].a-1)<<endl;
            if(brokenbridge[j] > infos[i].a){
                //brokenbridge[j]<=>brokenbridge[j]-1 compare infos[i].a<=>infos[i].a+1
                broke=true;
                break;
            }
        } 

        if(!broke) brokenbridge.emplace_back(infos[i].b);
    }

    cout << brokenbridge.size() << endl;
    return 0;
}

Measured memory_bytes: 2680
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;

struct edge {
  ll from, to, cost;
};

int main()
{
  ll N;
  scanf("%lld",&N);
  ll M;
  scanf("%lld",&M);
  ll P;
  scanf("%lld",&P);
  ll A,B,C;
  vector<edge> es;
  for(int i=0; i<M; i++){
    scanf("%lld",&A);
    scanf("%lld",&B);
    scanf("%lld",&C);
    es.push_back(edge{A-1,B-1,P-C});
  }

  vector<ll> d(N, INF);
  d[0] = 0;
  for (int i=0; i<N; i++) {
    for (int j=0; j<M; j++) {
      edge e = es[j];
      if (d[e.from] == INF) continue;
      d[e.to] = min(d[e.to], d[e.from] + e.cost);
    }
  }

  ll dN = d[N-1];
  for (int i=0; i<N; i++) {
    for (int j=0; j<M; j++) {
      edge e = es[j];
      if (d[e.from] == INF) continue;
      d[e.to] = min(d[e.to], d[e.from] + e.cost);
    }
  }

  if (dN > d[N-1]) cout << -1 << endl;
  else cout << max(0LL, -d[N-1]) << endl;

  return 0;
}


Measured memory_bytes: 576
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <algorithm>
using namespace std;
int n,m;
struct island
{
    int a;
    int b;
}k[200000];
int cmp(island x,island y)
{
    return x.b<y.b;
}
int main()
{
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        cin>>k[i].a>>k[i].b;
    }
    sort(k,k+m,cmp);
    int t=0;
    int sum=0;
     for(int i=0;i<m;i++)
     {
         if(t<=k[i].a)
         {
             t=k[i].b;
             sum++;
         }
     }
     cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 1152
#include <cstring>
#include <iostream>
#include <vector>

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

    int link[n];
    std::vector<std::vector<int>> list;
    for (int i = 0; i < n; i++) {
        link[i] = -1;
    }

    int cnt = 0;
    int s, t;
    for (int i = 0; i < m; i++) {
        std::cin >> s >> t;
        if (link[s] == -1 && link[t] == -1) {
            link[s] = link[t] = cnt;
            cnt++;
            list.emplace_back(std::vector<int>({s, t}));
        } else if (link[s] == -1) {
            link[s] = link[t];
            list[link[t]].emplace_back(s);
        } else if (link[t] == -1) {
            link[t] = link[s];
            list[link[s]].emplace_back(t);
        } else if (link[s] < link[t]) {
            list[link[s]].insert(list[link[s]].end(), list[link[t]].begin(), list[link[t]].end());
            for (auto val : list[link[t]]) {
                link[val] = link[s];
            }
        } else if (link[t] < link[s]) {
            list[link[t]].insert(list[link[t]].end(), list[link[s]].begin(), list[link[s]].end());
            for (auto val : list[link[s]]) {
                link[val] = link[t];
            }
        }
    }

    int q;
    std::cin >> q;
    for (int i = 0; i < q; i++) {
        std::cin >> s >> t;
        if (link[s] == link[t] && link[s] != -1) {
            std::cout << "yes" << std::endl;
        } else {
            std::cout << "no" << std::endl;
        }
    }
}



Measured memory_bytes: 5488
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>;
using namespace std;
char s[100010];
int main()
{
    cin>>s;
    int k=strlen(s);
    if(k%2!=0) return printf("No"),0;
    for(int i=0;i<k/2;i++)
	{
        int u=abs(s[i]-s[k-i-1]);
        if(u!=1&&u!=2) return printf("No"),0;
    }
    printf("Yes");
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <sstream>
using namespace std;

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

    int res = 1000;

    for (int i = 0; i < s.size() - 2; i++) {
        stringstream ss;
        string str;
        str = s.substr(i, 3);
        int num;
        ss << str;
        ss >> num;
        int dif;
        dif = abs(753 - num);
        res = min(res, dif);
    }

    cout << res << endl;
}

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


def solve(N: int, X: int, T: int):
    i = 1
    A = 0
    while(True):
        A = N - X*i

        if A <= 0:
            break

        i+=1

    return print(i*T)


# 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
    X = int(next(tokens))  # type: int
    T = int(next(tokens))  # type: int
    solve(N, X, T)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9204
#include <stdio.h>

int main(void)
{
	int x, y, z;
	
	scanf("%d %d", &x, &y);
	
	z = x % y;
	
	while (z != 0){
		x = y;
		y = z;
		z = x % y;
	}
	
	printf("%d\n", y);
	
	return (0);
}

Measured memory_bytes: 592
import numpy as np

num = int(input())
value_list = np.array(list(map(int, input().split())))
cost_list = np.array(list(map(int, input().split())))

diff = value_list - cost_list

max_value = 0

for d in diff:
    if d > 0:
        max_value += d

print(max_value)

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

using namespace std;

const int INF = 1e9+10;

int main(){

	int n,k;

	cin >> n >> k;

	vector<int> v(n),dp(n,INF);

	for(int &x:v) cin >> x;

	dp[0] = 0;

	for(int i=0;i<n;++i){
		for(int j=i+1;j<=i+k;++j){
			if(j<n) dp[j] = min(dp[j],dp[i] + abs(v[i]-v[j]));
		}
	}


	cout << dp[n-1] << '\n';

	return 0;
}

Measured memory_bytes: 1024
n = int(input())
a = list(map(int,input().split()))
from collections import deque
ans = deque([a[0]])
odd = True
if n%2 == 0:
    for i in range(1,n):
        if odd:
            ans.appendleft(a[i])
            odd = False
        else:
            ans.append(a[i])
            odd = True
else:
    for i in range(1,n):
        if odd:
            ans.append(a[i])
            odd = False
        else:
            ans.appendleft(a[i])
            odd = True
ans = list(ans)
for i in range(n):
    print(ans[i],end = ' ')

Measured memory_bytes: 100308
def up(n)
  (10**(n+1) - 10**n) * (n+1) + count_fiz(n, n, 0, 1, 10)
end
def count_fiz(k, n, tmp, s, t)
  top = 10**k*t+tmp-1
  btm = 10**k*s+tmp-1
  a =top/3 -  btm/3 
  b =top/5 -  btm/5
  c =top/15 - btm/15
  (a + b - c) * (3-n) + c * 4
end
def down(n, mod)
  ret = 10**n
  k = n
  while k >= 0
    9.times do
      t = 10**k*(n+1) + count_fiz(k, n, ret, 0, 1)
      if mod < t
        k -= 1
        break
      end
      ret += 10**k
      mod -= t
    end
  end
  [ret,mod]
end
num = gets.to_i - 1
n = 0
while (tmp = up(n)) < num
  n += 1
  num -= tmp
end
p, q = down(n, num)
puts (p..p+20).map{|x|a=[[:Fizz][x%3],[:Buzz][x%5]]*'';a==''?x.to_s: a}.join('')[q,20]

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

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define FILE "file"

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int INF = numeric_limits<int>::max();
const ll LLINF = numeric_limits<ll>::max();
const ull ULLINF = numeric_limits<ull>::max();
const double PI = acos(-1.0);

int d[110][110];

int main()
{
//    freopen(FILE".in", "r", stdin);
//    freopen(FILE".out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            d[i][j] = INF;
    for(int i = 0; i < n; i++)
        d[i][i] = 0;
    vector<pair<pair<int, int>, int>> edges;
    for(int i = 0; i < m; i++)
    {
        int a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        d[a][b] = c;
        d[b][a] = c;
        edges.pb(mp(mp(a, b), c));
    }
    for(int k = 0; k < n; k++)
        for(int i = 0; i < n; i++)
            for(int j = 0; j < n; j++)
                if(d[i][k] < INF && d[k][j] < INF)
                    d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    int ans = 0;
    for(auto ed: edges)
    {
        int a = ed.first.first, b = ed.first.second, c = ed.second;
        bool good = 0;
        for(int i = 0; i < n; i++)
        {
            for(int j = 0; j < n; j++)
            {
                if(i == j)
                    continue;
                if(d[i][a] + d[b][j] + c == d[i][j])
                    good = 1;
                if(d[i][b] + d[a][j] + c == d[i][j])
                    good = 1;
            }
        }
        if(!good)
            ans++;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h> 
using namespace std;
int main(void){
    // Your code here!
   int N;
   cin >> N;
   vector<int> vec(2 * N);
   for(int i = 0; i < 2 * N; i++)cin >> vec.at(i);
   sort(vec.begin(),vec.end());
   int count = 0;
   for(int i = 0; i < N; i++) count += vec.at(2 * i);
   cout << count << endl;
}



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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<ll> Vector;
typedef vector<Vector> DVector;

#define fi          first
#define se          second
#define pb          push_back
#define INF         INT_MAX
#define bcnt        __builtin_popcount
#define all(x)      (x).begin(),(x).end()
#define dbg(x)      cout<<#x"="<<x<<endl
#define uni(x)      x.erase(unique(all(x)),x.end())
#define ub(x,y)     upper_bound(all(x),y)-x.begin()
#define lb(x,y)     lower_bound(all(x),y)-x.begin()
#define rep(i,n)    repl(i,0,n-1)
#define usort(x)    sort(all(x))
#define dsort(x)    sort(all(x),greater<ll>())
#define mkp(x,y)    make_pair(x,y)
#define mmax(x,y)   (x>y?x:y)
#define mmin(x,y)   (x<y?x:y)
#define maxch(x,y)  x=mmax(x,y)
#define minch(x,y)  x=mmin(x,y)
#define exist(x,y)  (find(all(x),y)!=x.end())
#define each(itr,v) for(auto itr:v)
#define repl(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);i++)
DVector mp(2000,Vector(2000,0));

ll calc(ll x1, ll y1, ll x2, ll y2){
  if(x1 > x2 || y1 > y2)return 0;
  ll ret = mp[x2][y2];
  if(x1 > 0)ret -= mp[x1 - 1][y2];
  if(y1 > 0)ret -= mp[x2][y1 - 1];
  if(x1 > 0 && y1 > 0)ret += mp[x1 - 1][y1 - 1];
  return ret;
}

int main(){
  cin.sync_with_stdio(false);
  ll n,k;
  cin >> n >> k;
  rep(i,n){
    ll tx, ty;
    string c;
    cin >> tx >> ty >> c;
    if(c == "W")ty += k;
    ll x = tx % (2 * k);
    ll y = ty % (2 * k);
    mp[x][y]++;
  }

  rep(i, 2 * k)rep(j, 2 * k)if(j > 0)mp[i][j] += mp[i][j - 1];
  rep(i, 2 * k)rep(j, 2 * k)if(i > 0)mp[i][j] += mp[i - 1][j];

  ll ans = 0;
  repl(i,0,k)repl(j,0,k){
    ll tmp = calc(0, 0, i - 1, j - 1) + calc(i + k, 0, 2 * k - 1, j - 1) + calc(i, j, i + k - 1, j + k - 1) + calc(0, j + k, i - 1, 2 * k - 1) + calc(i + k, j + k, 2 * k - 1, 2 * k - 1);
    ans = mmax(ans, mmax(tmp, n - tmp));
  }
  cout << ans << endl;
}


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

int main(void){
    long long n, m;
    
    cin >> n >> m;
    
    long long p[m], s_l[m], count_wa[n+1], count_wa_sum = 0, count_ac = 0;
    string s;
    
    for(int i = 0; i < m; i++){
        cin >> p[i] >> s;
        if(s[0] == 'A'){
            s_l[i] = 0;
        } else {
            s_l[i] = 1;
        }
    }
    
    long long c[n+1];
    
    for(int i = 1; i <= n; i++){
        c[i] = 0;
		count_wa[i] = 0;
    }
    
    for(int i = 0; i < m; i++){
        if(s_l[i] == 1 && c[p[i]] == 0){
            count_wa[p[i]]++;
        }
        if(s_l[i] == 0 && c[p[i]] == 0){
            c[p[i]] = 1;
            count_ac++;
        }
    }
  
  	for(int i = 1; i <= n; i++){
     if(c[i] == 1){
     	count_wa_sum += count_wa[i];
     }
    }
    
    cout << count_ac << " " << count_wa_sum << endl;
    
    return 0;
}


Measured memory_bytes: 3328
from sys import stdin

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

sa,sb,sc = [list(S()) for i in range(3)]

f = sa.pop(0)
l = {'a':sa, 'b':sb, 'c':sc}
p = {'a':'A', 'b':'B', 'c':'C'}
while True:
    if 0 < len(l.get(f)):
        f = l.get(f).pop(0)
    else:
        break

print(p.get(f))

Measured memory_bytes: 3064
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		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();
			}
		}
		sc.close();

		String space = " ";
		List<String> ans = new ArrayList<String>(h * w);
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w - 1; j++) {
				if (a[i][j] % 2 == 1) {
					a[i][j]--;
					a[i][j + 1]++;
					StringBuilder sb = new StringBuilder();
					sb.append(i + 1).append(space).append(j + 1).append(space)
						.append(i + 1).append(space).append(j + 2);
					ans.add(sb.toString());
				}
			}
		}
		for (int i = 0; i < h - 1; i++) {
			if (a[i][w - 1] % 2 == 1) {
				a[i][w - 1]--;
				a[i + 1][w - 1]++;
				StringBuilder sb = new StringBuilder();
				sb.append(i + 1).append(space).append(w).append(space)
					.append(i + 2).append(space).append(w);
				ans.add(sb.toString());
			}
		}
		System.out.println(ans.size());
		for (String s : ans) {
			System.out.println(s);
		}
	}
}


Measured memory_bytes: 100900
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).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;}

int main(){
    int n;cin>>n;
    vector<int> a(n+1);
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    int ans = 0;
    for(int i=1;i<=n;i++){
        int t=a[i];
        if(a[t]==i) ans++;
    }
    cout<<ans/2<<endl;
}

Measured memory_bytes: 640
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        System.out.println(solve(s, t));
    }

    static String solve(String s, String t) {
        Map<Character, Integer> smap = new HashMap<>();
        Map<Character, Integer> tmap = new HashMap<>();
        for (int i = 0; i < 26; i++) {
            smap.put((char) ('a' + i), 0);
            tmap.put((char) ('a' + i), 0);
        }

        // 文字をアルファベット毎に何個あるかを保持って比較する
        for (int i = 0; i < s.length(); i++) {
            char sc = s.charAt(i);
            char tc = t.charAt(i);
            smap.put(sc, smap.get(sc) + 1);
            tmap.put(tc, tmap.get(tc) + 1);
        }

        List<Integer> stype = new ArrayList<>();
        List<Integer> ttype = new ArrayList<>();
        for (int i = 0; i < 26; i++) {
            int snum = smap.get((char) ('a' + i));
            int tnum = tmap.get((char) ('a' + i));

            if (snum != 0) {
                stype.add(snum);
            }
            if (tnum != 0) {
                ttype.add(tnum);
            }
        }
        Collections.sort(stype);
        Collections.sort(ttype);

        return stype.equals(ttype) ? "Yes" : "No";
    }
}



Measured memory_bytes: 33324
#include<bits/stdc++.h>
//using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i,j,n) for(ll i=(ll)(j);i<(ll)(n);i++)
#define REP(i,j,n) for(ll i=(ll)(j);i<=(ll)(n);i++)
#define per(i,j,n) for(ll i=(ll)(j);(ll)(n)<=i;i--)
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(ll)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(ll)(key)))
#define pb emplace_back
#define mp std::make_pair
//
#define endl "\n"
//using std::endl;
using std::cin;
using std::cout;
using std::vector;
using std::string;
using std::upper_bound;
using std::lower_bound;
using vi=vector<ll>;
using vii=vector<vi>;
using pii=std::pair<ll,ll>;
//
constexpr ll MOD=1e9+7;
//constexpr ll MOD=998244353;
//constexpr ll MOD=10000000;
//constexpr ll MOD=1e5;
constexpr ll MAX=1e7;
constexpr ll INF=(1ll<<62);
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
const ll N=26;
ll solve(ll D,vii &A,vi &C,vi &S){
    vi last(N,-1);
    ll a=0;
    rep(i,0,D){
        ll memo; memo=S[i];
        last[memo]=i;
        a+=A[i][memo];
        rep(j,0,N) a-=(i-last[j])*C[j];
    }
    return a;
}
int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    srand((unsigned)time(NULL));
    ll D; cin>>D;
    vi C(N);
    rep(i,0,N) cin>>C[i];
    vii A(D,vi(N));
    rep(i,0,D){
        rep(j,0,N) cin>>A[i][j];
    }
    vi last(N,-1);
    vi ans(D);
    rep(i,0,D){
        ll max=0,memo=0;
        rep(j,0,N){
            if(max<A[i][j]+(i-last[j])*C[j]){
                max=A[i][j]+(i-last[j])*C[j];
                memo=j;
            }
        }
        last[memo]=i;
        ans[i]=memo;
    }
    ll max=solve(D,A,C,ans);
    rep(_,0,40){
    rep(i,0,D){
        rep(j,0,N){
            vi S=ans;
            S[i]=j;
            ll X=solve(D,A,C,S);
            if(max<X){
                max=X;
                ans=S;
            }
        }
    }
    }
    rep(i,0,D) cout<<ans[i]+1<<endl;
}


Measured memory_bytes: 3696
#include<bits/stdc++.h>
using namespace std;
struct edge {int u, v, w;};
vector<edge>G;
inline void add(int u, int v, int w) {
  G.push_back((edge) {u , v , w});
}
int main() {
  int L, t;
  cin >> L;
  for (int i = 0; i < 21; ++i) if (L & (1 << i)) t = i;
  for (int i = 1; i <= t - 1; i++) add(i, i+1, 1 << i-1), add(i, i+1, 0);
  add(t, 20, 0);
  add(t, 20, 1 << t-1);
  int g = 1 << t;
  while (g < L) {
    // cout << bitset<5>(L - g) << ' ';
    for(int i = 0; i < 21; ++i) if ((1 << i) & (L - g)) t = i; 
    add(t+1, 20, g);
    // cout << g << ' ' << bitset<5>(g) << endl;
    g |= 1 << t;
  }
  cout << "20 " << G.size() << endl;
  for (auto it = G.begin(); it != G.end(); ++it) cout << it->u << ' ' << it->v << ' ' << it->w << endl;
  return 0;
}

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

#define MAX 200000
#define MOD 1000000007

long long modpow(long long a,long long n,long long mod){
  long long res=1;
  while(n>0){
    if(n&1){       //nのbitと...00001を比較  nが2で割り切れるならtrue
      res=(res*a)%mod;
    }
    a=(a*a)%mod;
    n>>=1;
  }
  return res;
}

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

long long fac[MAX],finv[MAX],inv[MAX];

void COMinit(){
  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;
  }
}

long long COM(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;
}

Graph G;
ll K;

int solve(int v,int p){
  int n=G.at(v).size();
  if(K-1<n){
    return 0;
  }
  ll ans=fac[K-2]*finv[K-2-n+1]%MOD;
  if(v==0){
    ans=fac[K]*finv[K-n-1]%MOD;
  }
  for(auto nv:G.at(v)){
    if(nv==p){
      continue;
    }
    ans*=solve(nv,v);
    ans%=MOD;
  }
  return ans;
}

int main(){
  int N;
  cin>>N>>K;
  G.resize(N);
  for(int i=0;i<N-1;i++){
    int a,b;
    cin>>a>>b;
    a--,b--;
    G.at(a).push_back(b);
    G.at(b).push_back(a);
  }
  COMinit();

  cout<<solve(0,-1)<<endl;
}


Measured memory_bytes: 15104
s = int(input())
a = [s]
tmp = s
ans = 1
while True:
    ans += 1
    if tmp % 2 == 0:
        num = int(tmp/2)
    else:
        num = 3*tmp+1
    if num in a:
        break
    a.append(num)
    tmp = num
print(ans)

Measured memory_bytes: 3060
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }

void main()
{
	auto K = RD;
	auto A = RD;
	auto B = RD;

	bool ans;
	foreach (i; A..B+1)
	{
		if (i % K == 0)
		{
			ans = true;
		}
	}

	writeln(ans ? "OK" : "NG");
	stdout.flush;
	debug readln;
}


Measured memory_bytes: 2752
n, m = map(int, input().split())
wa = [0 for i in range(100005)]
ac = [False for i in range(100005)]
for sa in range(m):
    p, v = input().split()
    p = int(p)
    if v == "WA":
        if ac[p] == False:
            wa[p] += 1
    else:
        ac[p] = True
w = 0
c = 0
for i in range(n+5):
    if ac[i]:
        w += wa[i]
        c += 1
print(c, w)

Measured memory_bytes: 4784
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define F first
#define S second
#define vll vector<ll>
#define fast ios:: sync_with_stdio(false),cin.tie(0);
#define COUT cout<<fixed<<setprecision(12)
#define SET set<ll,greater<ll>>gquiz
#define ITERATOR set<ll,greater<ll>> :: iterator itr
#define V vector<ll>vector
#define sz size()
//#define A vector<pair<ll,ll>>vect
ll N=100000,M=100000;
#define B vect.push_back(make_pair(N,M));
ll MOD=1000000007;
 
bool isprime(ll n){if(n==1 || (n!=2 && n%2==0))return false; if(n==2)return true; 
		for(ll i=3;i<=sqrt(n);i+=2)if(n%i==0)return false; return true; }
ll gcd(ll a,ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 

void solve()
{
	ll a[5];
	for(ll i=0;i<5;i++)
	{
		cin>>a[i];
	/*	if(a[i]==0)
		{
			cout<<i+1;
			return;
		}*/
	}
	//cout<<"4";
	
	for(ll i=0;i<5;i++)
	{
		if(a[i]==0)
		{
			cout<<i+1;
			return;
		}
	}
	
}
int main()
{
	fast;
	ll t=1;
//	cin>>t;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 3540
#include <bits/stdc++.h>
using namespace std;
const int N=11,M=1e3+5;
int b[N][M],c[N][M];
int n,m,k,x,ms,l,r,mid,ans;

inline bool jay(int p,int mid)
{
	memset(c,0,sizeof(c));
	int tot=1;
	for (register int j=1; j<=m; ++j) c[tot][j]=b[1][j]; 
	
	
	
	for (register int i=2; i<=n; ++i)
	{
		if (p&(1<<(i-1))) tot++;
		for (register int j=1; j<=m; ++j) c[tot][j]+=b[i][j];
	}
	
	int res=mid-tot+1;
	if (res<0) return false;
	
	int l=0;
	for (register int r=1; r<=m; ++r)
	for (register int i=1; i<=tot; ++i)
	{
		if (c[i][r]-c[i][r-1]>k) return false;
		if (c[i][r]-c[i][l]>k) res--,l=r-1;
		if (res<0) return false;
	}
	return true;
}

int main(){
	scanf("%d%d%d",&n,&m,&k);
	for (register int i=1; i<=n; ++i)
	for (register int j=1; j<=m; ++j) 
	{
		scanf("%1d",&x);
		b[i][j]=b[i][j-1]+x;
	}
	
	int ms=1<<n;
	l=0; r=n+m-2;
	while (l<=r)
	{
		bool f=false;
		mid=l+r>>1;
		for (register int p=0; p<ms; ++p) if (jay(p,mid)) {f=true; break;}
		if (f) ans=mid,r=mid-1; else l=mid+1;
	}
	printf("%d\n",ans);
return 0;	
}


Measured memory_bytes: 384
# -*- coding: utf-8 -*-
# dwacon6th-prelims/dwacon6th_prelims_b
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

MAX = 10**5 + 100
MOD = 10**9 + 7

fac = [1, 1] + [0] * MAX
finv = [1, 1] + [0] * MAX
inv = [1, 1] + [0] * MAX
coef = [1, 1] + [0] * MAX

for i in range(2, MAX):
    fac[i] = fac[i - 1] * i % MOD
    inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
    finv[i] = finv[i - 1] * inv[i] % MOD
    coef[i] = coef[i - 1] * i % MOD + fac[i - 1] % MOD

def main():
    N = i2n()
    n = N - 1
    x = i2nn()
    total = 0
    for i in range(1, N):
        d = x[i] - x[i - 1]
        total = total + (coef[i] * fac[n] % MOD * finv[i] % MOD * d % MOD) % MOD
    print(total % MOD)
    return

main()


Measured memory_bytes: 32432
// #pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define N 1000000007
#define N2 998244353
#define Nmax 100005
#define INF (ll)1e18
#define pll pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
#define vv vector
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(ll i=m;i<(n);i++)
#define repr(i,n) repr2(i,n,0)
#define repr2(i,m,n) for(ll i=m;i>=(n);i--)
#define get(n) ll (n); scanf("%lld",&(n));
#define get2(n,k) ll (n),(k); scanf("%lld%lld",&(n),&(k));
#define get3(n,m,k) ll (n),(m),(k); scanf("%lld%lld%lld",&(n),&(m),&(k));
#define gets(s) string (s); cin >> (s);
#define ALL(c) (c).begin(),(c).end()
#define fill_nums(A,n) vector<ll> A((n)); for(ll i=0;i<n;i++) scanf("%lld",&A[i]);
#define fill_edges(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1); adj[b-1].pb(a-1);}
#define fill_direct(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1);}
#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); //cout.tie(0);
#define pi 3.1415926535897L
#define db long double  /* print with %Lf */
#define EPS 1e-9
#define flu fflush(stdout)
#define imp {cout<<"No\n"; return 0;}
#define yup {cout<<"Yes\n"; return 0;}
#define debug_vec(vec,n) {rep(idxi,n) cout<<vec[idxi]<<" "; cout<<"\n";}
#define debug_pvec(vec,n) {rep(idxi,n) cout<<vec[idxi].fi<<"-"<<vec[idxi].se<<"  "; cout<<"\n";}
#define debug_set(seta) {cout<<seta.size()<<"\n"; for(auto idxi:seta) cout<<idxi<<" "; cout<<"\n";}
#define debug_map(mappa) {cout<<mappa.size()<<"\n";for(auto idxi:mappa) cout<<idxi.fi<<"-"<<idxi.se<<"  "; cout<<"\n";}
#define debug_vecvec(vec,n) {rep(idxi,n) {for(auto idxi2:vec[idxi]) cout<<idxi2<<" "; cout<<"\n";}}
 
// LOOK AT THESE BEFORE SUBMISSION
// LOOK AT THESE BEFORE SUBMISSION
// ============================================================
// Nmax value and is index access offset taking it beyond Nmax.
// Precision error in case of real numbers.
// N vs N2 chosen correctly.
// Modulo applied everywhere.
// Flush in case of interactive.
// Don't erase value in multiset.
// Check for array indices out of bound (in pre or suff sums).
// Correct return value for functions.
// Confirm the letter case of yes and no.
// Dont paste code two times in the text file.
// ============================================================

bool ispalin(string a) {
    string t = a; reverse(ALL(t));
    return t==a;
}
int main() {


    gets(s);

    ll n = s.length();
    string t1 = s.substr(0,(n-1)/2);
    string t2 = s.substr((n+1)/2,(n-1)/2);
    bool f = ispalin(s) && ispalin(t1) && ispalin(t2);
    if(f) printf("Yes\n");
    else printf("No\n");

    return 0;  
}   


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define bits_count __builtin_popcountll
#define endl '\n'
#define ld long double
#define FOR(i,a,n) for (ll i=(a);i<(n);++i)
#define RFOR(i,a,n) for (ll i=(n);i>=(a);--i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define MINUS(a) memset((a),-1,sizeof((a)))
#define fi first
#define se second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
#define sz(x) (ll)x.size()
#define pr pair<int,int>

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int a;
    cin>>a;
    cout<<a*(1+ a + a*a)<<endl;
	
}

Measured memory_bytes: 3456
x_1, y_1, x_2, y_2 = map(int, input().split())

vec_x = -(y_2 - y_1)
vec_y = x_2 - x_1

x_3, y_3 = x_2 + vec_x, y_2 + vec_y
x_4, y_4 = x_1 + vec_x, y_1 + vec_y

print(x_3, y_3, x_4, y_4)


Measured memory_bytes: 2940
L, R = map(int, input().split())

if L // 2019 < R // 2019 or L % 2019 == 0:
    ans = 0
else:
    l = L % 2019
    r = R % 2019
    ans = 2019
    for i in range(l, r):
        for j in range(i + 1, r + 1):
            ans = min(ans, (i * j) % 2019)
print(ans)


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

#define ll long long
#define llu unsigned long long
#define ld long double
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define vi vector < int >
#define vll vector < ll >
#define pb push_back
#define pf push_front
#define iter :: iterator
#define pii pair < int , int >
#define pll pair < ll, ll >
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'
#define all(x) x.begin(),x.end()
#define foreach(it,v) for( __typeof((v).begin())it = (v).begin() ; it != (v).end() ; it++ )
#define present(v,x) (v).find(x) != (v).end()
#define cpresent(v,x) (find(all(v),x) != (v).end())
#define mset(x,v) memset(x, v, sizeof(x))
#define sz(x) (int)x.size()
#define shout()  {cout << "I'm Here...!!!" << endl;}
#define dbg(x) { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }

inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int addmod(int a, int val, int p = MOD) {{if ((a = (a + val)) >= p) a -= p;} return a;}
inline int submod(int a, int val, int p = MOD) {{if ((a = (a - val)) < 0) a += p;}return a;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}

#define INFLL 0x3f3f3f3f3f3f3f3fLL

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

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

	ll dp[n+1][n+1];

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

	vector<ll> pref(n+1);
	partial_sum(all(a), pref.begin());

	for(int l=2; l<=n; l++)
		for(int i=1; i<=n-l+1; i++){
			int j = i+l-1;
			dp[i][j] = INFLL;
			for(int k=i; k<j; k++)
				dp[i][j] = min(dp[i][k]+dp[k+1][j]+pref[j]-pref[i-1], dp[i][j]);
		}

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

	return 0;
}

Measured memory_bytes: 1536