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

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

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    int n,m,q;
    cin >> n >> m >> q;
    string s[n];
    for (int i = 0;i < n;++i) cin >> s[i];
    vector<vector<int>> a(n+1,vector<int>(m+1,0)),b(n+1,vector<int>(m+1,0)),c(n+1,vector<int>(m+1,0));
    for (int i = 1;i < n;++i) for (int j = 0;j < m;++j) if (s[i-1][j] == '1' && s[i][j] == '1') a[i+1][j+1]++;
    for (int i = 0;i < n;++i) for (int j = 1;j < m;++j) if (s[i][j-1] == '1' && s[i][j] == '1') b[i+1][j+1]++;
    for (int i = 0;i < n;++i) for (int j = 0;j < m;++j) if (s[i][j] == '1') c[i+1][j+1]++;
    for (int i = 0;i < n;++i) for (int j = 0;j < m;++j) {
        a[i+1][j+1] += a[i][j+1];
        b[i+1][j+1] += b[i][j+1];
        c[i+1][j+1] += c[i][j+1];
    }
    for (int i = 0;i < n;++i) for (int j = 0;j < m;++j) {
        a[i+1][j+1] += a[i+1][j];
        b[i+1][j+1] += b[i+1][j];
        c[i+1][j+1] += c[i+1][j];
    }
    for (int i = 0;i < q;++i) {
        int x1,x2,y1,y2;
        cin >> x1 >> y1 >> x2 >> y2;
        int ans = c[x2][y2]+c[x1-1][y1-1]-c[x2][y1-1]-c[x1-1][y2];
        ans -= a[x2][y2]+a[x1][y1-1]-a[x2][y1-1]-a[x1][y2];
        ans -= b[x2][y2]+b[x1-1][y1]-b[x2][y1]-b[x1-1][y2];
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 52992
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<math.h>
#include<bitset>
#include<random>
using namespace std;
using ll = long long;
using lll = __int128_t;
typedef pair<ll,ll> P;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
const ll longinf=1ll<<60;
const int inf=(1<<30)-1;
const ll mod=1e9+7;


int keta(int k){
      int ret=0;
      while(k>0){
            ret++;
            k/=10;
      }
      return ret;
}

int main(){
      int n;
      cin>>n;
      int h[n];
      rep0(i,n) cin>>h[i];
      int posmax=h[0];
      bool ok=true;
      for(int i=1;i<n;i++){
            if(posmax>h[i]+1) ok=false;
            if(h[i]>posmax) posmax=h[i];
      }
      if(ok) cout<<"Yes"<<endl;
      else cout<<"No"<<endl;
      return 0;
}

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

int func(int d,int n){
  if(n != 100){
    return pow(10,2*d)*n;
  }else{
    return pow(10,2*d)*(n+1);
  }
}

int main() {
  int d,n;
  cin >> d >> n;
  
  cout << func(d,n) << endl;
  return 0;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
#define fast_in ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp  make_pair
#define pb  push_back
#define  sz(x)   (int)x.size()
#define  all(x)  x.begin(), x.end()
#define	 allr(x)  x.rbegin(), x.rend()
#define  bit(x)  __builtin_popcountll(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int,int> pii;
const int inf = (int) 1e9+99999, mod = (int)1e9+7;
const ll linf = (ll) 2e18+99999;
int mul (int x, int y) { return ((ll)x * y) % mod; } 
int sub (int x, int y) { x -= y; if (x < 0) return x + mod; return x; } 
int add (int x, int y) { x += y; if (x >= mod) return x - mod; return x; }
 
const int maxn = (int) 3e5;
 
int a[maxn], b[maxn];

void solve () {
	string s; cin >> s; s += 'R'; s = '$' + s;
	int n = sz (s);
	int cntL, cntR, c;
	cntL = cntR = 0;
	vector <pii> v;
	for (int i = 0; i < n; i ++) {
		if (s[i] == 'R' && s[i-1] == 'L') {
			if ((cntL + cntR) % 2 == 0) {
				v.pb (mp (c-1, (cntL + cntR) / 2));				
				v.pb (mp (c, (cntL + cntR) / 2));				
			} else {
				if (cntR > cntL && cntR % 2 == 1) {
					v.pb (mp (c-1, (cntL + cntR) / 2 + 1));
					v.pb (mp (c, (cntL + cntR) / 2));
				} else if (cntR > cntL && cntR % 2 == 0) {
					v.pb (mp (c-1, (cntL + cntR) / 2));
					v.pb (mp (c, (cntL + cntR) / 2 + 1));				
				}	

				if (cntR < cntL && cntL % 2 == 0) {
					v.pb (mp (c-1, (cntL + cntR) / 2 + 1));
					v.pb (mp (c, (cntL + cntR) / 2));
				} else if (cntR < cntL && cntL % 2 == 1) {
					v.pb (mp (c-1, (cntL + cntR) / 2));
					v.pb (mp (c, (cntL + cntR) / 2 + 1));				
				}	
			}
			cntL = 0, cntR = 1;
		} else if (s[i] == 'R') {
			cntR ++;
		} else if (s[i] == 'L' && s[i - 1] == 'R') {
			c = i;
			cntL ++;
		} else if (s[i] == 'L') {
			cntL ++;
		}

		//cout << cntL << ' ' << cntR << endl;
	}

	for (auto to: v) {
		a[to.first] = to.second;
	}

	for (int i = 1; i < n-1; i ++)
		cout << a[i] << ' ';
}

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

Measured memory_bytes: 4456
#include <bits/stdc++.h>
using namespace std;
#define LONG_LONG ll
int main(){
    cin.tie(0);
    //ios::sync_with_stdio(false);
    int N;
    cin >> N;
    long long a[N + 1];
    a[0] = 2;
    a[1] = 1;
    for(int i = 2; i <= N;i++){
        a[i] = a[i - 1] + a[i - 2];
    }
    cout << a[N] << endl;
}

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

int main() {
  int n,x,k,sum=0,ans=1;
  cin >> n >> x ;
  
  for(int i=0;i<n;i++){
    cin >> k;
    sum += k ;
    
    if(sum <= x) ans++;  
  }
  cout << ans << endl;
}

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

int main() {
    string str;
    cin >> str;
    int count=0;
    for(int i=0;i<4;i++){
        for(int j=i+1;j<4;j++){
            if(str.at(i)==str.at(j)) count++;
        }
    }
    if(count==2) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

using namespace std;

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

const int MOD = 1000000007;
int n;
string s;
int memo[200000][2];
int loop[200000];

int run(int x, int time) {
    int b = (time % 2 == 1? 1 : 0);
    if(memo[x][b] != -1) return memo[x][b];
    if(loop[x] == 2 && time % 2 == 0) {
        memo[x][b] = x;
        return x;
    }
    int y = -1;
    if(s[x] == 'R') y = x + 1;
    else if(s[x] == 'L') y = x - 1;
    else cout << "err" << endl;

    int tmp = run(y, time + 1);
    memo[x][b] = tmp;
    return memo[x][b];
}

int main() {
    cin >> s;
    n = s.length();

    for(int i = 0; i < n; i++) {
        for(int j = 0; j < 2; j++) {
            memo[i][j] = -1;
        }
    }

    for(int i = 0; i < n; i++) {
        loop[i] = -1;
    }
    for(int i = 0; i < n; i++) {
        if(s[i] == 'R') {
            loop[i] = (s[i + 1] == 'L'? 2 : 0);
        }else {
            loop[i] = (s[i - 1] == 'R'? 2 : 0);
        }
    }

    int ans[200000];
    /*
    for(int i = 0; i < n; i++) {
        ans[i] = 0;
    }
    */


    for(int i = 0; i < n; i++) {
        ans[run(i, 0)]++;
    }

    for(int i = 0; i < n; i++) {
        if(i != 0) cout << ' ';
        cout << ans[i];
    }
    cout << endl;

    return 0;
}



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

long long gcd(ll a, ll b){
    if (a < b) {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    
    return b ? gcd(b, a % b) : a;
}

long long lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}
int main(){
  ll a,b; cin >> a >> b;
  ll x = lcm(a,b);
    cout << x << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#define RG register
using namespace std;
const int N=1e5+10;
int n,m,q,num[N],cnt,sum[N],pos[N],a[N];
bool vis[N];
template<typename I> inline void read(I &ot){
	I ch=getchar(), x=0, f=1;
	while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar();	}
	while(ch>='0' && ch<='9'){x=x*10+ch-'0'; ch=getchar();	}
	ot=x*f;}
template<typename I, typename... U> inline void read(I &x,U&... y){read(x); read(y...);}
int main()
{
	//freopen("LRU Puzzle.in","r",stdin);
	//freopen(".out","w",stdout);
	read(n,m,q);
	for(int i=1;i<=q;i++) read(a[i]);
	for(int i=q;i;i--)
	{
		if(!vis[a[i]])
		{
			num[++cnt]=a[i];
			pos[a[i]]=cnt;
			vis[a[i]]=1;
		}
	}
	for(int i=1, cnt2=0;i<=m;i++) if(!vis[i]) num[cnt+(++cnt2)]=i;
	sum[0]=n;
	for(int i=q;i;i--)
	{
		int tt=pos[a[i]];
		if(sum[tt-1])
		{
			sum[tt-1]--;
			sum[tt]++;
		}
	}
	int st=n;
	for(int i=0;i<=cnt;i++) 
	{
		if(sum[i])
		{
			st=i;
			break;
		}
	}
	for(int i=st+2;i<=m;i++)
	{
		if(num[i]<num[i-1])
		{
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	//fclose(stdin); fclose(stdout);
	return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define int long long
 
using namespace std;
 
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, a;
    double t;
    cin >> n >> t >> a;
    int best = 1;
    double maxi = numeric_limits<double>::max();
    for(int i = 0; i < n; i++){
        double b;
        cin >> b;
        double rep = t-0.006*b;
        if(abs(a-rep) < maxi){
            maxi = abs(a-rep);
            best = i+1;
        }
    }
    cout << best << endl;
}

Measured memory_bytes: 256
ary = []
n   = gets.to_i

n.times do |i|
  tmp = gets.split
  ary << [tmp[0], tmp[1].to_i, i]
end

ary.sort{|a, b| a[0] > b[0] ? 1 : a[0] == b[0] && a[1] < b[1] ? 1 : -1}.each{|a| puts a[2] + 1}


Measured memory_bytes: 1788
#include<stdio.h>

int main(){
  char s[5];
  int n;
  scanf("%d",&n);
  int ac,wa,tle,re;
  ac=wa=tle=re=0;
  for (int i=0;i<n;i++) {
    scanf("%s",s);
    if(s[0]=='A')ac++;
    if(s[0]=='W')wa++;
    if(s[0]=='T')tle++;
    if(s[0]=='R')re++;
  }
  printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d\n",ac,wa,tle,re);
  return 0;
}

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

class Program
{
    bool isPrime(int num)
    {
        for (int i = 2; i * i <= num; i++)
        {
            if(num % i == 0) return false;
        }
        return true;
    }

    static void Main() => new Program().Solve();
    void Solve()
    {
        int N = int.Parse(Console.ReadLine());
        for (int i = N; ; i++)
        {
            if (isPrime(i))
            {
                Console.WriteLine(i);
                return;
            }
        }
    }
}

Measured memory_bytes: 27480
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int p[555555];
int vis[555555];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	vi a,b;
	vector<ii> a2,b2;
	for(int i=0;i<n;i++)
	{
		int x; cin>>x; a.pb(x); a2.pb({x,i});
	}
	for(int i=0;i<n;i++)
	{
		int x; cin>>x; b.pb(x); b2.pb({x,i});
	}
	sort(a2.begin(),a2.end()); sort(b2.begin(),b2.end());
	for(int i=0;i<n;i++)
	{
		if(a2[i].fi>b2[i].fi)
		{
			cout<<"No\n"; return 0;
		}
	}
	//check if answer is unique
	for(int i=0;i+1<n;i++)
	{
		if(a2[i+1].fi<=b2[i].fi)
		{
			cout<<"Yes\n"; return 0;
		}
	}
	for(int i=0;i<n;i++)
	{
		p[b2[i].se]=a2[i].se;
	}
	int cc=0;
	for(int i=0;i<n;i++)
	{
		if(!vis[i])
		{
			cc++; int cur=i;
			while(!vis[cur])
			{
				vis[cur]=1; cur=p[cur];
			}
		}
	}
	if(cc==1) cout<<"No\n";
	else cout<<"Yes\n";
}	


Measured memory_bytes: 6000
#include<iostream>
using namespace std;
int main()
{
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  int i,j;
  i=A+B;
  j=C+D;
  if(i>j)
  {
    cout<<"Left"<<endl;
  }
  if(i==j)
  {
    cout<<"Balanced"<<endl;
  }
  if(i<j)
  {
    cout<<"Right"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;
#define print(x) cout<<(x)<<endl;

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007



int main() {
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		ans += 800;
		if (i % 15==0)ans -= 200;
	}
	print(ans);







	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
const int N = 3001;
double dp[N][N];
bool vis[N][N];
double p[N];
int n;
 
double rec(int i, int h) {
  if(i == n) {
    return double(h > (n - h));
  }
  auto &res = dp[i][h];
  if(vis[i][h]) return res;
  vis[i][h] = true;
  return res = p[i] * rec(i + 1, h + 1) + (1 - p[i]) * (rec(i + 1, h));
}
 
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(20);
  cout << fixed;
  memset(dp, 0, sizeof dp);
  memset(vis, false, sizeof vis);
  cin >> n;
  for(int i = 0; i < n; ++i) {
    cin >> p[i];
  }
  cout << rec(0, 0) << '\n';
  return 0;
}

Measured memory_bytes: 79616
#include<cstdio>
#include<algorithm>
#define N_ 101000
using namespace std;
int w[N_], n,C[N_][2], r;
int main() {
	int i;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &w[i]);
		C[w[i]][i % 2]++;
	}
	int Mx = 0;
	for (i = 1; i <= 100000; i++) {
		r = max(r, Mx + C[i][1]);
		Mx = max(Mx, C[i][0]);
	}
	Mx = 0;

	for (i = 1; i <= 100000; i++) {
		r = max(r, Mx + C[i][0]);
		Mx = max(Mx, C[i][1]);
	}
	printf("%d\n", n - r);
}

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

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

using namespace std;


int main(){
    ll n, m;
    cin >> n >> m;
    vector<ll> a(m);
    vector<ll> b(m);
    rep(i, m)   cin >> a[i] >> b[i];

    rep(i, m){
        a[i]--;
        b[i]--;
        if(a[i] > b[i]){
            ll x = a[i];
            a[i] = b[i];
            b[i] = x;
        }
    }

    vector<ll> list(n+5, 0);

    rep(i, m){
        list[a[i]]++;
        list[b[i]]--;
    }

    bool f = true;
    ll e = 0;
    rep(i, m){
        e += list[i];
        if(e % 2 == 1){
            f = false;
            break;
        }
    }

    cout << (f?"YES":"NO") << endl;


    return 0;
}


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


using namespace std;

#ifdef CLION
ifstream ifs("/home/kyuridenamida/CLionProjects/project/input.txt");
#define cin ifs
#define scanf DONT_USE_SCANF
#endif

int main() {
    string s, t;
    int A, B;
    string U;
    cin >> s >> t >> A >> B >> U;

    if (s == U) A--;
    if (t == U) B--;
    cout << A << " " << B << endl;
}

Measured memory_bytes: 256
h={?I=>1,?V=>5,?X=>10,?L=>50,?C=>100,?D=>500,?M=>1000}
$<.map{|x|
  a=x.chop.split("").map{|c|h[c]}
  i,p,s=a.size-1,0,0
  while i>=0 do
    n=a[i]
    if n<p
      n=-n
    else
      p=n
    end
    s+=n
    i-=1
  end
  p s
}

Measured memory_bytes: 6120
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#define loop(n) for(int i=0;i<n;i++)
#define INT_MAX 2147483647
#define LLINT_MAX 9223372036854775807
#define mod 1000000007
#define ll long long int
using namespace std;

int main() {
	string s;
	cin >> s;
//	cout << s.size() << endl;
	for (int i = (s.size() - 1) / 2; i > 0; i--) {
//		cout << i << ' ' << s.substr(0, i) << ' ' << s.substr(i, i) << endl;
		if (s.substr(0, i) == s.substr(i, i)) {
			cout << i + i << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
const int MAXN = 1e5+5,MAXM = 2e5+5,MOD = 20130427,INF = 0x3f3f3f3f,N=100050;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
const db eps = 1e-9;
#define lson o<<1,l,m
#define rson o<<1|1,m+1,r
#define mid l + ((r-l)>>1)
#define rep(i,a,b) for(register int i=(a);i<=(b);i++)
#define vii vector<pair<int,int>>
#define vi vector<int>
using namespace std;

char s[MAXN];
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    //freopen("../A.in","r",stdin);
    //freopen("../A.out","w",stdout);
    cin>>s;
    int n=strlen(s);
    int ans=INF;
    int sum=0;
    for(int i=0;i<n;i++){
        if(i&1)sum+=s[i]=='0';
        else sum+=s[i]=='1';
    }
    ans=min(ans,sum);
    sum=0;
    for(int i=0;i<n;i++){
        if(i&1)sum+=s[i]=='1';
        else sum+=s[i]=='0';
    }
    ans=min(ans,sum);
    cout<<ans<<'\n';
    return 0;
}

Measured memory_bytes: 384
import math

IsPrime = [True] * 100001

IsPrime[0] = False;
IsPrime[1] = False;

for i in range(2, int(math.sqrt(100001)) + 1):
    if IsPrime[i]:
        for j in range(i*i, 100001, i):
            IsPrime[j] = False

cnt = [0] * 100001

for i in range(3, 100001, 2):
    if IsPrime[i] and IsPrime[(i+1)/2]:
        cnt[i] += 1

for i in range(1, 100001):
    cnt[i] += cnt[i-1]

Q = int(raw_input())

for i in range(Q):
    l, r = map(int, raw_input().split())
    print cnt[r] - cnt[l-1]


Measured memory_bytes: 11120
n=int(input())
s=input()
d=list(s)
z=0
if n%2==0:
  for i in range(n//2):
    if d[i]==d[n//2+i]:
      z+=1
  if z==n//2:
    print("Yes")
  else:
    print("No")
else:
  print("No")


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

using namespace std;
int main(){
    // Your code here!
 int d,t,s;
 cin>>d>>t>>s;
 if(s*t>=d) cout<<"Yes"<<endl;
 else cout<<"No"<<endl;
}


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

int main()
{
 map<string,int> d;
 int n,m;
 cin>>n;
 for(int i=0;i<n;i++)
   {
     string s;
     cin>>s;
     d[s]=1;
   }
 cin>>m;
 bool door =false;
 for(int i=0;i<m;i++)
   {
     string s;
     cin>>s;
     if(d.count(s))
       {
	 if(door)
	     cout<<"Closed by ";
	 else
	     cout<<"Opened by ";
	 door=!door;
       }
     else
       cout<<"Unknown ";
     cout<<s<<endl;
   }
}

Measured memory_bytes: 1236
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int a = sc.nextInt();
    int b = sc.nextInt();

    System.out.printf("%d %d %f\n", a / b, a % b, 1.0 * a / b);
  }
}


Measured memory_bytes: 26592
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) begin(x), end(x)
#define debug(x) cout << #x " => " << (x) << endl
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
#endif
using lint = long long;
constexpr int MOD = (int)1e9 + 7;
constexpr double EPS = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int main(void) {
  lint n, k;
  cin >> n >> k;
  if (n < k) {
    cout << min(n, k - n) << endl;
  } else {
    lint tmp = n % k;
    cout << min(tmp, k - tmp) << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import sys

input = sys.stdin.readline

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

bc = [list(map(int, input().split())) for _ in range(m)]

bc.sort(reverse=True, key=lambda x: x[1])

cnt = 0

for b, c in bc:
    cnt += b
    if cnt > n:
        add = n - cnt + b
        a.extend([c] * add)
        break
    else:
        a.extend([c] * b)

print(sum(sorted(a, reverse=True)[:n]))


Measured memory_bytes: 35976
#!/usr/bin/env python3
import sys


def solve(a: int, b: int, c: int, d: int, e: int, k: int):
    if (e-a) > k:
        print(":(")
    else:
        print("Yay!")


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    c = int(next(tokens))  # type: int
    d = int(next(tokens))  # type: int
    e = int(next(tokens))  # type: int
    k = int(next(tokens))  # type: int
    solve(a, b, c, d, e, k)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#pragma warning(disable : 4996)
#define rng(x, y) (0 <= x && x < W && 0 <= y && y < H)
int H, W, n, gx, gy, x[12][12], d[4] = { 1, 0, -1, 0 };
int solve(int sx, int sy, int depth) {
	if (depth == n) {
		if (sx == gx || sy == gy) return 1;
		return 0;
	}
	depth++;
	int ret = 0;
	for (int i = 0; i < 4; i++) {
		int tx = sx + d[i], ty = sy + d[i ^ 1];
		while (rng(tx, ty)) {
			if (x[ty][tx] == 1) {
				x[ty][tx] = 0;
				ret += solve(tx, ty, depth);
				x[ty][tx] = 1;
				break;
			}
			tx += d[i];
			ty += d[i ^ 1];
		}
	}
	return ret;
}
int main() {
	while (scanf("%d%d", &W, &H), W | H) {
		n = 0;
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				scanf("%d", &x[i][j]);
				if (x[i][j] == 1) n++;
				if (x[i][j] == 2) gx = j, gy = i;
			}
		}
		printf("%d\n", solve(gx, gy, 0));
	}
	return 0;
}

Measured memory_bytes: 2708
from collections import deque

N=int(input())
G=[{} for i in range(N+1)]
colors = []
for i in range(N-1):
  a,b=map(int,input().split())
  G[a][b]=[i,-1]
  G[b][a]=[i,-1]

def bfs(s):
  seen = [0 for i in range(N+1)]
  prev = [0 for i in range(N+1)]
  todo = deque([])
  cmax = 0
  now = s
  seen[now]=1
  todo.append(now)
  while 1:
    if len(todo)==0:break
    a = todo.popleft()
    if len(G[a])<50:
      if prev[a] == 0:
        a_color=set([])
      else:
        a_color=set([G[a][prev[a]][1]])
      for b in G[a]:
        if seen[b] == 0:
          seen[b] = 1
          todo.append(b)
          prev[b] = a
          for c in range(1,N+1):
            if c not in a_color:
              a_color.add(c)
              colors.append((G[a][b][0],c))
              G[a][b][1]=G[b][a][1]=c
              if c > cmax: cmax = c
              break
    else:
      temp = list(range(1,N))
      if prev[a] != 0:
        del temp[G[a][prev[a]][1]-1]
      temp = deque(temp)
      for i,b in enumerate(G[a]):
        if seen[b] == 0:
          seen[b] = 1
          todo.append(b)
          prev[b] = a
          c = temp.popleft()
          colors.append((G[a][b][0],c))
          G[a][b][1]=G[b][a][1]=c
          if c > cmax: cmax = c
            
  return colors, cmax

colors,cmax = bfs(1)
colors=sorted(colors)

print(cmax)
for i in range(N-1):
  print(colors[i][1])

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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define FORD(i,b,a) for (int i = (int)(b) - 1; i >= a; --i)
#define REP(i,N) FOR(i,0,N)
#define st first
#define nd second
#define pb push_back

typedef pair<int, int> PII;
typedef long long LL;

char S[222222];
char res[222222];
int main() {
  int N;
  scanf("%d%s", &N, S);
  REP(i,N) S[i] = (S[i] == 'x' ? 1 : 0);

  for (res[0] = 0; res[0] < 2; ++res[0]) {
    for (res[1] = 0; res[1] < 2; ++res[1]) {
      FOR(i,2,N) {
        res[i] = res[i-2] ^ S[i-1] ^ res[i-1];
      }
      bool ok = (res[0] == (res[N-2] ^ S[N-1] ^ res[N-1]));
      ok = ok && (res[1] == (res[N-1] ^ S[0] ^ res[0]));

      if (ok) {
        REP(i,N) printf("%c", res[i] ? 'W' : 'S');
        printf("\n");
        return 0;
      }
    }
  }

  printf("-1\n");
}


Measured memory_bytes: 512
//50
#include<iostream>
#include<string>

using namespace std;

const int ND=10005+9;

string add(string a,string b){
  int c=0;
  string r(ND,0);
  for(int i=ND-1;i>1;i--){
    int s=a[i]+b[i]-'0'*2+c;
    r[i]=s%10+'0';
    c=s/10;
  }
  r[0]=c+'0';
  r[1]='.';
  return r;
}

string div1(int x){
  if(x==1){
    return "1."+string(ND-2,'0');
  }else{
    int y=10;
    string a="0.";
    while(a.size()<ND){
      a+=char(y/x+'0');
      y=(y%x)*10;
    }
    return a;
  }
}

int main(){
  for(int n,k,m,r;cin>>n>>k>>m>>r,n|k|m|r;){
    string a=div1(n);
    if(m){
      for(int i=1;i<=n-1;i++){
	a=add(a,div1(n*i));
      }
    }
    cout<<a.substr(0,r+2)<<endl;
  }
  return 0;
}

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


int main(void)
{
    int i,j;
    
    for(i = 1;i < 10 ; i++){
        for(j=1 ;j < 10 ;j++){
            cout << i << "x" << j << "=" << i*j << endl;
        }
    }
    
    return 0;
}

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

const int ac = 2e5 + 5;
bool A[ac];
bool B[ac];

int main()
{
        ios_base::sync_with_stdio(0);
        int n, m; cin >> n >> m;
        while (m--)
        {
                int a, b; cin >> a >> b;
                if (a == 1) A[b] = 1;   
                if (b == 1) A[a] = 1;
                if (a == n) B[b] = 1;
                if (b == n) B[a] = 1;
                if (A[a] && B[a] || A[b] && B[b])
                { cout << "POSSIBLE\n"; return 0; }
        }
        cout << "IMPOSSIBLE\n";
}


Measured memory_bytes: 640
from itertools import accumulate

n = int(input())
b = []
# iがあるインデックス
bc = {}
wc = {}
for i in range(2*n):
    c,a = input().split()
    a = int(a)
    b.append((c,a))
    if c == "B":
        bc[a]=i
    else:
        wc[a]=i

# black[i][j] : 黒のi(1-indexed)のある位置より左にある、i未満の個数 + 白のj以下の個数
black = [[0]*(n+1) for i in range(n+1)]
white = [[0]*(n+1) for i in range(n+1)]

for i in range(2*n):
    c,a = b[i]
    # 同色でa未満の個数 cnt
    cnt = 0
    num = [0]*(n+1)
    for j in range(i):
        if b[j][0] == c:
            if b[j][1] < a:
                cnt += 1
        else:
            num[b[j][1]] += 1
    # 累積和
    num = list(accumulate(num))
    if c == "B":
        black[a] = [j+cnt for j in num]
    else:
        white[a] = [j+cnt for j in num]

DP = [[float("inf")]*(n+1) for i in range(n+1)]
DP[0][0] = 0
for i in range(n+1):
    for j in range(n+1):
        # 黒がi個、白がj個→i+1, j or i, j+1
        if i+1 <= n:
            DP[i+1][j] = min(DP[i+1][j], DP[i][j]+bc[i+1]-black[i+1][j])
        if j+1 <= n:
            DP[i][j+1] = min(DP[i][j+1], DP[i][j]+wc[j+1]-white[j+1][i])
print(DP[n][n])

Measured memory_bytes: 212228
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define MOD 1e+7
#define inf 1e9
#define fi first
#define se second
using namespace std;

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

  int n;
  cin >> n;
  vector<int> spot(n+2);
  reps(i,1,n+1) cin >> spot[i];

  int sum = 0;
  rep(i,n+1) sum += abs(spot[i + 1] - spot[i]);
  reps(i,1,n+1) {
    int res = sum;
    res -= abs(spot[i]     - spot[i - 1]);
    res -= abs(spot[i + 1] - spot[i]    );
    res += abs(spot[i + 1] - spot[i - 1]);
    cout << res << endl;
  }

  return 0;
}

Measured memory_bytes: 1664
#pragma GCC optimize("O3")

#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define sz(x) (int)x.size()
#define f first
#define s second

bool check(vector<int> &set,vector<vector<pi>> &arr)
{
    F0R(i,sz(set))
    {
        if(set[i]==0)
            continue;
        F0R(j,sz(arr[i]))
        {
            pi val=arr[i][j];
            if(set[val.f]!=val.s)
                return false;
        }
    }
    return true;
}

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

    int n;
    cin >> n;
    vector<vector<pi>> arr(n);
    int a;
    F0R(i,n)
    {
        cin >> a;
        int e1,e2;
        vector<pi> nv;
        arr[i]=nv;
        F0R(j,a)
        {
            cin >> e1 >> e2;
            arr[i].pb({--e1,e2});
        }
    } 
    int best=0;
    int cnt;
    F0R(i,pow(2,n))
    {
        cnt=0;
        vector<int> set(n,0);
        F0R(j,n)
        {
            if(((i >> j) & 1)==1)
            {
                cnt++;
                set[j]=1;
            }
        }
        if(check(set,arr))
        {
            best=max(best,cnt); 
        }
    }
    cout << best;

    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int r, n, a, b;
int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n>>a;
    r = a;
    for(int i = 2; i < n; i++){
        cin >> b;
        r += min(a,b);
        a= b;
    }
    r += a;
    cout << r;
}

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

int H, W;
char G[20][20];
int adj[26][26];

int match[20];

int cc[1 << 12];
int dp(int mask) {
    int &ret = cc[mask];
    if(ret != -1) return ret;
    if(mask == (1 << H) - 1) return ret = 1;

    ret = 0;
    int cnt = 0;
    int p = -1;
    for(int i = 0; i < H; i++) {
        if(mask & (1 << i)) continue;
        if(p == -1) p = i;
        cnt++;
    }
    for(int i = cnt % 2? p : p + 1; i < H; i++) {
        if(mask & (1 << i)) continue;

        bool ok = true;
        for(int j = 0; j < W; j++) {
            if(G[p][j] != G[i][ match[j] ]) {
                ok = false;
                break;
            }
        }
        if(ok) {
            ret |= dp(mask | (1 << p) | (1 << i));
        }
    }
    return ret;
}

void dfs(int mask, int x, int y) {
    if(mask == (1 << W) - 1) {
        memset(cc, -1, sizeof(cc));
        if(dp( (1 << x) ^ (1 << y) )) {
            printf("YES");
            exit(0);
        }
        return;
    }
    int cnt = 0;
    int p = -1;
    for(int i = 0; i < W; i++) {
        if(mask & (1 << i)) continue;
        if(p == -1) p = i;
        cnt++;
    }
    for(int i = cnt % 2? p : p + 1; i < W; i++) {
        if(mask & (1 << i)) continue;

        if(G[x][i] == G[y][p] && G[y][i] == G[x][p]) {
            match[p] = i;
            match[i] = p;
            dfs(mask | (1 << p) | (1 << i), x, y);
        }
    }
}

int main() {
    scanf("%d %d", &H, &W);

    for(int i = 0; i < H; i++) {
        scanf("\n");
        for(int j = 0; j < W; j++) {
            scanf("%c", &G[i][j]);
        }
    }

    if(H == 1 && W == 1) {
        printf("YES");
        return 0;
    }
    if(H < W) {
        for(int i = 0; i < H; i++) {
            for(int j = i + 1; j < W; j++) {
                swap(G[i][j], G[j][i]);
            }
        }
        swap(H, W);
    }

    for(int i = 0; i < H; i++) {
        for(int j = i + 1; j < H; j++) {
            memset(adj, 0, sizeof(adj));

            for(int k = 0; k < W; k++) {
                adj[ G[i][k] - 'a' ][ G[j][k] - 'a' ]++;
            }
            bool ok = true;
            for(int a = 0; a < 26; a++) {
                for(int b = 0; b < 26; b++) {
                    if(adj[a][b] != adj[b][a]) {
                        ok = false;
                        break;
                    }
                }
                if(!ok) break;
            }
            if(!ok) continue;
            dfs(0, i, j);
        }
    }
    printf("NO");
}


Measured memory_bytes: 256
import java.util.*

/**
 * Created on 2017/09/09.
 */
fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val int = sc.nextInt()
    var list = Array<Int>(4) { 0 }
    for (i in 0..3) {
        list[i] = (int / (Math.pow(10.0, i.toDouble())).toInt()) % 10
    }
    if((list[0] == list[1] && list[1] == list[2]) || (list[1] == list[2] && list[2] == list[3]) ) println("Yes")
    else println("No")
}

Measured memory_bytes: 29724
def ex_euclid(x,y):
    c0,c1 = x,y
    a0,a1 = 1,0
    b0,b1 = 0,1
    while c1:
        a0,a1 = a1,a0-c0//c1*a1
        b0,b1 = b1,b0-c0//c1*b1
        c0,c1 = c1,c0%c1
    return c0,a0,b0

x,y = map(int,input().split())
c,a,b = ex_euclid(x,y)
print(a,b)



Measured memory_bytes: 5600
N = int(input())
AB = []

for _ in range(N):
    A, B = map(int, input().split())
    AB.append([A+B, A, B])

AB.sort()
result = [0, 0]

for i in range(N):
    result[i%2] += AB[-1][i%2+1]
    del AB[-1]

print(result[0] - result[1])


Measured memory_bytes: 23260
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    print((n*(n+1))//2)

if __name__ == '__main__':
  main()


Measured memory_bytes: 5276
#include<iostream>

using namespace std;

int main()
{
	int A,B,K;

	cin >> A >> B >> K;

	int roop = min(A,B);
	int cnt = 0;

	for(int i=roop;i>0;i--)
	{
		if(A%i == 0 && B%i==0)
		{
			cnt++;
		}
		if(cnt == K)
		{
			cout << i << endl;
			break;
		}
	}

	return 0;
}

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

using ll =long long;

int main() {

  string S;
  cin>>S;
  
  
    if(S[5]=='0'){
if(S[6]=='1'||S[6]=='2'||S[6]=='3'||S[6]=='4'){cout<<"Heisei"<<endl;}
      else{cout<<"TBD"<<endl;}
    }else if(S[5]=='1'){cout<<"TBD"<<endl;}
  
}

Measured memory_bytes: 256
/// Kazuki Hoshino


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define f first
#define ss second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define endl '\n'
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;


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

//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);



ll a, b;

cin >> a >> b;

rep(i, 1, 3){
if((a*b*i) % 2==1 ){
    cout << "Yes" << endl;
    return 0;
}
}
cout << "No" << endl;








return 0;}
///....


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int number,x, i;
    cin >> number >> x;
    int foo[number];
    for(i=0; i<=(number-1); i++)
    {
     foo[i]=x;
        cin >> x;
    }
   for(i=number-1; i>=0; i--)
   {
       cout << foo[i];
       if(i!=0)
       cout << " ";
       else
       cout << endl;
       
   }
   return 0;
}


