akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

const int INF = 1 << 30;

class State
{
public:
  int cost, op;
  vector<int> tray;
  State(vector<int> _tray = vector<int>(), int _cost = 0, int _op = -1)
    :cost(_cost), op(_op)
  {
    tray = _tray;
  }

  bool operator < (const State& st) const
  {
    return this->cost > st.cost;
  }
};

inline int ntz(int bit)
{
  int res = __builtin_popcount((~bit)&(bit-1));
  if (res == 32)
    res = INF;
  return res;
}

int main()
{
  int n, m;
  while (cin >> n >> m) {
    if ((n|m) == 0)
      break;

    vector<int> tray(3, 0);
    for (int i = 0; i < tray.size(); ++i) {
      int num;
      cin >> num;
      for (int j = 0; j < num; ++j) {
	int bit;
	cin >> bit;
	tray[i] |= 1 << (n-bit);
      }
    }

    int ans = -1;
    State st, next;
    priority_queue<State> que;
    que.push(State(tray));
    const int FIN = (1 << n) - 1;
    while (!que.empty()) {
      st = que.top();
      que.pop();

      if (st.tray[0] == FIN || st.tray[2] == FIN) {
	ans = st.cost;
	break;
      }

      if (st.cost > m)
	break;

      int A = ntz(st.tray[0]), B = ntz(st.tray[1]), C = ntz(st.tray[2]);

      ++st.cost;
      // A -> B
      if (st.tray[0] != 0 && st.op !=  1 && A < B) {
	next = st;
	next.tray[0] ^= (1 << A);
	next.tray[1] |= (1 << A);
	next.op = 0;
	que.push(next);
      }

      if (st.tray[1] != 0) {
	// B -> A
	if (st.op != 0 && B < A) {
	  next = st;
	  next.tray[1] ^= (1 << B);
	  next.tray[0] |= (1 << B);
	  next.op = 1;
	  que.push(next);
	}

	// B -> C
	if (st.op != 3 && B < C) {
	  next = st;
	  next.tray[1] ^= (1 << B);
	  next.tray[2] |= (1 << B);
	  next.op = 2;
	  que.push(next);
	}
      }

      // C -> B
      if (st.tray[2] && st.op !=  2 && C < B ) {
	next = st;
	next.tray[2] ^= (1 << C);
	next.tray[1] |= (1 << C);
	next.op = 3;
	que.push(next);
      }
    }

    cout << ans << endl;
  }
  return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int a, b, c;
    cin >> a >> b >> c;
    if (a + b + c >= 22) cout << "bust" << endl;
    else cout << "win" << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include <string>
#include<cstdio>
#include<stack>
#include<cstring>
#include<vector>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define D(n,retu) REP(i,n){cin>>retu[i];}

using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) { return y ? gcd(y, x%y) : x; }
template<typename T>
void fill_all(T& arr, const T& v) {
	arr = v;
}
template<typename T, typename ARR>
void fill_all(ARR& arr, const T& v) {
	for (auto& i : arr) { fill_all(i, v); }
}

//------------------変数-----------------------//
ll n, k, a[300005], goukei = 0;
//-------------------関数----------------------//

int main() {
	cin >> n;
	REP(i, 100001) {
		goukei += i + 1;
		if (goukei >= n) { cout << i + 1 << endl; return 0; }
	}
}

Measured memory_bytes: 256
import heapq

N, M = map(int, input().split())
W = [[] for _ in range(100005)]
for i in range(N):
    A, B = map(int, input().split())
    W[A].append(B)

hq = []

ans = 0
for A in range(1, M+1):
    for B in W[A]:
        heapq.heappush(hq, -B)
    if hq:
        B = heapq.heappop(hq)
        ans -= B
print(ans)


Measured memory_bytes: 72352
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int d;
int main()
{
	cin>>d;
	switch(d)
	  {
		  case 25:cout<<"Christmas";break;
		  case 24:cout<<"Christmas Eve";break;
		  case 23:cout<<"Christmas Eve Eve";break;
		  case 22:cout<<"Christmas Eve Eve Eve";break;
	  }
	return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;//例: VVI dp(10, vector<int>(10, INF);
typedef priority_queue<int, vector<int>, less<int> > QUE_int;
const ll INF = pow(10, 12) + 1;//+1しないとREになる(out of rangeになるんかな?? )

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



ll func(ll H , vector<ll> &dp) {
	if (H == 1) return 1;
	if (H == 2) return 3;

	if (dp[H / 2] != INF) return 1 + 2 * dp[H / 2];
	dp[H/2] = 1 + 2 * func(H / 2,  dp);
  	return dp[H/2];
}

int main(void) {
	ll H;
	cin >> H;
	vector<ll> dp(50, INF);
	
  	ll num_binary = 0;
  
  	ll tmp_H = H;
  	while(tmp_H != 0){
      tmp_H /= 2;
      num_binary++;
    }
	
 	ll ans = 1;
  	for(int i = 0; i< num_binary ; i++){
      ans *= 2;
    }
  cout << ans-1 << endl;
	

}


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

using namespace std;

#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fi first
#define se second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fore(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)
#define fort(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define ford(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#ifdef BUG
#define bug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << ": " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " /";
    __f(comma + 1, args...);
}
#endif

template <class T> bool mini(T& a, T b) { return a > b ? (a = b, 1) : 0; }
template <class T> bool maxi(T& a, T b) { return a < b ? (a = b, 1) : 0; }

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vii> vvii;

const int INF = (int)1e9 + 7;

int main() {
#ifdef LOCAL
    freopen("CP.inp", "r", stdin);
//    freopen("CP.out", "w", stdout);
#endif // LOCAL
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, k; cin >> n >> k;
    vector<bool> f(10);
    fore(i, 0, k) {
        int x; cin >> x;
        f[x] = 1;
    }
    auto check = [&](int x) {
        while (x) {
            if (f[x % 10]) return 0;
            x /= 10;
        }
        return 1;
    };
    while (!check(n)) ++n;
    cout << n << '\n';
    return 0;
}


