akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
   using namespace std;
   vector<int> l[100005];
   int dp[100005];
   int visited[100005];
   long long int mod=1000000000+7;
  int main()
  {   
     long long int n,k;
     cin>>n>>k;
     long long int a[n];

     for(int i=0;i<n;i++)
      cin>>a[i];
     
     long long int dp[n+1][k+1];
     memset(dp,0,sizeof(dp));
     dp[0][0]=1;
   //   for(int i=0;i<=k;i++)
   //     dp[0][i]=1;

     for(int i=0;i<=n;i++)
     {
        dp[i][0]=1;
     }
      long long int sum=0;
      long long int prefix[k+1];
     for(int i=1;i<=n;i++)
     {   sum=0;
       
        prefix[0]=dp[i-1][0];
        for(int p=1;p<=k;p++)
           {  
             prefix[p]=(prefix[p-1]%mod+dp[i-1][p]%mod)%mod;
              
          }
        for(int j=0;j<=k;j++)
        {
            // for(int t=0;t<=a[i-1];t++)
            // {     if(j>=t)
            //     {
            //       // dp[i][j]=dp[i][j]+dp[i-1][j-t];
                  
            //      // dp[i][j]=sum;
            //      }

            long long int t=prefix[j];
            long long int f=j-a[i-1]-1;

            if(f>=0)
            {
               t=(t-prefix[f]+mod)%mod;
            }
            dp[i][j]=t;
         } 
        
        
     }
   //   for(int i=0;i<=n;i++)
   //   {
   //      for(int j=0;j<=k;j++)
   //      {
   //         cout<<dp[i][j]<<" ";
   //      }
   //      cout<<"\n";

   //   }
     cout<<dp[n][k];


  }



Measured memory_bytes: 82304
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**7)
import bisect
import heapq
import itertools
import math
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
  bunshi=1
  bunbo=1
  for i in range(r):
    bunbo = bunbo*(i+1)%mod
    bunshi = bunshi*(n-i)%mod
  return (bunshi*pow(bunbo,mod-2,mod))%mod
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

#bisect.bisect_left(list,key)はlistのなかでkey未満の数字がいくつあるかを返す
#bisect.bisect_right(list, key)はlistのなかでkey以下の数字がいくつあるかを返す
#これを応用することで
#len(list) - bisect.bisect_left(list,key)はlistのなかでkey以上の数字がいくつあるかを返す
#len(list) - bisect.bisect_right(list,key)はlistのなかでkeyより大きい数字がいくつあるかを返す
#これらを使うときはあらかじめlistをソートしておくこと！

n =I()
for i in range(10000):
    if 1000*i - n >= 0:
        print(1000*i - n)
        break


Measured memory_bytes: 10084
n=int(input())
(a,b)=list(map(lambda x: int (x), input().split()))
c=list(map(lambda x: int(x), input().split()))

n1=0
n2=0
n3=0

for i in c:
    if i <= a:
        n1 += 1
    elif a + 1 <= i and i <= b:
        n2 += 1
    else:
        n3 += 1

print(min([n1, n2, n3]))
        


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

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

const int mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 11


