akhauriyash/Code-Regression huggingface dataset:
/*
    Author:zeke

    pass System Test!
    GET AC!!
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
// cout << "Case #" << index << " :IMPOSSIBLE";
long long GCD(long long a,long long b){
    if(b==0)return a;
    return GCD(b,a%b);
}
long long LCM(long long a,long long b){
    return a*b/GCD(a,b);
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    ll n;
    cin>>n;
    VV vec(n+1,V(3));
    rep3(i,1,n+1){
        rep(j,3){
            cin>>vec[i][j];
        }
    }
    VV dp(n+2,V(3));
    rep3(i,2,n+2){
        dp[i][0]=max(dp[i-1][1]+vec[i-1][1],dp[i-1][2]+vec[i-1][2]);
        dp[i][1]=max(dp[i-1][0]+vec[i-1][0],dp[i-1][2]+vec[i-1][2]);
        dp[i][2]=max(dp[i-1][1]+vec[i-1][1],dp[i-1][0]+vec[i-1][0]);
    }
    cout<<max({dp[n+1][0],dp[n+1][1],dp[n+1][2]})<<endl;
}


Measured memory_bytes: 11136
// Last Change: 07/30/2019 18:24:01.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N + 1);
  vector<ll> B(N);
  for (auto &&e : A) {
    cin >> e;
  }

  ll ipt, ans = 0;
  for (ll i = 0; i < N; ++i) {
    cin >> ipt;
    if (ipt - A[i] > 0) {
      ans += A[i];
      ipt -= A[i];
      if (ipt - A[i + 1] > 0) {
        ans += A[i + 1];
        A[i + 1] = 0;
      } else {
        ans += ipt;
        A[i + 1] -= ipt;
      }
    } else {
      ans += ipt;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> l(n), r(n);
	rep(i, n) cin >> l[i] >> r[i];

	int ans = 0;
	rep(i, n) {
		ans += r[i] - l[i] + 1;
	}
	dunk(ans);

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define vvvel vector<vvel>
void mmin(int &a, int b) { a = min(a, b); }
void mmax(int &a, int b){ a = max(a, b); }
void sor(vel &v) { sort(v.begin(), v.end()); }
int zero() { return 0; }
signed main() {
	int h, w;
	cin >> h >> w;
	vvel co(h, vel(w));
	vvel alch(h, vel(w, 0));
	for (int i = 0; i < h; i++) {
		string s;
		cin >> s;
		for (int j = 0; j < w; j++) {
			if (s[j] == '.') {
				alch[i][j] = 1;
				co[i][j] = 0;
			}
			else {
				co[i][j] = s[j];
				co[i][j] -= 48;
			}
		}
	}
	vel queh(h*w);
	vel quew(h*w);
	int st = 0;
	int to = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (alch[i][j] == 0) {
				for (int k = i - 1; k <= i + 1; k++) {
					for (int l = j - 1; l <= j + 1; l++) {
						co[i][j] -= alch[k][l];
					}
				}
				if (co[i][j] <= 0) {
					queh[to] = i;
					quew[to] = j;
					to++;
				}
			}
		}
	}
	int ans = 0;
	while (to > st) {
		ans++;
		int qto = to;
		for (int in = st; in < to; in++){
			int chi = queh[in];
			int chj = quew[in];
			for (int i = chi - 1; i <= chi + 1; i++) {
				for (int j = chj - 1; j <= chj + 1; j++) {
					if (co[i][j] > 0) {
						co[i][j]--;
						if (co[i][j] <= 0) {
							queh[qto] = i;
							quew[qto] = j;
							qto++;
						}
					}
				}
			}
		}
		st = to;
		to=qto;
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 34252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
constexpr int di[] = { 0, 1, 0, -1 }, dj[] = { 1, 0, -1, 0 };
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define N 100005
constexpr ll inf = 100000000000000;
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/

bool check(int mid){

  return false;
}

ll serch(ll ok,ll ng) {
	while (abs(ok-ng) > 1) {
		ll mid = (ok + ng) / 2;
		if (check(mid))ok = mid;
		else ng = mid;
	}
	return ok;
}

int main(){
  cout<<fixed<<setprecision(20);
  cin.tie(0);ios::sync_with_stdio(false);
  int n,y;
  cin>>n>>y;
  n++;
  rep(i,n){
    rep(j,n){
      if(10000*i+5000*j<=y){
        int k=(y-10000*i-5000*j)/1000;
        if((y-10000*i-5000*j)%1000==0&&i+j+k==n-1){
          cout<<i<<' '<<j<<' '<<k<<endl;
          return 0;
        }
      }
    }
  }
  cout<<-1<<' '<<-1<<' '<<-1<<endl;
  return 0;
}



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

int main(){
	long long int a,b;
	cin>>a>>b;
	
	if(a%b==0){
		cout<<-1<<endl;
		return 0;
	}
	
	for(int i=a;i<b*b+a*a;i+=a){
		if(i%b!=0){
			cout<<i<<endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

public class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int[] a = new int[n];
        int[] input = new int[n];
        int tmp;
        for (int i = 0; i < n; i++)
        {
            tmp = int.Parse(Console.ReadLine());
            a[i] = tmp;
            input[i] = tmp;
        }
        Array.Sort(a);
        a = a.Reverse().ToArray();
        int max = a[0];
        for (int i = 0; i < n; i++)
        {
            if (input[i] == max)
            {
                Console.WriteLine(a[1]);
            }
            else
                Console.WriteLine(max);
        }
    }
}

Measured memory_bytes: 21460
#include <cstdio>
#include <algorithm>
#define ISPLUS(X) ((X) > 0)
#define ISZERO(X) ((X) == 0)
#define ABS(X) ((ISPLUS(X)) ? (X) : -(X))
const int DIV = 1000000007;

int comp(int a, int b) {
	if (!ISPLUS(a)) a *= -1;
	if (!ISPLUS(b)) b *= -1;
	return a > b;
}

int main() {
	int arr[200003], n, k;
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; i++) {
		scanf("%d", &arr[i]);
	}
	std::sort(arr, arr + n, comp);
	int p_min = -1, n_min = -1, n_cnt = 0;;
	for (int i = 0; i < k; i++) {
		if (ISPLUS(arr[i]) || ISZERO(arr[i])) p_min = i;
		if (!ISPLUS(arr[i]) || ISZERO(arr[i])) n_min = i, ++n_cnt;
	}
	
	if (n_cnt % 2 == 0) {
		long long ans = 1;
		for (int i = 0; i < k; i++) {
			ans *= ABS(arr[i]);
			ans %= DIV;
		}
		printf("%lld", ans);
		return 0;
	}
	
	int p_max = -1, n_max = -1;
	for (int i = n-1; i >= k; i--) {
		if (ISPLUS(arr[i]) || ISZERO(arr[i])) p_max = i;
		if (!ISPLUS(arr[i]) || ISZERO(arr[i])) n_max = i;
	}


	long long ta1 = 0, ta2 = 0;
	if (p_max == -1 || n_min == -1) ta1 = -1;
	if (n_max == -1 || p_min == -1) ta2 = -1;

	if (ta1 != -1 && ta2 != -1) {
		ta1 = arr[p_max] * (long long)arr[p_min];
		ta2 = arr[n_max] * (long long)arr[n_min];
	}

	if (ta1 >= ta2) {
		if (ta1 == -1 && ta2 == -1) {
			long long ans = 1;
			for (int i = 0; i < k; i++) {
				ans *= ABS(arr[n - 1 - i]);
				ans %= DIV;
			}
			ans *= -1;
			ans += DIV;
			ans %= DIV;
			printf("%lld", ans);
			return 0;
		}
		long long ans = 1;
		for (int i = 0; i < k; i++) {
			if (i == n_min) continue;
			ans *= ABS(arr[i]);
			ans %= DIV;
		}
		ans *= ABS(arr[p_max]);
		ans %= DIV;
		printf("%lld", ans);
		return 0;
	}
	else {
		long long ans = 1;
		for (int i = 0; i < k; i++) {
			if (i == p_min) continue;
			ans *= ABS(arr[i]);
			ans %= DIV;
		}
		ans *= ABS(arr[n_max]);
		ans %= DIV;
		printf("%lld", ans);
		return 0;
	}
}

Measured memory_bytes: 4008
N=int(input())
flag=0
for h in range(1,3501):
    for n in range(1,3501):
        if 4*h*n-n*N-h*N!=0:
            w = N*h*n/(4*h*n-n*N-h*N)
            if int(w)==w and 1<=w<=3500:
                print(h,n,int(w))
                flag = 1
                break
    if flag==1:
        break

Measured memory_bytes: 73760
import java.util.*;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] ary = new int[n];
        int[] ans = new int[n];

        for (int i = 0; i < n; i++) {
            ary[i] = Integer.parseInt(sc.next());
            ans[ary[i] - 1] = i + 1;
        }
        for (int i = 0; i < n; i++) {
            System.out.print(ans[i] + " ");

        }
    }
}

Measured memory_bytes: 48308
input_line = input()
str = ""

for i in range(0,len(input_line)):
  if input_line[i] == '0':
    str += "0"
  elif input_line[i] == '1':
    str += "1"
  elif input_line[i] == 'B':
    str = str[:-1]
else:
  print(str)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(void){
    ll W,H,x,y;
    cin>>W>>H>>x>>y;
    double res=(double)(W)*H/2;
    cout<<fixed<<setprecision(10)<<res<<" ";
    if(x*2==W && y*2==H) cout<<1<<endl;
    else cout<<0<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
     
using namespace std;
     
typedef long long ll;
typedef pair<ll, int> pii;
     
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
     
mt19937 rnd(chrono::steady_clock().now().time_since_epoch().count());

int main(){
    fastIO;
    int n;
    cin >> n;
    ll f=0;
    map<ll,int>cnt;
    ll res = 0;
    ll x;
    cnt[0ll]++;
    for(int i = 1; i <= n; i ++ ){
        cin >> x;
        f+=x;
        res+=cnt[f];
        cnt[f]++;
    }
    cout << res;
    return 0;
}

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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

//実行部
void Main()
{
  ll n, m; cin >> n >> m;
  vll a(n), b(n); rep(i, n) cin >> a[i] >> b[i];
  vpll s(n); rep(i, n) s[i] = mp(a[i], b[i]);
  sort(all(s));
  ll en = 0, base = 0;
  for(ll i = 0;i < m;i++)
  {
    if(s[base].second == 0) base++;
    en += s[base].first;
    s[base].second--;
  }
  fin(en);
}

//前処理
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}

/*
//test時
  g++ test.cpp -o test;./test
*/


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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))

