akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    string str, order, s;
    cin >> str;
    int q, a, b;
    cin >> q;
    getline(cin, s);
    for (int i = 0; i < q; i++) {
        cin >> order;
        if (order == "print") {
            cin >> a >> b;
            for (int i = a; i <= b; i++) {
                cout << str[i];
            }
            cout << endl;
        }
        if (order == "replace") {
            cin >> a >> b >> s;
            str.replace(str.begin() + a, str.begin() + b + 1, s);
        }
        if (order == "reverse") {
            cin >> a >> b;
            reverse(str.begin() + a, str.begin() + b + 1);
        }
    }
}


Measured memory_bytes: 3180
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
#define MOD 1000000007
#define tp tuple<ll,ll,ll>

ll seg[262144], sseg[262144];

ll rsq(int s, int t, int k = 1, int l = 0, int r = 131071) {
	if (s > t)return 0;
	if (t < l || r < s)return 0;
	if (s <= l && r <= t)return seg[k];

	ll lv = rsq(s, t, k * 2, l, (l + r) / 2);
	ll rv = rsq(s, t, k * 2 + 1, (l + r) / 2 + 1, r);
	return lv + rv;
}

void upd(int x, ll v) {
	x += 131072;
	seg[x] = v;
	while (x) {
		x /= 2;
		seg[x] = seg[x * 2] + seg[x * 2 + 1];
	}
	return;
}

int main() {
	ll N, M;
	cin >> N >> M;
	vector<ll> A(N);
	for (int i = 0;i < N;i++) {
		cin >> A[i];
	}
	sort(all(A));
	
	ll ok = 0, ng = 200001, mid;
	ll a, oa;
	while (ok + 1 != ng) {
		mid = (ng + ok) / 2;
		a = 0;
		for (int i = 0;i < N;i++) {
			auto it = lower_bound(all(A), mid - A[i]);
			//これ以上はすべて握手
			a += N - (ll)(it - A.begin());
		}
		if (a > M) {
			ok = mid;
			oa = a;
		}
		else {
			ng = mid;
		}
	}
	
	for (int i = 0;i < N;i++) {
		upd(i, A[i]);
	}
	ll ans = 0, r;
	for (int i = 0;i < N;i++) {
		auto it = lower_bound(all(A), ok - A[i]);
		r = N - 1 - (it - A.begin());
		ans += rsq(it - A.begin(), N - 1) + A[i] * (r + 1);
	}
	cout << ans - (oa - M) * ok << endl;
}

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

int main() {
  int a, b, c, K;
  cin >> a >> b >> c >> K;
  
  if ((a > b) && (a > c)) {
    for (int i = 0; i < K; i++) a *= 2;
  }
  else if (b > c) {
    for (int i = 0; i < K; i++) b *= 2;
  }
  else {
    for (int i = 0; i < K; i++) c *= 2;
  }
  cout << a+b+c << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

#define MOD 1000000007

int main(void) {
	int c, ans = 0, cnt = 2;
	while ((c = getchar()) != EOF) {
		if (c != '1' && c != '0') continue;
		ans = ((ans*2)%MOD + ans + 2) % MOD;
		if (c == '1') cnt = (cnt*2) % MOD;
		else ans = (ans + MOD - cnt) % MOD;
	}
	printf("%d\n", (ans+1) % MOD);
}


Measured memory_bytes: 128
import scala.io.Source.stdin

object Main extends App {
  var b = new StringBuilder

  for(d<-stdin.getLines.map(_.toInt)) {
    var (j,s) = (0,0)

    while((j-1)*d < 600-d) {
      s += j*j*d*d*d
      j += 1
    }
    b.append(s+"\n")
  }

  print(b.result)
}

Measured memory_bytes: 43872
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Solver {
    Scanner sc = new Scanner();

    public void Solve() {
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] s, t, c;
        s = new int[N];
        t = new int[N];
        c = new int[N];
        var dic = new Dictionary<int, int[]>();
        for (int i = 0; i < N; i++) {
            s[i] = sc.nextInt();
            t[i] = sc.nextInt();
            c[i] = sc.nextInt();
            if (!dic.ContainsKey(c[i])) {
                dic.Add(c[i], new int[100001]);
            }
            for (int j = s[i]-1; j < t[i]; j++) {
                dic[c[i]][j] = 1;
            }
        }

        var sum = new int[100001];
        foreach (var kvp in dic) {
            for (int i = 0; i < 100001; i++) {
                sum[i] += kvp.Value[i];
            }
        }

        WriteLine(sum.Max());
    }
}



class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Program {
    static void Main(string[] args) {
        Solver s = new Solver();
        s.Solve();
    }
}


Measured memory_bytes: 30292
// Problem : C - Sum of product of pairs
// Contest : AtCoder - AtCoder Beginner Contest 177
// URL : https://atcoder.jp/contests/abc177/tasks/abc177_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sort(a) sort(all(a))
#define ff first
#define ss second
#define vi vector<int>
#define pii pair<int, int>
#define vll vector<ll>
#define pll pair<ll,ll>
// #define mod (ll)1e9+7
#define FAST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define repf(i,a,b) for(i=a;i<b;i++)
#define repb(i,a,b) for(i=a;i>=b;i--)
#define N 100005
int main()
{
	FAST
    int t=1;
    // cin>>t;
    ll mod=1000000007;
    while(t--)
    {
		int i,n;
		cin>>n;
		vll a(n+1,0);
		// a[0]=0;
		repf(i,1,n+1) cin>>a[i];
		ll b=0;
		ll ans=0;
		ans=ans+a[i]*b;
		repb(i,n,1)
		{
			// ans = (ans%mod+((a[i]%mod)*(b%mod))%mod)%mod;
			ans=(ans+((a[i]%mod)*(b%mod))%mod)%mod;
			// cout<<ans<<"\n";
			b+=a[i];
		}
		cout<<ans;
    }
    return 0;
} 


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

