akhauriyash/Code-Regression huggingface dataset:
### main

loop do
  n, k = gets.strip.split(' ').map{|s| s.to_i}
  break if (n | k) == 0

  i = 0
  sum = 0
  as = []

  while i < k
    ai = gets.strip.to_i
    as << ai

    sum += ai

    i += 1
  end

  max_sum = sum

  while i < n
    ai = gets.strip.to_i
    aj = as.shift
    as << ai

    sum += ai - aj
    max_sum = sum if max_sum < sum

    i += 1
  end

  puts max_sum
end

Measured memory_bytes: 6696
// In the name of God 
#include <bits/stdc++.h>

using namespace std ;


#define int long long
#define all(v) v.begin() , v.end()

template<typename T> inline bool smin(T &a, const T &b){ return b < a ? a = b,1:0;}
template<typename T> inline bool smax(T &a, const T &b){ return a < b ? a = b,1:0;}

const int mod = 998244353 , N = ( int ) 6e5 + 10 ; 

int n , a , b , k , fact [ N ] , inv [ N ] ; 

int pw ( int x , int y ) {
	int ret = 1 ;
	for ( ; y ; y >>= 1 , ( x *= x ) %= mod )
		if ( y & 1 )
			( ret *= x ) %= mod ;
	return ret ; 
}

int comb ( int n , int r ) {
	if ( r > n || r < 0 ) return 0 ; 
	return fact [ n ] * inv [ r ] % mod * inv [ n - r ] % mod ; 
}

int32_t main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	fact [ 0 ] = inv [ 0 ] = 1 ;
	for ( int j = 1 ; j < N ; ++j ) {
		fact [ j ] = fact [ j - 1 ] * j % mod ;
		inv [ j ] = pw ( fact [ j ] , mod - 2 ) ; 
	}
	cin >> n >> a >> b >> k ;
	if ( !k )
		return cout << 1 << '\n' , 0 ;
	if ( k % __gcd ( a , b ) != 0 )
		return cout << 0 << '\n' , 0 ;
	int res = 0 ; 
	for ( int x = 0 ; x <= n ; ++x ) {
		int y = ( k - a * x ) / b ;
		if ( ( k - a * x ) % b != 0 || y > n ) continue ;
		res += ( comb ( n , x ) * comb ( n , y ) % mod ) ;
		if ( res >= mod )
			res -= mod ; 
	}
	cout << res << '\n' ; 
}


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

int main()
{
  int N, dp[1 << 16];

  while(cin >> N, N) {
    memset(dp, 0, sizeof(dp));
    for(int i = 0; i < N; i++) {
      int M, L;
      cin >> M >> L;
      int bitMask = 0;
      while(M--) {
        int S, E;
        cin >> S >> E;
        S -= 6, E -= 6;
        bitMask |= (1 << E) - (1 << S);
      }
      for(int j = 0; j < 1 << 16; j++) {
        if(!(bitMask & j)) {
          dp[bitMask | j] = max(dp[bitMask | j], dp[j] + L);
        }
      }
    }
    cout << dp[(1 << 16) - 1] << endl;
  }
}

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

using namespace std;

const int mod = 1e9 + 7;

int n;
int cnt[64][2];

inline void read(long long &x) {
	x = 0; char ch = getchar();
	while(!isdigit(ch)) ch = getchar();
	while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
}

