akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    if(n == 1) {
        cout << "Hello World" << endl;
    }
    else {
        int a,b;
        cin >> a >> b;
        cout << a + b << endl;
    }
    return 0;
}

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

using namespace std;

int n;
char s[maxn];
int sum, x;

int main(){
	scanf("%d%s", &n, s + 1);
	for(int i = 1;i <= n;i++){
		if(s[i] == 'R') sum++;
	}
	for(int i = 1;i <= sum;i++){
		if(s[i] == 'W') x++; 
	}
	printf("%d", min(x, min(sum, n - sum)));
}

Measured memory_bytes: 4016
#include<iostream>
using namespace std;
int main()
{
    int a,b,av;
    cin>>a>>b;
    av=(a+b)/2;
    double av2=(a+b)/2.0;
    if(av2>(double)av) cout<<(double)av+1<<endl;
    else cout<<av2<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int i;
  string s;
  cin >> s;
  for (i=0;i<3;i++){
    if (s.at(i)=='1') s.at(i)='9';
    else s.at(i)='1';
  }
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
<?php
    while(true){
        list($h,$w) = explode(" ", trim(fgets(STDIN)));
        if($h == 0 && $w == 0)break;
        $odd_line = '';
        $even_line = '';
        $ary = array();
        for($i = 0;$i < $w;$i++){
            if($i % 2 == 1){
                $odd_line .= '#';
                $even_line .= '.';
            }else{
                $odd_line .= '.';
                $even_line .= '#';
            }
        }
        for($i = 0;$i < $h;$i++){
            $i % 2 == 1 ? print($odd_line . "\n") : print($even_line . "\n");
        }
        //print("\n");
        echo PHP_EOL;
    }



Measured memory_bytes: 9248
#include<iostream>
#include<iomanip>
 
int main() {
  int N, K;
  double base;
  double sum;
  int score;

  std::cin >> N >> K;

  sum = 0.0;

  for(int i=1; i<=N; i++) {
    double p = 1.0;
    score = i;
    while(score < K) {
      p = p * 0.5;
      score = score * 2;
    }
    //std::cout << p << std::endl;
    sum = sum + p;
  }

  double ans = sum / (double)N;
  std::cout << std::setprecision(10) << ans;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int N;
  cin >> N;
  map<string,int> memo;
  rep(i,N){
    string s;
    cin >> s;
    memo[s]++;
  }

  int mx = 0;
  FOR(it,memo){
    mx = max(mx, it->second);
  }

  vector<string> v;
  FOR(it,memo){
    if(it->second == mx) v.push_back(it->first);
  }
  sort(ALLOF(v));

  rep(i,v.size()){
    cout << v[i] << endl;
  }
  
  return 0;
}


Measured memory_bytes: 26868
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S divup_L(S a, T b){
  return (a+b-1)/b;
}
int main(){
  int D, N, res;
  rd(N);
  rd(D);
  res =divup_L(N,(2*D+1));
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190715-1

// --- original code ---
// {
//   int N, D, res;
//   rd(N,D);
//   res = N /+ (2D+1);
//   wt(res);
// }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int              //cout<<fixed<<setprecision(9)<<double value; 
#define INF 1000000000000000007
#define pb emplace_back 
#define md 1000000007
#define all(s) s.begin(),s.end()
typedef vector<int> vi;
ll ans=0;
int gh[10005];
int d;
ll dp[10005][102][2];
ll getsum(int idx,int n,int sum,bool flag){
	if(idx>n)return (sum==0);
	if(dp[idx][sum][flag]!=-1)return dp[idx][sum][flag];
	int limit=9;
	if(!flag)limit=gh[idx];
	ll res=0;
	for(int i=0;i<=limit;i++){
		if(i<limit||flag){
			res+=getsum(idx+1,n,(sum+i)%d,true);
		}
		else{
			res+=getsum(idx+1,n,(sum+i)%d,false);
		}
	}
	return dp[idx][sum][flag]=res%md;
}
void solve(){
	string b;
	cin>>b;
	cin>>d;
	for(int i=0;i<b.size();i++){
		gh[i+1]=b[i]-'0';
	}
	memset(dp,-1,sizeof dp);
    ll r=getsum(1,b.size(),0,0);
  
   cout<<(r-1+md)%md<<"\n";
}
int main(){
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
ios::sync_with_stdio(false);
cin.tie(0);
   int t=1;
  // cin>>t;
     while(t--){
     	solve();
	 }
     return 0;
}

Measured memory_bytes: 20544
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#define RI register int
#define CI const int&
using namespace std;
const int N=1594324;
int n,m,rt,tot,ch[N][3],ans[N],id[N]; char s[N]; bool rev[N];
inline void build(int& now,CI dep=0,CI st=0)
{
	now=++tot; if (dep==n) return (void)(id[now]=st);
	int len=pow(3,dep); build(ch[now][0],dep+1,st);
	build(ch[now][1],dep+1,st+len); build(ch[now][2],dep+1,st+(len<<1));
}
inline void rever(CI now)
{
	swap(ch[now][1],ch[now][2]); rev[now]^=1;
}
inline void pushdown(CI now)
{
	if (!rev[now]) return; rev[now]=0;
	for (RI i=0;i<3;++i) rever(ch[now][i]);
}
inline void swaping(CI now,CI dep=0)
{
	pushdown(now); if (dep==n) return; swap(ch[now][1],ch[now][2]);
	swap(ch[now][0],ch[now][1]); swaping(ch[now][0],dep+1);
}
inline void DFS(CI now,CI dep=0,CI st=0)
{
	pushdown(now); if (dep==n) return (void)(ans[id[now]]=st); int len=pow(3,dep);
	DFS(ch[now][0],dep+1,st); DFS(ch[now][1],dep+1,st+len); DFS(ch[now][2],dep+1,st+(len<<1));
}
int main()
{
	RI i; scanf("%d%s",&n,s+1); m=strlen(s+1);
	for (build(rt),i=1;i<=m;++i) if (s[i]=='S') rever(rt); else swaping(rt);
	for (DFS(rt),n=pow(3,n),i=0;i<n;++i) printf("%d ",ans[i]); return 0;
}

Measured memory_bytes: 19652
//雪花飄飄北風嘯嘯
//天地一片蒼茫

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl;

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

ll MAX(ll a){return a;}
ll MIN(ll a){return a;}
template<typename... Args>
ll MAX(ll a,Args... args){return max(a,MAX(args...));}
template<typename... Args>
ll MIN(ll a,Args... args){return min(a,MIN(args...));}

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

int memo[200005];
int dp(int i){
	if (memo[i]!=-1) return memo[i];
	
	return memo[i]=dp(i%__builtin_popcount(i))+1;
}

int fix(int i,int j){
	while (i<0) i+=j;
	while (j<=i) i-=j;
	
	return i;
}

int n;
string s;

int ones=0;
int m1,m2;

int v1,v2;
int p1=1,p2=1;

vector<int> ans;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	memset(memo,-1,sizeof(memo));
	memo[0]=1;
	
	cin>>n;
	cin>>s;
	
	rep(x,0,n) if (s[x]=='1') ones++;
	m1=ones+1,m2=max(ones-1,1); //ew
	
	rep(x,0,n){
		v1=(v1*2)%m1;
		v2=(v2*2)%m2;
		if (s[x]=='1'){
			v1=(v1+1)%m1;
			v2=(v2+1)%m2;
		}
	}
	
	rep(x,n,0){
		if (s[x]=='1'){
			if (ones==1) ans.push_back(0);
			else ans.push_back(dp(fix(v2-p2,m2)));
		}
		else{
			ans.push_back(dp(fix(v1+p1,m1)));
		}
		
		p1=(p1*2)%m1;
		p2=(p2*2)%m2;
	}
	
	reverse(all(ans));
	
	rep(x,0,n) cout<<ans[x]<<endl;
}


Measured memory_bytes: 5284
n,*xyh=map(int,open(0).read().split())
x=xyh[0::3]
y=xyh[1::3]
h=xyh[2::3]

hmax_i = h.index(max(h))
for cx in range(101):
    for cy in range(101):
        H = abs(cx-x[hmax_i]) + abs(cy-y[hmax_i]) + h[hmax_i]
        for i in range(0,n):
            if max(H-abs(cx-x[i])-abs(cy-y[i]),0) == h[i]:
                if i == n-1:
                    print(cx,cy,H)
                    exit()
                else:
                    continue
            else:
                break

Measured memory_bytes: 3064
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	sum, max := 0, 0
	for i := 0; i < n; i++ {
		var tmp int
		fmt.Scan(&tmp)
		sum += tmp
		if max < tmp {
			max = tmp
		}
	}
	fmt.Println(sum - (max / 2))
}

