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

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n; cin>>n;
	vector<int> a(n);
	map<int,int> ct;
	for (int i=0; i<n; i++)
		cin>>a[i], ct[a[i]]++;
	if (ct[0]==n) {
		cout<<"Yes\n";
		return 0;
	}
	if(n%3) {
		cout<<"No\n";
		return 0;
	}
	map<int,vector<int>> mp;
	for (auto it : ct)
		mp[it.second].push_back(it.first);
	if(!mp[n/3].empty() && !mp[2*n/3].empty() && ct[0]==n/3) {
		cout<<"Yes\n";
		return 0;
	}
	if(mp[n/3].size()!=3) {
		cout<<"No\n";
		return 0;
	}
	int cur=mp[n/3][0]^mp[n/3][1]^mp[n/3][2];
	cout<<(cur?"No":"Yes")<<"\n";
	return 0;
}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,t=1; cin >>n;
  vector<int>v(n);
  for(int i=0; i<n; i++) cin >>v[i];
  for(int i=0; i<n-1; i++){
    t=max(t,v[i]);
    if(t-v[i]>1){cout <<"No"; return 0;}
    if(v[i]>v[i+1]&&v[i+1]>v[i+2]&&n-2-i){cout <<"No"; return 0;}
  }
  cout <<"Yes";
return 0;}

Measured memory_bytes: 640
N,M = map(int,input().split())

judge = [False]*N
WAcnt = [0] * N
ACcnt = 0
for i in range(M):
    p,S = (x for x in input().split())
    p = int(p)
    if judge[p-1] == False:
        if S == "AC":
            judge[p-1] = True
            ACcnt += 1
        else:
            WAcnt[p-1] += 1

WAans = 0
for i in range(N):
    if judge[i] == True:
        WAans += WAcnt[i]

print(ACcnt,WAans)

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