typedef pair<int, int> P;
#define INF 1e9
#define INF_LL 1LL<<60
#define ll long long

int main() {
    vector<int> c[3];
    REP(i, 3) REP(j, 3) {
        int tmp;
        cin >> tmp;
        c[i].push_back(tmp);
    }

    int a[3], b[3];

    a[0] = 0;
    REP(i, 3) {
        b[i] = c[0][i] - a[0];
    }

    REP(i, 2) {
        a[i+1] = c[i+1][0] - b[0];
    }

    REP(i, 3) {
        //cout << a[i] << " " << b[i] << endl;
    }

    REP(i, 3) REP(j, 3) {
        if(a[i] + b[j] != c[i][j]) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<unordered_map>
#include<queue>
#define sqr(x) (x)*(x)
#define fz1(i,n) for (i=1;i<=n;i++)
#define fd1(i,n) for (i=n;i>=1;i--)
#define fz0g(i,n) for (i=0;i<=n;i++)
#define fd0g(i,n) for (i=n;i>=0;i--)
#define fz0k(i,n) for (i=0;i<n;i++)
#define fd0k(i,n) for (i=(long long)(n-1);i>=0;i--)
#define fz(i,x,y) for (i=x;i<=y;i++)
#define fd(i,y,x) for (i=y;i>=x;i--)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len) {char ss[len];scanf("%s",ss);(st)=ss;}
using namespace std;
int n,m,i,j,x,y,z,ans;
unordered_map<int,vector<pair<pair<int,int>,int> > > bi[100005];
unordered_map<int,int> dis[100005];
int main()
{
	scanf("%d%d",&n,&m);
	fz1(i,m)
	{
		scanf("%d%d%d",&x,&y,&z);
		bi[x][z].push_back(make_pair(make_pair(y,z),0));
		bi[x][z].push_back(make_pair(make_pair(x,0),0));
		bi[x][0].push_back(make_pair(make_pair(x,z),1));
		bi[y][z].push_back(make_pair(make_pair(x,z),0));
		bi[y][z].push_back(make_pair(make_pair(y,0),0));
		bi[y][0].push_back(make_pair(make_pair(y,z),1));
		dis[x][z]=dis[y][z]=0x22222222;
	}
	fz1(i,n) dis[i][0]=0x22222222;
	dis[1][0]=0;
	priority_queue<pair<int,pair<int,int> > > pq;
	pq.push(make_pair(0,make_pair(1,0)));
	while (!pq.empty())
	{
		x=pq.top().second.first,y=pq.top().second.second;
		pq.pop();
		ff(bi[x][y],it)
		{
			int nx=it->first.first,ny=it->first.second,nz=dis[x][y]+it->second;
			if (dis[nx][ny]>nz)
			{
				dis[nx][ny]=nz;
				pq.push(make_pair(-nz,make_pair(nx,ny)));
			}
		}
	}
	if (dis[n][0]>=0x22222222) puts("-1"); else printf("%d\n",dis[n][0]);
	return 0;
}

Measured memory_bytes: 87160
//                             In The Name Of Allah
#include <bits/stdc++.h>
#define	ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ret(n) return cout << n, 0
#define se(n) cout << setprecision(n) << fixed
#define pb push_back
#define int long long
#define ld long double
using namespace std; 
 
const int N = 1e5 + 1000, OO = 1e14 + 100, M = 1e9 + 7, P = 6151, SQ = 120, lg = 31;
typedef pair <int, int> pii;
string s[N];
int t[N];

int32_t main() {
    use_fast;
	int n;
	cin >> n;
	for(int i = 0; i < n; i++) 
		cin >> s[i] >> t[i];
	string x;
	cin >> x;
	bool u = false;
	int ans = 0;
	for(int i = 0; i < n; i++) {
		if(u)
			ans += t[i];
		if(s[i] == x)
			u = true;
	}
	cout << ans << endl;
	return 0; 
}
/*
be carefull :
1- if not solve after 20 min, read again twice
2- after submit read the code again
3- fun with contest
4- ... 
*/	

Measured memory_bytes: 1024
#include<stdio.h>

#define MAX 101
#define inf 1000000000
#define NIL -1000000000
#define WHITE 0
#define BLACK 1

int n;
int d[MAX],pi[MAX],a[MAX][MAX];

prim(){
  int u,i,v,mincost;
  int color[MAX];

  for(u=0;u<n;u++){
    d[u]=inf;
    pi[u]=NIL;
    color[u]=WHITE;
  }

  d[0]=0;

  while(1){
    mincost=inf;
    for(i=0;i<n;i++){
      if(color[i]!=BLACK && d[i]<mincost){
	mincost=d[i];
	u=i;
      }
    }

    if(mincost==inf) break;

    color[u]=BLACK;

    for(v=0;v<n;v++){
      if(a[u][v]!=-1){
	if(color[v]!=BLACK && a[u][v]<d[v]){
	  pi[v]=u;
	  d[v]=a[u][v];
	}
      }
    }
  }
}

int main(){
  int i,j,sum=0;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&a[i][j]);
    }
  }

  prim();

  for(i=0;i<n;i++){
    if(pi[i]!=-1) sum+=d[i];
  }

  printf("%d\n",sum);

  return 0; 
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define inc(x,y) {x+=(y);if(x>=mod)x-=mod;}
#define dec(x,y) {x-=(y);if(x<0)x+=mod;}
#define spln(i,n) (i==n?'\n':' ')
using namespace std;
long long n,m,i,j,a[100005],s[100005],b[100005],bb[100005],f[100005];
vector<long long> bi[100005],seq;
void dfs1(long long x,long long fa)
{
	if((bi[x].size()-(fa>0)==0)){
		s[x]=a[x];
	}
	ff(bi[x],it){
		if(*it==fa) continue;
		dfs1(*it,x);
		s[x]+=s[*it];
	}
}
void dfs2(long long x,long long fa)
{
	b[x]=s[x]-a[x];
	b[fa]-=b[x];
	ff(bi[x],it){
		if(*it==fa) continue;
		dfs2(*it,x);
		b[x]-=b[*it];
	}
	if(b[x]<0){
		puts("NO");
		exit(0);
	}
}
void dfs4(long long x,long long fa)
{
	if((bi[x].size()-(fa>0)==0)) f[x]=a[x];
	vector<long long> seq;	
	ff(bi[x],it){
		if(*it==fa) continue;
		dfs4(*it,x);
		seq.push_back(f[*it]);
		f[x]+=f[*it];
	}
	if((bi[x].size()-(fa>0)==0)){
		return;
	}
	sort(seq.begin(),seq.end());
	reverse(seq.begin(),seq.end());
	long long sum=0;
	ff(seq,it){
		sum+=*it;
	}
	if(!fa&&sum<seq[0]*2){
		puts("NO");
		exit(0);
	}
	if(sum<seq[0]*2) sum=2*(sum-seq[0]);
	sum/=2;
	if(b[x]>sum){
		puts("NO");
		exit(0);
	}
	f[x]-=b[x]*2;
}
int main()
{
//	freopen("1.in","r",stdin);
	scanf("%lld",&n);
	fz1(i,n) scanf("%lld",&a[i]);
	fz1(i,n-1){
		long long x,y;
		scanf("%lld%lld",&x,&y);
		bi[x].push_back(y);
		bi[y].push_back(x);
	}
	if(n==2){
		if(a[1]==a[2]) puts("YES"); else puts("NO");
		return 0;
	}
	int rt=0;
	fz1(i,n){
		if(bi[i].size()!=1) rt=i;
	}
	dfs1(rt,0);
	dfs2(rt,0);
	dfs4(rt,0);
	if(f[rt]||(s[rt]&1)){
		puts("NO");
	}
	else puts("YES");
	return 0;
}

