akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define INF 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

int n,n_;
vector<P> vec;
vector<ll> vec2;
struct data{
	ll val,lazy;
	data(){}
	data(ll vv,ll la){
		val=vv;
		lazy=la;
	}
};

data dat[1<<20];

void lazy_evaluate(int k){
	dat[k].val=max(dat[k].val,dat[k].lazy);
	if(k<n_-1){
		dat[k*2+1].lazy=max(dat[k].lazy,dat[k*2+1].lazy);
		dat[k*2+2].lazy=max(dat[k].lazy,dat[k*2+2].lazy);
	}
}

void lazy_update(int k){
}

void update(int a,int b,ll v,int k=0,int l=0,int r=n_){
	lazy_evaluate(k);
	if(r<=a || b<=l)return;
	if(a<=l && r<=b){
		dat[k].lazy=max(dat[k].lazy,v);
		lazy_evaluate(k);
		return;
	}
	update(a,b,v,k*2+1,l,(l+r)/2);
	update(a,b,v,k*2+2,(l+r)/2,r);
	lazy_update(k);
	return;
}

ll query(int a,int b,int k=0,int l=0,int r=n_){
	lazy_evaluate(k);
	if(r<=a || b<=l)return INF;
	if(a<=l && r<=b)return dat[k].val;
	ll vl=query(a,b,k*2+1,l,(l+r)/2);
	ll vr=query(a,b,k*2+2,(l+r)/2,r);
	lazy_update(k);
	return min(vl,vr);
}

int main(void){
	scanf("%d",&n);
	ll maxi=0,mini=INF;
	for(int i=0;i<n;i++){
		P p;
		scanf("%lld%lld",&p.first,&p.second);
		vec.push_back(p);
		if(vec[i].first>vec[i].second){
			swap(vec[i].first,vec[i].second);
		}
		maxi=max(vec[i].first,maxi);
		maxi=max(vec[i].second,maxi);
		mini=min(vec[i].first,mini);
		mini=min(vec[i].second,mini);
		vec2.push_back(vec[i].first);
		vec2.push_back(vec[i].second);
	}
	sort(vec2.begin(),vec2.end());
	vec2.erase(unique(vec2.begin(),vec2.end()),vec2.end());
	bool fa=false,fi=false;
	ll mini2=INF,maxi2=0;

	for(int i=0;i<n;i++){
		mini2=min(vec[i].second,mini2);
		maxi2=max(vec[i].first,maxi2);
	}
	ll res=(ll)(maxi-mini2)*(maxi2-mini);
	mini2=INF,maxi2=0;
	n_=1;
	while(n_<vec2.size()){
		n_*=2;
	}
	for(int i=0;i<vec2.size();i++){
		update(i,i+1,i);
		ll v=query(i,i+1);
	}
	for(int i=0;i<n;i++){
		vec[i].first=lower_bound(vec2.begin(),vec2.end(),vec[i].first)-vec2.begin();
		vec[i].second=lower_bound(vec2.begin(),vec2.end(),vec[i].second)-vec2.begin();
		update(0,vec[i].first+1,vec[i].first);
		update(vec[i].first+1,vec[i].second+1,vec[i].second);
		update(vec[i].second+1,vec2.size(),INF);
	}
	for(int i=0;i<vec2.size();i++){
		ll v=query(i,i+1);
		if(v!=INF){
			res=min(res,(maxi-mini)*(vec2[v]-vec2[i]));
		}
	}
	printf("%lld\n",res);
	return 0;
}


Measured memory_bytes: 23388
#include<iostream>

using namespace std;