int main()
{
  int N;
  cin>>N;
  N=N%10;
  if(N==2 || N==4|| N==5|| N==7|| N==9)
    cout<<"hon";
  if(N==0 || N==1|| N==6|| N==8)
    cout<<"pon";
  if(N==3)
    cout<<"bon";
}

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

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

  int N;
  cin >> N;
  
  int A[N] = {};
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  
  int ans = A[0];
  for (int i = 1; i < N; i++) {
    ans = gcd (ans, A[i]);
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
#define INF 100000000
int main(){
  int n,m,k;
  while(cin>>n>>m){
    if(n==0&&m==0) break;
    int glaf[m+1][m+1][2];
    for(int i=0;i<=m;i++){
      for(int j=0;j<=m;j++)
        glaf[i][j][0] = glaf[i][j][1] = INF;
      glaf[i][i][0] = glaf[i][i][1] = 0;
    }
    int a,b,cost,time;
    for(int i=0;i<n;i++){
      cin >> a >> b >> cost >> time;
      glaf[a][b][0] = glaf[b][a][0] = cost;
      glaf[a][b][1] = glaf[b][a][1] = time;
    }
    for(int x=1;x<=m;x++){
      for(int i=1;i<=m;i++){
        for(int j=1;j<=m;j++){
          glaf[i][j][0] = min(glaf[i][j][0],glaf[i][x][0]+glaf[x][j][0]);
          glaf[i][j][1] = min(glaf[i][j][1],glaf[i][x][1]+glaf[x][j][1]);
        }
      }
    }
    cin >> k;
    int p,q,r;
    for(int i=0;i<k;i++){
      cin >> p >> q >> r;
      cout << glaf[p][q][r] << endl;
    }
  }
}



Measured memory_bytes: 3144
#include<cstdio>
#include<cstring>
#include<iostream>
#include<vector>
using namespace std;
typedef pair<int,int> PII;
int n,m;
int an;
int q[2050];
int head[2050];
int id[2050][2050];
int anc[2050][2050];
struct edge
{
	int to,nex;
	edge(int to=0,int nex=0):to(to),nex(nex){}
};
vector<edge> G;
void addedge(int u,int v)
{
	G.push_back(edge(v,head[u])),head[u]=G.size()-1;
	G.push_back(edge(u,head[v])),head[v]=G.size()-1;
}
void BFS(int a,int b,vector<PII> &E)
{
	int hd=0,tl=0;
	q[tl++]=b;
	while(hd<tl)
	{
		int u=q[hd++];
		for(int i=head[u];~i;i=G[i].nex)
		{
			int v=G[i].to;
			if(v!=anc[a][u])
			{
				if(id[a][v]!=-1)
				{
					E.push_back(make_pair(b,v));
					continue;
				}
				id[a][v]=b;
				q[tl++]=v;
			}
		}
	}
}
void adde(int a,int b)
{
	if(a==b)
	{
		return;
	}
	if(id[a][b]!=-1)
	{
		adde(id[a][b],b);
		return;
	}
	if(id[b][a]!=-1)
	{
		adde(id[b][a],a);
		return;
	}
	vector<PII> E;
	id[a][b]=b,BFS(a,b,E);
	id[b][a]=a,BFS(b,a,E);
	for(unsigned int i=0;i<E.size();++i)
	{
		adde(E[i].first,E[i].second);
	}
}
void dfs1(int u,int root)
{
	for(int i=head[u];~i;i=G[i].nex)
	{
		int v=G[i].to;
		if(v!=anc[root][u])
		{
			anc[root][v]=u;
			dfs1(v,root);
		}
	}
}
void dfs2(int u,int lst)
{
	int t=lst;
	if(id[lst][u]!=-1)
	{
		++an;
		t=u;
	}
	for(int i=head[u];~i;i=G[i].nex)
	{
		int v=G[i].to;
		if(v!=anc[lst][u])
		{
			dfs2(v,t);
		}
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	memset(head,-1,sizeof(head));
	for(int i=1;i<n;++i)
	{
		int u,v; scanf("%d%d",&u,&v);
		addedge(u,v);
	}
	for(int i=1;i<=n;++i)
	{
		anc[i][i]=-1;
		dfs1(i,i);
	}
	memset(id,-1,sizeof(id));
	for(int i=1;i<=m;++i)
	{
		int a,b; scanf("%d%d",&a,&b);
		adde(a,b);
	}
	for(int i=1;i<=n;++i)
	{
		dfs2(i,i);
	}
	an>>=1;
	printf("%d\n",an);
	return 0;
}

Measured memory_bytes: 33152
#include <bits/stdc++.h>
using namespace std;
int main()
{
    std::ios::sync_with_stdio(false);
    int n,a,b;
	cin>>n>>a>>b;
	if(n==1)
	{
		if(a==b)
		{
			cout<<1;
		}
		else
		{
			cout<<0;
		}
	}
	else
	{
		if(a==b)
		{
			cout<<1;
		}
		else if(a>b)
		{
			cout<<0;
		}
		else
		{
			long long minn = (long long)a*(n-1)+b;
			long long maxn = (long long)b*(n-1)+a;
			cout<<(long long)maxn-minn + 1;
		}
	}
		
    return 0;
}

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

//N以下の素数列挙。O(N log log N)
int N = 100000;
vector<int> primes;
vector<bool> is_prime(N + 1, true);
void init() {
        is_prime[0] = is_prime[1] = false;
        for (int i = 2; i <= N; i ++) {
                if (is_prime[i]) {
                        primes.push_back(i);
                        for (int j = i + i; j <= N; j += i) is_prime[j] = false;
                }
        }
}

int main() {
        init();
        int n;
        scanf("%d", &n);
        vector<int> ans;
        for (int i = 0; i < 100000; i ++) {
                if (primes[i] % 5 == 1) {
                        ans.push_back(primes[i]);
                        if (ans.size() == n) break;
                }
        }
        for (int i = 0; i < n; i ++) {
                printf("%d%c", ans[i], i == n - 1 ? '\n' : ' ');
        }
        return 0;
}



Measured memory_bytes: 384
#from numpy import*
#from scipy import*
from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2)
from operator import mul
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial
from copy import deepcopy
import sys
#input=sys.stdin.readline  #危険！基本オフにしろ！
sys.setrecursionlimit(10**6)

#enumerate input

def main():
    h,w=map(int,input().split())
    stack=deque()
    grid=[["#"]*(w+2)]
    for i in range(h):
        tmp=[]
        for k,v in enumerate(input()):
            if v=="#":
                tmp.append("#")
                stack.appendleft((i+1,k+1))
            else:
                tmp.append(v)
        grid.append(["#"]+tmp+["#"])
    grid.append(["#"]*(w+2))
#    for i in grid:
#        print(*i)
    for i in range(h*w):
        tmp=deque()
        while stack:
            y,x=stack.pop()
            for my,mx in ((0,1),(1,0),(-1,0),(0,-1)):
                if grid[y+my][x+mx]==".":
                    grid[y+my][x+mx]="#"
                    tmp.appendleft((y+my,x+mx))
        stack=tmp
        if not len(stack):
            print(i)
            exit()
if __name__ == '__main__':
    main()

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

int main() {
  int n,k;
  cin >> n >> k;
  int sum = 0;
  for(int i = 0; i < n; i++){
    int x;
    cin >> x;
    if(k - x <= x){
      sum += 2*k - 2*x;
    }
    else{
      sum += 2*x;
    }
  }
  cout << sum << endl;
}

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

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A,B,C;
    cin >> A >> B >> C;
    A = C+B-A;
    if(A < 0){
        cout << 0 << "\n";
    }else{
        cout << A << "\n";
    }
}

Measured memory_bytes: 256
def coffee(word):
    ar = [char for char in word] 
    if (ar[2] == ar[3]) and (ar[4] == ar[5]):
      return 'Yes'
    else:
      return 'No'

if __name__ == '__main__':

    ar = str(input())

    result = coffee(ar)
    print(result)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
void solve(){
	ll a,b,c,k;
	cin>>a>>b>>c>>k;
	ll res=min(a,k);
	k-=min(a,k);
	k-=min(b,k);
	res-=min(c,k);
	cout<<res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll qc=1;
    for(ll i=1;i<=qc;i++)
    solve();
}


Measured memory_bytes: 3608
A, B, C, X = [int(input()) for _ in range(4)]
ans = 0
for a in range(0, A + 1):
  for b in range(0, B + 1):
    for c in range(0, C + 1):
      x = a * 500 + b * 100 + c * 50
      if X == x:
        ans += 1

print(ans)

Measured memory_bytes: 3060
S = []
for i in range(3):
    tmp = list(input())
    S.append(tmp)
turn = 0
while True:
    if len(S[turn]) == 0:
        print(chr(ord('A')+turn))
        break
    next = ord(S[turn][0]) - ord('a')
    del S[turn][0]
    turn = next


Measured memory_bytes: 9056
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2　//1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) (max(x,y)-min(x,y))
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int,int>;
typedef vector<int> vit;

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

    lol a, b, c;
    cin >> a >> b >> c;
    if(4 * a * b < (c - a - b) * (c - a - b) && (c - a - b) > 0){
      cout << "Yes\n";
    } else {
      cout << "No\n";
    }
    return 0;
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