Measured memory_bytes: 512
s = input()
n = len(s)
char_in_s = set()
for i in range(n):
    char_in_s.add(s[i])
ans = float('inf')
for char in char_in_s:
    max_interval = 0
    now = 0
    for i in range(n-1,-1,-1):
        if s[i] != char:
            now += 1
        else:
            max_interval = max(max_interval,now)
            now = 0
    max_interval = max(max_interval,now)
    ans = min(ans,max_interval)
print(ans)
        


Measured memory_bytes: 8996
#include<iostream>
#include<string>
#include<iomanip>
#include<map>
#include<vector>
using namespace std;
#define int long long
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF (long long)(1e18)
#define MOD (int)(1e9+7)
#define MAX_N 103
#define MAX_V 10
#define MAX_M 101
#define min(a,b) (a>b?b:a)
#define max(a,b) (a>b?a:b)
#define yn(f) (f?"Yes":"No")
#define YN(f) (f?"YES":"NO")
#define pro "はいプロ　世界一○○が上手　○○界のtourist　○○時代の終焉を告げる者　実質○○　○○するために生まれてきた男"
#define Answer_to_the_Ultimate_Question_of_Life_the_Universe_and_Everything 42
 #define tMAX 1000000000
#define MAX 10000000
// #define MAX 130

int temp[MAX +100];
int temp2[MAX +100];
int l, r;
int spn[110];

inline int huga(int i){
	for(int j = l/i*i; j <= r; j+=i){//cout<<i<<" "<<j<<" "<<endl;
		if(j < l)continue;
		if(temp2[j-l] == 0)temp2[j-l] = j;
		int count = 0, tx = temp2[j-l];
		while(tx%i == 0){
			tx/=i;
			count++;
		}

		temp[j-l]+=count;
		temp2[j-l] = tx;
	}
}

inline bool ispn(int x){
  if(x==2||x==3) return true;
  if(x <= 4||x%2==0||x%3==0) return false;
  for(int i = 6; (i-1)*(i-1) <= x; i+=6)
    if(x%(i-1)==0||x%(i+1)==0)return false;
  return true;
}



int Sieve_of_Eratosthenes(){
	huga(2); huga(3);
	for(int i = 6; (i-1)*(i-1)<= r+100; i+=6){//cout<<"i = "<<i<<endl;
		if(ispn(i-1)) huga(i-1);
		if(ispn(i+1)) huga(i+1);
	}
}

signed main(){
	cout<<fixed<<setprecision(7);
	int count = 0;
	cin>>l>>r;
	
	for(int i = 1; i <= 100; i++){
		spn[i] = ispn(i);
	}

	Sieve_of_Eratosthenes();
	
	for(int i = l; i <= r; i++){
		if(temp2[i-l]!=1&&temp2[i-l]!=0)temp[i-l]++;
		if(spn[temp[i-l]] ) count++;
	}
	
	
	cout<<count<<endl;
	
	
	return 0;
}


