akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include <cstring>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P; 
const int N = 200005;
//////////////////////////////

Int n, c;
Int dp[N];
Int h[N];

Int calc(P f, Int x)
{
	return f.first * x + f.second;
}

struct CHTrick {
	vector<Int> to;
	vector<P> f;
	CHTrick(){}

	void add_line(Int a, Int b) {
		P new_f = P(a, b);
		if (f.empty()) {
			f.push_back(new_f);
			return;
		}
		if (calc(new_f, INF) >= calc(f.back(), INF)) return;
		if (calc(new_f, -INF) <= calc(f.front(), -INF)) {
			f.clear();
			to.clear();
			f.push_back(new_f);
			return;
		}

		while (!to.empty()) {
			int last1 = to.back() + 1;
			if (calc(new_f, last1) <= calc(f.back(), last1)) {
				f.pop_back();
				to.pop_back();
			}
			else break;
		}
		int bottom;
		if (to.empty()) bottom = -INF;
		else bottom = to.back() + 1;
		int top = INF;
		while (top - bottom > 1) {
			int mid = (top + bottom) / 2;
			if (calc(new_f, mid) <= calc(f.back(), mid)) top = mid;
			else bottom = mid;
		}
		to.push_back(bottom);
		f.push_back(new_f);
	}

	Int get_min(int x) {
		Int ind = lower_bound(to.begin(), to.end(), x) - to.begin();
		return calc(f[ind], x);
	}
};

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

	CHTrick ch;
	dp[0] = 0;
	ch.add_line(-2 * h[0], dp[0] + h[0] * h[0]);
	for (int i = 1; i < n; i++) {
		dp[i] = ch.get_min(h[i]) + h[i] * h[i] + c;
		ch.add_line(-2 * h[i], dp[i] + h[i] * h[i]);
	}
	cout << dp[n - 1] << endl;
	return 0;
}




Measured memory_bytes: 11120
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

ll A,B,C;

void run() {
	scanf("%lld%lld%lld",&A,&B,&C);
	if(A%2==1||B%2==1||C%2==1) { printf("0\n"); return; }
	if(A==B&&B==C) { printf("-1\n"); return; }
	int ret=0;
	while(A%2==0&&B%2==0&&C%2==0) {
		++ret;
		ll na=B/2+C/2,nb=A/2+C/2,nc=A/2+B/2;
		A=na,B=nb,C=nc;
	}
	printf("%d\n",ret);
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <b; i++)
typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pi;
#define trace(x) cout<<#x<<"="<<x<<"\n";
#define sz(x) (int)(x.size())
#define mod 1000000007

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define deb(x) cerr << #x << " = " << x << endl;



int32_t main(){
    ios::sync_with_stdio(false);
    string s, t;
    cin>>s>>t;
    int ans=0;
    for(int i=0;i<3;i++){
        if(s[i]==t[i]){
            ans++;
        }
    }
    cout<<ans<<"\n";



    return 0;
}

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

int main() {
  int R;
  cin >> R;
  if (R < 1200) {
    cout << "ABC"
         << "\n";
  } else if (R >= 2800) {
    cout << "AGC" << '\n';
  } else {
    cout << "ARC" << '\n';
  }
  return 0;
}

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

void show( int arr[], unsigned int size )
{
	cout<<arr[0]<<flush;
	for( unsigned int i=1; i<size; i++ ){
		cout<<' '<<arr[i]<<flush;
	}
	cout<<endl;
}

int merge( int arr[], unsigned int arr_s, unsigned int lft, unsigned int md, unsigned int rgt )
{//??????????????????????????????lft??\???md?????????md??\???rgt???????????????
	int cnt=0;

	//?????????????????????????????????( ???????????????????????????????????????????????????????????? )
	int left_s=md-lft+1, right_s=rgt-md+1, *left=new int[left_s], *right=new int[right_s];
	for( int i=0; i<left_s-1; i++ ){
		left[i]=arr[lft+i];
	}
	left[left_s-1]=INT_MAX;
	for( int i=0; i<right_s-1; i++ ){
		right[i]=arr[md+i];
	}
	right[right_s-1]=INT_MAX; //???????????????????????±???????????¨???????????????????????????

	//??????????????????????????????????????±???,??????
	for( int i=0, left_i=0, right_i=0; i<left_s+right_s-2; i++, cnt++ ){
		if( left[left_i] < right[right_i] ){
			arr[lft+i]=left[left_i];
			++left_i;
		}else{
			arr[lft+i]=right[right_i];
			++right_i;
		}
	}

	delete[] right;delete[] left;
	return cnt;
}

