akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int n;
int l[210];

void solve(){
  cin >> n;
  rep(i,2*n){
    cin >> l[i];
  }
  sort(l,l+2*n);
  int ans=0;
  rep(i,n){
    ans+=l[2*i];
  }
  cout << ans << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a == b) {
    cout << c << endl;
  } else if (b == c) {
    cout << a << endl;
  } else if (c == a) {
    cout << b << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <array>
#include <vector>

using namespace std;

int main() {

  while ( true ) {
	int n;
	cin >> n;
	n /= 4;
	if ( n == 0 ) break;
	int sum = 0;
	for ( int i = 0; i < n; i++ ) {
	  int val;
	  cin >> val;
	  sum += val;
	}
	cout << sum << endl;
  }
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
//康托展开式
int jc[10];
void make_excel(int n){
     for(int i = 0; i < 10; ++i) jc[i] = 1;
     for(int i = 1; i <= n; ++i){
          jc[i] = jc[i - 1] * i;
     }     
}
int ct(vector<int> nums, int n){
     int ans = 0;
     for(int i = 1; i <= n; ++i){
          int flag = 0;
          for(int j = i + 1; j <= n; j++) if(nums[j] < nums[i]) flag++;
          ans += flag * jc[n - i];
     }
     return ans;
}
int main(){
     int n; cin >> n;
     vector<int> a;
     a.push_back(0);
     for(int i = 1; i <= n; ++i){
          int x; cin >> x;
          a.push_back(x);
     }
     vector<int> b;
     b.push_back(0);
     for(int i = 1; i <= n; ++i){
          int x; cin >> x;
          b.push_back(x);
     }
     make_excel(n); 
     int x = ct(a, n);
     int y = ct(b, n);
     cout << abs(x - y) << endl;
     return 0;
}

Measured memory_bytes: 256
//#include <stdio.h>
//  int main(){
// int a,b;
//    while(scanf("%d%d",&a,&b) != EOF){
//   int oa,ob;
//     oa = a;
//     ob = b;
//     while(a%b != 0 && b%a != 0){
//        if(a>b){
//          while(a>b){
//            a -= b;
//              }
//                }
//               else if(b>a){
//                while(b>a){
//                     b -= a;
//                     }
//                         } 
//}
//int x;
//if(a>b){
//x = b;
//}
//else{
//x = a;
//}
//int y= oa/x;
//y *= ob;
//printf("%d %d\n",x,y);
//}
//return 0;
//}
  #include <stdio.h>

  int main(){
    char str[20];
     int i,j;
	 i=0;
	 j=0;
	 scanf("%s",&str);
	 while(str[i]){
		 j++;
		 i++;
	 }
	 for(i=j;i>0;i--){
		 printf("%c",str[i-1]);
	 }
	 printf("\n");
	return 0;
}
       


 

Measured memory_bytes: 524
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007



def mat_mul(a, b) :
    I, J, K = len(a), len(b[0]), len(b)
    c = [[0] * J for _ in range(I)]
    for i in range(I) :
        for j in range(J) :
            for k in range(K) :
                c[i][j] += a[i][k] * b[k][j]
            c[i][j] %= m
    return c


def mat_pow(x, n):
    y = [[0] * len(x) for _ in range(len(x))]

    for i in range(len(x)):
        y[i][i] = 1

    while n > 0:
        if n & 1:
            y = mat_mul(x, y)
        x = mat_mul(x, x)
        n >>= 1

    return y


l, a, b, m = LI()
d0 = 0
ret = [[0], [a], [1]]
for i in range(1, 19):
    if 10 ** i - 1 - a < 0:
        continue
    d1 = min((10 ** i - 1 - a) // b + 1, l)
    mat = [[10 ** i, 1, 0], [0, 1, b], [0, 0, 1]]
    ret = mat_mul(mat_pow(mat, d1 - d0), ret)
    if d1 == l:
        break
    d0 = d1


print(ret[0][0])


Measured memory_bytes: 41968
def main():
    n,k=map(int,input().split())
    v=list(map(int,input().split()))
    ans=0
    for a in range(min(n,k)+1):
        for b in range(min(n,k)-a+1):
            chk=v[:a]+v[n-b:]
            chk.sort()
            x,s=0,sum(chk)
            while x<k-(a+b) and len(chk)>x:
                s-=min(0,chk[x])
                x+=1
            ans=max(ans,s)
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <set>

using namespace std;

using ll = long long;

int main()
{
    set<ll> s;

    int n;
    cin >> n;

    for (int i = 0, in; i < n && cin >> in; ++i)
    {
        if (s.find(in) == s.end())
        {
            s.emplace(in);
        }
        else
        {
            s.erase(in);
        }
    }

    cout << s.size() << endl;

    return 0;
}


Measured memory_bytes: 4864
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<cstdio>

using namespace std;

class CTeam{
public:
	int id;
	int solved;
	int rank;
	bool operator>(const CTeam &t) const{
		if( solved > t.solved ) return true;
		else return false;
	}
};

int main(void){
	int t = 1, rank;
	vector<CTeam> vTeam;
	
	while( true ){
		CTeam tmp;
		scanf("%d,%d", &tmp.id, &tmp.solved);
		if( tmp.id == 0 && tmp.solved == 0 ) break;
		vTeam.push_back( tmp );
	}
	
	sort(vTeam.begin(), vTeam.end(), greater<CTeam>());
	rank = 1;
	vTeam[0].rank = rank;
	for(unsigned int i = 1; i < vTeam.size(); i++){
		if( vTeam[i - 1].solved != vTeam[i].solved ) rank++;
		vTeam[i].rank = rank;
	}
	/*for(unsigned int i = 0; i < vTeam.size(); i++){
		cout << "ID:" << vTeam[i].id << " Solved:" << vTeam[i].solved << " Rank:" << vTeam[i].rank << endl;
	}*/
	while( true ){
		int cid;

		cin >> cid;
		if( cin.eof() ) break;

		for(unsigned int i = 0; i < vTeam.size(); i++){
			if( vTeam[i].id == cid ){
				cout << vTeam[i].rank << endl;
				break;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int min(int a,int b)
{
    if(a<b)
    {
        return a;
    }else{
        return b;
    }
}
int main()
{
    int n;
    scanf("%d",&n);
    int arr[n], sum=0;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
    }
    int dp[n];
    dp[0]=0;
    dp[1]=abs(arr[0]-arr[1]);
    for(int i=2;i<n;i++)
    {
        dp[i]=min(dp[i-2]+abs(arr[i-2]-arr[i]),dp[i-1]+abs(arr[i-1]-arr[i]));
    }

        printf("%d ",dp[n-1]);


    return 0;
}


Measured memory_bytes: 2492
def main():
  M=10**9+7
  r1,c1,r2,c2=map(int,input().split())
  n=r2+c2+2
  fac=[0]*(n+1)
  fac[0]=val=1
  for i in range(1,n+1):fac[i]=val=val*i%M
  f=lambda r,c:fac[r+c+2]*pow(fac[c+1],M-2,M)*pow(fac[r+1],M-2,M)-c-r-2
  print((f(r2,c2)-f(r2,c1-1)-f(r1-1,c2)+f(r1-1,c1-1))%M)
main()

Measured memory_bytes: 54128
N,K=map(int,input().split())
h=[None]*N
for i in range(N):
    h[i] = int(input())

minvalue = 10**9
h.sort()
for i in range(N-K+1):
    if abs(h[K-1+i]-h[i])<minvalue:
        minvalue = abs(h[K-1+i]-h[i])

print(minvalue)


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

int main(){
	int R, G, B, N;
	cin >> R >> G >> B >> N;
	int n, cnt;
	cnt = 0;
	for(int i=0; i<=N; i++){
		for(int j=0; j<=N-i; j++){
			n = N - i*R	- j*G;
			if(n >= 0 && n%B == 0){
				cnt++;
			}
		}
	}
	cout << cnt << endl;
	return 0;
}

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

using namespace std;

#define inf 1<<30
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define fn fill_n
typedef long long llong;
typedef unsigned long long ullong;
typedef pair<int, int> P;

int mini = inf;
int n,k;
vector<int> v;
void solve(int num){
	if(num >= n){
		mini = min(mini, num);
		return;
	}
	for(int i = 0; i < v.size(); i++){
		if(v[i] == 0 && num == 0) continue;
		else
			solve(num*10+v[i]);
	}

}

int main(){
	set<int> s = {0,1,2,3,4,5,6,7,8,9};
	cin >> n >> k;
	for(int i = 0; i < k; i++){
		int in;
		cin >> in;
		s.erase(in);
	}

	for(auto it = s.begin(); it != s.end(); it++)
		v.pb(*it);

	solve(0);
	cout << mini << endl;

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define p(s) cout<<(s)<<endl
#define REP(i,n,N) for(int i=n;i<N;i++)
#define RREP(i,n,N) for(int i=N-1;i>=n;i--)
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
#define F first
#define S second
typedef long long ll;
using namespace std;
const ll mod = 1e9+7;

int N,M;
char S[110];
set<char> s;
int main() {
    cin>>N;
    REP(i,0,N){
        cin>>S[i];
        s.insert(S[i]);
    }
    if(s.size()==3){
        p("Three");
    }else if(s.size()==4){
        p("Four");
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 15;
long long a[N];
int main(){
	int time;
//	scanf("%d",&time);
//	while(time--){		
//	}
    int n;
    scanf("%d",&n);
    long long ans=0;
    for(int i=0;i<n;i++){
    	scanf("%d",&a[i]);
	}
	sort(a,a+n);
	for(int i=0;i<n-1;i++)
	ans+=a[i];
	ans+=a[n-1]/2;
	printf("%lld\n",ans);
//	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#define inf 1000000000

using namespace std;

int n;
int p[100005];
int to[100005];
bool used[100005];
vector<int> G[100005];
int dist[100005];

int dfs(int v)
{
	used[v] = true;
	int u = v + p[v];
	
	if(p[v] == 0) to[v] = v;
	else if(used[u])to[v] = inf;
	else if(to[u] != 0) to[v] = to[u];
	else to[v] = dfs(u);
	
	used[v] = false;
	return to[v];
}

void bfs()
{
	for(int i = 1; i <= n; i++) dist[i] = inf;
	dist[1] = 0;
	
	queue<int> Q;
	Q.push(1);
	int v;
	while(Q.size()){
		v = Q.front();
		Q.pop();
		for(int i = 0; i < G[v].size(); i++){
			if(dist[G[v][i]] < inf) continue;
			dist[G[v][i]] = dist[v] + 1;
			Q.push(G[v][i]);
		}
	}
}

int main(void)
{
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> p[i];
	
	for(int i = 1; i <= n; i++) if(to[i] == 0) to[i] = dfs(i);
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= 6; j++){
			int v = min(i+j, n);
			if(to[v] == inf) continue;
			G[i].push_back(to[v]);
		}
	}
	
	bfs();
	cout << dist[n] << endl;
	
	return 0;
}


Measured memory_bytes: 12608
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <memory>
#include <cstring>
#include <cassert>
#include <numeric>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cctype>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#define REP2(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(S) (S).begin(), (S).end()
typedef long long ll;

bool larger(int a, int b, int c, int d){
  if (a * a + b * b >  c * c + d * d) return true;
  if (a * a + b * b == c * c + d * d && a > c) return true;
  return false;
}

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

  
  int H, W;
  while (cin >> H >> W && H + W > 0){

    int resH = 1000;
    int resW = 1000;
    REP2(h, 1, 1000){
      REP2(w, 1, 1000){
        if (h < w && larger(h, w, H, W) && larger(resH, resW, h, w)){
          resH = h;
          resW = w;
        }
      }
    }
    cout << resH << " " << resW << endl;
  }
  return 0;
}

Measured memory_bytes: 1192
import sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**6)
n,q=map(int,input().split())
g=[[] for i in range(n)]
for _ in range(n-1):
    a,b=map(int,input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)
add=[0]*n
for _ in range(q):
    a,b=map(int,input().split())
    add[a-1]+=b
st=set() ; v=0 ; s=add[0]
ans=[0]*n
def dfs(g,v,s):
    global ans,st
    if v not in st:
        st.add(v)
        ans[v]+=s
    else: return
    for p in g[v]:
        dfs(g,p,s+add[p])
dfs(g,v,s)
print(*ans)
        
        
    
    

Measured memory_bytes: 251416
<?php
list($r,$u,$n) = explode(" ",trim(fgets(STDIN)));
$l = 0;
$d = 0;
while($n > 0){
list($x,$y,$a) = explode(" ",trim(fgets(STDIN)));
if($a == 1){
$l = max($l,$x);
}elseif($a == 2){
$r = min($r,$x);
}elseif($a == 3){
$d = max($d,$y);
}else{
$u = min($u,$y);
}
--$n;
}
if($d >= $u || $l >= $r){
echo 0;
}else{
echo ($u - $d) * ($r - $l);
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int const N = 1e5 + 5;
int a[N];
int n, k;
int dp[N];
int oo = 1e9;
void iterative_dp(){
    dp[n] = 0;
    for(int i=n-2; i>=0; i--){
        dp[i] = oo;
        for(int j = 1; j<=k && i+j<n ; j++){
            dp[i] = min(dp[i], dp[i+j] + abs(a[i] - a[i+j]));
        }
    }
}

int main() {
#ifdef ONLINE_JUDGE
    ios::sync_with_stdio(false), cin.tie(0);
#endif
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    cin>>n>>k;
    for(int i=0; i<n; i++)
        cin>>a[i];
    iterative_dp();
    cout<<dp[0]<<'\n';
}


Measured memory_bytes: 4340
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<unordered_map>
using namespace std;
const int N=200010,mod=998244353;
int n,m,ans,c[N],dp[N],f[N];
char a[N];
int Add(int a,int b){
	return a+b>=mod?a+b-mod:a+b;
}
int Minus(int a,int b){
	return a<b?a-b+mod:a-b;
}
int dfs(int now,int flag){
	if(now==m){
		if(!flag)
			return 1;
		else{
			while(now<n){
				if((c[now%m]^((now/m)&1))<a[now]-'0')
					return 1;
				else if((c[now%m]^((now/m)&1))>a[now]-'0')
					return 0;
				now++;
			}
			return 1;
		}
	}
	if(!flag&&~dp[now])
		return dp[now];
	int ret=0;
	for(int i=0;i<=(flag?a[now]-'0':1);i++){
		c[now]=i;
		ret=Add(ret,dfs(now+1,flag&&i==a[now]-'0'));
	}
	if(!flag)
		dp[now]=ret;
	return ret;
}
int main(){
	scanf("%d%s",&n,a);
	for(int i=1;i<=n;i++)
		if(n%i==0&&((n/i)&1)){
			memset(dp,-1,sizeof(dp));
			m=i;
			int tmp=mod-f[i];
			f[i]=Add(f[i],dfs(0,1));
			for(int j=3;i*j<=n;j+=2)
				f[i*j]=Minus(f[i*j],f[i]);
			ans=(ans+2ll*i*f[i])%mod;
		}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 15232
// Problem : C - A x B + C
// Contest : AtCoder - AtCoder Beginner Contest 179
// URL : https://atcoder.jp/contests/abc179/tasks/abc179_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define ff         first
#define ss         second
#define endl       '\n'
#define pb         push_back
#define int        long long
#define vi         vector<int>
#define mii        map<int, int>
#define pii        pair<int, int>
#define all(x)     (x).begin(), (x).end()
#define fill(a,b)  memset(a, b, sizeof(a))
#define setbits(x) __builtin_popcountll(x)
#define rep(i,x,y) for(int i=(int)x; i<y; i++)
#define px(a)      for(auto x: a) cout<<x<<" "; cout<<'\n';
#define pxy(a,n)   rep(i,0,n) {px(a[i])};
const long long MOD=1e9+7,N=1e6+5;
int power(int x, unsigned int y)  
{  
    int res = 1;
    x = x % MOD;
    if (x == 0) return 0;
  
    while (y > 0)  
    { 
        if (y & 1)  
            res = (res*x) % MOD;
        y = y>>1;
        x = (x*x) % MOD;  
    }  
    return res;  
}

/*_________________________________________________________*/
int si[N];
void seive(){
	for(int i=1;i<N;i++){
		for(int j=i;j<N;j+=i) si[j]++;
	}
}
int solve()
{
	int n,ans=0;
	cin>>n;
	rep(i,1,n+1){
		ans+=si[n-i];
		//cout<<si[i]<<endl;
	}
	return ans;
}
int32_t main()
{	
	std::ios::sync_with_stdio(false); 
	cin.tie(NULL);
	cout.tie(NULL);
	seive();
	int t=1; 
	//cin>>t;
	while(t--) 
	//solve();
	cout<<solve()<<endl;
	//cout<<(solve()?"YES":"NO")<<endl;
}

Measured memory_bytes: 11460
#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t n;
  cin>>n;
  int64_t z=0;
  int64_t x=sqrt(n)/1;
  for(int i=0;i<x;i++){
    if(n%(x-i)==0){
     z+=n/(x-i);
      break;
    }
  }
  string s=to_string(z);
  cout<<s.size();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
void Main(){
    ll n;cin>>n;
    vector<ll> a(n+1,0);
    For(i,0,n-1){
        ll x;cin>>x;
        a[x]++;
    }
    For(i,1,n+1) cout<<a[i]<<endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

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

#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define unq(v) sort(v.begin(),v.end()),v.erase(unique(v.begin(),v.end()),v.end())
#define ll long long
#define pb push_back
#define fill(arr) memset(arr,0,sizeof(arr))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define pi acos(-1.00)
#define _ios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main()
{
    _ios;
    ll n,m,r;
    cin>>n>>m;
    while(m--)
    {
        cin>>r;
        n-=r;
    }
    if(n<0)cout<<-1<<endl;
    else cout<<n<<endl;
    return 0;
}



Measured memory_bytes: 3644
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        int c=sc.nextInt();
        if(a<b&&b<c){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 26256
H,W,D = map(int,input().split())
L = []
for i in range(H):
  L.append(list(map(int,input().split())))
Q = int(input())
query = []
for i in range(Q):
  query.append(list(map(int,input().split())))
P = [[0,0]]*(H*W)
for i in range(H):
  for j in range(W):
    P[L[i][j]-1] = [i,j]
dp = [0]*(H*W)
for i in range(D):
  dp[i] = 0
  cnt = i+D
  while cnt < H*W:
    dp[cnt] = dp[cnt-D]+abs(P[cnt][0]-P[cnt-D][0])+abs(P[cnt][1]-P[cnt-D][1])
    cnt = cnt+D
for j in range(Q):
  print(dp[query[j][1]-1]-dp[query[j][0]-1])

Measured memory_bytes: 42256
public class Main{public static void main(String[] g){java.util.Scanner s=new java.util.Scanner(System.in);int l=s.nextInt();int a=s.nextInt();int b=s.nextInt();int c=s.nextInt();System.out.println(l-(int)(Math.ceil(Math.max(a*1.0/c,b*1.0/s.nextInt()))));}}

Measured memory_bytes: 17360
#include <bits/stdc++.h>                                           
 
#define int long long
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector") 
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
 
 
using namespace std;
 
 
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;
typedef unsigned long long ull;         
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb; 
typedef long long ll;  
typedef double db;                         
 
 
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}, block = 555;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const int inf = 1e9, N = 2e5 + 48, mod = 1e9 + 7;
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;


int n, m, l, r, x, t[N << 2], add[N << 2], dp[N];
vpii gg[N];
vi g[N];


void push (int v) {
	if (add[v]) {
		add[v << 1] += add[v];
		add[v << 1 | 1] += add[v];
		t[v << 1] += add[v];
		t[v << 1 | 1] += add[v];
		add[v] = 0;
	}
}


void update (int l, int r, int x, int v = 1, int tl = 0, int tr = n) {
	if (l > r || l > tr || tl > r) 
		return;
	
	if (l <= tl && tr <= r) {
		t[v] += x;
		add[v] += x;
		return;
	}

	push(v);
	int tm = (tl + tr) >> 1;
	update(l, r, x, v << 1, tl, tm);
	update(l, r, x, v << 1 | 1, tm + 1, tr);
	t[v] = max(t[v << 1], t[v << 1 | 1]);
}

int get (int l, int r, int v = 1, int tl = 0, int tr = n) {
	if (l > r || tl > r || l > tr)
		return -INF;

	if (l <= tl && tr <= r) 
		return t[v]; 
	

	push(v);
	int tm = (tl + tr) >> 1;
	return max(get(l, r, v << 1, tl, tm), get(l, r, v << 1 | 1, tm + 1, tr));
}



main () {
	cin >> n >> m;
	while (m--) {
		cin >> l >> r >> x;
		g[l].pb(x);		
		gg[r + 1].pb({l, x});
	}


	forn (i, 1, n) {
		for (auto x : g[i]) 
			update(0, i - 1, x); 

		for (auto x : gg[i]) 
			update(0, x.f - 1, -x.s); 

		dp[i] = get(0, i - 1);			
		update(i, i, dp[i]);					
	}	
	

	cout << *max_element(dp, dp + 1 + n);	
}          
 

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

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	vector<pair<string, int>> v(n);
	for(auto &x:v) cin >> x.first >> x.second;
	string p; cin >> p;
	bool found = false; int ans = 0;
	for(int i=0;i<n;i++){
		if(v[i].first == p){
			found = true;
			continue;
		}
		if(found) ans += v[i].second;
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
	string s;
	int c = 0;
	while(cin >> s){
		bool a = true;
		for(int i=0;i<s.size()/2;i++) if(s[i]!=s[s.size()-i-1]) a = false;
		if(a) c++;
	}
	cout << c << endl;
}

Measured memory_bytes: 1184
#include <stdio.h>

#define MAX_N (50)

typedef struct{
    char suit;
    int value;
} Card;

Card Array1[MAX_N];
Card Array2[MAX_N];

static
void
BubbleSort( Card A[], int N )
{
    int i, j;
    for ( i = 0; i < N-1; i++ ) {
	for ( j = N-1; j > i; j-- ) {
	    if ( A[j-1].value > A[j].value ) {
		Card tmp = A[j-1];
		A[j-1] = A[j];
		A[j] = tmp;
	    }
	}
    }
}


static
void
SelectionSort( Card A[], int N )
{
    int i, j;
    for ( i = 0; i < N-1; i++ ) {
	int min_i = i;
	for ( j = i+1; j < N; j++ ) {
	    if ( A[min_i].value > A[j].value ) {
		min_i = j;
	    }
	}
	if ( min_i != i ) {
	    Card tmp = A[i];
	    A[i] = A[min_i];
	    A[min_i] = tmp;
	}
    }
}

static
void
printArray( Card A[], int N )
{
    int i;
    for ( i = 0; i < N; i++ ) {
	printf("%c%d%c", A[i].suit, A[i].value, (i == N-1) ? '\n' : ' ');
    }
}

static
bool
isStable( Card stable[], Card check[], int N )
{
    int i;
    for ( i = 0; i < N; i++ ) {
	if ( stable[i].value != check[i].value || stable[i].suit != check[i].suit ) {
	    return false;
	}
    }
    
    return true;
}


int main()
{
    int N;
    int i;
    scanf("%d", &N);

    for ( i = 0; i < N; i++ ) {
	Card c;
	scanf(" %c", &c.suit);
	scanf("%d", &c.value);
	Array1[i] = c;
	Array2[i] = c;
	// printf("%d: %c%d\n", i, c.suit, c.value);
    }

    BubbleSort( Array1, N );
    SelectionSort( Array2, N );
    printArray( Array1, N );
    printf("Stable\n");
    printArray( Array2, N );    

    if ( isStable( Array1, Array2, N ) ) {
	printf("Stable\n");
    }
    else {
	printf("Not stable\n");
    }

    return 0;
}

Measured memory_bytes: 1040
#include <bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
//#define int long long
#define gcd __gcd
const int inf = 0x3f3f3f3f;
const int maxn = 201110;
const int M = 1e9+7;
int n,m,ok;

int a[4];

signed main()
{
	for(int i = 0; i < 3; i++) 
	{
		cin>>a[i];
	}
	sort(a,a+3);
	if(a[0] == a[1] && a[1] != a[2]) ok = 1;
	if(a[2] == a[1] && a[1] != a[0]) ok = 1;
	if(ok) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

  bool ans = true;
  if (N % 2 == 1) {
    ans = false;
  }
  else {
    for (int i = 0; i < N/2; i++) {
      if (S[i] != S[i + N/2]) {
        ans = false;
        break;
      }
    }
  }
  cout << (ans ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
h,w = map(int,input().split())

s = [list('.'*(w+2))]
for _ in range(h):
    s.append(list('.'+input()+'.'))
s.append(list('.'*(w+2)))

for i in range(h):
    for j in range(w):
        if s[i+1][j+1] == '#':
            if s[i+2][j+1] == '.' and s[i][j+1] == '.' and s[i+1][j+2] == '.' and s[i+1][j] == '.':
                print('No')
                exit()
print('Yes')

Measured memory_bytes: 3064
n=gets.to_i
arr=gets.split.map(&:to_i)
num=0
for i in 0..n-1
  (n-1).downto(i+1) do |j|
    if(arr[j]<arr[j-1])
      arr[j],arr[j-1]=arr[j-1],arr[j]
      num+=1
    end
  end
end
puts arr.join(' ')
puts num

Measured memory_bytes: 8672
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX 300003
#define MOD 998244353
#define INF 1000000000000000

int main(){
  int H,W;
  cin>>H>>W;
  vector<vector<int>> A(H,vector<int>(W)),B(H,vector<int>(W));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>A.at(i).at(j);
    }
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>B.at(i).at(j);
    }
  }
  vector<vector<int>> C(H,vector<int>(W));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      C.at(i).at(j)=abs(A.at(i).at(j)-B.at(i).at(j));
    }
  }
  vector<vector<vector<bool>>> dp(H,vector<vector<bool>>(W,vector<bool>(6500,false)));
  dp[0][0][C.at(0).at(0)]=true;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(i>0){
        for(int k=0;k<6500;k++){
          int nk=k+C.at(i).at(j);
          if(nk<6500){
            dp[i][j][nk]=dp[i-1][j][k]|dp[i][j][nk];
          }
          nk=abs(k-C.at(i).at(j));
          dp[i][j][nk]=dp[i-1][j][k]|dp[i][j][nk];
        }
      }
      if(j>0){
        for(int k=0;k<6500;k++){
          int nk=k+C.at(i).at(j);
          if(nk<6500){
            dp[i][j][nk]=dp[i][j-1][k]|dp[i][j][nk];
          }
          nk=abs(k-C.at(i).at(j));
          dp[i][j][nk]=dp[i][j-1][k]|dp[i][j][nk];
        }
      }
    }
  }

  for(int i=0;i<6500;i++){
    if(dp[H-1][W-1][i]){
      cout<<i<<endl;
      break;
    }
  }
}


Measured memory_bytes: 7936
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <set>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

typedef long long ll;
typedef long long int llt;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

char dif = 'A' - 'a';

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin >> n >> s;
    vector<int> r(n, 0), l(n, 0);
    int sum = 0;
    for (int i = 0; i < n;i++){
        if(s[i]=='W')
            sum++;
        r[i] += sum;
    }
    sum = 0;
    for (int i = n; i >= 0; i--)
    {
        if(s[i]=='E')
            sum++;
        l[i] += sum;
    }
    int ans = MOD;
    rep(i,n){
        ans = min(ans, r[i] + l[i]);
    }
    cout << ans - 1 << endl;
    return 0;
}

Measured memory_bytes: 2964
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.PriorityQueue;

 
public class Main {
  public static void main(String[] args) {
    InputReader sc = new InputReader(System.in);
 
    int n = sc.nextInt();
    int[] numbers = new int[n];
    for(int i = 0; i < n; i++){
      numbers[i] = sc.nextInt();
    }

    boolean notok = true;
    int count = 0;
    while(notok){
      notok = false;
      for(int i = 0; i < n - 1; i++){
        if(numbers[i] > numbers[i+1]){
          notok = true;
          int keep = numbers[i];
          numbers[i] = numbers[i+1];
          numbers[i+1] = keep;
          count++;
        }
      }
    }

    for(int i = 0; i < n-1; i++){
      System.out.print(numbers[i]);
      System.out.print(" ");
    }
    System.out.println(numbers[n-1]);
    System.out.println(count);
  }
 
  
// LinkedList<Integer>[] setsu = new LinkedList[n];
// for(int i = 0; i < n; i++){
//   setsu[i] = new LinkedList<Integer>();
// } 

 //ここからテンプレ
  static class InputReader {
      private InputStream stream;
      private byte[] buf = new byte[1024];
      private int curChar;
      private int numChars;
      private SpaceCharFilter filter;

      public InputReader(InputStream stream) {
          this.stream = stream;
      }
 
      public int next() {
          if (numChars == -1)
              throw new InputMismatchException();
          if (curChar >= numChars) {
              curChar = 0;
              try {
                  numChars = stream.read(buf);
              } catch (IOException e) {
                  throw new InputMismatchException();
              }
              if (numChars <= 0)
                  return -1;
          }
          return buf[curChar++];
      }
 
      public String nextStr() {
        int c = next();
        while(isSpaceChar(c)){c = next();}
        StringBuffer str = new StringBuffer();
        do{
          str.append((char)c);
          c = next();
        }while(!isSpaceChar(c));
        return str.toString();
      }

      public int nextInt() {
          int c = next();
          while (isSpaceChar(c))
              c = next();
          int sgn = 1;
          if (c == '-') {
              sgn = -1;
              c = next();
          }
          int res = 0;
          do {
              if (c < '0' || c > '9')
                  throw new InputMismatchException();
              res *= 10;
              res += c - '0';
              c = next();
          } while (!isSpaceChar(c));
          return res * sgn;
      }
 
      public boolean isSpaceChar(int c) {
          if (filter != null)
              return filter.isSpaceChar(c);
          return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
      }
 
      public interface SpaceCharFilter {
          public boolean isSpaceChar(int ch);
      }
  }
}

Measured memory_bytes: 16992
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		
		final int a = sc.nextInt();
		final int b = sc.nextInt();
		final int C = sc.nextInt();
		
		final double h = Math.sin(Math.toRadians(C)) * b;
		final double rest_a = a - Math.cos(Math.toRadians(C)) * b;
		
		final double c = Math.sqrt(h * h + rest_a * rest_a);
		
		System.out.printf("%.7f\n%.7f\n%.7f\n", a * h / 2, a + b + c, h);
		
	}
}

Measured memory_bytes: 17188
#include<bits/stdc++.h>
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define range(i,l,h) for(int i=l;i<h;i++)
#define endl '\n'
#define I INT_MAX
#define L INT_MIN
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vi vector<int>
using namespace std;
using std::ios;
constexpr int MOD=1e9+7;
constexpr int mod=998244353;
ll cost[100005];
int main() 
{   fastio;
    memset(cost,0,sizeof cost);
    int n;
    cin>>n;
    vi a(n+1);
    range(i,1,n+1)cin>>a[i];
    cost[1]=0;
    cost[2]=abs(a[2]-a[1]);
    range(i,3,n+1) 
      cost[i]= min(cost[i-1]+abs(a[i]-a[i-1]), cost[i-2]+abs(a[i]-a[i-2]));
    cout<<cost[n];
}

Measured memory_bytes: 1408
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card {
    char suit;
    int value;
};

struct Card L[MAX / 2 + 2], R[MAX / 2 + 2];

void merge(struct Card A[], int n, int left, int mid, int right) {
    int i, j, k;
    int n1 = mid - left;
    int n2 = right - mid;
    for ( i = 0; i < n1; i++ ) L[i] = A[left + i];
    for ( i = 0; i < n2; i++ ) R[i] = A[mid + i]; 
    L[n1].value = R[n2].value = SENTINEL;
    i = j = 0;
    for ( k = left; k < right; k++ ) {
        if ( L[i].value <= R[j].value ) {
            A[k] = L[i++];
        } else {
            A[k] = R[j++];
        }
    }
}

void mergeSort(struct Card A[], int n, int left, int right) {
    int mid;
    if ( left + 1 < right ) {
        mid = (left + right) / 2;
        mergeSort(A, n, left, mid);
        mergeSort(A, n, mid, right);
        merge(A, n, left, mid, right);
    }
}

int partition(struct Card A[], int n, int p, int r) {
    int i, j;
    struct Card t, x;
    x = A[r];
    i = p - 1;
    for ( j = p; j < r; j++) {
        if ( A[j].value <= x.value ) {
            i++;
            t = A[i]; A[i] = A[j]; A[j] = t;
        }
    }
    t = A[i + 1]; A[i + 1] = A[r]; A[r] = t;
    return i + 1;
}

void quickSort(struct Card A[], int n, int p, int r) {
    int q;
    if ( p < r ) {
        q = partition(A, n, p, r);
        quickSort(A, n, p, q - 1);
        quickSort(A, n, q + 1, r);
    }
}

int main() {
    int n, i, v;
    struct Card A[MAX], B[MAX];
    char S[10];
    int stable = 1;
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ) {
        scanf("%s %d", S, &v);
        A[i].suit = B[i].suit = S[0];
        A[i].value = B[i].value = v;
    }
    
    mergeSort(A, n, 0, n);
    quickSort(B, n, 0, n-1);
    
    for ( i = 0; i < n; i++ ) {
        if ( A[i].suit != B[i].suit ) stable = 0;
    }
    
    if ( stable == 1 ) printf("Stable\n");
    else printf("Not stable\n");
    for ( i = 0; i < n; i++ ) {
        printf("%c %d\n", B[i].suit, B[i].value);
    }
    
    return 0;
}