Measured memory_bytes: 256
import math 
D,G = map(int, input().split())
pc = [list(map(int, input().split())) for i in range(D)]

ans = 10000
for i in range(2**D):
    count = 0
    no = []
    s = 0
    for j in range(D):
        if (i >> j) & 1:
            count += pc[j][0]
            s += 100*(j+1)*pc[j][0] + pc[j][1]
        else:
            no.append(j)
    if s >= G:
        ans = min(ans, count)
    else:
        for j in no:
            t = s + 100*(j+1)*(pc[j][0] -1)
            if t >= G:
                ans = min(ans, count + math.ceil((G-s) /(100*(j+1))))
print(ans)

Measured memory_bytes: 9000
n, m, q = map(int, input().split())
A, B, C, D = [0]*q, [0]*q, [0]*q, [0]*q
for i in range(q):
   A[i], B[i], C[i], D[i] = map(int, input().split())

a = [1]
ans = 0
def dfs(a):
    global ans
    if len(a) == n+1:
        now = 0
        for i in range(q):
            if a[B[i]] - a[A[i]] == C[i]:
                now += D[i]
        ans = max(ans, now)
        return

    a.append(a[-1])
    while a[-1] <= m:
        dfs(a)
        a[-1] += 1
    a.pop(-1)

dfs(a)
print(ans)

Measured memory_bytes: 9200
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
struct team { ll name, time; };
bool comp(const team& a, const team& b) { return a.time<b.time; };
team t[1000000];
int main() {
    int n;
    while (scanf("%d",&n)) {
        if (!n) break;
        for (int i=0; i<n; i++) {
            scanf("%lld",&t[i].name);
            int a,b,c,d,e,f,g,h;scanf("%d%d%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f,&g,&h);
            t[i].time=(a+c+e+g)*60+b+d+f+h;
        }
        sort(t, t+n, comp);
        printf("%lld\n%lld\n%lld\n",t[0].name,t[1].name,t[n-2].name);
    }
}

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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

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

    if(s == "Sunny"){
        cout << "Cloudy" << endl;
    } else if(s == "Cloudy"){
        cout << "Rainy" << endl;        
    } else {
        cout << "Sunny" << endl;        
    }

    return 0;
}


Measured memory_bytes: 764
#!/usr/bin/env python3
import sys


def solve(S: str):
    if S == 'Sunny':
        print('Cloudy')
    elif S == 'Cloudy':
        print('Rainy')
    else:
        print('Sunny')
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define rep(a,b,c) for(int a=c;a<b;a++)
using namespace std;

int main(){
  int N,ans=0;cin>>N;
  int t[N+10],s[N+10];
    rep(i,N,0)cin>>t[i];
    rep(i,N,0)cin>>s[i];
  rep(i,N,0){
    int res=0;
    rep(j,i+1,0)res+=t[j];
    rep(k,N,i)res+=s[k];
    ans=max(ans,res);
  }
  cout<<ans<<endl;
}

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

int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
int gcd3(int x, int y, int z) {
  int v = gcd(x,y);

  return gcd(v, z);
}

int main() {
    int n;
    int sum = 0;
    scanf("%d", &n);

for (int i = 1; i <= n; i++) {
  /* code */
  for (int j = 1; j <= n; j++) {
    /* code */
    for (int k = 1; k <= n; k++) {
      /* code */
      sum += gcd3(i,j,k);
      }
    }
  }

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

  return 0;
}

Measured memory_bytes: 1736
n = int(input()) + 1
txy = [list(map(int, input().split())) for _ in range(n-1)]
# 初期条件
txy.insert(0, [0,0,0])
for i in range(n-1):
    # 現在地
    t_now = txy[i][0]
    x_now = txy[i][1]
    y_now = txy[i][2]
    # 目的地
    t = txy[i+1][0]
    x = txy[i+1][1]
    y = txy[i+1][2]
    if (t - t_now) % 2 == (x - x_now + y - y_now) % 2 and (t - t_now) >= abs(x - x_now) + abs(y - y_now):
        continue
    else:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 27380
inf = 10 ** 20
n, m = map(int, input().split())
a_list = []
for _ in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    a_list.append([a, b, c])
a_list[0][0] = 0
d = [-inf for _ in range(n)]
d[0] = 0
for i in range(m):
    a, b, c = a_list[i]
    d[b] = max(d[a] + c, d[b])
temp = d[-1]
for i in range(m):
    a, b, c = a_list[i]
    d[b] = max(d[a] + c, d[b])
if temp != d[-1]:
    print("inf")
else:
    print(d[-1])

Measured memory_bytes: 3444
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long int lli;

const int maxn = int(1e5)+5;

lli A[maxn], B[maxn], C[maxn], dp[maxn][3];

int main(void)
{
	lli n;
	scanf("%lld", &n);
	for(lli i = 0;i < n;i++) scanf("%lld", &A[i]);
	for(lli i = 0;i < n;i++) scanf("%lld", &B[i]);
	for(lli i = 0;i < n;i++) scanf("%lld", &C[i]);
	sort(A, A+n), sort(B, B+n), sort(C, C+n);

	for(lli i = 0;i < n;i++) dp[i][0] = i+1;

	for(lli i = 0;i < n;i++)
	{
		lli idx = lli(lower_bound(A, A+n, B[i])-A)-1;
		if(idx >= 0) dp[i][1] += dp[idx][0];
		if(i) dp[i][1] += dp[i-1][1];
	}

	for(lli i = 0;i < n;i++)
	{
		lli idx = lli(lower_bound(B, B+n, C[i])-B)-1;
		if(idx >= 0) dp[i][2] += dp[idx][1];
		if(i) dp[i][2] += dp[i-1][2];
	}
	printf("%lld\n", dp[n-1][2]);
}

