akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <string>
#include <unordered_map>
#include <bitset>

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

const ll mod=1000000007ll;

const ll hmax=100000;
const ll wmax=100000;


// x^n (mod を法として)
ll mod_pow(ll x,ll n,ll mod){
    ll r=1;
    while(n>0){
        if(n&1){
            r=r*x%mod;
        }
        x=x*x%mod;
        n>>=1;
    }
    return r%mod;
}



ll mod_inv_prime(ll n,ll mod){
    return mod_pow(n,mod-2,mod)%mod;
}


ll mod_comb(ll n,ll k,ll mod,ll facttable[],ll factinvtable[]){
//    ll tm=facttable[n]*factinvtable[k];
//    tm%=mod;
//    tm*=factinvtable[n-k];
//    tm%=mod;
    return (((facttable[n]*factinvtable[k])%mod)*factinvtable[n-k])%mod;
}


int main(){

    ll h,w,a,b,ans,tm1,tm2;
    cin>>h>>w>>a>>b;

    ll facttable[h+w+2];
    ll factinvtable[h+w+2];

    //fact_tableを用意
    facttable[0]=1ll;
    ll tm=1;
    for(ll i=1;i<=w+h;i++){
        tm*=i;
        tm%=mod;
        facttable[i]=tm;
    }

    for(ll i=0;i<=w+h;i++){
        tm=facttable[i];
        factinvtable[i]=mod_inv_prime(tm,mod)%mod;
    }

    ans=0;
    for(ll i=1;i<=w-b;i++){
    //for(ll i=1;i<=100;i++){
    //    cout<<facttable[i]<<","<<factinvtable[i]<<endl;
        //cout<<h-a+b+i-2<<","<<h-a-1<<","<<h-a+b+i-2-(h-a-1)<<endl;
        //cout<<facttable[h-a+b+i-1]<<","<<factinvtable[a-1]<<","<<factinvtable[h-a+b+i-1-(a-1)]<<endl;
        //cout<<facttable[h-a+b+i-2]<<","<<factinvtable[h-a-1]<<","<<factinvtable[h-a+b+i-2-(h-a-1)]<<endl;
        //cout<<mod_comb(h-a+b+i-2,h-a-1,mod)<<","<<mod_comb(a+w-b-i-1,a-1,mod)<<endl;
        //cout<<(((facttable[h-a+b+i-1]*factinvtable[a-1])%mod)*factinvtable[h-a+b+i-1-(a-1)])%mod<<endl;
        /*
        tm=1;
        tm*=facttable[h-a+b+i-2];
        tm%=mod;
        tm*=factinvtable[h-a-1];
        tm%=mod;
        tm*=factinvtable[h-a+b+i-2-(h-a-1)];
        tm%=mod;
        tm*=facttable[a+w-b-i-1];
        tm%=mod;
        tm*=factinvtable[a-1];
        tm%=mod;
        tm*=factinvtable[a+w-b-i-1-(a-1)];
        tm%=mod;

        ans+=tm;
        */
        //cout<<facttable[a+w-b-i-1]<<","<<factinvtable[a-1]<<","<<factinvtable[a+w-b-i-1-(a-1)]<<endl;
        //ans+=((((facttable[h-a+b+i-2]*factinvtable[h-a-1])%mod)*factinvtable[h-a+b+i-2-(h-a-1)])%mod)*(((facttable[a+w-b-i-1]*factinvtable[a-1])%mod)*factinvtable[a+w-b-i-1-(a-1)]%mod);
        ans+=mod_comb(h-a+b+i-2,h-a-1,mod,facttable,factinvtable)*mod_comb(a+w-b-i-1,a-1,mod,facttable,factinvtable);
        ans%=mod;
    }
    cout<<ans%mod<<endl;
    return 0;
}



Measured memory_bytes: 3328
#include<iostream>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main(){
    int N,K;
    cin>>N>>K;
    vector<int> V(N);
    rep(i,N){cin>>V[i];}

    int res = 0;
    for(int i=0;i<=K;i++){
            for(int j=0;j<=K-i;j++){
                if(i+j>N)continue;
                int d = K - i - j;
                vector<int> t;
                int score = 0;
                for(int k=0;k<i;k++){
                    score += V[k];
                    t.push_back(V[k]);
                }
                for(int k=N-j;k<N;k++){
                    score+=V[k];
                    t.push_back(V[k]);
                }
                sort(t.begin(),t.end());

                for(int l=0;l<d;l++){
                    if(l>=t.size())break;
                    if(t[l]>0)break;
                    score-=t[l];
                }
                res = max(res,score);
        }
    }
    cout<<res;
}

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

#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0
const ll MOD = 1000000000 + 7;

ll dfs(ll n, vector<ll> &ans) {
  if (ans.at(n) != -1) {
    return ans.at(n);
  }
  if (n == 3) {
    return 1;
  } else if (n < 3) {
    return 0;
  }
  ll count = 0;
  for (long long i = 3; i < n; i++) {
    count += dfs(n - i, ans);
  }
  count++;
  ans.at(n) = count % MOD;
  return count % MOD;
}

int main() {
  ll s;
  cin >> s;
  vector<ll> ans(s + 1, -1);
  cout << dfs(s, ans) << endl;
}


Measured memory_bytes: 3632
import numpy as np
import itertools
def fraction(n):
    r = 1
    for i in range(n):
        r *= (i+1)
    return(r)


n=int(input())
x = [0 for _ in range(n)]
y = [0 for _ in range(n)]
d = [[0 for _ in range(n)] for _ in range(n)]
for i in range(n):
    X,Y = map(int,input().split())
    x[i] = X
    y[i] = Y


for i in range(n):
    for j in range(n):
        d[i][j] = np.sqrt((x[i] - x[j])**2 + (y[i] - y[j])**2)


seq = range(n)

