akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define PII pair<int, int>
#define PLL pair<LL, LL>
#define VI vector<int>
#define VPII vector<PII>
#define LL long long
#define LD long double
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define pb pop_back
#define ALL(c) (c).begin(), (c).end()
#define SIZ(c) (int)(c).size()
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, b, e) for(int i = (b); i <= (int)(e); ++i)
#define FORD(i, b, e) for(int i = (b); i >= (int)(e); --i)

#define Sim template<class n
Sim, class s> ostream & operator << (ostream &p, pair<n, s> x)
{return p << "<" << x.f << ", " << x.s << ">";}
Sim> auto operator << (ostream &p, n y) -> 
typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type 
{int o = 0; p << "{"; for(auto c: y) {if(o++) p << ", "; p << c;} return p << "}";}
void dor() {cerr << endl;}
Sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);}
Sim, class s> void mini(n &p, s y) {if(p>y) p = y;}
Sim, class s> void maxi(n &p, s y) {if(p<y) p = y;}
#ifdef DEB
#define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__)
#else
#define debug(...)
#endif 

#define I(x) #x " = ", (x), " "
#define A(a, i) #a "[" #i " = ", i, "] = ", a[i], " "
const int M = 1024;

int n;
VI R;

int main()
{
	//ios_base::sync_with_stdio(0);
	//cin.tie(NULL);
	scanf("%d", &n);
	VI V;
	FOR(i, 1, n)
	{
		int a;
		scanf("%d", &a);
		V.PB(a);
	}
	while (!V.empty())
	{
		debug(V);
		bool boo = false;
		FORD(i, SIZ(V) - 1, 0)
		{
			if (V[i] == i + 1)
			{
				R.PB(i + 1);
				V.erase(V.begin() + i);
				boo = true;
				break;
			}
		}
		if (!boo)
		{
			printf("-1\n");
			return 0;
		}
	}
	reverse(ALL(R));
	for (auto x : R)
	{
		printf("%d\n", x);
	}
	return 0;
}

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

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

    int num[26] = {0};
    for (int i = 0; i < w.size(); i++)
    {
        num[w[i] - 'a']++;
    }

    for (int i = 0; i < 26; i++)
    {
        if (num[i] % 2 == 1)
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// atoi : atoi(変数名.c_str())
// to_string(数値)
// %0桁数d とすると表示桁数が「桁数」に満たない場合に0埋めされる
// find(): int i = 変数名.find(“文字列”) 何番目にあるかを得る
// cout << (条件 ? "Yes" : "No") << endl;
// printf("%02d:%02d:%02d",hour,minute,second);
// 降順 sort(a.begin(),a.end(),greater<int>());
// bitset<ビット数> 変数名;  // すべてのビットが0の状態で初期化される
// bitset<ビット数> 変数名("ビット列");  // 指定したビット列で初期化される
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)