int mergeSort( int arr[], unsigned int arr_s, unsigned int lft, unsigned int rgt ) //??????????????????mergeSort???????????¨???????????¨?????????????????????????????????
{
	static int cnt=0;
		unsigned int md=(lft + rgt)/2;
	if( rgt - lft >=2 ){ //???????????¶???????????????????????\??????????????¨???! ??? lft????????????????´????????¬???????????????????  ?????????????????????????????????????????????merge????????°??????????????????!

		//????????????????????¨???????????????.
		mergeSort(arr, arr_s, lft, md);  
		mergeSort(arr, arr_s, md, rgt);
		//??????(????????????)! ?????§?????????????????????????????????????????°?????????????????????????????????????????????????????§????????????
		cnt+= merge(arr, arr_s, lft, md, rgt); //if ?????????????????????????????????????¨?
	
	}
	return cnt;
}

int main()
{
	int arr_s;
	cin>>arr_s;
	int *arr=new int[arr_s];
	for( int i=0; i<arr_s; i++ ){
		cin>>arr[i];
	}

	int cnt=mergeSort(arr, arr_s, 0, arr_s);
	show(arr, arr_s);
	cout<<cnt<<endl;

	delete[] arr;
}

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

using namespace std;

int main(){
    int n;
    scanf("%d",&n);
    map<long long,int>mp;
    long long s=0,ans=0;
    mp[0]=1;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        s+=x;
        ans+=mp[s];
        mp[s]++;

    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 12800
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

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

ll mod = 1e9 + 7;

ll comb[5001][5001];


int main(){
	int a,b,c;
	cin >> a >> b>> c;
	cout << max(0,c-(a-b)) << endl;
	return 0;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"

using namespace std;
const int N=1e6+9;

vector<int>prime;
bool flag[N+100];

void seive(){
    for(int i=4;i<N;i+=2)flag[i]=true;
    for(int i=3;i*i<N;i+=2){
        if(!flag[i]){
            for(int j=i*3;j<N;j+=i*2)flag[j]=true;
        }
    }
    prime.push_back(2);
    for(int i=3;i<=N;i+=2){
        if(!flag[i])prime.push_back(i);
    }
}

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

    int a[n];
    for(int& i : a )cin >> i;
    seive();
    //for(int i=0;i<20;i++)cout<<prime[i]<<" ";
    //cout<<endl;
    map<int,int> cnt;

    for(int i : a){
        int temp=i;

        for(int x : prime){
            if(x*x>temp)break;
            if(temp%x==0){
                    cnt[x]++;
                    while(temp%x==0)temp/=x;
            }
        }
        if(temp>1)cnt[temp]++;
    }
    bool flag = true;

    for(auto [x,y ] : cnt){
        if(y>1){
            flag=false;
            break;
        }
    }
    if(flag){
        cout<<"pairwise coprime"<<endl;
        return 0;    
    }

    int g=a[0];
    for(int i=1;i<n;i++)g=__gcd(g,a[i]);
    if(g==1)cout<<"setwise coprime"<<endl;
    else cout<<"not coprime"<<endl;
}



Measured memory_bytes: 12152
N, A, B = map(int, input().split())
ma = min(A, B)
if N >= A + B:
    mi = 0
else:
    n = N
    n -= A
    if n == 0:
        mi = B
    else:
        if n >= B:
            mi = 0
        else:
            mi = B - n
print(ma, mi)

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

int main() {
    string a;
    cin >> a;
    int n = a.size();
    vector<int> counter(1 << 8, 0);

    ll ans = 1;
	rep(i,n) {
		ans += i - counter[a[i]];
		counter[a[i]]++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007
typedef long long ll;

int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> vec(n);
    rep(i, n){
        ll num;
        cin >> num;
        vec[i] = num-1;
    } 
    vector<ll> flag(n, -1);
    vector<ll> track;
    ll now = 0;
    while(flag[now] == -1){
        flag[now] = track.size();
        track.push_back(now);
        now = vec[now];
    }
    ll shuki = track.size() - flag[now];
    if(k < flag[now]) cout << track[k]+1 << endl;
    else{
        cout << track[flag[now] + (k-flag[now]) % shuki]+1 << endl;
    }
    return 0;
}

Measured memory_bytes: 8496
// Package main provides
//
// File:  main.go
// Author: ymiyamoto
//
// Created on Mon Jan 28 11:49:52 2019
//
package main

import (
	"fmt"
	"sort"
)

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func main() {
	var n int
	fmt.Scan(&n)

	slice := make([]int, n)
	for i := range slice {
		fmt.Scan(&slice[i])
	}
	sort.Ints(slice)

	a := slice[len(slice)-1]
	b := 0
	diff := 1 << 60
	for i := range slice {
		d := abs(a - 2*slice[i])
		if d < diff {
			diff = d
			b = slice[i]
		}
	}
	fmt.Println(a, b)
}


Measured memory_bytes: 5504
#include<iostream>
#include<math.h>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<deque>
#include<cstring>
using namespace std;
int a[5000];
int bubuwa(int t);//tを省いた中で、部分和がk-a[t]以上k未満になるかどうか
int n, k;
bool dp[5001][5001];
int main() {

	//B


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

	sort(a, a + n);

	int left, right, mid;
	left = -1;
	right = n;
	mid = (left + right) / 2;

	while (right - left > 1) {

		if (bubuwa(mid) == 1) {

			right = mid;

		}
		else {

			left = mid;

		}
		mid = (right + left) / 2;
	
	}

	cout << right << endl;
	return 0;

	//ある値が必要であれば、それ以上もすべて必要である。従って二分探索を
	//用いて、最初に必要となる数を求める。必要かどうかの判定は部分和問題
	//である。その数を省いた数列から部分和を取って、k未満かつその数があ
	//ればk以上となるような値となるかを調べる




	//A

	/*int x;
	cin >> x;
	int i;
	for (i = 0; i <= x; i++) {

		if (((i * (i - 1)) / 2 < x) && (x <= (i * (i + 1)) / 2)) {
			cout << i << endl;
			return 0;
		}

	}
	return 0;
	*/
}

int bubuwa(int t) {

	int i, j;
	memset(dp, 0, sizeof(dp));
	dp[0][0] = true;
	for (i = 0; i < n; i++) {
		//if (i != t) {
			for (j = 0; j <= k; j++) {

				dp[i + 1][j] |= dp[i][j];
				if (j >= a[i] && i != t)dp[i + 1][j] |= dp[i][j - a[i]];

			}
		//}
	}

	for (i = max(k - a[t], 0); i < k; i++) {
		if (dp[n][i] == true) {
			return 1;
		}
	}
	return 0;

}

Measured memory_bytes: 28072
//Utkarsh.25dec
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// ordered_set s ; s.order_of_key(val)  no. of elements strictly less than val
// s.find_by_order(i)  itertor to ith element (0 indexed)
typedef vector<vector<ll>> matrix;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=500023;
bool vis[N];
vector <int> adj[N];
ll par[N];
ll sz[N];
ll find(ll curr)
{
    while(curr!=par[curr])
        curr=par[curr];
    return curr;
}
void merge(ll x,ll y)
{
    if(sz[x]>=sz[y])
    {
        par[y]=x;
        sz[x]+=sz[y];
    }
    else
    {
        par[x]=y;
        sz[y]+=sz[x];
    }
}
void solve()
{
    ll n,h,w;
    cin>>n>>h>>w;
    vector <tuple<ll,ll,ll>> v;
    for(int i=0;i<n;i++)
    {
        ll a,b,c;
        cin>>a>>b>>c;
        v.pb(make_tuple(c,a,b));
    }
    for(int i=1;i<N;i++)
    {
        sz[i]=1;
        par[i]=i;
    }
    sort(all(v));
    reverse(all(v));
    ll ans=0;
    for(auto t:v)
    {
        ll add=get<0>(t);
        ll r=get<1>(t);
        ll c=get<2>(t);
        r+=1e5;
        r=find(r);
        c=find(c);
        if(vis[r] && vis[c])
            continue;
        if(r==c)
        {
            if(vis[r]==0)
            {
                vis[r]=1;
                ans+=add;
                continue;
            }
            else
                continue;
        }
        else
        {
            merge(r,c);
            int final=max(vis[r],vis[c]);
            r=find(r);
            vis[r]=final;
            ans+=add;
        }
    }
    cout<<ans<<'\n';
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
    //cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 25380
import sys
from collections import Counter

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


class UnionFind:
    # Reference: https://note.nkmk.me/python-union-find/
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -self.parents[self.find(x)]

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}


def main():
    N, *XY = map(int, read().split())

    MAX = 100010
    uf = UnionFind(MAX * 2)
    for x, y in zip(*[iter(XY)] * 2):
        uf.union(x, y + MAX)

    x_comp = Counter()
    y_comp = Counter()
    for i in range(MAX):
        x_comp[uf.find(i)] += 1
    for i in range(MAX, 2 * MAX):
        y_comp[uf.find(i)] += 1

    ans = 0
    for k in x_comp.keys():
        ans += x_comp[k] * y_comp[k]

    ans -= N

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 39912
N = int(input())
S = input()

cnt = [0, 0]
for s in S:
    if s == "(":
        cnt[0] += 1
    else:
        if cnt[0]:
            cnt[0] -= 1
        else:
            cnt[1] += 1

print("(" * cnt[1] + S + ")" * cnt[0])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  int n,k,ans;
  cin>>n>>k;
  ans=0;
  rep(i,n){
  int x;
  cin>>x;
  if((k-x)*2>=x*2){
  ans+=x*2;
  }else{
  ans+=(k-x)*2;
  }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
using namespace std;


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

	int m = 0;
	int sum = 0;
	for (auto i = 0; i < N; ++i)
	{
		int temp;
		cin >> temp;
		sum += temp;
		m = max(m, temp);
	}

	sum -= m / 2;

	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin >> n;
  int log=0;
  int m = n;
  while (m>=10){
    m /=10;
    log++;
  }
  if(log==0){
    cout << n << endl;
  }
  else if(log == 1){
    cout << 9 << endl;
  }
   else if(log == 2){
    cout << n-90 << endl;
  }
   else if(log == 3){
    cout << 909 << endl;
  }
   else if(log == 4){
    cout << n-9090 << endl;
  }
   else cout << 90909 << endl;
}
    
  
    

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc156/tasks/abc156_b
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, K;
    cin >> N >> K;
    int ans = 0;
    while (N > 0) {
        N /= K;
        ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os, const map<T,U>& mp){ os << "{"; for(auto& p : mp){ os << p << ","; } os << "}"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int,int>;
using vi = std::vector<int>;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/
ll n,m;

void solve(){
    vector<ll> a(n);
    rep(i,n) cin >> a[i];

    ll ans = -1;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(a[i]+a[j]<=m){
                ans = max(ans,a[i]+a[j]);
            }
        }
    }
    if(ans==-1){
        cout << "NONE" << endl;
    }else{
        cout << ans << endl;
    }
}

int main(){
    while(cin>>n>>m){
        if(!n and !m) break;
        solve();
    }
}



Measured memory_bytes: 3108
#include<iostream>

using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	int sum=0;
	sum=a+b+c;
	if(sum>=22)
	{
		cout<<"bust"<<endl;
	}
	else
	{
		cout<<"win"<<endl;
	}
}