p = list(itertools.permutations(seq))
a = 0.0
for pp in p:
    for i in range(n-1):
        a += d[pp[i]][pp[i+1]]
print(a/fraction(n))

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

#define sc2(a,b)  scanf("%d %d",&a,&b)

int main(){
    int mod=1000000007;
    int n,k,ans;
    sc2(n,k);
    char s[n];
    scanf("%s",s);
    s[k-1]=tolower(s[k-1]);
    printf("%s\n",s);
    return 0;
}


Measured memory_bytes: 3604
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<functional>
#include<math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1001001001;
const double PI = acos(-1);

int main() {
	string s, t;
	cin >> s >> t;
	int cnt = 0;
	rep(i, s.size()) {
		if (s[i] != t[i]) cnt++;
	}
	cout << cnt << endl;

	return 0;
}

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

int main(int argc, char *argv[]){
  vector<char> alpS(27,'A');
  string S,T;
  cin>>S>>T;
  char tmp;
  for(int i=0; i<S.size(); i++){
    tmp=T[i];
    int count=0;
    if(alpS[S[i]-96]!=tmp && alpS[S[i]-96]!='A'){
      cout<<"No"<<endl;
      return 0;
    }
    alpS[S[i]-96]=tmp;
    for(int j=1; j<27; j++){
      if(alpS[j]==tmp) count++;
      if(count>=2){
	cout<<"No"<<endl;
	return 0;
      }
    }
  }
     



  cout<<"Yes"<<endl;
}




 


Measured memory_bytes: 776
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.*;
import java.util.*;

import static java.util.stream.Collectors.*;
import static java.util.Map.Entry.*;

public class Main {

	
	public static void main(String[] args) throws IOException {
		FastReader in = new FastReader(System.in);
		PrintWriter out = new PrintWriter(System.out);
	
		int [] a = new int[4+1];
		for (int i = 0; i < 3; i++) {
			int x = in.nextInt();
			int y = in.nextInt();
			a[x]++;
			a[y]++;
		}
		int u = 0;
		int v = 0;
		int w = 0;
		for (int i = 0; i < a.length; i++) {
			if (a[i] == 1) {
				++u;
			} 
			else if (a[i] == 2) {
				++v;
			} else {
				++w;
			}
		}
		if (u == 2 && v == 2) {
			out.println("YES");
		} else {
			out.println("NO");
		}
		out.flush();
		out.close();

	}

	
	static class FastReader {
		StringTokenizer st;
		BufferedReader br;

		public FastReader(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public FastReader(FileReader fileReader) {
			br = new BufferedReader(fileReader);
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			int[] ret = new int[n];
			for (int i = 0; i < n; i++) {
				ret[i] = nextInt();
			}
			return ret;
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public boolean ready() throws IOException {
			return br.ready();
		}
	}

}

Measured memory_bytes: 22740
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
ll f(ll n)
{
    if(n%4==0)
        return n;
    if(n%4==2)
        return n+1;
    if(n%4==1)
        return 1;
    if(n%4==3)
        return 0;
}
int main()
{
   ll a,b;
   cin>>a>>b;
   if(a==0)
    cout<<f(b);
   else
   {
       ll ans=f(a-1)^f(b);
       cout<<ans;
   }
   return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int a,b,c,k;
	scanf("%d%d%d%d",&a,&b,&c,&k);
	if(k<=a) printf("%d",k);
	else if(k<=a+b) printf("%d",a);
	else printf("%d",a-(k-a-b));
	return 0;
} 

Measured memory_bytes: 1728
def main():
    S = int(input())
    dp = [0]*(S+1)
    dp[0] = 1
    dp[1] = 0
    if S >= 2:
        dp[2] = 0
    for i in range(3,S+1,1):
        for j in range(0,i-2,1):
            dp[i] += dp[j]

    return dp[S]%1000000007

print(main())


Measured memory_bytes: 9136
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int n,m,i,c[100005],a,b,v,k,t[100005];
set<int> g[100005];
vector<int>first_half;
vector<int>second_half;
vector<int>total;
int par[209],group[209];
int arra[150000];
vector<ll>points;
map<char,ll>vis_c;
map<string,ll>nibo;
vector<ll>req;
vector<ll>instru;
vector< pair <ll,ll> > vect;
map<ll,ll>snuke;
int main()
{
  ll i,j,k,l,p,q,r,s,t,u=0,v,w,x,y,z,n,m;
  string str;
  cin>>str;
  if(str=="ABC")
    cout<<"ARC"<<'\n';
   else
   cout<<"ABC"; 	
}

Measured memory_bytes: 8320
n = int(input())
a = list(map(int, input().split()))

def exists_odd_number(a):
    for a_i in a:
        if a_i % 2 != 0:
            return True

    return False


count = 0
while True:
    if exists_odd_number(a):
        break

    count += 1
    for i, a_i in enumerate(a):
        a[i] = a_i // 2

print(count)


Measured memory_bytes: 2940
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = float("inf")


def find_lt(a, x):
    i = bisect_left(a, x)
    if i:
        return i
    return 0


def find_gt(a, x):
    i = bisect_right(a, x)
    if i != len(a):
        return i
    return len(a)


def main():
    N = int(input())
    A = list(sorted(list(map(int, input().split()))))
    B = list(sorted(list(map(int, input().split()))))
    C = list(sorted(list(map(int, input().split()))))

    ans = 0
    for b in B:
        a = find_lt(A, b)
        b = N - find_gt(C, b)
        ans += a * b
    print(ans)


if __name__ == '__main__':
    main()


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

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

  vector<ll> a(n);
  map<ll, ll> cnt;
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
    cnt[i - a[i]]++;
  }
  
  ll ans = 0;
  for (ll i = 0; i < n; i++) {
    ans += cnt[a[i] + i];
    cnt[i - a[i]]--;
  }

  cout << ans << endl;
}


Measured memory_bytes: 27432
use proconio::input;
use proconio::marker::Chars;