Measured memory_bytes: 3116
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<cstdlib>
#include<stack>
#include<queue>
#include<algorithm>
#include<set>
#include<vector>
#include<cmath>
#include<string>
#include<bitset>
#define lmid l,mid,rt<<1
#define rmid mid+1,r,rt<<1|1
#define ll long long
using namespace std;
int vis[100005];
void prime() {
     vis[0] = vis[1] = 1;
     for (int i = 2; i <= 100000; i++) {
          if (!vis[i]) {
               for (int j = 2; i * j <= 100000; j++)
                    vis[i * j] = 1;
          }
     }
}
int s[100005];
int main() {
     prime();
     for (int i = 1; i <= 100000; i++) {
          int res = 0;
          if (i % 2 == 0) {
               s[i] = s[i - 1] + res;
               continue;
          }
          if (!vis[i] && (!vis[(i + 1) / 2]))
               res = 1;
          s[i] = s[i - 1] + res;
     }
     int n;
     scanf("%d", &n);
     for (int i = 0; i < n; i++) {
          int l, r;
          scanf("%d%d", &l, &r);
          printf("%d\n", s[r] - s[l - 1]);
     }
     return 0;
}


Measured memory_bytes: 1408
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<vector>
using namespace std;
using uint = unsigned int;
using ll = long long;
const int M = 1e9 + 7;
const ll MLL = 1e18L + 9;
#pragma unused(M)
#pragma unused(MLL)
#ifdef LOCAL
#include"rprint.hpp"
#else
template <class... T> void printl(T&&...){ }
template <class... T> void printc(T&&...){ }
template <class... T> void prints(T&&...){ }
template <class... T> void printd(T&&...){ }
#endif