Measured memory_bytes: 18728
#include <stdio.h>
#define MAX 10000
#define NIL -1
typedef struct{
  int l,r,p;
}Node;

Node Tree[MAX];
int n;

void Preorder(int u){
  if(u==NIL) return;
  printf(" %d",u);
  Preorder(Tree[u].l);
  Preorder(Tree[u].r);
}

void Inorder(int u){
  if(u==NIL)return;
  Inorder(Tree[u].l);
  printf(" %d",u);
  Inorder(Tree[u].r);
}

void Postorder(int u){
  if(u==NIL)return;
  Postorder(Tree[u].l);
  Postorder(Tree[u].r);
  printf(" %d",u);
}

int main(){
  int i,id,left,right,root;
  scanf("%d",&n);
  for(i=0;i<n;i++) Tree[i].p=NIL;
  for(i=0;i<n;i++){
    scanf("%d %d %d",&id,&left,&right);
    Tree[id].l=left;
    Tree[id].r=right;
    if(left!=NIL)Tree[left].p=id;
    if(right!=NIL)Tree[right].p=id;
  }
  for(i=0;i<n;i++)
    if(Tree[i].p==NIL) root=i;
  printf("Preorder\n");
  Preorder(root);
  printf("\n");
  printf("Inorder\n");
  Inorder(root);
  printf("\n");
  printf("Postorder\n");
  Postorder(root);
  printf("\n");
  return 0;
}

Measured memory_bytes: 616
#include<iostream>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;
#define MAXN 105
int n,a[MAXN];
int solve(){
	int totalcost;
	int cost=INT_MAX;
	for(int i=a[1];i<=a[n];++i){
		totalcost=0;
		for(int j=1;j<=n;++j){
			totalcost+=(a[j]-i)*(a[j]-i);
		}
		cost=min(cost,totalcost);
	}
	return cost;
}
int main(){
	cin>>n;
	for(int i=1;i<=n;++i)
		cin>>a[i];
	sort(a+1,a+n+1);
	cout<<solve()<<endl;
	return 0;
}

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

using namespace std;
using Long = long long;

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

	int n, x, y;
	cin >> n >> x >> y;

	if (x > y)
		swap(x, y);

	vector<int> ans(n);

	if (x + 1 != y)
	{
		int d = y - x;

		for (int i = 1; i <= n; ++i)
		{
			for (int j = i + 1; j <= n; ++j)
			{
				int currD = j - i;

				if (j >= y and i <= x)
					currD -= (d - 1);
				else if (i <= x and x < j and j < y)
					currD = min(currD, abs(y - j) + 1 + x - i);				
				else if (x < i and i < y)
					currD = min(currD, abs(j - y) + abs(x - i) + 1);

				++ans[currD];
			}
		}
	}

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

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int top;

const int MAX = 200;
int stack[MAX];

void initialize(){
    top = 0;
}

bool isEmpty(){
    return top == 0;
}

bool isFull(){
    return top >= MAX -1;
}

bool push(int x){
    if (isFull()) return false;
    top++;
    stack[top] = x;
    return true;
}

int pop(){
    if (isEmpty()) return 0;
    top--;
    return stack[top+1];
}

int main(){

    initialize();

    string s , input;

    getline(cin,input);
    input += " ";

    std::string::size_type pos1 = 0, pos2 = input.find(" ");

    int result;
    while(pos2 != std::string::npos){
        s = input.substr(pos1, pos2-pos1);

        int n, m;
        if(s=="+") {
            n = pop();
            m = pop();
            result = m + n;
        }else if(s=="-"){
            n = pop();
            m = pop();
            result = m - n;
        }else if(s=="*"){
            n = pop();
            m = pop();
            result = m * n;
        }else{
            result = atoi(s.c_str());
        }
        push(result);
        pos1 = pos2 + 1;
        pos2 = input.find(" ", pos1);
    }

    cout << pop() << endl;
    
    return 0;
}


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

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define upper(n,m) (n+m-1)/m
#define rounding(n) (int)((double)n+0.5)

#define REP(i,n) for(int i=0;i<n;i++)
#define ALL(a) a.begin(),a.end()
#define coutALL(i,a) for(auto e:a) cout<<(i++?" ":"")<<e; cout<<endl;

#define deb cout<<"debug"<<endl
#define debn(n) cout<<"debug: "<<n<<endl

//#define int long long

const int MAX=INT_MAX;
const int MOD=(int)1e9+7;
const int EPS=1e-12;
//const int dx[]={0,1,0,-1},dy[]={-1,0,1,0};
const int dx[]={-1,-1,-1,0,1,1,1,0},dy[]={-1,0,1,1,1,0,-1,-1};

using namespace std;

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

signed main(){

  int n,l;
  cin>>n>>l;

  vector <int> a(n);
  REP(i,n) cin>>a[i];

  multiset <int> a2;
  REP(i,l) a2.insert(a[i]);

  cout<<*a2.begin();

  REP(i,n-l){

    a2.erase(a2.lower_bound(a[i]));
    a2.insert(a[l+i]);

    cout<<" "<<*a2.begin();

  }

  cout<<endl;

  return 0;

}



Measured memory_bytes: 11472
from collections import defaultdict
def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()

s = readChar()
k = readInt()
for i in range(k):
  if s[i]!="1":
    print(s[i])
    exit()

print(1)

Measured memory_bytes: 9420
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C;
  cin >> A >> B;
  for(int i=0;i<B;i++){
      cin >> C;
      A=A-C;
  }
  if(A>=0){
  cout << A << endl;}else{
      cout << -1 << endl;
  }
}

Measured memory_bytes: 3636
n=int(input())
#i+j-2=cnt & i*j=n
import math
minn=100000000000000000000
for i in range(1,int(math.sqrt(n))+2):
    if n%i==0:
        j=n/i
        minn=min(int(i+j-2),minn)