int main() {
	cin >> n;
	long long x;
	for(int i = 1; i <= n; ++i) {
		read(x);
		for(int i = 0; i < 60; ++i)
			if(x >> i & 1)
				++cnt[i][1];
			else
				++cnt[i][0];
	}
	long long ans = 0;
	for(int i = 0; i < 60; ++i)
		ans = ( ans + (1LL << i) % mod * (1LL * cnt[i][0] * cnt[i][1] % mod) ) % mod; 
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import math

A, B, H, M = map(int, input().split())

h = H / 12 * 360 + M / 2
m = M / 60 * 360

d = min(360 - abs(h-m), abs(h-m))
C = math.sqrt(A**2 + B**2 - 2*A*B*math.cos(math.radians(d)))

print(C)

Measured memory_bytes: 9496
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
using namespace std;
typedef long long ll;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<pair<int, int>> v;
    for(int i = 0; i < n; i++)
    {
        int x; cin >> x;
        v.push_back(make_pair(x, i + 1));
    }
    sort(v.begin(), v.end(), greater<pair<int, int>>());
    vector<int> used(n + 2, 0);
    int ans = 0, cnt = 0;
    for(int i = 0; i < n; i++)
    {
        int pos = i;
        if(v[i].first == 0) break;
        while(v[pos].first == v[i].first)
        {
            int u = v[pos].second;
            if(used[u]) break;
            used[u] = true;
            cnt++;
            if(used[u + 1]) cnt--;
            if(used[u - 1]) cnt--;
            pos++;
        }
        ans = max(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}




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

int main() {
    vector<int> v(26, 0);
    
    char ch;
    while (cin >> ch) {
        ch = tolower(ch);
        
        if (ch >= 'a' && ch <= 'z') {
            int n = ch - 'a';
            v.at(n)++;
        }
    }
    
    for (int i = 0; i < 26; i++) {
        char ch = 'a' + i;
        cout << ch << " : " << v.at(i) << endl;
    }
}


Measured memory_bytes: 3104
n = int(input())
x = list(map(int, input().split()))

if 0 in x :
    print(0)
else :
    ans = 1
    con = True
    for i in range(0, n):
        ans *= x[i]
        if ans > 1000000000000000000:
            print(-1)
            con = False
            break
    if con : print(ans)

Measured memory_bytes: 21588
#include <cstdio>
#include <cstring> 
#include <iostream>
#include <queue> 
using namespace std;
int n,k; 
char str[200010];
int main(){
	scanf("%d",&n);long long m=0;k=0;
	for(int i=1;i<=n;++i){
		int x;scanf("%d",&x);
		if(k<=x) k=x;
		else m+=k-x;
	}
	printf("%lld\n",m);
	return 0;
} 

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

int main()
{
	int N;
	scanf("%d", &N);
	
	string s = "";
	int rCount = 0, ans = 0;
	for(int i = 1; i <= N; i++)
	{
		char currChar;
		scanf(" %c", &currChar);
		s += currChar;
		
		if(currChar == 'R')
			rCount++;
	}
	
	for(int i = 0; i < rCount; i++)
	{
		if(s[i] != 'R')
			ans++;
	}
	
	printf("%d", ans);
}


Measured memory_bytes: 3916
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,cnt(0);
  string s;
  bool flg(false);
  cin >> n >> s;
  for(int i = 0;i<n;i++){
    cnt++;
    do{
      i++;
      flg = true;
    }while(i<n && s.at(i)==s.at(i-1));
    if(flg){
      i--;
      flg = false;
    }
  }
  
  cout << cnt << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define INF 2e9
using namespace std;
typedef long long llong;
typedef long double ldouble;

using Graph = vector<vector<int>>;

int main(){
  int H, A;
  cin >> H >> A;
  if(H%A==0) cout << H/A << endl;
  else cout << H/A+1 << endl;
}

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

int main() {
    int x, y, z, K;
    cin >> x >> y >> z >> K;
    vector<long long> as(x), bs(y), cs(z);
    for (int i = 0; i < x; i++) cin >> as[i];
    for (int i = 0; i < y; i++) cin >> bs[i];
    for (int i = 0; i < z; i++) cin >> cs[i];

    vector<long long> yz;
    yz.reserve(y * z);
    for (int i = 0; i < y; i++) {
        for (int j = 0; j < z; j++) {
            yz.push_back(bs[i] + cs[j]);
        }
    }
    sort(yz.begin(), yz.end());


    auto num_gex = [&](long long k) {
        long long ret = 0;
        for (int i = 0; i < x; i++) {
            long long rem = k - as[i];
            ret += yz.size() - (lower_bound(yz.begin(), yz.end(), rem) - yz.begin());
        }
        return ret;
    };
    long long l = 0, r = 1e18;
    while (l < r - 1) {
        long long m = (l + r) / 2;
        if (num_gex(m) >= K) {
            l = m;
        } else {
            r = m;
        }
    }
    long long nax = l;
    vector<long long> ans;
    ans.reserve(3000);
    cerr << "nax: " << nax << endl;
    for (int i = 0; i < x; i++) {
        long long rem = nax + 1 - as[i];
        int lt = lower_bound(yz.begin(), yz.end(), rem) - yz.begin();
        for (int j = lt; j < yz.size(); j++) {
            ans.push_back(as[i] + yz[j]);
        }
    }
    assert(ans.size() <= K);
    while (ans.size() < K) {
        ans.push_back(nax);
    }
    sort(ans.rbegin(), ans.rend());
    for (long long a : ans) {
        cout << a << '\n';
    }
}

Measured memory_bytes: 8192
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;

int main(void){
  int N;
  long long  a[300010];
  cin >> N;
  for(int i=0;i<3*N;i++) cin >> a[i];
  sort(a,a+3*N,greater<int>());
  long long sum=0;
  for(int i=0;i<N;i++) sum+=a[2*i+1];
  cout << sum;
  return 0;
}

Measured memory_bytes: 2560
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define gcd __gcd
#define F first
#define B begin()
#define E end()
#define ln length()
#define sz size()
#define S second
#define em empty()
#define mp make_pair
#define pb push_back
#define pq priority_queue
#define um unordered_map
#define us unordered_set
#define lb lower_bound
#define ub upper_bound
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define sbits(a) __builtin_popcount(a)
#define lcm(a, b) ((a * b) / gcd(a, b))
#define nani(x) cerr << #x << " is " << x << endl;
#define adde(g, u, v) g[u].pb(v), g[v].pb(u);
#define addew(g, u, v, w) g[u].pb({ v, w }), g[v].pb({ u, w });
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define inf 10000000000
#define mod 1000000007

typedef long long ll;

const int N = 1e5 + 5;

int A[N];

int main()
{
    fast;

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

    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;

    for (int i = 0; i < s.ln; i++)
        cout << s[i] << t[i];
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	string str;
	cin >> str;
	int ans = 0;
	for(int i = 1; i < str.length(); i++) {
		if(str[i - 1] != str[i]) ans++;
	}
	cout << ans << endl;

	return 0;
}

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

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

    int n;
    cin>>n;

    int ans=0;
    int m=1;

    for(int i=0;i<n;i++)
    {
        int a;
        cin>>a;

        if(a==m)m++;
        else ans++;
    }

    if(m==1) cout<<-1<<"\n";
    else cout<<ans<<"\n";

    return 0;
}


Measured memory_bytes: 3664
#include<iostream>
#include<vector>
#include<string>
#include<list>
#include<stdio.h>
#pragma warning(disable : 4996)
using namespace std;

int main() {
	list<int>a;
	int b;
	scanf("%d", &b);
	for (int c = 0; c < b; c++) {
		string d;
		cin >> d;
		if (d == "insert") {
			int e;
			scanf("%d", &e);
			a.push_front(e);
		}
		else if (d == "deleteFirst")a.pop_front();
		else if (d == "deleteLast")a.pop_back();
		else {
			int g;
			cin >> g;
			auto h = a.end();
			for (auto k = a.begin(); k != a.end(); k++) {
				if ((*k) == g) { h = k; break; }
			}
			if (h != a.end())a.erase(h);
		}
	}
	for (auto k = a.begin(); k!=a.end(); k++) {
		printf("%d", (*k));
		if (k != --a.end())printf(" ");
		else printf("\n");
	}
}

Measured memory_bytes: 34416
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000000
using namespace std;

signed main(){
    int n; cin>>n;
    int ans=n;
    rep(i,n+1){
        int t=i,cc=0;
        while(t){
            cc+=t%6;
            t/=6;
        }
        t=n-i;
        while(t){
            cc+=t%9;
            t/=9;
        }
        ans=min(ans,cc);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  int n;
  cin >> n;
  int c = 0, four = 0;
  for(int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    if(tmp % 2 == 1) {
      c++;
    } else if(tmp % 4 == 0) {
      four++;
    }
  }
  if(c <= four || c == 0 || (n == c + four && c <= four + 1)) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <iterator>
#include <functional>
#include <vector>
#include <math.h>
#include <typeinfo>
using namespace std;


int main(void) {
	
	string a, b;
	cin >> a >> b;

	string tmp = a + b;
	int num = atoi(tmp.c_str());

	double ddd = sqrt(num * 1.0);
	int iii = ddd;

	string ans = "No";
	if (iii == ddd)
	{
		ans = "Yes";
	}

	cout << ans << endl;

	return 0;
}

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

#define rep(i,n) for(i=1;i<=n;i++)
#define Rep(i,n) for(i=0;i<n;i++)
#define For(i,a,b) for(i=a;i<=b;i++)

#define pb(x) push_back(x)
#define sz(x) x.size()

#define mem(ara,val) memset(ara,val,sizeof(ara))
#define eps 1e-9

#define si(x) scanf("%d",&x)
#define sii(x,y) scanf("%d %d",&x,&y)
#define siii(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sll(x,y) scanf("%lld %lld",&x,&y)
#define slll(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define ss(ch) scanf("%s",ch)
#define pi(x) printf("%d",x)
#define pii(x,y) printf("%d %d",x,y)
#define piii(x,y,z) printf("%d %d %d",x,y,z)
#define pl(x) printf("%lld",x)
#define pll(x,y) printf("%lld %lld",x,y)
#define plll(x,y,z) printf("%lld %lld %lld",x,y,z)
#define ps(ch) printf("%s",ch)
#define Afridi 0
#define NL printf("\n")
#define D(x) cout << #x << " = " << x << endl
#define DD(x,y) cout << #x << " = " << x << " " << #y << " = " << y << endl
#define Max 300005
#define PI 3.141592653589793
#define FI freopen("in.txt","r",stdin)
#define FO freopen("out.txt","w",stdout)
#define mod 1000000007
#define INF (LL)1e18

typedef long long LL;
typedef unsigned long long ULL;

using namespace std;

LL bigmod(LL b,LL p)
{
    if(p == 0)return 1;
    LL my = bigmod(b,p/2);
    my*=my;
    my%=mod;
    if(p & 1)my*=b,my%=mod;
    return my;
}
int setb(int n,int pos)
{
    return n=n | (1 << pos);
}
int resb(int n,int pos)
{
    return n=n & ~(1 << pos);
}
bool checkb(int n,int pos)
{
    return (bool)(n & (1 << pos));
}

LL n,dist[Max],par[Max],s[Max],m;
vector <LL> g[Max];


int main()
{
	//FI;
	LL i,x,y,j;
	sll(n,m);
	rep(i,m)
	{
		sll(x,y);
		g[x].pb(y);
		g[y].pb(x);
	}
	rep(i,n)
	{
		if( sz(g[i]) )
		{
			sort(g[i].begin(),g[i].end());
			reverse(g[i].begin(),g[i].end());
		}
	}
	LL flag = 0;
	Rep(i,sz(g[1]))
	{
		LL u = g[1][i];
		Rep(j,sz(g[u]))
		{
			LL v = g[u][j];
			if(v == n)
			{
				flag = 1;
			}
			break;
		}
		if(flag)break;
	}
	if(flag)puts("POSSIBLE");
	else puts("IMPOSSIBLE");
	return 0;
}


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

void solve(int64_t N)
{
    int64_t res = 1e13;
    for (int64_t x = 1; x * x <= N; x++)
    {
        if (N % x != 0)
            continue;
        int64_t y = N / x;
        res = min(res, x - 1 + y - 1);
    }
    cout << res << endl;
}

int main()
{
    int64_t N;
    cin >> N;
    solve(N);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
    long long int N,K,i,sum=0,a,b;
    long long int n[100001]={};
    scanf("%lld %lld",&N,&K);
    for(i=1;i<=N;i++){
        scanf("%lld %lld",&a,&b);
        n[a]+=b;
    }
    for(i=1;;i++){
        sum+=n[i];
        if(sum>=K) break;
    }
    printf("%lld\n",i);
    return 0;
}

Measured memory_bytes: 896
package main

import "fmt"

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func main() {
	var a, b, c, d int
	fmt.Scan(&a, &b, &c, &d)

	if b < c || d < a {
		fmt.Println(0)
	} else {
		fmt.Println(min(b, d) - max(a, c))
	}
}


Measured memory_bytes: 512
#include<stdio.h>

int main(){

int a[3]={0,0,0};
int x[10];
int i;

for(i=0;i<10;i++){
scanf("%d",&x[i]);
if(a[2]<x[i]){
	
   if(a[1]<x[i]){
   	
      if(a[0]<x[i]){
      a[2]=a[1];
	  a[1]=a[0];
	  a[0]=x[i]; 
	}
	
	else{
      a[2]=a[1];
	  a[1]=x[i];
		}	
   	}
   	else{
      a[2]=x[i];
   		}
   		    	
	}
	}


for(i=0;i<3;i++){
printf("%d\n",a[i]);
}
return 0;
	}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#define int long long
#define pb emplace_back
#define mp make_pair
#define mt make_tuple
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define revrep(i,n) for(long long i=n-1;i>=0;i--)
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define osit ostream_iterator<int> output (cout," ")
#define endl '\n'
#define f first
#define s second
#define PI 3.141592653589793
#define MOD 1000000007
#define set0(x) memset(x,0,sizeof(x))
#define set1(x) memset(x,1,sizeof(x))
using namespace std;
typedef vector<int> vi;
typedef list<int> li;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef tuple<int, int, int> iii;
template<typename T> T gcd(T a,T b){if(a==0) return b; return gcd(b%a,a);}
template<typename P> P dectobin(P a){if(a==0)return 0; else return(a%2 + 10*dectobin(a/2));}
template<typename Y> Y bintodec(Y a){int ans=0,b=1,t=a; while (t){int ld=t%10; t/=10;ans+=ld* b;b=b*2;} return ans; }
template<typename H> H modExp(H x, H n){ int r=1; while(n>0){if(n%2==1){r=(r*x)%MOD;}x=(x*x)%MOD;n/=2;}return r;}
template<typename T> T isPowerOfTwo(T x){return x && (!(x & (x - 1)));}	
template<typename T> T lcm(T a,T b) {return a*b/gcd(a,b);}
//template<typename T> T extendedEuclid(T A,T B){if(B==0){d=A; x=1;y=0;}else{ extendedEuclid(B,A%B);int temp=x; x=y; y=temp-(A
//B)*y;}}
int32_t main(){
	boost;osit;
	int l,r,a,b;
	cin>>l>>r;
	if(l==2019 || r==2019){
		cout<<0;
		return 0;
	}
	else if(l<2019 && r<2019){
		int minn=100000000;
		rep(i,l,r){
			rep(j,i+1,r+1){
				int k=(i*j)%2019;
				if(k<minn) {minn=k; a=i; b=j;}
			}
		}
	}
	else if(l>2019 && r>2019){
		int p=0;
		rep(i,l,r+1){
			if(i%2019==0) {p=1; cout<<0; return 0;}
		}
		if(p==0){
			int minn=100000000;
			rep(i,l,r){
			rep(j,i+1,r+1){
				int k=(i*j)%2019;
				if(k<minn) {minn=k; a=i; b=j;}
			} }
		}
	}
	else if(l<2019 && r>2019){
		cout<<0;
		return 0;
	}
	cout<<(a*b)%2019;
	return 0;
}

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

void four(int n);

int main(){
	int n;
	while(1){
		cin >> n;
		if(n == -1) break;
		four(n);
		cout << endl;
	}
}

void four(int n){
	if(n / 4 == 0){
		cout << n;
	}
	else {
		four(n/4);
		cout << n % 4;
	}
	return;
}

Measured memory_bytes: 1160
A=[list(map(int,input().split())) for i in range(3)]
A1=list(zip(*A))
A2=[A[0][0], A[1][1], A[2][2]]
A3=[A[2][0], A[1][1], A[0][2]]
N=int(input())
b=[int(input()) for i in range(N)]

count=0
for i in range(3):
  for j in range(3):
    if A[i][j] in b:
      count+=1
  if count==3:
    print('Yes')
    exit()
  else:
    count=0

for i in range(3):
  for j in range(3):
    if A1[i][j] in b:
      count+=1
  if count==3:
    print('Yes')
    exit()
  else:
    count=0

for i in range(3):
  if A2[i] in b:
    count+=1
if count==3:
  print('Yes')
  exit()
else:
  count=0
  
for i in range(3):
  if A3[i] in b:
    count+=1
if count==3:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, k;
    cin >> n >> k;
    int* cost = new int[n];
    vector<int> dp(n);
    for(int i =0; i < n; i++){
        cin >>cost[i];
        dp[i] = INT_MAX;
    }
    dp[0] = 0;
    for(int i = 1; i < n; i++){
        for(int j = i-1, count = 1; j >= 0 && count <= k; j--, count++){
            dp[i] = min(dp[j] + abs(cost[i] - cost[j]), dp[i]);
        }
    }
    cout<<dp[n-1]<<"\n";
    return 0;
}

Measured memory_bytes: 1024
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import math


def sieve_of_erastosthenes(num):
    input_list = [False if i % 2 == 0 or i % 3 == 0 or i % 5 == 0 else True for i in range(num)]
    input_list[0] = input_list[1] = False
    input_list[2] = input_list[3] = input_list[5] = True
    sqrt = math.sqrt(num)

    for serial in range(3, num, 2):
        if serial >= sqrt:
            return input_list
        for s in range(serial ** 2, num, serial): 
            input_list[s] = False

primeTable = sieve_of_erastosthenes((10**6))

while True:
    a,d,n = map(int,input().split())
    if a== 0 and d==0 and n==0:
        break
    count = 0
    while count != n:
        if primeTable[a]:
            count += 1
        a += d
    print(a-d)

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

int f[100001], n, m;
pair<int, pair<int, int> > p[300000];

inline void ad(int i, int x) { while (i <= m)f[i] += x, i += i & -i; }
inline int gt(int i) { int an = 0; while (i)an += f[i], i ^= i & -i; return an; }

int main(){
	scanf("%d%d", &n, &m);
	f(i, 0, n){
		int a, b;
		scanf("%d%d", &a, &b);
		p[i] = make_pair(b - a + 1, make_pair(a, b));
	}
	sort(p, p + n);
	int j = 0;
	f(i, 1, m + 1){
		while (j < n && p[j].first < i){
			ad(p[j].second.first, 1);
			ad(p[j].second.second + 1, -1);
			++j;
		}
		int an = n - j;
		for (int j = i; j <= m; j += i)an += gt(j);
		printf("%d\n", an);
	}
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(),v.end()

const int maxn = 5e5 + 100, maxlog = 27;
const ll inf = 2e18, mod = 1e9 + 7;

int n, k, p[maxn], q[maxn], seg[4 * maxn], deg[maxlog * maxn], vertcnt, ans[maxn];
pair<int, int> segE[maxlog * maxn];
vector<int> graph[maxn];
priority_queue<int, vector<int>, greater<int> > pq;
bitset<maxlog * maxn> vis;

inline void handle(int a, int b)
{
	if (segE[a].ff == -1)
		segE[a].ff = b;
	else
		segE[a].ss = b;
	deg[b]++;
}

void add(int u, int l, int r, int x)
{
	if (seg[u] != -1)
		handle(vertcnt, seg[u]);
	seg[u] = vertcnt++;
	//cerr << "ADD " << seg[u] << ' ' << l << ' ' << r << endl;
	if (r - l == 1)
	{
		//cerr << "ADD FINISHED TO " << x << endl;
		handle(seg[u], x);
		return;
	}
	handle(seg[u], vertcnt);
	int mid = (l + r) / 2;
	if (x < mid)
		add(2 * u, l, mid, x);
	else
		add(2 * u + 1, mid, r, x);
}

void connect(int u, int l, int r, int b, int e, int vert)
{
	if (seg[u] == -1)
		return;
	if (b <= l && r <= e)
	{
		graph[vert].pb(seg[u]);
		deg[seg[u]]++;
		//cerr << "CONNECT " << vert << " TO " << seg[u] << ' ' << l << ' ' << r << endl;
		return;
	}
	int mid = (l + r) / 2;
	if (b < mid)
		connect(2 * u, l, mid, b, e, vert);
	if (e > mid)
		connect(2 * u + 1, mid, r, b, e, vert);
}

void dfs(int u)
{
	if (vis[u])
		return;
	vis[u] = true;
	//cerr << "DFS " << u << endl;
	if (u < n)
	{
		for (int i : graph[u])
		{
			deg[i]--;
			if (!deg[i])
			{
				if (i < n)
					pq.push(i);
				else
					dfs(i);
			}
		}
	}
	else
	{
		int i = segE[u].ff;
		if (i != -1)
		{
			deg[i]--;
			if (!deg[i])
			{
				if (i < n)
					pq.push(i);
				else
					dfs(i);
			}
		}
		i = segE[u].ss;
		if (i != -1)
		{
			deg[i]--;
			if (!deg[i])
			{
				if (i < n)
					pq.push(i);
				else
					dfs(i);
			}
		}
	}
}

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

	memset(seg, -1, sizeof(seg));
	for (int i = 0; i < maxlog * maxn; i++)
		segE[i] = mp(-1, -1);

	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
		cin >> p[i];
		p[i]--;
		q[p[i]] = i;
	}
	/*for (int i = 0; i < n; i++)
		cerr << '_' << q[i];
	cerr << endl;*/

	vertcnt = n;
	for (int i = n - 1; i >= 0; i--)
	{
		int now = q[i];
		//cerr << "### NOW AT " << now << endl;
		int L = max(0, now - k + 1), R = min(n, now + k);
		connect(1, 0, n, L, R, now);
		add(1, 0, n, now);
	}

	for (int i = 0; i < vertcnt; i++)
		if (!deg[i])
		{
			if (i < n)
				pq.push(i);
			else
				dfs(i);
		}
	int now, ind = 0;
	while (!pq.empty())
	{
		now = pq.top();
		//cerr << "TOPOL SORT AT" << ' ' << now << endl;
		pq.pop();
		ans[now] = ++ind;
		dfs(now);
	}
	for (int i = 0; i < n; i++)
		cout << ans[i] << endl;
}



Measured memory_bytes: 244736
/*input
2
1 2 3 1
*/
#include<bits/stdc++.h>
using namespace std;
const int N=18;
const int mod=1e9 + 7;
#define int long long
#define pii pair<int, int>
#define f first
#define s second 
#define mp make_pair
int dp[(1<<N)][2], n, arr[(1<<N)];
struct comp
{
	bool operator()(int a, int b)
	{
		return (arr[a]>=arr[b]&&a!=b);
	}
};
signed main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	cin>>n;
	for(int i=0;i<(1<<n);i++) cin>>arr[i];
	dp[0][0]=0;dp[0][1]=-1;int ans=0;
	for(int i=1;i<(1<<n);i++)
	{
		set<int, comp> inds;inds.insert(i);
		for(int j=0;j<n;j++)
		{
			if((i&(1<<j))) 
			{
				int prev=(i^(1<<j));
				inds.insert(dp[prev][0]);
				if(dp[prev][1]!=-1) inds.insert(dp[prev][1]);
			}
		}
		dp[i][0]=(*inds.begin());
		inds.erase(inds.begin());
		dp[i][1]=-1;
		if(!inds.empty()) dp[i][1]=(*inds.begin());
		//if(i==(1<<n)-1) cout<<dp[i][0]<<" "<<dp[i][1]<<endl<<endl;
		ans=max(ans, arr[dp[i][1]] + arr[dp[i][0]]);cout<<ans<<endl;
	}
}

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