Measured memory_bytes: 4992
#include<stdio.h>

#define MAX_N 200000

int n;
int a[MAX_N];

int main(void)
{
	int i;
	
	scanf( "%d", &n );
	
	for( i=0; i<n; i++ ) {
		scanf( " %d", &a[i] );
	}
	
	i=n-1;
        while(1) {
		printf( "%d", a[i] );
                i-=2;
                if ( i < 0 ) break;
                putchar( ' ' );
	}
	
	if ( n % 2 == 0 )
		i = 0;
	else
		i = 1;
	
	while( i<n) {
		printf( " %d", a[i] );
		i += 2;
	}
	
	putchar( '\n' );
	
	return 0;
}

Measured memory_bytes: 2816
<?php
while (fscanf(STDIN, "%d", $n) && $n) {
  $cnt = 0;
  for ($i = 1; $i < $n; $i++) {
    $sum = $i;
    for ($j = $i + 1; $j <= $n; $j++) {
      $sum += $j;
      if ($sum == $n) {
        $cnt++;
      } else if ($sum > $n) {
        break;
      }
    }
  }
  print $cnt . "\n";
}

Measured memory_bytes: 6548
#include <stdio.h>

int main(){
	int n, a, b;
	scanf("%d %d %d", &n, &a, &b);
	int sum = 0;
	for(int i = 1; i <= n; i++){
		int count = 0;
		int temp = i;
		while (temp != 0){
			count = count + temp % 10;
			temp /= 10;
		}
		if(count >= a && count <= b){
			sum += i;
		}
	}
	printf("%d", sum);
	return 0;
}

Measured memory_bytes: 1732
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bcs
{
    class Program
    {
        static void Main( string[] args ) {
            var ks = Console.ReadLine().Split( ' ' ).Select( x => Int32.Parse( x ) ).ToArray();

            var k = ks[0];
            var s = ks[1];

            int ans = 0;
            for (int x = 0; x <= k; ++x)
                for (int y = 0; y <= k; ++y)
                {
                    var z = s - x - y;
                    if (0<=z && z<=k)
                        ans += 1;
                }
            Console.WriteLine( ans );
        }
    }
}


Measured memory_bytes: 13396
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
using namespace std;
int main() {
	int H, W, ans = 0 ,v[2001][2001] = {}, k = 0, n = 0;
	char masu[2001][2001];
	cin >> H >> W;
	for (int i = 0; i < H; i++)
	{
		k = 0;
		n = 0;
		for (int j = 0; j < W; j++)
		{
			cin >> masu[i][j];
			if (masu[i][j] == '.')k++;
			else {
				for (int l = 0; l < k; l++) {
					v[i][n] += k;
					n++;
				}
				n = n + 1;
				k = 0;
			}
		}
		if (masu[i][W - 1] == '.') {
			for (int l = 0; l < k; l++) {
				v[i][n] += k;
				n++;
			}
			n = n + 1;
			k = 0;
		}
	}
	for (int i = 0; i < W; i++)
	{
		k = 0;
		n = 0;
		for (int j = 0; j < H; j++)
		{
			if (masu[j][i] == '.')k++;
			else {
				for (int l = 0; l < k; l++) {
					v[n][i] += k;
					n++;
				}
				n = n + 1;
				k = 0;
			}
		}
		if (masu[H - 1][i] == '.') {
			for (int l = 0; l < k; l++) {
				v[n][i] += k;
				n++;
			}
			k = 0;
		}
	}
	for (int i = 0; i < H; i++)
	{
		for (int j = 0; j < W; j++)
		{
			ans = max(v[i][j], ans);
			//cout << v[i][j] << " ";
		}
		//cout << endl;
	}
	cout << ans-1;
}

Measured memory_bytes: 19840
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod = 1e9 + 7;

int main(){
    ll n;
    cin>>n;
    vector<ll>arr(n);
    vector<vector<ll>>dp(n, vector<ll>(n, 0));
    vector<ll>temp(n);
    for(ll i = 0; i < n; i++){
        cin>>arr[i];
        //dp[i][i]=arr[i];
        temp[i]=arr[i];
    }
    // for(ll i = 0;i < n ; i++){
    //     for(ll j = i+1; j < n ;j++){
    //         ll ans = 1e18;
    //         for(ll k = i; k < j; k++){
    //             ans=min(ans, dp[i][k]+dp[k+1][j]);
    //         }
    //         dp[i][j]=ans;
    //     }
    // }
    for(ll i = 1 ; i < n; i++){
        temp[i]=temp[i-1]+temp[i];
    }
    for(ll i = n-1; i>= 0; i--){
        for(ll j = i+1; j<n; j++){
            ll ans = 1e18;
            for(ll k = i; k<j;k++){
                ans = min(ans, dp[i][k]+dp[k+1][j]+temp[j]-temp[i]+arr[i]);
            }
            dp[i][j] = ans;
        }
    }
    // for(int i = 0; i <  n; i++){
    //     for(int j= 0;j < n ;j++){
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    cout<<dp[0][n-1];
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int n,i,c=0;
  cin>>s;
  n=s.size();
  vector<int> a(n),m(n+1),mc(2019);
  a.at(0)=1;
  m.at(0)=0;
  mc.at(m.at(0))++;
  for(i=1;i<=n;i++) {
    if (i<n) a.at(i)=10*a.at(i-1)%2019;
    m.at(i)=(m.at(i-1)+a.at(i-1)*(s.at(n-i)-'0'))%2019;
    mc.at(m.at(i))++;
  }
  for(i=0;i<2019;i++) if (mc.at(i)>=2) c+=mc.at(i)*(mc.at(i)-1)/2;
  cout<<c<<endl;
}

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