int main()
{
    int n; cin >> n;
    ll ans = 0;
    for(int i = 1; i <= n; i++){
        ll num = n / i;
        ans += (i+i*num)*num/2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

//=============modpow============================
ll modpow(ll a, ll n, ll mod)
{
    ll res = 1;
    while (n > 0)
    {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//=================================================


const ll MAX = 500010;
const ll MOD = 998244353;
vector<ll> fac(MAX), finv(MAX), inv(MAX);
bool init_called = false;
//=============modinv============================
void COMinit() {
  init_called = true;
  fac.at(0) = 1;
  fac.at(1) = 1;
  finv.at(0) = 1;
  finv.at(1) = 1;
  inv.at(1) = 1;
  for (ll i = 2; i < MAX; i++){
    fac.at(i) = fac.at(i - 1) * i % MOD;
    inv.at(i) = MOD - inv.at(MOD % i) * (MOD / i) % MOD;
    finv.at(i) = finv.at(i - 1) * inv.at(i) % MOD;
  }
}

ll COM(ll n, ll k){
  if (!init_called) {
    COMinit();
  }
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac.at(n) * (finv.at(k) * finv.at(n - k) % MOD) % MOD;
}
//=================================================


int main()
{
  ll N, M, K;
  cin >> N >> M >> K;
  ll p = modpow(M - 1, N - 1 - K, MOD);
  ll ans = 0;
  for (ll i = K; i >= 0; --i) {
    ll temp = M * p % MOD;
    temp = (temp * COM(N - 1, i)) % MOD;
    ans = (ans + temp) % MOD;
    p = (p * (M - 1)) % MOD;
  }
  cout << ans << "\n";
}


Measured memory_bytes: 14728
#include <stdio.h>
int main(void)
{
          int days , a;
          int i ;
          scanf("%d%d", &days, &a ) ;
          int d, sum = 0;
          for ( i = 0 ; i < a ; i++)
          {
                   scanf("%d", &d) ;
                   sum += d ;
          }
          if(sum > days) printf("-1") ;
          else printf("%d", days - sum) ;
          return 0 ;
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;

int main() {
    int N;
    cin >> N;
    vec<ll> A(N);
    rep(i, N) cin >> A[i];

    ll ans   = 0;
    ll msk   = A[0];
    ll left  = 0;
    ll right = 0;
    while (right <= N - 1) {
        if (left == right){
            ++ans;
            ++right;
            msk = A[left];
        } else if ((msk ^ A[right]) == msk + A[right]) {
            ++ans;
            msk ^= A[right];
            ++right;
        } else {
            msk ^= A[left];
            ++left;
            ans+=(right-left);
        }
        
    }
    ll count = right - left - 1;
    ans += count * (count - 1) / 2;
    ans += count;

    cout << ans << endl;
}

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

using ll = long long;
const ll amari = 1e9+7;
const char BC = 'A' - 'a';
#define ben(a) a.begin(),a.end()
#define pb(a,b) a.push_back(b)

int main(){
	int t;
	cin >> t;
	int a[t];
	int b[t];
	int sum = 0;
	for(int i = 0; i < t; i++){
		cin >> a[i];
	}
	for(int i = 0; i < t; i++){
		cin >> b[i];
		if(a[i] > b[i])sum+= a[i] - b[i];
	}
	cout << sum << endl;
	return 0; 
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;

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

        int n = sc.nextInt();

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

        Arrays.sort(s);

        int total_score = 0;
        for (int i = 0; i < n; i++) {
            total_score += s[i];
        }
        
        if (total_score % 10 != 0) {
            System.out.println(total_score);
        } else {
            for (int i = 0; i < n; i++) {
                int sum = total_score - s[i];
                if (sum % 10 != 0) {
                    System.out.println(sum);
                    return;
                }
            }
            System.out.println("0");
        }
    }
}

Measured memory_bytes: 21844
import java.util.*;

public class Main {
	static class Path {
		int dir;
		int step;
		int move;
		int y, x;
		
		public Path(int dir, int step, int move, int y, int x) {
			this.dir = dir;
			this.step = step;
			this.move = move;
			this.y = y;
			this.x = x;
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int H = sc.nextInt();
		int W = sc.nextInt();
		int K = sc.nextInt();
		int y1 = sc.nextInt()-1;
		int x1 = sc.nextInt()-1;
		int y2 = sc.nextInt()-1;
		int x2 = sc.nextInt()-1;

		char[][] m = new char[H][];
		for(int i=0; i<H; i++)
			m[i] = sc.next().toCharArray();

		long[][][] best = new long[H][W][4];
		for(int i=0; i<H; i++)
			for(int j=0; j<W; j++)
				Arrays.fill(best[i][j], Long.MAX_VALUE);
		
		final int[] dx = {0, 1, 0, -1};
		final int[] dy = {1, 0, -1, 0};
		
		PriorityQueue<Path> q = new PriorityQueue<Path>(new Comparator<Path>() {
			public int compare(Path p1, Path p2) {
				if(p1.step==p2.step)
					return Integer.compare(p1.move, p2.move);
				else
					return Integer.compare(p1.step, p2.step);
			}
		});
		
		for(int d=0; d<4; d++) {
			q.add(new Path(d, 1, 0, y1, x1));
		}
		
		while(!q.isEmpty()) {
			Path cur = q.poll();
			
			if(best[cur.y][cur.x][cur.dir] <= cur.step*(K+1)+cur.move)
				continue;
			best[cur.y][cur.x][cur.dir] = cur.step*(K+1)+cur.move;
			
			for(int d=0; d<4; d++) {
				int ny = cur.y + dy[d];
				int nx = cur.x + dx[d];
				if(0<=ny && ny<H && 0<=nx && nx<W &&m[ny][nx]=='.') {
					int nextStep = cur.step;
					int nextMove = cur.move;
					if(d==cur.dir && nextMove<K) {
						nextMove++;
					} else {
						nextStep++;
						nextMove = 1;
					}
					if(best[ny][nx][d] > nextStep*(K+1)+nextMove)
						q.add(new Path(d, nextStep, nextMove, ny, nx));
				}
			}
		}
		long ans = Long.MAX_VALUE;
		for(int d=0; d<4; d++)
			ans = Math.min(ans, best[y2][x2][d]);
		System.out.println(ans < Long.MAX_VALUE ? ans/(K+1) : -1);

		sc.close();
	}
}


Measured memory_bytes: 130772
#E
from bisect import bisect_left
from itertools import accumulate

N,M=map(int,input().split())
A=list(map(int,input().split()))
A=sorted(A)
A_r=list(reversed(A))
B=[0]+list(accumulate(A_r))

def f(x):
    count=0
    for i in A:
        idx=bisect_left(A,x-i)
        count+=N-idx
    if count>=M:
        return True
    else:
        return False
    
MIN=0
MAX=2*10**5+1
while MAX-MIN>1:
    MID=(MIN+MAX)//2
    if f(MID):
        MIN=MID
    else:
        MAX=MID

ans=0
count=0
for i in A_r:
    idx=bisect_left(A,MIN-i)
    ans+=i*(N-idx)+B[N-idx]
    count+=N-idx
print(ans-(count-M)*MIN)

Measured memory_bytes: 59196
import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.HashSet;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int K=sc.nextInt();
    String S=sc.next();
    String Ss[]=S.split("");
    if(Ss.length<=K){
      System.out.println(S);
    }else{
      for(int i=0;i<K;i++){
        System.out.print(Ss[i]);

      }
       System.out.print("...");
    }




  }
}


Measured memory_bytes: 35804
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>
#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 1LL << 61;
const ll mod = 1000000007LL;
//const ll mod = 998244353LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
ll dx[9] = { 0,1,0,-1,0,1,1,-1,-1 }, dy[9] = { 0,0,1,0,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222


ll a[MAX], num[MAX];



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


  cin >> n;
  ll x1 = -inf, x2 = -inf;
  rep(i, n) {
    cin >> a[i];
    if (a[i] >= x1) {
      x2 = x1;
      x1 = a[i];
    }
    else x2 = max(x2, a[i]);
    num[a[i]]++;
  }
  rep(i, n) {
    if (a[i] == x1) {
      if (num[x1] > 1) cout << x1 << endl;
      else cout << x2 << endl;
    }
    else cout << x1 << endl;
  }



  return 0;
}


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

using i64 = int64_t;

int main(){
    string a, b;
    cin >> a >> b;
    bool ok = false;
    for(int i=0;i<=(int)a.size()-(int)b.size();++i){
        bool flag = true;
        for(int j=0;j<(int)b.size();++j){
            if(b[j] != '_' && a[i+j] != b[j]){
                flag = false;
                break;
            }
        }
        if(flag){
            ok = true;
            break;
        }
    }

    cout << (ok ? "Yes" : "No") << endl;

    return 0;
}



Measured memory_bytes: 3200
n, a, b = map(int, input().split())
s = [0]*5
ans = 0
for i in range(n+1):
    s[0] = i // 10000
    s[1] = (i % 10000) // 1000
    s[2] = (i % 1000) // 100
    s[3] = (i % 100) // 10
    s[4] = (i % 10) // 1
    temp = s[0]*10000+s[1]*1000+s[2]*100+s[3]*10+s[4]

    if a <= sum(s) and sum(s) <= b:
        ans += temp
print(ans)

Measured memory_bytes: 3064
N,K=map(int,input().split())
A=[0]+list(map(int,input().split()))
city=1
if K<=N:
    for k in range(K):
        city=A[city]
    print(city)
else:
    visited=[-1]*(N+1)
    for k in range(K):
        if visited[city]!=-1:
            roop_start=visited[city]
            cycle_num=k-roop_start
            break
        visited[city]=k
        city=A[city]
    K=(K-roop_start)%cycle_num+roop_start
    city=1
    for k in range(K):
        city=A[city]
    print(city)

Measured memory_bytes: 32236
N = int(input())
x = [int(i) for i in input().split()]

mod = 10 ** 9 + 7

ret = 1
c = 0
for i in range(N) :
    if x[i] >= 2 * c + 1 :
        c += 1
    else :
        ret *= (c + 1)
        ret %= mod
        
for i in range(1, c + 1) :
    ret *= i
    ret %= mod
    
print(ret)

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

#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

const int32_t inf = 1001001001;
const int64_t infll = 1001001001001001001ll;
const int dx[] = {0, -1, 1, 0, -1, 1, -1, 1}, dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};

template <typename T> using vector2d = vector<vector<T>>;

// clang-format off
template <typename T> void sort(vector<T> &v) { sort(all(v)); }
// ostream &operator<<(ostream &os, __int128_t value) { if (ostream::sentry(os)) { __uint128_t tmp = value < 0 ? -value : value; char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
// istream &operator>>(istream &is, __int128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } if (in[0] == '-') value *= -1; return is; }
// ostream &operator<<(ostream &os, __uint128_t value) { if (ostream::sentry(os)) { char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[value % 10]; value /= 10; } while (value != 0); int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
// istream &operator>>(istream &is, __uint128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } return is; }
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { os << v[0]; for (int i = 1; i < v.size(); ++i) os << " " << v[i]; return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.fs << " " << p.sc; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.fs >> p.sc; return is; }

struct IoSetup { IoSetup(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup;

inline int64_t in() { int64_t x = 0; cin >> x; return x; }
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

signed main(int argc, char *argv[]) {
  int n = in(), t = in();

  long double ans = 0;
  for (int i = 0; i < n; ++i) {
    int x = in(), h = in();
    chmax(ans, t * (long double)h / x);
  }

  cout << ans << endl;
}



Measured memory_bytes: 3320
import sys
input = sys.stdin.readline

N = int(input())
H = list(map(int, input().split()))
ct = 0
ans = 0
for i in range(N-1):
    if H[i] >= H[i+1]:
        ct += 1
    else:
        ans = max(ans, ct)
        ct = 0
print(max(ct, ans))


Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define Rep(i,n) for(int i=1;i<=(n);++i)
using LL = long long;
using ULL = unsigned long long;

struct pair_hash {
    template <class T1, class T2>
    size_t operator () (const pair<T1, T2> &p) const {
        auto h1 = hash<T1>{}(p.first);
        auto h2 = hash<T2>{}(p.second);
        return h1 ^ h2;  
    }
};

const int mod = 1000000007;

LL gcd(LL x, LL y) {
	return y ? gcd(y, x%y) : x;
}

LL p2[200123]{1};

int main()
{
	Rep(i, 200000) {
		p2[i] = p2[i-1] * 2;
		if(p2[i] >= mod) p2[i] -= mod;
	}
	int n, sum = 0;
	cin >> n;
	unordered_map<pair<LL, LL>, int, pair_hash> p, q;
	p.reserve(4e5); q.reserve(4e5);
	LL x, y;
	rep(i, n) {
		scanf("%lld%lld", &x, &y);
		if(x == 0 && y == 0) continue;
		LL t = gcd(x, y);
		x /= t; y /= t;
		if(y < 0) x = -x, y = -y;
		if(x == 1 && y == 0) x = -1;
		if(x >= 0) ++q[{x, y}];
		else ++p[{y, -x}];
		++sum;
	}
	LL ans = 1, z = n - sum;
	for(auto& kv: p) {
		auto it = q.find(kv.first);
		if(it == q.end()) continue;
		sum -= it->second + kv.second;
		ans = ans * (p2[it->second] + p2[kv.second] - 1) % mod;
	}
	ans = ans * p2[sum] % mod;
	--ans;
	ans += z;
	if(ans < 0) ans += mod;
	if(ans >= mod) ans -= mod;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 20640
#include <bits/stdc++.h>
using namespace std;
const int max_v = 1000;
int v,E,n,m;
int d[max_v][max_v];
const int INF = 1e9;
vector<int> ls;

void solve(){
    int k = n/2;
    if(n%2 == 1)    k++;
    cout << k << endl;
}
int main(){
    cin >> n;
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
void chmin(long long &a, long long b) { if (a > b) a = b; }
const long long INF = 1LL<<58;

// vector v において、x の前方と後方の index を求める
template<class T> int former(const vector<T> &v, T x) {
    return upper_bound(v.begin(), v.end(), x) - v.begin() - 1;
}
template<class T> int latter(const vector<T> &v, T x) {
    return lower_bound(v.begin(), v.end(), x) - v.begin();
}

int main() {
    int A, B, Q; cin >> A >> B >> Q;
    vector<long long> s(A), t(B);
    for (int i = 0; i < A; ++i) cin >> s[i];
    for (int i = 0; i < B; ++i) cin >> t[i];
    s.push_back(INF); s.push_back(-INF); sort(s.begin(), s.end());
    t.push_back(INF); t.push_back(-INF); sort(t.begin(), t.end());
    
    for (int _ = 0; _ < Q; ++_) {
        long long x; cin >> x;
        long long res = INF;
        
        // 最初に s (前方に行くか後方に行くか場合分け)
        for (int i = 0; i < 2; ++i) {
            long long first = (i ? s[former(s, x)] : s[latter(s, x)]);
            // 次に t (現在地の前後を見る)
            for (int j = 0; j < 2; ++j) {
                long long second = (j ? t[former(t, first)] : t[latter(t, first)]);
                chmin(res, abs(x - first) + abs(first - second));
            }
        }
        // 最初に t (前方に行くか後方に行くか場合分け)
        for (int i = 0; i < 2; ++i) {
            long long first = (i ? t[former(t, x)] : t[latter(t, x)]);
            // 次に t (現在地の前後を見る)
            for (int j = 0; j < 2; ++j) {
                long long second = (j ? s[former(s, first)] : s[latter(s, first)]);
                chmin(res, abs(x - first) + abs(first - second));
            }
        }
        cout << res << endl;
    }
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,l; cin>>n>>l;
    int sum=0, mi=INT_MAX, sgn;
    rep(i,n){
        sum+=l+i;
        if (mi>abs(l+i)){
            mi = abs(l+i);
            sgn = (l+i>0)?1:-1;
        }
    }
    cout<<sum-sgn*mi<<endl;
    return 0;
}


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

public class Main {
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        Integer n = Integer.parseInt(scanner.next());

        List<Long> listA = new ArrayList<Long>();

        Integer[] a = new Integer[n];
        for(int i = 0; i < a.length; i++) {
            listA.add(scanner.nextLong());
            //a[i] = Integer.parseInt(scanner.next());
        }

        List<Long> listB = new ArrayList<Long>(new HashSet<>(listA));

        if(listA.size() == listB.size()) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }

    }
}


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

const int maxn = 100010;
int n, m, d[maxn];

int main() {
    cin >> n >> m;
    for (int i = 1, u, v; i <= m; i++) {
        cin >> u >> v;
        d[u]++, d[v]++;
    }
    for (int i = 1; i <= n; i++) {
        if (d[i] & 1) { cout << "NO" << endl; exit(0); }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
/*
*/
using Graph = vector<bitset<10>>;
ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b, a % b);
}
const ll P =  1000000007;
ll factorial(ll n){
   ll ans = 1;
   for(int i = n;i>=1;i--){
     ans *= i;
     ans %= P;
   }
   return ans;
}
 
//繰り返し二乗法
ll calc(ll a, ll b, ll p){//aのb乗をpで割った余り
  if(b == 0) return 1;

  else if(b%2 == 0){
    ll d = calc(a,b/2,p);
    return (d*d)%p;
  }
  else if(b%2 == 1){
    return (a * calc(a,b-1,p))%p;
  }
  
}

int main(){
  ll N;
  cin >> N;
  vector<ll> A(N),B(N),C(N);
  rep(i,N){
    cin >> A[i];
  }
  rep(i,N){
    cin >> B[i];
  }
  rep(i,N){
    cin >> C[i];
  }
  sort(A.begin(),A.end());
  sort(B.begin(),B.end());
  sort(C.begin(),C.end());
  ll ans = 0;

  rep(i,N){
    ll k = B[i];
    ll c1 = 0;//Aの中でk未満の要素数
    //A[i] >= kとなる最小のi
    auto itr = lower_bound(A.begin(), A.end(), k);
    c1 = distance(A.begin(),itr);
    //cout << c1 << endl;
    
    ll c2 = 0;//Cの中でkより大きい要素数
    //C[i] > k となる最小のi
    auto itr2 = upper_bound(C.begin(), C.end(), k);
    c2 = N - distance(C.begin(),itr2);
    //cout << c2 << endl;
    ans += c1 * c2;
  }
   cout << ans << endl;
}

Measured memory_bytes: 2560
# coding: utf-8
# Here your code !

def func():
    try:
        time=int(input().rstrip())
        if(time<0):
            print("input error")
    except:
        print("input error 1")
        return -1
    
    hours = time // 3600
    minutes = (time % 3600) // 60
    seconds = time % 60
    
    print(str(hours)+":"+str(minutes)+":"+str(seconds))

func()

Measured memory_bytes: 7616
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;

#define maxn 10000+10
#define maxe maxn*maxn/2+1
int pa[maxn],ran[maxn];

void init(const int& n){
	for(int i=0; i<n; i++){
		pa[i] = i;
		ran[i] = 0;
	}
}

// int find(const int& x){
// 	if(pa[x]==x) return x;
// 	else pa[x] = find(pa[x]);
// }
int find(const int& x)
{
	if (pa[x] == x)
	{
		return x;
	}
	else
	{
		return pa[x] = find(pa[x]);
	}
}

// void unite(int x,int y){
// 	x = find(x); y = find(y);

// 	if(x==y) return;
// 	if(ran[x] < ran[y]){
// 		pa[x] = y;
// 	}else{
// 		pa[y] = x;
// 		if(ran[x] == ran[y])
// 			++ran[x];
// 	}
// }
void unite(int x, int y)
{
	x = find(x);
	y = find(y);
	if (x == y)
	{
		return;
	}
 
	if (ran[x] < ran[y])
	{
		pa[x] = y;
	}
	else
	{
		pa[y] = x;
		if (ran[x] == ran[y])
		{
			++ran[x];
		}
	}
}

bool same(const int& x,const int& y){
	return find(x) == find(y);
}

struct edge{
	int u,v;
	double cost;
	edge(int u=0,int v=0,double cost=0) : u(u),v(v),cost(cost){}
	bool operator<(const edge& rhs) const{
		return cost > rhs.cost;
	}
};
edge es[maxe];
int V,E;

pair<int,int> pile[maxn];

double kruskal(){
	sort(es,es+E);
	init(V);
	double res = 0;
	for(int i=0; i<E; i++){
		edge e = es[i];
		if(!same(e.u,e.v))
			unite(e.u,e.v);
		else
			res += e.cost;
	}

	return res;
}


int main(){
	scanf("%d%d",&V,&E);
	for(int i=0; i<V; i++)
		scanf("%d%d",&pile[i].first,&pile[i].second);

	for(int i=0; i<E; i++){
		scanf("%d%d",&es[i].u,&es[i].v);
		--es[i].u,--es[i].v;
		int dx = pile[es[i].u].first - pile[es[i].v].first;
		int dy = pile[es[i].u].second - pile[es[i].v].second;
		es[i].cost = sqrt(dx*dx+dy*dy);	
	}

	printf("%.3lf\n",kruskal());
}

Measured memory_bytes: 5036
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int n; string s;
	cin >> n >> s;
	vector<pair<string, string> > fw, bk;
	for (int i = 0; i < 1 << n; ++i) {
		string fwa, fwb, bka, bkb;
		for (int j = 0; j < n; ++j) {
			if ((i >> j) & 1) {
				fwa += s[j];
				bka += s[2 * n - j - 1];
			}
			else {
				fwb += s[j];
				bkb += s[2 * n - j - 1];
			}
		}
		fw.push_back(make_pair(fwa, fwb));
		bk.push_back(make_pair(bkb, bka));
	}
	sort(fw.begin(), fw.end());
	sort(bk.begin(), bk.end());
	long long ans = 0;
	for (pair<string, string> i : fw) {
		ans += upper_bound(bk.begin(), bk.end(), i) - lower_bound(bk.begin(), bk.end(), i);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 69336
#include<cstdio>
#define NMAX 10000

int search(int A[], int n, int key){
	int i = 0;
	A[n] = key;
	while(A[i] != key) i++;
	return i != n;
}

int main(void){
	int i, n, A[NMAX + 1], q, key, sum = 0;

	scanf("%d", &n);
	for(i = 0; i < n; i++) scanf("%d", &A[i]);

	scanf("%d", &q);
	for(i = 0; i < q; i++){
		scanf("%d", &key);
		if(search(A, n, key)) sum++;
	}
	printf("%d\n", sum);

	return 0;
}

Measured memory_bytes: 2756
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>


/* 
*    coder :: ATUL_PANDEY_2608
*        >>> INDIA <<<
*/
using namespace std;
using namespace __gnu_pbds;

// #define  part ..
#define pb(a) push_back(a)
#define all(a) a.begin(),a.end() 
#define mod 1000000007
//#define maxx 200006
#define ll long long 
#define quick    ios_base::sync_with_stdio(NULL),cin.tie(0);
#define listll vector< long long > 
#define listi vector< int> 
#define pii   pair<int , int> 
#define pll pair<long long , long long > 
#define minheap priority_queue<long long , vector< long long >, greater<long long > >
#define rep(i,a,b) for(int i=a;i<b;i++)
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}


template < class T > using oset = tree< T , null_type, less  < T  > , rb_tree_tag , tree_order_statistics_node_update > ;


// end of #define 

// define globals ...
const int maxx = 2e5+26;

//write function from here ...







int Main(){


int n;
cin>>n;

vector < ll > arr(n);

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

ll mxx = arr[0] ;

ll ans =0 ;


for(auto it :arr)
{
	 
	 ans += max(0LL , mxx - it);
	 mxx = max(mxx , it);
 }
 
 cout<<ans<<endl;







return 0;

}

















int main(){
 quick;
int t =1; 
//cin>>t;
while(t-- )
 Main();

 return 0;


}


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

using namespace std;

void solve(long A, long B, long C) {
  long count = 0;
  while (true) {
    if ((A % 2) || (B % 2) || (C % 2)) {
      cout << count << endl;
      return;
    }
    long An = (B + C) / 2;
    long Bn = (C + A) / 2;
    long Cn = (A + B) / 2;
    A = An;
    B = Bn;
    C = Cn;
    count++;
    if (A == B && B == C) {
      cout << -1 << endl;
      return;
    }
  }
}

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

  long A, B, C;
  cin >> A >> B >> C;
  solve(A, B, C);
  return 0;
}


Measured memory_bytes: 256
fn main() {
    let n: usize = read();
    let mut a: Vec<usize> = Vec::new();
    for _i in 0..n {
        a.push(read());
    }
    let mut i = 0;
    let mut count = 0;
    while count < n {
        i = a[i] - 1;
        count += 1;
        if i == 1 {
            break;
        }
    }
    if i == 1 { println!("{}", count); }
    else { println!("-1"); }
}

// 以下関数


use std::io::*;
use std::str::FromStr;
pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

pub const MOD: u64 = 1_000_000_007;

pub fn is_prime(n: i32) -> bool {
    if n < 2 {
        return false;
    } else if n == 2 {
        return true;
    }
    let mut i = 2;
    while i * i < n {
        if n % i == 0 {
            return false;
        } else {
            i += 1;
            continue;
        }
    }
    true
}

pub fn lcm(mut n: i32, mut m: i32) -> i32 {
    n = if n > m { m } else { n };
    m = if n > m { n } else { m };
    let mut i = n;
    while i % m != 0 {
        i += n;
    }
    i
}

pub fn abs(n: i32) -> i32 {
    if n >= 0 {
        n
    } else {
        -n
    }
}

pub fn max(n: i32, m: i32) -> i32 {
    if n >= m {
        n
    } else {
        m
    }
}

pub fn min(n: i32, m: i32) -> i32 {
    if n <= m {
        n
    } else {
        m
    }
}

pub fn factorial(n: u32) -> u32 {
    if n == 0 {
        return 1
    }
    let mut r = n;
    for i in 0..n-1{
        r *= n-i-1;
    }
    r
}

pub fn combination(n: u32, m: u32) -> u32 {
    factorial(n) / factorial(m) / factorial(n-m)
}

Measured memory_bytes: 4352
import sys
import time
import math
def inpl():
    return list(map(int, input().split()))
st = time.perf_counter()
# ------------------------------

X, Y, Z = map(int, input().split())
for i in range(1, 1001001001):
	if Y * i + Z * (i+1) > X:
		print(i-1)
		sys.exit()

# ------------------------------
ed = time.perf_counter()
print('time:', ed-st, file=sys.stderr)


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

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long int ll;

int n, d, x, i, j, a, k;
int ans;
int main() {
	cin >> n;
	cin >> d >> x;
	ans = 0;
	for (i = 1; i <= n; i++) {
		cin >> a;
		k = 0;
		for (j = 0; k <= d; j++) {
			k = a*j + 1;
			if(k <= d)
				ans++;
		}
	}
	ans += x;
	cout << ans << endl;
	return 0;
}

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

typedef long long ll;

int main() {
	int n; cin >> n;
	int a[100003], t[100003];
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	t[0] = 0;
	for (int i = 1; i < n; ++i) {
		if (t[i - 1] == 0) {
			if (a[i - 1] == a[i]) t[i] = 0;
			else if (a[i - 1] < a[i]) t[i] = 1;
			else t[i] = -1;
		}
		else if (t[i - 1] == 1) {
			t[i] = a[i - 1] <= a[i] ? 1 : 0;
		}
		else {
			t[i] = a[i - 1] >= a[i] ? -1 : 0;
		}
	}

	int ans = 1;
	for (int i = 1; i < n; ++i) {
		ans += t[i - 1] != t[i] && t[i] == 0;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (int i=0;i<N;i++)
#define loop(i,N,M) for(int i=N;i<M;i++)

//変数
ll N,K;
vector<ll> vec;

ll i1 = 0;

//解法
void solve() {

	ll ans = 1+ (N - K) / (K - 1);
	if ((N - K) % (K - 1) != 0) {
		ans++;
	}

	cout << ans;

	return;
}

int main() {
	//入力
	cin >> N >> K;
	vec.resize(N);
	rep(i, N) {
		cin >> vec[i];
		if (vec[i] == 1) i1 = i;
	}
	solve();
	cout << endl;
	return 0;
}


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

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n)  FOR(i, 0, n)
#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
  vector<int> v(3);
  REP(i, 3) cin >> v[i];
  ASC(v);
  int sum = 0;
  FOR(i, 1, 3) sum += abs(v[i - 1] - v[i]);
  cout << sum << endl;
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  ll n,a,b; cin >> n >> a >> b;
  vector<ll> x(n);cin >> x;
  for(int i = n-1; i > 0; --i) x[i] -= x[i-1];
  x.front()=0;
  ll ans = 0;
  for(auto&e:x)ans += min(b,e*a);
  cout << ans << endl;
  return 0;
}


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

namespace ts{
  const int tsv=101000,tse=5202333;
  int n,ans[tsv];
  struct R{
    int to,nex;
  }r[tse];
  int hea[tsv<<1],cnt,bel[tsv<<1],blt,st[tsv<<1],top,dfn[tsv<<1],dft,low[tsv<<1];
      
  void RE(){
    memset(hea,0,sizeof hea);cnt=0;
    memset(bel,0,sizeof bel);blt=0;
    memset(dfn,0,sizeof dfn);dft=0;
  }
  void A(int u,int v){
    r[++cnt]=(R){v,hea[u]};hea[u]=cnt;
  }
  void must(int x,int x2,int y,int y2){
    A(x<<1|x2,y<<1|y2);
  }
  void XX(int x,int x2,int y,int y2){ // can't be together
    //printf("XX::%d %d %d %d\n",x,x2,y,y2);
    must(x,x2,y,y2^1);
    must(y,y2,x,x2^1);
  }
  void dfs(int x){
    low[x]=dfn[x]=++dft;
    st[++top]=x;
    int y;
    for (int i=hea[x];i>0;i=r[i].nex){
      y=r[i].to;
      if (!dfn[y]){
	dfs(y);
	low[x]=min(low[x],low[y]);
      }else{
	if (!bel[y]){
	  low[x]=min(low[x],dfn[y]);
	}
      }
    }
    if (low[x]==dfn[x]){
      bel[x]=++blt;
      while (st[top]!=x){
	bel[st[top]]=blt;
	top--;
      }
      top--;
    }
  }
  bool realmain(int n_){ // [1,n]
    n=n_;
    int u,v;
    for (int i=2;i<=(n<<1|1);i++){
      if (!bel[i]){
	top=0;
	dfs(i);
      }
    }
    for (int i=1;i<=n;i++){
      if (bel[i<<1|0]==bel[i<<1|1]) return 0;
      ans[i]=bel[i<<1|0]>bel[i<<1|1]?1:0;
    }
    return 1;
  }
}

int n, m, rt, cnt, lc[101000], rc[101000];
#define pii pair<int,int>
#define fi first
#define se second
vector<int>wei[10100];
pii p[20200];

void build(int &x,int l,int r){
  if (l==r){
    x=l; return;
  }
  x=++cnt;
  int mid=l+r>>1;
  build(lc[x],l,mid); ts::XX(x,0,lc[x],1);
  build(rc[x],mid+1,r); ts::XX(x,0,rc[x],1);
}

void gao(int &l,int &r,pii s,pii t){
  l=lower_bound(p+1,p+m+1,s)-p;
  r=lower_bound(p+1,p+m+1,t)-p-1;
}

void add(int x,int l,int r,int st,int en,int who){
  st=max(st,l); en=min(en,r);
  if (st>en) return;
  if (st==l&&en==r){
    ts::XX(x,1,who,1);
    return;
  }
  int mid=l+r>>1;
  add(lc[x],l,mid,st,en,who);
  add(rc[x],mid+1,r,st,en,who);
}

bool chk(int now){
  ts::RE();
  cnt=m; build(rt,1,m);
  for (int i=1;i<=n;++i)
    ts::XX(wei[i][0],0,wei[i][1],0);

  for (int i=1;i<=m;++i){
    int l, r;
    gao(l,r,(pii){p[i].fi-now+1,-1},p[i]);
    add(rt,1,m,l,r,i);
    gao(l,r,(pii){p[i].fi,p[i].se+1},(pii){p[i].fi+now-1,1e9});
    add(rt,1,m,l,r,i);
  }
  return ts::realmain(cnt);
}

int main(){
  
  cin>>n; int x;
  for (int i=1;i<=n;++i){
    cin>>x; p[++m]=(pii){x,i};
    cin>>x; p[++m]=(pii){x,i};
  }
  sort(p+1,p+m+1);
  for (int i=1;i<=m;++i)
    wei[p[i].se].push_back(i);

  int l=0, r=1e9+7, mid, ans=0;
  for (;l<=r;){
    mid=l+r>>1;
    if (chk(mid)){
      ans=mid; l=mid+1;
    }else{
      r=mid-1;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 20992
#include<bits/stdc++.h>
    #define ll long long
    #define f   first
    #define s   second
    #define pb          push_back
    #define mod         1000000007
    #define hell        998244353
    #define inf         1000000000000000000LL
    using namespace std;
    ll n,k,m,l,mx,sum,q;
    //ll dp[15][1005]
    void solve()
    {   ll a,b,x,y;
        set<string> s;
        cin>>n;
        for(int i=0;i<n;i++)
        {
            string s1;
            cin>>s1;
            s.insert(s1);
        }
        cout<<s.size();
        
    }    
    int main()
    {  
        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
        //cout<<primes.size();
        
        ll t=1;
        //cin>>t;
        while(t--)
            solve();

    }


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

#define int long long

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int mi[26];

signed main(){
    int n;cin>>n;
    fill_n(mi,26,INT_MAX);
    rep(i,n){
        string s;cin>>s;
        vint cnt(26);
        rep(j,s.size())cnt[s[j]-'a']++;
        rep(j,26)chmin(mi[j],cnt[j]);
    }

    string ans;
    rep(i,26)ans+=string(mi[i],'a'+i);
    cout<<ans<<endl;
    return 0;
}


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

int main()
{
  int n, x, c;
  while (1)
  {
    c = 0;
    scanf("%d %d", &n, &x);
    if (n == 0 && x == 0)
      break;
    for (int i = 1; i <= n; i++)
    {
      for (int j = i + 1; j <= n; j++)
      {
        for (int k = j + 1; k <= n; k++)
        {
          if (i + j + k == x)
            c++;
        }
      }
    }
    printf("%d\n", c);
  }

  return 0;
}


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

int main()
{
    int A, B, K;
    int ans = 0;
    cin >> A >> B >> K;

    for (int i = min(A, B); i > 0; i--)
    {
        if (A % i == 0 && B % i == 0)
        {
            ans++;
            if (ans == K)
            {
                cout << i << endl;
                return 0;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 256
import sys
a,b,c,x,y=map(int,input().split())
val=0
if a+b<=2*c:
  print(a*x+b*y)
  sys.exit()
else:
  m=min(x,y)
  val+=m*c*2
  x=x-m
  y=y-m
  if x==0:
    if y==0:
      print(val)
      sys.exit()
    val+=min(b*y,y*2*c)
  if y==0:
    val+=min(a*x,x*2*c)
  print(val)
  sys.exit()


Measured memory_bytes: 3064
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i = (a);i < (n);i++)
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

int main(){
    int a[4],b[2],memo = 0;
    
    cin >> a[0] >> a[1] >> a[2] >> a[3] >> b[0] >> b[1];
    
    sort(a,a+4,greater<int>());
    
    rep(i,0,3){
        memo += a[i];
    }
    
    memo += max(b[0],b[1]);
    cout << memo << endl;
    
    
    return 0;
}


Measured memory_bytes: 3172
# -*- coding: utf-8 -*-
from collections import deque
def inpl(): return map(int, input().split())
N = int(input())

G = [[] for _ in range(N+1)]
for _ in range(N-1):
    a, b, c = inpl()
    G[a].append((b, c))
    G[b].append((a, c))

D = [0] * (N+1)
Q, K = inpl()
DQ = deque([[K, 0]])
visited = [False]*(N+1)

while DQ:
    p, c = DQ.popleft()
    D[p] = c
    visited[p] = True
    for q, d in G[p]:
        if not visited[q]:
            DQ.append([q, c+d])

for _ in range(Q):
    x, y = inpl()
    print(D[x] + D[y])

Measured memory_bytes: 51096
function parseInt(x) parse(Int, x) end

function power(n)
	m = n
	t = 0
	while(m%2 == 0)
		m = m/2
		t += 1
	end
	return(t)
end

function main()
	n = readline() |> n -> parseInt(n)
	a = readline() |> split |> a -> parseInt.(a)
	sum = 0
	for i in 1:n
		sum += power(a[i])
	end
	print(sum)
end

main()

Measured memory_bytes: 131720
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(ull i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define iter(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define riter(i,c) for(auto i=(c).rbegin(); i!=(c).rend(); ++i)
const double eps = 1e-10;
const double pi = acos(-1.0);
const double inf = (int)1e8;

int main(){
  rep(i,9)rep(j,9){
    cout << i+1 << "x" << j+1 << "=" << (i+1)*(j+1) << endl;
  }
}

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

#define debug(...) fprintf(stderr, __VA_ARGS__)

#ifndef AT_HOME
#define getchar() IO::myGetchar()
#define putchar(x) IO::myPutchar(x)
#endif

namespace IO {
	static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23;

	inline char myGetchar() {
		static char buf[IN_BUF], *ps = buf, *pt = buf;
		if (ps == pt) {
			ps = buf, pt = buf + fread(buf, 1, IN_BUF, stdin);
		}
		return ps == pt ? EOF : *ps++;
	}

	template<typename T>
	inline bool read(T &x) {
		bool op = 0;
		char ch = getchar();
		x = 0;
		for (; !isdigit(ch) && ch != EOF; ch = getchar()) {
			op ^= (ch == '-');
		}
		if (ch == EOF) {
			return false;
		}
		for (; isdigit(ch); ch = getchar()) {
			x = x * 10 + (ch ^ '0');
		}
		if (op) {
			x = -x;
		}
		return true;
	}

	inline int readStr(char *s) {
		int n = 0;
		char ch = getchar();
		for (; isspace(ch) && ch != EOF; ch = getchar())
			;
		for (; !isspace(ch) && ch != EOF; ch = getchar()) {
			s[n++] = ch;
		}
		s[n] = '\0';
		return n;
	}

	inline void myPutchar(char x) {
		static char pbuf[OUT_BUF], *pp = pbuf;
		struct _flusher {
			~_flusher() {
				fwrite(pbuf, 1, pp - pbuf, stdout);
			}
		};
		static _flusher outputFlusher;
		if (pp == pbuf + OUT_BUF) {
			fwrite(pbuf, 1, OUT_BUF, stdout);
			pp = pbuf;
		}
		*pp++ = x;
	}

	template<typename T>
	inline void print_(T x) {
		if (x == 0) {
			putchar('0');
			return;
		}
		static int num[40];
		if (x < 0) {
			putchar('-');
			x = -x;
		}
		for (*num = 0; x; x /= 10) {
			num[++*num] = x % 10;
		}
		while (*num){
			putchar(num[*num] ^ '0');
			--*num;
		}
	}

	template<typename T>
	inline void print(T x, char ch = '\n') {
		print_(x);
		putchar(ch);
	}

	inline void printStr_(const char *s, int n = -1) {
		if (n == -1) {
			n = strlen(s);
		}
		for (int i = 0; i < n; ++i) {
			putchar(s[i]);
		}
	}

	inline void printStr(const char *s, int n = -1, char ch = '\n') {
		printStr_(s, n);
		putchar(ch);
	}
}
using namespace IO;

const int N = 100005;

int n, m, q, a[N], b[N];

void solve() {
	read(n), read(m), read(q);
	for (int i = 1; i <= n; ++i) {
		read(a[i]);
	}
	for (int i = 1; i <= m; ++i) {
		read(b[i]);
	}
	int ans = *std::min_element(a + 1, a + 1 + n) + *std::min_element(b + 1, b + 1 + m);
	for (int i = 1; i <= q; ++i) {
		int x, y, c;
		read(x), read(y), read(c);
		ans = std::min(ans, a[x] + b[y] - c);
	}
	print(ans);
}

int main() {
	int T = 1;
	// read(T);
	while (T--) {
		solve();
	}
}


Measured memory_bytes: 7256
#include <iostream>
#include <vector>

using namespace std;

int main() {
	/* ----- 変数宣言 ----- */
	long long n;
	vector<int> vn;
	int len = 0;

	int i;
	int ans = 0;

	/* ----- 入力 ----- */
	cin >> n;

	/* ----- 計算 ----- */
	// 各位を配列に格納
	while (n > 0) {
		vn.push_back(n % 10);
		len++;

		n /= 10;
	}
	len--;

	// 小さい位が9未満なら、隣を一つ小さくして9にする
	for (i = 0; i < len; i++) {
		if (vn[i] < 9) {
			vn[i] = 9;
			vn[i + 1]--;
		}
	}

	// 各位の合計を計算
	len++;
	for (i = 0; i < len; i++) {
		ans += vn[i];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
  var n int
  var k int
  var tmp int
  var min int
  fmt.Scan(&n)
  sc := bufio.NewScanner(os.Stdin)
  var s string
  if sc.Scan(){
	s = sc.Text()
  }
  slice := strings.Split(s, " ")
//  k := make([]int, len[n])
  for i := 0; i<n; i++ {
	k,_ = strconv.Atoi(slice[i])
	tmp = 0
	for j:=0; j%2==0;{
	  if k%2 == 0 {
		k = k/2
		tmp = tmp + 1
	  }
	  j = k%2
//	  fmt.Println(tmp)
	}
	if i == 0 {
	  min = tmp
	} else if min > tmp{
	  min = tmp
	}
  }
  fmt.Println(min)

}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
char a[111],b[111],c[111];
int main(){
    scanf("%s\n%s",a,b);
    int la,lb,lc;
    la=strlen(a);
    lb=strlen(b);
    /*lc = la + lb;
    for(int i=0;i<lc;i++){
        if(i%2==0)c[2*i]=a[i];
        else c[2*i+1]=b[i];}*/
    for(int i=0;i<lb;i++)
        printf("%c%c",a[i],b[i]);
    la==lb?la=lb:printf("%c",a[la-1]);
    printf("%s\n",c);
    return 0;}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int n, a[8], aa, i, j, k, tmp;
	scanf("%d", &n);
	for(i = 0; i < n; i++){
		for(j = 0; j < 8; j++) scanf("%1d", &a[j]);
		for(j = 0; j < 7; j++){
			for(k = j + 1; k < 8; k++){
				if(a[j] < a[k]){
					tmp = a[j];
					a[j] = a[k];
					a[k] = tmp;
				}
			}
		}
		aa = (a[0] * 10000000 + a[1] * 1000000 + a[2] * 100000 + a[3] * 10000 + a[4] * 1000 + a[5] * 100 + a[6] * 10 + a[7]);
		aa -= (a[7] * 10000000 + a[6] * 1000000 + a[5] * 100000 + a[4] * 10000 + a[3] * 1000 + a[2] * 100 + a[1] * 10 + a[0]);
		printf("%d\n", aa);
	}
	return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define int long lnog

//const int maxn = 1; 


main(){
	unsigned long long q , h , s , d; cin >> q >> h >> s >> d;
	q *= 8;
	h *= 4;
	s *= 2;
	long n; cin >> n;
	if(n % 2 == 0)
		cout << (n / 2) * min(q , min(h , min( s, d))) << endl;
	else
		cout << (n / 2) * min(q , min(h , min( s, d))) + min(q , min(h , s)) / 2 << endl;
}

Measured memory_bytes: 256