akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll, ll> P;
using VP = vector<P>;
using VVP = vector<VP>;
using VI = vector<ll>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const ll INF = 1LL << 61;
const ll mod = 1e9 + 7;

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int i, j;
    int n, m;
    cin >> n >> m;
    VI s(n);
    VI t(m);
    for (i = 0; i < n; i++) cin >> s[i];
    for (i = 0; i < m; i++) cin >> t[i];
    VVI dp(n, VI(m));
    if (s[0] == t[0])
        dp[0][0] = 2;
    else
        dp[0][0] = 1;
    for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++) {
            if (i == 0 && j == 0) continue;
            if (s[i] == t[j]) {
                if (i > 0 && j > 0)
                    dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
                else if (i > 0)
                    dp[i][j] = dp[i - 1][j] + 1;
                else
                    dp[i][j] = dp[i][j - 1] + 1;
            } else {
                if (i > 0 && j > 0)
                    dp[i][j] = dp[i - 1][j] + dp[i][j - 1] + mod - dp[i - 1][j - 1];
                else if (i > 0)
                    dp[i][j] = dp[i - 1][j];
                else
                    dp[i][j] = dp[i][j - 1];
            }
            dp[i][j] %= mod;
            // cout << i << j << " " << dp[i][j] << endl;
        }
    }
    ll ans;
    ans = dp[n - 1][m - 1];
    cout << ans << endl;
}