int main(){
    long long int n, ans = 0;
    while (1){
	cin >> n;
	if (n == 0) break;
	ans = 0;
	while (n != 1){
	    if (n % 2 == 0) n /= 2;
	    else n = 3 * n + 1;
	    ans++;
	}
	cout << ans << endl;
    }
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")

#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007;

int main(){
  int n; cin >> n;
  string s = to_string(n);
  int digit = 0;
  rep(i,s.size()){
    digit += s.at(i)-'0';
  }
  if(n == 10 || n == 100 || n == 1000 || n == 10000 || n == 100000){
    cout << 10 << "\n";
  }else{
    cout << digit << "\n";
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    int main()
    {
     
        int n;
        cin>>n;
      double a[n],ans=0.0;
      for(int i=0;i<n;i++)
        cin>>a[i];
      sort(a,a+n);
      ans=(a[0]+a[1])/2;
      for(int i=2;i<n;i++)
      {
       ans=(ans+a[i])/2;
      } 
        cout<<ans;
      return 0;
    } 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define F first
#define S second
#define mod 1000000007
#define INF 9000000000000000000
signed main(void){
    int n;cin>>n;
    vector<int>V(n);
    rep(i,n)cin>>V[i];
    vector<int>Ans(n);int x=0;
    rep(i,n){
        if(i%2==0)x+=V[i];
        else x-=V[i];
    }
    Ans[0]=x;
    rep(i,n-1){
        Ans[i+1]=V[i]*2-Ans[i];
    }
    rep(i,n)cout<<Ans[i]<<' ';
}




Measured memory_bytes: 2816
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
# include <cstdlib>
# include <tuple>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2147483647;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr double HDINF = 50000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (c).erase(unique(ALL((c))),(c).end())
# define LOWER(s)    transform(ALL((s)),(s).begin(),TL<char>)
# define UPPER(s)    transform(ALL((s)),(s).begin(),TU<char>)
# define FOR(i,a,b)  for(LL i=(a);i<(b);i++)
# define RFOR(i,a,b) for(LL i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)




LL MOD = 1000000007;
LL combi(LL N_, LL C_) {
	const int NUM_ = 1010101;
	static LL fact[NUM_ + 1], factr[NUM_ + 1], inv[NUM_ + 1];
	if (fact[0] == 0) {
		inv[1] = fact[0] = factr[0] = 1;
		for (int i = 2; i <= NUM_; ++i) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
		for (int i = 1; i <= NUM_; ++i) fact[i] = fact[i - 1] * i%MOD, factr[i] = factr[i - 1] * inv[i] % MOD;
	}
	if (C_<0 || C_>N_) return 0;
	return factr[C_] * fact[N_] % MOD*factr[N_ - C_] % MOD;
}
LL hcomb(int P_, int Q_) { return (P_ == 0 && Q_ == 0) ? 1 : combi(P_ + Q_ - 1, Q_); }

LL modpow(LL a, LL n = MOD - 2) {
	LL r = 1;
	while (n) r = r*((n % 2) ? a : 1) % MOD, a = a*a%MOD, n >>= 1;
	return r;
}

int n, m, k;

int main() {
	cin >> n >> m >> k;
	LL ans = 0;
	for (int l = 0; l <= k; l++) {
		int r = k - l;
		LL num = combi(n + m + 2 * k, n + 2 * l);
		LL lk = 1, rk = 1;
		if (l)lk = (combi(n + 2 * l, l) - combi(n + 2 * l, l - 1) + MOD) % MOD;
		if (r)rk = (combi(m + 2 * r, r) - combi(m + 2 * r, r - 1) + MOD) % MOD;
		ans = (ans +(num*((lk*rk)%MOD))%MOD)%MOD;
	}
	cout << ans << endl;
	//system("pause");
}


Measured memory_bytes: 26792
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var sc = bufio.NewScanner(os.Stdin)

var n int

func main() {
	sc.Split(bufio.ScanWords)
	var n, q int

	n = nextInt()
	A := make([]int, n)
	for i := 0; i < n; i++ {
		A[i] = nextInt()
	}

	q = nextInt()
	for j := 0; j < q; j++ {
		m := nextInt()
		if solve(0, m, A) {
			fmt.Println("yes")
		} else {
			fmt.Println("no")
		}
	}

}

func solve(i int, m int, A []int) bool {
	if i >= len(A) {
		return false
	}
	if m == 0 {
		return true
	}
	if A[i] == m {
		return true
	}
	res := solve(i+1, m, A) || solve(i+1, m-A[i], A)
	return res
}



Measured memory_bytes: 1116
N = int(input())
tate = int(input())
yoko = int(input())
if N - tate == 0:
    tatea = 1
else:
    tatea = N - tate + 1
if N - yoko == 0:
    yokoa = 1
else:
    yokoa = N - yoko + 1
ans = tatea * yokoa
print(ans)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007
using namespace std;
long long int arr[100001][2];
vector<ll>vec[100001];

ll foo(int col,int curr,int parent)
{

    if(arr[curr][col] !=(-1)) return arr[curr][col];
    ll ans1 = 1;
    ll ans2 = 1;

    for(ll i=0;i<vec[curr].size();i++)
    {
        if(vec[curr][i]!= parent)
        {
            ans1 = (ans1 * foo(0,vec[curr][i],curr))%mod;
        }
    }
    if(col == 0)
    {
        for(ll i=0;i<vec[curr].size();i++)
        {
            if(vec[curr][i]!= parent)
            {
                 ans2 = (ans2 * foo(1,vec[curr][i],curr))%mod;
            }
        }
        ans1  = (ans1 + ans2)%mod;
    }

    arr[curr][col] = ans1;
    return ans1;
}
int main()
{
    ll n;
    cin>>n;

    for(ll i=1;i<n;i++)
    {
        ll x,y;
        cin>>x>>y;
        vec[x].push_back(y);
        vec[y].push_back(x);
        arr[i][0] = (-1);
        arr[i][1] = (-1);
    }

    arr[n][0] = (-1);
    arr[n][1] = (-1);


    cout<<(foo(0,1,-1)%mod)<<endl;
    //for(int i=1;i<=n;i++) cout<<i<<" "<<arr[i][0]<<" "<<arr[i][1]<<endl;
}



Measured memory_bytes: 14208
#include <bits/stdc++.h>
#define Task "C"

using namespace std;
const int maxN = 1e5 + 5;
int n, a[maxN];
pair<int,int> b[maxN];

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int val;
    cin >> n;
    for(int i = 1; i<=n; ++i){
        cin >> val;
        b[i] = {val, i};
    }
    sort(b+1,b+n+1);
    for(int i = 1; i<=n; ++i)
        cout << b[i].second << " ";
    return 0;
}


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

int main()
{
  int N;
  cin >> N;
  
  long long power = 1;
  long long tmp = pow(10, 9) + 7;
  for (int i = 1; i <= N; i++)
  {
    power = power * i % tmp;
  }
  
  cout << power << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		long answer = 0;
		for (int i = 0; i < N; i++) {
			answer+=input.nextLong();
		}
		System.out.println(answer-N);
	}
}

Measured memory_bytes: 25932
#include <algorithm>
#include <array>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <utility>

using namespace std;

#define E18 1000000000000000000

int main() {
  int n;

  cin >> n;

  deque<long long> values(n);

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

    if (values[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }

  long long res = 1;

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

    if (before > E18 / values[i]) {
      cout << -1 << endl;
      return 0;
    }

    res *= values[i];

    if (res > E18) {
      cout << -1 << endl;
      return 0;
    }
  }

  cout << res << endl;

  return 0;
}

Measured memory_bytes: 3900
from collections import deque
h, w = map(int, input().split())
grid = [[c == "." for c in input()] for i in range(h)]
q = deque()
q.append((0,0,1))
visited = set()
min_dist = 0
while q:
    y, x, d = q.popleft()
    # 訪問済み、黒マスならスキップ
    if (y,x) in visited or not grid[y][x]:
        continue
    visited.add((y,x))
    # 終了条件
    if y == h-1 and x == w-1:
        min_dist = d
        break

    for dy, dx in [[-1,0],[1,0],[0,1],[0,-1]]:
        yn = y + dy
        xn = x + dx
        if 0<=yn<h and 0<=xn<w:
            q.append((yn, xn, d+1))
if min_dist:
    white = sum(sum(i) for i in grid)
    #print(white, min_dist)
    print(white - min_dist)
else:
    print(-1)

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

using namespace std;

const int maxn=2e6+10;
int f[maxn],n,m,d[maxn],c[maxn];

int main() 
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i) {
		scanf("%d",&d[i]);
	}
	c[0]=m;
	for(int i=1;i<=n;++i) {
		c[i]=min(c[i-1],abs(c[i-1]-d[i]));
	}
	f[n+1]=0;
	for(int i=n;i;i--) {
		f[i]=f[i+1];
		if(d[i]<=2*f[i+1]+1) {
			f[i]=max(f[i],f[i+1]+d[i]);
		}
	}
	int q;
	scanf("%d",&q);
	while(q--) {
		int x;
		scanf("%d",&x);
		if(c[x-1]>f[x+1]) {
			puts("YES");
		}else {
			puts("NO");
		}
	}
	return 0;
} 