fn main() {
    input! {
        a: usize,
        b: usize,
        s: Chars
    };
    let mut is_ok = true;
    for (i, &s_i) in s.iter().enumerate() {
        if i < a {
            if !s_i.is_digit(10) {
                is_ok = false;
                break;
            }
        } else if i == a {
            if s_i != '-' {
                is_ok = false;
                break;
            }
        } else {
            if !s_i.is_digit(10) {
                is_ok = false;
                break;
            }
        }
    }
    println!("{}", if is_ok { "Yes" } else { "No" });
}


Measured memory_bytes: 2156
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

map<int,vector<int> > v1,v2;
map<int,set<int> >s1,s2;
map<pii,int> id;

int n,a,b;
LL x[100111],y[100111],d;
bool vis[100111];int q[100111],sz;

void addx(LL x,LL ly,LL ry)
{
	set<int>&cur=s1[x];
	set<int>::iterator it,it2;
	for(it=cur.lower_bound(ly);it!=cur.end()&&*it<=ry;it=it2)
	{
		it++;it2=it;it--;
		int v=id[mp(x,*it)];vis[v]=1;q[sz++]=v;
		cur.erase(it);
		s2[*it].erase(x);
	}
}
void addy(LL y,LL lx,LL rx)
{
	set<int>&cur=s2[y];
	set<int>::iterator it,it2;
	for(it=cur.lower_bound(lx);it!=cur.end()&&*it<=rx;it=it2)
	{
		it++;it2=it;it--;
		int v=id[mp(*it,y)];vis[v]=1;q[sz++]=v;
		cur.erase(it);
		s1[*it].erase(y);
	}
}
int qx(LL x,LL ly,LL ry){return upper_bound(v1[x].begin(),v1[x].end(),ry)-lower_bound(v1[x].begin(),v1[x].end(),ly);}
int qy(LL y,LL lx,LL rx){return upper_bound(v2[y].begin(),v2[y].end(),rx)-lower_bound(v2[y].begin(),v2[y].end(),lx);}
int main()
{
	get3(n,a,b);
	for(int i=1;i<=n;i++)
	{
		get2(x[i],y[i]);
		int tmp=x[i]+y[i];y[i]=x[i]-y[i];x[i]=tmp;
		v1[x[i]].pb(y[i]);v2[y[i]].pb(x[i]);
		if(i!=a&&i!=b){s1[x[i]].insert(y[i]);s2[y[i]].insert(x[i]);}
		id[mp(x[i],y[i])]=i;
	}
	for(auto &v:v1)sort(v.ss.begin(),v.ss.end());
	for(auto &v:v2)sort(v.ss.begin(),v.ss.end());
	d=max(abs(x[a]-x[b]),abs(y[a]-y[b]));
	q[sz++]=a;q[sz++]=b;vis[a]=vis[b]=1;
	for(int _=0,i;_<sz;_++)
	{
		i=q[_];
		addx(x[i]-d,y[i]-d,y[i]+d);
		addx(x[i]+d,y[i]-d,y[i]+d);
		addy(y[i]-d,x[i]-d,x[i]+d);
		addy(y[i]+d,x[i]-d,x[i]+d);
	}
	LL ans=0;
	
	for(int i=1;i<=n;i++)
	{
		if(!vis[i])continue;
		ans+=qx(x[i]-d,y[i]-d,y[i]+d-1);
		ans+=qy(y[i]+d,x[i]-d,x[i]+d-1);
		ans+=qx(x[i]+d,y[i]-d+1,y[i]+d);
		ans+=qy(y[i]-d,x[i]-d+1,x[i]+d);
	}
	printendl(ans>>1);
	return 0;
}

Measured memory_bytes: 86144
#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>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define n_p(v) next_permutation(v.begin(),v.end())
#define to_ll(b) stoll(b)
#define MOD 1000000007
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int n,m; cin>>n>>m;
	vvi vec(n,vi(n));
	vvi vec2(m,vi(m));
	rep(i,0,n){
		string s;
		cin>>s;
		rep(j,0,n){
			vec[i][j]=s[j];
		}
	}
	rep(i,0,m){
		string s;
		cin>>s;
		rep(j,0,m){
			vec2[i][j]=s[j];
		}
	}
	rep(i,0,n-m+1){
		rep(j,0,n-m+1){
			bool ok=true;
			rep(k,0,m){
				rep(l,0,m){
					if(vec[i+k][j+l]!=vec2[k][l]) ok=false;
				}
			}
			if(ok){
				cout<<"Yes";
				return 0;
			}
		}
	}	
	cout<<"No";		
	return 0;
}

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

using namespace std;

int n, k;
char s[100005];

bool check(int v) {
	int cnt = 0;
	for (int i = 0; i < v - 1; i++) {
		if (s[i] == '0' && (i == 0 || s[i - 1] == '1')) cnt++;
	}
	
	for (int i = v - 1; i < n; i++) {
		if (s[i] == '0' && (i == 0 || s[i - 1] == '1')) cnt++;
		
		if (cnt <= k) return 1;
		
		if (s[i - v + 1] == '0' && s[i - v + 2] == '1') cnt--;
	}
	
	return 0;
}

int main() {
	scanf("%d%d", &n, &k);
	scanf("%s", s);
	
	int lb = 0;
	int ub = n + 1;
	
	while (ub - lb > 1) {
		int mid = (lb + ub) / 2;
		
		if (check(mid)) lb = mid;
		else ub = mid;
	}
	
	printf("%d\n", lb);
}