int main(){
  int x,y,z;
  cin >> x >> y >> z;
  cout << (x-z) / (y+z) << endl;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

next = []
while(1):

    A.sort()
    m = A[0]
    next = []
    for x in A:
        if x % m:
            next.append(x % m)
    next.append(m)
    if next[0] == next[-1]:
        break
    A = list(next)
print(next[0])


Measured memory_bytes: 64408
import math
def isPrime(x):
	if(x<2):
		return False
	else:
		for i in range(2,int(math.sqrt(x)//1)+1):
			if(x%i==0):
				return False
		return True

n=int(input())
ans=0
for i in range(n):
	a=int(input())
	if(isPrime(a)):
		ans+=1
print(ans)


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

int a[5];

int main(){
    for(int i = 0; i < 3; i++){
        int c, b;
        cin >> b >> c;
        a[b]++, a[c]++;
    }
    int b = 0, c = 0;
    for(int i = 1; i <= 4; i++){
        if(a[i] == 1)b++;
        if(a[i] == 2)c++;
    }
    if(b == 2 && c == 2) cout << "YES\n";
    else cout << "NO\n";
    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
#include<map>
using namespace std;


int main() {
    int a, b;
    cin >> a >> b;
    int r = 0;
    for(int i = 0; i < a; i++){
        r += i;
    }   
    for(int i = 0; i < b; i++){
        r += i;
    }     
    cout << r;
    cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define S second
#define F first

using namespace std;
typedef long long ll;
#define int ll
typedef pair<int,int> pii;
const int maxn = 200 + 4;
const int mod = 1e9 + 7;
const int maxk = 2;
int dp[3][maxn],table[3][maxn];
int32_t main(){
    int n;
    cin >> n;
    for (int i = 1;i <= 2;i++){
        for (int j = 1;j <= n;j++){
            cin >> table[i][j];
        }
    }
    for (int i= 1;i <= 2;i++){
        for (int j = 1;j <= n;j++){
            dp[i][j] = max(dp[i - 1][j],dp[i][j - 1]) + table[i][j];
        }
    }
    cout << dp[2][n] << endl;
    return 0;
}


Measured memory_bytes: 256
using namespace std;
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

#define INF INT_MAX/3

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define dump(x)  cerr << #x << " = " << (x) << endl;

#define MAX_N 800

long long dp[MAX_N][2];
int N;

struct Edge {
  int dest;
  int length;
};

vector<Edge> Graph[MAX_N];

long long dfs(int start, int from, int is_round_trip) {
  if( dp[start][is_round_trip] >= 0 ) {
    return dp[start][is_round_trip];
  }

  long long ret = 0;
  int sz = Graph[start].size();
  REP(i, sz) {
    Edge e = Graph[start][i];
    if( e.dest == from ) {
      continue;
    }

    dfs(e.dest, start, 0);
    dfs(e.dest, start, 1);

    if( Graph[e.dest].size() == 1 ) {
      ret += e.length;
      continue;
    }

    ret += e.length + dp[e.dest][1] + e.length + e.length;
  }

  if( is_round_trip ) {
    dp[start][is_round_trip] = ret;
    return ret;
  }

  long long delta = 0;
  REP(i, sz) {
    Edge e = Graph[start][i];
    if( e.dest == from ) {
      continue;
    }

    if( Graph[e.dest].size() == 1 ) {
      continue;
    }
    delta = min(delta, dp[e.dest][0] - dp[e.dest][1] - e.length);
  }
  ret += delta;
  dp[start][is_round_trip] = ret;
  return ret;
}

long long solve1() {
  long long ans = 100000 * 800 * 3;
  REP(i, N) {
    memset(dp, -1, sizeof(dp));
    ans = min(ans, dfs(i, -1, 0));
  }
  return ans;
}

int load() {
  scanf("%d", &N);
  if( !N ) return 0;

  int Ps[MAX_N];
  int Ds[MAX_N];

  FOR(i, 1, N) {
    scanf("%d", &Ps[i]);
    --Ps[i];
  }
  FOR(i, 1, N) {
    scanf("%d", &Ds[i]);
  }

  REP(i, N) {
    Graph[i].clear();
  }

  FOR(i, 1, N) {
    int p = Ps[i];
    int d = Ds[i];
    Edge e;
    e.dest = p;
    e.length = d;
    Graph[i].push_back(e);
    e.dest = i;
    Graph[p].push_back(e);
  }
  return 1;
}


int main() {
  while(load()) {
    long long ans = solve1();
    printf("%lld\n", ans);
  }
  return 0;
}

Measured memory_bytes: 1396
using System;
using System.Collections;
using System.Collections.Generic;
 
class TEST{
	static void Main(){
		while(true){
			var d=Console.ReadLine().Split(' ');
			if(int.Parse(d[0])==0&&int.Parse(d[1])==0)break;
			Sol mySol =new Sol(int.Parse(d[0]),int.Parse(d[1]));
			mySol.Solve();
		}
	}
}

class Sol{
	public void Solve(){
		List<Pair> L=new List<Pair>();
		for(int i=0;i<H;i++){
			var d=rsa();
			for(int j=0;j<W;j++){
				if(int.Parse(d[j])==1)L.Add(new Pair(i,j));
			}
		}
		L.Sort((p,q)=>p.X>q.X?1:(p.X<q.X?-1:0));
		int N=L.Count;
		List<Pair> NotEat =new List<Pair>();
		NotEat.Add(L[0]);
		
		for(int i=1;i<N;i++){
			//プリム法 （っぽい感じ）
			//次のポイントへのマンハッタン距離の一番近いものを選ぶ
			//同じマンハッタン距離なら、Xの大きいものを選ぶ
			//NotEatには後ろに行くほどXの大きいものが入っている
			Pair P=new Pair(-1,-1);
			int mhMax=99999;
			for(int j=0;j<NotEat.Count;j++){
				if(Math.Abs(NotEat[j].X-L[i].X)+Math.Abs(NotEat[j].Y-L[i].Y)<=mhMax){
					mhMax=Math.Abs(NotEat[j].X-L[i].X)+Math.Abs(NotEat[j].Y-L[i].Y);
					P=NotEat[j];
				}
			}
			//上行ってから左右に行く
			for(int j=1;P.X+j<=L[i].X;j++){
				NotEat.Add(new Pair(P.X+j,P.Y));
			}
			int direction=L[i].Y-P.Y;
			if(direction==0)continue;
			if(direction>0){
				for(int j=1;P.Y+j<=L[i].Y;j++){
					NotEat.Add(new Pair(L[i].X,P.Y+j));
				}
			}
			if(direction<0){
				for(int j=-1;P.Y+j>=L[i].Y;j--){
					NotEat.Add(new Pair(L[i].X,P.Y+j));
				}
			}
		}
		int ans1=H*W-NotEat.Count;

		
		L.Sort((p,q)=>p.Y>q.Y?1:(p.Y<q.Y?-1:0));
		N=L.Count;
		NotEat =new List<Pair>();
		NotEat.Add(L[0]);
		
		for(int i=1;i<N;i++){
			//Yについてもやってみる（どっちかで答えが得られるのでは？）
			Pair P=new Pair(-1,-1);
			int mhMax=99999;
			for(int j=0;j<NotEat.Count;j++){
				if(Math.Abs(NotEat[j].X-L[i].X)+Math.Abs(NotEat[j].Y-L[i].Y)<=mhMax){
					mhMax=Math.Abs(NotEat[j].X-L[i].X)+Math.Abs(NotEat[j].Y-L[i].Y);
					P=NotEat[j];
				}
			}
			//右行ってから上下に行く
			for(int j=1;P.Y+j<=L[i].Y;j++){
				NotEat.Add(new Pair(P.X,P.Y+j));
			}
			int direction=L[i].X-P.X;
			if(direction==0)continue;
			if(direction>0){
				for(int j=1;P.X+j<=L[i].X;j++){
					NotEat.Add(new Pair(P.X+j,L[i].Y));
				}
			}
			if(direction<0){
				for(int j=-1;P.X+j>=L[i].X;j--){
					NotEat.Add(new Pair(P.X+j,L[i].Y));
				}
			}
		}
		int ans2=H*W-NotEat.Count;		
		Console.WriteLine("{0}",Math.Max(ans1,ans2));

	}
	
	int H;
	int W;
	public Sol(int h_,int w_){
		H=h_;W=w_;
	}

	struct Pair{
		public int X;
		public int Y;
		public Pair(int x_,int y_){
			X=x_;Y=y_;
		}
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(){return Console.ReadLine().Split(' ');}
	static int[] ria(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>int.Parse(e));}
	static long[] rla(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>long.Parse(e));}
	static double[] rda(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>double.Parse(e));}
}

Measured memory_bytes: 5824
#include <bits/stdc++.h>
using namespace std;
int n,frst,cnt[100005];
vector<int> son[100005];
vector<int> st;
void dfs(int v,int p)
{
	cnt[v]=1;
	st.push_back(v);
	if (v==n-1)
		frst=st[(st.size()+1)/2];
	for(int	i=0;i<son[v].size();i++)
	{
		int to=son[v][i];
		if (to==p)
			continue;
		dfs(to,v);
		cnt[v]+=cnt[to];
	}
	st.pop_back();
}
int main()
{
	cin>>n;
	for(int i=0;i<n-1;i++)
	{
		int a,b;
		cin>>a>>b;
		a--;b--;
		son[a].push_back(b);
		son[b].push_back(a); 
	}
	dfs(0,0);
	bool win=(cnt[frst]*2<n);
	string ans=(win?"Fennec":"Snuke");
	cout<<ans;
	return 0;
}

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

#define pb push_back
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define MAXN 10005
#define MAXM 100005
#define pi 3.14159265359

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int>> vpii;
typedef long long ll;
typedef priority_queue<int> pqi;
typedef priority_queue<pii, vpii, greater<pii> > dij;

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

	ll N, sum = 0;

	cin >> N;

	for(int i = 1 ; i <= N; i++){
		if(i%3 != 0 and i%5 != 0)
			sum += i;
	}

	cout << sum << "\n";
	return 0;		
}

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

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) {
        freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);
        //freopen("d:\\code\\cpp\\contests\\stdout", "w", stdout);
    }

    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    FOR(i, n){
        cout << s[i] << t[i];
    }

    if (argc == 2 && atoi(argv[1]) == 123456789)        cerr << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

  int n;
  string s;
  cin >> n >> s;

  int ans = 0;

  int x = 0;
  for (int i = 0; i < n; i++) {
    char c = s[i];

    if (c == 'I') {
      ++x;
    } else {
      --x;
    }

    ans = max(ans, x);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
/*
 * 2362.cc: Chicken or the Egg
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

typedef vector<int> vi;

/* global variables */

/* subroutines */

/* main */

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

  vi cs;
  for (int i = 0; i < s.size();) {
    if (s[i] == 'e') cs.push_back(0), i += 3;
    else cs.push_back(1), i += 7;
  }
  //for (int i = 0; i < cs.size(); i++) printf("%d", cs[i]); putchar('\n');

  int prv = -1, k = -1, maxk = -1, maxc = -1;

  for (int i = 0; i < cs.size(); i++) {
    if (prv == cs[i]) k = -1;
    k++;
    if (maxk < k) {
      maxk = k;
      maxc = cs[i];
    }
    prv = cs[i];
  }

  cout << (maxc == 0 ? "egg" : "chicken") << endl;
  return 0;
}

