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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
	EACH(x,vec) is >> x;
	return is;
}
/*
template<class... T>
ostream& operator<<(ostream& os, tuple<T...>& t) {
	for (size_t i = 0; i < tuple_size< tuple<T...> >::value; ++i) {
		if (i) os << " ";
		os << get<0>(t);
	}
	return os;
}
*/
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
	REP(i,vec.size()) {
		if (i) os << " ";
		os << vec[i];
	}
	return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
	REP(i,vec.size()) {
		if (i) os << endl;
		os << vec[i];
	}
	return os;
}

vector<string> m0, m;
int H, W, n;
bool isGoal() {
	REP(y, H) REP(x, W) {
		if (m[y][x] != '.') return false;
	}
	return true;
}
bool fall() {
	bool res = false;
	REP(i, H) {
		for (int y = H-1; y >= 1; --y) {
			REP(x, W) {
				if (m[y][x] == '.' && m[y-1][x] != '.') {
					m[y][x] = m[y-1][x];
					m[y-1][x] = '.';
					res = true;
				}
			}
		}
	}
	return res;
}
bool check() {
	while (1) {
		bool isUpdated = false;
		isUpdated |= fall();
		vector< vector<bool> > f(H, vector<bool>(W, false));
		REP(y, H) REP(x, W-n+1) {
			if (m[y][x] != '.') {
				bool flag = true;
				REP(i, n) if (m[y][x+i] != m[y][x]) flag = false;
				if (flag) {
					REP(i, n) f[y][x+i] = true;
					isUpdated = true;
				}
			}
		}
		REP(x, W) REP(y, H-n+1) {
			if (m[y][x] != '.') {
				bool flag = true;
				REP(i, n) if (m[y+i][x] != m[y][x]) flag = false;
				if (flag) {
					REP(i, n) f[y+i][x] = true;
					isUpdated = true;
				}
			}
		}
		REP(y, H) REP(x, W) {
			if (f[y][x]) m[y][x] = '.';
		}
		isUpdated |= fall();
		if (!isUpdated) break;
	}
	return isGoal();
}
int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	cin >> H >> W >> n;
	m0.resize(H); cin >> m0;
	bool ans = false;
	REP(y, H) REP(x, W-1) {
		m = m0;
		swap(m[y][x], m[y][x+1]);
		if ( check() ) ans = true;
	}
	if (ans) cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 3256
#include <bits/stdc++.h>
#define pb push_back

using namespace std;
using ll = long long int;

void solve()
{
	int n, k; cin >> n >> k;
	string s; cin >> s;
	if (s[k-1] >= 'A') s[k-1] = s[k-1] - 'A' + 'a';
	cout << s;
}

//  ---------------------Template---------------------------
void InputSetup()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	#ifdef LOCAL
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
	#endif
}

int main(void)
{
	auto start = chrono::high_resolution_clock::now();

	InputSetup();
	solve();

	auto finish = chrono::high_resolution_clock::now();
	cerr << "Time elapsed: " << (chrono::duration<long double>(finish-start)).count() << "s\n";
}
//  ---------------------Template---------------------------

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