int main()
{
    map<string, int> d_map = {{"SUN", 0}, {"MON", 1}, {"TUE", 2}, {"WED", 3}, {"THU", 4}, {"FRI", 5}, {"SAT", 6}};
    string s;
    cin >> s;

    int n = d_map[s];
    int res;
    rep(i, 1, 8)
    if ((n + i)%7 == 0) res = i;
    cout << res << endl;
    return 0;
}

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

int strln(char* s){
    int i;
    while(s[i]!='\0'){
        i++;
    }
    return i;
}

int main(){
    char a[101];
    char b[101];
    scanf("%s",a);
    scanf("%s",b);
    int A=strln(a);
    int B=strln(b);
    if(A<B){
        printf("LESS\n");
    }
    else if(B<A){
        printf("GREATER\n");
    }
    else{
        for(int i=0;i<A;i++){
            if(a[i]<b[i]){
                printf("LESS\n");
                break;
            }
            if(b[i]<a[i]){
                printf("GREATER\n");
                break;
            }
            if(a[i]==b[i] && i==A-1){
                printf("EQUAL\n");
                break;
            }
        }
    }
    return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  int ans = -1;
  for (int i = 1; i <= 1009; i++) {
    if (a == i * 8 / 100 && b == i * 10 / 100) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repb(i, n) for(ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define reprb(i, a, b) for(ll i = (b)-1; i >= (a); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
const ld EPS = 1e-12L;
const ld PI = 3.1415926535897932385L;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ull x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class S, class T>inline bool chmax(S &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class S, class T>inline bool chmin(S &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

vvi adj;
// n, cut
vector<vector<ld>> dp;

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n, m;
    cin >> n >> m;
    vll s(m), t(m);
    adj.resize(n+1);
    dp.resize(n+1, vector<ld>(n+1, INF));
    rep(i, m){
        cin >> s[i] >> t[i];
        adj[s[i]].emplace_back(t[i]);
    }
    rep(i, n+1) dp[n][i] = 0;
    rep(cut, n){
        reprb(i, 1, n){
            if(i == cut){
                ld r = 0;
                ld ma = 0;
                for(auto&& e: adj[i]){
                    r += dp[e][cut];
                    chmax(ma, dp[e][cut]);
                }
                if(SZ(adj[i]) > 1)
                    chmin(dp[i][cut], (r-ma)/(SZ(adj[i])-1) + 1);
            }else{
                ld r = 0;
                for(auto&& e: adj[i]){
                    r += dp[e][cut];
                }
                chmin(dp[i][cut], r/SZ(adj[i]) + 1);
            }
        }
    }
    dump(dp);
    cout << *min_element(ALL(dp[1])) << endl;
    return 0;
}

Measured memory_bytes: 9984
#include <cstdio>
#include <cstdint>
#include <cstddef>
#include <cassert>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <queue>
#include <stack>

constexpr intmax_t  operator ""_jd(unsigned long long n) { return n; }
constexpr uintmax_t operator ""_ju(unsigned long long n) { return n; }
constexpr size_t    operator ""_zu(unsigned long long n) { return n; }
// constexpr ptrdiff_t operator ""_td(unsigned long long n) { return n; }

namespace detail {
template <typename Tp, size_t N>
std::vector<Tp> make_vector(
    std::vector<size_t>& sizes,
    typename std::enable_if<(N == 1), Tp const&>::type x
) {
  return std::vector<Tp>(sizes[0], x);
}
template <typename Tp, size_t N>
auto make_vector(
    std::vector<size_t>& sizes,
    typename std::enable_if<(N > 1), Tp const&>::type x
) {
  size_t size = sizes[N-1];
  sizes.pop_back();
  return std::vector<decltype(make_vector<Tp, N-1>(sizes, x))>(
      size, make_vector<Tp, N-1>(sizes, x)
  );
}
}  // detail::

template <typename Tp, size_t N>
auto make_vector(size_t const(&sizes)[N], Tp const& x) {
  std::vector<size_t> s(N);
  for (size_t i = 0; i < N; ++i) s[i] = sizes[N-i-1];
  return detail::make_vector<Tp, N>(s, x);
}

int main() {
  size_t n;
  scanf("%zu", &n);

  char buf[131072];
  scanf("%s", buf);
  std::string s = buf;

  s.erase(std::unique(s.begin(), s.end()), s.end());
  printf("%zu\n", s.length());
}


Measured memory_bytes: 512
import java.util.TreeSet
fun main(args: Array<String>) {
    val N = nextInt()
    val A = listOfInt()
    val B = LongArray(N)
    for ((i, v) in A.withIndex()) B[v - 1] = 1L + i
    val S = TreeSet<Long>()
    S.add(0L); S.add(1L + N)
    var ans = 0L
    for ((i, v) in B.withIndex()) {
        ans += (v - S.floor(v)!!) * (S.ceiling(v)!! - v) * (i + 1)
        S.add(v)
    }
    println(ans)
}
fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { it.toInt() }


Measured memory_bytes: 93452
//1 2 3 -1 // 2 3 2 -1
//5 4 3  1 // 5 4 5  1
//7 8 9 -1 // 9 10 10 -1
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long A,B,C,K;
    cin >> A >> B >> C >> K;
    if(K%2 == 0) {
        cout << A-B << endl;
    }
    else {
        cout << B-A << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <math.h>
#include <cmath>
#include <numeric>
#include <iomanip>


#define log(x) cout<<x<<endl
#define pb push_back
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
using namespace std;


// <<fixed<<setprecision(6)<<


int gcd(lint x, lint y){
  return y==0 ? x:gcd(y,x % y);
}


int combi(int n, int r){
  int num = 1;
  for(int i = 1; i <= r; i++){
    num = num * (n - i + 1) / i;
  }
  return num;
}


int main(){
  int n,m;
  int sum=0;
  cin>>n>>m;
  vector<int> l;
  for(int i=0;i<m;i++){
    int j;
    cin>>j;
    sum+=j;
    l.pb(j);
  }
  if(n<sum){
    cout<<"-1";
  }
  else if(n==sum){
    cout<<"0";
  }
  else{
    cout<<n-sum;
  }


}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
  long long N, Y;
  cin >> N >> Y;
  int x = -1, y = -1, z = -1;
  for (int a = 0; a <= N; ++a)
  {
    for (int b = 0; b <= N - a; ++b)
    {
      for (int c = 0; c <= N - a - b; c++)
      {
          long long sum = 10000 * a + 5000 * b + 1000 * c;
        if ((a+b+c)==N&&sum == Y)
          x = a, y = b, z = c;
      }
    }
  }
  cout << x << " " << y << " " << z << endl;
}


Measured memory_bytes: 256
from bisect import bisect

N = int(input())
aa = sorted(list(map(int,input().split())))
bb = sorted(list(map(int,input().split())))
cc = sorted(list(map(int,input().split())))

b_cost = [0]

for i,b in enumerate(bb):
  b_cost.append(N-bisect(cc, b)+b_cost[i])

ans = 0
for a in aa:
  idx = bisect(bb, a)
  ans += b_cost[-1]-b_cost[idx]
print(ans)

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

int main() {
    int n,m,x; cin >> n >> m >> x;
    int c[12] = {};
    int a[12][12] = {};
    for (int i = 0; i < n; i++) {
        cin >> c[i];
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }
    int res = 10000000;
    for (int i = 0; i < (1 << n); i++) {
        int current = 0;
        int aa[12] = {};
        for (int j = 0; j < n; j++) {
            if (i & (1 << j)) {
                current += c[j];
                for (int k = 0; k < m; k++) {
                    aa[k] += a[j][k];
                }
            }
        }
        bool master = true;
        for (int k = 0; k < m; k++) {
            if (aa[k] < x) {
                master = false;
                break;
            }
        }
        if (master) res = min(current, res);
    }
    if (res == 10000000) {
        cout << -1 << endl;
    } else {
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<vector>
using namespace std;
int main(void) {
	int input_num;
	vector<int> train_num;
	while (cin >> input_num) {
		if (input_num == 0) {
			cout << train_num.back() << endl;
			train_num.pop_back();
		}
		else{
			train_num.push_back(input_num);
		}
	}
	return 0;
}

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll n,x;
  cin >> n >> x;
  ll m[100];
  REP(i,n) cin >> m[i];
  sort(m,m+n);
  ll ans = n;
  REP(i,n) x -= m[i];
  ans += x/m[0];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#define pb push_back
#define mp make_pair
#define p1 first
#define p2 second
using namespace std;

int main()
{
    //freopen("a.inp","r",stdin);
    int r; cin >> r; cout << r * r * 3;
}


Measured memory_bytes: 256
using System;

namespace PriTestCa
{
    class Program
    {
        static void Main(string[] args)
        {
            int i = 0;
            while(true){
              
                int data = int.Parse(Console.ReadLine());
                if (data == 0)
                    break;
                i++;
                Console.WriteLine("Case {0}: {1}", i, data);
            }
      }
    }
}

Measured memory_bytes: 5760
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <limits>
#include <cmath>
#include <cassert>

using namespace std;
using ll = long long;

const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int sumA = 0;
    for(int i = 0; i < 4; i++)
    {
        int x; cin >> x;
        sumA += x;
    }
    int sumB = 0;
    for(int i = 0; i < 4; i++)
    {
        int x; cin >> x;
        sumB += x;
    }
    cout << (sumA > sumB ? sumA : sumB) << endl;
    return 0;
}




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



int main() {

  int N, X;
  cin >> N >> X;

  vector<int> L(N+1);
  for(int i=0; i<N+1; i++){
    cin >> L.at(i);
  }

  vector<int> D(N+1);
  int ans = 1;
  D.at(0) = 0;
  for(int i=1; i<N+1; i++){
    D.at(i) = D.at(i-1) + L.at(i-1);
    if(D.at(i) <= X) ans += 1;
    else break;
  }
  

  

  


  cout << ans << endl;
  
}


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

int main() {
  string S;
  cin >> S;
  string divide[4] = {"dream", "dreamer", "erase", "eraser"};
  reverse(S.begin(), S.end());
  for(int i=0; i<4; i++) reverse(divide[i].begin(), divide[i].end());

  bool can = true;
  for(int i=0; i<S.size();) {
    bool can2 = false;
    for(int j=0; j<4; j++) {
      string d = divide[j];
      if(S.substr(i,d.size()) == d) {
        can2 = true;
        i += d.size();
      }
    }
    if(!can2) {
      can = false;
      break;
    }
  }

  if(can) cout << "YES" << endl;
  else cout << "NO" << endl;
}

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

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct edge{
    ll to, cost;
};


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

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

vector<bool> IsPrime;
void sieve(size_t max){
    if(max+1 > IsPrime.size()){
        IsPrime.resize(max+1,true);
    } 
    IsPrime[0] = false;
    IsPrime[1] = false;

    for(size_t i=2; i*i<=max; ++i){
        if(IsPrime[i]){
            for(size_t j=2; i*j<=max; ++j){
                IsPrime[i*j] = false;
            }
        }
    }
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    ll n;
    cin>>n;
    ll a = 0, b = 0, c = 0, d = 0;
    for(ll i=0;i<n;++i){
        string s;
        cin>>s;
        if(s == "AC"){
            a++;
        }else if(s == "WA"){
            b++;
        }else if(s == "TLE"){
            c++;
        }else if(s == "RE"){
            d++;
        }
    }
    cout<<"AC x "<<a<<endl;
    cout<<"WA x "<<b<<endl;
    cout<<"TLE x "<<c<<endl;
    cout<<"RE x "<<d<<endl;

    return 0;
}

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

int main(){
    string n;
    cin >> n;
    int s = n.size();
    if(n[s-1] == '2' || n[s-1] == '4' || n[s-1] == '5' || n[s-1] == '7' || n[s-1] == '9'){
        cout << "hon" << endl;
    }else if(n[s-1] == '0' || n[s-1] == '1' || n[s-1] == '6' || n[s-1] == '8'){
        cout << "pon" << endl;
    }else{
        cout << "bon" << endl;
    }
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  int res = 0;
  for (int i = 1; i <= n; ++i) {
    auto s = to_string(i);
    res += s.size() & 1;
  }
  cout << res << '\n';
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int n,k,s;scanf("%d %d %d",&n,&k,&s);
    int cnt=0;
    //printf(">%d\n",(int)10e1);
    for(int i=0;i<n;i++){
        if(cnt==k){
            if(s==1000000000)printf("%d ",s-1);
            else printf("%d ",s+1);
        }else{
            printf("%d ",s);
            cnt++;
        }
    }
    printf("\n");
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define SpeeD ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define ll long long
#define endl '\n'
//pair<int, int> *p=new pair<int, int>[n];
//std::vector<pair<int,int>> vp;
//v.push_back(make_pair(x,y))
//pair<int, int> p[1000001];
//string *s=new string [n];
//int freq[e];
//freq[a[i]-'a']++; freq[a[i]]++;
using namespace std;
ll n, t, m, c1, c2, c, x, y, sum, mn = 999999999, avg, pos, dif, dis,k, mx, xi, yi, q;
const int MXN=1e7;

const int md=1e9+7;
ll dp [MXN];
ll pre[MXN];
bool prime[MXN];
bool vis [MXN];
bool PE ( ll x )
{
    for ( ll i = 2; i * i <= x; i+=1+(i&1))
    if ( x % i == 0 )
    return false;
    return true;
}
void sieve()
{
    memset(prime , 1 , sizeof prime);

    for ( ll i = 2; i * i <= MXN; i+=1+(i&1))
    if (prime[i])
    {
          for (ll j = i * i; j < MXN; j +=i)
         prime[j] = false;
    }
}

bool PR ( string s )
{
    int n = s.length();
    for ( ll i = 0; i < n / 2; i++ )
    if ( s[i] != s[n - i - 1] )
    return false;
    return true;
}


int main (void){
    SpeeD;
   cin >> n;
   cout << n +(n*n) + (n*n*n);





}







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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

int main(){

    string w;
    cin >> w;

    map<char, int> mp;
    for(int i = 0; i < (int)w.size(); i++){
        mp[w[i]]++;
    }
    bool ok = true;
    for(auto v: mp){
        if(v.second % 2 == 1) ok = false;
    }
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

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

int main(){
  string s;
  cin >> s;
  int num=0;
  for(int i=1;i<s.size()-1;i++){
    num++;
  }
  
  cout << s.at(0) << num << s.at(s.size()-1) << endl;
}


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

bool is(string str)
{
    auto t=str;
    reverse(begin(t),end(t));
    return str==t;
}

main()
{
    string s; cin>>s;
    int n=s.size();
    if(is(s) and is(s.substr(0,n/2)) and is(s.substr(n/2+1,n)))
    {
        cout << "Yes" << "\n";
    }
    else
    {
        cout << "No" << "\n";
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>

using namespace std;

#define ll long long
const int N = 105;

int n,a[N],maxn = -1,minn = 0x7fffffff;

int main(){
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		maxn = max(maxn,a[i]);
		minn = min(minn,a[i]);
	}
	cout << maxn - minn;
} 

Measured memory_bytes: 256
exception Error of string
let err s = raise (Error s)

let _ =
    let x = Scanf.scanf "%d" (fun x -> x) in
    let h = x / 3600 in
    let m = (x mod 3600) / 60 in
    let s = (x mod 60) in
    Printf.printf "%d:%d:%d\n" h m s


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

int main() {
  int n;cin>>n;
  vector<int> a(n);
  rep(i,n)cin>>a[i];
  int cnt=0;
  while(1){
    int ans=0;
    rep(i,n){
      if(a[i]%2!=0)continue;
      ans++;
      a[i]/=2;
    }
    if(ans!=n)break;
    cnt++;
  }
  cout<<cnt<<endl;
}

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

int main()
{
    int a,b,c,i,cnt=0;
    cin>>a>>b>>c;
    if(c<a)cout<<"0"<<endl;
    else {
        for(i=1;;i++){
            if((a*i)>c)break;
            cnt += b;
        }
        cout<<cnt<<endl;
    }
    return 0;
}


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

int main(){
    //体力がx以下となるかならないか？で二分探索.
    //体力s = -1は絶対false,体力s = INFは絶対trueとして。
    int N;cin>>N;
    vector<int> lst(N);
    rep(i,N)cin>>lst[i];
    ll min = -1;
    ll max = INF;
    while(min+1<max){
        ll mid = (min+max)/2;

        auto judge=[&](ll x){
            //体力がx以下となる場所が存在すればtrue
            //あり得る候補は1~100の座標のどれか。これは全探索。
            for(int i=1;i<101;i++){
                ll s = 0;
                rep(j,N){
                    s += pow(lst[j]-i,2);
                }
                if( s <= x){
                    return true;
                }
            }
            return false;
        };

        if(judge(mid)){
            max = mid;
        }else{
            min = mid;
        }
    }
    cout<<max<<endl;
    return 0;
}

Measured memory_bytes: 256
program AT5668;
 const
  sqrnd=1008208820;
 var
  i,m,n:longint;
  ssum,spum,x,y:int64;
 begin
  readln(m);
  ssum:=0;
  spum:=0;
  for i:=1 to m do
   begin
    readln(x,y);
    inc(ssum,x*y);
    inc(spum,y);
   end;
  writeln((ssum-1) div 9+spum-1);
 end.


Measured memory_bytes: 1324
import sys

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")


s=input()

if s[0] == s[1] or s[1] == s[2] or s[2] == s[3]:
    print('Bad')
else:
    print('Good')


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const int INF=1e7;
const LL LINF=1e18;

LL l[51][51];

LL combination(int a,int b){
    if(l[a][b]!=-1) return l[a][b];
    if(a==b) return 1;
    if(b==1) return a;
    return l[a][b]=(combination(a-1,b-1)+combination(a-1,b));
}

int main(){
    int N,A,B;
    cin >> N >> A >> B;
    LL v[N];
    memset(l,-1,sizeof(l));
    for(int i=0;i<N;i++){
        cin >> v[i];
    }
    sort(v,v+N);
    int count=0;
    double sum=0.0;
    int t=0;
    for(int i=N-1;i>=0;i--){
        if(v[N-A]==v[i]) count++;
        if(N-A<=i){
            sum+=v[i];
            if(v[N-A]!=v[i]) t++;
        }
    }
    double h=(double)sum/A;
    printf("%.30f\n",h);
    LL ans=0;
    if(v[N-1]==v[N-A]){
        for(int i=A;i<=min(B,count);i++){
            ans+=combination(count,i);
        }
    }   
    else ans=combination(count,A-t);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.stream.IntStream;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    try {
      int n = scanner.nextInt();
      int x = scanner.nextInt();
      int[] m = IntStream.range(0, n).map(i -> scanner.nextInt()).sorted().toArray();

      int ans = solve(n, x, m);
      System.out.println(ans);
    } finally {
      scanner.close();
    }
  }

  private static int solve(int n, int x, int[] m) {
    // 少なくとも1つ作らなくてはならないので、各1個づつの量を合計して引く
    // 個数はn個
    int sum = Arrays.stream(m).sum();
    int ans = n;
    x -= sum;

    // あらかじめ昇順にソートしてあるので、m[0]が一番少ない材料のお菓子
    // これを作れるだけ作るのが最大値
    int mini = m[0];
    ans += x / mini;

    return ans;
  }
}


Measured memory_bytes: 36592
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long A;
    string B;
    cin >> A;
    cin >> B;
    string S;
    for(int i = 0; i < B.size(); i++){
        if(B[i] != '.') S+=B[i];
    }
    long long C = atoll(S.c_str());
    cout << A*C / 100 << endl;
}

Measured memory_bytes: 3628
from fractions import gcd
a, b, k = map(int, input().split())

_gcd = gcd(a, b)

count = 0
for i in range(1, _gcd+1)[::-1]:
    if a % i == 0 and b % i == 0:
        count += 1
    if count == k:
        print(i)
        break


Measured memory_bytes: 5304
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,d[100],ans=0;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>d[i];
  }
  for(int i=0;i<n-1;i++){
    for(int j=i+1;j<n;j++){
      ans+=d[i]*d[j];
    }
  }
  cout<<ans<<endl;
  return(0);
}

Measured memory_bytes: 256