Measured memory_bytes: 12032
//problem name: Brick Break
 
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;
 
int main() {
    int N; cin >> N;
    priority_queue<int,vector<int>,greater<int>> que;
    que.push(4);
    que.push(7);
    while(1) {
        int v = que.top();
        que.pop();
        if(v == N) {
            cout << "Yes" << endl;
            break;
        } else if(N < v)  {
            cout << "No" << endl;
            break;
        }
        que.push(v+4);
        que.push(v+7);
    }
}

Measured memory_bytes: 5744
# ABC 142: B – Roller Coaster
n, k = [int(s) for s in input().split()]
h = [int(s) for s in input().split()]

the_number_can_ride = 0

for height in h:
    if height >= k:
        the_number_can_ride += 1

print(the_number_can_ride)

Measured memory_bytes: 11916
#include <stdio.h>

int main()
{
	long long int n, m;
	scanf("%lld%lld", &n, &m);
	if(n>2 && m>2) printf("%lld", (n-2)*(m-2));
	else if(n==2 || m==2) printf("0");
	else if(n==1 && m==1) printf("1");
	else if(n==1) printf("%lld", m-2);
	else printf("%lld", n-2);
}

Measured memory_bytes: 128
def solve():
    N = int(input())
    R = [None] * N
    for i in range(N):
        x, l = map(int, input().split())
        R[i] = (x + l, x - l)
    R.sort()
    
    right_most = R[0][0]
    save = 1
    for i in range(1, N):
        if R[i][1] >= right_most:
            save += 1
            right_most = R[i][0]

    left_most = R[N-1][1]
    saver = 1
    for i in reversed(range(N-1)):
        if R[i][0] <= left_most:
            saver += 1
            left_most = R[i][1]


    print(max(save, saver))


    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 17032
import math
from functools import reduce

def gcd(ns):
    return reduce(math.gcd, ns)

N, X = map(int, input().split())
L = list(map(int, input().split()))

diff = [abs(x - X) for x in L]

if len(diff) == 1:
    print(diff[0])
else:
    print(gcd(diff))


Measured memory_bytes: 20336
n, m = map(int, input().split())
g = [[] for _ in range(n)]
ig = [[] for _ in range(n)]
z = []

for i in range(m):
    s, t = map(int, input().split())
    g[s-1].append(t-1)
    ig[t-1].append(s-1)
    z.append((s, t))

dp = [0]*n
for v in range(n-1)[::-1]:#DAGだから可能
    now = 0
    for u in g[v]:#DAGだからできる
        now += dp[u]
    now /= len(g[v])
    now += 1
    dp[v] = now