using namespace std;

#define int long long
#define test int t; cin >> t; while (t--)
#define deb(x) cerr << #x << " " << x << endl;
#define debb(x, y) cerr << #x << " = " << x << "," << #y << " = " << y << endl <<endl;
#define pb push_back
#define pp pop_back
#define mkp make_pair 
#define f first
#define s second
#define all(x) x.begin(),x.end()

#define MOD 1000000007
#define MAX 50000

typedef long double ld;
const int N = 1e5 + 10;
const int maxn = 2e6 + 10;
const long double Pie = acos(-1);

signed main() 
{		
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	int n;	cin >> n;
	cout << (1000 - n % 1000) % 1000 << endl;
	
	return 0;
}



Measured memory_bytes: 3652
import java.io.*;
import java.util.*;
 
public class Main {
 
	void submit() {
	    long N = nextInt();
	    long total = 0;
	    
	    for(long i=0; i<N; i++){
	        total += i;
	    }
        out.println(total);
	}

	void preCalc() {
 
	}
 
	void stress() {
 
	}
 
	void test() {
 
	}
 
	Main() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		preCalc();
		submit();
		//stress();
		//test();
		out.close();
	}
 
	static final Random rng = new Random();
 
	static int rand(int l, int r) {
		return l + rng.nextInt(r - l + 1);
	}
 
	public static void main(String[] args) throws IOException {
		new Main();
	}
 
	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
 
	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}
 
	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
 
	int nextInt() {
		return Integer.parseInt(nextToken());
	}
 
	long nextLong() {
		return Long.parseLong(nextToken());
	}
 
	double nextDouble() {
		return Double.parseDouble(nextToken());
	}
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
using namespace std;
inline int read(){
	int v=0,f=1;
	char c=getchar();
	while (c<'0' || c>'9'){
		if (c=='-') f=-1;
		c=getchar();
	}
	while (c>='0' && c<='9'){
		v=v*10+c-'0';
		c=getchar();
	}
	return v*f;
}
const int Maxn=200005;
char s[Maxn];
int n;
int dp[Maxn][2];
int main(){
	scanf("%s",s);
	n=strlen(s);
	for (int i=0;i<Maxn;i++){
		for (int j=0;j<2;j++) dp[i][j]=-1e9;
	}
	dp[0][0]=dp[1][1]=1;
	if (s[0]!=s[1]) dp[1][0]=2;
	for (int i=2;i<n;i++){
		if (s[i]!=s[i-1]) dp[i][0]=max(dp[i-1][0],dp[i-1][1])+1;
		else dp[i][0]=dp[i-1][1]+1;
		dp[i][1]=dp[i-2][0]+1;
		if (i!=2){
			if (s[i-1]!=s[i-3] || s[i]!=s[i-2]){
				dp[i][1]=max(dp[i][1],dp[i-2][1]+1);
			}
		}
	}
	printf("%d\n",max(dp[n-1][0],dp[n-1][1]));
	return 0;
}

Measured memory_bytes: 2048
#include <iostream>
#include <bits/stdc++.h>
#define MOD 998244353
#define pb push_back
#define ll long long int
using namespace std;




int main()
{    ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);
     ll i,j,m,n,k;
     ll t;
     string s;
     cin>>n;
     cin>>s;
     vector<ll> v1,v2;
     unordered_map<ll,ll> m1;
     for(i=0;i<n;i++)
     {
         if(s[i]=='R')
             v1.pb(i);
         else if(s[i]=='G')
             v2.pb(i);
         else 
         {
          m1[i]=1;}
     }
     ll s1=0;
     ll o=m1.size();
     /*for(i=0;i<v1.size();i++)
     {
         cout<<v1[i]<<" ";
     }
     cout<<endl;
 for(i=0;i<v2.size();i++)
     {
         cout<<v2[i]<<" ";
     }
     cout<<endl;
     for(auto p:m1)
     {
         cout<<p.first<<" ";
     }
     cout<<endl;*/
     for(i=0;i<(ll)v1.size();i++)
     {
         for(j=0;j<(ll)v2.size();j++)
         {   ll c=0;
             ll d=abs(v1[i]-v2[j]);
             if(m1[v1[i]+d]==1)
                 c++;
             if(m1[v1[i]-d]==1)
                 c++;
             if(m1[v2[j]+d]==1)
                 c++;
             if(m1[v2[j]-d]==1)
                 c++;
             if(d%2==0 && m1[min(v1[i],v2[j])+d/2]==1)
                 c++;
             //cout<<c<<" "; 
             s1+=o-c;
         }
     }
     cout<<s1;
}


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