Measured memory_bytes: 4040
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    string s; cin >> s;
    int c1 = 0, c2 = 0;
    for(auto c : s) {
        if(c == 'A') c1++;
        if(c == 'B') c2++;
    }

    if(c1 == 3 or c2 == 3) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}


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

int main(){
  string a,b,c;
  cin>>a>>b>>c;
  if(a.back()==b.front()&&b.back()==c.front()){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
  
 
}


Measured memory_bytes: 256
#include <iostream>
#include<cstdio>
#include<stdio.h>
using namespace std;

int main() {
	int h[100], w[100];
	int count = 0;
	while (true) {
		cin >> h[count];
		cin >> w[count];
		
		if (h[count] == 0 && w[count] == 0) {
			break;
		}
		count++;
		
	}
	
	for(int a =0;a<count;a++){
		for (int i = 0; i < h[a]; i++) {
			for (int j = 0; j < w[a]; j++) {
				if ((i + j) % 2 == 0) cout << '#';
				else {
					cout << '.';
				}
			}
			cout << endl;
		}
		cout << endl;
	}

	

	return 0;
}



Measured memory_bytes: 3076
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
//// NG!!
int main() {
  int B,N,M,K,X,Y,Z;
  cin >> N >> K;

  vector<unsigned long long> H(N);

  for(int i=0 ; i < N ; i++){
    cin >> H[i];
  }
  sort(H.begin(), H.end(), greater<int>());
  unsigned long long result = 0;
  for(int i = K ; i < N ; i++){
    result += H[i];
  }
  cout << result << endl;
  return(0);
}

Measured memory_bytes: 1920
N = int(input())

t = [int(x) for x in input().split()]
vSection = [int(x) for x in input().split()]

vPoint = [0]
for i in range(1, N):
	vPoint.append(min(vSection[i - 1], vSection[i]))
vPoint.append(0)

for i in reversed(range(1, N + 1)):
	if t[i - 1] < vPoint[i - 1] - vPoint[i]:
		vPoint[i - 1] = t[i - 1] + vPoint[i]


ans = 0
VE = 0
for i in range(N):
	VS = VE
	if VS + t[i] <= vPoint[i + 1]:
		VE = VS + t[i]
		ans += VS * t[i] + t[i] ** 2 / 2
	else:
		VE = vPoint[i + 1]
		sumT = sum(t[:i])
		a = VS - (0 if i == 0 else sumT)
		b = VE + sum(t[:i+1])
		y = (a + b) / 2
		if y >= vSection[i]:
			t1 = vSection[i] - VS
			t2 = vSection[i] - VE
			ans += VS * t1 + t1 ** 2 / 2 + vSection[i] * (t[i] - t1 - t2) + VE * t2 + t2 ** 2 / 2
		else:
			x = y - a
			ans += VS * (x - sumT) + (x - sumT) ** 2 / 2 + VE * (t[i] - (x - sumT)) + (t[i] - (x - sumT)) ** 2 / 2
			
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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;
}

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
#define pb push_back

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * g / b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}