Measured memory_bytes: 384
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#define lld long long int
#define DBG1(vari1) cerr<<#vari1<<" = "<<(vari1)<<endl;
#define DBG2(vari1,vari2) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<endl;
#define DBG3(vari1,vari2,vari3) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<" "<<#vari3<<" = "<<(vari3)<<endl;
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	// freopen("input.txt", "r", stdin);  
	int n;
	cin >> n;
	int arr[n];
	for(int i=0;i<n;i++)
		cin >> arr[i];
	int sum=accumulate(arr,arr+n,0);
	int m;
	cin >> m;
	for(int i=0;i<m;i++)
	{
		int a,b;
		cin >> a >> b;
		cout << sum - arr[a-1] + b<<"\n";
	}
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
int main(){
    int n;
    scanf("%d",&n);

    int k;
    scanf("%d",&k);

    int a,b;
    int x = 0,y = 0,ans=0;
    for(int i = 0;i < k; i++){
        scanf("%d%d",&a,&b);
        x = min(a,n - a+1);
        y = min(b,n - b+1);
        ans = min(x,y);
        ans %= 3;
        if(ans == 0)ans = 3;
        printf("%d\n",ans);
    }
    return 0;
}

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

/* short names and const
using ll = long long; using vi = vector<int>; using vll = vector<ll>;
using vvi = vector<vi>; using vvll = vector<vll>;
const int MOD = 1e9 + 7;
const int INF = numeric_limits<int>::max();
const ll INF_MAX = numeric_limits<ll>::max();
*/

/* Boost!
#include <boost/algorithm/string/classification.hpp> // is_any_of
#include <boost/algorithm/string/split.hpp>
using boost::algorithm::split; // split(result, s, boost::is_any_of(","));
#include <boost/algorithm/string/join.hpp>
using boost::algorithm::join; // string s = join(arr, "");
#include <boost/algorithm/string/replace.hpp>
using boost::algorithm::replace_all; // replace_all(s, "AtCoder", "A");
#include <boost/range/algorithm.hpp> // boost::sort(arr)
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;
*/

/* print(arr)
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
}
*/

/* fast cin and precise cout
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  getline(cin, s);
  cout << fixed << setprecision(15);
*/

/* sum function
int sum(vector<int> &arr) {
  int res = accumulate(arr.begin(), arr.end(), 0);
  return res;
}
*/

/* if in function
template <class T>
bool contain(vector<T> &vec, T find_it) {
  auto it = find(vec.begin(), vec.end(), find_it);
  return it != vec.end();
}

bool contain(string &str, char c) {
  return str.find(c) != string::npos;
}
*/

using ll = long long; using vi = vector<int>; using vll = vector<ll>;
using vvi = vector<vi>; using vvll = vector<vll>;
const int MOD = 1e9 + 7;
const int INF = numeric_limits<int>::max();
const ll INF_MAX = numeric_limits<ll>::max();

int main() {
  vi arr(3);
  for (int i = 0; i < 3; ++i) cin >> arr[i];
  sort(arr.begin(), arr.end());
  cout << arr[2] * 10 + arr[0] + arr[1] << endl;
}


Measured memory_bytes: 256
x, n = map(int, input().split())
if n != 0:
    p = [int(x) for x in input().split()]
else:
    print(x)
    exit()
    
if x not in p:
    print(x)
    exit()
    
xl = x-1
xr = x+1
while 1:
    if xl not in p:
        print(xl)
        exit()
    if xr not in p:
        print(xr)
        exit()
    xl -= 1
    xr += 1


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

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pf printf
#define sc scanf

#define sf(n) scanf("%d",&n)
#define sff(n1,n2) scanf("%d %d",&n1,&n2)
#define sfff(n1,n2,n3) scanf("%d %d %d",&n1,&n2,&n3)
#define sl(n) scanf("%lld",&n)
#define sll(n1,n2) scanf("%lld %lld",&n1,&n2)
#define slll(n1,n2,n3) scanf("%lld %lld %lld",&n1,&n2,&n3)

#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,n) for(i=1;i<=n;i++)
#define reps(i,a,n) for(i=a;i<=n;i++)

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define sz(x) x.size()

#define mem(ara,n) memset(ara,n,sizeof(ara))
#define memb(ara) memset(ara,false,sizeof(ara))

#define pi pair<int,int>
#define pii pair<pair<int,int>,pair<int,int> >

#define nl puts("")
#define line puts("-------");
#define dbb(x) cout<<#x<<" : "<<x<<"\n";

