akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;

namespace MixJuce
{
    class Program
    {
        static void Main(string[] args)
        {
            int N, K;

            string inD0 = Console.ReadLine();
            string[] cngD0 = inD0.Split(' ');

            int[] p = new int[1001];

            List<int> list = new List<int>();

            N = int.Parse(cngD0[0]);
            K = int.Parse(cngD0[1]);

            string inD1 = Console.ReadLine();
            string[] cngD1 = inD1.Split(' ');

            for (int i = 0; i <= N - 1; i++)
            {
                p[i] = int.Parse(cngD1[i]);
                list.Add(p[i]);

            }

            int cnt = list.Count;

            list.Sort();

            var res = 0;
            int cnt_p = 0;
            foreach(int val in list)
            {
                res += val;
                cnt_p++ ;
                if (cnt_p >= K) break;
            }

            Console.WriteLine(res);
        }


    }
}
   

Measured memory_bytes: 28004
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define MOD3 1000000000
#define MOD2 998244353 
float PHI = 1.6180339;
const float  PI_F=3.14159265358979f;
#define MAX 1000 m
#define endl "\n"    
#define manhunt 32 
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define pi 3.1415926535897932384626433
//typedef long long float;
#define int long long
//#define double long double
typedef pair<int, int> pii;
//#define float unsigned long long
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define CHAR_SIZE 26 

int modpow(int x, int n, int m) { if (n == 0) return 1%m; long long u = modpow(x,n/2,m); u = (u*u)%m; if (n%2 == 1) u = (u*x)%m; return u; } 


int add(int x, int y,int m) 
{
	x += y;
	if (x >= m) return x - m;
	return x;
}
int sub(int x, int y) 
{
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
int inv(int a, int m = MOD2)
{
	return modpow(a, m - 2, m);
}
int mul(int a, int b,int m) 
{
	return (long long) a * b % m;
}


int nCrModp(int n, int r, int p) 
{ 
    int C[r+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1; 
    for (int i = 1; i <= n; i++) 
    { 
        for (int j = min(i, r); j > 0; j--) 
            C[j] = (C[j] + C[j-1])%p; 
    } 
    return C[r]; 
} 

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

int32_t main()
{
    /* freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout); */
    FAST
    cout << fixed << setprecision(12);

    int n;
    cin>>n;
    int arr[n+10];
    map<int,int>mp;
    int sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        ++mp[arr[i]];
        sum+=arr[i];
    }
    int q;
    cin>>q;
    while(q--)
    {
        int b,c;
        cin>>b>>c;
        int diff=c-b;
        int howmuch=mp[b];
        mp[b]=0;
        int added=howmuch*diff;
        sum+=added;
        mp[c]+=howmuch;
        cout<<sum<<endl;
    }
    
    
    return 0;
}





Measured memory_bytes: 10348
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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 (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/






int S;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> S;

    map<int, int> memo;
    memo[S] = 1;
    int cur = S;

    rep(id, 2, 1010101) {
        int nxt;
        if (cur % 2 == 0) nxt = cur / 2;
        else nxt = 3 * cur + 1;

        if (memo[nxt]) {
            printf("%d\n", id);
            return;
        }
        memo[nxt] = id;
        cur = nxt;
    }
}

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

using namespace std;

typedef long long ll;

int main() {
    ll h, cnt = 0, ans = 1;
    cin >> h;
    while (h) {
        h /= 2;
        ++cnt;
    }
    for (ll i = 0; i < cnt; ++i)
        ans *= 2;
    --ans;
    cout << ans << '\n';
}

Measured memory_bytes: 256
def f(n)
  if n % 2 == 0
    n / 2
  else
    3 * n + 1
  end
end

s = gets.to_i
arr = [s]
s = f(s)
m = 2
loop do
  break if arr.include?(s)
  
  arr << s
  s = f(s)
  m += 1
end
puts m

Measured memory_bytes: 1788
//
// Created by 伊東麻沙美 on 2019/10/22.
//

#include<iostream>
#include<algorithm>
#include<stdlib.h>
using namespace std;


int main() {
    int D;
    cin>>D;

    if(D==25){
        std::cout<<"Christmas";
    }else if(D == 24){
        std::cout<<"Christmas Eve";
    }else if(D == 23){
        std::cout<<"Christmas Eve Eve";
    }else if(D == 22){
        std::cout<<"Christmas Eve Eve Eve";
    }
     return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		int[] a = new int[n];
		for(int i=0; i<n; i++){
			a[i] = scn.nextInt();
		}
      	int max = 0;
      	int count = 0;
      	for(int i=0; i<n; i++){
          if(a[i]>=max){
            count++;
            max=a[i];
          }
        }
      	System.out.println(count);
	}
}

Measured memory_bytes: 35796
s = input()
n = len(s)
power = [0]*(n+1)
power[-1] = 1
x = 1
for i in range(n-1,-1,-1):
	x = (x*10) % 2019
	power[i] = x
mod19 = [0]*(n+1)
cnt = [0]*2020
cnt[0] = 1
x=0
mod19[n] = 0
for i in range(n-1, -1,-1):
	x = (x+int(s[i])*power[i])%2019
	mod19[i] = x
	cnt[x]+=1
ans = 0
for i in range(2020):x = cnt[i];ans+= x*(x-1)//2
print(ans)




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