Measured memory_bytes: 1216
import math

buf = input().split()

a = float(buf[0])
b = float(buf[1])
C = float(buf[2])

S = a * b * math.sin(math.radians(C)) / 2
L = a + b + math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(C)))
h = b * math.sin(math.radians(C))

print(S)
print(L)
print(h)



Measured memory_bytes: 5692
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

#define max(x, y) ((x)>(y)?(x):(y))
#define min(x, y) ((x)<(y)?(x):(y))

Int dp[10800][2][108];
string k;
Int d;

int main(){
  cin >> k >> d;
  dp[0][1][0] = 1;
  for(int i = 0;i < k.size();i++){
    int now = (int)(k[i] - '0');
    for(int j = 0;j < d;j++){
      (dp[i+1][1][(j + now) % d] += dp[i][1][j]) %= MOD;
      for(int l = 0;l < 10;l++){
	(dp[i+1][0][(j+l) % d] += dp[i][0][j]) %= MOD;
	if(l < now){
	  (dp[i+1][0][(j+l) %d] += dp[i][1][j]) %= MOD;
	}
      }
    }
  }
  cout << (dp[k.size()][0][0] + dp[k.size()][1][0] + MOD - 1) % MOD << endl;
  return 0;
}

Measured memory_bytes: 17152
def solve(n, debug=0):
    m = 1000
    r = n % m
    return 0 if r == 0 else m - r


def main(istr, ostr):
    n = int(istr.readline())
    print(solve(n), file=ostr)


if __name__ == "__main__":
    import sys

    main(sys.stdin, sys.stdout)


Measured memory_bytes: 9060
H, W = map(int, input().split())
sl = [input() for _ in range(H)]

ans = "Yes"
for i, s in enumerate(sl):
    for j, p in enumerate(s):
        if sl[i][j] == ".":
            continue
        up_s = sl[i - 1][j] if i - 1 >= 0 else ""
        down_s = sl[i + 1][j] if i + 1 < H else ""
        left_s = sl[i][j - 1] if j - 1 >= 0 else ""
        right_s = sl[i][j + 1] if j + 1 < W else ""
        if "#" in [up_s, down_s, left_s, right_s]:
            continue
        ans = "No"
        break
    if ans == "No":
        break

print(ans)


Measured memory_bytes: 67784
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;
ll v[100][100];
ll ab[100][4];
ll ans=0;
ll n,m,q;

void dfs(vector<int> a){
    if(a.size()==n+1){
        ll now=0;
        for(int i=0;i<q;i++){
            if(a[ab[i][1]]-a[ab[i][0]]==ab[i][2]) now+=ab[i][3];
        }
        ans=max(ans,now);
        return;
    }

    a.push_back(a.back());
    while(a.back()<=m){
        dfs(a);
        a.back()++;
    }
}