void __print(int x) {cerr << x;} void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;} void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V> void __print(const pair<T, V> &x)
{cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T> void __print(const queue<T> &x)
{queue<T>temp=x;cerr<<"\n-----\n";while(!temp.empty())
{cerr << temp.front() << endl;temp.pop();}cerr<<"-----\n";}
template<typename T> void __print(const stack<T> &x)
{stack<T>temp=x;cerr<<"\n-----\n";while(!temp.empty())
{cerr << temp.top() << endl;temp.pop();}cerr<<"-----\n";}
template<typename T> void __print(const T &x)
{int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V> void _print(T t, V... v)
{__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifndef ONLINE_JUDGE
    #define db(x...) cerr << "[" << #x << "] = [", _print(x)
#endif
using ll = long long;
const int N = 100005;
const int MOD = 1000000007;

int main()
{
    #ifndef ONLINE_JUDGE
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt","w",stdout);
    #endif
    int i,n,k,p;
    sff(n,k);
    vector<int>vec;
    rep0(i,n)
    {
        sf(p);
        vec.pb(p);
    }
    sort(all(vec));
    int sum=0;
    rep0(i,k)
        sum+=vec[i];
    cout<<sum;
}


Measured memory_bytes: 3596
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <vector>
#if __cplusplus >= 201103L
#include <random>
#include <unordered_map>
#include <unordered_set>
#endif

#define ll int
#define FOR(i,a) for(ll i=0;i<(ll)a.size();i++)
#define pb push_back
#define ld long double
#define mp make_pair
#define F first
#define S second
#define pii pair<ll,ll> 

using namespace :: std;

const ll maxn=310;
const ll mod=1e9+7;

vector<pii> que[maxn];
long long dp[maxn][maxn][maxn];

void ok(ll a){
	for(auto e:que[a]){
		ll l=e.F;
		ll x=e.S;
		if(x==1){
			for(ll j=l;j<a;j++){
				for(ll k=0;k<j;k++){
					dp[a][j][k]=0;
				}
			}	
		}
		if(x==2){
			for(ll j=1;j<a;j++){
				for(ll k=l;k<j;k++){
					dp[a][j][k]=0;
				}
			}	
			for(ll j=1;j<l;j++){
				for(ll k=0;k<j;k++){
					dp[a][j][k]=0;
				}
			}	
		}
		if(x==3){
			for(ll j=1;j<a;j++){
				for(ll k=0;k<min(j,l);k++){
					dp[a][j][k]=0;
				}
			}	
		}
	}
	for(ll j=1;j<a;j++){
		for(ll k=0;k<j;k++){
			dp[a][j][k]%=mod;
		}
	}
}
int main(){
	ll n,m;
	cin>>n>>m;
	for(ll i=0;i<m;i++){
		ll l,r,x;
		cin>>l>>r>>x;
		l+=2;
		r+=2;
		que[r].pb(mp(l,x));
	}
	dp[2][1][0]=1;
	for(ll i=2;i<=n+1;i++){
		for(ll j=1;j<i;j++){
			for(ll k=0;k<j;k++){
				dp[i+1][j][k]+=dp[i][j][k];
				dp[i+1][i][k]+=dp[i][j][k];
				dp[i+1][i][j]+=dp[i][j][k];
			}
		}
		ok(i+1);
	}
	long long ans=0;
	for(ll i=0;i<maxn;i++){
		for(ll j=0;j<maxn;j++){
			ans+=dp[n+2][i][j];
		}
	}
	ans%=mod;
	cout<<ans;
}



Measured memory_bytes: 227584
#include <bits/stdc++.h>
#define int long long int
#define endl '\n'
using namespace std;

void solve(){
   int n,ans = 0; cin >> n;

   for(int i = 1; i <= n ; ++i){
       if(i%3!=0 && i%5!=0) ans += i;
   }
   cout << ans;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < n; ++i)
#define repe(i, n) for(int i=0; i <= n; ++i)
#define repr(i, n) for(int i=n-1; i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)

using namespace std;
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;}
template <class T> using V=vector<T>;
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }

int main() {
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i,n) {
        cin >> p[i];
    }
    int res = 0;
    for(int i=1; i<n-1; ++i) {
        if (p[i] != max(p[i], max(p[i+1], p[i-1])) && p[i] != min(p[i], min(p[i+1], p[i-1]))) {
            res++;
        }
    }
    cout << res << "\n";
}


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

int main() {
  int a, b, c;
  bool IsPoor = false;
  cin >> a >> b >> c;
  if (a == b && a != c) {
    IsPoor = true;
  } else if (a == c && a != b) {
    IsPoor = true;
  } else if (b == c && b != a) {
    IsPoor = true;
  }
  if (IsPoor)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() // single long
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map(String::toInt) // list of ints
private fun readLongs() = readStrings().map(String::toLong) // list of longs

fun main(args: Array<String>) {
    val (n, m) = readInts()
    val a = readInts()
    val b = a.sortedDescending().take(m)
    //println(b.last())
    println(if (b.last() * 4 * m >= a.sum()) "Yes" else "No")
}


Measured memory_bytes: 36140
#include <iostream>
using namespace std;
 
int main(){
    int N, i, l, d[100];
    int a = 0;
    int b = 0;
 
    cin >> N;
    for(i = 0; i < N; i++) {
        cin >> d[i];
    }
    for(i = 1; i < N; i++){
        a = 0;
        for(l = 0; l < i; l++){
            if(d[i] == d[l]){
                a += 1;
            }
        }
        if(a == 0){
            b += 1;
        }
    }
 
    cout << b+1 <<endl;
 
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a[105];
int main(){
	int t,n=0;
	cin>>t;
	for(int i=1;i<=t;i++){
		cin>>a[i];
	}
	for(int i=1;i<=t;i++){
		if(a[i]%2==0 &&a[i]%3!=0 && a[i]%5!=0){
			cout<<"DENIED"<<endl;
			return 0;
		}	
	}
	cout<<"APPROVED"<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/* {{{ */
/*-------------------------------*/
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (b) - 1; i >= (a); i--)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define rep(i, n) for(int i = 0; i < (n); i++)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)

#define all(i) (i).begin(),(i).end()
#define rall(i) (i).begin(),(i).end(),greater<int>()
#define MAX_INT 2147483647
#define PB push_back
#define pb push_back
#define mp make_pair
#define FI first
#define SE second

//#define int long long

inline int in(){int x;std::cin>>x;return x;}
struct FAST {FAST(){cin.tie(0);ios::sync_with_stdio(false);}} Fast;
template <class X> void print(X hoge){ cout << hoge<< '\n'; }

typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef vector<long long> llv;
typedef vector<pint> vpint;
/*-------------------------------*/
/* }}} */ 

signed main(void)
{
  int h, w;

  cin >> h >> w;

  rep(i, h){
    string s;
    int p[110] = {};
    
    memset(p, -1, sizeof(p));

    cin >> s;
    
    rep(j, w) {
      if (s[j] == 'c'){
        int a = 0;
        for (int k = j; k < w; k++){
          p[k] = a;
          a++;
        }
      }
    }
   
    rep(j, w) {
      if (j == w - 1) cout << p[j] << endl;
      else cout << p[j] << " ";
    }
  }

  return 0;
}

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

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var ABCXY = Io.ReadSplit<int>();
            var A = ABCXY[0];
            var B = ABCXY[1];
            var C = ABCXY[2];
            var X = ABCXY[3];
            var Y = ABCXY[4];

            var output = 5000d * 2 * 100000;
            for (var abi = 0; abi <= 2 * Math.Max(X, Y); abi += 2)
            {
                var ai = Math.Max(X - abi * 0.5, 0);
                var bi = Math.Max(Y - abi * 0.5, 0);

                var money = A * ai + B * bi + C * abi;
                output = Math.Min(money, output);
            }

            Console.WriteLine(output);
        }
    }

    class Io
    {
        public static string Read()
        {
            return Console.ReadLine();
        }

        public static IEnumerable<string> ReadRepeat(int count)
        {
            return Enumerable.Range(0, count).Select(_ => Read());
        }

        public static T Read<T>()
        {
            return (T)Convert.ChangeType(Read(), typeof(T));
        }

        public static IEnumerable<T> ReadRepeat<T>(int count)
        {
            return Enumerable.Range(0, count).Select(_ => Read<T>());
        }

        public static string[] ReadSplit(char devide = ' ')
        {
            return Read().Split(devide);
        }

        public static T[] ReadSplit<T>(char devide = ' ')
        {
            return ReadSplit(devide)
                .Select(s => (T)Convert.ChangeType(s, typeof(T)))
                .ToArray();
        }

        public static IEnumerable<T[]> ReadSplitRepeat<T>(int count, char devide = ' ')
        {
            return Enumerable.Range(0, count).Select(_ => ReadSplit<T>(devide));
        }
    }
}