int main(){
  int n;
  cin >> n;
  if(n < 10){
    cout << n << endl;
  }else if(n < 100){
    cout << 9 << endl;
  }else if(n < 1000){
    cout << 9 + n - 99 << endl;
  }else if(n < 10000){
    cout << 909 << endl;
  }else if(n < 100000){
    cout << 909 + n - 9999 << endl;
  }else{
    cout << 90909 << endl;
  }
}


Measured memory_bytes: 256
let () =
    let main () =
        let n = Scanf.sscanf (read_line ()) "%d" (fun n -> n) in
        let ab = Array.init n (fun _ -> Scanf.sscanf (read_line ()) "%d %d" (fun a b -> b, a)) in
        Array.sort compare ab;
        let a = Array.init n (fun i -> snd ab.(i)) in
        let b = Array.init n (fun i -> fst ab.(i)) in
        let c = Array.make n 0 in
        let rec loop time i =
            if i < n then (
                let time = time + a.(i) in
                c.(i) <- time;
                loop time (i + 1)
            )
        in
        loop 0 0;
        let rec loop i =
            if i = n then "Yes" else if c.(i) > b.(i) then "No" else loop (i + 1)
        in
        print_endline (loop 0)
    in
    main ()

Measured memory_bytes: 16132
/**
 *    author:  Daredevil666
 *    institution: IIT Patna
**/
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define nl cout<<"\n";
#define ll long long int
#define IOS  ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
ll mod=1e9+7;
int main()
{
IOS
ll n;
cin>>n;
vector<ll> v(n);
ll sum=0;
for(ll i=0;i<n;i++)
{
    cin>>v[i];

}
sort(v.begin(),v.end());
reverse(v.begin(),v.end());
sum+=v[0];
priority_queue<pair<ll,ll> > pq;
pq.push(make_pair(v[1],v[0]));
  pq.push(make_pair(v[1],v[0]));
  for(ll i=2;i<n;i++)
  {
      ll x=pq.top().first,y=pq.top().second;
      pq.pop();
      sum+=x;
      pq.push(make_pair(v[i],x));
      pq.push(make_pair(v[i],y));
  }
cout<<sum;
return 0;
}


Measured memory_bytes: 8996
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

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

#define MOD 1000000007

void solve(int test_case) {//221
	int n;
	cin>>n;
	cout<<n/3;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


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

int main() {
    int k;
    int a[5];
    int min = 0;
    int max = 1000;
    rep(i,5){
        cin >> a[i];
    }
    cin >> k;
    if(a[4]-a[0]<=k)cout << "Yay!" << endl;
    else cout << ":(" << endl;
}

Measured memory_bytes: 256
while True:
    a,op,b = input().split()
    a = int(a)
    b = int(b)
    if op == "?":
        break
    if op == "+":
        print(a+b)
    elif op == "-":
        print(a-b)
    elif op == "*":
        print(a*b)
    elif op == "/":
        print(a//b)


Measured memory_bytes: 5592
import heapq
n=int(input())
a=list(map(int,input().split()))
s1=sum(a[:n])
hq1=a[:n]
heapq.heapify(hq1)
A=[s1]
for i in range(n,2*n):
  s1+=a[i]
  heapq.heappush(hq1,a[i])
  x=heapq.heappop(hq1)
  s1-=x
  A.append(s1)
a=a[::-1]
s2=sum(a[:n])
hq2=[-a[i] for i in range(n)]
heapq.heapify(hq2)
B=[s2]
for i in range(n,2*n):
  s2+=a[i]
  heapq.heappush(hq2,-a[i])
  x=heapq.heappop(hq2)
  s2-=-x
  B.append(s2)
B=B[::-1]
ans=-10**18
for i in range(len(A)):
  ans=max(ans,A[i]-B[i])
print(ans)

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

using namespace std;

const int N = 200000 + 10;

int n;
int p[N];
int res[N];

int rmq[2][20][N];

struct Node{
  int l, r;
  vector<int> out;
  pair<int, int> res;
};

Node nodes[N];

int nid = 0;


void init(){
    for(int pp=0; pp<=1; ++pp)
      for(int i=0; i<n; ++i)
        rmq[pp][0][i] = n;
 
    for(int pp=0; pp<=1; ++pp)
      for(int i=pp; i<n; i+=2)
        rmq[pp][0][i] = i;
    
    for(int pp=0; pp<=1; ++pp)
      for (int i=1; (1<<i)-1<n; ++i)
        for (int j=0; j+(1<<i)-1<n; ++j){
            int& L = rmq[pp][i-1][j];
            int& R = rmq[pp][i-1][j+(1<<(i-1))];
            rmq[pp][i][j] = (p[L] <= p[R] ? L : R);
        }
}

int query(int pp, int l, int r){
    int d = r - l + 1;
    int x = 31 - __builtin_clz(d);
 
    int& L = rmq[pp][x][l];
    int& R = rmq[pp][x][r-(1<<x)+1];
    return p[L] <= p[R] ? L : R;
}

int build(int l, int r){
  if(l>=r) return -1;
  int id = nid;
  
  ++nid;
  
  nodes[id].l = l;
  nodes[id].r = r;
  
  nodes[id].res.first = query(l%2, l ,r);
  nodes[id].res.second = query((nodes[id].res.first+1)%2, nodes[id].res.first+1, r);
  
  int x = build(l, nodes[id].res.first-1);
  if(x != -1) nodes[id].out.push_back(x);
  x = build(nodes[id].res.first+1, nodes[id].res.second-1);
  if(x != -1) nodes[id].out.push_back(x);
  x = build(nodes[id].res.second+1, r);
  if(x != -1) nodes[id].out.push_back(x);
  return id;
}

void solve(){
  int pos = 0;
  map<pair<int, int>, int> ps;
  ps[ {p[nodes[0].res.first], p[nodes[0].res.second]}] = 0;
  while(!ps.empty()){
    auto item = (*ps.begin());
    ps.erase(ps.begin());
    res[pos] = item.first.first;
    ++pos;
    res[pos] = item.first.second;
    ++pos;
    for(auto child: nodes[item.second].out){
      ps[{p[nodes[child].res.first], p[nodes[child].res.second] }] = child;
    }
  }
  
}

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

    cin >> n;
    for(int i=0; i!=n; ++i){
      cin >> p[i];
    }
    p[n] = N;
    
    init();
    build(0, n-1);
    solve();
    
    for(int i=0; i!=n; ++i){
      cout << res[i] << " ";
    }
    cout << endl;
    
    
    return 0;
}

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

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] ABCK = Console.ReadLine().Split(' ');
            int A = int.Parse(ABCK[0]);
            int B = int.Parse(ABCK[1]);
            int C = int.Parse(ABCK[2]);
            int K = int.Parse(ABCK[3]);

            if(K <= A)
            {
                Console.WriteLine(K);
            }
            else if(K <= A + B)
            {
                Console.WriteLine(A);
            }
            else
            {
                Console.WriteLine(A - (K - A - B));
            }

            Console.ReadLine();
        }
    }
}