using namespace std;

long s[222], d[222][111111];
int main() {
	int n, x, p = 1e9 + 7;
	cin >> n >> x;
	for (int i = 0; i < n; i++)
		cin >> s[i];
	sort(s, s + n);
	for (int i = 0; i <= x; i++)
		d[0][i] = i;
	for (int i = 0; i < n; i++)
		for (int j = 0; j <= x; j++)
			d[~i & 1][j] = (d[i & 1][j%s[i]] + d[i & 1][j] * i) % p;
	cout << d[n & 1][x] << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <climits>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;

string b;

bool hantei(char p){
	for(int i=0;i<3;i++){
		if(b[i+0]==p&b[i+3]==p&b[i+6]==p)return true;
		if(b[i*3]==p&b[i*3+1]==p&b[i*3+2]==p)return true;
	}
	if(b[0]==p&b[4]==p&b[8]==p)return true;
	if(b[2]==p&b[4]==p&b[6]==p)return true;
	
	return false;
}

int main(){
	int n;
	while(cin>>b){
		if(hantei('o'))cout<<"o"<<endl;
		else if(hantei('x'))cout<<"x"<<endl;
		else cout<<"d"<<endl;
	}
}

Measured memory_bytes: 0
def set_depth(id, depth)
  @depths[id] = depth

  @nodes[id].each do |child_id|
    set_depth(child_id, depth + 1)
  end
end

def root_id
  @nodes.each do |k, _|
    if @parents[k] == -1
      return k
    end
  end
end

def type(id)
  return 'root' if @parents[id] == -1
  return 'leaf' if @nodes[id].empty?
  'internal node'
end

n = gets.chomp.to_i
@nodes = Hash.new([])
@parents = Hash.new(-1)
@depths = {}
n.times do
  id, k, *c = gets.chomp.split.map(&:to_i)
  @nodes[id] = c
  c.each do |ci|
    @parents[ci] = id
  end
end
set_depth(root_id, 0)

@nodes.keys.sort.each do |k|
  puts "node #{k}: parent = #{@parents[k]}, depth = #{@depths[k]}, #{type(k)}, #{@nodes[k]}"
end


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

int main(){
    string s;string t;
    cin >>s>>t;
    ll n=s.size();
    ll m=t.size();
    vector<vector<ll>>dp(n+1,vector<ll>(m+1,0));
    dp[0][0]=0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            ll cost=(s[i]==t[j])?1:0;
            dp[i+1][j+1]=max({dp[i][j]+cost,dp[i+1][j],dp[i][j+1]});
        }
    }
    string ans="";
    while(n>0&&m>0){
        if(dp[n][m]==dp[n-1][m]){
            n--;
        }
        else if(dp[n][m]==dp[n][m-1]){
            m--;
        }
        else {
            ans=s[n-1]+ans;
            n--;m--;
        }
    }
    cout <<ans <<endl;
    return 0;
}



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

const int INF = INT_MAX / 2;

int main(){
    int N, M; cin >> N >> M;
    priority_queue<int> que;
    for (int i = 0; i < N; i++)
    {
        int a; cin >> a;
        que.push(a);
    }

    for (int i = 0; i < M; i++)
    {
        int mprice = que.top(); que.pop();
        que.push(mprice/2);
    }
    long ans = 0;
    while(!que.empty()){
        ans += que.top();
        que.pop();
    } 
    cout << ans << endl;
}

Measured memory_bytes: 892
#include <iostream>
#include <cstdio>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <stdlib.h>
#include <functional>
#include <string>
#include <list>
#include <fstream>
#include <iomanip>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <cassert>
#include <unordered_set>
#include <chrono>
#include <bitset>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int

#include <nmmintrin.h>
#ifdef _MSC_VER

#define __builtin_popcount _mm_popcnt_u32
#define __builtin_popcountll _mm_popcnt_u64
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}

struct Edge {
	int from, to, s;
};

signed main() {

	int n;
	cin >> n;
	vector<ll> num(n);
	ll sum = 0;
	REP(i, n) {
		scanf("%d", &num[i]);
	}

	sort(ALL(num));

	int i = 0, j = n - 1;
	vector<ll> e,o;
	ll esum = 0, osum = 0;
	while (i < j) {
		e.push_back(num[i]);
		esum += num[i];
		o.push_back(num[j]);
		osum += num[j];
		i++;
		j--;
	}
	if (i == j) {
		sum = max(osum * 2 - (esum + num[i]) * 2 + num[i] + e[e.size() - 1],
			(num[i] + osum) * 2 - esum * 2 - num[i] - o[o.size() - 1]);
	}
	else
		sum = osum * 2 - esum * 2 - o[o.size()-1] + e[e.size() - 1];
	cout << sum << endl;
	return 0;
}

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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;i++)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;i++)
#define ROF(i,a,b) for(int i=(a)-1,i##_cond=(b);i>=i##_cond;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((int)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll,ll> pii;


#define int ll

const int inf = 1ll<<62;
const int mod = 1e9+7;