int main(){
	int W, a, b;
	cin >> W >> a >> b;
	if (a > b){
		int c = b;
		b = a;
		a = c;
	}
	if (a + W >= b){
		cout << "0" << endl;
		return 0;
	}
	else{
		cout << b - (a + W) << endl;
		return 0;
	}
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acos(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#define DEBUG

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	ll n, a, b;
	cin >> n >> a >> b;
	ll ans = n / (a + b) * a;
	ll rem = n % (a + b);
	ans += min(rem, a);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    A = [0] + list(map(int, input().rstrip().split()))
    for i in range(n // 2, 0, -1):  # second half: no multiples
        A[i] = sum(A[i::i]) % 2
    ans = [i for i, j in enumerate(A) if j]
    print(len(ans))  # all cells: [1] -> len() (much faster than sum())
    print(*ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 12720
n = input().strip()
n = int(n)
r = list()
if n % 2 == 0:
    x = n + 1
    for i in range(n):
        i = i + 1
        for j in range(n):
            j = j + 1
            if j <= i:
                continue
            if i + j == x:
                continue
            r.append((i,j))
else:
    m = n - 1
    x = n
    for i in range(m):
        i = i + 1
        for j in range(m):
            j = j + 1
            if j <= i:
                continue
            if i + j == x:
                continue
            r.append((i, j))
    for i in range(m):
        r.append((i+1, x))
print(len(r))
for l in r:
    print(l[0], l[1])


Measured memory_bytes: 3996
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;
const ll mininf = -922337203685477;
const ll nax = 0;
ll ans=0, n, a, b, c, d, e, mins;

int main(){
	IOS
    cin >> n >> a >> b >> c >> d >> e;
    mins=min({a, b, c, d, e});
    ans+=n/mins+(n%mins!=0);
    ans+=4;
    cout << ans << '\n';
}


Measured memory_bytes: 3652
#include <iostream>
#include <atcoder/segtree>

#define MAX_N (300000)

int op(int a, int b) {
  return std::max<int>(a, b);
}

int e() {
  return 0;
}

int main() {
  int N, K;
  std::cin >> N >> K;
  std::vector<int> A(N);
  for (int i = 0; i < N; i++) {
    std::cin >> A[i];
  }
  atcoder::segtree<int,op,e> seg(MAX_N);
  for (int i = N - 1; i >= 0; i--) {
    int len = seg.prod(std::max<int>(0,A[i]-K), std::min<int>(MAX_N,A[i]+K)+1);
    seg.set(A[i], len + 1);
  }
  std::cout << seg.all_prod() << std::endl;
  return 0;
}


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

#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back

using i32 = int;
using i64 = long long;
using ll = long long;

using namespace std;

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

    int64_t a;cin >> a;
    cout << a + a*a + a*a*a << '\n';

}



Measured memory_bytes: 3648
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cassert>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
typedef pair<int,int> pii;
const int N = 10000;

void compute(int i,int *buf){
  buf[0]=i/1000%10;
  buf[1]=i/100%10;
  buf[2]=i/10%10;
  buf[3]=i%10;
}

pii hitAndBlow(int n,int q){
  int hit=0,blow=0;
  int buf1[5],buf2[5];
  compute(n,buf1);
  compute(q,buf2);
  rep(i,4){
    rep(j,4){
      if (buf1[i] == buf2[j]){
	if (i == j)hit++;
	else blow++;
      }
    }
  }
  return make_pair(hit,blow);
}

int solve(vector<int> &a,vector<int> all){
 // if (a.size() > 15)return -1;
  rep(i,all.size()){
    int buf[5];
    bool isok=true;
    int cnt[5][5]={0};
    rep(j,a.size()){
      pii tmp = hitAndBlow(a[j],all[i]);
      cnt[tmp.first][tmp.second]++;
      if (cnt[tmp.first][tmp.second] > 1)isok=false;
    }
    if (isok)return all[i];
  }
  return -1;
}

main(){
  int n;
  vector<int> all(N);
  rep(i,N){
    int buf[4];
    compute(i,buf);
    bool isok=true;
    rep(j,4)REP(k,j+1,4)if (buf[j] == buf[k]){isok=false;}
    all[i]=(isok?i:-1);
  }
  sort(all.begin(),all.end());
  all.erase(remove(all.begin(),all.end(),-1),all.end());
  while(cin>>n && n){
    /*
    vector<pii> in(n);
    vector<int> cand,query(n);
    rep(i,n)cin>>query[i]>>in[i].first>>in[i].second;
    rep(i,all.size()){
      bool isok=true;
      int buf[5];
      rep(j,n){
	pii tmp =hitAndBlow(all[i],query[j]);
	if (tmp.first == in[j].first && tmp.second == in[j].second);
	else {
	  isok=false;
	}
      }
      if (isok)cand.push_back(all[i]);
    }
    sort(cand.begin(),cand.end());
    */
    vector<int> cand;
    cand=all;
    rep(k,n){
      vector<int> b;
      int q,hit,blow;
      cin>>q>>hit>>blow;
      rep(i,cand.size()){
	bool isok=true;
	pii tmp =hitAndBlow(q,cand[i]);
	if (hit == tmp.first && blow == tmp.second);
	else {
	  isok=false;
	}
	if (isok)b.push_back(cand[i]);
      }
      cand=b;
    }

    int ans = cand.size() == 1?cand[0]:solve(cand,all);
    if (ans !=-1)printf("%04d\n",ans);
    else puts("????");
  }
  return false;
}

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

const int MAX_T = 55;
const int MAX_P = 11;

bool is_correct[MAX_T][MAX_P];
int correct_cnt[MAX_T];
int penalty_record[MAX_T][MAX_P];
int elapsed[MAX_T];

bool cmp(const int& team1, const int& team2) {
    if (correct_cnt[team1] != correct_cnt[team2]) {
        return correct_cnt[team1] > correct_cnt[team2];
    }
    else {
        if (elapsed[team1] != elapsed[team2]) {
            return elapsed[team1] < elapsed[team2];
        }
        return team1 > team2;
    }
}

void solve(int M, int T, int P, int R) {
    for (int i = 1; i <= T; i++) {
        correct_cnt[i] = 0;
        elapsed[i] = 0;
        for (int j = 1; j <= P; j++) {
            penalty_record[i][j] = 0;
            is_correct[i][j] = false;
        }
    }
    int m, t, p, j;
    for (int i = 0; i < R; i++) {
        cin >> m >> t >> p >> j;
        if (j == 0) {
            correct_cnt[t]++;
            is_correct[t][p] = true;
            elapsed[t] += m + 20 * penalty_record[t][p];
        }
        else {
            penalty_record[t][p]++;
        }
    }
    vector<int> ans;
    for (int i = 1; i <= T; i++) {
        ans.push_back(i);
    }
    sort(ans.begin(), ans.end(), cmp);
    for (int i = 0; i < ans.size() - 1; i++) {
        cout << ans[i];
        if (correct_cnt[ans[i]] != correct_cnt[ans[i + 1]]) {
            cout << ',';
        }
        else {
            if (elapsed[ans[i]] != elapsed[ans[i + 1]]) {
                cout << ',';
            }
            else cout << '=';
        }
    }
    cout << ans[ans.size() - 1] << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int M, T, P, R;
    while (true) {
        cin >> M >> T >> P >> R;
        if (M == 0 && T == 0 && P == 0 && R == 0) break;
        solve(M, T, P, R);
    }
    return 0;
}


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

int a[21], b[21], c[21];

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

    int sol=0, r=-1;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=n;i++)cin>>b[i];
    for(int i=1;i<n;i++)cin>>c[i];

    for(int i=1;i<=n;i++){
        sol+=b[a[i]];
        if(r+1==a[i])sol+=c[r];
        r=a[i];
    }

    cout<<sol;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int N,i;
  int l,r;
  int d;
  int sum;
  cin >> N;
  for(i=0; i<N; i++){
    cin >> l >> r;
    d=r-l+1;
    sum+=d;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
int main(){

  int n,tmp;
  priority_queue<int, vector<int>, greater<int> > queue;
  std::cin >> n;

  for (int i = 0; i < n; i++) {
    std::cin >> tmp;
    queue.push(tmp*100000);
  }



  do {
    int now=0;
    now+=queue.top();
    queue.pop();
    now+=queue.top();
    queue.pop();
    queue.push(now/2);
  } while(queue.size()!=1);

  printf("%5f\n",(double)queue.top()/100000);



  return 0;
}



Measured memory_bytes: 256
#ifdef __APPLE__
#include <iostream>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#else
#include <bits/stdc++.h>
#endif

using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define tc(t) for (int tc=1; tc<=t; tc++)
typedef vector<int> VI;
typedef vector<long long int> VLLI;
typedef vector<pair<int, int> > VPI;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll, ll> PLL;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll modInverse (ll a) {ll p = mod - 2; return powmod(a, p);}
// head

int main() {
    vector<int>a (3);
    ll ans = 0;
    for (int i = 0; i < 3; i++)
        cin >> a[i], ans += a[i];

    if (ans >= 22)
        cout << "bust" << "\n";
    else
    {
        cout << "win" << "\n";
    }
    
}



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

namespace ConsoleApp1
{
    static class BCountABC
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());            
            var s = Console.ReadLine();
            int count = 0;

            while (true)
            {
                var index = s.IndexOf("ABC");
                if (index < 0)
                {
                    break;
                }

                s = s.Substring(index + 3);
                count++;
            }            

            Console.WriteLine(count);
            Console.ReadLine();
        }
    }
}

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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define repi(i, n) for(int i=0;i<(int)(n);i++)
#define rep2i(i, s, n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(), v.end()

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const ll INF = (1LL<<60);
const int INFi = (1<<29);