int main(){
    cin>>n>>m>>q;
    for(int i=0;i<q;i++){
        cin>>ab[i][0]>>ab[i][1]>>ab[i][2]>>ab[i][3];
    }
    vector<int> a(1,1);
    dfs(a);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define LL long long
int n;
const int N = 300000;
const LL INF = 1e15;
#define pI pair <LL, int>
#define fr first
#define sc second
#define mp make_pair
int xi[N];
vector <int> bi[N], ci[N];
int fp[N];
int get_fp(int a)
{
    if (fp[a] == a) return a;
    else return fp[a] = get_fp(fp[a]);
}
struct PP
{
    pI a, b;
} O, edge[N], F[N], tmp[N], U[N];
LL ans;
PP merge(PP x, PP y)
{
    PP z;
    if (x.a > y.a) swap(x, y);
    z.a = x.a;
    if (x.a.sc == y.a.sc)
        if (x.a.sc == y.b.sc)
            z.b = x.b;
        else if (x.b < y.b)
            z.b = x.b;
        else z.b = y.b;
    else if (x.b < y.a)
        z.b = x.b;
    else z.b = y.a;
    return z;
}
PP ADD(PP x, int v)
{
    return (PP){mp(x.a.fr + v, x.a.sc), mp(x.b.fr + v, x.b.sc)};
}
PP dfs1(int t, int f)
{
    F[t] = O; F[t].a = mp(xi[t], get_fp(t));
    for (int i = 0; i < bi[t].size(); ++ i)
        if (bi[t][i] != f)
        {
            PP res = ADD(dfs1(bi[t][i], t), ci[t][i]);
            F[t] = merge(F[t], res);
        }
    edge[get_fp(t)] = merge(edge[get_fp(t)], ADD(F[t], xi[t]));
    return F[t];
}
void dfs2(int t, int f, PP u)
{
    edge[get_fp(t)] = merge(edge[get_fp(t)], ADD(u, xi[t]));
    tmp[bi[t].size()] = O;
    for (int i = bi[t].size() - 1; ~i; -- i)
    {
        tmp[i] = tmp[i + 1];
        if (bi[t][i] != f) tmp[i] = merge(tmp[i], ADD(F[bi[t][i]], ci[t][i]));
    }
    PP p = O; p.a = mp(xi[t], get_fp(t));
    for (int i = 0; i < bi[t].size(); ++ i)
        if (bi[t][i] != f)
        {
            U[bi[t][i]] = ADD(merge(merge(u, p), tmp[i + 1]), ci[t][i]);
            p = merge(p, ADD(F[bi[t][i]], ci[t][i]));
        }
    for (int i = 0; i < bi[t].size(); ++ i)
        if (bi[t][i] != f)
            dfs2(bi[t][i], t, U[bi[t][i]]);
}
int C;
int main()
{
    O = (PP){mp(INF, -1), mp(INF, -2)};
    scanf("%d", &n);
    for (int i = 1; i <= n; ++ i) scanf("%d", &xi[i]);
    for (int i = 1; i < n; ++ i)
    {
        int a, b, c;
        scanf("%d%d%d", &a, &b, &c);
        bi[a].push_back(b); ci[a].push_back(c);
        bi[b].push_back(a); ci[b].push_back(c);
    }
    for (int i = 1; i <= n; ++ i) fp[i] = i;
    while (C < n - 1)
    {
        for (int i = 1; i <= n; ++ i) edge[i] = O;
        dfs1(1, 0);
        dfs2(1, 0, O);
        for (int i = 1; i <= n; ++ i) if (fp[i] == i)
        {
            pI w;
            if (edge[i].a.sc == i) w = edge[i].b;
            else w = edge[i].a;
            if (get_fp(w.sc) != get_fp(i))
            {
                fp[i] = w.sc;
                ans += w.fr;
                C ++;
            }
        }
    }
    printf("%lld\n", ans);
}


Measured memory_bytes: 124800
import java.util.*;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long n = Long.parseLong(sc.next());
    long min = Long.MAX_VALUE;
    List<Long> list  = new ArrayList<>();
    for(long i = 1; i <= 1000000l; i++) {
      if(n%i==0) {
		list.add(i+n/i-2);
      }
      if(n<i)
        break;
    }
    for(Long i : list) {
	  if(i < min) {
        min = i;
      }
    }
    System.out.println(min);
  }
}


Measured memory_bytes: 23252
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
typedef long long ll;
ll mod=998244353;
ll dp[5011][10011];
#define SIZE 100000
ll inv[SIZE+1];
ll kai[SIZE+1];
ll invkai[SIZE+1];
void invinit()
{
	inv[1] = 1;
	for (int i = 2; i <= SIZE; i++)
	{
		inv[i] = mod - (mod / i)*inv[mod%i] % mod;
	}
	kai[0] = invkai[0] = 1;
	for (int i = 1; i <= SIZE; i++)
	{
		kai[i] = kai[i - 1] * i%mod;
		invkai[i] = invkai[i - 1] * inv[i] % mod;
	}
}
ll com(ll a, ll b)
{
	if (b < 0 || a < b)return 0;
	return (invkai[b] * invkai[a - b]) % mod*kai[a] % mod;
}
int main()
{
	string sa,sb;
	cin>>sa>>sb;
	invinit();
	int c1=0,c2=0;
	for(int i=0;i<sa.size();i++)
	{
		if(sa[i]=='0'&&sb[i]=='1')c1++;
		if(sa[i]=='1'&&sb[i]=='1')c2++;
	}
	dp[0][0]=1;
	for(int i=0;i<=c1;i++)
	{
		for(int j=0;j<=c2;j++)
		{
			dp[i+1][j]=(dp[i+1][j]+(ll)(i+1)*(ll)(i+1)*dp[i][j])%mod;
			dp[i][j+1]=(dp[i][j+1]+(ll)(i)*(ll)(j+1)*dp[i][j])%mod;
			//printf("%lld ",dp[i][j]);
		}
		//printf("\n");
	}
	ll ans=0;
	ll t=1;
	for(int i=0;i<=c2;i++)
	{
		ans+=dp[c1][c2-i]*t%mod*com(c1+c2,i)%mod*com(c2,i);
		ans%=mod;
		t*=(i+1)*(i+1);
		t%=mod;
	}
	printf("%lld\n",ans);
}

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

#ifndef ONLINE_JUDGE 
const bool DEBUG = true;
#else
const bool DEBUG = false;
#endif