const long double PI = 3.14159265359;
const int MAX_N = 100010;


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int a, b, c, d, e, f; cin >> a >> b >> c >> d >> e >> f;
	P ans;
	double now = -1.0;
	for (int i = 0; i * a * 100 <= f; i++) {
		for (int j = 0; (i + a + j * b) * 100 <= f; j++) {
			if (i + j == 0)continue;
			int w = (i*a + j * b) * 100;
			int ms = min(f - w, e*w / 100);
			for (int k = 0; k * c <= ms; k++) {
				int l = (ms - k * c) / d;
				int s = k * c + l * d;
				if (now < 100.0 * s / (s + w)) {
					now = 100.0*s / (s + w);
					ans = P(s + w, s);
				}
			}
		}
	}
	cout << ans.first << " " << ans.second << endl;
	return 0;
}

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

int main() {
    while (1) {
        string X;
        cin >> X;
        if (X == "0") break;
        int ans = 0;
        for (int i = 0; i < X.size(); i++) ans += X[i] - '0';
        cout << ans << endl;
    }
}


Measured memory_bytes: 3212
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define eb emplace_back
#define precision(n) cout << fixed << setprecision(n);
#define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}
int main()
{
    fast;
    int k,a,b;
    int f=0;
    cin>>k;
    cin>>a>>b;
    for(int i=a;i<=b;i++)
    {
        if(i%k==0)
        {
            f=1;
        }
    }
    if(f)
    {
        cout<<"OK"<<endl;
    }
    else
        cout<<"NG"<<endl;


return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X, Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define len(X) ((int)(X).size())
#define mod(n, m) (((n)%(m)+(m))%(m))
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 8;
int N;
int P[MAX_N];
int Q[MAX_N];

bool remained[MAX_N + 1];

int fact(int f) {
    int res = 1;
    for (int i = 1; i <= f; ++i) {
        res *= i;
    }
    return res;
}


int main() {

    cin >> N;
    rep(i, N) cin >> P[i];
    rep(i, N) cin >> Q[i];

    int a = 0;
    memset(remained, true, sizeof(remained));
    for (int i = 0; i < N; ++i) {
        int tmp = 0;
        for (int j = 1; j <= N; ++j) {
            if (remained[j]) {
                ++tmp;
            }
            if (P[i] == j) break;
        }
        a += fact(N - i - 1) * (tmp - 1);
        remained[P[i]] = false;
    }

    int b = 0;
    memset(remained, true, sizeof(remained));
    for (int i = 0; i < N; ++i) {
        int tmp = 0;
        for (int j = 1; j <= N; ++j) {
            if (remained[j]) {
                ++tmp;
            }
            if (Q[i] == j) break;
        }
        b += fact(N - i - 1) * (tmp - 1);
        remained[Q[i]] = false;
    }

    cerr << a << endl;
    cerr << b << endl;

    cout << abs(a - b) << endl;

    return 0;
}


Measured memory_bytes: 256
module WeightedDirectedGraph
  (Weight : sig
    type t
    val zero : t
    val ( + ) : t -> t -> t
    val compare : t -> t -> int
  end) :
sig
  val bellman_ford :
    (* 頂点数 *)
    int ->
    (* 辺のリスト *)
    ('v * 'v * Weight.t) list ->
    (* 始点 *)
    'v ->
    ('v -> [ `Weight of Weight.t | `Inf | `NegInf ])
end =
struct
  let bellman_ford n es s =
    (* 距離を覚えるやつ *)
    (* d に入っていない頂点への距離は無限大とみなす *)
    let d = Hashtbl.create n in
    (* 負閉路に含まれる頂点を覚えるやつ *)
    (* 負閉路に含まれている iff neg に含まれる *)
    let neg = Hashtbl.create n in
    Hashtbl.replace d s Weight.zero;
    for i = 0 to 2 * n - 1 do
      List.iter (fun (u, v, c) ->
        (* c は u から v への辺の重さ *)
        (* d.(v) <- min d.(v) (d.(u) + c) *)
        let open Weight in
        match Hashtbl.find d u with
        | exception Not_found -> () (* d.(u) は無限大 *)
        | du ->
            (* d.(v) > d.(u) + c *)
            if
              try 0 < compare (Hashtbl.find d v) (du + c)
              with Not_found -> true (* d.(v) は無限大 *)
            then begin
              Hashtbl.replace d v (du + c);
              if n - 1 <= i then
                Hashtbl.replace neg v ()
            end) es
    done;
    fun v ->
      if Hashtbl.mem neg v then `NegInf
      else try `Weight (Hashtbl.find d v) with Not_found -> `Inf
end

module G = WeightedDirectedGraph (struct
  type t = int
  let zero = 0
  let ( + ) = ( + )
  let compare x y = compare y x
end)

let () = Scanf.scanf "%d %d\n" (fun n m ->
  let abcs = Array.init m (fun _ -> Scanf.scanf "%d %d %d\n" (fun a b c -> a - 1, b - 1, c)) in
  match G.bellman_ford n (Array.to_list abcs) 0 (n - 1) with
  | `NegInf -> print_endline "inf"
  | `Weight c -> Printf.printf "%d\n" c)

Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


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

  string s;
  map<string, int> m;
  REP(i, N){
    cin >> s;
    m[s]++;
  }

  vector<pair<int, string>> v;
  for(auto i: m){
    v.emplace_back(i.second, i.first);
  }

  sort(ALL(v));

  int n = v.back().first;
  vector<string> ans;
  RREP(i, v.size()){
    if(v[i].first == n) ans.emplace_back(v[i].second);
  }


  sort(ALL(ans));
  REP(i, ans.size()){
    cout << ans[i] << endl;
  }


  return 0;
}

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

int main(){
  int N;
  int64_t A=2,B=1;
  cin >> N;
  if(N == 0){
    cout << A << endl;
  }
  else if(N == 1){
    cout << B << endl;
  }
  else if(N >= 2){
    
    for(int i=2;i<N;i++){
      if(i%2 == 0){
        A=A+B;
      }
      else if(i%2 == 1){
        B=A+B;
    }
  }
  int64_t L=A + B;
  cout << L << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string.h>
#include<map>
#include<queue>

using namespace std;

typedef pair<int,int> pii;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)
#define in(i,j,k) ((i)>=(j)&&(i)<=(k))


int main(){
	char s[1023],t[1023],*o;
	const char *a="apple",*p="peach",*n="nnnnn";
	gets(s);
	strcpy(t,s);
	o=s;
	while((o=strstr(o,a))!=NULL){
		strncpy(o-s+t,p,5);
		strncpy(o,n,5);
	}
	o=s;
	while((o=strstr(o,p))!=NULL){
		strncpy(o-s+t,a,5);
		strncpy(o,n,5);
	}
	puts(t);
	return 0;
}

Measured memory_bytes: 1104