int main(){
    int n; cin >> n;
    int cnt = 0;
    for(int i=0;i<n;i++){
        int a; cin >> a;
        cnt += a % 2;
    }
    cout << (cnt % 2 == 0 ? "YES" : "NO") << '\n';
    return 0;
}


Measured memory_bytes: 888
#include <stdio.h>
#include <stdlib.h>

int main(){
	int a[100], n, i, j, temp;
	scanf("%d", &n);
	for (i = 0; i < n; i++){
		scanf("%d", &a[i]);
	}
	for (i = 0; i < n; i++){
		for (j = i + 1; j < n; j++){
			if (a[i]>a[j]){
				temp = a[i];
				a[i] = a[j];
				a[j] = temp;
			}
		}
	}
	printf("%d", a[n - 1] - a[0]);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<stack>
#include<cstdlib>
using namespace std;

int main()
{
    stack<int> S;
    int a, b, x;
    string s;
    
    while( cin >> s)                     
    {
        if( s[0] == '+'){                  
            a = S.top() ; S.pop() ;
            b = S.top() ; S.pop() ;
            S.push(a + b); 
        }else if( s[0] == '-' ){
            b = S.top() ; S.pop() ;
            a = S.top() ; S.pop() ;
            S.push(a - b); 
        }else if( s[0] == '*'){
            a = S.top() ; S.pop() ;
            b = S.top() ;S.pop() ;
            S.push(a * b); 
        }else{                                                             
            S.push(atoi(s.c_str()));       
        }
    }
    
    cout << S.top() <<endl;
    
    return 0;
}


Measured memory_bytes: 3180
X, Y, A, B, C = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))