p = [0]*(n)
p[0] = 1
#削除したとき用：
for i in range(1, n):
    for _p in ig[i]:
        p[i]+=p[_p]/len(g[_p])

ma = 0
for s, t in z:#削除する矢印
    k = len(g[s-1])
    if k ==1 : continue
    a, b = dp[s-1], dp[t-1]
    c = k/(k-1)*(a-1-b/k) + 1
    ma = max(ma, (a-c)*p[s-1])
print(dp[0]-ma)


Measured memory_bytes: 84568
import itertools
n = int(input())
m = 0
a = 0
r = 0
c = 0
h = 0

A = [input()[0] for i in range(n)]
for i in A:
    if i == 'M':
        m+=1
    elif i == 'A':
        a+=1
    elif i == 'R':
        r+=1
    elif i == 'C':
        c+=1
    elif i == 'H':
        h+=1

ans = 0
B = [m,a,r,c,h]
for b in list(itertools.combinations(B,3)):
    ans += b[0]*b[1]*b[2]

print(ans)

Measured memory_bytes: 3892
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <string>
#include <unordered_map>
#include <map>

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

ll factor(ll n){
    ll ct=0;
    for(ll i=1;i<=n;i++){
        if(n%i==0)ct++;
    }
    return ct;
}

int main(){
    ll n,ans;
    cin>>n;
    ans=0;
    for(ll i=1;i<=n;i+=2){
        if(factor(i)==8)ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
n, m = gets.chomp.split(" ").map(&:to_i)
s, c = m.times.map{gets.split.map(&:to_i)}.transpose
nums = []
n.times { nums << 0 }
if n != 1
  nums[0] = 1
end

flag = true

(0...m).each do |j|
  (j+1...m).each do |k|
    if s[j] == s[k] && c[j] != c[k]
      puts -1
      flag = false
      break
    end
  end
end

if flag
  (0...m).each do |i|
    if c[i] == 0 && s[i] == 1 && n != 1 
      puts -1
      flag = false
      break
    end
    nums[s[i]-1] = c[i] 
  end
end

if flag
  puts nums.join
end

Measured memory_bytes: 1788
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();

        int[][] s = new int[h+1][w+1];

        for(int i=0; i<h; i++) {
            for(int j=0; j<w; j++) {
                int n = sc.nextInt();
                s[i][j] = n;
                s[i][w] += n;
                s[h][j] += n;
            }
        }

        for(int i=0; i<h+1; i++) {
            for(int j=0; j<w+1; j++) {
                if(i == h && j == w) {
                    System.out.println(s[h][w]);
                } else if(j == w) {
                    System.out.println(s[i][j]);
                    s[h][w] += s[i][j];
                } else {
                    System.out.print(s[i][j] + " ");
                }
            }
        }
    }
}



Measured memory_bytes: 41940
def Year():
    Ya = 0
    for j in range(Y-1):
        Ya += 19*5+20*5
    for j in range((Y-1)/3):
        Ya += 5
    return Ya
def Mouth():
    Ma = 0
    for i in range(1, M):
        if Y%3 == 0:
            Ma += 20
        else:
            Ma += 19 + (i%2)
    return Ma

x = int(raw_input())
for i in range(x):
    Y,M,D = map(int,raw_input().split())
    print 196471 - (Year()+Mouth()+D)

Measured memory_bytes: 6316
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

int main()
{
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	string ans;
	for (int i = 0; i < tx - sx; i++) ans.push_back('R');
	for (int i = 0; i < ty - sy; i++) ans.push_back('U');
	for (int i = 0; i < tx - sx; i++) ans.push_back('L');
	for (int i = 0; i < ty - sy; i++) ans.push_back('D');
	ans.push_back('D');
	for (int i = 0; i < tx - sx + 1; i++) ans.push_back('R');
	for (int i = 0; i < ty - sy + 1; i++) ans.push_back('U');
	ans.push_back('L');
	ans.push_back('U');
	for (int i = 0; i < tx - sx + 1; i++) ans.push_back('L');
	for (int i = 0; i < ty - sy + 1; i++) ans.push_back('D');
	ans.push_back('R');
	cout << ans << endl;
}


Measured memory_bytes: 256
a,b,c,k = map(int,input().split())

ans=0
if k>a:
    ans = ans + a
    k=k-a
    if k>b:
        ans = ans
        k=k-b
        ans = ans-k
        print(ans)
    else:
        print(ans)
else:
    ans = ans + k
    print(ans)


Measured memory_bytes: 9124
#include<bits/stdc++.h>
using namespace std;
#define faster ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define pb push_back
#define vi vector<int>
struct Node
{
    int t;
    int x;
    int y;
    Node(int a,int b, int c)
    {
        t = a;
        x = b;
        y = c;
    }
    bool operator<(const Node&ob) const
    {
        return t<ob.t;
    }
};
int main()
{
    faster;
    int n,t,x,y,a=0,b=0,tme=0;
    int ans = 1;
    cin>>n;
    vector<Node> v;
    for(int i=1; i<=n; i++){
        cin>>t>>x>>y;
        v.push_back(Node(t,x,y));
    }
    sort(v.begin(),v.end());
    for(int i=0; i<n; i++){
        t = v[i].t;
        x = v[i].x;
        y = v[i].y;
        if(t==tme && (a!=x || b!=y)) ans = 0;
        int dist = abs(x-a) + abs(y-b);
        if(dist>abs(tme-t)) ans = 0;
        else{
            int diff = abs(tme-t) - dist;
            if(diff%2==1) ans = 0;
        }
        a = x;
        b = y;
        tme = t;
    }
    if(ans==1) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}




Measured memory_bytes: 1912
#include <stdio.h>
#include <string.h>