int main(void){
	int n;
	cin >> n;
	for(int i=0; i<n; i++){
		string a, b;
		cin >> a >> b;
		if(a.size()>80 || b.size()>80) {cout << "overflow" << endl;}
		else{
			vector<int> x, y, z;
			for(int j=0; j<80; j++){
				x.push_back(0);
				y.push_back(0);
				z.push_back(0);
			}

			for(int j=0; j<a.size(); j++)
				x[j] = atoi( a.substr(a.size()-1-j,1).c_str() );
			for(int j=0; j<b.size(); j++)
				y[j] = atoi( b.substr(b.size()-1-j,1).c_str() );
			
			for(int j=0; j<80; j++){
				z[j] = x[j]+y[j];
			}
			for(int j=0; j<79; j++){
				if( z[j]>=10 ){
					z[j+1]++;
					z[j]-=10;
				}
			}
			if(z[79]>=10) {cout << "overflow" << endl;}
			else {
				bool zeroume = false;
				for(int j=0; j<80; j++){
					if(z[79-j]==0 && zeroume==false){}
					else{cout << z[79-j];zeroume=true;}
				}
				if(zeroume==false) cout << 0;
				cout << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
using pii = pair<int, int>;
int main() {
  int n, k;
  cin >> n >> k;

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

  sort(p.begin(), p.end());

  int sum = 0;
  for (int i = 0; i < k; i++) {
    sum += p[i];
  }

  cout << sum << endl;
}

Measured memory_bytes: 3636
import sys

import numba as nb
import numpy as np

input = sys.stdin.readline


@nb.njit("i8(i8,i8,i8[:],i8[:])")
def solve(N, W, w, v):
    dp = np.full(shape=(N + 1, np.sum(v) + 1), fill_value=(N * W), dtype=np.int64)
    dp[:, 0] = 0
    for i in range(N):
        # TODO: use out keyward
        dp[i + 1][:v[i]] = np.minimum(w[i], dp[i][:v[i]])
        dp[i + 1][v[i]:] = np.minimum(w[i] + dp[i][: - v[i]], dp[i][v[i]:])
    return np.where(dp[-1] <= W)[0][-1]


def main():
    N, W = map(int, input().split())

    w = np.empty(shape=N, dtype=np.int64)
    v = np.empty(shape=N, dtype=np.int64)
    for i in range(N):
        w[i], v[i] = map(int, input().split())

    ans = solve(N, W, w, v)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 200464
from collections import deque

n = int(input())
g = tuple(set() for _ in range(n))
for _ in range(n - 1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    g[u].add((v, w))
    g[v].add((u, w))

d = [-1] * n
d[0] = 0

q = deque()
q.append(0)

while q:
    v = q.popleft()
    for u, w in g[v]:
        if d[u] != -1:
            continue
        d[u] = (d[v] + w) % 2
        q.append(u)

print(*d, sep='\n')


Measured memory_bytes: 52228
A,B,C = map(int,input().split())
if A % 2 == 1:
    if B % 2 == 1:
        if C % 2 == 1:
            answer = (3*max(A,B,C)-(A+B+C))//2
        else:
            answer = (3*max(A+1,B+1,C)-(A+B+C+2))//2 + 1
    else:
        if C % 2 == 1:
            answer = (3*max(A+1,B,C+1)-(A+B+C+2))//2 + 1
        else:
            answer = (3*max(A,B+1,C+1)-(A+B+C+2))//2 + 1
else:
    if B % 2 == 1:
        if C % 2 == 1:
            answer = (3*max(A,B+1,C+1)-(A+B+C+2))//2 + 1
        else:
            answer = (3*max(A+1,B,C+1)-(A+B+C+2))//2 + 1
    else:
        if C % 2 == 1:
            answer = (3*max(A+1,B+1,C)-(A+B+C+2))//2 + 1
        else:
            answer = (3*max(A,B,C)-(A+B+C))//2

print(answer)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    string str;
    while(cin>>str){
        string st="CODEFESTIVAL2016";
        int cnt=0;
        for(int i=0;i<str.length();i++){
            if(str[i]!=st[i])cnt++;
        }
        cout<<cnt<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll>pi;
const int MAXN=100005;
const int MOD=1000000007;

#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define DEC(i,a,b) for(int i=(a);i>=(b);i--)
#define fst first
#define snd second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define db(x) cerr<<#x<<" = "<<x<<"\n"
#define LOW(v,x) (lower_bound(all(v),(x))-(v).begin())
#define UP(v,x) (upper_bound(all(v),(x))-(v).begin())

main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int K; cin>>K;
	int ans=0;
	FOR(a,1,K) FOR(b,1,K) FOR(c,1,K){
		ans += __gcd(__gcd(a,b),c);
	}
	cout<<ans;
}


Measured memory_bytes: 3652
#include <stdio.h>

int main()
{
	int a[5000];
	int n;
	long int max;
	long int dummy;
	scanf("%d",&n);
	while(n != 0){
		for(int i = 0; i < n; i++){
			scanf("%d",&a[i]);
		}
		max = a[0];
		for(int i = 0; i < n; i++){
			dummy = 0;
			for(int j = i; j < n; j++){
				dummy += a[j];
				if(dummy > max){
					max = dummy;
				}
			}
		}
		printf("%ld\n",max);
		scanf("%d",&n);
	}
	return 0;
}

Measured memory_bytes: 1048
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,m;
  	cin >> n >> m;
  	int a,ans = 0;
  	for(int i = 0;i < m;i++)
    {
       scanf("%d",&a);ans += a;
    }
  	if(n < ans)puts("-1");
  	else cout << n - ans;
  	return 0;
}


Measured memory_bytes: 3740
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
string S;

int main() {
  INCANT;
  cin >> S;
  if (S[0]==S[1] && S[1]==S[2] && S[0]=='R') {
    cout << 3 << endl;
  } else if ((S[0]==S[1] && S[1]=='R' )|| (S[1]==S[2]&& S[1]=='R' )) {
    cout << 2 << "\n";
  } else if (S[0]=='R' || S[1]=='R' || S[2]=='R'){
    cout << 1 << "\n";
  } else cout << 0 << "\n";
  
  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1061109567
#define int long long
#define INFLL 4557430888798830399
#define bp __builtin_popcountll
#define pb push_back
#define in(s) freopen(s,"r",stdin);
#define out(s) freopen(s,"w",stdout);
#define fi first
#define se second
#define bw(i,r,l) for (int i=r-1;i>=l;i--)
#define fw(i,l,r) for (int i=l;i<r;i++)
#define fa(i,x) for (auto i:x)
using namespace std;
const int N = 55;
int n, a[N], b[N];
bool need[N], dp[N][N][N];
bool check(int x) {
	bool ans = 0, can[N];
	fw (i, 0, n) {
		memset(can, 0, sizeof can);
		can[a[i]] = 1;
		bw (j, a[i] + 1, 0) if (can[j]) {
			bw (k, 51, 1) if (need[k]) can[j % k] = 1;
		}
		bool really = 1;
		bw (j, a[i] + 1, 0) if (can[j]) {
			if (dp[j][b[i]][x - 1]) really = 0;
		}
		if (really) ans = 1;
	}
	return ans;
}
signed main() {
	#ifdef BLU
	in("blu.inp");
	#endif
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	fw (i, 0, n) cin >> a[i];
	fw (i, 0, n) cin >> b[i];
	/*
	Firstly, each MOD will be used only once and they will be performed in decreasing order on every
	number.
	Now consider for a certain i if we need to MOD it in order to have our sequence. This is a simple
	task. For every element a[i], store all reachable new values after random MODding with the
	previous found requirements. Then just use DP to find out if we really need i or not easily.
	*/
	fw (i, 0, N) dp[i][i][0] = 1;
	fw (i, 1, 51) fw (j, 0, N) fw (k, 0, N) {
		dp[j][k][i] = max(dp[j][k][i - 1], dp[j % i][k][i - 1]);
	}
	fw (i, 0, n) if (!dp[a[i]][b[i]][50]) {
		cout << "-1";
		return 0;
	}
	memset(need, 0, sizeof need);
	int ans = 0;
	bw (i, 51, 1) {
		if (check(i)) need[i] = 1, ans += (1LL << i);
	}
	cout << ans;
	return 0;
}

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

int main(void) {
    int A,B,C,X,Y, ans=0;
    cin >> A >> B >> C >> X >> Y;
    int tmp_A=0;
    int tmp_B=0;
    int tmp_C=0;
    bool ABC_flag = true; //(A+B)と2*Cどっちが安いか
    if(A+B < 2*C) ABC_flag = false;
    bool calc_flag = true;

    int tmp_XY;
    bool XY_flag = true;
    if(ABC_flag){
      if(X>Y){
          tmp_C += 2*Y;
          tmp_XY = X-Y;
      }
      else{
          tmp_C += 2*X;
          tmp_XY = Y-X;
          XY_flag =false;
      }
    }
    else{
      tmp_A += X;
      tmp_B += Y;
      calc_flag = false;
    }

    if(calc_flag){
      if(XY_flag){
        if(A*tmp_XY > 2*C*tmp_XY)  tmp_C += 2*tmp_XY;
        else                       tmp_A += tmp_XY;
      }
      else{
        if(B*tmp_XY > 2*C*tmp_XY)  tmp_C += 2*tmp_XY;
        else                       tmp_B += tmp_XY;
      }
    }

    ans = A*tmp_A + B*tmp_B + C*tmp_C;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0; i < (int)(n); i++ )

int main( void )
{
    string A,s,C;
    cin >> A >> s >> C;
    
    cout << A.at(0) << s.at(0) << C.at(0) << endl;
}

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

long long gcd(long long a, long long b) {
  if (b == 0) return a;
  else return gcd(b, a % b);
}

long long lcm(long long a, long long b) {
  long long g = gcd(a, b);
  return a / g * b;
}

int main() {
  int N;
  cin >> N;
  vector<long long> T(N);
  for (int i = 0; i < N; i++) cin >> T.at(i);
  long long ans = 1;
  for (int i = 0; i < N; i++) ans = lcm(ans, T.at(i));
  cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        const int MAX_G = 401;
        int N, MA, MB;
        int[] A = new int[40];
        int[] B = new int[40];
        int[] C = new int[40];
        int[,] G = new int[MAX_G, MAX_G];
        const int NIL = 999999;

        string[] values = Console.ReadLine().Split(' ');
        N = int.Parse(values[0]);
        MA = int.Parse(values[1]);
        MB = int.Parse(values[2]);

        for (int i = 0; i < N; i++)
        {
            string[] vals = Console.ReadLine().Split(' ');
            A[i] = int.Parse(vals[0]);
            B[i] = int.Parse(vals[1]);
            C[i] = int.Parse(vals[2]);
        }

        for (int a = 0; a < MAX_G; a++)
            for (int b = 0; b < MAX_G; b++)
            {
                G[a, b] = NIL;
            }
        G[0, 0] = 0;

        for (int i = 0; i < N; i++)
        {
            for (int a = MAX_G - 1; a >= 0; a--)
                for (int b = MAX_G - 1; b >= 0; b--)
                {
                    if (G[a, b] != NIL)
                    {
                        int aa = a + A[i];
                        int bb = b + B[i];
                        G[aa, bb] = Math.Min(G[aa, bb], G[a, b] + C[i]);
                    }
                }
        }

        int ret = NIL;
        int ma = MA;
        int mb = MB;
        while (true)
        {
            ret = Math.Min(G[ma, mb], ret);

            ma += MA;
            mb += MB;
            if (ma >= MAX_G || mb >= MAX_G) break;
        }

        if (ret == NIL) ret = -1;
        Console.WriteLine(ret);

    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll f[55][55];
int main(){
	ll n,c;
	cin>>n>>c;
	vector<ll>x(n),y(n),xx(n),yy(n),nx(n),ny(n);
	for(int i=0;i<n;i++){
		cin>>x[i]>>y[i];
	}
	xx=x;
	yy=y;
	sort(xx.begin(),xx.end());
	sort(yy.begin(),yy.end());
	xx.erase(unique(xx.begin(),xx.end()),xx.end());
	yy.erase(unique(yy.begin(),yy.end()),yy.end());
	for(int i=0;i<n;i++){
		auto p=lower_bound(xx.begin(),xx.end(),x[i]);
		auto q=lower_bound(yy.begin(),yy.end(),y[i]);
		nx[i]=p-xx.begin()+1;
		ny[i]=q-yy.begin()+1;
	}
	for(int i=0;i<n;i++)f[nx[i]][ny[i]]=1;
	sort(nx.begin(),nx.end());
	sort(ny.begin(),ny.end());
	nx.erase(unique(nx.begin(),nx.end()),nx.end());
	ny.erase(unique(ny.begin(),ny.end()),ny.end());
	ll ans=5e18;
	// for(int i=0;i<nx.size();i++)cout<<nx[i]<<' ';
	// cout<<endl;
	// for(int i=0;i<nx.size();i++)cout<<xx[i]<<' ';
	// cout<<endl;
	// for(int i=0;i<ny.size();i++)cout<<ny[i]<<' ';
	// cout<<endl;
	// for(int i=0;i<ny.size();i++)cout<<yy[i]<<' ';
	// cout<<endl;
	for(int i=0;i<=50;i++)for(int j=1;j<=50;j++)f[i][j]+=f[i][j-1];
	for(int i=0;i<=50;i++)for(int j=1;j<=50;j++)f[i][j]+=f[i-1][j];
	for(int i=0;i<nx.size();i++){
		for(int j=0;j<ny.size();j++){
			for(int k=i+1;k<nx.size();k++){
				for(int l=j+1;l<ny.size();l++){
					if(f[nx[k]][ny[l]]+f[nx[i]-1][ny[j]-1]-f[nx[k]][ny[j]-1]-f[nx[i]-1][ny[l]]>=c){
						ans=min(ans,(xx[k]-xx[i])*(yy[l]-yy[j]));
					}
				}
			}
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3636
def main():
    K = int(input())
    a = 7 % K
    d = 1
    for k in range(1, K+1):
        if a == 0:
            return print(k)
        d *= 10
        d %= K
        a += 7 * d
        a %= K
    print(-1)


if __name__ == '__main__':
    main()


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

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

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

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

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

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

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

int main()
{
	for(string s,t;cin>>s>>t;){
		vi sa(s.size()+1),sb(s.size()+1),ta(t.size()+1),tb(t.size()+1);
		rep(i,s.size()){
			sa[i+1]=sa[i]+(s[i]=='A');
			sb[i+1]=sb[i]+(s[i]=='B');
		}
		rep(i,t.size()){
			ta[i+1]=ta[i]+(t[i]=='A');
			tb[i+1]=tb[i]+(t[i]=='B');
		}
		int q; cin>>q;
		rep(_,q){
			int a,b,c,d; cin>>a>>b>>c>>d; a--,c--;
			int x=((sa[b]-sa[a])-(sb[b]-sb[a])+999999)%3;
			int y=((ta[d]-ta[c])-(tb[d]-tb[c])+999999)%3;
			cout<<(x==y?"YES":"NO")<<endl;
		}
	}
}


Measured memory_bytes: 2432
#include <iostream>
#include <cstring>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define pb push_back
#define sz size()
#define vi vector<int>

int n,x[25],y[25],r[25],c[25],ans;
bool v[1<<24];

int sq(int x){return x*x;}

void f(int mask){
	if(v[mask])return;
	v[mask]=1;
	vi d;
	rep(i,n)if(mask>>i&1)d.pb(i);
	ans=max(ans,n-(int)d.sz);
	bool top[25];
	rep(i,d.sz)top[i]=1;
	rep(i,d.sz)rep2(j,i+1,d.sz){
		if(sq(x[d[i]]-x[d[j]])+sq(y[d[i]]-y[d[j]])<sq(r[d[i]]+r[d[j]])){
			top[j]=0;
		}
	}
	rep(i,d.sz)rep2(j,i+1,d.sz){
		if(top[i] && top[j] && c[d[i]]==c[d[j]]){
			f(mask-(1<<d[i])-(1<<d[j]));
		}
	}
}

int main(){
	while(cin>>n && n){
		rep(i,n)cin>>x[i]>>y[i]>>r[i]>>c[i];
		ans=0;
		memset(v,0,sizeof(v));
		f((1<<n)-1);
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 16000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int N;
int d[500];
int ans;

void solve() {
  cin >> N;
  for(int i = 1; i <= N; i++) cin >> d[i];
  for(int i = 1; i <= N; i++) {
    for(int j = i + 1; j <= N; j++) {
      ans += d[i] * d[j];
    }
  }
  cout << ans << endl;
    return;
}

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

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

int main() {
  string S;
  cin >> S;
  int odd = 0;
  int even = 0;
  int N = S.size();
  vector<int> ans(N,0);
  int cop;
  for (int i=0; i<N; i++) {
    if (S[i] == 'R') {
      if (i % 2 == 0) {
        even++;
      }
      else {
        odd++;
      }
    }
    else {
      for (int j=i; j<N; j++) {
        if (S[j] == 'L') {
          if (j % 2 == 0) {
            even++;
          }
          else {
            odd++;
          }
          if (j == N-1) {
            cop = N+1;
          }
        }
        else {
          cop = j;
          break;
        }
      }
      if (i % 2 == 0) {
        ans[i] = even;
        ans[i-1] = odd;
      }
      else {
        ans[i] = odd;
        ans[i-1] = even;
      }
      even = 0;
      odd = 0;
      i = cop-1;
    }
  }
  for (int i=0; i<N; i++) {
    if (i != 0) {
      cout << " ";
    }
    cout << ans[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdlib>
#include <algorithm>

using namespace std;

typedef long long ll;

int px[100001],py[100001],sx[100001],sy[100001];
int main(){
    int w,h,n;
    cin>>w>>h>>n;
    ll x,y;
    for(int i=0;i<n;++i){
        cin>>x>>y;
        px[i]=sx[i]=x;py[i]=sy[i]=y;
    }
    sort(sx,sx+n);
    sort(sy,sy+n);
    int posx[4]={sx[n/2-1],sx[n/2-1],sx[n/2],sx[n/2]};
    int posy[4]={sy[n/2-1],sy[n/2],sy[n/2-1],sy[n/2]};
    ll ans[4]={0};
    ll mx[4]={0};
    for(int i=0;i<n;++i){
        for(int j=0;j<4;++j){
            ll tx=abs(posx[j]-px[i]),ty=abs(posy[j]-py[i]);
            ans[j] +=(tx+ty)*2;mx[j]=mx[j]>tx+ty?mx[j]:tx+ty;
        }
    }
    ll mn=9223372036854775800;
    for(int i=0;i<4;++i){
        if(mn<=ans[i]-mx[i]) continue;
        mn=ans[i]-mx[i];x=posx[i];y=posy[i];
    }
    cout<<mn<<endl;
    cout<<x<<" "<<y<<endl;
    return 0;
}

Measured memory_bytes: 4712
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath> //abs();
using namespace std;

int main(void)
{
    long long int a,b,c,d,i,j,k,n,x[10];
    string s;
    char C[5];

    cin >> s;

    cout << "ABC" << s;

    return 0;
}

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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int N,M;
	cin>>N>>M;
	vector <int> ls[N+1];
	int A,B;
	for (int i=0;i<M;i++){
	    cin>>A>>B;
	    ls[A].push_back(B);
	    ls[B].push_back(A);
	}
	int ans[N+1];
	for (int i=0;i<=N;i++) ans[i]=-1;
	queue <int> q;
	q.push(1);
	while (!q.empty()){
	    int u=q.front();
	    q.pop();
	    for (int i=0;i<ls[u].size();i++){
	        if(ans[ls[u][i]]==-1){
	            ans[ls[u][i]]=u;
	            q.push(ls[u][i]);
	        }     
	    }
	}
	cout<<"Yes"<<"\n";
	for (int i=2;i<=N;i++)
	    cout<<ans[i]<<"\n";
	return 0;
}


Measured memory_bytes: 10516
#include <bits/stdc++.h>
#define REP(i,n) for (long long i=0;i<(n);i++)
#define FOR(i,a,b) for (long long i=(a);i<(b);i++)
#define RREP(i,n) for(long long i=n;i>=0;i--)
#define RFOR(i,a,b) for(long long i=(a);i>(b);i--)
#define dump1d_arr(array) REP(i,array.size()) cerr << #array << "[" << (i) << "] ==> " << (array[i]) << endl;
#define dump2d_arr(array) REP(i,array.size()) REP(j,array[i].size()) cerr << #array << "[" << (i) << "]" << "[" << (j) << "] ==> " << (array[i][j]) << endl;
#define dump(x)  cerr << #x << " => " << (x) << endl;
#define CLR(vec) { REP(i,vec.size()) vec[i] = 0; } 
#define llINF (long long) 9223372036854775807
#define loINF (long) 2147483647
#define shINF (short) 32767
#define SORT(c) sort((c).begin(),(c).end())

using namespace std;
typedef vector<long> VI;
typedef vector<VI> VVI;
typedef long long LL;

int main(void){
	LL N;
	cin >> N;
	LL minv = (N / 4);
	if (minv == 0) minv = 1;
	LL maxv = (N * 3)/4;

	#ifdef DEBUG
		dump(minv);
		dump(maxv);
	#endif

	FOR(w,maxv,loINF){
		FOR(h,minv,maxv+1){
			#ifdef DEBUG
				dump(w);
				dump(h);
			#endif

			if (((4*h*w)-(N*w)-(N*h)) == 0) continue;
			if (((N*h*w) % ((4*h*w)-(N*w)-(N*h))) == 0 && ((4*h*w)-(N*w)-(N*h)) > 0) {
				cout << w << " " << h << " " << ((N*h*w) / ((4*h*w)-(N*w)-(N*h))) << endl;
				exit(0);
			}
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <bitset>
#include <map>
#include <cmath>

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

using namespace std;

int main() {
	int N;
	scanf("%d", &N);
	printf("%d\n", (1000 - (N % 1000)) % 1000);
}

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

int main()
{
    int N, K, T, U, V, L;
    std::cin >> N >> K >> T >> U >> V >> L;
    std::vector<long double> D(N);
    for (auto& e: D) std::cin >> e;
    D.push_back(L);
    for (int i{N}; i > 0; i--)
        D[i] -= D[i - 1];
    
    long double rest{}, time{};
    for (int i{}; i <= N; i++)
    {
        if (rest * V <= D[i])
        {
            time += rest + (D[i] - rest * V) / U;
            rest = 0;
        }
        else
        {
            time += D[i] / V;
            rest -= D[i] / V;
        }
        rest = std::min(rest + T, (long double)T * (K + 1));
    }
    printf("%.10Lf\n", time);

    return 0;
}


Measured memory_bytes: 3348
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
#include <tuple>
using namespace std;

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

    double res = 0;

    for (int i = 0; i < n; i++) {
        double x;
        string u;
        cin >> x >> u;
        if (u == "JPY") res += x;
        else res += x * 380000;
    }

    cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI acos(-1)
#define e 2.718281828459
using namespace std;
const int maxn = 1e4 + 5;
typedef long long ll;

int n;
double a[55];


int main()
{
	cin >> n;
	for(int i = 0; i < n; i ++)
		scanf("%lf",&a[i]);
	sort(a, a + n);
	for(int i = 0; i < n - 1; i ++)
		a[i + 1] = (a[i] + a[i + 1]) / 2;
	cout << a[n - 1] << endl;
	return 0;
}


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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define IINF (INT_MAX)
#define MAX 200

using namespace std;

struct Data{
  int from,to,cost,index;
  Data(int from=-1,int to=-1,int cost=-1,int index=-1):from(from),to(to),cost(cost),index(index){}
};

int V,E;
vector<Data> G[MAX];
bool visited[MAX];

void isconnect(int cur,int &counter,int *ban){
  if(visited[cur])return;
  visited[cur] = true;
  counter++;
  rep(i,G[cur].size()){
    if( ban[0] == G[cur][i].index || ban[1] == G[cur][i].index ) continue;
    isconnect(G[cur][i].to,counter,ban);
  }
}

int main(){
  while(cin >> V >> E,V|E){
    Data *input = new Data[E];
    int mincost = IINF,coef = 0;
    rep(i,V)G[i].clear();
    rep(i,E){
      cin >> input[i].from >> input[i].to >> input[i].cost;
      input[i].index = i;
      if( input[i].cost < 0 ) coef += input[i].cost;
      else {
	G[input[i].from].push_back(input[i]);
	G[input[i].to].push_back(Data(input[i].to,input[i].from,input[i].cost,input[i].index));
      }
    }

    int counter = 0;
    int ban[2] = {-1,-1};
    rep(i,V)visited[i] = false;
    isconnect(0,counter,ban);
    if(counter != V)mincost = min(mincost,coef);

    rep(i,E){
      if( input[i].cost < 0 ) continue;
      rep(j,E){
	if( input[j].cost < 0 ) continue;
	rep(k,V)visited[k] = false;
	ban[0] = i, ban[1] = j;
	counter = 0;
	isconnect(0,counter,ban);
	if( counter != V )mincost = min(mincost,coef+input[i].cost+((i==j)?0:input[j].cost));
      }
    }
    cout << mincost << endl;

    delete [] input;
  }
  return 0;
}

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

#define Omar45 ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define pb push_back
#define F first
#define S second
#define endl '\n'
#define mod 1e9 + 7
const ll maxN = 1e5 + 5;
const int INF = 0x3f3f3f3f;

int n, m, ans, dp[maxN];
vector <int> g[maxN];

int dfs(int x){
    int _max=0;
    for(auto it: g[x]){
        if(dp[it]+1)
            _max = max(_max, dp[it]+1);
        else
            _max = max(_max, dfs(it)+1);
    }
    return dp[x] = _max;
}

int main() {
	Omar45
    cin >> n >> m;
    for (int i=0; i<m; i++){
        int u, v;
        cin >> u >> v;
        g[u].pb(v);
    }
    memset(dp, -1, sizeof dp);
    for (int i=1; i<=n; i++) {
        if (dp[i]==-1)
            dfs(i);
        ans = max(ans,dp[i]);
    }
    cout << ans;
}

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

using namespace std;

int main(){
  int array[4] = {0,0,0,0};
  string ans = "YES";
  for(int i = 0; i < 6 ; i++){
    int t = 0;
    cin >> t;
    array[t-1] += 1;
  }
  for(int i = 0; i < 4 ;i ++){
    if(array[i] > 2){
      ans = "NO";
    }
  }
  cout << ans << endl;

}


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

#define LL long long
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VL vector<LL>
#define VVL vector<vector<LL>>
#define VVVL vector<vector<vector<LL>>>
#define VB vector<bool>
#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define EPS 1e-14

template<class T> T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> void print(T x) { std::cout << x << std::endl; }

const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy = { 0, -1, 0, 1 }, dx = { 1, 0, -1, 0 };    // 4近傍（右, 下, 左, 上）

using namespace std;


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

    vector<LL> v, odd;

    FOR(n, 1, 200) {
        LL num = n * (n + 1) * (n + 2) / 6;
        v.emplace_back(num);
        if (num % 2 != 0) {
            odd.emplace_back(num);
        }
    }

    VI dp(1000001, INT_MAX), dp_odd(1000001, INT_MAX);
    dp[0] = 0;
    dp_odd[0] = 0;


    FOR(i, 0, dp.size()) {
        FOE(num, v) {
            if (dp[i] != INT_MAX and i + num < dp.size()) {
                dp[i + num] = min(dp[i + num], dp[i] + 1);
            }
        }
    }
    FOR(i, 0, dp_odd.size()) {
        FOE(num, odd) {
            if (dp_odd[i] != INT_MAX and i + num < dp_odd.size()) {
                dp_odd[i + num] = min(dp_odd[i + num], dp_odd[i] + 1);
            }
        }
    }

    while (true) {
        int n;
        cin >> n;
        if (n == 0) { break; }

        cout << dp[n] << " " << dp_odd[n] << endl;
    }

}




Measured memory_bytes: 10640
#include"bits/stdc++.h"
#define rep(i,n) for(ll i=0;i<n;++i)
#define ALL(x) x.begin(),x.end()

using namespace std;
typedef long long ll;

template<typename T>
T gcd(T a, T b) {
    if (a % b == 0) {
        return(b);
    }
    else {
        return(gcd(b, a % b));
    }
}

template<typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

int main(void) {
    string s;
    cin >> s;
    ll n = 0;
    for (char c : s) {
        n += c - '0';
    }
    if (n % 9 == 0) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }
}

/*
*/


Measured memory_bytes: 3684
void main() {
	(ri < 1200 ? "ABC" : "ARC").writeln;
}

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

import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#define For(i,a,b) for(int i=(a); i<(b); i++)
using namespace std;

const double pi=3.1415926;

int main(){
	double r;
	cin>>r;
	cout<<2*pi*r;
	return 0;
}

Measured memory_bytes: 3792
// in the name of Allah

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

#define endl '\n'
#define pb push_back
#define ll long long
#define double long double
#define sz(x) ((int) (x.size()))

#define fr first
#define se second

const ll mod = 1000000009;

inline ll add(ll a, ll b) {
	a += b;
	if(a >= mod) return a - mod;
	return a;
}

inline ll mul(ll a, ll b) {
	a *= b;
	if(a >= mod) return a % mod;
	return a;
}

inline ll power(ll a, ll b) {
	ll p = 1;
	while(b) {
		if(b&1) p = mul(p, a);
		a = mul(a, a);
		b /= 2;
	}
	return p;
}

const int N = 1e5 + 5;

int co[N];
vector < pair <int, int> > g[N];

void dfs(int u, int p, int c) {
	co[u] = c;
	for(auto e : g[u]) {
		int v = e.fr;
		if(v == p) continue;
		int w = e.se;
		if(w&1) {
			dfs(v, u, (c == 0));
		}
		else {
			dfs(v, u, c);
		}
	}
}

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

	int n, a, b, w;
	cin >> n;
	for(int i=1; i<n; i++) {
		cin >> a >> b >> w;
		g[a].pb({b, w});
		g[b].pb({a, w});
	}
	dfs(1, 0, 0);
	for(int i=1; i<=n; i++) cout << co[i] << endl;

	return 0;
}

Measured memory_bytes: 8448
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int n_copy = n;
    int r = 0;

    while(n_copy > 0){
      r += n_copy % 10;
      n_copy /= 10;
    }

    if(n % r == 0){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }

  }
}


Measured memory_bytes: 22868
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
using namespace std;

int main() {
  int a[3] = {0}, b[3] = {0}, c[3][3];
  bool exist = false;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) cin >> c[i][j];
  }
  for (a[0] = 0; a[0] <= c[0][0]; a[0]++) {
    for (int i = 0; i < 3; i++) b[i] = c[0][i] - a[0];
    for (int i = 1; i < 3; i++) a[i] = c[i][0] - b[0];
    int counter = 0;
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        if (c[i][j] == a[i] + b[j]) counter++;
        if (counter == 9) exist = true;
      }
    }
  }
  cout << (exist ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 256
N, K  = map(int, input().split())
hn = list(map(int,input().split() ) )
# カエルがi番目からi+j番目に到着するには
# dp[i+j] = min(dp[i]+abs(hn[i+j] - hn[i]) + , dp[i+j])
dp = [10**10] * (N)
dp[0] = 0
dp[1] = abs(hn[0]-hn[1])
for i in range(N):
    for j in range(1,K+1):
        if i + j < N:
            dp[i+j] = min(dp[i] + abs(hn[i+j] - hn[i]), dp[i+j])

print(dp[N-1])

Measured memory_bytes: 52448
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class AtCoderr
    {
        static void Main(string[] args)
        {
            long[] s = ReadLine().Split(' ').Select(long.Parse).ToArray();
            long a = s[0];
            long b = s[1];

            WriteLine(
                a <= 9 && b <= 9 ? a*b : -1
                );
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
const int N = 2e5 + 10;
int a[N], need[N], need2[N];
LL sum[N][2];
int main() {
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", a + i);
	for (int i = 2; i <= n; i++) {
		LL t1 = a[i - 1], t2 = a[i];
		if (t1 < t2) swap(t1, t2);
		while (t1 > t2) {
			t2 *= 4;
			need[i]++;
		}
	}
	for (int i = 2; i <= n; i++) {
		LL t1 = a[i - 1], t2 = a[i];
		if (t1 < t2) swap(t1, t2);
		while (t1 >= t2) {
			t2 *= 4;
			need2[i]++;
		}
	}
	vector<PII> v;
	//for (int i = 1; i <= n; i++) cout << need[i] << endl;
	v.emplace_back(n + 1, (int)2e9);
	for (int i = n - 1; i >= 1; i--) {
		sum[i][1] = sum[i + 1][1];
		if (a[i] > a[i + 1]) {
			int tmp = need[i + 1];
			int pos = i + 1;
			while (v.back().second <= tmp) {
				//cout << v.back().first << v.back().second << endl;
				sum[i][1] += 1LL * (v.back().first - pos) * tmp;
				pos = v.back().first;
				tmp -= v.back().second - 1;
				v.pop_back();
			}
			v.back().second -= tmp;
			sum[i][1] += 1LL * (v.back().first - pos) * tmp;
		} else {
			v.emplace_back(i + 1, need2[i + 1]);
		}
		//cout << i << ' ' << sum[i][1] << endl;
	}
	for (int i = 1; i <= n; i++) a[i] *= 2;
	//for (int i = 1; i <= n; i++) cout << need[i] << endl;
	v.clear();
	v.emplace_back(0, (int)2e9);
	for (int i = 2; i <= n; i++) {
		sum[i][0] = sum[i - 1][0];
		if (a[i] > a[i - 1]) {
			int tmp = need[i];
			int pos = i - 1;
			while (v.back().second <= tmp) {
				sum[i][0] += 1LL * (pos - v.back().first) * tmp;
				pos = v.back().first;
				tmp -= v.back().second - 1;
				v.pop_back();
			}
			v.back().second -= tmp;
			sum[i][0] += 1LL * (pos - v.back().first) * tmp;
		} else {
			v.emplace_back(i - 1, need2[i]);
		}
		//cout << sum[i][0] << ' ' << i << endl;
	}
	LL ans = 1e18;
	for (int i = 0; i <= n; i++) {
		ans = min(ans, sum[i][0] * 2 + i + sum[i + 1][1] * 2);
		if (ans == 7) {
			//cout << i << endl;
			//cout << sum[i][0] * 2 << ' ' << sum[i + 1][1] << endl;
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 7924
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;


int main(){

    int N;
    cin >> N;
    string s;
    cin >> s;
    int c = 0;
    for(int i=0;i<N-2;i++) {
        if(s.substr(i,3) == "ABC") c++;
    }
    cout << c << endl;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
s = input()
if set(list(s)) == 1:
    print(n)
    exit

s = '0' + s + '0'
list_ones = []
for i in range(1, n+1):
    if s[i-1] == '0' and s[i] == '1':
        i_start = i
    if s[i] == '1' and s[i+1] == '0':
        i_end = i
        list_ones.append((i_start, i_end))
list_ones = [(1, 1)] + list_ones + [(n, n)]
# print(list_ones)

ans = 0
for j, (i_start, _) in enumerate(list_ones):
    j_end = min(len(list_ones)-1, j+k)
    _, i_end = list_ones[j_end]
    ans = max(ans, i_end-i_start+1)
print(ans)


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

int main(){
	//Make the code faster
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	//Declaring the vars
	int shift;
	string c;
	
	cin >> shift >> c;
	
	for(int i = 0; i < c.size(); ++i){
		cout << (char) ((c[i] + shift - 'A') %26 + 'A');
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Weverything"
//#include <boost/multi_array.hpp>
//#include <boost/optional.hpp>
//#include <boost/range/adaptors.hpp>
//#include <boost/range/algorithm.hpp>
//#include <boost/range/irange.hpp>
#pragma clang diagnostic pop

using namespace std;

struct restaurant_t {
  std::string name;
  int point;
  int idx;
};

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int64_t n;
  std::cin >> n;
  std::vector<restaurant_t> rs(n);
  for (int i = 0; i < n; i++) {
    std::cin >> rs[i].name;
    std::cin >> rs[i].point;
    rs[i].idx = i + 1;
  }
  std::sort(rs.begin(), rs.end(), [](const auto& lhs, const auto& rhs) {
    if (lhs.name < rhs.name) {
      return true;
    }
    if (lhs.name > rhs.name) {
      return false;
    }
    return lhs.point > rhs.point;
  });
  for (const auto& res : rs) {
    std::cout << res.idx << std::endl;
  }
  return 0;
}


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

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin, n;
    vector<int> arr(n, 0);
    for (ll x = 1; x * x <= n; x++) {
        for (ll y = 1; y * y <= n; y++) {
            for (ll z = 1; z * z <= n; z++) {
                ll t = x * x + y * y + z * z + x * y + y * z + z * x;
                if (t <= 0 || t > n) continue;
                arr[t - 1]++;
            }
        }
    }
    REP(i, 0, n) {
        print(arr[i]);
    }
    return 0;
}


Measured memory_bytes: 3596
{-# LANGUAGE BangPatterns      #-} --引数に!
{-# LANGUAGE MultiWayIf        #-}
{-# LANGUAGE TupleSections     #-}

import Data.List
import Data.Array
import Data.Array.MArray
import Data.Array.ST
import qualified Data.Vector.Unboxed as V (last,(!),fromList,Vector)
import Control.Monad
import Control.Monad.State
import Control.Monad.ST
import Debug.Trace

type Table = Array Int [Int] -- True == White, x <= y
type DP s = STUArray s (Bool,Int) Int

--TLE!!!
--DFS
dp_i :: DP s -> Table -> Int -> Int -> Int -> ST s ()
dp_i dparr table n prev v = do
  let nh = filter (/=prev) (table!v)
  if nh == []
      then forM_ [False,True] $ \c -> writeArray dparr (c,v) 1
      else do
        ls <- forM nh $ \v' -> do
          dp_i dparr table n v v'
          nextF <- readArray dparr (False,v')
          nextT <- readArray dparr (True,v')
          return (nextT+nextF,nextT)
        let ls' = foldl1' (\(a,b) (c,d) -> (mod0 $ a*c,mod0 $ b*d)) ls
        writeArray dparr (False,v) $ mod0 $ snd ls'
        writeArray dparr (True,v)  $ mod0 $ fst ls'

setArr :: Int -> [(Int,Int)] -> Table
setArr n xs = runST $ do
  arr <- newArray (1,n) [] :: ST s (STArray s Int [Int])
  setArrsub arr xs >>= freeze
    where
      setArrsub :: (STArray s Int [Int]) -> [(Int,Int)] -> ST s (STArray s Int [Int])
      setArrsub arr' [] = return arr'
      setArrsub arr' ((a,b):as) = do
        readArray arr' a >>= (writeArray arr' a).(b:)
        readArray arr' b >>= (writeArray arr' b).(a:)
        setArrsub arr' as

solve :: [(Int,Int)] -> Int -> ST s Int
solve ls n = do
  let table = setArr n ls
  dparr  <- newArray ((False,1),(True,n)) 0
  dp_i dparr table n (-1) 1
  ans0 <- forM [False,True] $ \c -> readArray dparr (c,1)
  return $ mod0 $ sum ans0


main :: IO ()
main = do
   n <- read <$> getLine
   ls <- replicateM (n-1) $ do
     (x:y:_) <- map read.words <$> getLine
     return (x,y)
   putStrLn $ show $ runST $ solve ls n

mod0 :: Int -> Int
mod0 n = if n < 1000000007 then n else mod n 1000000007


Measured memory_bytes: 93052
#include<iostream>
using namespace std;
#define ll long long
ll arr[3005][3005];
ll dp[3005][3005][4];
ll n;
ll m;
ll k;
ll solve(ll i,ll j,ll p) {
    if(dp[i][j][p]!=-1)
        return dp[i][j][p];
    if(i>n || j>m)
        dp[i][j][p]=0;
    else if(p==3)
        dp[i][j][p]=solve(i+1,j,0);
    else if(j==m && i==n)
        dp[i][j][p]=arr[i][j];
    else if(j==m)
        dp[i][j][p]=arr[i][j]+
                    solve(i+1,j,0);
    else if(i==n) dp[i][j][p]=max(arr[i][j]+ solve(i,j+1,p+1),solve(i,j+1,p));
    else {
        ll a,b,c,d;
        a=arr[i][j]+solve(i+1,j,0);
        b=arr[i][j]+solve(i,j+1,p+1);
        c=solve(i,j+1,p);
        dp[i][j][p]=max(a,max(b,c));
    }
    return dp[i][j][p];
}
int main() {
    cin>>n>>m>>k;
    for(int i=1; i<=n; i++)
        for(int j=1; j<=m; j++)
            for(int p=0; p<=3; p++)
                dp[i][j][p]=-1;
    while(k--) {
        ll i,j,v;
        cin>>i>>j>>v;
        arr[i][j]=v;
    }
    cout<<solve(1,1,0)<<endl;
    return 0;
}


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

int main() {
  int X, Y;
  cin >> X >> Y;
  bool b = false;
  for(int i = 0; i < 100; i++) {
    for(int j = 0; j < 100; j++) {
    if(i+j == X && 2*i + 4*j == Y) {
      b = true;
      break;
    }
  }
  }
  if(b) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


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

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long pw = 1;
		for(int i=1;i<=N;i++) {
			pw *= i;
			pw %= (Math.pow(10,9)+7);
		}
		System.out.println(pw);
	}

}

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

int n, k;
string s;

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

    string t = s;
    reverse(t.begin(), t.end());

    s += t;

    string ans;
    ans.append(n, 'z');
    for(int i=0; i<=n; i++) {
        t = s.substr(i, n);
        ans = min(ans, t);
    }

    int cnt = 0;
    for(int i=0; i<ans.size(); i++) {
        if(ans[i] == ans[0]) cnt++;
        else break;
    }
    int st = cnt;

    for(int i=1; i<k; i++) {
        cnt *= 2;
        if(cnt > n) break;
    }

    for(int i=0; i<cnt && i < n; i++) {
        cout << ans[0];
    }

    for(int i = st; i - st + cnt < n; i++)
        cout << ans[i];
}


Measured memory_bytes: 256
import numpy as np

N = int(input())
A = list(map(int, input().split()))

A = np.array(A)
mod = 10 ** 9 + 7
ans = 0
for i in range(60):
    b = np.count_nonzero(A >> i & 1)
    ans += 2 ** i * b * (N - b)
    ans %= mod
print(ans)


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

using namespace std;

int N;
int Score[100];

void solve() {
	int maxScore;

	maxScore = 0;
	for (int i = 0; i < N; ++i) {
		//cout << "curScore:" << Score[i] << " <=:" << N-i << endl;
		maxScore = max(maxScore,min(Score[i], N - i));
	}
	cout << maxScore << endl;
}

int main() {

	memset(Score, 0, sizeof(Score));
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> Score[i];
	}
	sort(Score, Score + N);
	solve();

	return 0;
}



Measured memory_bytes: 3156