Measured memory_bytes: 256
import math
s = int(input())
iMax=math.floor(s/3)
modN = 1000000007
ans=0;

P = modN
N = iMax
inv_t = [0]+[1]
for i in range(2,N):
  inv_t += [inv_t[P % i] * (P - int(P / i)) % P]

for i in range(iMax):
    #(n+k)*(n+2)....*(n+1)/(1*2*....k)
    n=s-3*(i+1)
    temp=1
    for k in range(1,i+1):
        temp=(temp*((n+k)%modN * inv_t[k])%modN)%modN
    ans=(ans+temp)%modN

print(ans)

Measured memory_bytes: 9220
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    int weight;
    edge(int f,int t,int w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

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

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

bool isPalindrome(string s){
    string t = s;
    reverse(all(t));
    return s==t;
}

constexpr ll LNF = 1e18+7;

constexpr int INF = 1e9+7;



vector<int> dx = {-1,0,1,0,-1,1,-1,1};
vector<int> dy = {0,-1,0,1,1,-1,-1,1};

/* template */

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n,c,k; cin >> n >> c >> k;
    vector<ll> t(n);
    rep(i,0,n) cin >> t[i];
    sort(all(t));
    ll ans = 0ll;
    ll flag = t[0];
    ll s = 0ll;
    rep(i,0,n){
        if(flag+k>=t[i]){
            if(s<c) s++;
            else{
                ans++;
                s = 1ll;
                flag = t[i];
            }
        }
        else{
            ans++;
            flag = t[i];
            s = 1ll;
        }
    }
    ans++;
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

//int counter(int bit, int N) {
//  int count = 0;
//  for (int i = 0; i < (1 << N); i++) {
//    if(bit & (1 << i)){
//      count++;
//    }
//  }
//  return count;
//}
int counter(int x) {
    if(x == 0) return 0;
    return counter(x >> 1) + (x & 1);
}

int main(int argc, const char *argv[]) {
  int N;
  int ans = 0;
  cin >> N;
  vector<int> A(N);
  vector<vector<int> > x(N, vector<int>(N));
  vector<vector<int> > y(N, vector<int>(N));
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    for (int j = 0; j < A[i]; j++) {
      cin >> x[i][j] >> y[i][j];
      x[i][j]--;
    }
  }

  for (int bit = 0; bit < (1 << N); bit++) {
    bool status = true;
    for (int i = 0; i < N; i++) {
       if(!(bit & (1 << i))) continue;
      for (int j = 0; j < A[i]; j++) {
        if (((bit >> (x[i][j])) & 1) ^ y[i][j]){
          status = false;
        }
      }
    }
    if(status){
      //ans = max(ans, counter(bit, N));
      ans = max(ans, counter(bit));
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
// #include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

const int INF = 1050000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

const int N_MAX = 2010;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}

int main() //input->compute->output
{
        string S, T;
        int ans = 0;

        cin >> S >> T;
        for (int i = 0; i < 3; i++)
        {
                if (S[i] == T[i])
                {
                        ans++;
                }
        }
        cout << ans;

        return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int main2() {
  ll A, B; cin >> A >> B;
  if (A > B) swap(A, B);
  if (A == 1 && B == 1) {
    cout << 1 << endl;
    return 0;
  }
  if (A == 1) {
    cout << B-2 << endl;
    return 0;
  }
  cout << (A-2)*(B-2) << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  ll n,k;
  cin >> n >> k;
  vector<ll> a(n),s(n+1,0);
  rep(i,n) {
    cin >> a[i];
    s[i+1] += s[i] + a[i];
  }
  vector<ll> b(n+1);
  rep(i,n+1) {
    b[i] = (s[i] - i) % k;
  }

  ll ans = 0;
  unordered_map<ll,ll> mp;
  for (int i = 0; i < k && i < n+1; ++i) {
    mp[b[i]]++;
  }
  for (auto p:mp) {
    ans += p.second*(p.second-1)/2;
  }
  for (int i = 1; i+k-1 < n+1; ++i) { //i+(k-1) 区間の右端
    mp[b[i-1]]--;
    ans += mp[b[i+k-1]]++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 13256
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>  
#include <stdbool.h>   
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define PI 3.14159265358979323846;
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
/*
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r)
*/
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r)
#define TYPE long long
#define ll long long
#define MEMSET(a) memset(a,0,sizeof(a))
#define MEMSET_U(a) memset(a,-1,sizeof(a))
#define bool    _Bool
const int mod = (int)1e09 + 7;

//#define DEBUG1
//#define DEBUG2
//#define DEBUGF
#define DUMMY

int in(void) { int i; scanf("%d", &i); return i; }
long long llin(void) { long long i; scanf("%lld", &i); return i; }
double din(void) { double i; scanf("%lf", &i); return i; }
void chin(char s[]) { scanf("%s", s); }

void print(int a) { printf("%d\n", a); }
void llprint(long long a) { printf("%lld\n", a); }
void dprint(double a) { printf("%.10f\n", a); }
void print2(int a, int b) { printf("%d %d\n", a, b); }
int Max(int a, int b) { if (a > b) { return a; }return b; }
int Min(int a, int b) { if (a < b) { return a; }return b; }
long long llmax(long long a, long long b) { return a > b ? a : b; }
long long llmin(long long a, long long b) { return a < b ? a : b; }
double dmax(double a, double b) { return a > b ? a : b; }
double dmin(double a, double b) { return a < b ? a : b; }
//long long llmax(long long a, long long b) { return a > b ? a : b; }
//long long llmin(long long a, long long b) { return a < b ? a : b; }
//double dmax(double a, double b) { return a > b ? a : b; }
int cmp(const void *a, const void *b) { return *(TYPE *)a - *(TYPE *)b; }
int cmp_r(const void *a, const void *b) { return *(TYPE *)b - *(TYPE *)a; }
int char_cmp(const void *a, const void *b) { return strcmp((char *)a, (char *)b); }
int char_cmp_r(const void *a, const void *b) { return strcmp((char *)b, (char *)a); }
void swap(int *a, int *b) { int t = *a; *a = *b; *b = t; }



int main() {
	int K, S;
	scanf("%d%d", &K, &S);
	int ans = 0;

	for (int i = 0; i <= K; i++) {
		for (int j = 0; j <= K; j++) {
			if (0 <= S - i - j && S - i - j <= K) {
				ans++;
			}
		}
	}

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




#ifdef DEBUGF
	getch();
#endif
	return 0;
		}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007
using namespace std;
typedef long long ll;

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(void){
  int n, m;
  cin >> n >> m;

  UnionFind uf(n);
  rep(i, m){
    int s, t;
    cin >> s >> t;
    uf.unionSet(s, t);
  }

  vector<string> ans;
  int q;
  cin >> q;
  rep(i, q){
    int a, b;
    cin >> a >> b;
    if(uf.findSet(a, b)) ans.push_back("yes");
    else ans.push_back("no");
  }
  rep(i, ans.size()) cout << ans[i] << endl;
  return 0;
}



Measured memory_bytes: 3976
#include <stdio.h>
     
    int main(void){
        int N, i, sum = 0;
        int a[3000];
        scanf("%d",&N);
        for(i = 0; i < N; i++){
            scanf("%d",&a[i]);
            sum += a[i];        
        }
        printf("%d",sum-N);
    }

Measured memory_bytes: 128
import java.util.*;
import java.lang.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        String s = String.valueOf(n);
        int l = s.length();
        if (l == 1) {
            System.out.println(n);
        } else {
            boolean nine = true;
            for (int i = 1; i < l; i++) {
                if (s.charAt(i) != '9') {
                    nine = false;
                    break;
                }
            }
            if (nine) {
                System.out.println(9 * (l - 1) + n / (long)(Math.pow(10, l - 1)));
            } else {
                System.out.println(9 * (l - 1) + n / (long)(Math.pow(10, l - 1)) - 1);
            }

        }
    }
}


Measured memory_bytes: 22996
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *
from math import *

sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()

N = int(input())
jobs = [tuple(map(int, input().split())) for _ in range(N)]
jobs.sort(key=lambda t: t[1])
t = 0
for a, b in jobs:
    t += a
    if t > b:
        print('No')
        exit()
print('Yes')



Measured memory_bytes: 76892
#[allow(unused_macros)]
macro_rules! input {
    ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } };
    ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ( $ next : expr ) => { };
    ( $ next : expr , ) => { };
    ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) };
    ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) };
    ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) };
    ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 };
    ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) };
}