int partition(int A[], int r){
    int x = A[r];
    int i = -1;
    int tmp;
    for(int j=0 ; j<r ; j++){
        if(A[j] <= x){
            i++;
            // swap(A[i], A[j])
            tmp   = A[j];
            A[j]  = A[i];
            A[i]  = tmp;
        }
    }
    // swap(A[i+1], A[r])
    tmp = A[i+1];
    A[i+1] = A[r];
    A[r] = tmp;
    return i+1;
}

int main(void){
    int n;
    scanf("%d", &n);
    
    int A[n];
    for(int i=0 ; i<n; i++) scanf("%d", &A[i]);
    int p = partition(A, n-1);
    for(int i=0 ; i<p; i++) printf("%d ", A[i]);
    printf("[%d] ", A[p]);
    for(int i=p+1 ; i<n-1; i++) printf("%d ", A[i]);
    printf("%d\n", A[n-1]);

    return 0;
}


Measured memory_bytes: 2156
#include<bits/stdc++.h>
#define maxn 200050
#define eps 1e-6

using namespace std;
typedef long long ll;

int a[maxn],b[maxn],n,m,k;

int main()
{
    scanf("%d",&n);
    for (int i=0;i<n;i++) scanf("%d",&a[i]);
    scanf("%d",&m);
    for (int i=0;i<m;i++) scanf("%d",&b[i]);
    sort(a,a+n);sort(b,b+m);
    k=0;
    for (int i=0;i<m;i++)
    {
        while (k<n&&a[k]!=b[i]) k++;
        if (k==n){
            printf("NO\n");
            return 0;
        }
        k++;
    }
    printf("YES\n");
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <iostream>
#include <string>
#include <fstream>
#include <queue>
#include <cmath>
using namespace std;
 
#define MIN(x,y)
typedef  unsigned long long int lli;
int main(){
  string s;
  cin   >> s;
  const char* p=s.c_str();
  int t=0;
  while(p[t]!='\0'){
    if(!(p[t++]=='h'&&p[t++]=='i')){
      puts("No");
      return 0;
    }
  }
  puts("Yes");
}

Measured memory_bytes: 256
import Control.Applicative ((<$>))
import Control.Arrow ((***))
import Control.Monad
import Data.List

main :: IO ()
main = do
  [n,h] <- map read . words <$> getLine
  (a,bs) <- fmap (maximum *** sortBy (flip compare)) $ fmap unzip $ replicateM n $ do
    [a,b] <- map read . words <$> getLine
    return (a,b)
  let bs' = takeWhile (>a) bs
      (ans,rest) = foldl' (\(aans,arest) b -> if arest <= 0 then (aans,arest) else (aans+1,arest-b)) (0,h) bs'
      ans' = if rest > 0 then ans + ceiling (fromIntegral rest / fromIntegral a) else ans

  print ans'

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

#define 	pie				3.1415926536
#define 	mod 			1000000007
#define 	ll  			long long int
#define 	rep(i, a, b) 	for(int i = a ; i < b ; i++)
#define 	mod1 			1000003
#define     mod2            998244353
#define 	hi   			"hello"
#define 	nl 				"\n"
#define 	ws 				" "
#define 	F 				first
#define 	S 				second
#define 	PB 				push_back
#define 	MP				make_pair
#define 	B 				begin()
#define 	E 				end()
#define 	all(v) 			v.begin(), v.end()
#define 	reset(a, val) 	memset(a, val, sizeof(a))
#define 	vi 				vector<int>
#define     pi              pair<int, int>
#define     vll             vector<long long int>
#define 	vs 				vector<string>
#define     vc              vector<char>
#define 	print1(a) 		for(auto i : a)cout<<i<<" ";cout<<"\n"
#define 	print2(a) 		for(auto i : a)cout<<i;cout<<"\n"
#define 	boost 			ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

using namespace std;

//g++ -std=c++14
//fixed<<setprecision(9);
//max_element(mp.begin(), mp.end(), compare)
//greater<int>()
// __gcd(a, b);

bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); }

bool compare(const pair<string, int>&a, const pair<string, int>&b){ return a.second<b.second; }

void solve()
{
    ll k, sum = 0; cin>>k;
    rep(i, 1, k+1){
        rep(j, 1, k+1){
            rep(l, 1, k+1){
                sum += __gcd(i, __gcd(j, l));
            }
        }
    }
    cout<<sum<<nl;
}

int main()
{
    //boost;
    int t = 1, k = 1;
    // cin>>t;
    while(t--){
        // cout<<"Case #"<<k<<": ";
        solve();
        k++;
    }
}
// ll n, sum = 0;cin>>n;
//    rep(i, 1, n+1){
//        if(i%3&&i%5){
//            sum += i;
//        }
//    }
//    cout<<sum<<nl;
// }

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

int main() {
 int K,X;
 int jen;
 cin >> K;
 cin >> X;
 K=K*500;
  if (K>=X) {
    cout << "Yes";
  }else{
    cout << "No";
  }
 
 
 
 
 
	return 0;
}


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

int main(){
int h,w,i;
string s[100];
cin>>h>>w;

for(i=0;i<h;i++){
  cin>>s[i];
}

for(i=0;i<w+2;i++){
  cout<<"#";
}

cout<<endl;

for(i=0;i<h;i++){
    cout<<"#"<<s[i]<<"#";
    cout<<endl;
}

for(i=0;i<w+2;i++){
  cout<<"#";
}


}



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

//最大公約数
int gcd(int x, int y){
  if(x % y == 0) return 1;
  return gcd(y, x % y);
}

//最小公倍数
int lcm(int x, int y){
  return x * y / gcd(x, y);
}



int main(){
  int n, m;
  cin >> n >> m;
  if(n == m) cout <<"Yes" << endl;
  else cout << "No" << endl;
}

 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