Measured memory_bytes: 18176
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
using namespace std;

typedef long long LL;
#define lowbit(x) ((x)&(-x))
#define INF 0x3f3f3f3f
#define memset(a,b) memset(a,b,sizeof(a))
#define	GE() printf(">----------\n")
#define	IN() freopen("in.txt","r",stdin)
#define	OUT() freopen("out.txt","w",stdout)
const int mod=1000000007;
const int inf=0x3f3f3f3f;
const double pi=acos(-1.0);
const double eps=1e-8;
const int maxn=105;

int x, y;
char mp[maxn][maxn];

int main()
{
    while(~scanf("%d%d", &x, &y)){
        for(int i=0;i<x;i++)scanf("%s", &mp[i]);
        for(int i=0;i<=y+1;i++)putchar('#');
        puts("");
        for(int i=0;i<x;i++){
            putchar('#');
            printf("%s", mp[i]);
            putchar('#');
            puts("");
        }
        for(int i=0;i<=y+1;i++)putchar('#');
        puts("");
    }
    return 0;
}



Measured memory_bytes: 256
S = input()

len_S = len(S)

ans = 0
B_count = 0

for i in range(len_S):
    pos_from_end = len_S-i-1
    c = S[pos_from_end]
    if c == "B":
        ans += len_S-1-B_count-pos_from_end
        B_count += 1