Measured memory_bytes: 27540
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll)x.size()
#define f first
#define s second
#define MAXN 200100


ll INF = 1e18;

struct node
{
	ll s,e,m;
	ll cnt,val;
	node *l, *r;
	node (ll _s, ll _e){
		s=_s;e=_e;m=(s+e)/2;cnt=0;val=0;
		if (s!=e){
			l = new node(s,m);
			r = new node(m+1,e);
		}
	}
	void up(ll x, ll v){
		if (s == e && v != -INF){val=v;cnt=1;return;}
		else if (s == e){val = 0;cnt = 0;return;}
		if (x <= m)l->up(x,v);
		else r->up(x,v);
		cnt = l->cnt+r->cnt; val=l->val+r->val;
	}
	ll query (ll x){
		if (x==0)return 0;
		// Query sum of X biggest elements
		if (s == e)return val;
		if (r->cnt >= x){
			return r->query(x);
		}else{
			return r->val + l->query(x - r->cnt);
		}
	}
}*U,*L;

ll N;
pi A[MAXN];
ll a,b,c;
ll X,Y,Z;
ll ans;
ll fstind[MAXN];
ll sndind[MAXN];
vpi V,V2;

int main(){
	cin>>X>>Y>>Z;
	N =X+Y+Z;
	for (ll i=1;i<=N;++i){
		cin>>a>>b>>c;
		ans += a;
		A[i] = mp(b-a,c-a);
	}

	sort(A+1,A+N+1);
	reverse(A+1,A+N+1);

	for (ll i=1;i<=N;++i){
		V.pb(A[i].s - A[i].f, i);
		V2.pb(A[i].s, i);
		// cout<<A[i].f<<' '<<A[i].s<<'\n';
	}

	sort(ALL(V));
	for (ll i=0;i<SZ(V);++i)fstind[V[i].s] = i+1;
	sort(ALL(V2));
	for (ll i=0;i<SZ(V2);++i)sndind[V2[i].s] = i+1;
	// cout<<ans;
	
	// for (ll i=1;i<=N;++i)cout<<A[i].f<<' '<<A[i].s<<'\n';
	L = new node(1,N);
	U = new node(1,N);

	for (ll i=1;i<=N;++i){
		U->up(sndind[i], A[i].s);
		// cout<<"Update U "<<sndind[i]<<' '<<A[i].s<<'\n';
	}

	ll cnt = 0;
	ll res = -INF;

	for (ll i=1;i<=N;++i){
		// cout<<"Left "<<L->cnt<<' '<<L->val<<" right "<<U->cnt<<' '<<U->val<<'\n';
		ll top = i - Y;
		ll btm = Z - top;
		ll toplen = i;
		ll btmlen = N - i;
		// Add to top
		cnt += A[i].f;
		U->up(sndind[i], -INF);
		// cout<<"Delete "<<A[i].s<<'\n';
		L->up(fstind[i], A[i].s - A[i].f);

		if (btm > btmlen || btm < 0 || top > toplen || top < 0)continue;
		// cout<<"Divide at "<<i<<" with "<<top<<" at the top and "<<btm<<" at the bottom "<<'\n';
		ll tp = L->query(top);
		ll bm = U ->query(btm);
		res = max(res, cnt+tp+bm);
		// cout<<"Val "<<cnt << ' '<<tp<<' '<<bm<<'\n';
	}
	cout<<ans+res;
}

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