int main(){

    long double a, b; cin >> a >> b;

    cout << (ll)(a*b) << endl;

    return 0;
}

Measured memory_bytes: 3732
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint a, b, k;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> a >> b >> k;
	
	llint cnt = 0;
	for(int i = 100; i >= 1; i--){
		if(a % i == 0 && b % i == 0){
			cnt++;
			if(cnt == k){
				cout <<i << endl;
				return 0;
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#pragma GCC optimize ("Ofast")

using namespace std;
#define ms(x,a) memset(x,a,sizeof x)
typedef long long ll;
typedef pair<int,int> pii;
const int mod=1e9+7,seed=131,MAXN=0;
const ll lim=1e18;

int main(){
    cin.tie(0)->sync_with_stdio(0);
    int n; cin >> n;
    vector<ll> arr(n);
    for (int i=0;i<n;++i){
        cin >> arr[i];
    }
    sort(arr.begin(),arr.end());
    ll tot=1;
    for (int i=0;i<n;++i){
        if (log10l(tot+0.0)+0.0+log10l(arr[i]+0.0)>18){ cout << -1 << '\n'; return 0; }
        tot*=arr[i];
        if (tot>lim || tot<0){ cout << -1 << '\n'; return 0; }
    }
    cout << tot << '\n';
}

Measured memory_bytes: 4028
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return 0&pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  return 0;
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;

int sum(ll x){return x<10?x:x%10+sum(x/10);}

int main(){
int k=read();
for (ll s=1,d=1;k--;s+=d) 
  for (write(s),pl;1.0*(s+d)/sum(s+d)>1.0*(s+(d<<1))/sum(s+(d<<1));) 
    d=(d<<3)+(d<<1);
}
/*
    令f(n)是对于某个n>N来说n/s(n)最小的正整数(如果碰到平局的情况,选择最小的那一个数.).
一开始令N=1,然后不断把f(N+1)赋值给N,我们就可以将所有的Snuke number按照递增的顺序罗列出来.
现在我们要做的是算出每一个N对应的f(N).
    我们可以证明f(N)总是可以通过把N的最后面(最不重要的)k个数字变成9而得到.
	令x=f(N).简单来说,我们令xi表示x的第i个数字(也就是x中10^i的系数).假设x>N并且第d个数字是 
x与N不相等的第一个(最重要的)数字.(注意N和x总是有相同数量的数字,比如说可以轻松证明999...999
永远是一个Snuke Number.)我们现在需要证明x0=x1=...=xd=9.
    如果对于某个i<d,xi<9,令y是那个可以被从xi变成9,并且xd变成xd-1而变成的数字.这样的话非常
清楚,N<=y<x并且s(y)>=s(x).这样与x/s(x)最小矛盾.所以x0=...=x[d-1]=9. 
    那么我们知道x0=...=x[d-1],xd不知道,并且x[d+1]以及之后的N的每一个位置上的数都不知道.
接下来我们定义z为当xd=0且w=xd的时候的x.那么可以得到x=z+w*10^d,s(x)=s(z)+w,且x/s(x)=(z+w*10^d)/(s(z)+w).
这是一个关于w的单调函数,最佳的w值既是最小的合法值,也是N的第d个位置上的数或者是最大的合法值(即9).
我们知道第d个位置的数,是x和N不等的地方,那么xd=9.(这种观察是不必要的-即使不观察,最终符合条件
的候选也是足够的.)
    那么我们已经把x的候选给限制了.对于每一个候选计算出x/s(x).f(N)就是使该值最小的数. 
*/


Measured memory_bytes: 256
// by adiforluls
#pragma GCC optimize ("-O2")
#include<bits/stdc++.h>
using namespace std;
#define FAST   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll          long long
#define ld          long double
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define mii         map<int,int>
#define vi          vector<int>
#define vll         vector<long long>
#define all(a)      (a).begin(),(a).end()
#define clz(a)      __builtin_clz(a) // count leading zeroes
#define ctz(a)      __builtin_ctz(a) // count trailing zeroes
#define popc(a)     __builtin_popcount(a) // count set bits (for ints only diff for ll)
#define lul         1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define SIZE        1000005
#define F           first
#define S           second
#define debug(x)    cerr << #x << " = " << x << endl;
#define mod         998244353

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " = " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " = " << arg1<<" |";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define endl        '\n'
const ld PI = acos(-1.0);
const int INF = 0x3f3f3f3f;

void solve()
{
   int r,g,b,n; cin>>r>>g>>b>>n;
   ll ans=0;
   rep(i,0,n+1)
   {
     rep(j,0,n+1)
     {
       int check=(n-i*r-j*g);
       if(check>=0 && check%b==0) ans++;
     }
   }
   cout<<ans;   
} 
int main()
{   
   FAST;
   //  #ifndef ONLINE_JUDGE
     // freopen("input.txt", "r", stdin);
     // freopen("output.txt", "w", stdout);
   //  #endif
    int t; t=1;
    while(t--){
       solve();
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}
	
	void run() {
		int s = sc.nextInt();
		
		boolean yymm = isYYMM(s);
		boolean mmyy = isMMYY(s);
		
		if(yymm && !mmyy) {
			System.out.println("YYMM");
		}else if(mmyy && !yymm) {
			System.out.println("MMYY");
		}else if(mmyy && yymm) {
			System.out.println("AMBIGUOUS");
		}else {
			System.out.println("NA");
		}
		
		
	}
	
	boolean isYYMM(int str) {
		int mm = str % 100;
		if(mm >= 1 && mm <= 12) {
			return true;
		}
		return false;
	}
	
	boolean isMMYY(int str) {
		int mm = str / 100;
		if(mm >= 1 && mm <= 12) {
			return true;
		}
		return false;
	}
}


Measured memory_bytes: 21588
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

#define N 200010 

using namespace std;

typedef long long ll;

char *p1, *p2, buf[100000];

#define nc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1 ++ )

int rd() {
    int x = 0, f = 1;
    char c = nc();
    while (c < 48) {
        if (c == '-')
            f = -1;
        c = nc();
    }
    while (c > 47) {
        x = (((x << 2) + x) << 1) + (c ^ 48), c = nc();
    }
    return x * f;
}

int b[2];

char s[N];

int main() {
    scanf("%s", s + 1);
    int n = strlen(s + 1);
    ll ans = 0;
    for (int i = 1; i <= n; i ++ ) {
        int c = ((s[i] == 'B') ? 1 : 0);
        // cout << c << endl ;
        if (!c) {
            ans += b[1];
        }
        b[c] ++ ;
    }
    cout << ans << endl ;
    return 0;
}

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

using namespace std;
typedef long long ll;

int main(void) {
  ll n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;

  b -= a;
  ll width = 1 + (d - c) * (n - 1);
  ll total = d * (n - 1) * 2 + 1;
  ll blank = max(0LL, 2 * (c - 1) + 1 - (d - c) * (n - 2));
  if (abs(b) > d * (n - 1)) {
    cout << "NO\n";
  } else {
    b += d * (n - 1);
    b %= (width + blank);
    cout << (0 <= b && b < width ? "YES" : "NO") << endl;
  }

  return 0;
}

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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int WWW = 0;WWW < (n);WWW++)cerr << v[WWW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

ll dp[4][55][55][55][55];
ll n,m;
vector<ll> a;
vector<ll> b;

ll check(ll hoge,ll x1,ll y1,ll x2,ll y2){
	ll ret = 0;
	for(ll i = x1-1;i >= x2;i--){
		if(a[i] != -1)ret += a[i];
	}
	for(ll i = y1-1;i >= y2;i--){
		if(b[i] != -1)ret -= b[i];
	}
	DBG(cout << "check " << hoge << ' ' << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << endl;
	cout << ret << endl;)
	return ret;
}

ll dfs(ll type,ll x1,ll y1,ll x2,ll y2){
	DBG(cout << "IN " << type << ' ' << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << endl;)
	if(dp[type][x1][y1][x2][y2] != LLINF)return dp[type][x1][y1][x2][y2];
	ll ret;
	//A
	if(type % 2 == 0){
		ret = -LLINF;
		//置く
		if(x1 < n){
			if(a[x1] == -1){
				ret = max(ret,dfs(1,x1+1,y1,x2,y1));
			}
			else{
				ret = max(ret,dfs(1,x1+1,y1,x2,y2));
			}
		}
		//置かない
		if(type == 2)ret = max(ret,0LL);
		else if(x1 == x2 && y1 == y2){
			ret = max(ret,dfs(3,x1,y1,x2,y2));
		}
		else{
			ll tmp = check(type,x1,y1,x2,y2);
			ret = max(ret,dfs(1,x1,y1,x1,y1)+tmp);
		}
	}
	//B
	else{
		ret = LLINF;
		//置く
		if(y1 < m){
			if(b[y1] == -1){
				ret = min(ret,dfs(0,x1,y1+1,x1,y2));
			}
			else{
				ret = min(ret,dfs(0,x1,y1+1,x2,y2));
			}
		}
		//置かない
		if(type == 3)ret = min(ret,0LL);
		else if(x1 == x2 && y1 == y2){
			ret = min(ret,dfs(2,x1,y1,x2,y2));
		}
		else{
			ll tmp = check(type,x1,y1,x2,y2);
			ret = min(ret,dfs(0,x1,y1,x1,y1)+tmp);
		}
	}
	
	DBG(cout << "OUT " << type << ' ' << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << ' ' << ret << endl;)
	return dp[type][x1][y1][x2][y2] = ret;
}

int main(){
	
	cin >> n >> m;
	REP(i,n){
		ll tmp;cin >> tmp;a.PB(tmp);
	}
	REP(i,m){
		ll tmp;cin >> tmp;b.PB(tmp);
	}
	
	REP(i,55)REP(j,55)REP(k,55)REP(l,55){
		dp[0][i][j][k][l] = LLINF;
		dp[2][i][j][k][l] = LLINF;
		dp[1][i][j][k][l] = LLINF;
		dp[3][i][j][k][l] = LLINF;
	}
	
	cout << dfs(0,0,0,0,0) << endl;

	return 0;
}



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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String [] sArray = s.split("");
		int count = 0;
		int maxlen = 0;
		for(int i = 0; i < sArray.length; i++) {
			if(sArray[i].equals("A")||sArray[i].equals("C")||sArray[i].equals("G")||sArray[i].equals("T")) {
				count++;
				if(count >= maxlen) maxlen = count;
			}else count = 0;
		}
		System.out.println(maxlen);
		sc.close();
	}

}


Measured memory_bytes: 21716
#include<iostream>
using namespace std;
int t1,t2;
string s;
int main()
{
    int i;
    cin>>s;
    for(i=0;i<3;i++) 
    {
        if(s[i]=='A') t1=1;
        else t2=1;
    }
    if(t1==1&&t2==1) cout<<"Yes";
    else cout<<"No";
}

    


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

int main() {
  int x, a;
  cin >> x >> a;
  if (x < a) {
    cout << 0 << endl;
  } else {
    cout << 10 << endl;
  }
}


Measured memory_bytes: 256
N = int(input())
p = [0] + list(map(float, input().split()))

dp = [[0] * (N + 1) for _ in range(N + 1)]
dp[0][0] = 1

for i in range(1, N + 1):
    for j in range(N + 1):
        dp[i][j] = dp[i - 1][j - 1] * p[i] + dp[i - 1][j] * (1 - p[i])

print(sum(dp[N][i] for i in range(N // 2 + 1, N + 1)))

Measured memory_bytes: 203728
n,a,b=map(int,input().split())
if (b-a)%2==0:
    print((b-a)//2)
else:
    if a-1<=n-b:
        tmp=a
        b=b-a
        print(((b-1)//2)+a)
    else:
        tmp=(n-b)+1
        a=a+tmp
        print(((n-a)//2)+tmp)

Measured memory_bytes: 3060
type UnionFind=record n:Longint;pr:Array of Longint;end;
procedure init(var uf:UnionFind;N:Longint);
var i:Longint;
begin
	uf.n:=N;
	setlength(uf.pr,N);
	for i:=1 to N do uf.pr[i]:=-1;
end;
function find(var uf:UnionFind;a:Longint):Longint;
begin
	if uf.pr[a]<0 then find:=a else begin
		uf.pr[a]:=find(uf,uf.pr[a]);
		find:=uf.pr[a];
	end;
end;
function same(var uf:UnionFind;a,b:Longint):Boolean;
begin
	same:=find(uf,a)=find(uf,b);
end;
function unite(var uf:UnionFind;a,b:Longint):Boolean;
begin
	a:=find(uf,a);
	b:=find(uf,b);
	if a=b then unite:=false else begin
		if uf.pr[a]>uf.pr[b] then begin
			inc(uf.pr[b],uf.pr[a]);
			uf.pr[a]:=b;
		end else begin
			inc(uf.pr[a],uf.pr[b]);
			uf.pr[b]:=a;
		end;
		unite:=true;
	end;
end;
function size(var uf:UnionFind;a:Longint):Longint;
begin
	size:=-uf.pr[find(uf,a)];
end;
var
	U,V,suc,beg:Array[1..400000]of Longint;
	N,M,K,i,id,a,b,ec,ans:Longint;
	uf:UnionFind;
procedure add_edge(a,b:Longint);
begin
	inc(ec);
	U[ec]:=a;
	V[ec]:=b;
	suc[ec]:=beg[a];
	beg[a]:=ec;
end;
begin
	read(N,M,K);
	init(uf,N);
	for i:=1 to M do begin
		read(a,b);
		add_edge(a,b);
		add_edge(b,a);
		unite(uf,a,b);
	end;
	for i:=1 to K do begin
		read(a,b);
		add_edge(a,b);
		add_edge(b,a);
	end;
	for i:=1 to N do begin
		ans:=size(uf,i)-1;
		id:=beg[i];
		while id>0 do begin
			if same(uf,i,V[id]) then dec(ans);
			id:=suc[id];
		end;
		writeln(ans);
	end;
end.


Measured memory_bytes: 7040
#include <iostream>
#include <math.h>
using namespace std;

int insSort(int *a, int n, int g) {
	int j, key, cnt = 0;
	for (int i = g; i < n; i++) {
		key = a[i];
		j = i - g;
		while(( j >= 0) && (a[j] > key)) {
			a[j+g] = a[j];
			j = j - g;
			cnt++;
		}
		a[j+g] = key;
	}
	return cnt;
}

int main(){
	int n, m, cnt=0;
	cin >> n;
	int *a = new int[n];
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (m = 1; m < n + 2; m++) {
		if ((pow( 3 , m ) -1) / 2 > n) {
			m = m - 1;
			break;
		}
	}
	int *g = new int[m];
	for (int i = 0; i < m; i++ ) {
		g[i] = (pow(3, m - i) -1) / 2;
		cnt += insSort(a, n, g[i]);
	}
	cout << m << endl;
	for (int i = 0; i < m - 1; i++ )
		cout << g[i] << ' ';
	cout << g[m - 1] << endl;
	cout << cnt << endl;
	for (int i = 0; i < n; i++)
		cout << a[i] << endl;
	return 0;
}

Measured memory_bytes: 7112
N=int(input())
happiness=[list(map(int,input().split())) for _ in range(N)]

dp=[[0]*3 for _ in range(N+1)]

for i in range(N):
    for j in range(3):
        for k in range(3):
            if j==k:
                continue

            dp[i+1][j]=max(dp[i+1][j],dp[i][k]+happiness[i][j])

print(max(dp[N]))

Measured memory_bytes: 74200
/*       In The Name Of ALLAH
                                            */

#include <bits/stdc++.h>  // This will work only for g++ compiler.


#define for0(i, n) for (int i = 0; i < (int)(n); ++i) // 0 based indexing
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i) // 1 based indexing
#define forc(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i) // closed interver from l to r r inclusive
#define forr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i) // reverse 0 based.
#define forr1(i, n) for (int i = (int)(n); i >= 1; --i) // reverse 1 based

//short hand for usual tokens
#define pb push_back
#define fi first
#define se second

// to be used with algorithms that processes a container Eg: find(all(c),42)
#define all(x) (x).begin(), (x).end() //Forward traversal
#define rall(x) (x).rbegin, (x).rend() //reverse traversal

// traversal function to avoid long template definition. Now with C++11 auto alleviates the pain.
#define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++)

// find if a given value is present in a container. Container version. Runs in log(n) for set and map
#define present(c,x) ((c).find(x) != (c).end())

//find version works for all containers. This is present in std namespace.
#define cpresent(c,x) (find(all(c),x) != (c).end())

// Avoiding wrap around of size()-1 where size is a unsigned int.
#define sz(a) int((a).size())
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'

using namespace std;

// Shorthand for commonly used types
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld;


int main() {

optimize();
   int n;
   cin>>n;
   vii vec;
   while(n--)
   {
      int x,y;
      cin>>x>>y;
      vec.pb({x,y});
   }
   int found=0;
   for(int i=0;i<vec.size()-2;i++)
   {
       if(vec[i].fi==vec[i].se)
       {
           if(vec[i+1].fi==vec[i+1].se)
           {
               if(vec[i+2].fi==vec[i+2].se)
               {
                   cout<<"Yes";
                   found=1;
                   return 0;
               }
               else
                found=0;
           }
       }
   }
   if(found==0)
    cout<<"No";

    return 0;
}


Measured memory_bytes: 3660
N = int(input())
b = [int(i) for i in input().split()]

answer_list = []
for i in range(N-1, -1, -1):
  answer = False
  for index, j in list(reversed(list(enumerate(b)))):
    if index == j-1:
      answer = True
      answer_list.append(j)
      b.pop(index)
      break
  if not answer:
      print(-1)
      exit()

for i in range(len(answer_list)-1, -1, -1):
  print(answer_list[i])



    


Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;

#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>0?(a):-(a))
#define ALLOC(size,type) ((type*)calloc((size),sizeof(type)))

void run (void) {
  i32 n;
  scanf ("%" SCNi32, &n);
  i32 *w = ALLOC (n + 1, i32);
  for (i32 i = 0; i < n; ++i) {
    scanf ("%" SCNi32, w + i);
  }
  for (i32 i = n - 2; i >= 0; --i) {
    w[i] += w[i + 1];
  }
  i32 min = 100 * n;
  for (i32 i = 0; i < n - 1; ++i) {
    min = MIN(min, ABS((w[0] - w[i + 1]) - (w[i + 1])));
  }
  printf ("%" PRIi32 "\n", min);
}

int main (void) {
  run();
  return 0;
}


Measured memory_bytes: 128
#include <cstdio>

int main()
{
	char ch;
	int n = 0;

	while ((ch = getchar())!= '0' || n != 0)
	{
		if (ch == '\n')
		{
			printf("%d\n",n);
			n = 0;
		}
		else
		{
			ch &= 0x0F;
			n += ch;
		}
	}
	return 0;
}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

int calc(int x, int targ)
{
    int ret = 0;
    while (x < targ) {
        ret++;
        x *= 2;
    }
    return ret;
}

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

    int2(n, k);
    double ans = 0.0;
    for (int i = n; i > 0; i--) {
        int tmp = calc(i, k);
        //double temp = 1.0 / (pow(2, tmp));
        //cout << i << " " << tmp << " " << temp << endl;
        ans += 1.0 / (pow(2, tmp));
    }
    std::cout << Decimal << ans / (double)n << std::endl;

    return 0;
}


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

struct bridge{
  int a;
  int b;
  int cost;
  bool operator<(const bridge &another) const{
    return cost<another.cost;
  };
};

int main(void){
  int n,m;
  int a,b,cost;
  int retval;
  while(1){
    cin>>n>>m;
    retval=0;
    if(n==0 and m==0)break;
    vector<bridge> bridges;
    for(int i=0;i<m;i++){
      bridge bri;
      cin>>a>>b>>cost;
      bri.a=a;
      bri.b=b;
      bri.cost=cost;
      bridges.push_back(bri);
    }
    sort(bridges.begin(),bridges.end());
    int city[n];
    for(int i=0;i<n;i++){
      city[i]=i;
    }
    for(int i=0;i<m;i++){
      bridge bri=bridges[i];
      if(city[bri.a]==city[bri.b]){
        continue;
      }
      else{
        retval+=bri.cost;
        int group=city[bri.b];
        for(int j=0;j<n;j++){
          if(city[j]==group){
            city[j]=city[bri.a];
          }
        }
      }
    }
    cout<<retval<<endl;
  }
  return 0;
}



Measured memory_bytes: 3172
#include <iostream>

int main(){
    int N;
    std::cin >> N;
    if(1 <= N && N <= 999){
        std::cout << "ABC" << std::endl;
    }else if(1000 <= N && N <= 1998){
        std::cout << "ABD" << std::endl;
    }
    return 0;
}


Measured memory_bytes: 256
/* https://atcoder.jp/contests/abc126/tasks/abc126_b */

#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>

using namespace std;

/* {{{ Variables */
string S;
/* }}} */

int main(int argc, char *argv[])
{
  /* {{{ Input */
  cin >> S;

  int a = (S.at(0)-'0')*10 + S.at(1)-'0';
  int b = (S.at(2)-'0')*10 + S.at(3)-'0';

  bool is_yymm = a >= 0 && a <= 99 && b >= 1 && b <= 12;
  bool is_mmyy = a >= 1 && a <= 12 && b >= 0 && b <= 99;
  /* }}} */

  /* {{{ Output */
  if (is_yymm && is_mmyy) {
    cout << "AMBIGUOUS" << endl;
    return 0;
  }

  if (is_yymm) {
    cout << "YYMM" << endl;
    return 0;
  }

  if (is_mmyy) {
    cout << "MMYY" << endl;
    return 0;
  }

  cout << "NA" << endl;
  /* }}} */

  return 0;
}


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

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

int main(){
	int n,a,b,c,d[100];
	cin >> n >> a >> b >> c;
	rep(i,n)  cin >> d[i];
	sort( d, d+n );
	int sval = a, scal = c;
	for(int i=n-1; i>=0; i--){
		if( (double)scal/(double)sval < (double)(scal+d[i])/(double)(sval+b) ){
			sval += b;
			scal += d[i];
		}else  break;
	}
	cout << (int)((double)scal/(double)sval) << endl;
	return 0;
}

Measured memory_bytes: 1176
import java.util.Scanner;

public class Main {
	private Scanner sc;

	int[][] map;
	public static void main(String[] args) {
		new Main();
	}
	
	public Main() {
		sc = new Scanner(System.in);
		
		int[][][] map = new int[11][(int)Math.pow(2, 10)][400];
		
		for (int i = 0; i < map.length; i++) {
			for (int j = 0; j < map[0].length; j++) {
				for (int k = 0; k < map[0][0].length; k++) {
					map[i][j][k] = 0;
				}
			}
		}
		map[0][0][0] = 1;
		
		for (int j = 1; j < map.length; j++) {
			for (int i = 0; i < map[0][0].length; i++) {
				for (int k = 0; k < 10; k++) {
					for (int bit = 0; bit < map[0].length; bit++) {	
						if ((i - j * k) >= 0) {
							if ((bit >> k) % 2 == 1) {
								map[j][bit][i] = map[j][bit][i] + map[j - 1][bit - (int)Math.pow(2, k)][i - j * k];
							}
						} else {
							break;
						}
					}
				}
			}
		}
		
		int[][] ans = new int[map.length][map[0][0].length];
		for (int i = 0; i < map.length; i++) {
			for (int k = 0; k < map[0][0].length; k++) {
				int sum = 0;
				
				for (int j = 0; j < map[0].length; j++) {
					sum = sum + map[i][j][k];
				}
				
				ans[i][k] = sum;
			}
		}
		
		while (sc.hasNextLine() == true) {
			String[] nico = sc.nextLine().split(" ");
			int n = Integer.parseInt(nico[0]);
			int s = Integer.parseInt(nico[1]);
			
			if (s >= 400) System.out.println("0");
			else System.out.println(ans[n][s]);
		}
	}
}

Measured memory_bytes: 46380
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
#define MOD 1000000007

void dijkstra(vector<vector<pair<ll,int>>> &graph, vll &dist, int s){
    priority_queue<pair<ll,int>> que;
    dist[s]=0;
    que.push({0,s});
    while(!que.empty()){
        auto x=que.top(); que.pop();
        if(dist[x.second]<x.first) continue;
        for(auto v:graph[x.second]){
            if(dist[v.second]<dist[x.second]+v.first) continue;
            dist[v.second]=dist[x.second]+v.first;
            que.push({dist[v.second],v.second});
        }
    }
    
}

int main(){
    int n;
    cin >> n;
    vector<vector<pair<ll,int>>> graph(n);
    rep(i,n-1){
        int a,b;
        ll c;
        cin >> a >> b >> c;
        a--; b--;
        graph[a].push_back({c,b});
        graph[b].push_back({c,a});
    }    
    vll dist(n,1e18);
    int q,k;
    cin >> q >> k; k--;
    dijkstra(graph,dist,k);
    rep(i,q){
        int x,y;
        cin >> x >> y;
        x--; y--;
        cout << dist[x]+dist[y] << endl;
    }



}

Measured memory_bytes: 13892
#!/usr/bin/env python3

# a = int(input())
a, b = list(map(int, input().split()))
# a = list(str(input()))

# com_div_list_min = [1]
# com_div_list_max = []
# if a%2==0 and b%2==0:
#     com_div_list_min.append(2)

if a != 1:
    diva_list_min = []
    diva_list_max = []
    count = 1
    while(count <= a**0.5):
        if a % count == 0:
            diva_list_min.append(count)
            diva_list_max.append(a//count)
        count += 1

    diva_list_max.reverse()
    div_a = diva_list_min+diva_list_max
else:
    div_a = [1]

com_div_ab = []
for i in (div_a):
    if b % i == 0:
        com_div_ab.append(i)


if com_div_ab == [1]:
    print(1)
    exit()

count = 1
while(count < len(com_div_ab)):
    new_com_div_ab = com_div_ab[:count+1]
    num = new_com_div_ab[-1]

    for i in range(count+1, len(com_div_ab)):
        if com_div_ab[i] % num != 0:
            new_com_div_ab.append(com_div_ab[i])
    # print(com_div_ab)
    # print(new_com_div_ab)
    # print()
    com_div_ab = new_com_div_ab
    count += 1


print(len(new_com_div_ab))


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

int main() {
  int A, B, C, D, x, y ;
  cin >>A >>B >>C >>D ;
  x = A+B ;
  y = C+D ;
  if ( x > y )
    cout << "Left" ;
  if ( x == y )
    cout << "Balanced" ;
  if ( x < y )
    cout << "Right" ;
  
  
}


Measured memory_bytes: 256
a, b, q = map(int, input().split())
INF = 10 ** 11
s = [int(input()) for _ in range(a)] + [INF]
t = [int(input()) for _ in range(b)] + [INF]
x = [[int(input()), int(i), INF, INF, INF, INF] for i in range(q)]
x.sort(key=lambda x: x[0])
si = 0
ti = 0
for i in range(q):
    xi = x[i][0]
    while xi > s[si]:
        si += 1
    ls = abs(xi - s[si - 1])
    rs = abs(xi - s[si])

    while xi > t[ti]:
        ti += 1
    lt = abs(xi - t[ti - 1])
    rt = abs(xi - t[ti])

    x[i][2] = ls
    x[i][3] = rs
    x[i][4] = lt
    x[i][5] = rt

x.sort(key=lambda x: x[1])
for xi, i, ls, rs, lt, rt in x:
    ans = min(max(ls, lt),
              max(rs, rt),
              min(ls, rt) * 2 + max(ls, rt),
              min(rs, lt) * 2 + max(rs, lt))
    print(ans)

Measured memory_bytes: 45000
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
// const int mod=998244353;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n;
    cin>>n;
    int ans=0;
    for(int i=2;i*i<=n;i++){
        int e=0;
        while(n%i==0)e++,n/=i;
        int z=1;
        while(z<=e)ans++,e-=z,z++;
    }
    if(n!=1)ans++;
    cout<<ans<<endl;
}

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

int main(){
  string S;
  cin >> S;
  bool flag=false;
  string A;
  string B;
  string C;
  string D;
  int count;
  A = S.substr(0,1);
  B = S.substr(1,1);
  C = S.substr(2,1);
  D = S.substr(3,1);
  if(A==B) count++;
  if(A==C) count++;
  if(A==D) count++;
  if(B==C) count++;
  if(B==D) count++;
  if(C==D) count++;


  if(count==2) flag=true;
  cout << (flag?"Yes":"No") << endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val s = readLine()!!.split(" ").map { it.toInt() }
    val a = readLine()!!.split(" ").map { it.toInt() }
    val x = s[1] - 1
    val distanceArray = Array(s[1]){0}
    for (i in 0..x-1){
        distanceArray[i] = a[x-i] - a[x-i-1]
    }
    val n = s[0] - a[x]
    distanceArray[x] = n + a[0]
    val max = distanceArray.max()!!
    val kotae = s[0] - max
    println(kotae)
}


Measured memory_bytes: 82560
using System;
 
namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
    string[] input = Console.ReadLine().Split(' ');
    int s =int.Parse(input[0]);
    int w =int.Parse(input[1]);
    
    if(s <= w){
    Console.WriteLine("unsafe");
    }else{
    Console.WriteLine("safe");
    }
    
  }

}
}

Measured memory_bytes: 27516
#include<bits/stdc++.h>
using namespace std;
const int N=4090;
int n,a[2][N],f[N/2][N/2],cnt[2][N][N/2];
int rec(int b,int w)
{
	if(f[b][w]!=-1)return f[b][w];
	if(b==0&&w==0)return 0;
	int ret=1e9;
	if(b>0)ret=min(ret,rec(b-1,w)+a[0][b]+cnt[0][a[0][b]][b-1]+cnt[1][a[0][b]][w]-b-w);
	if(w>0)ret=min(ret,rec(b,w-1)+a[1][w]+cnt[0][a[1][w]][b]+cnt[1][a[1][w]][w-1]-b-w);
	return f[b][w]=ret;
}
int main()
{
	scanf("%d",&n);
	for(int i=1,x;i<=2*n;i++)
	{
		char ch;scanf(" %c%d",&ch,&x);
		if(ch=='W')a[1][x]=i;else a[0][x]=i;
	}
	for(int i=0;i<=n;i++)for(int j=0;j<=n;j++)f[i][j]=-1;
	for(int i=1;i<=2*n;i++)for(int j=1;j<=n;j++)
	{
		if(i<a[0][j])cnt[0][i][j]++;
		if(i<a[1][j])cnt[1][i][j]++;
	}
	for(int i=1;i<=2*n;i++)for(int j=1;j<n;j++)
	cnt[0][i][j+1]+=cnt[0][i][j],cnt[1][i][j+1]+=cnt[1][i][j];
	memset(f,-1,sizeof f);
	printf("%d\n",rec(n,n));
}

Measured memory_bytes: 82176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1LL<<60;
const double EPS = 1e-10;
const ll mod=1000000007;

int main(void){
    int n;
    cin>>n;
    if(n==1) cout<<1<<endl;
    else if(n<4) cout<<2<<endl;
    else if(n<8) cout<<4<<endl;
    else if(n<16) cout<<8<<endl;
    else if(n<32) cout<<16<<endl;
    else if(n<64) cout<<32<<endl;
    else cout<<64<<endl;
}

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define INF 10000000000
using ll = long long;
using Graph = vector<vector<int>>;

//以下n,kが510000まで対応可能

//二項係数を求める。
const int MAX = 510000;
const int MOD = 1000000007;

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

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main(){
  int N,K; cin>>N>>K;
  COMinit();
  rep1(i,K+1){
    ll res = 0;
    res = COM(N-K+1,i)*COM(K-1,i-1);
    cout<<res%MOD<<endl;
  }
}


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

int main() {
  int N;
  cin >> N ;
  string ans = "Three";

  // ここにプログラムを追記
  for (int i=0;i<N;i++){
      string S;
      cin >>S;
      if(S=="Y")
          ans = "Four";
       
          
      
  }
  cout << ans << endl;
      
}


Measured memory_bytes: 256
import java.util.*;

class Main{

    int INF = Integer.MAX_VALUE;

    void solve(){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] ab = new int[m][2];
        for(int i=0; i<m; i++){
            ab[i][0] = sc.nextInt()-1;
            ab[i][1] = sc.nextInt()-1;
        }

        Arrays.sort(ab, new Comparator<int[]>(){
                public int compare(int[] a, int[] b){
                    if(a[0]>b[0]) return 1;
                    if(a[0]<b[0]) return -1;
                    if(a[1]>b[1]) return 1;
                    if(a[1]<b[1]) return -1;
                    return 0;
                }
            });

        int cnt = 0;
        int idx = 0;
        while(idx<n){
            int idx2 = -1;
            for(int i=0; i<m; i++){
                if(ab[i][0]<=idx && idx<=ab[i][1]) idx2 = Math.max(idx2, ab[i][1]);
            }
            if(idx2==-1) break;
            idx = idx2 + 1;
            cnt++;
        }

        if(idx!=n) System.out.println("Impossible");
        else System.out.println(cnt);
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

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

using namespace std;


int main() {

  string S;

  cin >> S;
  
  if(S == "SUN"){
    cout << 7 << endl;
  }else if(S == "MON"){
    cout << 6 << endl;
  }else if(S == "TUE"){
    cout << 5 << endl;
  }else if(S == "WED"){
    cout << 4 << endl;
  }else if(S == "THU"){
    cout << 3 << endl;
  }else if(S == "FRI"){
   cout << 2 << endl;
  }else if(S == "SAT"){
    cout << 1 << endl;
  }
}

Measured memory_bytes: 256