print(minn)
    

Measured memory_bytes: 9164
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = min(a) + min(b)

for _ in range(M):
  x, y, c = map(int, input().split())
  ans = min(ans, a[x-1] + b[y-1] - c)

print(ans)

Measured memory_bytes: 18612
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int , int >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int N=1e4+10;
ll a[N];
string solve(string s,ll k){
    if (k==0) return s;
    ll n=s.size();
    string t=s;
    reverse(t.begin(),t.end());
    s=s+t;
    char z='z';
    for (int i=0;i<s.size();i++) z=min(z,s[i]);
    memset(a,0,sizeof a);
    if (k>20){
        string y="";
        for (int i=0;i<n;i++) y+=z;
        return y;
    }
    ll ma=0,id=0;
    if (k!=1){
        for (int i=1;i<=s.size();i++){
            if (s[i-1]==z) a[i]=1+a[i-1];
            if (a[i]>=ma){
                ma=a[i];
                id=i;
            }
        }
        string y="";
        for (int i=id-n;i<id;i++){
            y+=s[i];
        }
        ll p1=1;
        k--;
        while(ma<n && k>1){
            p1=1;
            for (int i=0;i<ma;i++) y+=z;
            ma*=2;
            k--;
        }
        if (p1){
            s="";
            for (int i=y.size()-n;i<y.size();i++) s+=y[i];
            t=s;
            reverse(t.begin(),t.end());
            s=s+t;
            k=1;
        }
    }
   // cout << s << endl;
    ma=0,id=0;
    memset(a,0,sizeof a);
    if (k==1){
        string y="";
        for (int i=2*n;i;i--){
            if (s[i-1]==z) a[i]=a[i+1]+1;
            if (a[i]>=ma){
                ma=a[i];
                id=i;
            }
        }
        for (int j=id-1;j<id+n-1;j++) y+=s[j];
        return y;
    }
}
int32_t main(){
    sync;
    string s;
    ll k;
    ll n;
    cin >> n >> k;
    cin >> s;
    vector <string> ans;
    string t=s;
    reverse(t.begin(),t.end());
    s=s+t;
    for (int i=0;i<=n;i++){
        string y="";
        for (int j=i;j<n+i;j++) y+=s[j];
        ans.pb(solve(y,k-1));
    }
    sort(ans.begin(),ans.end());
    cout << ans[0] << endl;
}


Measured memory_bytes: 41064
#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, c, k;
  cin >> n >> c >> k;
  vector<int> t(n);
  rep(i, n) cin >> t[i];

  sort(t.begin(), t.end());
  int ti = 0;
  vector<bool> taken(n, false);

  int num_bus = 0;
  while (ti < n) {
    int last = min(n-1, ti + c - 1);
    ++num_bus;
    if (t[last] <= t[ti] + k) {
      ti = last + 1;
    } else {
      int nti = ti;
      while (t[nti] <= t[ti] + k) ++nti;
      ti = nti;
    }
  }
  cout << num_bus << endl;
  return 0;
}

Measured memory_bytes: 3732
#include <bits/stdc++.h>
//#include <mylib.h>
using namespace std;
//cin.sync_with_stdio(false);

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define FOR_EQ(i,a,b) for(int i = (a); i <= (b); ++i)
#define FOR_RE(i,a,b) for(int i = (a); i > (b); --i)
#define rep(i,n) FOR(i,0,n)
#define rep_eq(i,n) FOR_EQ(i,0,n)
#define rep_re(i,n) FOR_RE(i,n,0)
//1個上から時計周り
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
//上右下左
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> Vector;
typedef vector<Vector>  DVector;
int n;