using namespace std;
#define ll long long
#define endl "\n"
#define print_array(name,n) for(ll o=0;o<n;o++) cout<<name[o]<<" "
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 2e18
#define pll pair<ll,ll>
#define pii pair<int,int>
bool sortbysecond(const pair<int,int> &a,const pair<int,int> &b){
	return (a.ss>b.ss);
}
 
ll gcd(ll a,ll b){ if(b==0) return a; return gcd(b,a%b) ;} 

template <typename T>
string NumberTostring(T Number )
{
	ostringstream ss;
	ss<<Number;
	return ss.str();
}
 

 
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
 	ll n;
 	cin>>n;
 	vector<ll> vec(n,0);
 	ll tt = 0;
 	for(int i=0;i<n;i++){
 		cin>>vec[i];
 		tt = tt^vec[i];
 	}   
 	for(int i=0;i<n;i++){
 		ll ans = tt^vec[i];
 		cout<<ans<<" ";
 	}
 	cout<<endl;

    return 0;
}

Measured memory_bytes: 4784
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;

int main(void) {
  int n;
  cin >> n;
  vector<int> u;
  for(int i = 0; i < n; i++) {
    int ui;
    cin >> ui;
    u.push_back(ui);
  }
  sort(u.begin(), u.end());
  long double ans = u[0];
  for(int i = 1; i < n; i++) {
    ans = (ans + u[i]) / 2;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3776
// DPをグローバル宣言
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

#define REP(i,m,n) for(int i=(int)m; i < (int)n; ++i)
#define rep(i,n) REP(i,0,n)
#define all(a) (a).begin(), (a).end()

const int MOD = 1e9+7;
ll dp[101010][13] = {};

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

    string s; cin >> s;
    int N = s.size();
    dp[0][0] = 1;

    rep(i, N) {
        rep(j, 13) {
            if(s[i] == '?') {
                for(int k = 0; k <= 9; k++) {
                    int j2 = (j*10+k)%13;
                    dp[i+1][j2] = (dp[i+1][j2]+dp[i][j])%MOD;
                }
            } else {
                int k = s[i]-'0';
                int j2 = (j*10+k)%13;
                dp[i+1][j2] = (dp[i+1][j2]+dp[i][j])%MOD;
            }
        }
    }

    cout << dp[N][5] << '\n';
    return 0;
}

Measured memory_bytes: 10704
#include<bits/stdc++.h>
#define F first
#define S second
#define endl '\n'
#define MP make_pair
#define pb push_back

using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> i_P;
typedef long long LL;

static const int INF = INT_MAX;
static const LL L_INF = LLONG_MAX;
static const int MOD = (1000000000 + 7);

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

    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; ++i) cin >> a[i];
    int ans = a[0];
    for(int i = 1; i < n; ++i) {
        ans = __gcd( ans, a[i] );
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main(){
  int X, Y, cranes, turtles;
  bool is_true = false;
  cin >> X >> Y;
  for(cranes = 0; cranes <= X; cranes++){
    turtles = X - cranes;
    if(cranes * 2 + turtles * 4 == Y){
      is_true = true;
      break;
    }
  }
  if(is_true == true) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

using namespace std;

int main() {
    int a, ans = 0;

    cin >> a;

    for (int i = 0; i < 3; ++i) {
        if (a % 10 == 1) ++ans;
        a /= 10;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
class Program
{
	static void Main(string[] args)
	{
		var input = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
		int ans = input[2];
		if (input[0] * input[1] < input[2]) { ans = input[0] * input[1]; }
		Console.WriteLine(ans);


	}
}

Measured memory_bytes: 13268
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
''' 
------------------------
author : iiou16
------------------------
'''

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

    cc = [0] * N
    for i in range(N-1):
        cc[A[i-1]-1] += 1
    for n in cc:
        print(n)



if __name__ == '__main__':
    main()

Measured memory_bytes: 32304
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <set>
#include <map>

#define PB push_back
#define MP make_pair
#define X first
#define Y second

using namespace std;

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

const int N = 2e5 + 500;
const int M = 1e6 + 500;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int LOG = 20;
const int OFF = (1 << LOG);
const double EPS = 1e-9;

ll n, sol = 0;
vi v;

int main(){
    scanf("%lld", &n);
    for(int i = 0;i<n;i++){
        ll x;scanf("%lld",&x);
        v.PB(x);
    }
    if(n == 1 && v[0] != 0){
        printf("-1\n");
        return 0;
    }
    reverse(v.begin(),v.end());
    ll mi = v[0];
    sol += v[0];
    if(v[0] >= n){
        printf("-1\n");
        return 0;
    }
    for(int i = 1;i<v.size();i++){
        mi--;
        if(v[i] < mi){
            printf("-1\n");
            return 0;
        }
        if(v[i] == v[i - 1] - 1) continue;
        if(n - i - 1 < v[i]){
            printf("-1\n");
            return 0;
        }
        sol += v[i];
        mi = v[i];
    }
    printf("%lld\n", sol);
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> ppiii;

void solve() {
  string s;
  cin >> s;
  int ret = 0;
  int curr = 0;
  for(int i = 0; i < s.size(); i++) {
    if(s[i] == 'A') curr++;
    else if(s[i] == 'C') curr++;
    else if(s[i] == 'G') curr++;
    else if(s[i] == 'T') curr++;
    else curr = 0;
    ret = max(ret, curr);
  }
  cout << ret << endl;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = s; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using llong = long long;
using P = pair<int, int>;
const int inf = 1 << 30;
const int mod = 1e9 + 7;

int main() {
   int n, K;
   cin >> n >> K;
   vector<int> h(n);
   rep(i, 0, n) { cin >> h[i]; }
   vector<int> dp(n, inf);
   dp[0] = 0;
   rep(i, 0, n) {
      rep(j, i + 1, min(i + K + 1, n)) {
         dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
      }
   }
   cout << dp[n - 1] << endl;
   return 0;
}

Measured memory_bytes: 1024