akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>

namespace fuck
{
	typedef long long ll;
	template<typename T>inline void check_max(T a,T &b){if(a>b)b=a;}
	const int N=101000;
	struct node{int x,y,z;}s[N];
	bool operator < (node P,node Q){return P.z-P.y<Q.z-Q.y;}
	int n,A,B,C;
	void initialize()
	{
		scanf("%d%d%d",&A,&B,&C),n=A+B+C;
		for(int i=1;i<=n;i++)
			scanf("%d%d%d",&s[i].x,&s[i].y,&s[i].z);
		std::sort(s+1,s+n+1);
	}
	std::priority_queue<int,std::vector<int>,std::greater<int> >Q;
	ll f[N],g[N];
	void work()
	{
		while(!Q.empty())Q.pop();
		for(int i=1;i<=B;i++)
		{
			Q.push(s[i].y-s[i].x);
			f[B]+=s[i].y;
		}
		for(int i=B+1;i<=n-C;i++)
		{
			f[i]=f[i-1]+s[i].x;
			int x=s[i].y-s[i].x;
			if(x>Q.top())
			{
				f[i]+=x-Q.top();
				Q.pop();
				Q.push(x);
			}
		}

		while(!Q.empty())Q.pop();
		for(int i=n;i>=n-C+1;i--)
		{
			Q.push(s[i].z-s[i].x);
			g[n-C+1]+=s[i].z;
		}
		for(int i=n-C;i>=B;i--)
		{
			g[i]=g[i+1]+s[i].x;
			int x=s[i].z-s[i].x;
			if(x>Q.top())
			{
				g[i]+=x-Q.top();
				Q.pop();
				Q.push(x);
			}
		}
	}
	void solve()
	{
		initialize();
		work();
		ll ans=0;
		for(int i=B;i<=n-C;i++)
			check_max(f[i]+g[i+1],ans);
		printf("%lld\n",ans);
	}
}
int main()
{
//	freopen("b.in","r",stdin);
//	freopen("b.out","w",stdout);
	fuck::solve();
	return 0;
}


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

int main() {
  string s, t;
  cin >> s >> t;
  int l = s.size();
  for (int i = 0; i < l; i++) {
    bool match = true;
    for (int j = 0; j < l; j++) {
      if (s.at((j + i) % l) != t.at(j)) {
        match = false;
        break;
      }
    }
    if (match) {
      puts("Yes");
      return 0;
    }
  }
  puts("No");
}


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

void bubbleSort(int A[], int n) {
  int flag = -1;
  int num = 0;
  while (flag) {
    flag = 0;
    for (int j = n - 1; j > 0; j--) {
      if (A[j] < A[j - 1]) {
        swap(A[j], A[j - 1]);
        num++;
        flag = 1;
      }
    }
  }

  for (int i = 0; i < n; i++) {
    cout << A[i];
    if (i == n - 1) {
      cout << endl;
    } else {
      cout << " ";
    }
  }
  cout << num << endl;
}

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

  bubbleSort(R, count);
  return 0;
}


Measured memory_bytes: 3096
n, k = map(int,input().split())
hl = list(map(int,input().split()))

dp = [[] for _ in range(n)]
dp[0] = 0

for i in range(1,n):
    tmp = float('inf')
    for j in range(1,k+1):
        if i-j < 0:
            continue
        tmp = min(dp[i-j] + abs(hl[i]-hl[i-j]),tmp)
    dp[i] = tmp
print(dp[-1])

Measured memory_bytes: 94164
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr int mod  = 1e9+7;

int main(){
  int n;
  cin >> n;
  ll res = 1;
  vector<int> a(n), c(3,0);
  rep(i,n) cin >> a[i];
  
  for (int i = 0; i < n; i++) {
    ll cnt = 0, id = -1;
    if (a[i] == c[0]) {cnt++; id = 0;}
    if (a[i] == c[1]) {cnt++; id = 1;}
    if (a[i] == c[2]) {cnt++; id = 2;}
    if (id == -1) res *= 0;
    else {
    (res *= cnt) %= mod;
    c[id]++;
    }
  }
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define FI first
#define SE second
#define PB push_back
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define co(i) cout<<(i)<<endl
#define fcout cout<<fixed<<setprecision(10)
#define uni(i) i.erase(unique(i.begin(), i.end()), i.end());
#define all(i) i.begin(),i.end()
#define pint pair<int, int>
#define vint vector<int>
using namespace std;

const int INF=1e9+7;
const ll LINF=1e18;
const int MOD=1e9+7;
//const int MOD=998244353;

int par[2000],rnk[2000];
void init(int n){
	FOR(i,0,n){
		par[i]=i;
		rnk[i]=0;
	}
}
int find(int x){
	if(par[x]==x) return x;
	else return par[x]=find(par[x]);
}
void unite(int x,int y){
	x=find(x); y=find(y);
	if(x==y) return;
	if(rnk[x]<rnk[y]){
		par[x]=y;
	}else{
		par[y]=x;
		if(rnk[x]==rnk[y]) rnk[x]++;
	}
}
bool same(int x,int y){
	return find(x)==find(y);
}

int g[700][700];
int n,m;
int dp[1000][800];
int used[2000],size[2000];
int main(){
	cin>>n>>m;
	FOR(i,0,m){
		int a,b; cin>>a>>b; a--; b--;
		g[a][b]=g[b][a]=1;
	}
	init(2*n+1);
	FOR(i,0,n){
		FOR(j,i+1,n){
			if(g[i][j]) continue;
			unite(i,n+j);
			unite(n+i,j);
		}
	}
	FOR(i,0,n){
		if(same(i,n+i)){
			co(-1);
			return 0;
		}
	}
	dp[0][0]=1;
	FOR(i,0,n){
		size[find(i)]++;
	}
	int t=0;
	FOR(i,0,n){
		int p=find(i),q=find(n+i);
		if(used[p]) continue;
		used[p]=1; used[q]=1;
		int sp=size[p],sq=size[q];
		ROF(j,0,1000){
			if(j-sp>=0) if(dp[j-sp][t]) dp[j][t+1]=1;
			if(j-sq>=0) if(dp[j-sq][t]) dp[j][t+1]=1;
		}
		t++;
	}
	int z;
	ROF(i,0,n/2+1){
		if(dp[i][t]){
			z=i;
			break;
		}
	}
	int ans=n*(n-1)/2-z*(n-z);
	/**
	FOR(i,0,n) cout<<size[i]<<" \n"[i==n-1];
	FOR(i,0,n) cout<<used[i]<<" \n"[i==n-1];
	FOR(i,0,n) cout<<dp[i]<<" \n"[i==n-1];
	**/
	co(ans);
}


Measured memory_bytes: 5248
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#N = int(input())
A = int(input())
B = int(input())
C = int(input())
X = int(input())

cnt = 0
for i in range(A+1) :
  for j in range(B+1) :
    for k in range(C+1) :
      if 500*i + 100*j + 50*k == X :
        cnt += 1
print (cnt)
  
  




Measured memory_bytes: 39664
import java.util.*;

public class Main {// Main
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
      long a =sc.nextLong();
      long b =sc.nextLong();
      long c =sc.nextLong();
      long k =sc.nextLong();
     
      
       if(k <= a+b ) {
    	   System.out.println(Math.min(a, k));
       }else {
    	   System.out.println(a - (k-a-b));
       }
	}
}

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