// Reads a 1D vector
template <class T>
void read1d(vector<T> & arg) {
	const int l = arg.size();
	for (int i = 0; i < l; ++i) cin >> arg[i];
}

void read() {}
// Reads arbitrary values
template <class T1, class... T2>
void read(T1& var1, T2&... var2) { cin >> var1; read(var2...); }



void pln() { cout << (DEBUG ? "]\n" : "\n"); }
template <class T1, class... T2>
void pln(const T1& var1, const T2& ... var2) { cout << var1 << " "; pln(var2...); }

// Prints arbitrary values and goes to next line
template <class T1, class... T2>
constexpr void print(const T1& var1, const T2& ... var2) { cout << (DEBUG ? " [ " : ""); pln(var1, var2...); }

// Prints arbitrary values and goes to next line ONLY IF IN DEBUG MODE
template <class T1, class... T2>
constexpr void debug(const T1& var1, const T2& ... var2) { if (!DEBUG) return;  cout << " debug : [ "; pln(var1, var2...); }





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


#define all(x) begin(x), end(x)

const bool MULTIPLE_TEST_CASES = 0;


void exec() 
{
	int n;
	string s;
	read(n, s);

	int lptr = 0, rptr = n - 1;

	int rs = 0, ws = 0;
	for (char c : s) {
		rs += (c == 'R');
		ws += (c == 'W');
	}
	if (rs * ws == 0) { print(0); return; }

	int score = 0;
	while (lptr < rptr) {
		if (s[lptr] == 'R') { ++lptr; continue; }

		while (rptr > lptr && s[rptr] != 'R') --rptr;
		if (rptr == lptr) break;

		++score;
		swap(s[lptr], s[rptr]);
		++lptr;
	}

	lptr = 0;
	while (lptr < n && s[lptr] == 'R') ++lptr;
	while (lptr < n && s[lptr] == 'W') ++lptr;

	for (; lptr < n; ++lptr)
		if (s[lptr] == 'R') ++score;

	print(score);	
}

















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

	if (!MULTIPLE_TEST_CASES)
		exec();
	else {
		int n;
		cin >> n;

		while (n--)
			exec();
	}

    return 0;
}

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

#define fi first
#define se second

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

using namespace std;

int n;
int d[N][2];
vector < int > v[N];

void dfs(int x, int p = -1)
{
        d[x][0] = d[x][1] = 1;
        for(int y: v[x]){
                if(y == p){
                        continue;
                }
                dfs(y, x);
                d[x][0] = 1ll * d[x][0] * (d[y][0] + d[y][1]) % mod;
                d[x][1] = 1ll * d[x][1] * d[y][0] % mod;
        }
}

int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        ios_base::sync_with_stdio(0);

        cin >> n;
        for(int i = 1; i < n; i++){
                int x, y;
                cin >> x >> y;
                v[x].push_back(y);
                v[y].push_back(x);
        }
        dfs(1);
        cout << (d[1][0] + d[1][1]) % mod << "\n";
}



Measured memory_bytes: 13440
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<int, int>;
using PL = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr lint B1 = 1532834020;
constexpr lint M1 = 2147482409;
constexpr lint B2 = 1388622299;
constexpr lint M2 = 2147478017;
constexpr int INF = 2147483647;
void yes(bool expr) {cout << (expr ? "Yes" : "No") << "\n";}
template<class T>void chmax(T &a, const T &b) { if (a<b) a=b; }
template<class T>void chmin(T &a, const T &b) { if (b<a) a=b; }
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int N;
  cin >> N;
  lint pxpymax = -1e9;
  lint pxpymin = 1e9;
  lint pxmymax = -1e9;
  lint pxmymin = 1e9;
  lint mxpymax = -1e9;
  lint mxpymin = 1e9;
  lint mxmymax = -1e9;
  lint mxmymin = 1e9;
  REP(i, N) {
    lint x, y;
    cin >> x >> y;
    chmax(pxpymax, x+y);
    chmin(pxpymin, x+y);
    chmax(pxmymax, x-y);
    chmin(pxmymin, x-y);
    chmax(mxpymax, -x+y);
    chmin(mxpymin, -x+y);
    chmax(mxmymax, -x-y);
    chmin(mxmymin, -x-y);
  }
  lint ans = 0;
  chmax(ans, pxpymax-pxpymin);
  chmax(ans, pxmymax-pxmymin);
  chmax(ans, mxpymax-mxpymin);
  chmax(ans, mxmymax-mxmymin);
  cout << ans << endl;
}

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

int main(){
    Long x , k , d;
    cin >> x >> k >> d;
    x = abs(x);
    Long q = x / d;
    Long can = min( k , q );
    k = k - can;
    x -= can * d;
    
    if( k & 1 ) cout << abs( x - d ) << endl;
    else cout << x << endl;

    return 0;
}