Measured memory_bytes: 34548
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("-1"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
#define bn(x) ((1<<x)-1)
#define newline puts("")
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 200005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;



int main() {
  string s;
  cin>>s;
  puts(sz(s) >= 4 && s.substr(0,4) == "YAKI"?"Yes":"No");
  return 0;
}






















Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
#define inf 1e18
#define mk make_pair
#define ld long double
#define mod 1000000007
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test ll t; cin>>t; while(t--)
ll power(ll a,ll n)
{
    ll p;
    if(n==0)
    {
        return 1;
    }
    p=power(a,n/2);
    p=p*p;
    if(n%2==1)
    {
        p=p*a;
    }
    return p;
}
int main()
{
    ll n;
    ll h,a;
    cin>>h>>a;
    ll ans=0;
    while(h>0)
    {
        h-=a;
        ans++;
    }
    cout<<ans<<'\n';
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09;

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

  ll n;
  cin >> n;
  ll tmp = n, sum = 0;
  while(tmp){
    sum += tmp % 10;
    tmp /= 10;
  }
  if(n % sum == 0) cout << "Yes";
  else cout << "No";
  return 0;
}


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

const int mo=int(1e9+7);
int n,m,k,f[4010][4010],s[4010][4010],ans;

void work()
{
	scanf("%d %d %d",&n,&m,&k);
	f[0][0]=1;
	for (int j=0; j<=m; j++)  s[0][j]=1;
	for (int i=1; i<=(n+m)/(k-1); i++)
		{
			for (int j=0; j<=m; j++)
				{
					f[i][j]=(s[i-1][j]+(j>=k?mo-s[i-1][j-k]:0))%mo;
					if ((j%(k-1)==m%(k-1))&&(i*(k-1)-j<n)&&((i*(k-1)-j)%(k-1)==(n-1)%(k-1)))
						ans=(0LL+ans+f[i][j]+mo-f[i-1][j])%mo;
				}
			s[i][0]=f[i][0];
			for (int j=1; j<=m; j++)
				s[i][j]=(f[i][j]+s[i][j-1])%mo;
		}
	printf("%d",ans);
}

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


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

	ll A = 1;
	ll B;
	int judge = 0;

	while(A<=1000){
		B = 0;
		while(B<=1000){
			if(A*A*A*A*A-B*B*B*B*B==X){
				judge++;
				cout << "\n" << A << " " << B;
				break;
			}
			else if(A*A*A*A*A+B*B*B*B*B==X){
				judge++;
				B = B*(-1);
				cout << "\n" << A << " " << B;
				break;
			}
			B++;
		}
		if(judge == 1)
			break;

		A++;
	}

	cin >> judge;
	
	return 0;	
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define int long long 
int32_t main(){
  int H,W;
  cin>>H>>W;
  if(H%3==0 || W%3==0) cout<<0;
  else{
    int ans=1000000000000;
  for(int i=1;i<=H;i++){
    int a1 = W*i;
    int a2 = (W/2)*(H-i);
    int a3 = H*W -a1-a2;
    ans=min(ans,max(a1,max(a2,a3))-min(a1,min(a2,a3)));
            }
            swap(H,W);
            for(int i=1;i<=H;i++){
    int a1 = W*i;
    int a2 = (W/2)*(H-i);
    int a3 = H*W -a1-a2;
    ans=min(ans,max(a1,max(a2,a3))-min(a1,min(a2,a3)));
            }
            cout<<min(ans,min(H,W));
  }
}

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

int main()
{
    int n, i, j, k,a=0,b=0,c=0,d=0;
    cin >> n;
    while(n--)
    {
        string s;
        cin >> s;
        k = s.size();
        if(s[0]=='B'&&s[k-1]!='A')
            b++;
        if(s[k-1]=='A'&&s[0]!='B')
            a++;
        if(s[k-1]=='A'&&s[0]=='B')
            d++;
        if(s[k-1]=='B'&&s[0]=='A'&&k==2)
            c++;
        if(k>2)
            for(i=0; i<k-1; i++)
            {
                if(s[i]=='A'&&s[i+1]=='B')
                    c++;
            }
    }

    if(a>0&&b>0)c+=d+min(a,b);
    else{
        if(a>0||b>0){
            c+=d;
        }
        else if(d!=0)c+=(d-1);
    }
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main()
{
	int n;cin >> n;
	vector<pair<int,int>> ab(n);
	rep(i,n)
	{
		int foo,fooo;
		cin >> foo >> fooo;
		ab[i] = make_pair(foo,fooo);
	}
	pair<int,int> v;

	int ma=0;
	rep(i,n)
	{
		rep(j,n)
		{
			if(i==j)continue;
			v.first = ab[i].first-ab[j].first;
			v.second = ab[i].second - ab[j].second;
			int c=0;
			//cout<<v.first<<':'<<v.second<<endl;
			rep(ii,n)
			{
				pair<int,int> vv;
				vv.first = ab[ii].first+v.first;
				vv.second = ab[ii].second+v.second;
				rep(jj,n)
				{
					if(vv==ab[jj])c++;
				}
			}
			ma = max(ma,c); 
		}
	}

	cout<<n-ma<<endl;
	return 0;
}

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

struct edge{
  int to, cap, rev;
};

//from??????to??????????????????cap???????????°?????????????????????
void add_edge(vector<vector<edge> > &g, int from,int to,int cap){
  g[from].push_back((edge){to, cap, (int)g[to].size()});
  g[to].push_back((edge){from, 0, (int)g[from].size() - 1});
}

class FordFulkerson{
public:
  FordFulkerson(){};
  FordFulkerson(vector<vector<edge> >& _g):g(_g), flow_val(-1e9){};
  int MaxFlow(int s,int t){
    if(flow_val != -1e9)return flow_val;
    int flow=0;
    while(1){
      bool used[g.size()];
      memset(used, false, sizeof(used));
      int f = Dfs(s, t ,1e9, used);
      if(f==0)return flow_val = flow;
      flow+=f;
    }
  }
  int flow_val;
private:
  //?¢?????????????DFS??§??¢???
  int Dfs(int v,int t,int f, bool* used){
    if(v==t)return f;
    used[v] = true;
    for(int i=0;i < g[v].size();i++){
      edge &e = g[v][i];
      if(!used[e.to] && e.cap > 0){
        int d = Dfs(e.to, t, min(f, e.cap), used);
        if(d > 0){
          e.cap -= d;
          g[e.to][e.rev].cap +=d;
          return d;
        }
      }
    }
    return 0;
  }
  //s??????t???????????§???????±???????
  vector<vector<edge> > g;
};

int main(){
  int n, m;
  std::cin >> n >> m;
  vector<vector<edge> > g(n);
  for (int i = 0; i < m; i++) {
    int to, from, cost;
    std::cin >> from >> to >> cost;
    add_edge(g, from, to, cost);
  }
 FordFulkerson fd(g);
 std::cout << fd.MaxFlow(0, n - 1)<< std::endl;
  return 0;
}

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

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;

    vector<vector<int>> graph(n);
    vector<int> parent(n, -1);
    vector<int> dist(n, -1);
    queue<int> que;

    for (int i = 0; i < m; i++) {
        int tmp1, tmp2;
        cin >> tmp1 >> tmp2;
        tmp1--;
        tmp2--;

        graph[tmp1].push_back(tmp2);
        graph[tmp2].push_back(tmp1);
    }

    dist[0] = 0;
    que.push(0);
    parent[0] = 0;

    while (!que.empty()) {
        int v = que.front();
        que.pop();

        for (int next : graph[v]) {
            if (dist[next] == -1) {
                dist[next] = dist[v] + 1;
                que.push(next);
                parent[next] = v;
            }
        }
    }

    auto result = find(parent.begin(),parent.end(),-1);
    if(result == parent.end()){
        cout << "Yes" << endl;

        for(int i=1; i<n; i++){
            cout << parent[i]+1 << endl;
        }
    }else{
        cout << "No" << endl;
    }
    

    return 0;
}

Measured memory_bytes: 10724
#include <iostream>
#include <string>
#include <map>

using namespace std;

int main() {
    int n;
    string word;
    map<string, int> words;
    char last;

    cin >> n;
    for(int i=0;i<n;i++){
        cin >> word;
        if(i > 0 and word[0] != last){
            cout << "No";
            return 0;
        }
        last = word[word.size()-1];
        words[word] += 1;
    }
    for (const auto kv : words) {
        if(kv.second > 1) {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
    return 0;
}

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

#define endl '\n'

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

	int n, m;
	cin >> n >> m;

	vector<int> card(n, 1);
	vector<bool> red(n); red[0] = true;

	int a, b;
	while(m--)
	{
		cin >> a >> b; --a, --b;
		if(red[a]) red[b] = true;
		--card[a], ++card[b];
		if(!card[a]) red[a] = false;
	}

	cout << accumulate(red.begin(), red.end(), 0) << endl;

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;

int main(int argc, const char * argv[]) {
    int N;
    cin >> N;
    
    vector<int> a(N);
    
    for(int i=0;i<N;i++)
    {
        cin >> a[i];
    }
    
    int count = 0;
    bool check = true;
    while(check)
    {
        for(int i=0;i<N;i++)
        {
            if(a[i] % 2 == 0)
            {
                a[i] /= 2;
            }
            else
            {
                check = false;
                break;
            }
        }
        if(check)
        {
            count++;
        }
    }
    
    cout << count << endl;
    return 0;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int thousan, hundred, ten, one;
  thousan = N / 1000;
  N = N % 1000;
  hundred = N / 100;
  N = N % 100;
  ten = N / 10;
  N = N % 10;
  one = N;
    if ((thousan == hundred) && (hundred == ten)){
    cout << "Yes" << endl;
  }
  else if ((thousan == hundred) && (hundred == ten) && (ten == one)){
    cout << "Yes" << endl;
  }
  else if ((hundred == ten) && (ten == one)){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
n,m=map(int,input().split())
lst=[[] for i in range(n)]
cnt=[]
ans=m

for i in range(m):
  a,b=map(int,input().split())
  lst[a-1].append(b-1)
  lst[b-1].append(a-1)
  cnt.append([a-1,b-1])


for i in cnt:
  judge=False
  j=i[0]
  Q=[j]
  visited=[False]*n
  
  while Q:
      v=Q.pop(0)
      for k in lst[v]:
        if (v==i[0] and k==i[1]) or (v==i[1] and k==i[0]):
          continue
        if visited[k]==False:
              visited[k]=True
              Q.append(k)

  if visited[i[1]]==True:
      judge=True

  
  if judge:
    ans-=1


print(ans)

Measured memory_bytes: 68148
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
#include<functional>
#include<limits>
#include <unordered_map>
#include <numeric>
#include <array>
#include <queue>
#include <chrono>

using namespace std;
using  ull = unsigned long long int;

#define rep(i,n,m) for(long long int i=n;i<(long long int)(m);i++)
#define INF (1<<29)
#define MD 1000000007

int main() {

	ull n, cnt=0;
	cin >> n;

	vector<ull>monster(n+1);
	vector<ull>hero(n);

	rep(i, 0, n+1)cin >> monster[i];
	rep(i, 0, n)cin >> hero[i];

	rep(i, 0, n) {
		if (hero[i] > monster[i]) {
			hero[i] -= monster[i];
			cnt += monster[i];
			monster[i] = 0;
			if (hero[i] > monster[i+1]) {
				hero[i] -= monster[i+1];
				cnt += monster[i+1];
				monster[i+1] = 0;
			}
			else {
				monster[i+1] -= hero[i];
				cnt += hero[i];
				hero[i] = 0;
			}

			
		}
		else {
			monster[i] -= hero[i];
			cnt += hero[i];
			hero[i] = 0;
		}

	}

	cout << cnt << endl;

	return 0;
}



Measured memory_bytes: 1792
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        long n = long.Parse(Console.ReadLine());
        long t = 0, a = 0;
        long x = 1, y = 1;
        long s = 0;
        for (long i = 0; i < n; i++)
        {
            string[] cin = Console.ReadLine().Split();
            t = long.Parse(cin[0]);
            a = long.Parse(cin[1]);
            //while (s * t < x || s * a < y)
            //{
            //    s++;
            //}
            s = Math.Max((x + t - 1) / t, (y + a - 1) / a);
            //if (s * t < x || s * a < y) s++;
            x = s * t;
            y = s * a;
            s = 0;
        }
        Console.WriteLine(x + y);
    }
}

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

int N;

signed main() {
  cin >>N;
  vector<int> A(N), B(N);
  for(int i=0; i<N; i++) cin >> A[i] >> B[i];

  sort(A.begin(), A.end());
  sort(B.begin(), B.end());

  if (N%2) {
    int mn = A[N / 2];
    int mx = B[N / 2];
    cout << mx - mn + 1 << endl;
  }
  else {
    int mn = A[N / 2] + A[N / 2 - 1];
    int mx = B[N / 2] + B[N / 2 - 1];
    cout << mx - mn + 1 << endl;
  }
}


Measured memory_bytes: 4840
#! /usr/bin/env python3

import sys
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N = int(readline())


def num_divisors_table(n):
    table = [0] * (n + 1)

    for i in range(1, n + 1):
        for j in range(i, n + 1, i):
            table[j] += 1

    return table


table = num_divisors_table(N)

ans = 0
for i in range(N + 1):
    ans += i * table[i]

print(ans)


Measured memory_bytes: 146076
N = int(input())
S = input()
X = ["{:03d}".format(i) for i in range(1000)]
# print(X)
ans = 0
for x in X:
    now = 0
    for s in S:
        if s == x[now]:
            now += 1
        if now == 3:
            ans += 1
            break
print(ans)

Measured memory_bytes: 41180
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <list>
#include <string>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <iomanip> // setprecisionを使用するのに必要 cout << fixed << setprecision(15) << p でpを小数点以下15桁表示
using namespace std;
#define REPD(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) REPD(i, 0, n)
typedef long long ll;
#define fin(ans) cout << (ans) << '\n'
/*

*/
int main()
{
    int N;
    cin >> N;
    switch(N%10){
        case 2:
        case 4:
        case 5:
        case 7:
        case 9: fin("hon");break;
        case 0:
        case 1:
        case 6:
        case 8: fin("pon"); break;
        case 3: fin("bon"); break;
        default: break;
    }
    return 0;
}

Measured memory_bytes: 3092
#include "bits/stdc++.h"
#define ll long long
#define ALL(x) x.begin(),x.end()
using namespace std;

int main(){
  string s;
  cin>>s;

  string ten[3]={
    "Sunny",
    "Cloudy",
    "Rainy"
  };

  if(s==ten[0]){
    cout<<ten[1];
  }
    if(s==ten[1]){
    cout<<ten[2];
  }

  if(s==ten[2]){
    cout<<ten[0];
  }


}


Measured memory_bytes: 256
while True:
	try:
		n = int(raw_input())
		ans = 0
		for i in range(10):
			for j in range(10):
				for k in range(10):
					for l in range(10):
						if i+j+k+l == n:
							ans += 1
		print ans
	except EOFError:
		break

Measured memory_bytes: 6236
#include<iostream>
#include<string>
using namespace std;
struct Dice{
  int s[6];
  void roll(char c){
    int b;
    if(c=='E'){
      b=s[0];
      s[0]=s[3];
      s[3]=s[5];
      s[5]=s[2];
      s[2]=b;
    }
    if(c=='W'){
      b=s[0];
      s[0]=s[2];
      s[2]=s[5];
      s[5]=s[3];
      s[3]=b;
    }
    if(c=='N'){
      b=s[0];
      s[0]=s[1];
      s[1]=s[5];
      s[5]=s[4];
      s[4]=b;
    }
    if(c=='S'){
      b=s[0];
      s[0]=s[4];
      s[4]=s[5];
      s[5]=s[1];
      s[1]=b;
    }
  }
  int top() {
    return s[0];
  }
};
int main(){
  Dice d;
  for(int i=0;i<6;i++) cin >> d.s[i];
  string s;cin >> s;
  for(int i=0;i<s.size();i++) d.roll(s[i]);
  cout << d.top() << endl;
  return 0;
}


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

int main(){
    long A,B,C;cin>>A>>B>>C;
    if(B>=C){
        cout<<B+C<<endl;
    }else{
        if(C-B<=A){
            cout<<B+C<<endl;
        }else{
            cout<<A+2*B+1<<endl;
        }
    }
}


Measured memory_bytes: 256
//close stdin
//https://www.hackerrank.com/challenges/hackerrank-in-a-string/problem search
#include <bits/stdc++.h>
using namespace std;

int dp(vector<int>&arr,vector<int>&mem,int n){

    if(n<=0)
        return 0;
    if(n==1){
        mem[n]=abs(arr[n]-arr[n-1]) ;
        return mem[n];
    }

    if(mem[n]!=-1)
        return mem[n];

    
    int x1=abs(arr[n]-arr[n-1]) + dp(arr,mem,n-1);
    int x2=abs(arr[n]-arr[n-2]) + dp(arr,mem,n-2);
    mem[n]=min(x1,x2);
    return min(x1,x2);
}

int main(){
	//freopen ("t.txt","r",stdin);

    int n;
    cin>>n;

    vector<int> arr(n);

    vector<int> mem(n,-1);
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }

    cout<<dp(arr,mem,n-1);




return 0;
}


Measured memory_bytes: 7296
#include <cstdio>

typedef long long ll;
const ll MOD = 1e9 + 7;


ll fac[200001] = { 1 };
ll invfac[200001] = { 1 };

ll qpow(ll b, ll e) {
  ll c = 1;
  while (e) {
    if (e & 1LL)
      c = (c * b) % MOD;
    b = (b * b) % MOD;
    e /= 2LL;
  }
  return c;
}

ll comb(int n, int k) {
  ll tmp = fac[n] * invfac[k] % MOD;
  return tmp * invfac[n - k] % MOD;
}

int main()
{
  int h, w, a, b;
  scanf("%d%d%d%d", &h, &w, &a, &b);
  for (int i = 1; i <= h + w; ++i) {
    fac[i] = (fac[i - 1] * i) % MOD;
    invfac[i] = qpow(fac[i], MOD - 2LL);
  }

  ll ans = 0;
  for (int i = 1; i <= h - a; ++i) {
    ans = (ans + ((comb(i - 1 + b - 1, i - 1) * comb(h + w - b - i - 1, h - i)) % MOD)) % MOD;
  }
  printf("%lld", ans);
}

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

int main(){
  int N;
  cin >> N;
  int c, t;
  c = 0;
  t = N;
  while(t > 0){
    c += t % 10;
    t /= 10;
  }
  if(N % c == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

class Main{
  public static void main(String args[]) throws IOException{
   BufferedReader br = new BufferedReader(new InputStreamReader(System.in));


   int n = Integer.parseInt( br.readLine() );
   String[] string =  br.readLine().split(" ");
   int[] Progression = new int[n];

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

	   Progression[i] = Integer.parseInt( string[i] );

   }


   for(int k = 0; k < n; k++){

  	 System.out.print(Progression[k]);
  	 if(k < n-1){
           System.out.print(" ");
       }

   }
   System.out.println();


   int v;
   for(int i = 1; i < n ; i++ ){
     v =  Progression[i] ;
     int j = i - 1;



     while(j >= 0 &&  Progression[j]  > v){
    	 Progression[j + 1] = Progression[j];
         j--;
     }

     Progression[j + 1] = v;

     for(int k = 0; k < n; k++){

    	 System.out.print(Progression[k]);
    	 if(k < n-1){
             System.out.print(" ");
         }

     }


         System.out.println();


   }




 }
}

Measured memory_bytes: 30104
package main

import (
	"fmt"
)

func main() {
	var m1, d1, m2, d2 int
	fmt.Scan(&m1, &d1, &m2, &d2)
	if d2 == 1 {
		fmt.Println(1)
	} else {
		fmt.Println(0)
	}
}


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

int main(){
	int n;
	cin >> n;
	vector<int> p(n);
	vector<int> q(n);
	
	rep(i, n) cin >> p.at(i);
	rep(i, n) cin >> q.at(i);

	vector<int> a(n);
	rep(i, n) a.at(i) = i+1;

	map<vector<int>, int> mp;
	do{
		mp[a] = mp.size();
	}while(next_permutation(a.begin(), a.end()));

	int ans = abs(mp[p] - mp[q]);
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 5248
MOD=10**9+7
def facinv(N):
    fac,finv,inv=[0]*(N+1),[0]*(N+1),[0]*(N+1)
    fac[0]=1;fac[1]=1;finv[0]=1;finv[1]=1;inv[1]=1
    for i in range(2,N+1):
        fac[i]=fac[i-1]*i%MOD
        inv[i]=MOD-inv[MOD%i]*(MOD//i)%MOD
        finv[i]=finv[i-1]*inv[i]%MOD
    return fac,finv,inv

def COM(n,r):
    if n<r or r<0:
        return 0
    else:
        return ((fac[n]*finv[r])%MOD*finv[n-r])%MOD

def PER(n,r):
    if n<r or r<0:
        return 0
    else:
        return (fac[n]*finv[n-r]%MOD)

def p(r):
    return 1 if r%2 else -1

N,M=map(int,input().split())
fac,finv,inv=facinv(M)

ans=PER(M,N)**2%MOD
res=0
for r in range(1,N+1):
    f=COM(N,r)*PER(M,r)%MOD*(PER(M-r,N-r)**2%MOD)%MOD
    res=(res+(p(r)*f)+MOD)%MOD
print((ans-res+MOD)%MOD)

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

Measured memory_bytes: 256
n,c = map(int,input().split())
sortls = [list(map(int,input().split())) for i in range(n)]
sortls.sort(key = lambda k:(k[2],k[0]))
sortls.append([sortls[-1][0],sortls[-1][1],sortls[-1][2]+1])
count = 0;ls = [];start = -1;tf = False
while True:
    if tf:
        if sortls[count][1] == sortls[count+1][0] and sortls[count][2] == sortls[count+1][2]:
            pass
        else:
            ls.append([start,sortls[count][1],sortls[count][2]])
            tf = False
    elif sortls[count][1] != sortls[count+1][0] or sortls[count][2] != sortls[count+1][2]:
        ls.append(sortls[count])
    elif sortls[count][2] == sortls[count+1][2]:
        start = sortls[count][0]
        tf = True
    else:
        ls.append(sortls[count])
    count += 1
    if count > n-1:break

for i in range(len(ls)):
    ls[i][0] -= 0
ios = [0]*(10**5+5)
for i in range(len(ls)):
    ios[ls[i][0]] += 1
    ios[ls[i][1]+1] -= 1
ans = ios[0]
for i in range(1,len(ios)):
    ios[i] += ios[i-1]
    ans = max(ans,ios[i])
print(ans)

Measured memory_bytes: 72408
#include <cstdio>
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;
	int sum = k;
	for (int i = 0; i < n - 1; i++) {
		sum *= k - 1;
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
signed main(){
    long long x , a , b , i , j;
    cin >> x;
    
    for(a=-1000 ;a<=1000 ;a++){
        for(b=-1000; b<=1000 ;b++){
            if(a*a*a*a*a - b*b*b*b*b == x){
                i = a , j = b;
            }
        }
    }
    
    cout << i << ' ' << j << ' ' << endl;
    return(0);
}

Measured memory_bytes: 3656
# C
N = int(input())

res = 0
A_list = []
for i in range(N):
    A_list.append(int(input()))
for i in range(N):
    if i == 0:
        if A_list[i] != 0:
            res = -1
            break
    else:
        if A_list[i] > A_list[i-1] + 1:
            res = -1
            break
        elif A_list[i] == A_list[i-1] + 1:
            res += 1
        else:
            res += A_list[i]
print(res)

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

const int mxn = 2e5;
int a[mxn+11];

int main()
{
    int n,k;
    cin>>n>>k;
    for (int i = 0; i < n; i++)
    {
        scanf("%d",a+i);

    }
    sort(a,a+n);
    long long ans=0;
    for (int i = 0; i < n-k; i++)
    {
        ans+= a[i];
    }
    cout<<ans;
    

}

Measured memory_bytes: 1024
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
using lint = long long;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	lint L, R;
	cin >> L >> R;

	lint ans = numeric_limits<long long>::max();
	if (R - L >= 2018) ans = 0;
	else {
		for (lint i = L; i <= R; i++) {
			for (lint j = i + 1; j <= R; j++) {
				
				ans = min(ans, i*j % 2019);

			}
		}
	}

	cout << ans << "\n";
	
	return 0;
}

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

const int maxn = 100001;

int par[maxn];
int ranks[maxn];
int club[maxn];

void init(int n){
    for(int i=0;i<n;i++){
        par[i] = i;
        ranks[i] = 0;
        club[i] = -1;
    }
}

int find(int x){
    if(par[x] == x){
        return x;
    }
    else{
        return par[x] = find(par[x]);
    }
}

bool unite(int x,int y){
    x = find(x);
    y = find(y);
    if(club[x] != club[y] && club[x] != -1 && club[y] != -1){
        return true;
    }
    if(x==y) return false;

    if(ranks[x] < ranks[y]){
        par[x] = y;
        if(club[x] != -1)
            club[y] = club[x];
    }
    else{
        par[y] = x;
        if(club[y] != -1)
            club[x] = club[y];
        if(ranks[x] == ranks[y]) ranks[x]++;
    }
    return false;
}

int main() {

    int n,m,k;

    cin >> n >> m >> k;

    init(n);

    for(int i=0; i<k; i++){
        int select,a,b;
        cin >> select >> a >> b;

        if(select == 1){
            if(unite(a,b)){
                cout << i+1 << endl;
                return 0;
            }
        }
        else{
            int p = find(a);
            if(p  == -1){
                cout << i+1 << endl;
                return 0;
            }
            if(club[p] != -1 && club[p] != b){
                cout << i+1 << endl;
                return 0;
            }
            club[a] = b;
            club[p] = b;
        }
    }

    cout << "0" << endl;

    return 0;
}

Measured memory_bytes: 4280
#include <cstdio>
#include <cstring>
#include <map>

using namespace std;

char s[200'009];

int main() {
  scanf("%s", s);
  const int mod = 2019;
  int n = (int)strlen(s);
  int pw = 1;
  int sum = 0;
  map<int, int> w;
  w[0] = 1;
  long long ans = 0;
  for (int i = n - 1; i >= 0; --i) {
    sum = (sum + (int)(s[i] - '0') * pw) % mod;
    ans += w[sum];
    ++w[sum];
    pw = (pw * 10) % mod;
  }
  printf("%lld\n", ans);
}


Measured memory_bytes: 3580
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

N = INT()
A = LIST()

cnt = 0
for x in A:
	if x%2:
		cnt += 1

print("NO" if cnt%2 else "YES")

Measured memory_bytes: 17184
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int ans = INF;

int main(){
  int N,T;
	cin >>N>>T;
  rep(i,N){
    int c,t; cin >>c>>t;
    if(t<=T){ans = min(ans,c);}
  }
  if(ans == INF){cout<<"TLE"<<endl;}
  else{cout<<ans<<endl;}
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

string replaceOtherStr(std::string &replacedStr, std::string from, std::string to) {
    const ll pos = replacedStr.find(from);
    const ll len = from.length();
 
    if (pos == (ll)std::string::npos || from.empty()) {
        return replacedStr;
    }
 
    return replacedStr.replace(pos, len, to);
}


signed main() {
    ll s;
    cin >> s;
    if (s >= 30) {
        mes("Yes");
        re0;
    }
    
    
    mes ("No");
    
    
}

Measured memory_bytes: 3624
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <random>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;
using ll = long long;

ll n, k;

int main() {
    cin>>n>>k;
//    n = 10; k = 0;
    
    ll num = 0;
    for (ll b=k+1;b<=n;b++) {
        num += n/b*(b-k);
        auto lastFlow = n%b-k+(k > 0 ? 1 : 0);
        if (lastFlow > 0) num += lastFlow;
//        cerr<<num<<' '<<lastFlow <<endl;
    }
    cout<<num<<endl;
}





Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<map>
#include<algorithm>
using namespace std;
int main()
{
    int a,b,c,d;
    char n[100];
    while(~scanf("%s",n))
    {
        a=strlen(n);
        for(b=0;b<a;b++)
        {
            printf("x");
        }
        printf("\n");

    }

}

Measured memory_bytes: 128
a, b, c, x, y = map(int, input().split())

ans = min(x, y) * min(a + b, c * 2)

if x > y:
  ans += (x - y) * min(a, c * 2)
elif x < y:
  ans += (y - x) * min(b, c * 2)

print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
typedef long long ll;

int main(void) {
  ll i, n, cnt = 0, ans = 0;
  char s[200010];
  scanf("%s", s);
  n = strlen(s);
  for(i = 0; i < n; ++i) {
    if(s[i] == 'B') ++cnt;
    else ans += cnt;
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <vector>
#include <tuple>
#include <queue>
#include <stack>
#include <set>
#include <map>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
typedef long long ll;

int N,M,H,W,K,A,B;
string S;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
    cin>>N;
    vector<int> resbit(30,-1);
    int a,now;
    ll ans=0;
    int plus = 0;
    rep(i,N) {
        cin>>a;
        plus++;
        rep(j,30) {
            now = a % 2;
            if(now == 1){
                plus = min(plus,i-resbit.at(j));
                resbit.at(j) = i;
            }
	        a >>= 1;
            if(a==0) break;
        }
        ans += plus;
    }
    cout<<ans<<endl;
}

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

int main() {
  int N; cin>>N;
  int h[N+1];
  for(int i=1;i<=N;i++)cin>>h[i];
  int dp[N+1];
  dp[1]=0;

  for(int i=2;i<=N;i++){
    dp[i]=dp[i-1]+abs(h[i]-h[i-1]);
  if(i>2)dp[i]=min(dp[i],dp[i-2]+abs(h[i]-h[i-2]));

  }
  cout<<dp[N]<<endl;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
struct monster
{
	int ai,bi;
};
struct monster a[100010],b[100010];
bool cmp(monster a,monster b)
{
	return a.bi>b.bi;
}
int main()
{
	int n,h;
	cin>>n>>h;
	int i,maxv=-10000,k;
	for(i=1;i<=n;i++)
	{
		cin>>a[i].ai>>a[i].bi;
		if(a[i].ai>maxv)
		{
			maxv=a[i].ai;
			k=i;
		}
		if(a[i].ai==maxv)
		{
			if(a[i].bi<a[k].bi)
			{
				k=i;
			}
		}
	}
	int sum=0;
	for(i=1;i<=n;i++)
	{
		if(a[i].bi>=a[k].ai)
		{
			sum++;
			b[sum]=a[i];
		}
	}
	sort(b+1,b+1+sum,cmp);
	int num=0;
	for(i=1;i<=sum;i++)
	{
		num+=b[i].bi;
		if(num>=h)
		{
			cout<<i;
			return 0;
		}
	}
	int rest=h-num;
	if(rest%maxv==0)
	{
		cout<<sum+rest/maxv;		
	}
	else
	{
		cout<<sum+rest/maxv+1;
	}
	return 0;
}

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

using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n); i > 0; i--)
#define all(n) n.begin(), n.end()
#define print(n) cout << n << endl

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    ll n,p;
    string s;
    cin >> n >> p >> s;

    vector<ll> mods(p);
    ll m=0,order=1,ans=0;
    rep(i,n){
        if(p==2){
            if((s[i]-'0')%2==0) ans+=i+1;
        }else if(p==5){
            if((s[i]-'0')%5==0) ans+=i+1;
        }else{
            m = (m + order * (s[n-1-i] - '0')) % p;
            mods[m]++;
            order = (order*10)%p;
        }
        
    }
    if(p==2 || p==5){
        print(ans);
    }else{
        mods[0]++;
        rep(i,p){
            ans += mods[i]*(mods[i]-1)/2;
        }
        print(ans);
    }
    
    return 0;
}

Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto x:v)cerr<<x<<' ';cerr<<endl;
#define INF 1000000007
#define LINF 1000000000000000007
#define EPS 1e-9
typedef long long ll;

signed main(){
  int N;
  cin >> N;
  if(N-1){
    int A,B;
    cin >> A >> B;
    cout << A+B << endl;
  }
  else{
    puts("Hello World");
  }
}

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, double> pid;
typedef pair<double, int> pdi;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	string s;
	string ans;

	cin >> s;

	for (auto c : s)
	{
		if (c == 'B')
		{
			if (!ans.empty())
			{
				ans.pop_back();
			}
		}
		else
		{
			ans += c;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
// 2014/07/25 Tazoe

#include <iostream>
#include <string>
using namespace std;

int main()
{
	while(true){
		string x;
		cin >> x;

		if(x=="0")
			break;

		int sum = 0;

		for(int i=0; i<x.size(); i++){
			sum += (x[i]-'0');
		}

		cout << sum << endl;
	}

	return 0;
}

Measured memory_bytes: 1188
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int ans = (int) (Math.ceil((n-k)/(double)(k-1))+1);
        
        System.out.println(ans);
    }
}


Measured memory_bytes: 21844
"""D - 2017-like Number
"""

import math


class Sieve:
    """Sieve of Eratosthenes.

    List primes up to n.
    """

    def __init__(self, n):
        self.__prime = []
        self.__is_prime = [i >= 2 for i in range(n + 1)]

        for i in range(2, int(math.sqrt(n)) + 1):
            if self.__is_prime[i]:
                for j in range(i * i, n + 1, i):
                    self.__is_prime[j] = False

        for i in range(2, n + 1):
            if self.__is_prime[i]:
                self.__prime.append(i)

    def prime(self):
        return self.__prime

    def is_prime(self, n):
        return self.__is_prime[n]


class Fenwick:
    """Fenwick Tree implementation with 1-based index.

    Valid index: [1, N]
    """

    def __init__(self, N):
        self.fen = [0 for _ in range(N + 1)]

    def add(self, idx, val):
        while idx < len(self.fen):
            self.fen[idx] += val
            idx += idx & (-idx)

    def accum(self, idx):
        ret = 0
        while idx > 0:
            ret += self.fen[idx]
            idx -= idx & (-idx)
        return ret

    def sum(self, begin, end):
        return self.accum(end) - self.accum(begin - 1)


if __name__ == '__main__':
    Q = int(input())  # number of query
    A = [0 for _ in range(Q)]  # answer

    SIEVE = Sieve(10 ** 5)

    ACCUM = Fenwick(10 ** 5 + 1)
    for i in range(1, 10 ** 5 + 1):
        if SIEVE.is_prime(i) and SIEVE.is_prime((i + 1) // 2):
            ACCUM.add(i, 1)

    # print(ACCUM.fen)

    for i in range(Q):
        l, r = map(int, input().split())
        A[i] = ACCUM.sum(l, r)

    print('\n'.join(map(str, A)))


Measured memory_bytes: 65328
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n,a[200010],b[200010];
int main()
{
	cin>>n;
	for(int i=2;i<=n;i++)
	{
		cin>>a[i];
		b[a[i]]++;
	}
	for(int i=1;i<=n;i++)
	cout<<b[i]<<endl;
    return 0;
}

Measured memory_bytes: 5076
n = gets.chomp.to_i
k = gets.chomp.to_i

op_a = lambda{|c,k| c * 2 }
op_b = lambda{|c,k| c + k }

arr = [op_a,op_b]
ans = arr.repeated_permutation(n).to_a.map do |op_arr|
  op_arr.inject(1){|i,op| op[i,k]}
end.min

puts ans

Measured memory_bytes: 1916
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include<random>
#include<math.h>
#include<limits.h>
#include<iterator>
#include<queue>
#include<functional>
#define rep(i,a) for(int i=0;i<a;i++)
#define nrep(i,a,b) for(int i=a;i<b;i++)
#define mrep(i,a) for(int i=a;i>=0;i--)
#define ll long long
#define vl vector<ll> 
#define vvl vector<vector<ll> > 
#define vb vector<bool> 
#define vvb vector<vector<bool> > 
#define INF 11234567890123456789
using namespace std;

int main(){
	ll n, k; cin >> n >> k;
	ll ans = 0;
	rep(i, n){
		ll x; cin >> x;
		ans += 2*min(x, abs(k - x));
	}cout << ans << endl;
	return 0;
}

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

#define Rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PrintLn(X) cout << X << endl
int main(void)
{
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	int ans = a[0] + a[1];
	PrintLn(ans);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
	string s,ans,ans1;
	cin>>s;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='0')
		{
			string temp="0";
			ans+=temp;
		}
		else if(s[i]=='1')
		{
			string temp="1";
			ans+=temp;
		}
		else if(s[i]=='B')
		{
			if(ans.size()==0)
			{
				continue;
			}
			ans1="";
			for(int j=0;j<ans.size()-1;j++)
			{
				ans1+=ans[j];
			}
			ans=ans1;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
import sys


def LI():
    return list(map(int, input().split()))


N, A, B = LI()
if (B-A) % 2 == 0:
    print((B-A)//2)
    sys.exit()
a = 1
b = B-A
L = A+(b-a)//2
b = N
R = N-B+1
a = A+R
R += (b-a)//2
print(min(R, L))


Measured memory_bytes: 9060
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)

int main(){
 int a,b ;
 cin >> a >> b;
 int mx=-50000;
  mx= max(mx,a+b);
  mx= max(mx,a-b);
  mx= max(mx,a*b);
   cout << mx << endl;
  
     
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	long count = 0;

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

	private void run() {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		Card[] A = new Card[n];
		for (int i = 0; i < n; i++) {
			A[i] = new Card(scanner.next().charAt(0), scanner.nextInt(), i);
		}
		quicksort(A, 0, n - 1);
		boolean flag = true;
		int off;
		int[] I = new int[4];
		loop: for (int i = 0; i < n; i += off) {
			I[0] = A[i].idx;
			off = 1;
			while (i + off < n && A[i].num == A[i + off].num) {
				I[off] = A[i + off].idx;
				off++;
			}
			if (off != 1) {
				for (int j = 1; j < off; j++) {
					if (I[j - 1] > I[j]) {
						flag = false;
						break loop;

					}
				}
			}
		}
		if (flag)
			System.out.println("Stable");
		else
			System.out.println("Not stable");
		for (int i = 0; i < n; i++) {
			System.out.println(A[i].pic + " " + A[i].num);
		}

	}

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

	}

	private int partition(Card[] a, int p, int r) {
		Card work;
		int i = p - 1;
		for (int j = p; j < r; j++) {
			if (a[j].num <= a[r].num) {
				i++;
				work = a[i];
				a[i] = a[j];
				a[j] = work;
			}
		}
		work = a[i + 1];
		a[i + 1] = a[r];
		a[r] = work;
		return i + 1;
	}

	class Card {
		char pic;
		int num;
		int idx;

		public Card(char pic, int num, int idx) {
			this.pic = pic;
			this.num = num;
			this.idx = idx;
		}

		@Override
		public String toString() {
			return "[p=" + pic + ", n=" + num + ", id=" + idx + "]\n";
		}

	}
}

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

#define fi first
#define se second

const int N = 3030;
const long long mod = 1e9 + 7;

using namespace std;

int n;
int a[N];
long long d[N][N];

int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        ios_base::sync_with_stdio(0);

        cin >> n;
        for(int i = 1; i <= n; i++){
                cin >> a[i];
        }
        for(int i = n; i >= 1; i--){
                for(int j = i; j <= n; j++){
                        int tp = (n - j + i) % 2;
                        if(tp){
                                d[i][j] = max(d[i][j - 1] + a[j], d[i + 1][j] + a[i]);
                        }
                        else{
                                d[i][j] = min(d[i][j - 1] - a[j], d[i + 1][j] - a[i]);
                        }
                }
        }
        cout << d[1][n] << "\n";
}



Measured memory_bytes: 71936
using System;

public class Program
{
    public static void Main()
	{
        var input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        var N = input[0];
        var A = input[1];
        var B = input[2];

        var count = 0;

        for (var i=1; i<=N; i++)
        {
            var sum = FindSumOnDigits(i);
            
            if (sum >= A && sum <= B) count+=i;
        }
        Console.WriteLine(count);
    }

    static int FindSumOnDigits(int n)
    {
        var sum = 0;
        while(n >0)
        {
            sum += n % 10;
            n /= 10;
        }
        return sum;
    }
}


Measured memory_bytes: 13140