struct UnionFind{
    vector<int> data;
    //要素の根を管理
    //xが根ならdata[x]<0で、-data[x]がその集合のサイズ
    UnionFind(int n){data.assign(n, -1);}
    void init(int n){ data.assign(n, -1); }
    bool unite(int x, int y){
        x = root(x), y = root(y);
        if(x != y){
            if(data[y] < data[x])swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    int root(int x){ return data[x]<0 ? x : data[x]=root(data[x]); }
    int size(int x){ return -data[root(x)]; }
    bool same(int x, int y){ return root(x) == root(y); }
};

int main(){
    
    int N, M;
    scanf("%d %d", &N, &M);
    vector<int> p(N), x(M), y(M);
    rep(i,N)scanf("%d", &p[i]),p[i]--;
    rep(i,M)scanf("%d %d", &x[i], &y[i]),x[i]--,y[i]--;

    UnionFind uf(N);
    int ans=0;

    rep(i,M)uf.unite(x[i], y[i]);
    rep(i,N)if(uf.same(i, p[i]))ans++;
    cout << ans << endl;
}

Measured memory_bytes: 1792
A = int(input())
B = int(input())
C = int(input())
X = int(input())
count = 0
for a in range(A + 1):
    for b in range(B + 1):
        for c in range(C + 1):
            if 500 * a + 100 * b + 50 * c == X:
                count += 1
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 1e9+7;
using ll = long long;
using P = pair<ll, ll>;
vector<int> to[100005];
int cost[100005];
double PI = acos(-1);
int x[10];
int y[10];

double dist(ll i, ll j) {
    int xx = (x[i]-x[j])*(x[i]-x[j]);
    int yy = (y[i]-y[j])*(y[i]-y[j]);
    return sqrt(xx+yy);
}

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

    ll ans = 0;
    rep(i,n) {
        ans += i;
    }
    cout << ans << endl;

    return 0;
}



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

int main() {
	string S;
	cin >> S;
	for (int n = 0;n<S.size(); ++n) {
		if (0 ==n%2) {
			if ('L' == S[n]) {
				cout << "No"<<endl;
				return 0;
			}
		}
		else {
			if ('R' == S[n]) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    int ans = 1;
    if (n == 1) cout << ans << endl;
    else {
    for (int i = 7; i > 0; i--)
    {
        ans = pow(2, i);
        if (ans <= n) {
            cout << ans << endl;
            break;
        }
    }
}
}

Measured memory_bytes: 4068
#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
#define ll long long 
#define pb push_back
int main(){	
	fast;
		double n; cin>>n;
		double l,b,h;
		l=n/3;
		n-=l;
		b=n/2;
		h=n-b;
		cout<<fixed<<setprecision(12)<<l*b*h;
		}
		
		
		
	
	

	
	
	
		

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <math.h>

using namespace std;

//conversion
//------------------------------------------
inline long toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline long toLong(string s) {long v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const long double EPS = 1e-12;
const int INF = 10000;


int main(){
	int N;LL M;
	while(cin>>N>>M){
		if(N==0&&M==0)break;
		vector<PII>pi;
		LL sum=0;
		REP(i,N){
			int d,p;
			cin>>d>>p;
			pi.PB(MP(p,d));
			sum+=d*p;
		}
		sort(ALL(pi),greater<PII>());
		int cnt=0;
		LL mamo=0;
		while(pi[cnt].second<=M&&cnt<SZ(pi)){
			M-=pi[cnt].second;
			mamo+=pi[cnt].second*pi[cnt].first;
			cnt++;
		}
		if(cnt!=SZ(pi))mamo+=M*pi[cnt].first;
		cout<<sum-mamo<<endl;
	}
	return 0;
}

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

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

    int n;
    cin >> n;

    for(int i = 0; i <= 100; i++){
        for(int j = 0; j <= 100; j++){
            if(i * 4 + j * 7 == n){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	 int x,y,z,n,m;
	 scanf("%d %d %d",&x,&y,&z);
	 m=(x-z)%(y+z);
	 	 printf("%d\n",(x-z)/(y+z));
	return 0;
}



Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
const int N = 3005; 
using namespace std; 

int n, a[N], head[N], cnte, f[N];
struct edge { int to, nxt; } e[N << 1]; 

template < typename T >
inline T read()
{
	T x = 0, w = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * w; 
}

inline void adde(int u, int v) { e[++cnte] = (edge) { v, head[u] }, head[u] = cnte; }

void dfs(int u, int fa)
{
	for(int v, i = head[u]; i; i = e[i].nxt)
	{
		v = e[i].to; if(v == fa) continue;
		dfs(v, u), f[u] |= !f[v] && (a[v] < a[u]); 
	}
}

int main()
{
	n = read <int> ();
	for(int i = 1; i <= n; i++)
		a[i] = read <int> ();
	for(int u, v, i = 1; i < n; i++)
	{
		u = read <int> (), v = read <int> ();
		adde(u, v), adde(v, u); 
	}
	for(int i = 1; i <= n; i++)
	{
		for(int j = 1; j <= n; j++)
			f[j] = 0;
		dfs(i, 0);
		if(f[i]) printf("%d ", i); 
	}
	puts(""); 
	return 0; 
}


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

int n;


void dfs(string s, char mx){
    if(s.length()==n) cout << s << endl;
    else{
        for(char c='a';c<=mx;c++){
            dfs(s+c,(c==mx) ? char(mx+1) : mx);
        }
    }
}

int main(){
    cin >> n;
    dfs("",'a');
    
    
    
    
}

Measured memory_bytes: 1536
#include <iostream>
#include <string>
#include <cstdio>
using namespace std;
int n;

int check(int num,int start, string w[40]){
  int count = start;
  bool flag = true;
  while(flag){
    if(count >= n){
      flag = false;
      break;
    }
    else if(num - w[count].size() == 0){
      count++;
      break;
    }
    else if(num - w[count].size() > 0){
      num -= w[count].size();
      count++;
      continue;
    }
    else {
      flag = false;
      break;
    }
  }
  if(flag) return count;
  else return -1;
}

int main(){
  string w[40];
  while(true){
    cin >> n;
    //cout << "n="<<n << endl;
    if(n == 0) break;

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

    for(int i = 0; i < n - 4; i++){
      int point = i;

      point = check(5, i, w);
      if(point == -1) continue;
      point = check(7, point, w);
      if(point == -1) continue;
      point = check(5, point, w);
      if(point == -1) continue;
      point = check(7, point, w);
      if(point == -1) continue;
      point = check(7, point, w);
      if(point != -1){
         cout << i+1 << endl;
         break;
      }
    }
  }
  return 0;
}



Measured memory_bytes: 3208
//归并排序
#include<iostream>
using namespace std;
#define maxx 500000
#define INF 2000000000
int a[maxx];
int b[maxx/2+2];
int c[maxx/2+2];
int cnt=0;
void merge(int left,int right)
{
	int mid=(left+right)/2;
	int n1=mid-left;
	int n2=right-mid;
	for(int i=0;i<n1;i++)//不包含mid 
	{
		b[i]=a[i+left];
	}
	b[n1]=INF;//减少比较次数 
	for(int j=0;j<n2;j++)
	{
		c[j]=a[mid+j];
	}
	c[n2]=INF;//减少比较次数 
	int cn1=0;
	int cn2=0;
	int cn3=0;
	/*while(cn1<=n1-1&&cn2<=n2-1)
	{
		cnt++;
		if(b[cn1]<=c[cn2])
			a[cn3++]=b[cn1++];
		else
			a[cn3++]=c[cn2++];
	}
	if(cn1==n1)
	{
		while(cn2<=n2-1)
			a[cn3++]=c[cn2++];
	}
	else if(cn2==n2)
	{
		while(cn1<=n1-1)
			a[cn3++]=b[cn1++];
	}*/
	for(int k=left;k<right;k++)
	{
		cnt++;
		if(b[cn2]<=c[cn3])
			a[k]=b[cn2++];
		else
			a[k]=c[cn3++];
	}
} 
void mergesort(int left,int right)
{
	if(left+1<right)
	{
		int mid=(left+right)/2;
		mergesort(left,mid);
		mergesort(mid,right);
		merge(left,right);
	}
}
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	mergesort(0,n);
	for(int i=0;i<n;i++)
	{
		if(i>0)
			cout<<" ";
		cout<<a[i];
	}
	cout<<endl;
	cout<<cnt<<endl;
	return 0;
}



Measured memory_bytes: 6920
Sa = [a for a in (input()+'e')]
Sb = [b for b in (input()+'e')]
Sc = [c for c in (input()+'e')]

i = Sa.pop(0)
while(True):
    if i == 'a':
        i = Sa.pop(0)
    elif i == 'b':
        i = Sb.pop(0)
    elif i == 'c':
        i = Sc.pop(0)
    if len(Sa) == 0:
        print('A')
        break
    elif len(Sb) == 0:
        print('B')
        break
    elif len(Sc) == 0:
        print('C')
        break

Measured memory_bytes: 3188
n = gets.to_i
x = gets.split().map(&:to_i).sort
st = x[0]
ed = x[-1]

ans = 1000000000000

(st..ed).each do |p|
  sum = 0
  x.each do |i|
    sum += (p-i)**2
  end
  ans = [ans, sum].min
end

puts ans


Measured memory_bytes: 1788
N, K = gets.chop.split.map(&:to_i)
snk = Array.new(N, nil)

(K * 2).times do |i|
  a = gets.chop.split(' ').map(&:to_i)

  unless i == 0 || i % 2 == 0
    a.each do |i|
      snk[i - 1] = true
    end
  end
end


puts snk.count{ |x| x.nil? }

Measured memory_bytes: 14228
import sys
n = int(input())
l = list(map(int, input().split()))

pos = [0 for _ in range(100002)]
pos[0] = 3

ans = 1

MOD = 1000000007

for i in l:
    if pos[i+1] >= 3:
        print(0)
        sys.exit()

    if pos[i] == 0:
        print(0)
        sys.exit()

    ans *= pos[i]
    ans = ans % MOD
    pos[i] -= 1
    pos[i+1] += 1

print(ans)


Measured memory_bytes: 13964
from operator import add
N,M,X = map(int, input().split())
tmp = [list(map(int,list(input().split()))) for i in range(N)]
c= []
a = [[] for i in range(N)]
result = []
for i in range(N):
    c.append(tmp[i][0])
    a[i].extend(tmp[i][1:])

for bit in range(1 << (N)):
    suma = [0] * M
    disc = [X] * M
    c4i = []
    rsum = 0
    for i in range(N):
        if (bit & (1<<i)):
            # ここでとった要素を一個づつ見る
            suma = map(add,suma,a[i])
            c4i.append(i)
    suma = list(suma)
    # print(c4i)
    # print(suma,disc)
    # print(suma>=disc)
    flag = True
    for v in range(M):
        if suma[v] < disc[v]:
            flag = False
    if flag:
        for t in c4i:
            rsum = rsum + c[t]
        result.append(rsum)
# print(result)
if result:
    print(min(result))
else:
    print(-1)

Measured memory_bytes: 9284
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repf(i, a, b) for(ll i = (a); i < (b) ; i++ )
const ll mo = 1000000007;
const ll INF = 1LL << 60; //MAX 9223372036854775807
ll ans = 0;

int main()
{
ll n,l;
cin >> n>>l;

if(l>0){
    rep(i,n-1){
        ans+=l+i+1;
        
    }
    cout << ans << endl;
        return 0;
}
else if(n+l>=1){
    rep(i,n){
        ans+=l+i;
    }
    cout << ans << endl;
        return 0;
}
else{
    rep(i,n-1){
        ans+=l+i;

    }
    cout << ans << endl;
        return 0;
}

}


Measured memory_bytes: 256
N = int(input())
t, x, y = 0, 0, 0

for _ in range(N):
    ti, xi, yi = map(int, input().split())
    dt, dx, dy = ti - t, abs(xi - x), abs(yi - y)
    t, x, y = ti, xi, yi
    # print(dt, dx, dy)
    # print((dt - (dx + dy)) % 2)
    if ((dt - (dx + dy)) % 2 != 0) or (dx + dy > dt):
        print('No')
        exit()

print('Yes')

Measured memory_bytes: 3064
#include<stdio.h>

#define min(a,b) ((a)<(b)?(a):(b))

long long b[2000][2000];

int main(){
		int n,i,j,k;
		long long x,a[2000],ans=-1;
		scanf("%d%lld",&n,&x);
		for(i=0;i<n;i++){
				scanf("%lld",&a[i]);
				b[0][i]=a[i];
		}
		for(k=0;k<n;k++){
				long long tmp=k*x;
				if(k>0){
						for(i=0;i<n;i++){
								if(i>=k)b[k][i]=min(b[k-1][i],b[0][i-k]);
								else b[k][i]=min(b[k-1][i],b[0][n-k+i]);
						}
				}
				for(i=0;i<n;i++)tmp+=b[k][i];
				if(ans==-1)ans=tmp;
				ans=min(ans,tmp);
		}
		printf("%lld\n",ans);
		return 0;
}


Measured memory_bytes: 31488
from collections import Counter
s = input()
t = input()
S = Counter(s)
T = Counter(t)
li_s = sorted(list(s))
li_t = sorted(list(t),reverse=True)
ans_s = ''.join(li_s)
ans_t = ''.join(li_t)
if ans_s < ans_t:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  ll A, B, K;
  cin >> A >> B >> K;
  ll take = min(A, K);
  A -= take;
  K -= take;
  if (K > 0) B -= K;
  if (B < 0) B = 0;
  cout << A << ' ' << B << '\n';
  return 0;
}

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

using namespace std;

int main()
{
    int x,a,b;
    while(scanf("%d%d%d",&x,&a,&b)!=EOF)
        printf("%d\n",(x-a)%b);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
#include<queue>
using namespace std;
int m,n,k,d;
int f(string s)
{
	if(s=="H")return 0;
	else if(s=="D")return m+n+1;
	else if(s[0]=='C')return s[1]-'0';
	else return stoi(s.substr(1))+m;
}
main()
{
	while(cin>>m>>n>>k>>d,d)
	{
		int c[6];for(int i=0;i<m;i++)cin>>c[i];
		vector<vector<pair<int,int> > >G(m+n+2);
		for(int i=0;i<d;i++)
		{
			string ss,tt;int e;cin>>ss>>tt>>e;
			int s=f(ss),t=f(tt);
			G[s].push_back(make_pair(t,e*k));
			G[t].push_back(make_pair(s,e*k));
		}
		vector<vector<int> >d(m+n+2,vector<int>(1<<m,1e9));
		priority_queue<pair<int,pair<int,int> > >P;
		d[0][0]=0;
		P.push(make_pair(0,make_pair(0,0)));
		while(!P.empty())
		{
			int D=-P.top().first,u=P.top().second.first,L=P.top().second.second;
			P.pop();
			if(d[u][L]<D)continue;
			for(int i=0;i<G[u].size();i++)
			{
				int v=G[u][i].first,cost=G[u][i].second;
				int next=L;
				if(v>=1&&v<=m)
				{
					if(L&1<<v-1)continue;
					next|=1<<v-1;
				}
				if(d[v][next]>D+cost)
				{
					d[v][next]=D+cost;
					P.push(make_pair(-d[v][next],make_pair(v,next)));
				}
			}
		}
		vector<int>sc(1<<m,0);
		for(int i=0;i<1<<m;i++)
		{
			for(int j=0;j<m;j++)if(i&1<<j)sc[i]+=c[j];
		}
		int ans=1e9;
		for(int i=0;i<1<<m;i++)
		{
			ans=min(ans,d[m+n+1][i]-sc[i]);
		}
		cout<<ans<<endl;
	}
}



Measured memory_bytes: 3096
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	long long a, b, c = 0, d = 0, e;
	cin >> a;
	int test[10] = { 0 };
	for (int h = 1; h <= a; h++) {
		cin >> b;
		if (b < 400) {
			test[1] += 1;
		}
		else if (b < 800) {
			test[2] += 1;
		}
		else if (b < 1200) {
			test[3] += 1;
		}
		else if (b < 1600) {
			test[4] += 1;
		}
		else if (b < 2000) {
			test[5] += 1;
		}
		else if (b < 2400) {
			test[6] += 1;
		}
		else if (b < 2800) {
			test[7] += 1;
		}
		else if (b < 3200) {
			test[8] += 1;
		}
		else {
			test[9] += 1;
		}
	}
	for (int j = 0; j <= 8; j++) {
		if (test[j] >= 1) {
			c++;
		}
	}
	if (c == 0) {
		cout << '1' << ' ' << test[9] << endl;
	}
	else {
		cout << c << ' ' << c + test[9] << endl;
	}
	cin >> e;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args)  {

		Scanner scanner = new Scanner( System.in );

		ArrayList<Integer> nums = new ArrayList<Integer>();

		int a = Integer.parseInt( scanner.next() );
		int b = Integer.parseInt( scanner.next() );
		int c = Integer.parseInt( scanner.next() );

		for ( int i = 1; i <= c; i++ ) {
			if ( c % i == 0 ) {
				nums.add( i );
			}
		}

		int count = 0;
		for ( int num : nums ) {
			if ( num >= a && num <= b ) {
				count++;
			}
		}

		System.out.println( count );

		scanner.close();
	}
}

Measured memory_bytes: 26116
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	ll q; cin >> q;
	while(q--){
		string s; cin >> s;
		ll n = s.size();
		set<string> se;
		REP(i,1,n){
			string t = s.substr(0,i);
			string u = s.substr(i);
			string rt = t;
			string ru = u;
			reverse(all(rt));
			reverse(all(ru));
			se.insert(t+u);
			se.insert(u+t);
			se.insert(ru+t);
			se.insert(t+ru);
			se.insert(rt+u);
			se.insert(u+rt);
			se.insert(rt+ru);
			se.insert(ru+rt);
		}
		cout << se.size() << endl;
	}
}


Measured memory_bytes: 3068
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)

"""
逆にSを殻にする
"""
S = input()
S = S.replace('eraser', '')
S = S.replace('erase', '')
S = S.replace('dreamer', '')
S = S.replace('dream', '')
if len(S) == 0:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 5588
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod = 1e9+7;

int main(){
    int n;
    cin >> n;
    bool flag = false;
    int k = 0;
    int i = 2;
    while(i*(i-1) <= 2*n){
        if(i*(i-1) == 2*n && 2*n%i == 0){
            k = i;
            flag = true;
        }
        i++;
    }    
    vector<vector<int>> ans(k);
    int m = 1;
    for(int i = 0; i < k-1; i++){
        for(int j = i+1; j < k; j++){
            ans[i].push_back(m);
            ans[j].push_back(m);
            m++;
        }
    }
    if(flag){
        cout << "Yes" << endl;
        cout << ans.size() << endl;
        for(int i = 0; i < ans.size(); i++){
            cout << ans[i].size() << " ";
            for(int j = 0; j < ans[i].size(); j++){
                cout << ans[i][j] << " ";
            }
            cout << endl;
        }
    }
    else cout << "No" << endl;
}

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


int main() {
    int N;
    cin >> N;
    vector<ll> a(N);
    for (int i=0; i<N; i++) {
        cin >> a[i];
    }
    
    vector<ll> ans(N, 0);
    for (int i=0; i<N; i++) {
        while (a[i] % 2 == 0) {
            ans[i]++;
            a[i] /= 2;
        }
    }
    ll answer = 0;
    for (int i=0; i<N; i++) {
        answer += ans[i];
    }
    
    cout << answer << endl;
    
}


Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n;
int a[111111];
int cmp(int x,int y)
{
	return x>y;
 } 
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	sort(a+1,a+1+n,cmp);
	int alice=0,bob=0;
	for(int i=1;i<=n;i+=2)
	{
		alice+=a[i]; 
	}
	for(int i=2;i<=n;i+=2)
	{
		bob+=a[i];
	}
	cout<<alice-bob;
	return 0;
}