fn main() {
    input! {
        n: usize, k: usize
    }

    let mut p = 0f64;
    for i in 1..n+1 {
        let mut j = i;
        let mut q = 1f64 / n as f64;
        while j < k {
            j *= 2;
            q /= 2f64;
        }
        p += q;
    }

    println!("{}", p);
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define ROF(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define REP(i, n) FOR(i, 0, (n)-1)
#define all(x) (x).begin(), (x).end()
#define reset(x, y) memset(x, y, sizeof(x))
#define uni(x) (x).erase(unique(all(x)), (x).end());
#define BUG(x) cerr << #x << " = " << (x) << endl
#define pb push_back
#define mp make_pair
#define _1 first
#define _2 second

const int maxn = 123456;

vector<ll> dist[2];
int n, k;

int main() {
    scanf("%d%d", &n, &k);
    REP(i, n) {
        int x;
        scanf("%d", &x);
        dist[x >= 0].pb(abs(x));
    }
    reverse(all(dist[0]));
    ll ans = 1e20;
    REP(i, k) {
        if (i < dist[0].size() && k - i - 2 < dist[1].size()) ans = min(ans, 2 * dist[0][i] + dist[1][k - i - 2]);
        if (i < dist[1].size() && k - i - 2 < dist[0].size()) ans = min(ans, 2 * dist[1][i] + dist[0][k - i - 2]);
    }
    if (k <= dist[0].size()) ans = min(ans, dist[0][k - 1]);
    if (k <= dist[1].size()) ans = min(ans, dist[1][k - 1]);
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 1656
#include<bits/stdc++.h>
#define bug(x) cout<<(#x)<<" "<<(x)<<endl
#define ll long long
/*
char *TT,*mo,but[(1<<15)+2];
#define getchar() ((TT==mo&&(mo=(TT=but)+fread(but,1,1<<15,stdin),TT==mo))?-1:*TT++)//*/
using namespace std;
const int N=1e5+5;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int n;
ll mn=2,mx=2,a[N];
int main(){
	n=read();
	for(int i=1;i<=n;i++){
		a[i]=read();
	}
	for(int i=n;i;i--){
		mn=ceil((double)mn/a[i])*a[i],mx=(mx/a[i])*a[i]+a[i]-1;
		if(mn>mx) return cout<<-1<<endl,0;
	}
	cout<<mn<<" "<<mx<<endl;
}

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

int main() {
  long long K;
  cin >> K;
  string S;
  cin >> S;
  long long countR = 0;
  for (int i = 0; i < K; i++) {
    if (S.at(i) == 'R')
      countR++;
  }
  long long ansR = 0, ansW = 0;
  for (int j = 0; j < K; j++) {
    if (j < countR && S.at(j) == 'W')
      ansW++;
    if (j >= countR && S.at(j) == 'R')
      ansR++;
  }
  cout << max(ansW,ansR) << endl;
      
}


Measured memory_bytes: 3760
#入力
N = int(input())
S = input()

#文字列の前半部分を取得して二つ繋げる
halfN = int(N/2)
seq = ""

for i in range(2):
    for j in range(halfN):
        seq = seq + S[j]
        
#判定
if seq == S:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 2940
import itertools

n = int(input())
p = map(int, input().split())
q = map(int, input().split())
d = dict()
for i, v in enumerate(itertools.permutations([x for x in range(1, n+1, 1)]), 1):
  d[str(v)] = i

print(abs(d[str(tuple(p))] - d[str(tuple(q))]))


Measured memory_bytes: 14732
#include<bits/stdc++.h>
#include<math.h>
#include<queue>
#include<cstdio>
#include<set>
#include<map>
using namespace std;
using ll = long long;

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

    vector<ll> A(N);
    for(ll i=0; i<N; i++){
        cin >> A.at(i);
    }
    sort(A.begin(),A.end());
  	reverse(A.begin(),A.end());
    ll ans=A.at(0);
    if(N%2==0){
        for(ll i=1; i<=N/2-1; i++){
            ans+=2*A.at(i);
        }
    }else{
        for(ll i=1; i<=(N-3)/2; i++){
            ans+=2*A.at(i);
        }
        ans+=A.at((N-1)/2);
    }
    cout << ans << endl;
    return 0;
}

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

#ifdef LOCAL
#include "../dump.hpp"
#else
#define dump(...)
#endif

using namespace std;

#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ROF(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((int)(x).size())
#define pb push_back
#define fst first
#define snd second

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef long long ll;

int main(){
  int n,ma,mb; cin >> n >> ma >> mb;
  vi a(n),b(n),c(n); rep(i,n) cin >> a[i] >> b[i] >> c[i];

  vector<vvi> dp(n+1, vvi(401, vi(401,1<<29) ) );
  dp[0][0][0] = 0;
  rep(i,n) rep(j,401) rep(k,401){
    dp[i+1][j][k] = min(dp[i+1][j][k],dp[i][j][k]);
    if(j+a[i] <= 400 and k+b[i]<=400)
      dp[i+1][j+a[i]][k+b[i]] = min(dp[i+1][j+a[i]][k+b[i]],dp[i][j][k]+c[i]);
  }

  int ans = 1 << 29;
  FOR(i,1,401) FOR(j,1,401)
    if(i * mb == j * ma) ans = min(ans, dp[n][i][j]);

  if(ans == 1<<29) cout << "-1\n";
  else cout << ans << endl;
}

Measured memory_bytes: 27264
// 桁ごとの計算

#include <stdio.h>
#include <string.h>

int main(void){
  char num[1005];
  int i,sz;

  while(1){
    int sum =0;
    scanf("%s",num);
    if(num[0]=='0') break;
    sz = strlen(num);
    for(i=0; i<sz; i++) sum += num[i] - '0';

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



Measured memory_bytes: 2040
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint n; cin >> n;
    vec<lint> a_list(n);
    range(i, 0, n) cin >> a_list.at(i);
    vec<lint> res(n);
    range(i, 0, n) {
        lint idx_res = (i % 2 == 0 ? i / 2: n - 1 - i / 2);
        lint idx_a = n - 1 - i;
        res.at(idx_res) = a_list.at(idx_a);
    }
    range(i, 0, n) cout << res.at(i) << " ";
    cout << "\n";
}

Measured memory_bytes: 5376
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define pye cout << "yes" << endl
#define pno cout << "no" << endl
#define pYe cout << "Yes" << endl
#define pNo cout << "No" << endl
#define pYE cout << "YES" << endl
#define pNO cout << "NO" << endl
#define prin(num) cout << num << endl
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 1000005
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PA;
typedef map<ll, ll> Map;

int main(void) {
    ll N;
    ll p[20001];
    ll a[20001], b[20001];
    ll i;
    ll M=40000;
    
    cin >> N;
    for(i=0; i<N; i++) {
        cin >> p[i];
        p[i]--;
    }
    
    for(i=0; i<N; i++) {
        a[i]=M*i+1;
        b[i]=(N-i)*M;
    }
    
    for(i=0; i<N; i++) {
        a[p[i]]+=i;
    }
    
    
    for(i=0; i<N; i++) {
        cout << a[i] << " ";
    }
    cout << endl;
    
    for(i=0; i<N; i++) {
        cout << b[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 1152
#include <iostream>
#include <functional>
#include <algorithm>
using namespace std;

int n, a[100009], s;

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	sort(a + 1, a + n + 1, greater<int>());
	for (int i = 1; i <= n; i++) {
		if (i <= a[i])s = i;
	}
	int G1 = a[s] + s, G2 = 0;
	if (s != n) {
		for (int i = s; i <= n; i++) {
			if (a[i] == s)G2 = (i + a[i]);
		}
	}
	if (G1 % 2 == 1 || G2 % 2 == 1) { cout << "First" << endl; }
	else { cout << "Second" << endl; }
	return 0;
}

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

ll min(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    else return b;
}

int main() {
    ll n;cin>>n;
    double a[n];
    for(ll i=0;i<n;i++){
        cin>>a[i];
    }
    double dp[n+1][n+1];
    dp[0][0]=1;
    for(ll i=1;i<=n;i++){
        for(ll j=0;j<=i;j++){
            if(j==0){
                dp[i][j]=dp[i-1][j]*(1-a[i-1]);
            }else if(j==i){
                dp[i][j]=dp[i-1][j-1]*a[i-1];
            }else{
                dp[i][j]=dp[i-1][j]*(1-a[i-1])+dp[i-1][j-1]*a[i-1];
            }
        }
    }
    double ans;ans=0;
    for(ll i=(n+1)/2;i<=n;i++){
        ans=ans+dp[n][i];
    }
    cout<<setprecision(10)<<ans<<endl;
    return 0;
}


Measured memory_bytes: 70272
#include <algorithm>
#include <cstdio>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < int(n); ++(i))
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
using ll = long long;
using namespace std;

ll choose(int n, int r) { // O(r) for small n
    ll acc = 1;
    repeat (i,r) acc = acc * (n-i) / (i+1);
    return acc;
}
int main() {
    int n, p; scanf("%d%d", &n, &p);
    vector<int> a(n); repeat (i, n) scanf("%d", &a[i]);
    int even = whole(count_if, a, [](int a_i) { return a_i % 2 == 0; });
    int odd = n - even;
    ll result = 0;
    for (int k = p; k <= odd; k += 2) {
        result += choose(odd, k);
    }
    result *= 1ll << even;
    printf("%lld\n", result);
    return 0;
}


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

int main()
{
    int a;
    cin>>a;
    for(int i=1;i<=9;i++)
    {
        if(a%i==0&&a/i<=9)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <math.h>

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define PI 3.14159265358979323846264338327950L
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

int main() {
  long long X;

  cin >> X;

  long long P = 100, i = 0;

  while (P < X) {
    P += P / 100;
    i++;
  }

  cout << i << endl;
}


Measured memory_bytes: 3620