print(ans)


Measured memory_bytes: 3500
from collections import defaultdict
N = int(input())
gain_set = defaultdict(int)
for i in range(N):
    s = input()
    gain_set[s] += 1

M = int(input())
lose_set = defaultdict(int)
for i in range(M):
    s = input()
    lose_set[s] += 1


max_count = 0
for (k, v) in gain_set.items():
    c = lose_set[k]
    d = v - c
    if max_count < d:
        max_count = d

print(max_count)

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

#define int long long


signed main()
{
    string a, b;
    cin >> a >> b;
    if(a.size()>b.size()) cout << "GREATER" << endl;
    else if(a.size()<b.size()) cout << "LESS" << endl;
    else if(a>b) cout << "GREATER" << endl;
    else if(a==b) cout << "EQUAL" << endl;
    else cout << "LESS" << endl;
    return 0;
}



Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
bool visit[101];
int ans[57];
int finds = 2;
int choose[5];
bool per[55*555];
bool isper(int n)
{
	if (n < 2)
		return false;
	int p = sqrt(n);
	for (int i = 2; i <= p; i++)
	{
		if (n%i == 0)
			return false;
	}
	return true;
}
void j()
{
	for (int i = 1; i < 55*555; i++)
	{
		per[i] = isper(i);
	}
}

void dfs(int step, int cnt, int n)
{
	if (step == cnt && n == 4)
		return;
	if (cnt == 4)
	{
		int con = choose[0] + choose[1] + choose[2] + choose[3];
		for (int i = 0; i < n; i++)
		{
			if (visit[i] == false&&per[ans[i] + con] == true)
			{
				while (true)
				{
					finds++;
					if (per[finds])
					{
						ans[i] = finds;
						break;
					}
				}
			}
		}
		return;
	}
	for (int i = 0; i < n; i++)
	{
		if (visit[i] == false) {
			visit[i] = true;
			choose[cnt] = ans[i];
			dfs(i, cnt + 1, n);
			visit[i] = false;
		}
	}
}
int main()
{
	j();
	memset(visit, false, sizeof(visit));
	int n, cnt = 0;
	scanf("%d", &n);
	//dfs(0,0, n,2);
	for (finds = 2,cnt=0; cnt < n; finds++)
	{
		if (per[finds]&&finds%10==3)
			ans[cnt++] = finds;
	}
	//dfs(0,0, n);
	//sort(ans, ans + n);
	for (int i = 0; i < n; i++)
	{
		printf("%d ", ans[i]);
	}
	return 0;
}

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

using namespace std;

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

const int MN = 50500; 
const int MD = 1000003;

int n, m;
P g[MN];
int calc(int l, int r) {
    ll res = 1;
    while (l < r) {
        res *= g[l].second; res %= MD;
        l = g[l].first;
    }
    return res;
}

int solve() {
    if (n % 2) return 0;
    for (int i = 0; i < n-1; i++) {
        g[i] = P(i+2, 1);
    }
    vector<T> buf;
    buf.push_back(T(n-1, P(0, n)));
    for (int i = 0; i < m; i++) {
        int a, b;
        scanf("%d %d", &a, &b);
        if (a > b) swap(a, b); a--;
        if ((b-a) % 2) continue;
        buf.push_back(T(b-a, P(a, b)));
    }
    sort(buf.begin(), buf.end());
    for (T &t: buf) {
        int a, b;
        tie(a, b) = t.second;
        g[a] = P(b, (calc(a, b) + calc(a+1, b-1)) % MD);
    }
    return g[0].second;
}

int main() {
    while (true) {
        scanf("%d %d", &n, &m);
        if (!n) break;
        printf("%d\n", solve());
    }
}

Measured memory_bytes: 1896
#include <cstdio>           // printf(), scanf()
#include <cstring>          // memset()
#include <vector>

using namespace std;
static const int MAX_V = 2 * 100;

vector<int> G[MAX_V];
int match[MAX_V];
bool used[MAX_V];
int V;

bool
dfs(int v)
{
	used[v] = true;
	for (unsigned int i = 0; i < G[v].size(); ++i)
	{
		int u = G[v][i], w = match[u];
		if (w < 0 || (!used[w] && dfs(w)))
		{
			match[v] = u;
			match[u] = v;
			return true;
		}
	}

	return false;
}

int
bipartite_matching()
{
	int res = 0;
	memset(match, -1, sizeof(match));
	for (int v = 0; v < V; ++v)
	{
		if (match[v] < 0)
		{
			memset(used, 0, sizeof(used));
			if (dfs(v))
				res++;
		}
	}

	return res;
}