Measured memory_bytes: 256
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18) + 1;
const int MOD = 1000000007;
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 ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll d, g;
vector<ll> p,c;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> d>>g;
    for (int i = 0; i < d; i++)
    {
        ll temp,temp1;
        cin >> temp>>temp1;
        p.push_back(temp);
        c.push_back(temp1);
    }
    ll ans=LINF;
    for(int mask=0;mask<(1<<d);mask++){
        ll sum=0;
        ll count=0;
        for(int i=0;i<d;i++){
            if((1<<i)&mask){
                sum+=c[i];
                sum+=p[i]*(100*(i+1));
                count+=p[i];
            }
        }
        if(sum>=g){
            chmin(ans,count);
        }
        else{
            for(int i=d-1;i>=0;i--){
                if (!((1 << i) & mask)){
                    if (sum + p[i] * (100 * (i + 1))<g){
                        sum += p[i] * (100 * (i + 1));
                        count+=p[i];
                    }
                    else{
                        count += (g - sum + 100 * (i + 1) - 1) / (100 * (i + 1));
                        break;
                    }
                }
            }
            chmin(ans, count);
        }
    }
    cout << ans << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define ll long long
using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  if(a % 2 == 1 && b % 2 == 1) cout << "Yes\n";
  else cout << "No\n";
}