int a[50],b[50],c[50],d[50];
int n,m;

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

	for(int i=0;i<n;++i)cin>>a[i]>>b[i];
	for(int i=0;i<m;++i)cin>>c[i]>>d[i];
	
	for(int i=0;i<n;++i){
		int ans=0,min=1e9;
		for(int j=0;j<m;++j){
			if(abs(a[i]-c[j])+abs(b[i]-d[j])<min){
				ans=j+1;
				min=abs(a[i]-c[j])+abs(b[i]-d[j]);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<vector>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n){
  return n == 0 ? 1 : x * pow(x, n - 1);
}


/*
n a b c
l1
..
ln

n 8
c b a 1000
li 1000
 */
#define INF 10000
int n,a[3];
int l[8];

int main(){
  cin>>n;
  REP(i,3){
    cin>>a[i];
  }
  REP(i,n){
    cin>>l[i];
  }

  int ans=INF;
  REP(d,pow(4,n)){
    //0-2:a[0-2] 3:none
    vector<int> cnt(4,0);
    vector<int> len(4,0);

    REP(i,n){ //bamboo
      len[(d/pow(4,i))%4] += l[i];
      cnt[(d/pow(4,i))%4]++;
    }

    bool invalid = false;
    REP(j,3){
      invalid = invalid || cnt[j] == 0;
    }
    if(invalid) continue;

    int mp = 0;
    REP(j,3){
      mp += 10*(cnt[j]-1) + abs(a[j] - len[j]);
    }

    ans = min(ans, mp);
  }

  cout<<ans<<endl;

  return 0;
}


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

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

int main(){
    string s,t,ans;
    int an=0;
    cin>>s>>t;
    ans="UNRESTORABLE";
    for(int i=s.size()-t.size();i>=0;i--){
        for(int j=0;j<=t.size();j++){
            if(j<t.size()&&t[j]!=s[i+j]&&s[i+j]!='?'){
                break;
            }
            else if(j==t.size()){
                an=i;
                ans=s;
            }
        }
        if(ans!="UNRESTORABLE"){
            break;
        }
    }
    
    for(int i=an;i<an+t.size();i++){
       if(ans[i]=='?'){
           ans[i]=t[i-an];
       }
    }
    for(int i=0;i<s.size();i++){
       if(ans[i]=='?'){
           ans[i]='a';
       }
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 256
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <iostream>
#include <stack>
#include <queue>

#define ll long long int
#define all(x) x.begin(), x.end()
#define MOD 998244353
#define PI 3.141592653589793238462643383279502884197169399375105820974944

using namespace std;

const int maxN = 1e5;
vector<int> adj[maxN + 1];
vector<bool> vis(maxN + 1, false);
vector<int> ans(maxN + 1, 0);

void bfs()
{
    queue<int> q, v;
    q.push(1);
    vis[1] = true;

    while (q.size())
    {
        int v = q.front();
        q.pop();

        for (int u : adj[v])
        {
            if (!vis[u])
            {
                q.push(u);
                vis[u] = true;
                ans[u] = v;
            }
        }
    }
}

void solve()
{
    int n, m;
    cin >> n >> m;

    int u, v;
    for (int i = 0; i < m; i++)
    {
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    bfs();

    for (int i = 2; i <= n; i++)
    {
        if (ans[i] == 0)
        {
            cout << "No\n";
            return;
        }
    }

    cout << "Yes\n";

    for (int i = 2; i <= n; i++)
        cout << ans[i] << "\n";

}

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

    int T = 1;
    //cin >> T;
    while (T--)
    {
        solve();
    }
    return 0;
}



Measured memory_bytes: 10280
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8').trim()

const n = Number(stdin.split('\n')[0])
const w = stdin
  .split('\n')[1]
  .split(' ')
  .map(Number)

const ans = () => {
  const t = w.length - 2

  let res = Infinity
  for (let i = 0; i <= t; i++) {
    let s1 = 0
    let s2 = 0
    for (let j = 0; j < w.length; j++) {
      if (j <= i) {
        s1 += w[j]
      } else {
        s2 += w[j]
      }
    }
    const abs = Math.abs(s1 - s2)

    res = Math.min(abs, res)
  }

  return res
}

console.log(ans())


Measured memory_bytes: 7500
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>


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

using namespace std;
string a,b;

int main(){
  cin >> a >> b;
  REP(i,a.size()){
    cout << a[i];
    if(i<b.size()) cout << b[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <queue>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

void print(int x){
    if(x == 1)
        cout << 9;
    else if(x == 9)
        cout << 1;
    else 
        cout << x;
}

int main(){
    int n;
    cin >> n;
    int x = n / 100;
    print(x);
    x = (n / 10) % 10;
    print(x);
    x = n % 10;
    print(x);
    cout << endl;
        
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 10010;

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

    deque<char> q;
    for(char c : s) {
        q.pb(c);
    }

    ll Q;
    cin >> Q;

    ll flip = 0;
    rep(loop, Q) {
        ll ty;
        cin >> ty;
        if(ty == 1) {
            flip = 1 - flip;
        }
        else {
            ll f;
            char c;
            cin >> f >> c;
            f--;
            if(flip) {
                f = 1 - f;
            }
            if(f == 0) {
                q.push_front(c);
            }
            else {
                q.pb(c);
            }
        }
    }

    if(flip) {
        reverse(all(q));
    }
    
    for(char c : q) {
        cout << c;
    }

    cout << endl;
    re0;
}

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

int main(void){
    while(true){
        int n=0, nmin=0, nmax=0, m=0, prev=0, dif=0, max=-100;
        cin >> m >> nmin >> nmax;
        if(m==0 && nmin==0 && nmax==0) break;
        cin >> prev;
        for(int i=1;i<m;++i){
            int score;
            cin >> score;
            dif = prev - score;
            prev = score;
            if(i < nmin || i > nmax) continue;
            if(max <= dif){
                n = i;
                max = dif;
            }
        }
        cout << n << endl;
    }
}


Measured memory_bytes: 3080
N = int(input())
L = list(map(int, input().split()))
l = len(L)
cnt = 0
for i in range(l):
  for j in range(i+1, l):
    for k in range(j+1, l):
      if L[i] != L[j] and L[i] != L[k] and L[j] != L[k] and (L[i] + L[j]) > L[k] and (L[j] + L[k]) > L[i] and (L[i] + L[k]) > L[j]:
        cnt = cnt + 1
print(cnt)

Measured memory_bytes: 68412
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
/*LCS gfg*/

void solve()
{
    ll n,w,i,j,m,x,y,z,k;

    string s1, s2;
    cin >> s1 >> s2;
    n = s1.length();
    m = s2.length();
    ll a[n+1][m+1];
    memset(a,0,sizeof(a));
    for(i=0;i<n+1;i++)
    {
        for(j=0;j<m+1;j++)
        {
            if(i == 0 || j  == 0)
            {
                a[i][j] = 0;
            }
            else
            {
                char c1 = s1[i-1];
                char c2 = s2[j-1];
                if(c1 == c2)
                {
                    a[i][j] = 1 + a[i-1][j-1];
                }
                else
                {
                    a[i][j] = max(a[i-1][j],a[i][j-1]);
                }
            }
        }

    }
    i = n;
    j = m;
    string ans = "";
    while(i >= 1 && j >= 1)
    {
        x = a[i][j];
        y = a[i][j-1];
        z = a[i-1][j];
        k = a[i-1][j-1];
        if(x == k+1 && s1[i-1] == s2[j-1])
        {
            ans = s1[i-1] + ans;
            i--;
            j--;
        }
        else
        {
            if(x == y)
            {
                j--;
            }
            else
            {
                i--;
            }
        }

    }
    cout << ans;



}
int main()
{

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll t=1;
	//cin >> t;
	while(t-- > 0)
	{
		solve();
	}

}


Measured memory_bytes: 73904
/* In the name of Allah */
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2 * 100 * 1000 + 10;
	int arr[MAXN];
	int num[MAXN];
int main(){
	int n, m;
	cin >> n;

	int sum =0;
	for(int i = 2; i <= n; i++){
		cin >> arr[i];
		num[arr[i]]++;
	}
	for(int i = 1; i <= n; i++){
		cout << num [i] << endl;
	}
	return 0;
}

Measured memory_bytes: 5164
//  main.cpp
//  CppTest

#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

int main(int argc, const char * argv[]) {
    // cinを高速にするためのおまじない
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    /////////////////////
    // Write code below /
    /////////////////////

    int N,n=0;
    cin>>N;
    vector<int>D(N);
    for(int i=0;i<N;i++){
        cin>>D.at(i);
    }
    for(int i=0;i<N;i++){
        if(n<D.at(i)){
            n=D.at(i);
        }
    }
    for(int j=0;j<N;j++){
        int k;
        k=0;
        for(int i=0;i<N;i++){
            if(n>D.at(i)){
                if(k<D.at(i)){
                    k=D.at(i);
                }
            }
        }
        n=k;
        if(k==0){
            cout<<j+1<<endl;
            break;
        }
    }
    
        return 0;
}


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

bool check(int x) {
	rep(i, 10)rep(j, 10) {
		if (i * j == x)
			return true;
	}
	return false;
}

int main(int argc, char const *argv[])
{
	int n; cin >> n;
	cout << (check(n) ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm;
import std.math :abs;

void main() {
    int n;

    scan(n);

    int x, y, t;

    foreach (i ; 0 .. n) {
        int ti, xi, yi;
        scan(ti, xi, yi);

        int d = abs(xi - x) + abs(yi - y);
        int e = ((x + y) % 2) ^ ((xi + yi) % 2);

        if ((ti - t) < d || (ti - t) % 2 != e) {
            writeln("No");
            return;
        }

        x = xi, y = yi, t = ti;
    }

    writeln("Yes");
    return;
}



void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
int main(){
  int X = 0;
  cin >> X;
  if ((400 <= X) && (X < 600)){
    cout << "8" << endl;
  }
  if (600 <= X && X < 800){
    cout << "7" << endl;
  }
  if (800 <= X && X < 1000){
    cout << "6" << endl;
  }
  if (1000 <= X && X < 1200){
    cout << "5" << endl;
  }
  if (1200 <= X && X < 1400){
    cout << "4" << endl;
  }
  if (1400 <= X && X < 1600){
    cout << "3" << endl;
  }
  if (1600 <= X && X < 1800){
    cout << "2" << endl;
  }
  if (1800 <= X && X < 2000){
    cout << "1" << endl;
  }
  return 0;
}

Measured memory_bytes: 3572
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc *bufio.Scanner

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n, k := nextInt(), nextInt()

	aArray := make([]int, n)
	aSum := 0
	for i := range aArray {
		aArray[i] = nextInt()
		aSum += aArray[i]
	}

	var div []int
	for i := 1; i*i <= aSum; i++ {
		if aSum%i == 0 {
			div = append(div, i)
			if i != aSum/i {
				div = append(div, aSum/i)
			}
		}
	}
	sort.Sort(sort.Reverse(sort.IntSlice(div)))

	for _, d := range div {
		mod := make([]int, n)
		for i, a := range aArray {
			mod[i] = a % d
		}
		sort.Sort(sort.IntSlice(mod))
		modSum := 0
		for _, m := range mod {
			modSum += m
		}
		if modSum == 0 {
			fmt.Println(d)
			return
		}
		modDiff := 0
		for i := n - 1; modSum > modDiff; i-- {
			modSum -= mod[i]
			modDiff += d - mod[i]
		}
		if modSum == modDiff && modSum <= k {
			fmt.Println(d)
			return
		}
	}
}


Measured memory_bytes: 5376
#21:30
n = int(input())
peer = [[] for _ in range(n)]
for _ in range(n-1):
  a,b,x = map(int,input().split())
  a -= 1
  b -= 1
  peer[a].append([b,x])
  peer[b].append([a,x])
ans = [-1 for _ in range(n)]
now = [0]
while now != []:
  last = now
  now = []
  for x in last:
    for yz in peer[x]:
      y = yz[0]
      z = yz[1]
      if ans[y] == -1:
        ans[y] = (ans[x] + z) % 2
        now.append(y)
  #print(now)
for i in range(n):
  print(ans[i])

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

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

  int sum = 0;
  for (int i=0; i< N; i++) {
    int l, r;
    cin >> l >> r;
    sum += r-l+1;

  }
  cout << sum << endl;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=1005,INF=1<<30;
int lef[MAX][2],righ[MAX][2],score[MAX][2];
int root[2],siz[2];
int tu=0;

int expr(string S,int &i,int &id);
int number(string S,int &i,int &id);

int expr(string S,int &i,int &id){
    int lech=-1,rich=-1,par=-1,sco=-1;
    if(i==S.size()) return par;
    if(S[i]==')') return par;
    
    i++;
    lech=expr(S,i,id);
    i++;
    i++;
    sco=number(S,i,id);
    par=id;
    i++;
    i++;
    id++;
    rich=expr(S,i,id);
    i++;
    
    if(par>=0){
        lef[par][tu]=lech;
        righ[par][tu]=rich;
        score[par][tu]=sco;
    }
    
    return par;
}

int number(string S,int &i,int &id){
    int res=0;
    while('0'<=S[i]&&S[i]<='9'){
        res*=10;
        res+=(S[i]-'0');
        i++;
    }
    return res;
};

string DFS(int nowa,int nowb){
    string res="";
    
    res+='(';
    
    if(lef[nowa][0]>=0&&lef[nowb][1]>=0){
        res+=DFS(lef[nowa][0],lef[nowb][1]);
    }
    
    res+=')';
    
    res+='[';
    
    res+=to_string(score[nowa][0]+score[nowb][1]);
    
    res+=']';
    
    res+='(';
    
    if(righ[nowa][0]>=0&&righ[nowb][1]>=0){
        res+=DFS(righ[nowa][0],righ[nowb][1]);
    }
    
    res+=')';
    
    return res;
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string A,B;
    cin>>A>>B;
    memset(lef,-1,sizeof(lef));
    memset(righ,-1,sizeof(righ));
    memset(score,-1,sizeof(score));
    int i=0,id=0;
    expr(A,i,id);
    siz[0]=id;
    
    i=0;id=0;
    tu=1;
    expr(B,i,id);
    siz[1]=id;
    
    for(int j=0;j<2;j++){
        set<int> SE;
        for(int i=0;i<siz[j];i++) SE.insert(i);
        
        for(int i=0;i<siz[j];i++){
            SE.erase(lef[i][j]);
            SE.erase(righ[i][j]);
        }
        
        root[j]=*(SE.begin());
    }
    
    cout<<DFS(root[0],root[1])<<endl;
    
    
}




Measured memory_bytes: 3468
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#define MP make_pair
using ll = long long;
using namespace std;

int main()
{
  string s;
  cin >> s;
  s[3] = '8';
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 256
from collections import Counter
import sys
MOD = 998244353

n = int(input())
a = list(map(int,input().split()))

aa = Counter(a)
ma = max(aa)

def po(x,n):
    k = 1
    for i in range(n):
        k = k*x % MOD
    return k

if aa[0] != 1 or a[0] != 0:
    print(0)
    sys.exit()
    
ans = 1
for i in range(ma):
    c,d = aa[i],aa[i+1]
    if c == 0 or d == 0:
        print(0)
        sys.exit()
    else:
        ans = ans * po(c,d) % MOD
        
print(ans)

Measured memory_bytes: 62004
#include <stdio.h>

int main()
{
	int a, b;
	scanf("%d%d", &a, &b);
	if (a < b)
	{
		printf("a < b\n");
	}
	else if (a > b)
	{
		printf("a > b\n");
	}
	else
	{
		printf("a == b\n");
	}
	return 0;
}

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

int a[200000];
int b[200000];

int main() {
    int n, m; cin >> n >> m;
    rep(i, 0, m) {
        int c, d; cin >> c >> d;
        if (c == 1) a[d] = 1;
        if (d == n) b[c] = 1;
    }
    rep(i, 1, n) {
        if (a[i] == 1 && b[i] == 1) {
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 1792
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	int[] a;
	int n;
	boolean f;

	void run(){
		n=4;
		a=new int[n];
		for(;;){
			int sq=0;
			for(int i=0; i<n; i++){
				a[i]=sc.nextInt();
				sq+=a[i]*a[i];
			}
			if(sq==0){
				break;
			}
			solve();
		}
	}

	void solve(){
		f=false;
		rec(0);
		if(!f){
			println("0");
		}
	}

	void rec(int i){
		if(f){
			return;
		}
		if(i==n){
			// debug(a);
			check();
			return;
		}
		for(int j=i; j<n; j++){
			// swap[i,j];
			int t=a[i];
			a[i]=a[j];
			a[j]=t;
			rec(i+1);
			t=a[i];
			a[i]=a[j];
			a[j]=t;
		}
	}

	void check(){
		// (a(b(cd)))
		// (((ab)c)d)
		// ((ab)(cd))
		String[] ops={"+", "-", "*"};
		for(int i=0; i<3; i++){
			for(int j=0; j<3; j++){
				for(int k=0; k<3; k++){
					String format="";
					if(cal(a[0], i, cal(a[1], j, cal(a[2], k, a[3])))==10){
						format="(%d %s (%d %s (%d %s %d)))";
						f=true;
					}else if(cal(cal(cal(a[0], i, a[1]), j, a[2]), k, a[3])==10){
						format="(((%d %s %d) %s %d) %s %d)";
						f=true;
					}else if(cal(cal(a[0], i, a[1]), j, cal(a[2], k, a[3]))==10){
						format="((%d %s %d) %s (%d %s %d))";
						f=true;
					}
					if(f){
						println(String.format(format, a[0], ops[i], a[1],
								ops[j], a[2], ops[k], a[3]));
						return;
					}
				}
			}
		}
	}

	int cal(int a, int op, int b){
		switch(op){
		case 0:
			return a+b;
		case 1:
			return a-b;
		case 2:
			return a*b;
		}
		return 0;
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
int64_t comb(int x,int y){
  int64_t z=1;
  for(int j=1;j<=y;j++) z=z*(x+1-j)/j;
  return z;
}
int main(){
  int n,a,b,j,k;
  cin>>n>>a>>b;
  vector<int64_t> v(n),w(n);
  for(j=0;j<n;j++) cin>>v.at(j);
  sort(v.begin(),v.end());
  reverse(v.begin(),v.end());
  w.at(0)=v.at(0);
  for(j=1;j<n;j++) w.at(j)=w.at(j-1)+v.at(j);
  set<int> z={a-1};
  for(j=a;j<b;j++){
    k=*z.begin();
    if(w.at(j)*(k+1)==w.at(k)*(j+1)) z.insert(j);
    else if(w.at(j)*(k+1)>w.at(k)*(j+1)) z={j};
  }
  k=*z.begin();
  cout<<fixed<<setprecision(10)<<(double)w.at(k)/(k+1)<<endl;
  int l=-1,r=-1;
  for(j=0;j<n;j++){
    if(v.at(j)==v.at(*z.begin())&&l==-1) l=j;
    else if(v.at(j)<v.at(*z.begin())&&r==-1) r=j-1;
  }
  if(r==-1) r=n-1;
  int64_t ans=0;
  for(auto j:z) ans+=comb(r-l+1,j-l+1);
  cout<<ans<<endl;
}

Measured memory_bytes: 3804
require 'mathn'

STDIN.each_line do |line|
	m = line.split.map(&:to_i).each_slice(3).to_a
	m.reverse! if m[0][0].zero?

	a = m[0][0]
	d = m[1][0]
	1.upto(2) do |i|
		m[0][i] /= a
		m[1][i] -= d * m[0][i]
	end

	y = m[1][2] / m[1][1]
	x = m[0][2] - m[0][1] * y
	puts "%.3f %.3f" % [x, y]
end

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

int main() {
  int n, a;
  int x[50];
  long long total = 0;
  std::vector<std::vector<long long>> count, prev;
  std::cin >> n >> a;
  for (int ni = 0; ni < n; ++ni) {
    std::cin >> x[ni];
  }
  count.resize(n + 1, std::vector<long long>(50 * n + 1, 0));
  count[0][0] = 1;
  for (int ni = 0; ni < n; ++ni) {
    prev = count;
    for (int nj = 0; nj < n; ++nj) {
      for (int xi = 0; xi <= 50 * n; ++xi) {
        if (prev[nj][xi] > 0) {
          count[nj + 1][xi + x[ni]] += prev[nj][xi];
        }
      }
    }
  }
  for (int ni = 1; ni <= n; ++ni) {
    total += count[ni][ni * a];
  }
  std::cout << total << std::endl;
  return 0;
}


Measured memory_bytes: 2304
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
	int N,M,Q; cin >> N >> M >> Q;
	vector<vector<int>> F(N+1,vector<int>(N+1));
	rep(i,M){
		int L,R; cin >> L >> R;
		F[L][R]++;
	}
	rep(i,N)rep(j,N){
		F[i+1][j+1] += F[i][j+1] + F[i+1][j] - F[i][j];
	}
	rep(i,Q){
		int p,q; cin >> p >> q;
		int ans = F[q][q] - F[p-1][q] - F[q][p-1] + F[p-1][p-1];
		cout << ans << endl;
	}
}



Measured memory_bytes: 1920
let cnt = ref 0

let merge a l m r =
  let ni = m - l in
  let init_ary n p =
    Array.init (n + 1) (fun i -> if i = n then max_int else a.(p + i))
  in
  let ai = init_ary ni l in
  let aj = init_ary (r - m) m in
  let rec doit i j k =
    if k < r then begin
      if ai.(i) <= aj.(j) then (a.(k) <- ai.(i); doit (i + 1) j (k + 1))
      else (a.(k) <- aj.(j); cnt := !cnt + (ni - i); doit i (j + 1) (k + 1))
    end
  in
  doit 0 0 l

let rec merge_sort a l r =
  if (l + 1) < r then begin
    let m = (l + r) / 2 in
    merge_sort a l m;
    merge_sort a m r;
    merge a l m r
  end

let () =
  let n = read_int () in
  let a = Array.init n (fun _ -> Scanf.scanf "%d " (fun i -> i)) in
  merge_sort a 0 n;
  Printf.printf "%d\n" !cnt

Measured memory_bytes: 10512
N = int(input())
h = list(map(int, input().split()))
INF = 10**9
dp = [INF] * N
dp[0] = 0
for i in range(1, N):
    dp[i] = min(dp[i], dp[i-1]+abs(h[i] - h[i-1]))
    if i > 1:
        dp[i] = min(dp[i], dp[i-2]+abs(h[i] - h[i-2]))
print(dp[N-1])

Measured memory_bytes: 13976
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#pragma region Macros
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define all(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define CEIL(a,b) ((a+b-1)/b)
int GCD(int a, int b) // assuming a,b >= 1
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b) // assuming a,b >= 1
{
	return  a * b / GCD(a, b);
}
inline bool BETWEEN(int x, int min,int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}
using namespace std;
#pragma endregion
signed main() {
	int A,B,C,D;
	cin >> A >> B >> C >>D;
	if (A + B > C + D)
		cout << "Left";
	else if (A + B == C + D)
		cout << "Balanced";
	else
		cout << "Right";
}

Measured memory_bytes: 256
n=int(input())
a=[int(i) for i in input().split()]
#print(n,a)

def waru(x):
  count=0
  while x%2==0:
    x=x//2
    count+=1
  return count

ans=0
for i in range(n):
    ans+=waru(a[i])
    
print(ans)

Measured memory_bytes: 4148
N=int(input())
D=sorted(list(map(int,input().split(' '))))
M=int(input())
T=sorted(list(map(int,input().split(' '))))
D_cnt=0
T_cnt=0
while T_cnt<M and D_cnt<N:
    if D[D_cnt]==T[T_cnt]:
        D_cnt += 1
        T_cnt += 1
    else:
        D_cnt += 1
if T_cnt == M:
    print('YES')
else:
    print('NO')

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

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    unsigned long zeros{~0UL};
    map<pair<unsigned long, unsigned long>, pair<unsigned long, unsigned long>> mp;
    for(unsigned long i{0}; i < N; ++i){
        long A, B;
        cin >> A >> B;
        if(A == 0 && B == 0){
            ++zeros;
            continue;
        }
        auto g = gcd(A, B);
        A /= g;
        B /= g;
        if(A < 0 || (A == 0 && B < 0)){
            A *= -1;
            B *= -1;
        }
        if(B <= 0)++mp[{-B, A}].first;
        else++mp[{A, B}].second;
    }
    unsigned long ans{1};
    constexpr unsigned long MOD = 1000000007;
    const auto& mod2pow = [](unsigned long a, unsigned long n) -> unsigned long {
        unsigned long r{a}, p{2};
        while(n){
            if(n & 1)(r *= p) %= MOD;
            (p *= p) %= MOD;
            n >>= 1;
        }
        return r;
    };
    for(const auto& [_, i] : mp)ans = (mod2pow(ans, i.first) + mod2pow(ans, i.second) + MOD - ans) % MOD;
    cout << (ans + MOD + zeros) % MOD << endl;
    return 0;
}

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

int main() {
	int N; cin >> N;
	int odd = 0,even = 0,four = 0;
	bool exist = true;
	for (int i = 0; i < N; i++) {
		int a; cin >> a;
		if (a % 2) odd++;
		else {
			if (a % 4 == 0) four++;
			else even++;
		}
	}

	// 奇数の隣は必ず4の倍数
	int dif = odd - four;
	if (dif > 1) exist = false;
	// 両端が奇数の場合は偶数が存在したらダメ
	else if(dif==1){
		if (even != 0) exist = false;
	}
	
	if (exist)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	// system("pause");
	return 0;
}

Measured memory_bytes: 256
/*
ID: Aman Raj
LANG: C++
TASK: milk3
*/
#include<iostream>
#include <stdio.h>
//#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#include<math.h>
typedef long long ll;
 #include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
using namespace __gnu_pbds;

#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
//#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
//#define flush fflush(stdout)
#define primeDEN 727999983
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#include <fstream>
// find_by_order()  // order_of_key
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;


int main()
{    ifstream fin ("milk3.in");
     ofstream fout ("milk3.out");
     ll a;
      cin>>a;ll c=0,d=0;
       if(a%100<=12&&a%100>0)c++;
        a/=100;
        if(a<=12&&a>0)d++;
        if(c>0&&d>0)cout<<"AMBIGUOUS";
        else if(c>0&&d==0)cout<<"YYMM";
        else if(c==0&&d>0)cout<<"MMYY";
        else cout<<"NA";

    return 0;

}


Measured memory_bytes: 256
import java.util.List;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;

public class Main {

	public static void main(String[] args) throws IOException {
		String outStr = "";
		List<Integer> NumberList = new ArrayList<Integer>();
        String numbers = new BufferedReader(new InputStreamReader(System.in)).readLine();
        String[] NumberArray = numbers.split(" ");
        
        for(int i = 0; i < NumberArray.length; i++){
        	NumberList.add(Integer.parseInt(NumberArray[i]));
        }
        
        Collections.sort(NumberList);
        Collections.reverse(NumberList);
        
        Iterator numberIterate = NumberList.iterator();
        while(numberIterate.hasNext()){
        	outStr = outStr + numberIterate.next() + " ";
        }
        
        System.out.println(outStr.trim());
	}

}

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

int main(int argc, char** argv){
  int N, D;
  cin >> N >> D;
  int X[N][D];
  for(int cnt0=0; cnt0<N; cnt0++){
    for(int cnt1=0; cnt1<D; cnt1++){
      cin >> X[cnt0][cnt1];
    }
  }
  
  int d2;
  int ans = 0;
  for(int cnt0=0; cnt0<N-1; cnt0++){
    for(int cnt1=cnt0+1; cnt1<N; cnt1++){
      if(cnt0 == cnt1) continue;
      d2 = 0;
      for(int cnt2=0; cnt2<D; cnt2++) d2 += (X[cnt0][cnt2] - X[cnt1][cnt2])*(X[cnt0][cnt2] - X[cnt1][cnt2]);
//      cout << cnt0 << ", " << cnt1 << ", " << d2 << endl;

      double d = sqrt(d2);
//      cout << cnt0 << ", " << cnt1 << ", " << d << endl;
      if(abs(d - ceil(d)) <= 1e-3) {
//        cout << cnt0 << ", " << cnt1 << endl;
        ans++;
      }
    }
  }
  
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 256
import itertools
N = int(input())
P = tuple(map(int, input().split(" ")))
Q = tuple(map(int, input().split(" ")))

all_permutations = [p for p in itertools.permutations([i for i in range(1, N+1)])]
a = all_permutations.index(P)
b = all_permutations.index(Q)
print(abs(a - b))

Measured memory_bytes: 7924
#include<stdio.h>
int main()
{
    int N,A,B,s;
    scanf("%d %d %d",&N,&A,&B);
    s=N*A;
    if(s<B)
    printf("%d\n",s);
    else if(s>B)
    printf("%d\n",B);
    else
    printf("%d\n",s);
    return 0;

}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second

void cinv(vector<ll> &v){
    for(ll i=0;i < v.size();i++){
            cin >> v.at(i);
    }
}

int main(){
    ll x,y,z,k;
    cin >> x >> y >> z >> k;
    vector<ll> o(x),s(y),t(z),ans;//一気に宣言する

    cinv(o);cinv(s);cinv(t);
    sort(o.begin(),o.end(),greater<ll>());
    sort(s.begin(),s.end(),greater<ll>());
    sort(t.begin(),t.end(),greater<ll>());
    
    for(int a=0;a < x;a++){
        if(a>k){break;}
        for(int b=0;b < y;b++){
            if(a*b>k){break;}
            for(int c=0;c < z;c++){
                if(a*b*c>k){break;}
                ans.push_back(o[a]+s[b]+t[c]);
            }
        }
    }
    sort(ans.begin(),ans.end(),greater<ll>());
    for(ll i=0;i < k;i++){
        cout << ans[i] << endl;
    }

}
/*解法1 全探索だと間に合わない→途中まで探索して残った候補と残りで探索するor枝刈り*/


Measured memory_bytes: 35048
#include<stdio.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
int main(){
	ll n,t,a,T=1,A=1;
	scanf("%lld",&n);
	FOR(i,0,n){
		scanf("%lld %lld",&t,&a);
		ll tt = T%t == 0 ? T/t : T/t+1;
		ll aa = A%a == 0 ? A/a : A/a+1;
		ll max = tt > aa ? tt : aa;
		T = t * max;
		A = a * max;
	}
	printf("%lld\n",T+A);
}

Measured memory_bytes: 128