int
main(int argc, char** argv)
{
	int X, Y, E;
	int x, y;

	scanf("%d %d %d", &X, &Y, &E);
	V = X + Y;
	for (int i = 0; i < E; ++i)
	{
		scanf("%d %d", &x, &y);
		G[x].push_back(X + y);
		G[X + y].push_back(x);
	}

	printf("%d\n", bipartite_matching());
	return 0;
}

Measured memory_bytes: 2800
def swap(q,i,j)
    tmp = q[j]
    q[j] = q[i]
    q[i] = tmp
end
N = gets.to_i
q = gets.split.map(&:to_i)
res = 0
if q[-1] == N then
    swap(q,N-2,N-1)
    res += 1
end
(N-1).times do |i|
    n = i + 1
    if n == q[i] then
        if q[i] != n+1 && q[i+1] != n then
            swap(q,i,i+1)
            res += 1
        end
    end
end
puts res


Measured memory_bytes: 8076
#include<stdio.h>
#define N 100000
#define NIL -1
typedef struct{
  int parent;
  int left;
  int right;
}node;
node Tree[N];
int main()
{
  int i,id,j,n,kosuu,c[N],depth=0,num=0;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      Tree[i].parent=Tree[i].left=Tree[i].right=NIL;
    }
  for(i=0;i<n;i++)
    {
      scanf("%d%d",&id,&kosuu);
      for(j=0;j<kosuu;j++)
	{
	  scanf("%d",&c[j]);
	  if(j==0)
	    {
	      Tree[c[0]].parent=id;
	      Tree[id].left = c[0];
	    }
	  else
	    {
	      Tree[c[j]].parent = id;
	      Tree[c[j-1]].right=c[j];
	    }
	}
    }
  
  for(i=0;i<n;i++)
    {
      printf("node %d: parent = %d, ",i,Tree[i].parent);
      num=i;
      while(Tree[num].parent!=NIL)
	{
	  depth++;
	  num=Tree[num].parent;
	}
      printf("depth = %d,",depth);
      depth=0;
      if(Tree[i].parent==NIL  && Tree[i].left==NIL)
	{
	  printf(" root, []\n");
	}
      else if(Tree[i].parent==NIL && Tree[i].left!=NIL)
	{
	  printf(" root, [%d",Tree[i].left);
	  for(j=Tree[Tree[i].left].right;j!=NIL;j=Tree[j].right)
	    {
	      printf(", %d",j);
	    }
	  printf("]\n");
	}
      else if(Tree[i].left!=NIL)
	{
	  printf(" internal node, [%d",Tree[i].left);
	  for(j=Tree[Tree[i].left].right;j!=NIL;j=Tree[j].right)
	    {
	      printf(", %d",j);
	    }
	  printf("]\n");
	}

      else
	{
	  printf(" leaf, []\n");
	}
    }
  return 0;
}


  



Measured memory_bytes: 3336
N, M = map(int, input().split())
a = [0 for i in range(N)]
for i in range(N):
    A, B = map(int, input().split())
    a[i] = [A,B]
a.sort(key=lambda x:x[0])
cur = 0
ans = 0
for i in range(N):
    if cur+a[i][1]>= M:
        ans += a[i][0] * (M-cur)
        break
    else:
        ans += a[i][0] * a[i][1]
        cur += a[i][1]
print(ans)


Measured memory_bytes: 21244
n = input()
a = list(n)
if a[0] == a[1] ==a[2]:
    print(n)
else:
    if int(a[0])> int(a[1]):
        a[1] = a[0]
        a[2] = a[0]  
        for i in range(3):
            print(a[i] ,end="")

    elif a[0]==a[1] and int(a[0]) <int(a[2]):
         a[0] = str(int(a[0]) +1)
         a[1] =a[0]
         a[2] = a[0]

         for i in range(3):
            print(a[i] ,end="")
    elif a[0]==a[1] and int(a[0]) >int(a[2]):
         a[2] = a[0]
         for j in range(3):  
            print(a[j] ,end="")         


    else:
        a[0] = str(int(a[0]) +1)
        a[1] =a[0]
        a[2] = a[0]

        for j in range(3):  
            print(a[j] ,end="")

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

int main(){
	int n, k;
	cin >> n >> k;
	vector<int> x(n);
	rep(snip_i, n) cin >> x.at(snip_i);
	int ans = 1001001001;
	rep(i, n-k+1){
		int add;
		int l = x.at(i), r = x.at(i+k-1);
		if(l < 0 && 0 < r){
			if(fabs(l) > fabs(r)) add = fabs(r) + (r-l);
			else add = fabs(l) + (r-l);
		}else{
			if(r <= 0) add = fabs(l);
			else add = fabs(r);
		}
		ans = min(ans, add);
	}
	cout << ans << endl;

	return 0;
}

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

int main(){
  int H, W;
  while (true){
    cin >> H >> W;
    if (H==0){
      break;
    }
    else {
      for (int i=0; i<H; i++){
        for (int j=0; j<W; j++){
          cout << '#';
        }
        cout << endl;
      }
    cout << endl;
    }
  }
  
}



Measured memory_bytes: 3084
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2")  //Enable AVX
#include<bits/stdc++.h>
using namespace std;
#define int ll
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair
 
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
 
const int mod=998244353;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
int mul(int a,int b)
{
	return ((a)*1ll*(b))%mod;
}
 
void add(int &a,int b)
{
	a+=b;
	if(a>=mod)a-=mod;
}
 
int sub(int a,int b){
	a-=b;
	if(a<0){
		a+=mod;
	}
	return a;
}
 
int powz(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1){
			res=mul(res,a);
		}
		b/=2;
		a=mul(a,a);
	}
	return res;
}
 
template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
	input>>x.F>>x.S;
	return input;
}
 
template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
	for(auto& i:x)
		input>>i;
	return input;
}
 
template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
	for(auto& i:x)
		output<<i<<' ';
	return output;
}
 
const int N=1000002;