Measured memory_bytes: 3588
while 1:
    try:
        n = int(input())
    except:break

    n1 = 0
    n2 = 0
    for i in range(n):
        n1 = int(input())
        n2 = int(input())
        isOver = False
        ans = n1 + n2
        if len(str(ans)) >= 81 | len(str(n1)) | len(str(n1)) :
            isOver = True
        if isOver:
            print("overflow")
        else:
            print(ans)


Measured memory_bytes: 5588
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<ll> a;
	for(int i=0;i<n;++i){
		ll val;
		cin>>val;
		a.push_back(val);
	}
	ll mx = 0;
	ll sum = 0;
	for(int i=0;i<n;++i){
		mx = max(mx,a[i]);
		sum += max(0LL,mx-a[i]);
	}
	cout<<sum<<'\n';
	return 0;
}

Measured memory_bytes: 5336
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
#define f first
#define s second
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define debug(x) cout << #x << " " << x << "\n"
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
 
const ll N = 3e3 + 3;
const ll M = 1e9 + 7;
 
string s, t, res;
ll n, m;
ll dp[N][N];
 
int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	
	cin >> s >> t;
	n = s.size();
	m = t.size();
	s = " " + s;
	t = " " + t;
	
	for (ll i = 0; i <= n; ++i) dp[i][0] = 0;
	for (ll i = 0; i <= m; ++i) dp[0][i] = 0;
	
	for (ll i = 1; i <= n; ++i) {
		for (ll j = 1; j <= m; ++j) {
			dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
			if (s[i] == t[j]) {
				dp[i][j] = dp[i-1][j-1] + 1;
			}
		}
	}
	
	res = "";
	ll x = n, y = m;
	while (x && y) {
		if(dp[x][y] > dp[x - 1][y] && dp[x][y] > dp[x][y - 1]) {
			res += s[x];
			x--;y--;
		}
		else if(dp[x][y] == dp[x][y - 1]) {
			y--;
		}
		else if(dp[x][y] == dp[x - 1][y]) {
			x--;
		}
	}
	
	reverse(all(res));
	cout << res;
	
	return 0;
}