main(){
  string s; cin >> s;
  if(sz(s) == 26){
    if(s == "zyxwvutsrqponmlkjihgfedcba"){
      cout << -1 << endl;
    }else{
      ROF(i, sz(s), 0){
	if(s[i] < s[i - 1]) continue;
	vi used(26);
	rep(j, i - 1){
	  cout << s[j];
	  used[s[j] - 'a']++;
	}
	used[s[i-1] - 'a']++;
	//dump(used);
	FOR(j, s[i - 1] - 'a', 26){
	  if(used[j] == 0){
	    cout << char('a' + j) << endl;
	    break;
	  }
	}
	break;
      }
    }
  }else{
    vi used(26);
    rep(i, sz(s)){
      used[s[i] - 'a'] = 1;
    }
    cout << s;
    rep(i, 26)
      if(used[i] == 0){
	cout << char('a' + i) << endl;
	break;
      }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

int A[3][3];
int N;

void _main() {
    REP (i, 3) REP (j, 3) cin >> A[i][j];
    cin >> N;
    REP (t, N) {
        int b;
        cin >> b;
        REP (i, 3) REP (j, 3) {
            if (A[i][j] == b) A[i][j] = -1;
        }
    }
    bool yes = false;
    REP (i, 3) {
        bool ok = true;
        REP (j, 3) ok &= (A[i][j] == -1);
        yes |= ok;
        ok = true;
        REP (j, 3) ok &= (A[j][i] == -1);
        yes |= ok;
    }
    bool ok = true;
    REP (i, 3) ok &= (A[i][i] == -1);
    yes |= ok;
    ok = true;
    REP (i, 3) ok &= (A[i][2 - i] == -1);
    yes |= ok;
    cout << (yes ? "Yes" : "No") << endl;
}

signed main(signed argc, char **argv) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 256
#include <numeric>
#include <iostream>
#include <sstream>
#include <vector>
#include <cstdio>
#include <map>
#include <set>
#include <functional>
#include <queue>
#include <string>
#include <bitset>
#include <cassert>
#include <algorithm>
#include <cmath>
#include <set>
#include <algorithm>
#include <tuple>
#include <sstream>

using namespace std;

#ifdef LOCAL
#define logv(a) {cerr << #a << " = "; for (auto& e : a) {cerr << e << " ";} cerr << "\n";}
#define logvp(a) {cerr << #a << " = "; for (auto& e : a) {cerr << "(" << e.first << ", " << e.second << ") ";} cerr << "\n";}
#define logvv(a) {cerr << #a << " = \n"; for (auto& r : a) { for (auto& e : r) {cerr << e << " ";} cerr << "\n";} }
#define logvf(a, field) {cerr << #a"."#field << " = \n"; for (auto& e : a) { cerr << e.field << " ";} cerr << "\n"; }
#define logs(a) cerr << #a << " = " << (a) << "\n";
#define logss(a, b) cerr << #a << " = " << (a) << ", " << #b << " = " << (b) << "\n";
#define logp(a) cerr << #a << " = " << "(" << a.first << ", " << a.second << ")" << "\n";
#define cond(pred, stmt) if (pred) { stmt }
#else
#define logv(a)
#define logvp(a)
#define logvv(a)
#define logvf(a, field)
#define logs(a)
#define logss(a, b)
#define logp(a)
#define cond(pred, stmt)
#endif

#define forn(a, e) for (int a = 0; a < (int)e; a++)
#define forr(a, s, e) for (int a = s; a < (int)e; a++)

using i64 = long long;

template<typename T>
using Pair = array<T, 2>;

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

    i64 n;
    while (cin >> n) {
        cout << (n - 1) * n / 2 << endl;
    }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

__attribute__((constructor)) void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main() {
    int A, B, C, X;
    cin >> A >> B >> C >> X;
    vector<int> pairs;

    repto(i, A) {
        repto(j, B) {
            pairs.pb(i * 500 + j * 100);
        }
    }

    int l = pairs.size();
    int count = 0;
    rep(i, l) {
        repto(j, C) {
            if ((pairs[i] + j * 50) == X) count ++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
typedef long long ll;
using namespace std;
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;
}

struct Shop {
    string name;
    int point;
    int i;
};

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

    int N;
    cin >> N;
    vector<Shop> shop(N);
    REP(i, N) {
        cin >> shop[i].name >> shop[i].point;
        shop[i].i = i + 1;
    }

    sort(ALL(shop), [&](const Shop x, const Shop y) {
        if (x.name == y.name)
            return x.point > y.point;
        return x.name < y.name;
    });
    for (auto &i : shop) {
        std::cout << i.i << '\n';
    }

    return 0;
}

Measured memory_bytes: 256
import java.io.FileInputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	
	static int n, q;
	static int[] okday;
	
	static void start()
	{
		int okmax = 0;
		int day;
		
		for(day = 1;day < 100;day++)
		{
			okmax = Math.max(okmax, okday[day]);
		}
		if(okmax < q)
		{
			System.out.println("0");
			return;
		}

		for(day = 1;day < 100;day++)
		{
			if(okday[day] == okmax)
			{
				System.out.println(day);
				return;
			}
		}
	}
	
	public static void main(String[] args)
	{
		
		Scanner sca = new Scanner(System.in);
		
		while(true)
		{
			n = sca.nextInt();
			q = sca.nextInt();
			if(n == 0) break;
			
			okday = new int[100];
			for(int i = 0;i < 100;i++) okday[i] = 0;
			
			for(int i = 0;i < n;i++)
			{
				int m = sca.nextInt();
				for(int j = 0;j < m;j++) okday[sca.nextInt()]++;
			}
			
			start();
		}
	}
}

Measured memory_bytes: 62656
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include<stack>
#include <functional>
#include <queue>
#include <regex>
#include<time.h>

using namespace std;


#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl

#define Tof(x) (x) ? Yes : No
#define TOF(x) (x) ? YES : NO
#define tof(x) (x) ? yes : no

using ll = long long;

constexpr ll MOD = 1000000007;
constexpr ll INF = 1050000000;


/*vectorの要素を全部確認するやつだよ。普通に拡張for文したほうがいいよ。

for (vector<int>::iterator itr = ans.begin(); itr != ans.end(); ++itr) {
	cout << *itr << " ";
}

*/


/*for文でx,yを上下左右確認するやつだよ。正直使いづらいよ。

int dy[] = { 0, 1, 0, -1 };
int dx[] = { 1, 0, -1, 0 };


for (int i = 0; i < 4; i++) {
	int ny = y + dy[i];
	int nx = x + dx[i];
}

*/


/*繰り返し二乗法だよ。modもとってくれるよ。n^kをmodで割った余りでやってくれるよ。

ll POW_MOD(ll n, ll k, ll mod) {
	ll r = 1;

	for (; k > 0; k >>= 1) {
		if (k & 1) {
			r = (r * n) % mod;
		}
		n = (n * n) % mod;
	}
	return r;
}

*/


/*実行開始からの経過時間を表すよ。

while (clock() < 1900000) {  }

*/


/*まだ使えないテクニックのメモだよ。

for (int bit = 0; bit < (1<<n); ++bit)//bit全探索用のfor文だよ

*/


/*2重for文書くのめんどくなった時用だよ。

for (int i = 0; i < h; ++i) {
	for (int j = 0; j < w; ++j) {

	}
}

*/



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


	if (k == 1) { cout << "0" << endl; }
	else {
		cout << n - k << endl;
	}





	return 0;
}


Measured memory_bytes: 256
S=input()
Q=int(input())
reverse=0
back=""
front=""
for i in range(Q):
    T=input()
    if T[0]=="1":
        reverse=1-reverse
    else:
        q,F,C=T.split()
        F=int(F)
        if F-reverse==1:
            front=C+front
        else:
            back+=C

S=front+S+back
if reverse==0:
    print(S)
else:
    S=S[::-1]
    print(S)


Measured memory_bytes: 4452
#include <iostream>
#include <string>
using namespace std;
int dp[1000][1000];
int main(){
    int n,m,c[1000],d[1000];
    cin>>n>>m;
    for(int i=0;i<n;i++)
        cin>>d[i];
    for(int i=0;i<m;i++)
        cin>>c[i];
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            dp[i][j]=0;
    dp[1][0]=d[0]*c[0];
    for(int i=2;i<=n;i++)
        dp[i][0]=1000000000;
    for(int i=1;i<=n;i++){
        for(int j=1;j<m;j++){
            if(j==0)
                dp[i][0]=dp[i-1][0]+d[i-1]*c[j];
            else if(dp[i][j-1]<=dp[i-1][j-1]+d[i-1]*c[j])
                dp[i][j]+=dp[i][j-1];
            else
                dp[i][j]+=dp[i-1][j-1]+d[i-1]*c[j];
        }
    }
    cout<<dp[n][m-1]<<endl;
    return 0;
}

Measured memory_bytes: 4344
#互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

import math
MOD = 998244353
N,M,K = [int(hoge) for hoge in input().split()]
NcK = []
POWER = []
cur = 1#Nc0
for k in range(K+1):
    NcK.append(cur)
    cur *= (N-1-k)* mod_inv(k+1,MOD)
    cur %= MOD    

ans = 0
Power = 1
for k in range(N-1-K):#M-1**n-1-K
    Power *= M-1
    Power %= MOD

for k in range(K,-1,-1):
    ans += Power * NcK[k]
        #M-1 ** N-1-k ということは…？
    if k:
        Power *= M-1
        Power %= MOD
    

print((M*ans)%MOD)


Measured memory_bytes: 95924
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;

int main(){
  ll N,M,K;
  cin >> N >> M >> K;
  vector<ll> a(N+1,0),b(M+1,0);
  
  for(ll i=0;i<N;i++){
    ll x;
    cin >> x;
    a.at(i+1) = a.at(i) + x;
  }
  
  /*
  for(int i=0;i<N+1;i++){
	cout << a.at(i) << endl;
  }
  */
  
  for(ll i=0;i<M;i++){
    ll x;
    cin >> x;
    b.at(i+1) = b.at(i) + x;
  }
  
  ll ans = 0;
  ll j=M;
  for(ll i=0;i<N+1;i++){
    if(a.at(i) > K){
      break;
    }
    while(b.at(j) > K - a.at(i)){
      j--;
    }
    if(ans < i+j){
      ans = i+j;
    }
  }
  
  cout << ans << endl;
  
  return(0);
}

Measured memory_bytes: 6420
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
ll n,a[2000];
bool solve(){
	cin >> n;
	if(n == 0)
		return false;
	REP(i,n) 
		cin >> a[i];


	ll ans = 100000000;
	REP(i,n) {
		FOR(j,i + 1,n)  {
			ans = min(ans,abs(a[i] - a[j]));
		}
	}
	cout << ans << endl;
	return true;
}

int main(void) {
	while(solve());
	return 0;
}



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

using ll = long long;
using P = pair<int, int>;
//using P = pair<double, double>;
using edge = struct {int to; ll cost;};

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

const int di[] = {-1, 0, 1, 0, 1, 1, -1, -1};
const int dj[] = {0, -1, 0, 1, 1, -1, 1, -1};
const int INF = 1001001001;

const int mod = 1000000007;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};
struct combination
{
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1)
  {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i)
      fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i)
      ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k)
  {
    if (k < 0 || k > n)
      return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

void solve()
{
  int n, x;
  cin >> n >> x;
  vector<int> m(n);
  rep(i, n) cin >> m[i];
  sort(ALL(m));
  x -= accumulate(ALL(m), 0);
  cout << n+x/m[0] << "\n";
}

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

Measured memory_bytes: 256
N,M = list(map(int,input().split()))
from collections import deque

G = [[] for i in range(N)]
for i in range(M):
    A,B=list(map(int,input().split()))
    G[A-1].append(B-1)
    G[B-1].append(A-1)

Ls = []
dist = [0]*N
for i in range(N):
    if dist[i]==1:
        continue
    s = i
    que = deque([s])
    dist[s] = 1
    L = [s]
    while que:
        v = que.popleft()
        for w in G[v]:
            if dist[w]==1:
                continue
            dist[w] = 1
            que.append(w)
            L.append(w)
    Ls.append(L)
out = 0
for L in Ls:
    out=max(len(L),out)
print(out)


Measured memory_bytes: 114548
# -*- coding:utf-8 -*-
import sys
from collections import OrderedDict


def cleate_node_dict(children):
    node_dict = OrderedDict()
    for val in children:
        node_dict[val] = None
    return node_dict


def cleate_tree(nodes):
    tree = nodes.copy()
    for node, children in nodes.items():
        for key in children.keys():
            children[key] = nodes[key]
            del tree[key]

    return tree


def rec(current, acc, parent=-1, depth=0):
    if current == {}:
        return
    for node, children in current.items():
        cld_lst = list(children.keys())
        acc[node] = "node {0}: parent = {1}, depth = {2}, {3}, {4}".format(
                node, parent, depth, node_type(parent, children), cld_lst)
        rec(children, acc, node, depth+1)


def node_type(parent, children):
    if parent == -1:
        return "root"
    elif children != {}:
        return "internal node"
    else:
        return "leaf"


def rooted_trees(lst, n):
    nodes = {val[0]: cleate_node_dict(val[2:]) for val in lst}
    tree = cleate_tree(nodes)
    node_info = [None] * n
    rec(tree, node_info)
    print("\n".join(node_info))


if __name__ == "__main__":
    n = int(input())
    lst = [[int(n) for n in val.split()] for val in sys.stdin.readlines()]
    rooted_trees(lst, n)

Measured memory_bytes: 176224
#include<stdio.h>
int main()
{
    int N,X ,a,i,s=0,c=1;
    scanf("%d%d",&N,&X);
    for(i=0;i<N;i++)
        {
            scanf("%d",&a);
            s=s+a;
            if(s<=X) {
                c=c+1;
            }


        }
        printf("%d\n",c);
        return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int n,m,ans=0;
vector<vector<int> > s(15);
vector<int> v,p;
int main()
{
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int x;
		cin>>x;
		v.push_back(x);
		for(int j=0;j<x;j++)
		{
			int y;
			cin>>y;
			s[i].push_back(y);
		}
	}
	for(int i=0;i<m;i++)
	{
		int x;
		cin>>x;
		p.push_back(x);
	}
	for(int i=0;i<(1<<n);i++)
	{
		bool flag=true;
		for(int j=0;j<m;j++)
		{
			int cnt=0;
			for(int k=0;k<s[j].size();k++)
				if((1<<(s[j][k]-1))&i)
					++cnt;
			if(cnt%2!=p[j])
			{
				flag=false;
				break;
			}
		}
		if(flag)
			++ans;
	}
	cout<<ans<<endl;
	return 0;
}

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

//////////////////////////////   Begin Macros

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define in(x, a, b) (a <= x and x < b)
#define rep(i, N) for (int i = 0; i < (int)(N); i++)
#define reprev(i, N) for (int i = (int)(N)-1; i >= 0; i--)
#define rep1(i, N) for (int i = 1; i <= (int)(N); i++)
#define rep1rev(i, N) for (int i = (int)(N); i >= 0; i--)
#define forbe(i, b, e) for (int i = (b); i < (e); i++)
#define forberev(i, b, e) for (int i = (e)-1; i >= (b); i--)
#define forfl(i, f, l) for (int i = (f); i <= (l); i++)
#define forflrev(i, f, l) for (int i = (l); i >= (f); i--)
using ll = long long;

//////////////////////////////   End Macros

void solve()
{
  ll N;
  cin >> N;
  vector<vector<int>> s(N + 1);
  rep(i, N - 1)
  {
    int u, v;
    cin >> u >> v;
    if (u < v)
      swap(u, v);
    s[u].push_back(v);
  }

  ll ans = 0;
  ll dp = 0;
  rep1(i, N)
  {
    dp += i;
    for (auto e : s[i])
      dp -= e;
    ans += dp;
  }
  cout << ans << endl;
}

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


Measured memory_bytes: 13840
#include<bits/stdc++.h>
using namespace std;
using LL=int64_t;
const int INF=0x3f3f3f3f;
int main()
{
    string a,b;
    cin>>a>>b;
   if(a.length()>b.length()) cout<<"GREATER";
   else if(a.length()<b.length()) cout<<"LESS";
   else {
    for(int i=0;i<a.length();i++) {
        if(a[i]>b[i]) {cout<<"GREATER";break;}
        else if(a[i]<b[i]) {cout<<"LESS";break;}
        else if(i==a.length()-1) cout<<"EQUAL";
    }
   }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define pb push_back
#define fi first
#define se second

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

ull a, b, c, d;

void read() {
  cin >> a >> b >> c >> d;
  if (c == d)
    d = 2e18;
}

int euclid(int a, int b) {
  while (b) {
    int c = a % b;
    a = b;
    b = c;
  }
  return a;
}

void solve() {
  ull sol = b - a + 1;
  ull com = (c * d) / euclid(c, d);
  sol = sol - b / c - b / d + b / com + (a - 1) / c + (a - 1) / d - (a - 1) / com;
  cout << sol;
}

int main() {
  ios :: sync_with_stdio(false);
  cin.tie(nullptr);
  read();
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

#define ANS(f) if(f) cout << "YES" << endl; else cout << "NO" << endl;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
void debug(mat m){REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl; }}



signed main(){

    int N, K; cin >> N >> K;
    vec h(N); readv(h);
    vec dp(N);
    dp[0] = 0;
    FOR(i, 1, N){
        int v = INF;
        FOR(j, 1, K + 1){
            if(i - j >= 0) v = min(v, dp[i - j] + llabs(h[i] - h[i - j]));
        }
        dp[i] = v;
    }
    cout << dp[N - 1];
    
    return 0;
}

Measured memory_bytes: 1792
#include <malloc.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

//abc129B
int main(void) {
  int n, k, i, cou=100000, tmp=0,tm2=0;
  scanf("%d", &n);
  int w[n];
  for(i=0; i < n; i++){
    scanf("%d", &w[i]);
    tmp+=w[i];
  }
  for(i=0; i < n; i++){
    if(cou>abs(tmp-tm2))cou=abs(tmp-tm2);
    tmp-=w[i],tm2+=w[i];
  }
printf("%d",cou);
}


Measured memory_bytes: 128
#include <stdio.h>

int p[100000],l[100000],r[100000],d[100000],h[100000],root;

void depth(int x,int dep){
  d[x]=dep;
  if(r[x]!= -1)depth(r[x],dep+1);
  if(l[x]!= -1)depth(l[x],dep+1);
}

int height(int x){
  int h1=0,h2=0;

  if(l[x]!=-1)h1=height(l[x])+1;
  if(r[x]!=-1)h2=height(r[x])+1;

  if(h1>h2){
    h[x]=h1;
    return h1;
  }
  else{
    h[x]=h2;
    return h2;
  }
}

void pre(int x){
  if(x==-1)return;

  printf(" %d",x);
  pre(l[x]);
  pre(r[x]);
}

void in(int x){
  if(x==-1)return;

  in(l[x]);
  printf(" %d",x);
  in(r[x]);
}

void post(int x){
  if(x==-1)return;

  post(l[x]);
  post(r[x]);
  printf(" %d",x);
}

int main(){
  int i,j,n,t,t1,t2,t3;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    p[i]=-1;
    l[i]=-1;
    r[i]=-1;
  }
  for(i=0;i<n;i++){
    scanf("%d%d%d",&t1,&t2,&t3);
    l[t1]=t2;
    r[t1]=t3;
    if(t2!=-1)p[t2]=t1;
    if(t3!=-1)p[t3]=t1;
  }

  for(i=0;i<n;i++){
    if(p[i]==-1){
      root=i;
      break;
    }
  }
  depth(root,0);
  height(root);

  printf("Preorder\n");
  pre(root);
  printf("\nInorder\n");
  in(root);
  printf("\nPostorder\n");
  post(root);
  printf("\n");

  return 0;
}



Measured memory_bytes: 2112
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];puts("");}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
// #define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
// int dx[]={0,1,0,-1};
// int dy[]={1,0,-1,0};//RDLU
#define yes puts("YES")
#define no puts("NO")

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

	int n,q;
	cin>>n>>q;
	string s;
	cin>>s;
	vi d(n+1);
	rep(i,n-1)d[i+1]+=d[i]+(s[i]=='A'&&s[i+1]=='C');
	while(q--){
		int l,r;
		cin>>l>>r;
		l--;r--;
		cout<<d[r-1]-d[l]+(r&&s[r-1]=='A'&&s[r]=='C')<<endl;
	}
}


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


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)
#define w(x)  int x; cin>>x; while(x--)
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"
#define watch3(x,y,z) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<"\n"
#define watch4(x,y,z,q) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<" and "<<(#q)<<" is "<<(q)<<"\n"
#define MOD 1000000007
#define INF 1000000007;
#define F first
#define S second
#define pb(x) push_back(x);