P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)

a = sorted(P[:X] + Q[:Y])
ans = sum(a)

for i in range(min(X+Y, C)):
    if a[i] < R[i]:
        ans += R[i] - a[i]

print(ans)

Measured memory_bytes: 23328
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        String t = sc.next();
        int min = s.length() + t.length();
        for (int i = 1; i <= t.length(); i++) {
            StringBuilder sb = new StringBuilder(s);
            String tsub = t.substring(i);
            sb.append(tsub);
            if (sb.toString().startsWith(s) && sb.toString().endsWith(t)) {
                min = s.length() + tsub.length();
            }
        }
        System.out.println(min);
    }

}


Measured memory_bytes: 21844
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<i64>();
    let (a, b) = (v[0], v[1]);
    if (a - b).abs() % 2 == 1 {
        println!("IMPOSSIBLE");
    } else {
        println!("{}", (a + b) / 2);
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

using namespace std;

int main() {
    int N;
    cin >> N;
    
    int students[N];

    int x;
    for (int i = 1; i < N + 1; i++) {
        cin >> x;
        
        students[x - 1] = i;
    }

    for (const int &student_number : students)
    {
        cout << student_number << " ";
    }
}


Measured memory_bytes: 1152
import java.util.Scanner;
import java.util.Arrays;

public class Main {
  public static void main (String[] args) {
    Scanner in = new Scanner(System.in);
    
    while (in.hasNext()) {
      int N = in.nextInt();
      int[] A = new int[N];

      for (int i = 0; i < A.length; ++i) {
        A[i] = in.nextInt() - (i + 1);
      }

      Arrays.sort(A);
      
      int mid = A[A.length / 2];
      if ( A.length % 2 == 0) {
        mid = (mid + A[A.length / 2 - 1]) / 2;
      }

      long minSadVal = 0;
      for (int i = 0; i < A.length; ++i) {
        minSadVal += Math.abs(A[i] - mid);
      }

      System.out.println(minSadVal);
    }
  }
}

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

int main(void){
	int A, B;
	cin >> A >> B;
	int tot = 1;
	for (int i = 0; i < 20; i++) {
		if (tot >= B) {
			cout << i << endl;
			return 0;
		}
		tot += A-1;	
	}
return 0;
}


Measured memory_bytes: 3600
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
sys.setrecursionlimit(10 ** 9)



INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 998244353


class BIT:
    def __init__(self, size):
        self.bit = [0] * size
        self.size = size

    def add(self, i, w):
        x = i + 1
        while x <= self.size:
            self.bit[x - 1] += w
            x += x & -x
        return

    def sum(self, i):
        res = 0
        x = i + 1
        while x:
            res += self.bit[x - 1]
            x -= x & -x
        return res


n = I()
X = []
Y = []
XY = []
for x, y in LIR(n):
    Y += [y]
    X += [x]

co_to_ind = {e: i for i, e in enumerate(sorted(Y))}
Y = [co_to_ind[k] for k in Y]
Y = [Y[i] for i in sorted(range(n), key=lambda j:X[j])]
pow2 = [1]
for i in range(n):
    pow2 += [pow2[-1] * 2 % mod]


ans = pow2[n - 1] * n % mod
bit = BIT(n)
for i, y in enumerate(Y):
    bit.add(y, 1)
    ld = bit.sum(y - 1)
    lu = i - ld
    rd = y - ld
    ru = n - y - 1 - lu
    ans = ans + (pow2[ld] - 1) * (pow2[ru] - 1) % mod * pow2[lu] % mod * pow2[rd] % mod
    ans = ans + (pow2[lu] - 1) * (pow2[rd] - 1) % mod * pow2[ld] % mod * pow2[ru] % mod
    ans = ans - (pow2[ld] - 1) * (pow2[ru] - 1) % mod * (pow2[rd] - 1) % mod * (pow2[lu] - 1) % mod


print(ans % mod)








Measured memory_bytes: 119948
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <fstream>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;
typedef pair<int,int> PI;
typedef vector<PI> VPI;
typedef unsigned long long ull;
typedef long long ll;

#define FOR(i, n) for(int i=0;i<(n);++i)
#define REP(i,s,n) for(int i=s;i<=n;++i)
#define SZ(x) ((int)(x).size())
#define LOOP(i,x) FOR(i,SZ(x))
#define IT(it,x) for(typeof((x).begin()) it = (x).begin();it!=(x).end();++it)
#define ALL(x) (x).begin(), (x).end()
#define ST first
#define ND second
#define MP make_pair
#define PB push_back
#define gc getchar

const ll INF = 1e18L + 5L;
const int INT_INF = 1e9 + 5;

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

	int n, W;
	cin >> n >> W;

	vector<int> w(n), v(n);
	int totalValue = 0;
	for (int i = 0; i < n; i++) {
		cin >> w[i] >> v[i];
		totalValue += v[i];
	}

	vector<ll> dp(totalValue + 1, INF);
	dp[0] = 0;

	for (int i = 0; i < n; i++) {
		for (int value_now = totalValue - v[i]; value_now >= 0; value_now--) {
			dp[value_now + v[i]] = min(dp[value_now + v[i]], dp[value_now] + w[i]);
		}
	}

	int ans = 0;
	for (int i = 0; i <= totalValue; i++) {
		if (dp[i] <= W) ans = max(ans, i);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
// AOJ 0176
#include<algorithm>
#include<iostream>
#include<sstream>
#include<string>
#include<utility>

typedef std::pair<int, int> P;

const int INF = 1 << 30;

const int r[8] = { 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff },
		  g[8] = { 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff },
		  b[8] = { 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff };

const std::string cols[8] = { "black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white" };

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

int main()
{
	std::string s;
	while( std::cin >> s, s != "0" )
	{
		std::string t;
		for( int i = 1; i != s.size(); ++i )
		{
			t += s[i];
			if( i % 2 == 0 && i < 6 )
			{
				t += ' ';
			}
		}

		std::istringstream iss( t );
		int R, G, B;
		iss >> std::hex >> R >> G >> B;

		P ans( INF, INF );
		for( int i = 0; i != 8; ++i )
		{
			int d = sqr( R - r[i] ) + sqr( G - g[i] ) + sqr( B - b[i] );
			ans = std::min( ans, P( d, i ) );
		}

		std::cout << cols[ans.second] << std::endl;
	}

	return 0;
}

Measured memory_bytes: 1216