Measured memory_bytes: 70656
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;

void swap(int a,int b) {
	int tmp = a;
	a = b;
	b = tmp;
}

int main(void) {
	int n,x,y;
	cin >> n >> x >> y;
	vector<ll>ans(n);

	for (int i = 1; i <= n - 1; i++) {
		for (int j = i+1; j <= n; j++) {
			int saitan = min(j-i,abs(i-x)+abs(j-y)+1);
			ans[saitan]++;
		}
	}

	

	for (int i = 1; i < n;i++) {
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 3664
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>

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

using namespace std;

int main(void){
  int a,b;
  cin >> a >> b;
  int ans = -1;
  for(int i = a*12;i<=a*13;i++){
    if(i*8/100 == a && i/10 == b){
      ans = i;
      break;
    }
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll a,b,x;
  cin >> a >> b >> x;
  if(x >= a && a + b >= x)cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
N, M = [int(_) for _ in input().split()]
AB = [[int(_) for _ in input().split()] for i in range(N)]
CD = [[int(_) for _ in input().split()] for i in range(M)]

def calc(a, b, CD):
    mini, mind = -1, 10**10
    for i, cd in enumerate(CD):
        c, d = cd
        d = abs(c - a) + abs(d - b)
        if d < mind:
            mini, mind = i, d
    return mini + 1

for a, b in AB:
    print(calc(a, b, CD))



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
void YesNo(bool);
void YESNO(bool);


int main(){
    int a, b;
    cin >> a >> b;
    cout << a + b / 2 << endl;
    
}


void YesNo(bool x){
    if (x) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
}

void YESNO(bool x){
    if (x) {
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define RREP(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll W, H; cin >> W >> H;
    priority_queue<ll, vector<ll>, greater<ll>> p, q;
    ll psum = 0, qsum = 0;
    REP(i, W){
        ll x; cin >> x; p.push(x); psum += x;
    }
    REP(i, H){
        ll x; cin >> x; q.push(x); qsum += x;
    }
    ll ans = 0;
    ll pcnt = 0, qcnt = 0;
    while (!p.empty() || !q.empty()) {
        if(p.size() == 0){
            ans += q.top() * (W+1-pcnt);
            q.pop(); continue;
        }
        if(q.size() == 0){
            ans += p.top() * (H+1-qcnt);
            p.pop(); continue;
        }
        ll pt = p.top(), qt = q.top();
        if(pt < qt){
            ans += pt*(H+1-qcnt);
            p.pop(); pcnt++;
        }
        else{
            ans += qt*(W+1-pcnt);
            q.pop(); qcnt++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

inline void fastio(void) {
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}
template <typename T>
inline void read(T &x) {
  cin >> x;
}

namespace {
  const int mo = 1e9 + 7;
  inline int add(int x, int y) {
    if((x += y) >= mo) x -= mo;
    return x;
  }
  inline int sub(int x, int y) {
    if((x -= y) < 0) x += mo;
    return x;
  }
  inline int mul(int x, int y) {
    return 1LL * x * y % mo;
  }
  inline int pw(int a, int k) {
    int ans = 1;
    for (; k; k >>= 1, a = mul(a, a))
      if (k & 1) ans = mul(ans, a);
    return ans;
  }
}
const int N = 3e5 + 233;
int n, m, x;
pair <int, int> a[N];

signed main(void) {
  fastio();
  cin >> n;
  rep (i, n) cin >> x, a[++ m] = {x, 0};
  rep (i, n) cin >> x, a[++ m] = {x, 1};
  sort(a + 1, a + m + 1);
  int x = 0, y = 0, ans = 1;
  for (int i = 1; i <= m; i ++) {
    if (a[i].second == 0) {
      if (y) ans *= y --;
      else x ++;
    } else {
      if (x) ans *= x --;
      else y ++;
    }
    ans %= mo;
  }
  cout << ans << "\n";
}


Measured memory_bytes: 4352
#include <iostream>

using namespace std;
typedef long long LL;

int n, k;
LL w[100000];

bool check(LL P) {
   int i = 0;
   for (int j = 0; j < k; j++) {
       LL s = 0;
       while (s + w[i] <= P) {
           s += w[i++];
           if (i == n)
               return true;
       }
   }
   return false;
}

int solver() {
   LL left = 0, right = 100000 * 10000;
   LL mid;

   while (left < right) {
       mid = (left + right) / 2;
       if (check(mid))
           right = mid;
       else   
           left = mid + 1;
   }
   return right;
}

int main()
{
   cin >> n >> k;
 
   for (int i = 0; i < n; i++)
       cin >> w[i];
 
   cout << solver() << endl;

   return 0;
}

Measured memory_bytes: 3840