void solve(){
	int n;
	cin>>n;
	string s;
	cin>>s;
	int ans=0;
	for(int i=0;i<n-2;i++){
		if(s.substr(i,3)==(string)("ABC")){
			ans++;
		}
	}
	cout<<ans;
}

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int tc=1;
	//~ cin>>tc;
	for(int _=0;_<tc;_++){
		//~ cout<<"Case #"<<_+1<<": ";
		solve();
		if(_!=tc-1)
		cout<<"\n";
	}
}


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

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

  int p = N % 1000;
  int ans;
  if (p == 0) ans = 0;
  else ans = 1000 - p;
  cout << ans << endl;
  return 0;
}


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

int main(){
  int m, f, r;
  cin >> m >> f >> r;
  while ( m + f + r != -3 ) {
    if ( m == -1 || f == -1 ) cout << "F" << endl;
    else if ( m + f >= 80 ) cout << "A" << endl;
    else if ( 65 <= m + f && m + f < 80 ) cout << "B" << endl;
    else if ( 50 <= m + f && m + f < 65 ) cout << "C" << endl;
    else if ( m + f < 30 ) cout << "F" << endl;
    else if ( 30 <= m + f && m + f < 50 && r < 50 ) cout << "D" << endl;
    else cout << "C" << endl;
    cin >> m >> f >> r;
  }
  return 0;
}


Measured memory_bytes: 3036
N, M = map(int, input().split())
d = [list(map(int, input().split())) for i in range(N)]
d.sort(key=lambda x:(x[0],x[1]))

c = p = i = 0

while c < M:
    if c + d[i][1] <= M:
        c += d[i][1]
        p += d[i][0] * d[i][1]
        i += 1
    else:
        p += d[i][0] * (M - c)
        break

print(p)


Measured memory_bytes: 35292
/*================================================================
*   Copyright (C) 2019 Sangfor Ltd. All rights reserved.
*
*   创 建 者： badcw
*   创建日期： 2020/1/26
*
================================================================*/
#include <bits/stdc++.h>

#define ll long long
using namespace std;

const int maxn = 2e5+50;
const int mod = 1e9+7;
ll qp(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

template <class T>
inline bool scan(T& ret) {
    char c;
    int sgn;
    if (c = getchar(), c == EOF) return 0; // EOF
    while (c != '-' && (c < '0' || c > '9')) c = getchar();
    sgn = (c == '-') ? -1 : 1;
    ret = (c == '-') ? 0 : (c - '0');
    while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
    ret *= sgn;
    return 1;
}

//template <class T>
//inline void out(T x) {
//    if (x > 9) out(x / 10);
//    putchar(x % 10 + '0');
//}

int n, d, a;
int x[maxn];
int h[maxn];
int idx[maxn];
pair<int, int> t[maxn];

inline ll up(ll x, ll y) {
    if (x < 0) return 0;
    return x / y + (x % y ? 1 : 0);
}

int main(int argc, char* argv[]) {
    scanf("%d%d%d", &n, &d, &a);
    for (int i = 1; i <= n; ++i) {
        scanf("%d%d", &x[i], &h[i]);
        idx[i] = i;
    }
    ll tmp = 0;
    ll res = 0;
    int l = 0, r = -1;
    sort(idx + 1, idx + 1 + n, [](int a, int b) {
        return x[a] < x[b];
    });
    for (int i = 1; i <= n; ++i) {
        while (l <= r && t[l].first + d < x[idx[i]]) {
            tmp -= t[l].second;
            l ++;
        }
        ll gg = up(h[idx[i]] - tmp * a, a);
        if (gg) {
            t[++r] = {x[idx[i]] + d, gg};
            tmp += gg;
            res += gg;
        }
    }
    printf("%lld\n", res);
    return 0;
}

Measured memory_bytes: 4096
MOD = 10 ** 9 + 7

N, K = map(int, input().split())
l = list(map(int, input().split()))
pos = []
neg = []
z = 0

for v in l:
    if v > 0:
        pos.append(v)
    elif v < 0:
        neg.append(v)
    else:
        z += 1
pos.sort()
neg.sort()

if N - z < K:
    print(0)
elif N - z == K:
    if len(neg) % 2 and z:
        print(0)
    else:
        out = 1
        for v in neg + pos:
            out *= v
            out %= 10 ** 9 + 7
        print(out)
elif len(pos) == 0:
    if K % 2:
        if z:
            print(0)
        else:
            neg.reverse()
            out = 1
            for i in range(K):
                out *= neg[i]
                out %= 10 ** 9 + 7
            print(out)
    else:
        out = 1
        for i in range(K):
            out *= neg[i]
            out %= 10 ** 9 + 7
        print(out)
else:
    out = 1
    neg.reverse()
    if K % 2:
        out = pos.pop()
        K -= 1
    while K:
        if len(pos) >= 2:
            nP = pos[-1] * pos[-2]
        else:
            nP = 0

        if len(neg) >= 2:
            nN = neg[-1] * neg[-2]
        else:
            nN = 0

        if nP > nN:
            pos.pop()
            pos.pop()
            out *= nP
        else:
            neg.pop()
            neg.pop()
            out *= nN
        out %= MOD
        K -= 2
    print(out)

        


Measured memory_bytes: 108360
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    int n, k;
    cin >> n >> k;
    int h[n];
    for (int i = 0; i < n; i++) cin >> h[i];
    sort(h, h + n); 
    ll ans = 0;
    for (int i = 0; i < n - k; i++) ans += h[i];
    cout << ans << endl;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int T = N * (N - 1) + M * (M - 1);
		System.out.println(T / 2);		
	}
}


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

static const int INF=100000;
static const int MOD=1000000007;
typedef long long ll;
typedef pair<int,int> P;

ll dp[100005][13];

int main(){
    string s;
    cin >> s;
    int N=s.size();
    dp[N][0]=1;
    int mul=1;
    for(int i=N-1;i>=0;i--){
        if(s[i]=='?'){
            for(int j=0;j<10;j++){
                for(int k=0;k<13;k++){
                    dp[i][(j*mul+k)%13]+=dp[i+1][k];
                    dp[i][(j*mul+k)%13]%=MOD;
                }
            }
        }else{
            int j=s[i]-'0';
            for(int k=0;k<13;k++){
                dp[i][(j*mul+k)%13]+=dp[i+1][k];
                dp[i][(j*mul+k)%13]%=MOD;
            }
        }
        mul*=10;
        mul%=13;
    }
    cout << dp[0][5] << endl;
}


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