#define ll  long long
#define all(c) (c).begin(),(c).end()
#define endl "\n"

typedef vector<int> vl;
typedef vector< vl > vvl;
typedef pair< int, int> pll;
typedef map< int, int> mll;


#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif





void c_p_c()
{
#ifndef ONLINE_JUDGE
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
void parray(int a[], int n) {
	for (int i = 0; i < n; i++) {
		cout << a[i] << " ";
	}
	cout << endl;
}



int check(int n) {

	int temp = n + 9;

	temp = temp / 10;
	return temp * 10;



}

bool comp(pair<string,pair<int,int>> a , pair<string,pair<int,int>> b) {


	// return a % 10 > b % 10;
	if(a.F!=b.F)
		return a.F<b.F;
	return a.S.F>b.S.F;

}

int main() {
	int i, n, m, k, c = 0;
	c_p_c();
	int x;
	cin>>n>>x;
	int a[n];
	fo(i,n) cin>>a[i];

	int b[n]={0};

	int d=0;
	for (int i = 0; i < n; ++i)
	{
		/* code */
		b[i]=d+a[i];
		d=b[i];
	}
	// parray(b,n);
	if(binary_search(b,b+n,x)){
	cout<<2+lower_bound(b,b+n,x)-b<<endl;
	}
	else
		cout<<1+lower_bound(b,b+n,x)-b<<endl;
	return 0;
}



Measured memory_bytes: 3536
//*************************************************************************
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#include<regex>

#include<map>
using namespace std;

int main(){
	int n,k;
	cin>>n>>k;
	int ans=0;
	float half=k/2.0;
	for (int i=0;i<n;i++){
		int p;
		cin>>p;
		if (p<=half) ans+=(2*p);
		else ans+=(2*(k-p));
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
S = input()
S = S.split("/")
y= int(S[0])
m= int(S[1])
d= int(S[2])
if y < 2019:
  print("Heisei")
elif y == 2019:
  if m <= 4:
    print("Heisei")
  else:
    print("TBD")
else:
  print("TBD")

Measured memory_bytes: 3060
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

used=0
a_read=0
for i in range(N):
    if used+A[i]>K:
        break
    else:
        used+=A[i]
        a_read+=1

b_read=0
for i in range(M):
    if used+B[i]>K:
        break
    else:
        used+=B[i]
        b_read+=1
ans=a_read+b_read
tmp=ans

for i in range(a_read):
    if b_read==M:
        break
    used-=A[a_read-1]
    a_read-=1
    tmp-=1
    while True:
        if b_read>=M:
            break
        if used+B[b_read]<=K:
            b_read+=1
            used+=B[b_read-1]
            tmp+=1
        else:
            break
    ans=max(ans,tmp)

print(ans)

Measured memory_bytes: 40604
<?php
$input_array = explode(' ', trim(fgets(STDIN)));

$amount = (int)$input_array[0];
$blue = (int)$input_array[1];
$red = (int)$input_array[2];

$cycle_count = (int)floor($amount / ($blue + $red));

$remend = $amount - ($blue + $red) * $cycle_count;

if ($blue <= $remend) {
    echo $blue * $cycle_count + $blue;
} else {
    echo $blue * $cycle_count + $remend;
}


Measured memory_bytes: 4856
#include <cstdio>
#include <cctype>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define ll long long
#define reg register
#define rep(i, a, b) for (reg int i = (a), i##end = (b); i <= i##end; ++i)
#define dep(i, a, b) for (reg int i = (a), i##end = (b); i >= i##end; --i)

template <typename _typer> inline _typer read() {
    _typer init = 0;
    char ch = getchar(), k = 0;
    for ( ; !isdigit(ch); ch = getchar()) k = (ch == '-');
    for ( ; isdigit(ch); ch = getchar())
        init = (init << 3) + (init << 1) + (ch ^ 48);
    return k ? -init : init;
}
const ll N = 0, INF = 1e9;

/*******************************************************************************
 *
 *
 *
 ******************************************************************************/

int main() {
    int a = read<int>(), b = read<int>();
    cout << (a + b - 3) / (a - 1) << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int , int> P;
typedef pair<ll, ll> PL;
const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;

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

int n, t;

int main(){
    cin >> n >> t;
    int c, tt,ans = t,ansa = 10000;
    for(int i = 0; i < n; i++){
        cin >> c >> tt;
        if(ans >= tt){
            if(ansa >= c){
                ansa = c;
            }
            
        }
    }

    if(ansa == 10000){
        cout << "TLE\n";
    }
    else{
        cout << ansa;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#define int long long
using namespace std;
int test[213456];
int ok[213456];
signed main() {
	int n, m, k, a, b, x, y, c, sum = 1000000, num = 1000000, dum = 1000000, ans = 0; 
	cin >> a >> b >> m;
	for (int h = 1; h <= a; h++) {
		cin >> n; sum = min(sum, n);
		test[h] = n;
	}
	for (int h = 1; h <= b; h++) {
		cin >> k; num = min(num, k);
		ok[h] = k;
	}
	for (int h = 0; h < m; h++) {
		cin >> x >> y >> c;
		dum = min(test[x] + ok[y] - c, dum);
	}
	cout << min(sum + num, dum) << endl;
	return 0;
}


Measured memory_bytes: 1792
//https://atcoder.jp/contests/dp/submissions/9936508
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

const int mod = 1000000000+7;

int main(){
    int n,k;    cin >> n >> k;
    vector<int>a(n);
    rep(i, n)   cin >> a[i];
    if(k == 0){
        cout << 1 << endl;
        return 0;
    }
    vector<vector<ll> >dp(n+1, vector<ll>(k+1));    //dp[i][j]:=子供iまでにj個分ける(累積和)
    rep(i, n+1){ dp[i][0] = 1; }
    rep(j, k+1) dp[0][j] = 1;
    /*
     * dpテーブル
     * dp[i][j] = dp[i][j-1] + dp[i-1][j] - dp[i-1][j-1-a[i-1]]
     */
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= k; j++){
            dp[i][j] += dp[i][j-1];
            dp[i][j] %= mod;
            dp[i][j] += dp[i-1][j];
            dp[i][j] %= mod;
            if(j-1-a[i-1] >= 0){
                dp[i][j] -= dp[i-1][j-1-a[i-1]];
                //dp[i][j] += mod;
                dp[i][j] %= mod;
            }
        }
    }
    cout << (dp[n][k] - dp[n][k-1] + mod) % mod << endl;
}


Measured memory_bytes: 80256
#include <stdio.h>
#include <string.h>
int main(){
  int a, b, c;

  scanf("%d%d%d", &a, &b, &c);

  if((b-a) == (c-b)){
    printf("YES");
  }else{
    printf("NO");
  }
  
  //  printf("\n");
  
}


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

int main() {
  int n, l;
  cin >> n >> l;
  vector<string> arr;
  rep(i, n) {
    string s;
    cin >> s;
    arr.emplace_back(s);
  }
  sort(arr.begin(), arr.end());
  string s = boost::algorithm::join(arr, "");
  cout << s << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
ll const mod=998244353;
const ll MAX=300000;

int main(){
    int n;
    cin>>n;
    map<P,int>mp;
    arep(i,1,n+1){
        P p;
        p.second=i%10;
        int tmp=i;
        while(tmp>=10)tmp/=10;
        p.first =tmp;
        mp[p]++;       
    }
    
    ll ans=0;
    for(auto x:mp){
        
        int a=x.first.first,b=x.first.second;
        P p=P(b,a);
        ans+=mp[p]*x.second;

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

Measured memory_bytes: 3644
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
  let mut s = String::new();
  std::io::stdin().read_line(&mut s).ok();
  s.trim().split_whitespace()
    .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
  let ab: Vec<f64> = read_vec();
  let average = (ab[0] + ab[1]) / 2.0;
  if average % 1.0 != 0.0 { println!("IMPOSSIBLE"); } else { println!("{}", average as i32) };
}


Measured memory_bytes: 4352
class PotUnionFind:
    def __init__(self, n):
        self.parent = list(range(n)) #親ノード
        self.size = [1]*n #グループの要素数
        self.diff_p = [0]*n #親ノードを基準としたポテンシャル
 
    def root(self, x): #root(x): xの根ノードを返す．
        while self.parent[x] != x:
            self.diff_p[x] += self.diff_p[self.parent[x]]
            self.parent[x] = self.parent[self.parent[x]]
            x = self.parent[x]
        return x 

    def weight(self, x): #root(x): xの根ノードを返す．
        c=0
        while self.parent[x] != x:
            self.diff_p[x] += self.diff_p[self.parent[x]]
            self.parent[x] = self.parent[self.parent[x]]
            c += self.diff_p[x]
            x = self.parent[x]
        return c


    def merge(self, x, y, dxy): #ポテンシャル差p(y)-p(x)=dxyでxとyの組をまとめる
        dxy += self.weight(x) - self.weight(y) #dxyをで置き換え
        x,y = self.root(x), self.root(y)
        if x == y: return False
        if self.size[x] < self.size[y]: #xの要素数が大きいように
            x,y,dxy = y,x,-dxy
        self.size[x] += self.size[y] #xの要素数を更新
        self.parent[y] = x #yをxにつなぐ
        self.diff_p[y] = dxy #yの相対ポテンシャルを更新
        return True
 
    def issame(self, x, y): #xとyが同じ組ならTrue
        return self.root(x) == self.root(y)
        
    def diff(self,x,y): #xを基準としたyのポテンシャルを返す 
        if self.root(x) == self.root(y):
            return self.weight(y) - self.weight(x)
        else:
            return None

    def getsize(self,x): #xのいるグループの要素数を返す
        return self.size[self.root(x)]


import sys
while True:
    n,Q=[int(i) for i in input().split()]
    if n==0 and Q ==0: exit()
    T=PotUnionFind(n)
    for _ in [0]*(Q):
        u = [i for i in sys.stdin.readline().split()]
        if u[0] =="!":
            u1, u2, u3 = int(u[1])-1, int(u[2])-1, int(u[3])
            T.merge(u1,u2,u3)
        else:
            u1, u2 = int(u[1])-1, int(u[2])-1
            if T.issame(u1,u2):
                print(T.diff(u1,u2))
            else:
                print("UNKNOWN")
                
                
                


Measured memory_bytes: 17468
#include <stdio.h>

int main(void)
{
     int N,n,ans=0;
     int num[10000];
     scanf("%d",&N);
     for(n=0;n<N;n++){
     	scanf("%d",&num[n]);
     }
      for(n=0;n<N;n++){
     	while(num[n]%2==0){
     		num[n]/=2;
     		ans++;
     	}
     }
     printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256