//次数を得る
int degree(int n){
    int count = 0;
    while(1){
        if(count <= 0)  break;
        count /= 2;
        count++;
    }
    return count;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    cin >> s;
    
    int len = s.size();
    int digit[len];
    
    rep(i, len) digit[i] = s[i] - '0';
    //rep(i, len) cout << digit[i] << endl;
    int lim = len -1;
    
    ll total_sum = 0;
    ll sum;
    ll tmp[10];
    int now;
    //ll tmp;
    
    for(int bit = 0; bit < (1 << lim); ++bit){
        sum = 0;
        now = 0;
        rep(i, 10){
            if(i)   tmp[i] = 0;
            else    tmp[i] = digit[0];
        }
        
        //tmp = digit[0];
        for(int i = 0; i < lim; ++i){
            if(bit & (1 << i)){
                now++;
                tmp[now] = digit[i + 1];
                //sum += tmp;
                //tmp = 0;
            }else{
                tmp[now] = tmp[now] * 10 + digit[i + 1];
            }
            //tmp = tmp * 10 + digit[i + 1];
        }
        
        //rep(i, 10)  cout << tmp[i] << endl;
        
        rep(i, 10)  sum += tmp[i];
        //cout << sum << endl;
        //cout << endl;
        //sum += tmp;
        total_sum += sum;
    }
    cout << total_sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define  rep(i,a,b)for(int i=a;i<b;++i)
#define  rrep(i,a,b)for(int i=a;i>=b;--i)
#define  yesno(flag)if(flag)cout<<"Yes"<<endl; else cout<<"No"<<endl;
using namespace std;
typedef long long ll;
const int INF=1000000000LL;
const ll r197=1000000007;
typedef pair<int,int>P;
typedef pair<int,P>Pa;

ll k=1;
int n;
int main() {
	cin>>n;
	int a[101]={};
	rep(i,1,n+1){
		int k=i;
		rep(j,2,i+1){
			while(1){
				if(k%j>0)break;
				a[j]++;
				k/=j;
			}
		}
	}
//	cout<<a[2]<<" "<<a[3]<<" "<<a[5]<<endl;
	int ans=0;
	rep(i,2,101)if(a[i]>=74)ans++;
	rep(i,2,101){
		rep(j,2,101){
			if(i==j)continue;
			if(a[i]>=24&&a[j]>=2)ans++;
			if(a[i]>=14&&a[j]>=4)ans++;
		}
	}
	rep(i,2,101){
		rep(j,i+1,101){
			rep(k,2,101){
				if(i==k||j==k)continue;
				if(a[i]>=4&&a[j]>=4&&a[k]>=2){
					ans++;
//					cout<<i<<" "<<j<<" "<<k<<endl;
				}
			}
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<string>
#include<vector>

typedef unsigned long long ULL;
typedef long long LL;

using namespace std;

template<class T> void swap(T &a, T &b ){
    T temp;
    temp = a;
    a = b;
    b = temp;   
}

int main(){
    int N;
    int *L;
    int i,j,k;
    ULL count=0;

    cin >> N;
    L = new int[N];
    for(i=0;i<N;i++){
        cin >> L[i];
    }
    sort(L,L+N,std::greater<int>());
   for(i=0;i<N-2;i++){
       for(j=i+1;j<N-1;j++){
           for(k=j+1;k<N;k++){
               if( L[i] < L[j] + L[k]){
                   count++;
               }
               //count++;
           }
       }
   }
    cout << count << endl;
    return 0;
}


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

int main(){
  char dna[]={'A','C','G','T'};
  char c;
  
  cin >> c;
  
  switch(c){
    case 'A':
      cout << "T" << endl;
      break;
    case 'C':
      cout << "G" << endl;
      break;
    case 'G':
      cout << "C" << endl;
      break;
    case 'T':
      cout << "A" << endl;
      break;   
  }
  
  
  return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;

ll dp[45];

int main(){
  int n; cin >> n;
  dp[0]=dp[1]=1;
  for(int i=2;i<=n;i++){
    dp[i]=dp[i-1]+dp[i-2];
  }
  cout << dp[n] << endl;
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iostream>
#define ios   ios_base::sync_with_stdio(false);  cin.tie(0);    cout.tie(0);
typedef   long long int ll;
using namespace std;
const int M=1e9+7;
const int N=1e5+5;
#define fi first
#define se second
#define pb push_back
#define endl "\n"
bool check[N];
int main()
{
    ll n,k;cin>>n>>k;
    ll a[n];
    for(ll i=0;i<n;++i)
    cin>>a[i];
    for(ll i=a[0];i<=k;++i)
    {
        for(ll j=0;j<n && a[j]<=i;++j)
        {
            check[i]|=(!(check[i-a[j]]));
        }
    }
    if(check[k])
    cout<<"First";
    else
    cout<<"Second";
}

Measured memory_bytes: 3736
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

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

  public void run() {

    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      Card[] cards = new Card[n];
      char suit;
      int  value;

      for ( int i=0; i<n; i++ ) {
        suit = (char)br.read(); br.skip(1);
        value = Integer.parseInt(br.readLine());
        cards[i] = new Card(suit, value, i);
      }

      quickSortOfCards(cards, 0, n-1);
      dispCardArray(cards);
    }
    catch(IOException e) {
      System.out.println("IOException!");
    }
  }

  public void quickSortOfCards(Card[] card, int p, int r) {

    if( p < r) {
      int q = partitionOfCards(card, p, r);
      quickSortOfCards(card, p, q-1);
      quickSortOfCards(card, q+1, r);
    }
  }

  public int partitionOfCards(Card[] card, int p, int r) {

    int x = card[r].value;
    int i = p-1;
    Card t;

    for(int j=p; j<r; j++) {
      if(card[j].value <= x) {
        t = card[++i]; card[i] = card[j]; card[j] = t;
      }
    }
    t = card[i+1]; card[i+1] = card[r]; card[r] = t;

    return i+1;
  }

public void dispCardArray(Card[] target) {
  StringBuilder s = new StringBuilder();
  int l=target.length;
  boolean isStable = true;
  String sortState = "Stable";

  s.append(target[0]).append("\n");
  for (int i=1; i<l; i++) {
    s.append(target[i]).append("\n");
    if(target[i-1].value == target[i].value && isStable
      && target[i-1].storedNo > target[i].storedNo) {
      sortState = "Not stable";
      isStable = false;
    }
  }

  System.out.println(sortState);
  System.out.print(s);
  }
}

class Card {
  char suit;
  int value;
  int storedNo;

  public Card( char suit, int value, int storedNo ) {
    this.suit  = suit;
    this.value = value;
    this.storedNo = storedNo;
  }
  public Card( Card card ) {
    this(card.suit, card.value, card.storedNo);
  }

  @Override
  public String toString() {
    return suit + " " + String.valueOf(value);
  }
}


Measured memory_bytes: 58172
l,r=[int(i) for i in input().split()]
if r-l>2019:
    r=l+2018

minnum=1000000000000
for i in range(l,r):
    for j in range(i+1,r+1):
        check=(i*j)%2019
        if check<minnum:
            minnum=check
            
print(minnum)

Measured memory_bytes: 41452
#include <stack>
#include <queue>
#include <cstdio>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
 
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n0,n) for(int i=n0;i<n;i++)
#define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<n;j++)
#define INF (1<<29)
#define test cout << "test" << endl;
#define NNN_MAX 100010
typedef pair<int,int> P;


int main (){
	int HHH,WWW;
	cin >> HHH >> WWW;
	bool map[HHH+2][WWW+2];
	string tempa;
	string sharp="#";
	rep(i,HHH){
		cin >> tempa;
		rep(j,WWW){
			if(tempa[j]==sharp[0]){
				map[i+1][j+1]=true;
			}
			else map[i+1][j+1]=false;
		}
	}
	rep(i,HHH+2){
		map[i][0]=false;
		map[i][WWW+1]=false;
	}
	rep(i,WWW+2){
		map[0][i]=false;
		map[HHH+1][i]=false;
	}
/*
	rep(i,HHH+2){
		rep(j,WWW+2){
			if(map[i][j]){
				cout << "#";
			}
			else cout << ".";
		}
		cout << endl;
	}
*/

	int dh[4]={0,0,1,-1};
	int dw[4]={1,-1,0,0};
	bool check=false;
	Rep(i,1,HHH+1){
		Rep(j,1,WWW+1){
			if(map[i][j]==true){
				check =true;

				rep(k,4){
					//cout << i<<" " <<j <<" " << k << endl;
					if(map[i+dh[k]][j+dw[k]]==true){
						check =false;
					}
				}

				if(check == true){
					cout << "No" << endl;
					return 0;
				}

			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

int main()
{
  string s;
  cin>>s;
  if(s=="Sunny") cout<<"Cloudy";
  else if(s=="Cloudy") cout<<"Rainy";
  else cout<<"Sunny";
  
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000000000000;
const int MOD=1000000007;

int N;
int dp[105][5][5][5];

signed main(){
	cin>>N;
	dp[0][0][0][0]=1;
	REP(m,N){
		REP(i,4){
			REP(j,4){
				REP(k,4){
					REP(l,4){
						if(j==1&&k==2&&l==3)continue;//ACG
						if(j==1&&k==3&&l==2)continue;//AGC
						if(j==2&&k==1&&l==3)continue;//CAG
						if(i==1&&k==2&&l==3)continue;
						if(i==1&&j==2&&l==3)continue;
						(dp[m+1][j][k][l]+=dp[m][i][j][k])%=MOD;
					}
				}
			}
		}
	}
	int ans=0;
	REP(i,4){
		REP(j,4){
			REP(k,4){
				ans=(ans+dp[N][i][j][k])%MOD;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

int main(){
    int n,q,count;
    count = 0;
    string s;
    cin >>n>>q>>s;
    vector<int> vec(s.size()+1);
    for(int i = 0;i<s.size()-1;i++){
        if(s.at(i)=='A'&&s.at(i+1)=='C'){
            count++;
            vec.at(i+1) = count;
        }else{
            vec.at(i+1) = count;
        }
    }
    int l,r;
    for(int i = 0;i<q;i++){
        cin >> l >> r;
        cout << vec.at(r-1)-vec.at(l-1) << endl;
    }
}

Measured memory_bytes: 1408
import java.io.PrintWriter
val pw = PrintWriter(System.out)
fun main(args: Array<String>) {
    func()
    pw.flush()
}
fun println(value: Any) { pw.println(value) }

fun func() {
    val (N, X) = listOfInt()
    val L = listOfInt()
    var d = 0
    var i = 0
    while (d <= X && i < N) {
        d = d + L[i++]
    }
    println("${if (d > X) i else N + 1}")
}

fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }


Measured memory_bytes: 37932
/*
Though leaves are many, the root is one;
Through all the lying days of my youth
I swayed my leaves and flowers in the sun,
Now may I wither into the truth.

- William Butler Yeats
*/
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <vector>
#include <set>
#include <cassert>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <sstream>
#include <functional>
#include <iomanip>
#include <bitset>
//#include <windows.h>  //Should be deleted when using AtCoder&POJ
using namespace std;

#define ll long long
#define pii pair<int,int>
#define qi ios::sync_with_stdio(0)
/**==Info==
*Program:1
*Problem:Distance Sums
*Date:2019-11-18
*Algorithm:Redo greedy and sorting
*Status:Unknown*/

bool debug=false;

#define pli pair<ll,int>

int n;
pli p[100005];
map<ll,ll> mp;

vector<pii> tree;

vector<int> nei[100005];

int dep[100005];
int sz[100005];

void dfs(int x,int fa){
	for(int i=0;i<nei[x].size();i++){
		if(nei[x][i]==fa){
			continue;
		}
		
		dep[nei[x][i]]=dep[x]+1;
		dfs(nei[x][i],x);
	}
}

void validate(){
	for(pii x:tree){
		nei[x.first].push_back(x.second);
		nei[x.second].push_back(x.first);
	}
	
	dfs(p[n-1].second,-1);
	
	ll dick=0;
	for(int i=0;i<n;i++){
		dick+=dep[i];
	}
	
	if(dick!=p[n-1].first){
		cout<<"-1";
		exit(0);
	}
}

int main(int argc,char* argv[]){
	cin>>n;
	for(int i=0;i<n;i++){
		ll x;
		cin>>x;
		mp[x]=i;
		p[i]=make_pair(x,i);
	}
	
	fill(sz,sz+n,1);
	
	sort(p,p+n);
	reverse(p,p+n);
	for(int i=0;i<n-1;i++){
		
		ll ans=p[i].first;
		int x=p[i].second;
		
		ll faShould=p[i].first+sz[x]-(n-sz[x]);
		if(!mp.count(faShould)){
			cout<<"-1";
			return 0;
		}
		
		ll par=mp[faShould];
		sz[par]+=sz[x];
		tree.push_back(make_pair(par,x));
	}
	
	validate();
	
	for(pii x:tree){
		cout<<x.first+1<<" "<<x.second+1<<endl;
	}
	return 0;
}



Measured memory_bytes: 19320
#include <stdio.h>
int main() {
  int N;
  scanf("%d", &N);
  char S[N + 1];
  scanf("%s", S);
  int length = N / 2;
  int ans = 0;
  if (N % 2 != 0) {
    ++ans;
  }
  for (int i = 0; i < length; ++i) {
    if (S[i] != S[i+length]) {
      ++ans;
      break;
    }
  }
  if (ans == 0) {
    printf("Yes");
  } else {
    printf("No");
  }
  return 0;
}

Measured memory_bytes: 128
n = gets.to_i
 
a, b, c = 3.times.map{ gets.split.map(&:to_i).sort }
c.reverse!
 
res = b.inject(0) do |r, bi|
  ai = a.bsearch_index{ |x| x >= bi }
  ci = c.bsearch_index{ |x| x <= bi }
  r + ( ai || n ) * ( ci || n )
end
 
puts res

Measured memory_bytes: 24292
S = input()
K = int(input())
before = ''
count = 0
change_cnt = 0
for c in S:
  if c == before:
    count += 1
  else:
    if count >= 0:
      change_cnt += (count+1)//2
      count = 0
    before = c
if count > 0:
    change_cnt += (count+1)//2
c_cnt = 0
if S[0] == S[-1]:
  for c in S:
    if c == before:
      c_cnt += 1
    else:
      break
all_same = False
plus = False
if count%2 == 0 and c_cnt%2 != 0:
  plus = True
if count+c_cnt >= len(S):
  all_same = True
# print(all_same, plus, count, change_cnt, c_cnt)  
if all_same:
  print((K//2)*len(S) + (K%2)*(len(S)//2))
elif plus:
  print(K*change_cnt + K-1)
else:
  print(K*change_cnt)
  
  


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<ll> h(n);
    vector<ll> t(n, 0);

    rep(i, n) cin >> h[i];
    int a, b;
    rep(i, m) {
        cin >> a >> b;
        a--;
        b--;
        if (h[a] > h[b]) {
            t[b] = 1;
        } else if(h[a]<h[b]){
            t[a] = 1;
        } else{
            t[b] = 1;
            t[a] = 1;
        }

    }

    ll ans = 0;
    rep(i, n) {
        if (!t[i]) ans++;
    }



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

Measured memory_bytes: 4844
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x, std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll ac(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }
void error(const char* str) {
	puts(str);
	exit(0);
}
int main()
{
	int n, p = 0;
	cin >> n;
	vector<int> a(n);
	rep(i, 0, n)cin >> a[i];
	r_sort(all(a));
	if (n == 2) {
		printf("%d\n", a[0]);
		return 0;
	}
	ll ans = 0;
	rep(i, 1, n) {
		ans += a[i / 2];
		//printf("%d\n", i);
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 4044
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(int argc, char* argv[]){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int l = a + b;
    int r = c + d;
    if(l < r) cout << "Right" << endl;
    else if(l == r) cout << "Balanced" << endl;
    else cout << "Left" << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("-Ofast","-funroll-all-loops")
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,res;	map<int,int> mp;
signed main(){
	cin>>n;
	for(int i=2;i*i<=n;i++){
		while(n%i==0)	mp[i]++,n/=i;
	}
	if(n>1)	mp[n]++;
	for(auto i:mp){
		int tmp=i.second;
		for(int j=1;j<=tmp;j++)	res++,tmp-=j;
	}
	cout<<res;
	return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<ll ,ll >
#define vi          vector<ll int>
#define vii         vector<pii>
#define mi          map<ll int,ll int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007 
#define rep(i,a,b)  for(ll int i=a;i<b;i++)
#define take        rep(i,0,n) cin>>v[i];
#define MAXN        2000005

using namespace std;


void solve()
{
	ll n;
	cin>>n;
	vi v(n);
	for(ll i=0;i<n;i++)
	{
		cin>>v[i];
	}
	ll m=1000;
	ll s=0;
	for(ll i=0;i+1<n;i++)
	{
		if(v[i]<v[i+1])
		{
			s=m/v[i];
			m=m%v[i];
			
			m=s*v[i+1]+m;
			s=0;
			
		}
		
	}
	cout<<m<<endl;
	
}
int main()
    {
      
        ll t;
        t=1;
        
    
  //  cin>>t;
        while(t--)
        solve();
    }

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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i,n) cin >> a[i];
    reverse(a.begin(), a.end());
    REP(i,n) {
        cout << a[i];
        if (i != n-1) cout << " ";
        else cout << endl;
    }

    return 0;
}

Measured memory_bytes: 3072
import numpy as np
N = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

if sum(a) < sum(b):
    print(-1)

else:
    a_n = np.array(a)
    b_n = np.array(b)

    d = a_n - b_n
    d_min = d[d < 0]
    d_max = np.sort(d[d > 0])[::-1]
    num = len(d_min)
    if num == 0:
        print(0)
        exit()
    for i in range(len(d_max)+1):

        if np.sum(d_min) + np.sum(d_max[:i]) > 0:
            print(num + i)
            exit()




Measured memory_bytes: 27096
#include<bits/stdc++.h>
using namespace std;
inline int_fast64_t read(){int_fast64_t x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return x*f;}
inline string read_s(){string s="";char c=getchar();while(c<'!'||c>'~'){c=getchar();}while(c>='!'&&c<='~'){s+=c;c=getchar();}return s;}
void Main(){
    int H = read(), W = read(), ans = -1;
    bool A[H][W];
    queue<int> Q1, Q2;
    char c = getchar();
    for (int i = 0; i<H; i++) {
        while (c<'!'||c>'~') c = getchar();
        for (int j = 0; j<W; j++) {
            if (c == '#') {
                A[i][j] = true;
                Q1.push(i*W+j);
            }
            else A[i][j] = false;
            c = getchar();
        }
    }
    int i, j, q;
    while (!Q1.empty()) {
        ans++;
        swap(Q1, Q2);
        while (!Q2.empty()) {
            q = Q2.front();
            i = q/W;
            j = q%W;
            if (i > 0 && !A[i-1][j]) {A[i-1][j] = true; Q1.push((i-1)*W+j);}
            if (j > 0 && !A[i][j-1]) {A[i][j-1] = true; Q1.push(i*W+j-1);}
            if (i < H-1 && !A[i+1][j]) {A[i+1][j] = true; Q1.push((i+1)*W+j);}
            if (j < W-1 && !A[i][j+1]) {A[i][j+1] = true; Q1.push(i*W+j+1);}
            Q2.pop();
        }
    }
    printf("%d\n", ans);
}
int main(){cin.tie(nullptr);ios::sync_with_stdio(false);Main();return 0;}


Measured memory_bytes: 5376
n = int(input())
ws = list(map(int, input().split()))
ans = 99999

for i in range(n):
    former = 0
    latter = 0
    for j in range(0, i):
        former += ws[j]

    for h in range(i, n):
        latter += ws[h]

    if abs(former - latter) < ans:
        ans = abs(former - latter)

print(ans)



Measured memory_bytes: 3060
#include <iostream>

using namespace std;

typedef long long ll;

const int MAX_N = 2e5 + 5;

ll arr [MAX_N];
ll pref [MAX_N];

int main () {
  ios::sync_with_stdio(false);

  int n;
  cin >> n;

  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
    pref[i] = arr[i] + pref[i - 1];
  }

  ll mn = 1e18;
  for (int i = 1; i < n; i++) {
    mn = min(mn, abs(pref[i] - (pref[n] - pref[i])));
  }
  cout << mn << endl;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

#define INF 1<<30
#define LINF 1ll<<60ll
#define MOD 1000000007
#define pb(a) push_back(a)

#define _overload3(_1,_2,_3,_4,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a, i##_len=(b); i<i##_len; ++i)
#define _repis(i,a,b,s) for(int i=a, i##_len(b); i<i##_len; i+=s)
#define REP(...) _overload3(__VA_ARGS__,_repis,_repi,_rep,)(__VA_ARGS__)

#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REPARR(i, v) for(int i = 0;i < sz(v);++i)

#define all(vec) (vec.begin()),(vec.end())
#define sz(x) ((int)(x).size())
#define bit(n) (1ll<<(n))

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

#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"possible":"impossible")<<endl
#define Poss(n) cout<<((n)?"Possible":"Impossible")<<endl
#define POSS(n) cout<<((n)?"POSSIBLE":"IMPOSSIBLE")<<endl



int main(){
    int h,w;
    cin>>h>>w;
    vector<string> grid(h);
    REP(i,h){
        cin>>grid[i];
    }
    bool flag;
    REP(i,h){
        flag=true;
        REP(k,w){
            if(grid[i][k]=='#'){
                flag=false;
                break;
            }
        }
        if(flag){
            //cerr<<i<<endl;
            continue;
        }
        REP(j,w){
            flag=true;
            REP(k,h){
                if(grid[k][j]=='#'){
                    flag=false;
                    break;
                }
            }

            if(!flag){
                cout<<grid[i][j];
            }
        }
        cout<<endl;
    }
    return 0;
}


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

#define int long long
#define DBG 0
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
const double EPS = 1e-10;

signed main() {
	string s; cin >> s;
	int space = s.size() - 1;
	int ans(0);
	for (int bits = 0; bits < (1 << space); bits++) {
		string buf(s.substr(0,1));
		dump(bits);
		for (int i = 0; i < space; i++) {
			if (bits&(1 << i)) {
				ans += stoi(buf);
				buf = ""; buf += s[i + 1];
				dump(ans);
			}
			else buf += s[i + 1];
			dump(buf);
		}
		if (buf != "")ans += stoll(buf);
		dump(ans);
	}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.20f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;

struct UnionFind {
    vector<int> data;
    int sz;
    UnionFind(int sz) : data(sz, -1), sz(sz) { }
    bool unionSet(int x, int y) {
        if ((x = root(x)) == (y = root(y))) return false;
        if (data[x] > data[y]) swap(x, y);
        data[x] += data[y]; data[y] = x;
        sz--;
        return true;
    }
    bool findSet(int x, int y) { return root(x) == root(y); }
    int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
    int size(int x) { return -data[root(x)]; }
    int size() {return sz;}
};

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

	vector<ll> cnt(100005, 0);
	rep (i, n) cnt[a[i]]++;

	ll sum = 0;
	rep (i, n) sum += a[i];

	rep (i, q) {
		sum += (c[i]-b[i]) * cnt[b[i]];
		cnt[c[i]] += cnt[b[i]];
		cnt[b[i]] = 0;
		cout << sum << endl;
	}
	
	return 0;
}


Measured memory_bytes: 6428
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

string A;
map<char, LL>d;

int main(void)
{
	cin >> A;
	LL N = A.size();
	for (char c : A)d[c]++;
	LL par = 0;
	for (auto p : d)
	{
		par += (p.second) * (p.second - 1) / 2;
	}
	LL ans = N * (N - 1) / 2;
	ans -= par;
	ans++;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(){

	int N,M;

	scanf("%d %d",&N,&M);

	int i;

	int pow2=1;

	for(i=0;i<M;i++){
	pow2*=2;
	}

	printf("%d\n",pow2*((1800*M)+(100*N)));

	return 0;
}

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

int main() {
  int X;
  cin >> X;
  
  if (X==2) {
    cout << 2 << endl;
    return 0;
  }
    
  
  while (true){
    for (int i=2; i<X; i++){
      if (X%i == 0) {
        X++;
        break;
      }
      else if (i == X-1) {
        cout << X << endl;
        return 0;
      }
    }
    
  }
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b

signed main(){
	int a; cin>>a;
	a-=2;
	cout<<180*a<<endl;
	return 0;
}

Measured memory_bytes: 3588
n, m, c = map(int, input().split())
b = input().split()
cnt = 0

for i in range(n):
  a = input().split()
  sum = 0
  for ai, bi in zip(a, b):
    sum += int(ai)*int(bi)
  if sum + c > 0:
    cnt += 1

print(cnt)

Measured memory_bytes: 3060