Measured memory_bytes: 13268
# source wikipedia negabinary 
def main():
	n = int(input())
	ans = ""
	while n!=0:
		rem = n%(-2)
		n= n//(-2)
		if rem<0:
			rem = rem+2
			n = n+1
		ans = ans + chr(rem + ord('0'))
	if ans =="":
		print(0)
		exit()
	print(ans[::-1])
if __name__ =="__main__":
	main()

Measured memory_bytes: 61836
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;

int n;
char s[40];

vector<pair<string,string> > v1,v2;

char t1[20],t2[20];
int pos;

void f1(int num){
	if(num==n){
		t1[pos]=0;	t2[num-pos]=0;
		v1.push_back(make_pair(t1,t2));	return;
	}

	t2[num-pos]=s[num];	f1(num+1);

	pos++;
	t1[pos-1]=s[num];	f1(num+1);
	pos--;
}

void f2(int num){
	if(num==n){
		t1[pos]=0;	t2[num-pos]=0;
		v2.push_back(make_pair(t1,t2));	return;
	}

	t2[num-pos]=s[num+n];	f2(num+1);

	pos++;
	t1[pos-1]=s[num+n];	f2(num+1);
	pos--;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>s;
	int i,j;
	pos=0;	f1(0);
	pos=0;	f2(0);

	for(i=0;i<v1.size();i++){
		reverse(v1[i].second.begin(), v1[i].second.end());
		reverse(v2[i].first.begin(), v2[i].first.end());
	}

	sort(v1.begin(), v1.end());
	sort(v2.begin(), v2.end());

	i=0,j=0;

	ll ans=0;

	for(i=0;i<v1.size();i++){
		vector<pair<string,string> >::iterator it1,it2;
		it1=upper_bound(v1.begin(), v1.end(), v2[i]);
		it2=lower_bound(v1.begin(), v1.end(), v2[i]);
		ans+=distance(it2,it1);
	}

	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 57580
n = int(input())
a, b = map(int, input().split())
p = list(map(int, input().split()))
easy = []
norm = []
hard = []
for pi in p:
    if pi <= a:
        easy.append(pi)
    elif a < pi <= b:
        norm.append(pi)
    else:
        hard.append(pi)

ans = min(len(easy), len(norm))
ans = min(ans, len(hard))
print(ans)

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

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

using namespace std;

using ll = long long int;

const int MOD_NUM = 1e9 + 7;

int main() {
    // Input
    int N;
    vector<int> a;

    cin >> N;
    a = vector<int>(N);
    rep(i, N) cin >> a[i];

    // Process
    vector<int> ans(N);

    int x = a[0];
    rep(i, N - 1) x ^= a[i + 1];

    rep(i, N) ans[i] = x ^ a[i];

    // Output
    rep(i, N) {
        cout << ans[i];

        if (i < N - 1)
            cout << ' ';
        else
            cout << endl;
    }

    return 0;
}


Measured memory_bytes: 4732
N = int(input())
ABC = [list(map(int, input().split())) for _ in range(N)] + [[0, 0, 0]]

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

for n in range(1, N + 1):
	l = n - 1
	dp[n][0] = max([dp[l][1], dp[l][2]]) + ABC[n][0]
	dp[n][1] = max([dp[l][0], dp[l][2]]) + ABC[n][1]
	dp[n][2] = max([dp[l][0], dp[l][1]]) + ABC[n][2]
	#print(dp)
print(max(dp[-1]))


Measured memory_bytes: 47844
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
using ll = long long;
int MOD = 1e9 + 7;
using namespace std;
ll GCD(ll x, ll y)
{
    if (y == 0)
    {
        return x;
    }
    else
    {
        return GCD(y, x % y);
    }
}
ll LCM(ll x, ll y)
{
    return x / GCD(x, y) * y;
}
struct UnionFind
{
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N)
    { //最初は全てが根であるとして初期化
        for (int i = 0; i < N; i++)
            par[i] = i;
    }

    int root(int x)
    { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y)
    {                     // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry)
            return;   //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y)
    { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
//使い方　インスタンス化(頂点数)　uniteつなぐ(双方向注意) same判定
int main()
{
    int n;
    cin >> n;
    vector<int> vec(n);
    for (int i = 0; i < n;i++){
        int x;
        cin>> x;
        x--;
        vec[i] = x;
    }
    int c = 0;
    for (int i = 0; i < n;i++){
      //  cout << vec[vec[i]] << endl;
        if(vec[vec[i]]==i){
            c++;
        }
    }
    cout << c / 2 << endl;
}


Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
#define ref(i,x,y)for(int i=x;i<=y;++i)
string s;
int n,ans,a[1<<26];
int main()
{
	cin>>s;
	n=s.size();
	s=" "+s;
	int t=0;
	a[0]=1;
	ans=2e9;
	ref(i,1,n)
	{
		t=t^(1<<(s[i]-'a'));
		int tmp=2e9;
		if(a[t])tmp=a[t];
		ref(j,0,25)
		{
			int tt=t^(1<<j);
			if(a[tt])tmp=min(tmp,a[tt]);
		}
		if(i==n)ans=tmp+1;
		if(!a[t])a[t]=tmp+1;
		else a[t]=min(a[t],tmp+1);
	}
	cout<<ans-1<<endl;
}

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

int main(){
  int n;
  cin >> n;
  vector<int>h(n+1);
  for(int i=0; i<n; i++)cin >> h[i];
  h[n]=0;
  int cnt=0;
  for(int i=1; i<=100; i++){
    for(int j=1; j<=n; j++)if(h[j]<i && h[j-1]>=i)cnt++;
  }
  cout << cnt;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>

int main(int argc, char* argv[]) {
  int A, B;
  std::cin >> A >> B;
  if (B % A == 0) {
    std::cout << A + B << std::endl;
  } else {
    std::cout << B - A << std::endl;
  }
  return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    abc064c()
}

fun abc064c() {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(" ").map { it.toInt() }

    val under3200 = aList.filter { it < 3200 }.groupBy { it / 400 }.size
    val above3200 = aList.count { it >= 3200 }

    val min = Math.max(under3200, 1)
    val max = under3200 + above3200

    println("$min $max")
}


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

const long double EPS = 1e-10;
const long long INF = 1e18;
const int MOD = (int)1e9 + 7;
const long double PI = acos(-1.0L);

int main() {
  int x;
  cin >> x;
  if (x >= 30) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>

#define int long long
#define repi(i,start,end) for(int (i)=(start),TemPNuM=(int)(end);(i)<TemPNuM;++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x,v) for(auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fsort(v,lambda) sort(all((v)),(lambda))
#define vin(v) rep(i,(v).size())cin >> (v)[i];
#define vpin(v) rep(i,(v).size())cin>>v[i].first>>v[i].second

using namespace std;
using ll =  long long;
using pint =  pair<int,int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vpint = vector<pint>;

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; }
template<class T>void put_double(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<endl;}
template<class T>void print(T a){cout << a << endl;}
//lambda: [](int x, int y){return x<y;}

signed main(void) {
    int n, m; cin >> n >> m;
    vpint ab(n); vpin(ab);
    sort(all(ab), [](pint a, pint b) { 
            if(a.first != b.first){
            return a.first < b.first; } 
            return a.second > b.second;});
    int pos = 0, ans = 0;
    while(m > 0) {
        if(ab[pos].second == 0) {
            pos++;
            continue;
        }
        ans += ab[pos].first;
        ab[pos].second--;
        m--;
    }
    print(ans);

    return 0;
}


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

const int MOD = 1000000007;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to))
#define sort(a) sort(a.begin(), a.end())
#define reverse(s) reverse(s.begin(), s.end())
#define p(s) cout << (s) << endl

typedef long long ll;
using namespace std;

template<class T>
void load(vector<T> &v, int n) {
  for (int i = 0; i < n; ++i) {
    T t;
    cin >> t;
    v.push_back(t);
  }
}

template<class T>
T max(vector<T> &v) {
  return *max_element(v.begin(), v.end());
}

template<class T>
T min(vector<T> &v) {
  return *min_element(v.begin(), v.end());
}

void py(bool isUpper = false) {
  if (isUpper) {
    p("YES");
  } else {
    p("Yes");
  }
}

void pn(bool isUpper = false) {
  if (isUpper) {
    p("NO");
  } else {
    p("No");
  }
}

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> x;
  load(x, n);

  int distance = 0;
  for (int i = 0; i < n; ++i) {
    distance += 2 * min(x[i], abs(k - x[i]));
  }
  p(distance);
}

Measured memory_bytes: 256
d,n = map(int,input().split())
if d == 0:
    if n == 100:
        print(101)
    else:
        print(n)
elif d == 1:
    if n == 100:
        print(10100)
    else:
        print(n*100)
elif d == 2:
    if n == 100:
        print(1010000)
    else:
        print(n*10000)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <limits.h>
 
#define YesNo(b) ((b) ? "Yes" : "No")
#define YESNO(b) ((b) ? "YES" : "NO")

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;



int main()
{
    int N, M;
    cin >> N >> M;
    vi A(N);
    for (int i = 0; i < N; i++)
        cin >> A[i];
    
    int sumvote = accumulate(begin(A), end(A), 0);
    sort(begin(A), end(A), greater<int>());

    bool ans = A[M-1] * 4 * M >= sumvote;

    cout << YesNo(ans) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e9
#define INFLL 1ull<<60u
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

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

void solve() {
    ll N,X,M; cin >> N >> X >> M;
    vector<pair<ll,ll>> vm(M+1,make_pair(-1,1));
    vector<ll> memo(M+1,-1);
    vm[X] = make_pair(X,1);
    ll now = X;
    ll sum = X;
    memo[1] = X;
    memo[0] = 0;
    if (X == 0) {
        cout << 0 << endl;
        return;
    }
    // 回目
    FOR(cnt,2,min(M+1,N+1)) {
        now = (now*now) % M;
        if (now < 0) now+=M;

        if (now == 0) {
            cout << sum << endl;
            return;
        } else if (vm[now].first == -1) {
            sum += now;
            vm[now] = make_pair(sum,cnt);
            memo[cnt] = sum;
        } else {
            // cycle is cnt+1
            ll cycle_size = cnt - vm[now].second;
            ll cycle_point = memo[cnt-1] - memo[vm[now].second-1];
            // 残りのサイクル可能数
            ll can_cycle = (N-cnt+1) / cycle_size;
            // サイクル可能数だけ追加
            sum += cycle_point * can_cycle;
            // 余り
            ll surplus = (N-cnt+1) % cycle_size;
            // 余剰分の計算
            if (surplus > 0 )sum += now;
            REP(i,surplus-1) {
                now = (now*now) %M;
                sum += now;
            }
            cout << sum << endl;
            return;
        }
    }
    cout << sum << endl;
}

int main() {
    solve();
    return 0;
}

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

using namespace std;

long long int K, A, B;

int main(void) {
	cin >> K >> A >> B;

	long long int ans = 0;
	long long int count = K;
	long long int num;

	if ((A +2< B)) {
		num = (K - A + 1) / 2;
		num = min(K / 2, num);
		ans = (B - A)*num + A;
		if (((K - A + 1) % 2) == 1) { ans++; }
	}
	

	ans = max(ans, K + 1);

	cout << ans << endl;
	//system("pause");
	return 0;
}

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

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

	ll A, B, C;
	cin >> A >> B >> C;
	A++;
	ll ans = A;
	if (A >= B+2 && C > B+2) ans = max(ans, C + (A-(B+2))/2*(C-B) + (A-(B+2))%2);
	cout << ans << "\n";
}

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

int main(){
  int n, q; cin >> n >> q;
  queue<pair<string, int>> a;
  for(int i = 0; i < n; i++){
    string name; cin >> name;
    int time; cin >> time;
    a.push(make_pair(name, time));
  }
  int temp = 0;
  while(!a.empty()){
    pair<string, int> proc = a.front(); a.pop();
    if(proc.second <= q){
      temp += proc.second;
      cout << proc.first << ' ' << temp << endl;
    }
    else{
      temp += q;
      a.push(make_pair(proc.first, proc.second - q));
    }
  }
}



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

#define sc1(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define sc3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define pr1(a) printf("%d\n",a)
#define pr2(a,b) printf("%d %d\n",a,b)
#define pr3(a,b,c) printf("%d %d %d\n",a,b,c)
#define loop(i,a,b) for(int i=a;i<b;i+=1)
#define ll long long int
#define ld long double
#define lvec vector<long long int> v
#define vec vector<int> v
#define ite1 vector<int>:: iterator it1
#define ite2 vector<int>:: iterator it2
#define ite3 vector<int>:: iterator it3
#define mp make_pair
#define pb push_back
#define pf push_front
#define pff pop_front
#define pbb pop_back
#define ft first
#define sd second

int main()
{
    int t=1;

    //cin>>t;           // comment this line when number of testcases = 1

    while(t--)
    {
        int n,ans;
        cin>>n;
        int a[n];
        int b[n];
        int c[n];
        loop(i,0,n){cin>>a[i]>>b[i]>>c[i];}
        int dp[n][3];
        dp[0][0] = a[0];
        dp[0][1] = b[0];
        dp[0][2] = c[0];

        loop(i,1,n)
        {
            dp[i][0] = max(dp[i-1][1]+a[i],dp[i-1][2]+a[i]);
            dp[i][1] = max(dp[i-1][0]+b[i],dp[i-1][2]+b[i]);
            dp[i][2] = max(dp[i-1][0]+c[i],dp[i-1][1]+c[i]);
        }

        ans = max(dp[n-1][0],dp[n-1][1]);
        ans = max(ans,dp[n-1][2]);
        cout<<ans;
    }
}


Measured memory_bytes: 2560
# S = input()
# print('Heisei' if S <= '2019/04/30' else 'TBD')

# n,m,c=map(int,input().split())
# b=list(map(int,input().split()))
# e = [[int(i) for i in input().split()] for i in range(n)]

# array=[None]*3
# print(array)

# print('{0:.10f}'.format(11))

n=int(input())
b=[]
#b=list(map(str,input().split()))
for i in range(0,n):
	str=input()
	b.append(str)

flag=0

for i in range(1,n):
	str1=b[i-1]
	str2=b[i]

	if str1[-1:]!=str2[:1]:
		flag=1
	else:
		for k in range(0,i):
			# print("b[k] is "+b[k])
			# print("str2 is "+str2)
			# print(b[k]==str2)
			if b[k]==str2:
				flag=1
			#print("flag is ",flag)


if flag==1:
	print("No")
else:
	print("Yes")

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

int main(){
  int i,j,cnt=0;
  int n;
  string s;
  cin>>n;
  cin>>s;
  int r=0,b=0;
  for(i=0;i<n;i++){
    if(s[i]=='R')r++;
    else b++;
  }
  if(r>b)cout<<"Yes";
  else cout<<"No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// 2의 제곱수 판정
#define POW2(X) (X) == ((X)&(-(X)))

// 기본설정
typedef long long ll;
using namespace std;
int dirx[4] = {1, 0, -1, 0};
int diry[4] = {0, 1, 0, -1};

// 전역변수

int main(void) {
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);

	string s1, s2;
	int cnt = 0;
	cin >> s1 >> s2;
	for(int i = 0; i < s1.size(); i++) {
		if(s1[i] != s2[i]) cnt++;
	}
	cout<<cnt;

	return 0;
}

Measured memory_bytes: 3832
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long n,r=0,g=0,b=0;
    string s;
    cin >> n;
    cin >>s;
    for(int i=0;i<n;i++){
        if(s[i]=='R') r++;
        else if(s[i]=='G') g++;
        else b++;
    }
    long long ans=r*g*b;
    for(int i=0;i<n;i++){
        for(int j=1;i+j*2<n;j++){
            if(s[i]!=s[i+j]&&s[i]!=s[i+j*2]&&s[i+j]!=s[i+j*2]){
                ans--;
            }
        }
    }
    cout << ans;
}


Measured memory_bytes: 3652