int main() {
  int N;
  cin >> N;
  priority_queue<int> q;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    q.push(x);
  }
  int alice = 0;
  int bob =0;
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) {
      alice += q.top();
      q.pop();
    }
    else {
      bob += q.top();
      q.pop();
    }
  }
  cout << alice - bob << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>

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

int R, S, P;

int win ( int a, char b )
{
	//0 == Rock, 1 == Paper, 2 == Scissors
	if ( a == 0 && b == 's' )
		return R;
	if ( a == 1 && b == 'r' )
		return P;
	if ( a == 2 && b == 'p' )
		return S;
	return 0;
}

int main ()
{
	ios_base::sync_with_stdio ( 0 ); cin.tie ( 0 );
	int N, K;
	string moves;
	cin >> N >> K;
	cin >> R >> S >> P;
	cin >> moves;
	vector<vi> DP ( N + 5, vi ( 3, 0 ) );
	for ( int i = N - 1; i >= 0; i-- )
	{
		if ( i + K < N )
		{
			DP[i][0] = max ( DP[i + K][1] + win ( 1, moves[i] ), DP[i + K][2] + win ( 2, moves[i] ) );
			DP[i][1] = max ( DP[i + K][0] + win ( 0, moves[i] ), DP[i + K][2] + win ( 2, moves[i] ) );
			DP[i][2] = max ( DP[i + K][0] + win ( 0, moves[i] ), DP[i + K][1] + win ( 1, moves[i] ) );
		}
		else
		{
			DP[i][0] = max ( win ( 1, moves[i] ), win ( 2, moves[i] ) );
			DP[i][1] = max ( win ( 0, moves[i] ), win ( 2, moves[i] ) );
			DP[i][2] = max ( win ( 0, moves[i] ), win ( 1, moves[i] ) );
		}
	}
	int ans = 0;
	for ( int i = 0; i < K; i++ )
		ans += max ( DP[i][0], max ( DP[i][1], DP[i][2] ) );
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 5840
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

vector<ll> S, T;
ll x[100010];

int main()
{
	int A, B, Q;
	cin >> A >> B >> Q;
	S.push_back(-INF);
	T.push_back(-INF);
	for (int i = 0; i < A; i++) {
		ll s; cin >> s;
		S.push_back(s);
	}
	for (int i = 0; i < B; i++) {
		ll t; cin >> t;
		T.push_back(t);
	}
	S.push_back(INF);
	T.push_back(INF);
	for (int i = 0; i < Q; i++) {
		ll ans = INF;
		ll x; cin >> x;
		auto itr1 = lower_bound(S.begin(), S.end(), x);
		auto itr2 = lower_bound(T.begin(), T.end(), x);
		for (int j = 0; j < 2; j++) {
			ll x1 = *(itr1 - j);
			for (int k = 0; k < 2; k++) {
				ll x2 = *(itr2 - k);
				ans = min(ans, abs(abs(x - x1) + abs(x1 - x2)));
				ans = min(ans, abs(abs(x - x2) + abs(x2 - x1)));
				//cout << x << " " << x1 << " " << x2 << endl;
			}
		}
		//cout << i<<" "<<Q<<" ";
		cout << ans << endl;
	}

}

Measured memory_bytes: 3060
#include<iostream>
#include<map>
using namespace std;
int main(){
  map<string,int> word;
  string s,as,bs;
  int an = 0;
  while(cin >>s){
    word[s]++;
    if(word[s]>an){
      an = word[s];
      as = s;
    }
    if(s.size()>bs.size()) bs = s;
  }
  cout <<as<<" "<<bs<<endl;
  return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pi 3.1415926536
#define pb push_back
#define N 1000000007
#define M 998244353
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define nrep(i,a,b) for(int i=a;i>=b;i--)
ll a[1000005];
ll arr[200005];
int main(){
    ll t,i,j,l,h,n,x,k,y;
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n;
    rep(i,1,n){
    	cin>>arr[i];
    	a[arr[i]]++;
	}
	ll count = n;
	rep(i,1,n){
	    x = arr[i];
	    a[x]--;
	    for( j = 1;j*j<= x;j++){
	    	if(x%j == 0){
	    		if( a[j] || a[x/j]){
	    			count--;
	    			break;
				}
			}
		}
		a[x]++;
	}
	cout<<count;
}

Measured memory_bytes: 12884
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String str,hit="HIT",hr="HOMERUN",out="OUT";

		for(int i=0; i<n; i++){
			boolean runner[] = new boolean[3];
			int score=0;
			int outCount=0;

			while((str=br.readLine()) != null){
				if(str.equals(out)){
					outCount++;
					if(outCount==3)
						break;
				}else if(str.equals(hit)){
					if(runner[2]){
						score++;
					}
					runner[2]=runner[1];
					runner[1]=runner[0];
					runner[0]=true;
				}else if(str.equals(hr)){
					score++;
					for(int j=0; j<runner.length; j++){
						if(runner[j]){
							score++;
						}
						runner[j]=false;
					}
				}
			}
			System.out.println(score);
		}
	}
}