Measured memory_bytes: 3512
#include <bits/stdc++.h>
using namespace std;
int main() {
    int s;
    cin >> s;
    set<int> ss;
    int m = 1;
    while(true) {
        ss.insert(s);
        m++;
        if(s % 2 == 0) {
            s = s / 2;
            if(ss.count(s)) {
                cout << m << endl;
                return 0;
            }
        }else {
            s = 3 * s + 1;
            if(ss.count(s)) {
                cout << m << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
import sys
from collections import deque
def input(): return sys.stdin.readline().strip()


def main():
    S = input()
    if S[0] != 'A' or ord('A') <= ord(S[1]) <= ord('Z') or ord('A') <= ord(S[-1]) <= ord('Z'):
        print("WA")
        return
    capital = []
    for i in range(2, len(S) - 1):
        if ord('a') <= ord(S[i]) <= ord('z'): continue
        capital.append(S[i])
    
    if capital == ['C']:
        print("AC")
    else:
        print("WA") 


if __name__ == "__main__":
    main()


Measured memory_bytes: 38256
#include <iostream>
//#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
ll mod = 1e9+7 ;
//long double pie = acos(-1) ;
//ll INF = 1e15 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll n ; cin >> n ;
	string s ; cin >> s ;
	vll cnt(26,0) ;
	for(int i=0;i<n;i++) cnt.at(s.at(i)-'a')++ ;
	ll ans = 1 ;
	for(int i=0;i<26;i++) ans = ans*(cnt.at(i)+1)%mod ;
	cout << (ans-1+mod)%mod << endl ;
}


Measured memory_bytes: 3764
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
#include <string>
using namespace std;
int main() {
  long long A, B;
  cin >> A >> B;
  if ((A + B) % 2 == 0) {
	  cout << (A + B) / 2 << endl;
	}
  else {
	  cout << "IMPOSSIBLE" << endl;
	}
  return 0;
}


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

int main(){
  double R;
  cin >> R;
  double ans;
  ans = 3.141592653589793 * R * 2;
  cout << std::fixed << std::setprecision(15) << ans << endl;
}

Measured memory_bytes: 3776
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int n, k;
    cin >> n >> k;
    double ans = 0.0;
    for (int i=1; i<=n; i++) {
        if (i>=k) ans += 1.0;
        else {
            double x = 1.0;
            int now = i;
            while (now<k) {
                now *= 2;
                x *= 0.5;
            }
            ans += x;
        }
    }
    ans /= n;
    
    printf("%.10f\n", ans);
    return 0;
}


Measured memory_bytes: 256
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

S=get_nsp
N=S.size
lr=[]
cnt=(S[0]=="R" ? 1 : -1)
(N-1).times do|i|
  if S[i]==S[i+1]
      if S[i]=="R"
          cnt+=1
      else
          cnt-=1
      end
  else
      lr.push(cnt)
      cnt=(S[i+1]=="R" ? 1 : -1) 
  end
end
lr.push(cnt)
ans=array(N,0)
i=0
lr.each do|v|
    if v>0
        i+=v
        ans[i]+=v/2
        ans[i-1]+=v/2+v%2
    else
        v*=-1
        ans[i]+=v/2+v%2
        ans[i-1]+=v/2
        i+=v
    end
end
puts ans.join(" ")

Measured memory_bytes: 11516
// tsukasa_diary's programing contest code template
#include <bits/stdc++.h>
using namespace std;
#define TSUKASA_DIARY_S_TEMPLATE
// define
#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define for_rev(i,a,b) for(int i=(a);i>=(b);--i)
#define allof(a) (a).begin(),(a).end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) int((a).size())
#define cauto const auto
// typedef
typedef long long lint;
typedef double Double;
typedef pair< int, int > pii;
template< typename T > using Vec = vector< T >;
template< typename T > using Matrix = Vec< Vec< T > >;
template< typename T > using USet = unordered_set< T >;
template< typename T, class C > using MyUSet = unordered_set< T, C >;
template< typename T, typename F > using UMap = unordered_map< T, F >;
template< typename T, typename F, class C > using MyUMap = unordered_map< T, F, C >;
// hash
class PiiHash { public: size_t operator () (const pii& p) const { return (p.first << 16) | p.second; } };
// popcount
inline int POPCNT(int x) { return __builtin_popcount(x); }
inline int POPCNT(lint x) { return __builtin_popcount(x); }
// inf
const int iINF = 1L << 30;
const lint lINF = 1LL << 60;
// eps
const Double EPS = 1e-9;
const Double PI = acos(-1);
// inrange
template< typename T >
inline bool in_range(T v, T mi, T mx) { return mi <= v && v < mx; }
template< typename T >
inline bool in_range(T x, T y, T W, T H) { return in_range(x,0,W) && in_range(y,0,H); }
// neighbor clockwise
const int DX[4] = {0,1,0,-1}, DY[4] = {-1,0,1,0};
const int DX_[8] = {0,1,1,1,0,-1,-1,-1}, DY_[8] = {-1,-1,0,1,1,1,0,-1};
// variable update
template< typename T > inline void modAdd(T& a, T b, T mod) { a = (a + b) % mod; }
template< typename T > inline void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > inline void maxUpdate(T& a, T b) { a = max(a, b); }
// converter
template< typename F, typename T >
inline void convert(F& from, T& to) {
	stringstream ss;
	ss << from; ss >> to;
}

string S;

void solve() {
	int N = S.size();

	for_(i,0,N) {
		if (i < N - 1) {
			if (S[i] == S[i + 1]) {
				cout << i + 1 << " " << i + 2 << endl;
				exit(0);
			}
		}
		if (i < N - 2) {
			if (S[i] == S[i + 2]) {
				cout << i + 1 << " " << i + 3 << endl;
				exit(0);
			}
		}
	}
	
	cout << -1 << " " << -1 << endl;
}

int main() {
	cin >> S;
	solve();
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

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

signed main() {
  ll N;
  cin >> N;

  vll dp(N + 1);
  rep(i, N + 1) {
    dp[i] = INF;
  }

  rep(i, N + 1) {
    if (i == 0) {
      dp[i] = 0;
    }
    chmin(dp[i], 1 + dp[i - 1]);

    ll six = 6;
    while (1) {
      if (i - six < 0) {
        break;
      }
      chmin(dp[i], 1 + dp[i - six]);
      six *= 6;
    }

    ll nine = 9;
    while (1) {
      if (i - nine < 0) {
        break;
      }
      chmin(dp[i], 1 + dp[i - nine]);
      nine *= 9;
    }
  }

  ll ans = dp[N];
  COUT(ans);

  return 0;
}

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

int main(){
  int h,w;
  cin >> h >> w;
  vector<string> s(h);
  for(int i = 0;i < h;i++)cin >> s[i];
  vector<vector<int>> cnt(h,vector<int>(w));

  //縦と横に見る.

  for(int i = 0;i < h;i++){
    vector<int> done(w);
    for(int j = 0;j < w;j++){
      if(s[i][j] == '#')continue;//障害物ならcontinue
      if(done[j])continue;//既に参照済みならcontinue
      int l = 0;
      while(j + l < w){//#でない初めてのグリッドがここに入る.
        if(s[i][j+l] == '#')break;
        ++l;
      }
      for(int k = 0;k < l;k++){
        cnt[i][j+k] += l;//左からすでに見たものとして埋めていく.+=にしておくと縦に見るコードはそのままコピーしてよい.
        done[j+k] = 1;
      }
    }
  }

  for(int j = 0;j < w;j++){
    vector<int> done(h);
    for(int i = 0;i < h;i++){
      if(s[i][j] == '#')continue;
      if(done[i])continue;
      int l = 0;
      while(i + l < h){
        if(s[i+l][j] == '#')break;
        ++l;
      }
      for(int k = 0;k < l;k++){
        cnt[i+k][j] += l;
        done[i+k] = 1;
      }
    }
  }

  int ans = 0;
  for(int i = 0;i < h;i++)
    for(int j = 0;j < w;j++)ans = max(ans,cnt[i][j] - 1);

  cout << ans << endl;

  return 0;
}


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

int main(){
	string a,b,c;
	cin>>a>>b>>c;
	int lena=a.length();
	int lenb=b.length();
	if(a[lena-1]==b[0] && b[lenb-1]==c[0])
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;
	return 0;
}

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

int main(void){
    int n;
    long long int s = 0;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin >> a.at(i);
    }

    sort(a.begin(), a.end());
    cout << a.at(0) << " ";
    reverse(a.begin(), a.end());
    cout << a.at(0) << " ";
    s = accumulate(a.begin(), a.end(), 0LL);
    cout << s << endl;

    return 0;
}


Measured memory_bytes: 3204
e=10**9+7
n,m=map(int,input().split())
l=[]
for i in range(n):
    l.append(input())
dp=[]
for i in range(n):
    dp.append([0]*m)

dp[-1][-1]=1
for i in range(m-2,-1,-1):
    if l[n-1][i]=='#':
        pass
    else:
        dp[n-1][i]+=dp[n-1][i+1]
for i in range(n-2,-1,-1):
    if l[i][m-1]=='#':
        pass
    else:
        dp[i][m-1]+=dp[i+1][m-1]
for i in range(n-2,-1,-1):
    for j in range(m-2,-1,-1):
        if l[i][j]=='#':
            pass
        else:
            dp[i][j]=(dp[i][j+1]+dp[i+1][j])%e
print(dp[0][0])
    


Measured memory_bytes: 43620
//String Formation

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a / __gcd(a, b) * b
#define range(a) (a).begin(),(a).end()
const int inf = 2147483647;

int main (){
    string a;cin>>a;
    int q;cin>>q;
    int ss,pp;string oo;
    bool rev = false;
    rep(i,0,q){
        cin >> ss;
        if(ss==1)rev = !rev;
        else{
            cin >> pp >> oo;
            if(rev){
                if(pp==1)a.insert(a.size(),oo);
                else a.insert(0,oo);
            }else{
                if(pp==1)a.insert(0,oo);
                else a.insert(a.size(),oo);
            }
        }
    }
    if(rev)reverse(range(a));
    cout << a << endl;
    return 0;
}

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

using namespace std;

int n, nr, a;

int main()
{
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a;
    while (a % 2== 0) {
      a /= 2;
      nr++;
    }
  }
  cout << nr;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<stdio.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fr(i,j,n)   for(long long i=j;i<(n);++i)
#define bk(i,j,n)   for(long long i=j;i>=n;--i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define endl "\n"
#define MOD 1000000007
#define debug1(x) cout<<#x<<" "<<x<<endl;
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define srt(x) sort(x.begin(),x.end());
#define ret     return 0;
#define mem(x,y)    memset((x),(y),sizeof (x));
#define run ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ordered_set tree<ll , null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>

typedef long long ll;

//std::cout << std::setprecision(12) << s << '\n';
ll modpower(ll a,ll b,ll c)
{
	ll res=1;
	while(b)
	{
		if(b&1LL)
			res=(res*a)%c;
		a=(a*a)%c;
		b>>=1;
	}
	return res;
}

ll n;
ll a[3002];
ll dp[3002][3002][2];
ll vis[3002][3002][2];
ll fun(ll lo,ll hi,ll x,ll y,ll chnc)
{
    chnc%=2;
    if(hi<lo)
    {
        return x-y;
    }
    if(hi==lo)
    {
        if(chnc)
            y+=a[hi];
        else
            x+=a[hi];
        return x-y;

    }
    if(vis[lo][hi][chnc])
        return dp[lo][hi][chnc];
    vis[lo][hi][chnc]=1;

    if(chnc%2)
    {
        ll o=fun(lo,hi-1,x,y,chnc+1)-a[hi];
        ll p=fun(lo+1,hi,x,y,chnc+1)-a[lo];

        o=min(o,p);
        dp[lo][hi][chnc]=o;
        return o;


    }
    else
    {

        ll o=fun(lo,hi-1,x,y,chnc+1)+a[hi];
        ll p=fun(lo+1,hi,x,y,chnc+1)+a[lo];

        o=max(o,p);
        dp[lo][hi][chnc]=o;
        return o;

    }




}


int main()
{
    run;
    cin>>n;
    fr(i,0,n)
    {
        cin>>a[i];
    }
    ll o=fun(0,n-1,0,0,0);
    cout<<o;





}


Measured memory_bytes: 281216
//ΔAGC026B
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
typedef double DB;
LL gcd(LL x,LL y){
	if(!y)
		return x;
	return gcd(y,x%y);
}
LL A,B,C,D,x;
int main()
{
	int T;
	cin>>T;
	while(T--){
		cin>>A>>B>>C>>D;
		if(A<B||D<B){
			cout<<"No\n";
			continue;
		}
		x=gcd(B,D);
		A%=x;
		if(C%x<A)
			C=C-C%x+A;
		else
			C=C-C%x+A+x;
		if(C>=B)
			cout<<"Yes\n";
		else
			cout<<"No\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    static char str[100000];
    int len;//N 文字列の長さ
    int q;//Q 問の個数
    //scope[i][0]:l, scope[i][1]:r
    int scope[100000][2];
    static int csum[100000];
    int i,count;
    
    scanf("%d %d", &len, &q);
    scanf("%s", str);
    
    for(i = 0; i < len-1; i++){
        if(str[i] == 'A' && str[i+1] == 'C'){
            csum[i] += 1;
            csum[i+1] = csum[i];
        }else{
            csum[i+1] = csum[i];
        }
    }

    for(i = 0; i < q; i++){
        scanf("%d %d", &scope[i][0], &scope[i][1]);
    }
    
    for(i = 0; i < q; i++){
        count = csum[scope[i][1]-2] - csum[scope[i][0]-2];
        printf("%d\n", count);
    }

    return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define scl(n) scanf("%lld", &n)
#define ull unsigned long long
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define uu first
#define vv second
#define MOD 1000000007
#define inf 1000000001
#define limit 10001000

int dp[100005];
int ar[100005];

int main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
//    ios_base::sync_with_stdio(0);

    int i, j, n, k, x;

    while(scanf("%d", &n)==1)
    {
        for(i=1; i<=n; i++)
        {
            scanf("%d", &ar[i]);
            dp[i]=inf;
        }

        dp[1]=0;

        for(i=1; i<=n; i++)
        {
            x=inf;
            k=2;

            for(j=1; j<=k; j++)
            {
                if(i+j<=n)
                {
                    x=abs(ar[i+j]-ar[i])+dp[i];

                    dp[i+j]=min(dp[i+j], x);
                }
            }
        }

        printf("%d\n", dp[n]);
    }

    return 0;
}



Measured memory_bytes: 1024
h,w,n = gets.split.map(&:to_i)
x,y = gets.split.map{|i|i.to_i-1}
s = gets.chomp.reverse
t = gets.chomp.reverse
a = 0
b = w-1
n.times do |i|
    a -= 1 if t[i] == "R"
    a = 0 if a < 0
    b += 1 if t[i] == "L"
    b = w-1 if b >= w

    a += 1 if s[i] == "L"
    b -= 1 if s[i] == "R"
    if a > b
        puts "NO"
        exit
    end
end
if y < a || b < y
    puts "NO"
    exit
end
a = 0
b = h-1
n.times do |i|
    a -= 1 if t[i] == "D"
    a = 0 if a < 0
    b += 1 if t[i] == "U"
    b = h-1 if b >= h

    a += 1 if s[i] == "U"
    b -= 1 if s[i] == "D"
    if a > b
        puts "NO"
        exit
    end
end
if x < a || b < x
    puts "NO"
    exit
end
puts "YES"

Measured memory_bytes: 3024
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,K;
    cin>>N>>K;
    
    if(K%2){
        ll a=N/K;
        cout1(a*a*a)
    }else{
        ll a=N/K;
        ll b=0;
        if(N-K/2>=0) b=(N-K/2)/K+1;
        cout1(a*a*a+b*b*b)
    }
    
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

ll l, r, cnt1;
ll cnt2;
ll tmp = 2018;
bool judge;

int main() {

	cin >> l >> r;
	REP(i, l, r + 1) {
		REP(j, i + 1, r + 1) {

			if (tmp > (ll)(i)* (ll)(j) % 2019) {
				tmp = (ll)(i)* (ll)(j) % 2019;
			}
			if (tmp == 0)break;
		}
		if (tmp == 0)break;
	}


	cout << tmp << endl;

	return 0;
}




Measured memory_bytes: 256
import java.util.Scanner;
 class  Main {
    static public  void  main (String[] av){
     int  a,b;
        Scanner sc =new Scanner(System.in);
        a =sc.nextInt();
        b =sc.nextInt();
        System.out.println(a*b +" "+(a*2+b*2));
        
    }

}


Measured memory_bytes: 26088
import java.util.*;
public class Main {
    public static void main(String[] args){
      // 入力
      Scanner sc = new Scanner(System.in);
      int N = sc.nextInt();
      int[] A = new int[N];
      for(int i = 0; i < N; i++){
        A[i] = sc.nextInt();
      }
      
      // 取引
      long money = 1000L;
      long kabu = 0L;
      for(int i = 0; i < N; i++){
        if(kabu > 0){
          money = money + kabu * A[i];
          kabu = 0;
        }
        if(i < N-1 && A[i] < A[i+1]){
          kabu = money / A[i];
          money = money % A[i];
        }
      }
      
      // 出力
      System.out.println(money);
    }
    

}

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

const int maxn = 1e5 + 5;
int h[maxn];
int dp[maxn];

int main() {
    int n; scanf("%d", &n);
    for (int i = 0; i < n; ++i) scanf("%d", &h[i]);
    for (int i = 0; i < n; ++i) dp[i] = 2e9;
    dp[0] = 0;
    for (int i = 1; i < n; ++i) {
        if (i - 1 >= 0) dp[i] = min(dp[i], dp[i - 1] + abs(h[i - 1] - h[i]));
        if (i - 2 >= 0) dp[i] = min(dp[i], dp[i - 2] + abs(h[i - 2] - h[i]));
    }
    printf("%d\n", dp[n - 1]);
}


Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <unordered_map>
#include <random>
#include <queue>

#define BIG 998244353
#define LLMAX 9223372036854775807
#define LLMIN (-9223372036854775808)
#define long long long

using namespace std;


int main() {
    long n;
    cin >> n;
    long nsq = (long)sqrt(n);
    long t = 0;
    for(int k = 1;k <= nsq;++k){
        if(n % k == 0){
            long a = n / k;
            if(a - 1 <= k)break;
            t += a - 1;
        }
    }
    cout << t;
}




Measured memory_bytes: 256