const int mod = 1e9+7;
const int INF = 2000000;

int main() {
    ll X,Y;
    cin >> X >> Y;
    int ans = 0;
    while(X <= Y) {
        ++ans;
        X *= 2; 
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
int n, k;
ll two[20];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n>>k;
    two[0]=1;
    for(int i=1;i<20;i++){
        two[i]=2*two[i-1];
    }
    double ans=0.0;
    int temp;
    for(int i=1;i<=n;i++){
        ll sum=i;
        bool a=false;
        for(int j=0;j<20;j++){
            if(sum>=k&&a==false){
                temp=j;
                a=true;
            }
            sum=sum*2;
        }
        ans+=double(1.000000000)/double(n)/double(two[temp]);
    }
    cout <<setprecision(13)<< ans<< "\n";
}

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

class program
{
  static void Main(string[] args)
  {
    int R = int.Parse(Console.ReadLine());
    
    if (R<1200){
      Console.WriteLine("ABC");
 	}
    else if (R<2800){
      Console.WriteLine("ARC");
    }
    else{
      Console.WriteLine("AGC");
    }
  }
}

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

int main() {
  int h,w,k; cin >>h >>w >>k;
  vector<string> str(h);
  rep(i,h) cin >>str[i];
  int ans = 0;
  rep(is, 1<<h)rep(js, 1<<w){
    int cnt = 0;
    rep(i,h)rep(j,w){
      if(js>>j&1) continue;
      if(is>>i&1) continue;
      if(str[i][j]=='#') cnt++;
    }
    if(cnt==k) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3604
N = int(input())

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

ans_dict = {}
for i in range(N):
    ans_dict[i+1] = A[i]

ans_dict = sorted(ans_dict.items(), key=lambda x: x[1])

ans_list = []
for i in range(len(ans_dict)):
    ans_list.append(ans_dict[i][0])

hoge = map(str, ans_list)
ans = " ".join(hoge)
print(ans[:len(ans)])


Measured memory_bytes: 24944
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n ,m ;
  cin >> n;
  vector<string> s(n);
  for (int i = 0 ; i < n ; i++){
    cin >> s.at(i);
  }
  cin >> m ;
  vector<string> t(m);
  for (int i = 0 ; i < m ; i++){
    cin >> t.at(i);
  }
  int x  = 0 ;
  int counter;
  string pre ;
  for(int i = 0 ; i < n ; i++){
    pre = s.at(i);
    counter = 0;
    for(int j = 0 ; j < n ; j++){
      if( pre == s.at(j)){
          counter += 1;
      }
    }
    for(int j = 0 ; j < m ; j++){
      if( pre == t.at(j)){
        counter -= 1;
      }
    }
    if( x < counter){
      x = counter ;
    }
  }
  cout << x << endl;    
}

Measured memory_bytes: 384
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto K = readln.split.to!(int[])[3];
    auto AS = readln.split.to!(long[]);
    auto BS = readln.split.to!(long[]);
    auto CS = readln.split.to!(long[]);

    long[] abs, rs;
    foreach (a; AS) foreach (b; BS) abs ~= a + b;
    sort!"a > b"(abs);
    foreach (c; CS) foreach (d; abs[0..min(abs.length, K)]) rs ~= c + d;
    sort!"a > b"(rs);
    foreach (r; rs[0..K]) writeln(r);
}

Measured memory_bytes: 59772
#include <iostream>

class STACK{
public:
    long* data;
    int   size, memory;
    STACK(){
        memory = 4;
        size = 0;
        data = new long[memory];
    }
    ~STACK(){
        delete[] data;
    }
    void push(long x){
        size++;
        if (size > memory){
            memory *= 2;
            long* tmp = (long*)realloc(data, memory * sizeof(long));
            data = tmp;
        }
        data[size - 1] = x;
    }
    void pop(){
        if (size == 0) return;
        data[--size] = 0;
        if (size * 2 <= memory && memory >= 4){
            memory /= 2;
            long* tmp = (long*)realloc(data, memory * sizeof(long));
            data = tmp;
        }
    }
    void top(){
        if (size == 0) return;
        std::cout << data[size - 1] << std::endl;
    }
};

int main(){
    int n, q;
    std::cin >> n >> q;
    STACK* s = new STACK[n];
    while(q--){
        int com, t;
        std::cin >> com >> t;
        if (com == 0){
            long x;
            std::cin >> x;
            s[t].push(x);
        }
        if (com == 1){
            s[t].top();
        }
        if (com == 2){
            s[t].pop();
        }
    }
}


Measured memory_bytes: 4744
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF 1e18
#define INF 1e9
using namespace std;

#define fs first
#define sc second

using P = pair<ll,ll>;
using Pll = pair<P,ll>;
using PQ = priority_queue<P,vector<P>,greater<P>>;


const ll MOD = 1e9+7;

signed main(){
    ll n;
    cin >> n;
    ll tmp = n;
    ll cnt = 0;
    while(tmp){
        cnt += tmp % 10;
        tmp /= 10;
    }
    if(n % cnt){
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
    }
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int64_t> L(N+1);
  if (N == 1) {
    cout << 1 << endl;
  }
  else {
    L[0] = 2;
    L[1] = 1;
    rep(i, N-1) {
      L[i+2] = L[i+1] + L[i];
    }
    cout << L[N] << endl;
  }
}


Measured memory_bytes: 3640
n, a, b = map(int, input().split())
 
ans = 0
for i in range(1, n + 1):
    t = i
    sum = 0
    while(t > 0):
        sum += t % 10
        t = int(t / 10)
    
    if(a <= sum <= b):
        ans += i
    
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N, K;

int main() {
	cin >> N >> K;
	cout << N + 1 - K << endl;
}

Measured memory_bytes: 256
def calc_number_of_coin(sum, coins):
    dp = [999999999]*(sum+1)
    dp[0] = 0
    for i in range(len(coins)):
        for j in range(coins[i], sum+1):
            dp[j] = min(dp[j], dp[j-coins[i]]+1)
    return dp[sum]



if __name__ == '__main__':
    # ??????????????\???
    # f = open('input.txt')
    # sum, _ = [int(x) for x in f.readline().strip().split(' ')]
    # coins = [int(x) for x in f.readline().strip().split(' ')]

    sum, _ = [int(x) for x in input().strip().split(' ')]
    coins = [int(x) for x in input().strip().split(' ')]

    # ???????????????
    result = calc_number_of_coin(sum, coins)

    # ???????????¨???
    print(result)

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

int main(){
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    for (int i = 0; i < n; i++){
        bool flag = true;
        for (int j = 0; j < n - i; j++){
            if (s[i + j] != t[j]) flag = false;
        }
        if (flag){
            cout << n + i << endl;
            return 0;
        }
    }
    cout << n + n << endl;
}

Measured memory_bytes: 256
l = input().split(" ")
p = [int(l[0]),int(l[1])]
q = [int(l[2]),int(l[3])]
r = [0,0]
s = [0,0]
if p[0]==q[0]:
    m = q[1]-p[1]
    r[0] = q[0]-m
    r[1] = q[1]
    s[0] = p[0]-m
    s[1] = p[1]
else:
    v = [q[1]-p[1],q[0]-p[0]]
    r[0]= q[0]-v[0]
    r[1]=q[1]+v[1]
    s[0]=p[0]-v[0]
    s[1]=p[1]+v[1]
print(str(r[0])+" "+str(r[1])+" "+str(s[0])+" "+str(s[1]))

Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>

using namespace std;

int main() {
	int n;
	int a[4][2];
	int b[4];

	while (cin >> n) {
		if (n == 0) {
			break;
		
		}
		for (int k = 0; k < n; k++) {

		for (int i = 0; i < 2; i++) {
			for (int j = 0; j < 4; j++) {
				cin >> a[j][i];
			}
		}
		b[0] = a[0][0] * a[0][1];
		for (int i = 1; i < 4; i++) {
			b[0] -= (a[i][0] * a[i][1]);
		}
		b[1] = a[0][0] * a[1][1] + a[1][0] * a[0][1] + a[2][0] * a[3][1] - a[3][0] * a[2][1];
		b[2] = a[0][0] * a[2][1] - a[1][0] * a[3][1] + a[2][0] * a[0][1] + a[3][0] * a[1][1];
		b[3] = a[0][0] * a[3][1] + a[1][0] * a[2][1] - a[2][0] * a[1][1] + a[3][0] * a[0][1];
		printf("%d %d %d %d\n",b[0],b[1],b[2],b[3]);
		}
	}

	return 0;
}

Measured memory_bytes: 1144
X, Y, A, B, C = gets.chomp.split(" ").map(&:to_i)
red = gets.chomp.split(" ").map(&:to_i).max(X) #最大のＸ個の要素
grn = gets.chomp.split(" ").map(&:to_i).max(Y)
P = gets.split(" ").map(&:to_i).sort.reverse
RG = (red + grn).sort
ans = 0

(X + Y).times.inject(0) do |j, i|
    if j < P.size && P[j] > RG[i]
        ans += P[j]
        j + 1   
    else
        ans += RG[i]
        j
    end
end
puts ans 


Measured memory_bytes: 29436
import sys
sy=sys.stdin.readline
n,m=map(int,sy().split())
ab=[list(map(int,sy().split())) for i in range(n)]
ab.sort(key=lambda x:x[0])
ans,count=0,0
for i in ab:
    if count+i[1]<m:
        count+=i[1]
        ans+=i[0]*i[1]
    else:
        ans+=i[0]*(m-count)
        break
print(ans)

Measured memory_bytes: 28960
import sys


N, M = map(int, sys.stdin.readline().split())
X = list(map(int, sys.stdin.readline().split()))

if N >= M:
    ans = 0
    print(ans)
    sys.exit()

X.sort()
dif_list = []
for i in range(len(X) - 1):
    dif_list.append(X[i+1] - X[i])
dif_list.sort()
count = 0
ans = 0
for i in dif_list:
    ans += i
    count += 1
    if count == M - N:
        break

print(ans)

Measured memory_bytes: 13948
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
	int a, b, k; cin >> a >> b >> k;
	int ans = min(a, b);
	while (1) {
		if (a % ans == 0 && b % ans == 0) {
			k--;
			if (k == 0) break;
		}
		ans--;
	}
	cout << ans << endl;

	return 0;
}

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