Measured memory_bytes: 16868
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1000000000;

int main() {
    int N;
    cin >> N;
    vector<int>L(N);
    for (int i=0; i<N; i++)cin >> L[i];
    int cnt = 0;
    for (int i=0; i<N-2; i++){
        for (int j=i+1; j<N-1; j++){
            for (int k=j+1; k<N; k++){
                if (L[i] != L[j] and L[i] != L[k] and L[j] != L[k]){
                    int li, lj, lk;
                    li = L[i];
                    lj = L[j];
                    lk = L[k];

                    if (li < lj+lk and lj < li+lk and lk < li + lj){
                        cnt++;
                        //cout << i+1 << j+1 << k+1 << endl;
                    }
                }
            }
        }
    }
    cout << cnt << endl;

}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

ll a[500][500];
ll y_1[1000000] = {};
ll x_1[1000000] = {};
ll y_2[1000000] = {};
ll x_2[1000000] = {};

int main() {
	ll h, w; cin >> h >> w;
	rep(i, 0, h)rep(j, 0, w)cin >> a[i][j];

	ll cnt = 0;
	rep(i, 0, h) {
		rep(j, 0, w - 1) {
			if (a[i][j] & 1) {
				a[i][j]--;
				a[i][j + 1]++;
				y_1[cnt] = i;
				x_1[cnt] = j;
				y_2[cnt] = i;
				x_2[cnt] = j + 1;
				cnt++;
			}
		}
	}

	rep(i, 0, h - 1) {
		if (a[i][w - 1] & 1) {
			a[i][w - 1]--;
			a[i + 1][w - 1]++;
			y_1[cnt] = i;
			x_1[cnt] = w - 1;
			y_2[cnt] = i + 1;
			x_2[cnt] = w - 1;
			cnt++;
		}
	}
	cout << cnt << endl;
	rep(i, 0, cnt) {
		cout << y_1[i] + 1 << " " << x_1[i] + 1 << " " << y_2[i] + 1 << " " << x_2[i] + 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 15872
#include<iostream>
using namespace std;
 
int main()
{
	int year[20] = {};
	int i, j;
	for (i = 0; i < 15; i++)
		year[i] = 0;
	
	int gram, rate, die;
	cin >> rate >> die >> gram;
	for (j = 0; j < 10; j++){
		year[j] += rate*gram - die;
		cout << year[j] << endl;
		gram = year[j];
	}
	return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
s = input()
out_s='1'*(m)
if out_s in s:
    print(-1)
    exit()
s = s[::-1]
if s[0] == "1":
    print(-1)
    exit()
pre = [-1] * (n + 1)
stack = [0]
while stack:
    now = stack.pop()
    if now == n:
        break
    for i in range(1, m + 1):
        tsugi = now + i
        if tsugi > n:
            continue
        if s[tsugi] == "1":
            continue
        pre[tsugi] = now
        stack.append(tsugi)
else:
    print(-1)
    exit()
ato = n
mae = pre[n]
ans = []
while mae >= 0:
    ans.append(ato - mae)
    ato = mae
    mae = pre[ato]
print(*ans, sep=" ")


Measured memory_bytes: 50800
#include<iostream>
#include<vector>
#include<bitset>
#include<algorithm>

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;

ll dp[65][3];

int main() {
	ll N;
	cin >> N;
	vector<bool> trans;

	while (N > 0) {
		if (N & 1) { trans.insert(trans.begin(), 1); }
		else { trans.insert(trans.begin(), 0); }
		N >>= 1;
	}

	dp[0][0] = 1;
	for (int keta = 0; keta < trans.size(); keta++) {
		for (int j = 0; j < 3; j++) {
			dp[keta][j] %= MOD;
			if (trans[keta] == 0) {
				if(j * 2 - 2 >= 0)dp[keta + 1][min(2, j * 2 - 2)] += dp[keta][j];//(1, 1)
				if(j * 2 - 1 >= 0)dp[keta + 1][min(2, j * 2 - 1)] += dp[keta][j];//(1, 0)
				dp[keta + 1][min(2, 2 * j)] += dp[keta][j];//(0, 0)
			}
			else {
				dp[keta + 1][min(2, j * 2 + 1)] += dp[keta][j];//(1, 1)
				dp[keta + 1][min(2, j * 2)] += dp[keta][j];//(1, 0)
				if(j * 2 - 1 >= 0)dp[keta + 1][min(2, 2 * j - 1)] += dp[keta][j];//(0, 0)
			}
		}
	}

	cout << (dp[trans.size()][0] + dp[trans.size()][1] + dp[trans.size()][2]) % MOD << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0; i < n; i++)
#define repd(i, n) for (int i = n-1; i > -1; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;
using LP = pair<ll,ll>;
using P = pair<ll,int>;
ll inf = 1e18;

int di[4] = {-1, 0, 1, 0};
int dj[4] = {0, 1, 0, -1};
int main()
{
    int h, w;
    cin >> h >> w;
    vector<string> g(h);
    rep(i, h) cin >> g[i];
    rep(i, h) rep(j, w) {
        if (g[i][j] == '.') continue;
        bool flag = false;
        rep(k, 4){
        int ni = i+di[k];
        int nj = j+dj[k];
        if (ni < 0 or ni >= h or nj < 0 or nj >= w) continue;
        if (g[ni][nj] == '#') flag = true;
        }   
        if (not flag) {
            cout << "No" << endl;
            exit(0);
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 3580
//02-03-20202

#include<bits/stdc++.h>
using namespace std;
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);

    int a,b,c;
    cin>>a>>b>>c;

    if((a==b && a!=c) || (b==c && b!=a) || (c==a && c!=b))
        cout<<"Yes"<<"\n";
    else
        cout<<"No"<<"\n";

    return 0;   //:D

}


Measured memory_bytes: 256
s = input()
flag1 = False
flag2 = False
if s[0:2] == "01" or s[0:2] == "02" or s[0:2] == "03" or s[0:2] == "04" or s[0:2] == "05" or s[0:2] == "06" or s[0:2] == "07" or s[0:2] == "08" or s[0:2] == "09" or s[0:2] == "10" or s[0:2] == "11" or s[0:2] == "12":
    flag1 = True
if s[2:4] == "01" or s[2:4] == "02" or s[2:4] == "03" or s[2:4] == "04" or s[2:4] == "05" or s[2:4] == "06" or s[2:4] == "07" or s[2:4] == "08" or s[2:4] == "09" or s[2:4] == "10" or s[2:4] == "11" or s[2:4] == "12":
    flag2 = True
if flag1 and flag2:
    print("AMBIGUOUS")
elif flag1 and (not flag2):
    print("MMYY")
elif (not flag1) and flag2:
    print("YYMM")
elif (not flag1) and (not flag2):
    print("NA")

Measured memory_bytes: 3064
fun main(args: Array<String>) {
    val (A, B, K) = readLine()!!.split(" ").map(String::toInt)
    val list = mutableListOf<Int>()
    for (i in Math.min(A, B) downTo 1) {
        if (A % i == 0 && B % i == 0) {
            list.add(i)
            if (list.size == K) {
                println(list[K-1])
                return
            }
        }
    }
}

Measured memory_bytes: 36040
import sys
def MI(): return map(int, sys.stdin.readline().split())

H,W = MI()
s = [list(input()) for _ in range(H)]
dp = [[0 for _ in range(W)] for _ in range(H)]

if s[0][0]=='#':
	dp[0][0] = 1

for i in range(W-1):
	if s[0][i+1]=='#' and s[0][i]=='.':
		dp[0][i+1] = dp[0][i] + 1
	else:
		dp[0][i+1] = dp[0][i]

for i in range(H-1):
	if s[i+1][0]=='#' and s[i][0]=='.':
		dp[i+1][0] = dp[i][0] + 1
	else:
		dp[i+1][0] = dp[i][0]

def next(start, goal, start_value):
	if start=='.' and goal=='#':
		start_value += 1
	return start_value

for i in range(1,H):
	for j in range(1,W):
		# print(next(s[i][j-1],s[i][j],dp[i][j-1]),next(s[i-1][j],s[i][j],dp[i-1][j]))
		dp[i][j] = min(next(s[i][j-1],s[i][j],dp[i][j-1]), next(s[i-1][j],s[i][j],dp[i-1][j]))

print(dp[H-1][W-1])

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

using namespace std;


typedef long long ll;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;

#define rep(i,b) for(i=0;i<b;++i)
#define repp(i,a,b) for(i=a;i<b;++i)

int main() {
    ll a, b, c;
    cin >> a >> b >> c;
    if(((a == b) && (a != c))|| ((c == b) && (b != a))|| ((a == c) && (b != c)))
        cout << "Yes";
    else cout << "No";
    return 0;
}
/*
         ,--"""",--.__,---[],-------._
       ,"   __,'            \         \--""""""==;-
     ," _,-"  "/---.___     \       ___\   ,-'',"
    /,-'      / ;. ,.--'-.__\  _,-"" ,| `,'   /
   /``""""-._/,-|:\       []\,' ```-/:;-. `. /
             `  ;:::      ||       /:,;  `-.\
                =.,'__,---||-.____',.=
                =(:\_     ||__    ):)=
               ,"::::`----||::`--':::"._
             ,':::::::::::||::::::::::::'.
    .__     ;:::.-.:::::__||___:::::.-.:::\     __,
       """-;:::( O )::::>_|| _<::::( O )::::-"""
   =======;:::::`-`:::::::||':::::::`-`:::::\=======
    ,--"";:::_____________||______________::::""----.          , ,
         ; ::`._(    |    |||     |   )_,'::::\_,,,,,,,,,,____/,'_,
       ,;    :::`--._|____[]|_____|_.-'::::::::::::::::::::::::);_
      ;/ /      :::::::::,||,:::::::::::::::::::::::::::::::::::/
     /; ``''''----------/,'/,__,,,,,____:::::::::::::::::::::,"
     ;/                :);/|_;| ,--.. . ```-.:::::::::::::_,"
    /;                :::):__,'//""\\. ,--.. \:::,:::::_,"
   ;/              :::::/ . . . . . . //""\\. \::":__,"
   ;/          :::::::,' . . . . . . . . . . .:`::\
   ';      :::::::__,'. ,--.. . .,--. . . . . .:`::`
   ';   __,..--'''-. . //""\\. .//""\\ . ,--.. :`:::`
   ;    /  \\ .//""\\ . . . . . . . . . //""\\. :`::`
   ;   /       . . . . . . . . . . . . . . . . .:`::`
   ;   (          . . . . . . . . . . . . . . . ;:::`
   ,:  ;,            . . . . . . . . . . . . . ;':::`
   ,:  ;,             . . . . . . . . . . . . .;`:::
   ,:   ;,             . . . . . . . . . . . . ;`::;`
    ,:  ;             . . . . . . . . . . . . ;':::;`
     :   ;             . . . . . . . . . . . ,':::;
      :   '.          . . . . . . . .. . . .,':::;`
       :    `.       . . . . . . . . . . . ;::::;`
        '.    `-.   . . . . . . . . . . ,-'::::;
          `:_    ``--..___________..--'':::::;'`
             `._::,.:,.:,:_ctr_:,:,.::,.:_;'`
________________`"\/"\/\/'""""`\/"\/""\/"____________________________

*/


Measured memory_bytes: 256
N = int(input())
dp = [[0 for _ in range(3)] for i in range(N)]
a,b,c = list(map(int,input().split()))
dp[0][0] = a
dp[0][1] = b
dp[0][2] = c
for i in range(1,N):
    a,b,c = list(map(int,input().split()))
    dp[i][0] = max(dp[i-1][1] + a, dp[i-1][2] + a)
    dp[i][1] = max(dp[i-1][0] + b, dp[i-1][2] + b)
    dp[i][2] = max(dp[i-1][0] + c, dp[i-1][1] + c)
print(max(dp[N-1][0],dp[N-1][1],dp[N-1][2]))



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

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

  string answer;
  if (S == "Sunny") {
    answer = "Cloudy";
  } else if (S == "Cloudy") {
    answer = "Rainy";
  } else {
    answer = "Sunny";
  }
  cout << answer << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    int n;
    cin >> n;

    int x = 1;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;

        if (a == x) {
            x++;
        }
    }

    cout << (x == 1 ? -1 : n - (x - 1)) << endl;

    return 0;
}


Measured memory_bytes: 256
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<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()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let K: usize = read();
    use std::collections::VecDeque;
    let mut queue: VecDeque<i64> = VecDeque::new();
    for i in 1..10 {
        queue.push_back(i);
    }
    for _ in 0..K - 1 {
        let v = queue.pop_front().unwrap();
        let rem = v % 10;
        match rem {
            0 => {
                queue.push_back(v * 10 + rem);
                queue.push_back(v * 10 + rem + 1)
            }
            9 => {
                queue.push_back(v * 10 + rem - 1);
                queue.push_back(v * 10 + rem);
            }
            _ => {
                queue.push_back(v * 10 + rem - 1);
                queue.push_back(v * 10 + rem);
                queue.push_back(v * 10 + rem + 1)
            }
        }
    }
    println!("{}", queue.pop_front().unwrap());
}


Measured memory_bytes: 6396
#include<bits/stdc++.h>
using namespace std;
int a[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int main(){
    int n,m;
    cin>>n>>m;
    if(a[n-1]==a[m-1]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int m,d;
int main()
{
  cin >> m >> d;
  int cnt=0;
  for(int i=22;i<=d;++i){
    int a = i%10,b=i/10;
    if(a>=2&&b>=2&&a*b<=m) cnt++;
  }
  cout << cnt << "\n";
  return 0;
}


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

int main() {
  string a;
  cin>>a;
  int b=0;
  int c;
  c=a.size();
  for(int i=0;i<c;i++){
    if(!(a.at(i)==a.at(c-1-i))){
      b++;
    }
  }
  cout<<b/2<<endl;
}

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

//使用flag的冒泡排序法
int bubbleSort(int arr[],int N){
	int sw = 0;//记录次数 
	bool flag = 1;
	for( int i = 0; flag ; i++){
		flag = 0;
		for(int j = N - 1; j >= i + 1; j--){
			if(arr[j] < arr[j - 1]){
				swap(arr[j], arr[j - 1]);
				flag = 1;
				sw++;
			}
		}
	}
	return sw; 
} 
int main(){
	int arr[100], N, sw;
	cin >> N;
	for(int i = 0; i < N; i++){
		cin >> arr[i];
	}
	sw = bubbleSort(arr, N);
	for(int i = 0; i < N; i++){
		if(i) cout << " ";
		cout << arr[i];
	}
	cout << endl;
	cout << sw << endl;
	return 0;
}


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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }
const ll MOD = 1e9+7;
#define pii pair<int,int>
#define pll pair<ll,ll>

int main(){
  int N,K; cin>>N>>K;
  string s; cin>>s;
  int ans = 0;
  int idx1 = 0;
  int idx2 = 0;
  int manu = 0;
  while(idx2<N){
    while(idx2<N && s[idx2]=='1'){ ++idx2; }
    while(idx2<N && s[idx2]=='0'){ ++idx2; }
    if(s[idx2-1]=='0'){ ++manu; }
    while(s[idx2]=='1'){ ++idx2; }
    if( (idx2<N && s[idx2]=='0') || idx2==N){ chmax(ans,idx2-idx1); }
    else{ chmax(ans, idx2-idx1+1);}
    if(manu==K){
      while(idx1<N && s[idx1]=='1'){ ++idx1; }
      while(idx1<N && s[idx1]=='0'){ ++idx1; }
      if(s[idx1-1]=='0'){ --manu; }
    }
  }
  
  cout << ans << "\n";
  
}

Measured memory_bytes: 512
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
3 4 6
0 0
0 2
0 3
1 1
2 1
2 3

output:
3
"""

import sys


def dfs(current, matching, visited):
    for target in range(y_num):
        if not visited[target] and target in adj_table[current]:
            visited[target] = True
            ''' Matching[target] = -1: target not assigned to any of x.
            And dfs(matching[target], matching, visited) = True
            indicates that source in x has been already assigned
            to another target in y. '''
            if matching[target] == -1 or dfs(matching[target], matching, visited):
                matching[target] = current
                return True
    return False


def mbm():
    res = 0
    matching = [-1] * y_num
    for source in range(x_num):
        visited = [False] * y_num
        if dfs(source, matching, visited):
            res += 1
    return res


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    x_num, y_num, e_num = map(int, _input[0].split())
    edges = map(lambda x: x.split(), _input[1:])

    adj_table = tuple([] for _ in range(x_num))
    for edge in edges:
        vx, vy = map(int, edge)
        adj_table[vx].append(vy)
    print(mbm())

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))

#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repis(x, y, z, s) for ((x) = (z); (x) < (y); (x) += (s))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define nepit(x) for (__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); it++)

#define All(x) (x).begin(),(x).end()

#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))

#define Unique(v) v.resize(unique(All(v)) - v.begin())

#define peq(p0, p1)(p0.first == p1.first && p0.second == p1.second)

#define End '\n'
#define Out(x) cout<<(x)<<End
#define OutP(p, sep, end) cout<<p.first<<sep<<p.second<<end

template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define lb std::lower_bound
#define ub std::upper_bound

#define lbi(v, x) lb(All(v), (x))-v.begin()
#define ubi(v, x) ub(All(v), (x))-v.begin()

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);
	//std::cout.precision(18);

	string s;

	cin >> s;

	string y = "";
	string m = "";
	string d = "";
	int year, month, day;

	y += s[0];
	y += s[1];
	y += s[2];
	y += s[3];
	m += s[5];
	m += s[6];
	d += s[8];
	d += s[9];

	year = stoi(y);
	month = stoi(m);
	day = stoi(d);

    if (year < 2019) Out("Heisei");
	else if (year == 2019 && month < 4) Out("Heisei");
	else if (year == 2019 && month == 4 && day <= 30) Out("Heisei");
	else Out("TBD");
	
	return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <algorithm>
#include <complex>
#include <cassert>
#include <vector>
#include <iomanip>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;

typedef pair<int, int> P;
ll const mod = 1000000007;


int main(){
    int n, W;
    while (cin >> n >> W){
        vll w(n);
        rep(i, n) cin >> w[i];
        sort(all(w));

        vll sum(n + 1);
        rep(i, n) sum[i + 1] = sum[i] + w[i];

        if (sum[n] <= W){
            cout << 1 << endl;
            continue;
        }

        ll res = 0;
        vll dp(W + 1);
        dp[0] = 1;
        for (int i = n - 1; i >= 0; i--){
            for (int j = W; j >= w[i]; j--) {
                (dp[j] += dp[j - w[i]]) %= mod;
            }
            int l = W - sum[i] - w[i];
            int r = W - sum[i];
            if (i != 0) r -= w[i - 1];
            for (int j = r; j>=max(l + 1, 0); j--)
                (res += dp[j]) %= mod;
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 1284
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n;cin>>n;
  vector<int>a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  sort(a.begin(),a.end());
  int ans = 0, cnt=1;
  int pre = a[0];
  for(int i=1;i<n;i++){
    if(pre==a[i]){
     cnt++; 
    }
    else{
      ans += cnt % 2;
      pre = a[i];
      cnt=1; 
    }
  }
  ans += cnt%2;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 640
# your code goes here
num = list(map(int,input().split()))
num.sort()

ans = int((num[2] - num[1])/2)
num[1] += ans*2
ans += int((num[2]- num[0])/2)
num[0] += int((num[2]- num[0])/2)*2
num.sort()

if num[0] == num[1] and num[1] == num[2]:
	print(ans)
elif num[0] == num[1]:
	print(ans+1)
else:
	print(ans+2)

Measured memory_bytes: 3064
public class Main{
	public static void main(String[]$){
		java.util.Arrays.asList(11,31,41,61,71,101,131,151,181,191,211,241,251,271,281,311,331,401,421,431,461,491,521,541,571,601,631,641,661,691,701,751,761,811,821,881,911,941,971,991,1021,1031,1051,1061,1091,1151,1171,1181,1201,1231,1291,1301,1321,1361,1381).subList(0,new java.util.Scanner(System.in).nextInt()).forEach(System.out::println);
	}
}

Measured memory_bytes: 26708
line = STDIN.read.each_line.first.chomp

def count_hugs(str)
  if str.nil? || str.length == 0
    0
  else
    score = str[0] == str[-1] ? 0 : 1
    score + count_hugs(str[1..-2])
  end
end

puts count_hugs(line)


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

using namespace std;
typedef int  ll;
typedef long double ld;
typedef pair<ll,ll> pp;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> super_set;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> multi_set;
#define x1 dfds
#define y1 dsfdsfe
#define pb push_back
#define forn(i,n) for(ll i = 1;i<=n;++i)
#define fi first
#define sc second
#define endl '\n'
#define po(x) (1ll<<x)
const ll DIM = 2E3+7;
ll dist[DIM],cnt[DIM];
ll n,x,y;
void bfs(ll num){
    ll v = num;
    queue<ll> Q;
    Q.push(v);
    memset(dist,-1,sizeof(dist));
    dist[v] = 0;
    while(!Q.empty()){
        v = Q.front();
        Q.pop();
        if (v<n && dist[v+1]==-1){
            dist[v+1] = dist[v]+1;
            cnt[dist[v+1]]++;
            Q.push(v+1);
        }
        if (v>1 && dist[v-1]==-1){
            dist[v-1] = dist[v]+1;
            cnt[dist[v-1]]++;
            Q.push(v-1);
        }
        if ((v==x || v==y) && dist[x^y^v]==-1){
            dist[x^y^v] = dist[v]+1;
            cnt[dist[v^x^y]]++;
            Q.push(x^y^v);
        }
    }
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin>>n>>x>>y;
    forn(i,n){
        bfs(i);
    }
    forn(i,n-1){
        cout<<cnt[i]/2<<endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
	
	string s;
	cin >> s;
	if (s[0] == '0'&&s[1] != '0'){

		if (s[2] == '0'&& s[3] != '0'){ cout << "AMBIGUOUS" << endl; }

		else if (s[2] == '1'){

			if (s[3] == '0' || s[3] == '1' || s[3] == '2'){cout << "AMBIGUOUS" << endl;}

			else{cout << "MMYY" << endl;}
		}

		else{ cout << "MMYY" << endl; }

	}

	else if (s[0] == '1'){
		
		if (s[1] == '0' || s[1] == '1' || s[1] == '2'){
			if (s[2] == '0' && s[3] != '0'){ cout << "AMBIGUOUS" << endl; }

			else if (s[2] == '1'){

				if (s[3] == '0' || s[3] == '1' || s[3] == '2'){ cout << "AMBIGUOUS" << endl; }

				else{ cout << "MMYY" << endl; }
			}
		}

		else{
			if (s[2] == '0' && s[3] != '0'){ cout << "YYMM" << endl; }

			else if (s[2] == '1'){
				if (s[3] == '0' || s[3] == '1' || s[3] == '2'){ cout << "YYMM" << endl; }

				else{ cout << "NA" << endl; }
			}
			else{ cout << "NA" << endl; }
		}
	}

	else{
		if (s[2] == '0' && s[3] != '0'){ cout << "YYMM" << endl; }

		else if (s[2] == '1'){
			if (s[3] == '0' || s[3] == '1' || s[3] == '2'){ cout << "YYMM" << endl; }

			else{ cout << "NA" << endl; }
		}
		else{ cout << "NA" << endl; }
	}

	

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <vector>
using namespace std;

int main(){
    int N,W[105],X;
    X=10000000;
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> W[i];
    }
    int k;
    for(k=1;k<N-1;k++){
        int S1=0,S2=0;
        for(int i=0;i<=k;i++){
            S1=S1+W[i];
        }
        for(int i=k+1;i<N;i++){
            S2=S2+W[i];
        }
    int Y;
    Y=abs(S1-S2);
    if(X>Y){
        X=Y;
    }
    }
    cout << X << endl;
}

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

int int_compare(const long* a, const long* b)
{
    if (*a < *b) {
        return 1;
    } else if (*a > *b) {
        return -1;
    }
    return 0;
}

int main(void)
{
    int n;
    scanf("%d", &n);

    long* arr = calloc(n, sizeof(long));

    for (int i = 0; i < n; i++) {
        scanf("%ld", &arr[i]);
    }

    long* sorted = calloc(n, sizeof(long));

    for (int i = 0; i < n; i++) {
        sorted[i] = arr[i];
    }

    qsort(sorted, n, sizeof(long), (int (*)(const void*, const void*))(*int_compare));

    long max = sorted[0];
    long second_max = sorted[1];

    for (int i = 0; i < n; i++) {
        printf("%ld\n", arr[i] == max ? second_max : max);
    }

    free(arr);
    free(sorted);

    return 0;
}


Measured memory_bytes: 4860
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <numeric>

using namespace std;

int main(){
   int n;
   cin>>n;
   vector<int> a(n);
   for(int i=0;i<n;i++){
      cin>>a[i];
   }
   vector<int> ans(n);
   for(int i=0;i<n;i++){
      while(a[i]%2==0){
         a[i]/=2;
         ans[i]++;
      }
   }
   cout<<*min_element(ans.begin(), ans.end())<<endl;

}

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

// iterator
#define REP(i,init, n) for(lli i=init;i<n;i++)
#define REPE(i,init, n) for(lli i=init;i<=n;i++)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) {cin1(x[i]);}
#define ncin2(n, x, y)      REP(i, 0, n) {cin2(x[i], y[i]);}
#define ncin3(n, x, y, z)   REP(i, 0, n) {cin3(x[i], y[i], z[i]);}

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;

// 大きい順にpop
class CompareDist
{
public:
    bool operator()(P n1, P n2) {
        return n1.second<=n2.second;
    }
};

int main() {
    lli n;
    cin1(n);
    lli a[n];
    lli b[n];
    ncin1(n, a);
    ncin1(n, b);


    priority_queue< P, vector<P>, CompareDist > que;

    REP(i, 0, n) {
        if (a[i] != b[i])
            que.push(P(i, b[i]));
    }

    lli ans = 0;
    while (true) {
        P p = que.top();
        lli cur = p.first;
        lli prev = (cur + n - 1) % n;
        lli next = (cur + n + 1) % n;

        lli x = b[cur];
        lli y = b[prev] + b[next];
        lli count = (x - a[cur]) / y;
        if (count == 0)
            break;
        x -= y * count;

        b[cur] = x;
        que.pop();
        if (x != a[cur]) {
            que.push(P(cur, b[cur]));
        }

        ans+=count;
        //cout1(ans);
    }

    REP(i, 0, n) {
        if (a[i] != b[i]) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 9456
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cfloat>
#include <algorithm>
#include <functional>
#include <numeric>
#include <vector>
using namespace std;

const double PI=acos(-1);

int main(){
    long n, k;
    cin >> n >> k;

    long a = n - k*(n/k);
    while(a > abs(a - k)){
        a = abs(a-k);
    }
    cout << a  << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <cassert>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <tuple>

using namespace std;


int main() {
	int H,W,h,w;
	cin >> H >> W>> h >> w;
	cout << (H-h) * (W-w) << endl;

	return 0;
}

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

int main(){
    
    int a, b;
    
    cin >> a >> b;
    
    if(a > b){
        cout << "a > b\n";
    } else if(a == b){
        cout << "a == b\n" ;
    }else{
        cout << "a < b\n";
    }
    
    return 0;
}


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

#define ll long long
#define ld long double
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define int long long

using namespace std;
const int INF = 2e9;
const int MB = 20;
const int MOD = 1e9 + 7;

void solve() {
	int n;
	cin >> n;
	vector<pair<int, int>> a(n);
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		int y = 0;
		bool good = false;
		int now = 0;
		for (char c : s) {
			if (c == '.') {
				good = true;
				continue;
			}
			y = y * 10;
			if (good) now++;
			y = y + c - '0';
		}
		while (now < 9) {
			y *= 10;
			now++;
		}
		while (y % 2 == 0) {
			a[i].first++;
			y /= 2;
		}
		while (y % 5 == 0) {
			a[i].second++;
			y /= 5;
		}
		a[i].first = min(18LL, a[i].first);
		a[i].second = min(18LL, a[i].second);
	}

	vector<vector<int>> q(MB, vector<int>(MB));
	int ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 18 - a[i].first; j < MB; j++) {
			for (int c = 18 - a[i].second; c < MB; c++) {
				ans += q[j][c];
			}
		}
		q[a[i].first][a[i].second]++;
	}
	cout << ans;
}


signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(12);
	srand(time(0));
	int t = 1;
	//int t;
	//cin >> t;
	while (t--) solve();
}

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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = (1 << 30);
constexpr ll L_INF = (1ll << 62);

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

double dp[3010][3010];

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

    int N;
    cin >> N;
    vector<double> p(N);
    for (int i = 0; i < N; ++i) {
        cin >> p[i];
    }

    for (int i = 0; i <= N; ++i) {
        for (int j = 0; j <= N; ++j) {
            dp[i][j] = 0.0;
        }
    };
    dp[0][0] = 1.0;

    for (int i = 1; i <= N; ++i) {
        for (int j = 0; j <= N; ++j) {
            dp[i][j] += dp[i - 1][j] * (1.0 - p[i - 1]);
            dp[i][j + 1] += dp[i - 1][j] * p[i - 1];
        }
    }

    double ans = 0.0;

    for (int j = (N + 1) / 2; j <= N; ++j) {
        ans += dp[N][j];
    }

    cout << setprecision(15) << ans << endl;

    return 0;
}

Measured memory_bytes: 70784
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <ios>
#include <iomanip>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<double> x(N), y(N);
    rep(i, N) cin >> x[i] >> y[i];
    
    vector<int> vec;
    rep(i, N) vec.push_back(i);
    double sum = 0;
    int cnt = 0;
    do {
        REP(i, N) {
            int now_x = x[vec[i]];
            int now_y = y[vec[i]];
            int old_x = x[vec[i - 1]];
            int old_y = y[vec[i - 1]];
            sum += sqrt((now_x - old_x) * (now_x - old_x) + (now_y - old_y) * (now_y - old_y));
        }
        ++cnt;
    } while (next_permutation(vec.begin(), vec.end()));
    
    double ans = sum / cnt;
    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  vector<vector<mint>> dp(c+2, vector<mint>(d+2, 0));
  dp.at(a).at(b) = 1;
  rep2(i, a, c+1){
    rep2(j, b, d+1){
      dp.at(i+1).at(j) += dp.at(i).at(j) * j;
      dp.at(i).at(j+1) += dp.at(i).at(j) * i;
      dp.at(i+1).at(j+1) -= dp.at(i).at(j) * (i) * (j);
    }
  }
  cout << dp.at(c).at(d).x << endl;
  return 0;
}

Measured memory_bytes: 73536
#include <iostream>
#include <cstdio>
using namespace std;
long long k, k1, k2;
long long num[50];
int main() {
	cin >> k;
	k1 = k/50;
	k2 = k%50;
	for (int i = 0; i < 50; i++)	num[i] = 49+k1;
	for (int i = 0; i < k2; i++)	num[i] += (50-k2+1);
	for (int i = k2; i < 50; i++)	num[i] -= k2;
	cout << 50 << endl;
	for (int i = 0; i < 50; i++)	cout << num[i] << " ";
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();

		if ("RRR".equals(s)) {
			System.out.println(3);
		} else if (s.indexOf("RR") != -1) {
			System.out.println(2);
		} else if (s.indexOf("R") != -1) {
			System.out.println(1);
		} else {
			System.out.println(0);
		}

		sc.close();

	}

}

Measured memory_bytes: 35596
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln = '\n';

const int mx=100010;
const ll mod=1e9+7;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  unordered_map<int,int> mp;
  rep(i,n){
    cin >> a[i];
    mp[a[i]]++;
  }
  sort(a.begin(),a.end());
  if(a[0]==1){
    if(a[1]==1){
      cout << 0 << ln; return 0;
    } else {
      cout << 1 << ln; return 0;
    }
  }
  vector<bool> d(1000010,true);

  int ans = 0;
  rep(i,n){
    if(mp[a[i]]==1 && d[a[i]]){
      ans++;
    }
    for(int j=1; j*a[i]<1000001; j++){
      d[a[i]*j] = false;
    }
  }

  cout << ans << ln;

  return 0;
}

Measured memory_bytes: 12292
k=int(input())
l=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(l[k-1])

Measured memory_bytes: 9080
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
struct UnionFind {
    //If the vertex is a parent, this value will be the number of vertices that belongs to the set, multiplied by -1
    //Otherwise, this value will be the parent's id
    vector<int> r;
 
    UnionFind(int N) {
        r = vector<int>(N, -1);
    }
 
    int root(int x) {
        if (r[x] < 0) return x;
        return r[x] = root(r[x]);
    }
 
    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (r[x] > r[y]) swap(x, y);
        r[x] += r[y];
        r[y] = x;
        return true;
    }
 
    int size(int x) {
        return -r[root(x)];
    }
};
 
 
int main() {
    int N, M;
    cin >> N >> M;
 
    //Make friends-sets
    UnionFind UF(N);
    for (int i = 0; i < M; i++)
    {
        int A, B;
        cin >> A >> B;
        A -= 1; B -= 1;
        UF.unite(A, B);
    }
 
    //Find the maximum friends-set
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        ans = max(ans, UF.size(i));
    }
 
    cout << ans << endl;
}

Measured memory_bytes: 4048