#define ll long long
#define rep(i,n) for(int i = 0;i < (n); i++)
#define mod 1000000007

struct UnionFind {

	vector<ll> par;
	UnionFind(ll size) {
		par = vector<ll>(size, -1);
	}

	ll root(ll x) {
		if (par[x] < 0)return x;
		return par[x] = root(par[x]);
	}


	bool unit(ll a, ll b) {
		a = root(a);
		b = root(b);
		if (a == b)return false;
		if (-par[a] < -par[b])swap(a, b);
		par[a] += par[b];
		par[b] = a;
		return true;
	}

};


int main() {
	ll n, m;
	cin >> n >> m;
	struct UnionFind uf(n);
	
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		a--;	b--;
		uf.unit(a, b);
	}
	set<ll> ans;
	rep(i, n) {
		ans.insert(uf.root(i));
	}
	cout << ans.size() - 1 << endl;

	return 0;
}

Measured memory_bytes: 7920
#include <stdio.h>
#include <string.h>
#define ll long long int
#define e 2.7182818
#define pi 3.14159

int main (){
	int tc;
	scanf ("%d", &tc);
	int ct = 0;
	int oof = 0;
	while (tc != 0){
		int A, B;
		scanf ("%d %d", &A, &B);
		if (A == B){
			ct++;
		}
		else {
			ct = 0;
		}
		if (ct == 3){
			oof = 1;
		}
		tc--;
	}
	(oof == 1) ? (printf ("Yes\n")) : (printf("No\n"));

return 0;
}


Measured memory_bytes: 1660