akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
#include<list>
#include<iomanip>
using namespace std;
 
typedef long long ll;




int main(){
	int n;
	cin >> n;
	vector<int> v(n);
//	vector<list<pair<int,int> > > graph(n);
	
	vector<int> vfirst;
	vector<int> vsecond;
	vector<int> res(n-1);
	map<int,vector<int>> ma;
	map<int,int> ue;
	int a,b;
	for(int i=0;i<n-1;++i){
		cin >> a >> b;
		a--;b--;
		vfirst.push_back(a);
		vsecond.push_back(b);
		ma[a].push_back(i);
		ue[b] = i; //root も初期化するあとで
	}
	int res_cnt =1;
	int root = 0;
	for(int i=0;i<n-1;++i){
		int c = 1;
		/*
		if(hen_index != root){
			res[hen_index]
		}*/
		for(auto hen_index : ma[i]){
			int fi = vfirst[hen_index];
			int se = vsecond[hen_index];
			if(fi != root && c ==res[ue[fi]]){
				c++;
			}
			res_cnt = max(res_cnt,c);
			res[hen_index] = c;
			c++;
		}
	}
	cout << res_cnt <<endl;
	//cout << res.size() <<endl;
	//cout <<endl;
	for(auto a:res){
		cout << a <<endl;
	}
	
	
	
	
	
	
	return 0;
}



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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

const int MOD = 1e9 + 7;

long long inverse(long long a) {
    long long ret = 1;
    for (int b=MOD-2; b>0; b/=2) {
        if (b % 2) ret = ret * a % MOD;
        a = a * a % MOD;
    }
    return ret;
}

long long fact[400005], inv[400005];

long long choose(int n, int k) {
    return fact[n] * inv[k] % MOD * inv[n-k] % MOD;
}

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

    int n, k;
    cin >> n >> k;

    fact[0] = inv[0] = 1;
    for (int i=1; i<=2*n; i++) {
        fact[i] = fact[i-1] * i % MOD;
        inv[i] = inverse(fact[i]);
    }

    int ret = 0;
    for (int i=0; i<=min(n-1, k); i++) {
        ret += choose(n, i) * choose(n - 1, i) % MOD;
        if (ret >= MOD)
            ret -= MOD;
    }

    cout << ret << "\n";

    return 0;
}


Measured memory_bytes: 9856
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<iomanip>
#include<string>
using namespace std;

int main() {

	long long N;
	cin >> N;

	long long ans = N * (N - 1) / 2;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
loop do
  result = [0, 0]
  num = gets.chomp!.to_i
  if num == 0
    break
  else
    num.times do
      str = gets.chomp!.split(/\s+/)
      if str[0].to_i < str[1].to_i
        result[1] = result[1] + str[0].to_i + str[1].to_i
      elsif str[0].to_i > str[1].to_i
        result[0] = result[0] + str[0].to_i + str[1].to_i
      else
        result[0] = result[0] + str[0].to_i
      result[1] = result[1] + str[1].to_i
      end
    end
    print result[0],"\s",result[1],"\n"
  end
end

Measured memory_bytes: 6136
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> p(n+1);
    for(int i = 0; i < n; ++i) {
        int x; cin >> x;
        x--;
        p[i] = x;
    }
    int swaps = 0;
    for(int i = 0; i <n; ++i) {
        if(i == p[i]) {
            if(i < n-1)
                swap(p[i], p[i+1]);
            swaps++;
        }
    }
    cout << swaps << '\n';

    return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
		int now = 9;
		int[] tmp = new int[10];
		int weight = sc.nextInt();

		int max = -1;
		for(int i = 0; i < 10; i++) tmp[i] = 0;

		while(weight > 0) 
		{
		  if(weight>=Math.pow(2, now)) 
		  {
		   if(max == -1) max = now; 
		    tmp[now] = 1;
		    weight -= Math.pow(2, now);
		  }
		  now--;
		}
		for(int i = 0; i < 10; i++)
		{
		  if(tmp[i] == 1)
		  {
		  System.out.print((int)Math.pow(2, i));
		    if(i != max)System.out.print(" ");
		  }
		}
		System.out.println("");
		}
	}
}


Measured memory_bytes: 26048
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <vector>

using namespace std;

int main()
{   
    int x, a, b;
    cin >> x >> a >> b;
    int A = abs(x - a);
    int B = abs(x - b);
    if(A < B){
        cout << "A" << endl;
    }
    else{
        cout << "B" << endl;
    }
}

Measured memory_bytes: 256
#!/usr/bin/python3
# -*- coding: utf-8 -*-

class LinkedList():
    def __init__(self, val):
        self.val = val
        self.prev = None
        self.next = None

    def insert(self, cursor):
        #print('Insert, new cursor', self.val)
        self.prev = cursor.prev
        if self.prev: self.prev.next = self
        self.next = cursor
        cursor.prev = self
        #self.print_list()
        return self

    def remove(self):
        #print('Remove', self.val, 'new cursor', self.next.val)
        if self.prev:
            self.prev.next = self.next
        self.next.prev = self.prev
        #self.print_list()
        return self.next

    def move(self, count):  # cursor is passed
        #print('Moving', count, end = ' ')
        #self.print_list()
        cursor = self
        while count > 0:
            cursor = cursor.next
            count -= 1
        while count < 0:
            cursor = cursor.prev
            count += 1
        #print('new cursor', cursor.val)
        return cursor

    def print_list(self):
        top = self
        while top.prev != None:
            top = top.prev
        while top:
            print(top.val, end = ' ')
            top = top.next
        print()


import sys
cursor = LinkedList(None) 

num_tc = int(sys.stdin.readline())
for i in range(num_tc):
    q = list(map(int, sys.stdin.readline().split()))
    if q[0] == 0:
        elem = LinkedList(q[1])
        cursor = elem.insert(cursor)
    elif q[0] == 1:
        cursor = cursor.move(q[1])
    elif q[0] == 2:
        cursor = cursor.remove()
    else:
        raise ValueError

top = cursor
while top.prev != None:
    top = top.prev

while top.val!=None:
    print(top.val)
    top = top.next



Measured memory_bytes: 89076
/// 25-01-2018
/// MD:NUR ALAM
/// Eastern University of Bangladesh

#include "bits/stdc++.h"

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = (a); i < (b); ++i)
#define fo(i, a, b) for (int i = (a); i <(b); ++i)
#define fors(i, s) for (int i = 0; s[i]; ++i)
#define rs(x) scanf("%s", (x))
#define mp make_pair
#define pb push_back
#define mso(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define len(X) strlen(x)

using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef long double lu;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpll;
typedef pair<int,int> Pll;
typedef map<string,int>msi;
typedef set<int>se;

template<class t> void _r(t &x) { cin >> x; }
void _r(int &x) { scanf("%d", &x); }
void _r(int64_t &x) { scanf("%lld", &x); }
void _r(double &x) { scanf("%lf", &x); }
void _r(char &x) { scanf(" %c", &x); }
void _r(char *x) { scanf("%s", x); }
void r() {}
template<class t, class... u> void r(t &head, u &... tail) { _r(head); r(tail...); }
template<class t> void _w(const t &x) { cout << x; }
void _w(const int &x) { printf("%d", x); }
void _w(const int64_t &x) { printf("%lld", x); }
void _w(const double &x) { printf("%.16f", x); }
void _w(const char &x) { putchar(x); }
void _w(const char *x) { printf("%s", x); }
template<class t,class u> void _w(const pair<t,u> &x) {_w(x.f); putchar(' '); _w(x.s);}
void w() {}
template<class t, class... u> void w(const t &head, const u &... tail) { _w(head); putchar(sizeof...(tail) ? ' ' : '\n'); w(tail...); }
template<class t, class... u> void debug(const t &head, const u &... tail) {
#ifdef HOME
#endif
}

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


int main()
{
   ll a,b,c,d=0;
   r(a,b,c);
   d=a*b;
   if(d<=c) w(d);
   else w(c);
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define collect(arr, size) rep(i,size) cin >> arr[i];
#define int long long

signed main(){
	string s; cin >> s;
	int diff = 0;
	rep(i,s.length()){
		diff += s[i]=='0' ? 1 : -1;
	}
	cout << s.length()-abs(diff) << endl;
	return 0;
}

Measured memory_bytes: 512
#include<cstdio>
using namespace std;
int ch[10];
int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++)
	{
		int q;
		scanf("%d", &q);
		ch[q] = 1;
	}
	while (1)
	{
		int k = n;
		int update = 0;
		while (k)
		{
			if (ch[k % 10])
				update = 1;
			k /= 10;
		}
		if (!update)break;
		n++;
	}
	printf("%d", n);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{

int a; 
cin >> a ;

int h = a / 3600;
int m = a % 3600 / 60;
int s = a % 3600 % 60 ;

cout << h << ":" << m << ":" << s << endl;

return 0;
}


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

int main(){
  int s;
  int a[1000000];
  int x=0;
  
  cin >> s;
  
  a[0]=0;
  a[1]=s;
  
  if(a[1]==4 || a[1]==2 || a[1]==1){cout << 4 << endl;}
  else{
    for(int i=2;x==0;i++){
      if(a[i-1] % 2 == 1){a[i]=3*a[i-1]+1;}
      else{a[i]=a[i-1]/2;}
      
      if(a[i]==4){x=i+3;}
    }
  cout << x << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  if((a%3==0||b%3==0)||(a+b)%3==0){
    cout<<"Possible"<<endl;
  }
  else{
    cout<<"Impossible"<<endl;
  }
  return 0;
}

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

int main() {
	int N, M, A[1000], B[1000];
	scanf("%d%d", &N, &M);
	for(int i=0; i<N; i++){
		scanf("%d", &A[i]);
	}
	for(int i=0; i<M; i++){
		scanf("%d", &B[i]);
	}
	int get[1000]={0};
	for(int j=0; j<M; j++){
		for(int i=0; i<N; i++){
			if(A[i] <= B[j]){
				get[i]++;
				i=N;
			}
		}
	}
	int max=0;
	int ans;
	for(int i=0; i<N; i++){
		if(max < get[i]){
			max = get[i];
			ans = i;
		}
	}
	
	printf("%d\n", ans+1);
	
	return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> d(N);
    for(int i = 0; i < N; i++) {
        cin >> d.at(i);
    }
    int sum = 0;
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            if(i == j) {
                continue;
            }
            else {
                sum += d.at(i) * d.at(j);
            }
        }
    }
    cout << sum/2 << endl;
}

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

int main()
{
  long long H,result=1;
  cin >> H;

  if(H%2==0){
    long long tmp = 0;
    tmp = (log10(H)/log10(2.0));
    for(long long i=0;i<tmp;i++){
      result = result * 2 + 1;
    }
  }else{
    long long tmp = 0;
    tmp = (log10(H-1)/log10(2.0));
    for(long long i=0;i<tmp;i++){
      result = result * 2 + 1;
    }
  }

  cout << result << endl;
}

Measured memory_bytes: 640
V, E = list(map(int, input().split(' ')))
A = [[float('inf') if i != j else 0 for i in range(V)] for j in range(V)]
for i in range(E):
    s, t, d = list(map(int, input().split(' ')))
    A[s][t] = d

def warchall_floyd():
    global A
    for k in range(V):
        for i in range(V):
            if A[i][k] == float('inf'): continue
            for j in range(V):
                if A[k][j] == float('inf'): continue
                A[i][j] = min(A[i][j], A[i][k] + A[k][j])
                if i == j and A[i][i] < 0: return False
    return True

if warchall_floyd():
    for i in range(V):
        print(' '.join([str(x) if x != float('inf') else 'INF' for x in A[i]]))
else:
    print('NEGATIVE CYCLE')


Measured memory_bytes: 6240
fun main(args : Array<String>) {
    val N = readLine()!!.toInt()
    val A = readLine()!!.split(" ").map { it.toInt() }

    val res = A.reduce { acc, i -> gcd(acc, i) }
    println(res)
}

fun gcd(a: Int, b: Int) : Int {
    if (b == 0) {
        return a
    }

    return gcd(b, a % b)
}



Measured memory_bytes: 51932
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long int n,i,sum=0,count,cost1=0,cost2=0;
    cin >> n;
    vector <long int> a(n);
    
    for(i=0;i<n;i++){
        cin >> a[i];
    }
    if(a[0]<=0){  ////
        cost1+= abs(a[0])+1;
        //a[0]=1;
        sum=1;
    }else{
        sum+=a[0];
    }
    for(i=1;i<n;i++){
       sum+=a[i];
       if(sum<=0&&i%2==0){
           cost1+=abs(sum)+1;
           sum=1;
       }
       if(sum>=0&&i%2==1){
           cost1+=abs(sum)+1;
           sum=-1;
       }
    } ///////
    sum=0; //cout << a[0] <<endl;
   if(a[0]>=0){
        cost2+= abs(a[0])+1;
        a[0]=-1; sum =-1;
    }else sum+=a[0];
    //cout<<sum<< " "<<cost2<<endl;
    for(i=1;i<n;i++){
        
       sum+=a[i];
       //cout<<sum<< " "<<cost2<<endl;
       if(sum>=0&&i%2==0){
           cost2+=abs(sum)+1;
           sum=-1;
       }
       if(sum<=0&&i%2==1){
           cost2+=abs(sum)+1;
           sum=1;
       }
    } 
    cout << min(cost1,cost2) <<endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string.h>	
using namespace std;

void swapEx(char *a, char *b)
{
	char temp[3];
	strcpy(temp, b);
	strcpy(b, a);
	strcpy(a, temp);
}

void BubleSort(char C[][3], int N)
{
	int flag = 1;
	for (int i = 0; i < N, flag == 1; i++) {
		flag = 0;
		for (int j = N-1; j > i; j--) {
			if (C[j - 1][1] > C[j][1]) {
				swapEx(C[j - 1], C[j]);
				flag = 1;
			}
		}
	}
	for (int i = 0; i < N-1; i++) cout << C[i] << " ";
	cout << C[N - 1] << endl;
}

void SelectionSort(char C[][3], int N)
{
	int minj;
	for (int i = 0; i < N; i++) {
		minj = i;
		for (int j = i+1; j < N; j++) {
			if (C[minj][1] > C[j][1]) {
				minj = j;
			}
		}
		swapEx(C[minj], C[i]);
	}
	for (int i = 0; i < N - 1; i++) cout << C[i] << " ";
	cout << C[N - 1] << endl;
}

int main()
{
	int N;
	char C1[36][3];
	char C2[36][3];

	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> C1[i];
		strcpy(C2[i], C1[i]);
	}

	BubleSort(C1, N);
	cout << "Stable" << endl;

	SelectionSort(C2, N);
	for (int i = 0; i < N; i++) {
		if (strcmp(C1[i],C2[i])!=0) {
			cout << "Not stable" << endl;
			return 0;
		}
	}
	cout << "Stable" << endl;
	return 0;
}

Measured memory_bytes: 3152
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <set>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> Q;
const ll mod = 1000000007;
const ll INF = 1000000000000000;

ll k, X, Y;
ll dp[100010][18], tim[20];

ll pow_mod(ll x, ll y)
{
	ll res = 1;
	while (y > 0)
	{
		if (y % 2 == 1)
		{
			(res *= x) %= mod;
		}
		(x *= x) %= mod;
		y /= 2;
	}
	return res;
}

ll div(ll x)
{
	return pow_mod(x, mod - 2);
}



int main(void)
{
	string s;

	cin >> s;

	

	if (s[0] == '?')
	{
		for (int i = 0; i < 10; i++)
		{
			dp[0][i] = 1;
		}
	}
	else
	{
		dp[0][s[0] - '0'] = 1;
	}

	for (int i = 1; i < s.length(); i++)
	{
		for (int j = 0; j < 13; j++)
		{
			tim[j * 10 % 13] = dp[i - 1][j];
			
		}
		for (int j = 0; j < 13; j++)
		{
			if (s[i] == '?')
			{
				for (int k = 0; k < 10; k++)
				{
					(dp[i][(j + k) % 13] += tim[j]) %= mod;
				}
			}
			else
			{
				(dp[i][(j + (s[i] - '0')) % 13] += tim[j]) %= mod;
			}
		}
	}

	cout << dp[s.length() - 1][5] << endl;

	int www;
	cin >> www;
}


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

bool prime[1000005];

long long gcd (long long A, long long B){
    while (A != 0){
        long long C = A;
        A = B % A;
        B = C;
    }
    return B;
}

void setup(long long N){
    fill(prime, prime+N, true);
    for (long long i=2; i<=N; i++){
        if (prime[i]){
            for (long long j=2*i; j<=N; j+=i){
                prime[j] = false;
            }
        }
    }
}

int main() {
    long long A, B;
    cin >> A >> B;
    long long c = gcd(A, B);
    setup((int) sqrt(c) + 5);
    long long tot = 0;

    long long g = (long long) sqrt(c) + 5;
    for (long long i=2; i<= g; i++){
        if (prime[i] && c % i == 0) {
            tot++;
            while (c % i  == 0){
                c /= i;
            }
        }
    }
    if (c != 1) tot++;
    tot++;
    cout << tot << endl;
    return 0;
}

Measured memory_bytes: 1280
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// 自分の得意な言語で
		// Let's チャレンジ！！

		Scanner sc = new Scanner(System.in);

		// 問題数
		int n = sc.nextInt();
		// 提出数
		int m = sc.nextInt();

		String re = "No";
		if (n == m)
			re = "Yes";

		System.out.println(re);

	}

}

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

#define int long long
const int maxn = 2010;
int B[maxn], W[maxn], p[2 * maxn], T1[maxn][2 * maxn], T2[maxn][2 * maxn], dp[maxn][maxn];
char type[2 * maxn];
bool A1[2 * maxn], A2[2 * maxn];
int C1[2 * maxn], C2[2 * maxn];

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	for (int i = 0; i < 2 * n; i++) {
		cin >> type[i] >> p[i];
		p[i]--;
		if (type[i] == 'B')
			B[p[i]] = i;
		else
			W[p[i]] = i;
	}
	for (int i = n - 1; i >= 0; i--) {
		T1[i][0] = A1[0];
		for (int j = 1; j < 2 * n; j++) {
			T1[i][j] = T1[i][j - 1] + A1[j];
		}
		A1[B[i]] = 1;
	}
	C1[0] = A1[0];
	for (int i = 1; i < 2 * n; i++)
		C1[i] = C1[i - 1] + A1[i];
	for (int i = n - 1; i >= 0; i--) {
		T2[i][0] = A2[0];
		for (int j = 1; j < 2 * n; j++) {
			T2[i][j] = T2[i][j - 1] + A2[j];
		}
		A2[W[i]] = 1;
	}
	C2[0] = A2[0];
	for (int i = 1; i < 2 * n; i++)
		C2[i] = C2[i - 1] + A2[i];
	for (int i = 1; i <= n; i++) {
		dp[i][0] = dp[i - 1][0] + T1[i - 1][B[i - 1]] + C2[B[i - 1]];
	}
	for (int j = 1; j <= n; j++) {
		dp[0][j] = dp[0][j - 1] + T2[j - 1][W[j - 1]] + C1[W[j - 1]];
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			dp[i][j] = min(dp[i - 1][j] + T1[i - 1][B[i - 1]] + T2[j - 1][B[i - 1]], dp[i][j - 1] + T2[j - 1][W[j - 1]] + T1[i - 1][W[j - 1]]);
//			cout << i << ' ' << j << ' ' << dp[i][j] << endl;
		}
	}
	cout << dp[n][n];
}


Measured memory_bytes: 158080
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.next();
		boolean c = false;
		String result = "No";
		for (int i = 0; i < str.length(); i++) {
			if (str.charAt(i) == 'C') {
				c = true;
			} else if (str.charAt(i) == 'F' && c) {
				result = "Yes";
				break;
			}
		}
		System.out.println(result);
	}
}

Measured memory_bytes: 8916
n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
count = 0
for i in a:
    if x - i < 0:
        x = 0
        break
    else:
        x -= i
        count += 1
if x != 0:
    count -= 1
print(count)


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

signed main(void)
{
	int n;
	cin >> n;
	vector<ll> sum(n);
	map<ll, ll> mp;
	ll cnt;

	rep(i, n) cin >> sum[i];
	rep(i, n - 1) sum[i + 1] += sum[i];
	rep(i, n) mp[sum[i]]++;
	cnt = 0;
	for (auto p : mp)
	{
		auto k = p.first;
		auto v = p.second;
		if (k == 0)
			cnt += v;
		if (v >= 2)
			cnt += v * (v - 1) / 2;
	}
	cout << cnt << endl;
	return 0;
}


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

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

	vector<double> x(n);
	string u[n];
	for(int i = 0; i < n; i++){
		cin >> x[i] >> u[i];

	}

	double sum = 0;
	for(int i = 0; i < n; i++){
		if(u[i] == "BTC"){
			x[i] = x[i] * 380000.0;
		}
		sum += x[i];
	}

	printf("%0.6f\n", sum);


	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 62;

int main() {
  //
  ll n;
  cin >> n;
  vl a(n), sum(n), rsum(n);
  rep(i, n) {
    cin >> a[i];
    if (i == 0) {
      sum[i] = a[i];
    } else {
      sum[i] = sum[i - 1] + a[i];
    }
  }
  rsum[0] = a[n - 1];
  for (int i = n - 2; i >= 0; i--) {
    rsum[n - 1 - i] = rsum[n - 2 - i] + a[i];
  }

  ll ans = sum[n - 1];
  for (int rstart = 2; rstart <= n - 2; rstart++) {
    ll pq = sum[rstart - 1];
    ll rs = rsum[n - 1 - rstart];
    int lb_pq = lower_bound(sum.begin(), sum.begin() + rstart - 1, pq / 2) -
                sum.begin();
    int lb_rs =
        lower_bound(rsum.begin(), rsum.begin() + n - 1 - rstart, rs / 2) -
        rsum.begin();
    // cerr << lb_pq << "," << lb_rs << endl;

    for (int i = 0; i < 2; i++) {
      for (int j = 0; j < 2; j++) {
        ll p, q, r, s, m, M;
        if (i == 1) {
          if (lb_pq == 0) continue;
        } else if (j == 1) {
          if (lb_rs == 0) continue;
        }

        p = sum[lb_pq - i];
        q = pq - p;
        r = rsum[lb_rs - j];
        s = rs - r;
        m = min(min(p, q), min(r, s));
        M = max(max(p, q), max(r, s));
        ans = min(ans, abs(M - m));
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P;



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

	int min = abs(b-a) + abs(c-a);
	if(min > abs(a-b) + abs(c-b)){
		min = abs(a-b) + abs(c-b);
	}else if(min > abs(a-c) + abs(b-c)){
		min = abs(a-c) + abs(b-c);
	}

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


Measured memory_bytes: 256
#include <stdio.h>

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

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...);
}
#ifdef LOCAL
#define debug(x...)               \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define debug(x...)
#endif

#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)

typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N;
    cin >> N;
    long double even = 0;
    long double odd = 0;
    FOR(i, 1, N + 1) {
        if (i % 2==1) {
            odd++;
        } else {
            even++;
        }
    }
    cout << setprecision(20) << odd / (even + odd) << endl;

    return 0;
}


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

const int inf = 1001001001;

int main() {
  int w, h, n;
  cin >> w >> h >> n;

  vector<int> a(h + 2, 0);

  for (int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;

    a[y] = max(a[y], x);
  }

  int ans = inf;
  for (int i = h; i >= 0; --i) {
    ans = min(ans, i + a[i + 1]);
    a[i] = max(a[i], a[i + 1]);
  }

  cout << ans << endl;
}

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

using namespace std;

const int INF = 1e9;

int n,m,i,j,dist[200005];
vector <int> edge[200005];

int main(){
	scanf("%d%d", &n, &m);
	
	for(i = 0; i < m; i++){
		int x,y;
		scanf("%d%d", &x, &y);
		edge[x].push_back(y);
		edge[y].push_back(x);
	}
	
	for(i = 1; i <= n; i++)
	dist[i] = INF;
	
	dist[1] = 0;
	queue <int> que;
	que.push(1);
	
	while(que.size()){
		int now = que.front();
		que.pop();
		
		for(int k = 0; k < edge[now].size(); k++){
			int to = edge[now][k];
			if(dist[to] == INF){
				dist[to] = dist[now] + 1;
				que.push(to);
			}
		}
	}
	
	if(dist[n] == 2)
	printf("POSSIBLE\n");
	else
	printf("IMPOSSIBLE\n");
}


Measured memory_bytes: 13168
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

signed main(){
	string s;
	while(1){
		getline(cin, s);
		if(s == ".") break;
		stack<char> st;
		bool f = true;
		rep(i, 0, s.size()){
			if(s[i]=='(' || s[i]=='['){
				st.push(s[i]);
			}
			if(s[i]==')' || s[i]==']'){
				char tmp;
				if(st.empty()){
					f=false; break;
				}
				tmp = st.top(); st.pop();
				if((s[i]==')' && tmp=='[')||(s[i]==']' && tmp=='(')){
					f=false; break;
				}
			}
		}
		if(f && st.empty()) cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}
}

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

using namespace std;

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

    int N;
    cin >> N;
    double inv_sum = 0;
    for (int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        inv_sum += 1. / a;
    }
    cout.precision(17);
    cout << fixed << 1. / inv_sum << "\n";
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int stack[10]={0}, buf, crpos=0;
	while(scanf("%d", &buf) != EOF){
		if(buf == 0){
			crpos--;
			printf("%d\n", stack[crpos]);
		}else{
			stack[crpos] = buf;
			crpos++;
		}
	}
	return 0;
}

Measured memory_bytes: 596
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc= new Scanner(System.in);
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		int c = Integer.parseInt(sc.next());
		int d = Integer.parseInt(sc.next());
		int sum =0;
		if(a>b){
			sum+=b;
		}else {
			sum+=a;
		}
		if(c>d){
			sum+=d;
		}else {
			sum+=c;
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 21204
#include<iostream>
using namespace std;
typedef long long ll;
ll g[200006]={0};
int main(){
  string s;
  cin>>s;
  if(s.length()==1){
    cout<<1<<endl;
    return 0;
  }
  else if(s.length()==2){
    if(s[0]==s[1]) cout<<1<<endl;
    else cout<<2<<endl;
    return 0;
  }
  g[0]=1;
  if(s[0]==s[1]){
    g[1]=1;
    g[2]=2;
  }
  else if(s[1]==s[2]){
    g[1]=2;
    g[2]=2;
  }
  else{
    g[1]=2;
    g[2]=3;
  }
  for(int i=3;i<s.length();i++){
    if(s[i]==s[i-1]) g[i]=g[i-3]+2;
    else g[i]=g[i-1]+1;
    //cout<<g[i]<<" ";
  }
  cout<<g[s.length()-1]<<endl;
}


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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define sz(v) (int)v.size()
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;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
const char EOL = '\n';

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> s(n + 1, 0);
    REP(i, n) {
        cin >> a[i];
        s[i + 1] = s[i] + a[i];
    }
    ll m = s[n] / 2;
    int idx = -1;
    REP1(i, n) {
        if (s[i] >= m) {
            idx = i;
            break;
        }
    }
    ll ans = LINF;
    chmin(ans, abs(s[idx] - (s[n] - s[idx])));
    chmin(ans, abs(s[idx - 1] - (s[n] - s[idx - 1])));
    cout << ans << EOL;
}


Measured memory_bytes: 3328
import math
from collections import deque
def main():
    n = int(input())
    p = [int(t)for t in input().split()]
    q = [int(t)for t in input().split()]

    p_num = 0
    q_num = 0

    fact = [1]*n

    for i in range(n):
        fact[i] = fact[i-1]*(i+1)

    fact = fact[::-1]
    fact.append(1)

    temp = set([])
    for i, p_ in enumerate(p):
        t = p_-len([x for x in temp if x<p_])-1
        p_num += fact[i+1]*t
        temp.add(p_)

    temp = set([])
    for i, q_ in enumerate(q):
        t = q_-len([x for x in temp if x<q_])-1
        q_num += fact[i+1]*t
        temp.add(q_)

    print(abs(p_num-q_num))

if __name__ == "__main__":
    main()

Measured memory_bytes: 3316
//https://beta.atcoder.jp/contests/abc088/tasks/abc088_a
#include<iostream>

using namespace std;

int main(){
    int a,b;
    bool flag = false;
    cin >> a >> b;
    for(int i = 0;i <= a/500;i++){
        for(int j = 0;j <= b;j++)
        if(500*i + 1*j == a) flag = true;
    }
    if(flag == true) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
while True:
  m,f,r = map(int, input().split())
  if m == -1 & f == -1 & r == -1: break

  if m == -1 or f == -1:
    print("F")
  elif m + f >= 80:
    print("A")
  elif m + f >= 65:
    print("B")
  elif m + f >= 50:
    print("C")
  elif m + f >= 30:
    if r >= 50:
      print("C")
    else:
      print("D")
  else:
    print("F")


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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<string> vst;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;


const ll mod=(1e+9)+7;
const ll inf=1e+16; 

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)

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

 ll n;
  cin >> n;
 vpll a(n);
  rep(i,0,n) {
    cin >> a[i].first;
   a[i].second=i;
  }
  
  sort(a.begin(),a.end());
  
  ll res=0;
  rep(i,0,n) if(a[i].second%2!=i%2) res++;
  
  cout << res/2 << endl;
  
}


Measured memory_bytes: 1792
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Data.List
import Data.Char

main = do
    [a,b,c] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    putStrLn $ (show c) ++ [' '] ++ (show a) ++ [' '] ++ (show b)

Measured memory_bytes: 380
#include<stdio.h>
 int main(){
 	int x,y=0,z=0;
 	char a[99];
 	scanf("%d",&x);
 	scanf("%s", a);
 	for(int i=0;i<x;i++){
 		if(a[i]=='I'){
 			y=y+1;
		 }else {
		 	y=y-1;
		 }
		if(y>z){
			z=y;
		}	 
	 }
	 printf("%d",z);
	return 0;
 }

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

#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<int>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>

using namespace std;


//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


int power(int a,int n)
{
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return a*power(a*a,n/2);
    return power(a*a,n/2);
}
//const int md = 998244353;
//const int inf = (int) 1e18;

/*int inverse(int x){

    return power(x,mod-2)%mod;//little fermat....
}*/

int dp[20000];

signed main()
{
    showoff;
    int n,ans = 0,v[maxn],c[maxn];
    cin >> n;
    FOR(i,1,n+1){
        cin >> v[i];
    }
    FOR(i,1,n+1){
        cin >> c[i];
    }
    FOR(i,1,n+1){
        if(v[i]-c[i] > 0)ans += v[i]-c[i];
    }
    cout << ans;
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...    

Measured memory_bytes: 2304
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <functional>
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
int main(){
    int a[3][3];
    for(int i = 0;i < 3;i++){
        for(int j = 0;j < 3;j++){
            cin >> a[i][j];
        }
    }

    int n;
    cin >> n;

    map<int,bool> mp;
    for(int i = 0;i < n;i++){
        int b;
        cin >> b;
        mp[b] = true;
    }

    bool flag = false;
    for(int i = 0;i < 3;i++){
        if(mp[a[0][i]] && mp[a[1][i]] && mp[a[2][i]])flag = true;
    }

    for(int i = 0;i < 3;i++){
        if(mp[a[i][0]] && mp[a[i][1]] && mp[a[i][2]])flag = true;
    }

    if(mp[a[0][0]] && mp[a[1][1]] && mp[a[2][2]])flag = true;
    if(mp[a[0][2]] && mp[a[1][1]] && mp[a[2][0]])flag = true;

    if(flag)cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
a = input()
b = input()
c = input()
i = 'a'
while True:
    if i == 'a':
        if len(a)==0:
            print('A')
            exit()
        i = a[0]
        a = a[1:]
    elif i == 'b':
        if len(b)==0:
            print('B')
            exit()
        i = b[0]
        b = b[1:]
    else:
        if len(c)==0:
            print('C')
            exit()
        i = c[0]
        c = c[1:] 

Measured memory_bytes: 3064
#include<iostream>

using namespace std;

int main(){
  string s;
  cin >> s;
	bool found_a=false;
  int inic = 0;
  int fin = 0;
  for(int i = 0;i<s.length();++i){
  	if(s[i]=='A' && !found_a){
      found_a=true;
      inic = i;
    }
    else if(s[i]=='Z'){
    fin = i;
    }
  }
  cout << fin-inic+1 << endl;
  
return 0;
}

Measured memory_bytes: 640
def digitSum(n):
    s = str(n)
    array = list(map(int, s))
    return sum(array)

l = list(map(int, input().split()))

total = 0
for i in range(l[0]+1):
    
    digit = digitSum(i)
    if l[1] <= digit and digit <= l[2]:
        total += i

print(total)

Measured memory_bytes: 3060
def main():
    a = [int(input()) for _ in range(6)]
    k = a[5]

    for i in range(5):
        for j in range(i+1,5):
            if (a[j] - a[i]) <= k:
                continue
            else:
                return ':('

    return 'Yay!'

print(main())


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

int main()
{
	int a[3][3], n, b[10], c[3][3] = { 0 };
	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			cin >> a[i][j];
		}
	}cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> b[i];
		for (int k = 0; k < 3; k++)
		{
			for (int j = 0; j < 3; j++)
			{
				if (b[i] == a[k][j])
					c[k][j] = 1;
			}
		}
	}n = 0;
	if (c[0][0] == 1)//第一行
	{
		if (c[0][1] == 1)
		{
			if (c[0][2] == 1)
			{
				n = 1;
			}
		}
	}if (c[0][0] == 1)//第一列
	{
		if (c[1][0] == 1)
		{
			if (c[2][0] == 1)
			{
				n = 1;
			}
		}
	}
	if (c[0][0] == 1)//对角线1
	{
		if (c[1][1] == 1)
		{
			if (c[2][2] == 1)
			{
				n = 1;
			}
		}
	}
	if (c[0][1] == 1)//第二列
	{
		if (c[1][1] == 1)
		{
			if (c[2][1] == 1)
			{
				n = 1;
			}
		}
	}
	if (c[0][2] == 1)//第三列
	{
		if (c[1][2] == 1)
		{
			if (c[2][2] == 1)
			{
				n = 1;
			}
		}
	}
	if (c[1][0] == 1)//第二行
	{
		if (c[1][1] == 1)
		{
			if (c[1][2] == 1)
			{
				n = 1;
			}
		}
	}
	if (c[2][0] == 1)//第三行
	{
		if (c[2][1] == 1)
		{
			if (c[2][2] == 1)
			{
				n = 1;
			}
		}
	}
	if (c[2][0] == 1)//对角线2
	{
		if (c[1][1] == 1)
		{
			if (c[0][2] == 1)
			{
				n = 1;
			}
		}
	}
	if (n == 1)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
const int N = 1e5+5;
int n, m, v, p, a[N], ans; i64 s[N];
int main()
{
    scanf("%d%d%d%d", &n, &m, &v, &p), ans = p;
    for(int i = 1; i <= n; ++i) scanf("%d", a+i);
    sort(a+1, a+1+n, greater<int>());
    for(int i = 1; i <= n; ++i) s[i] = s[i-1]+a[i];
    for(int i = p+1; i <= n&&a[i]+m >= a[p]; ++i)
        if((i64)m*v <= (p-1ll)*m+(n-i+1ll)*m+i64(i-p)*(a[i]+m)-(s[i-1]-s[p-1])) ++ans; else break;
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 4968
#!/usr/bin/env python
"""AtCoder Beginner Contest 170: A - Five Variables
https://atcoder.jp/contests/abc170/tasks/abc170_a
"""


def main():
    Xs = list(map(int, input().split()))
    print(Xs.index(0) + 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9164
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		FastScanner sc=new FastScanner();
		int t=sc.nextInt();
	long ans=t+ t*t + t*t*t;
	System.out.println(ans);
		
		
	}
		static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
}
}


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

using namespace std;

#define max(a,b) (a>b? a:b)
#define min(a,b) (a<b? a:b)
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}

#pragma GCC Optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment (linker,"/stack:200000000")

typedef long long ll;

bool Finish_read;

template<class T>inline void read(T &x){Finish_read=0;x=0;T f=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')f=-1;if(ch==EOF)return;ch=getchar();}while(isdigit(ch))x=x*10+ch-'0',ch=getchar();x*=f;Finish_read=1;}
template<class T>inline void print(T x){if(x/10!=0)print(x/10);putchar(x%10+'0');}
template<class T>inline void writeln(T x){if(x<0)putchar('-');x=abs(x);print(x);putchar('\n');}
template<class T>inline void write(T x){if(x<0)putchar('-');x=abs(x);print(x);}

const unsigned Maxn=101;
unsigned n,a[Maxn],m,cnt=0,sum=0;
unsigned minx=1<<30;

int main() {
    read(n),read(m);
    for(unsigned i=1;i<=n;++i)
        read(a[i]),sum+=a[i];
    if(sum>m) {
        stable_sort(a+1,a+1+n);
        unsigned i=1;
        while(m>0) {
            m-=a[i];
            ++i;
            ++cnt;
        }
        --cnt;
    }
    else {
        m-=sum,cnt=n;
        for(unsigned i=1;i<=n;++i)
            minx=min(minx,a[i]);
        cnt+=(m/minx);
    }
    writeln(cnt);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.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 INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    cin >> s;
    int K;
    cin >> K;

    set<string> st;
    rep (i, s.size()) {
        rep (j, K+1) {
            st.insert(s.substr(i, j));
        }
    }

    int cnt = 0;
    for (auto it = st.begin(); it != st.end(); it++) {
        if (cnt == K) {
            cout << *it << endl;
        }
        cnt++;
    }
    
    return 0;
}

Measured memory_bytes: 1664
#include <stdio.h>

int main(void)
{
    int i, j;
    for (i = 1; i <= 9; ++i) {
        for (j = 1; j <= 9; ++j) {
            printf("%dx%d=%d\n", i, j, i * j);
        }
    }
    return 0;
}

Measured memory_bytes: 924
// Created by ...
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'

#define vll vector< ll >
#define M 100000
#define MD 1000000007
#define pb push_back
#define rep(i,a,b) for(ll i = a; i <= b; ++i)
#define fo(i,a,b) for(int i = a; i<= b; ++i)
#define pii pair<ll,ll> 
#define vec(a) vector<a >
#define all(a) a.begin(),a.end()
#define se second
#define fi first
#define inf 0xffffffff
#define inchar getchar_unlocked
#define outchar(x) putchar_unlocked(x)
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

using namespace std;
using ll = long long;
ll md=MD;

ll exp(ll a,ll b){ll r=1ll;while(b>0){if(b&1){r=r*(a%md);r=(r+md)%md;}b>>=1;a=(a%md)*(a%md);a=(a+md)%md;}return (r+md)%md;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll Min(ll a,ll b){if(a<b)return a; return b;}
ll Max(ll a,ll b){if(a>b)return a; return b;}
int32_t main() {
    IOS;

        int a,b,c,k;
        cin>>a>>b>>c>>k;
        if(k<=a+b)
        {
        	cout<<Min(a,k);
        }
        else
        {
        	cout<<a-(k-a-b);
        }
        



        cout<<'\n';
    return 0;
}

Measured memory_bytes: 3652
N = gets.chomp.to_i
s = gets.chomp
t = gets.chomp
str = Array.new(N + 1)
for i in 0..N do
  str[i] = s + t.slice(-i, i)
  if str[i].slice(-N, N) == t
    puts str[i].size
    exit
  end
end


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

using namespace std;
#define ll long long
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
const ll mod = 1e9 + 7;

int main (){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int ans = 0;
    ans = min(b,d) - max(a,c);
    if(ans < 0){
        ans = 0;
    }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int t[100];
	for(int i=0;i<n;i++){
		cin>>t[i];
	}
	int m;
	cin>>m;
	int p[100],x[100];
	for(int i=0;i<m;i++){
		cin>>p[i]>>x[i];
	}
	int sum=0;
	for(int i=0;i<m;i++){
		int f=t[p[i]-1];
		t[p[i]-1]=x[i];
		for(int j=0;j<n;j++){
			sum+=t[j];
		}
		cout<<sum<<endl;
		sum=0;
		t[p[i]-1]=f;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e9
#define INFLL 1ull<<60u
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

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

void solve() {
    int N,K; cin >> N >> K;
    vector<int> v(N);
    REP(i,N) cin >> v[i];
    // find min
    int mini = INF;
    REP(i,N) chmin(mini,v[i]);
    int cnt = 0;
    int ans = 0;
    int buf = 0;
    REP(i,N) {
        if (mini == v[i]) {
            auto right = N - i - 1;
            auto left_cost = (i+K-2)/(K-1);
            if (left_cost) right -= (i > K-1) ? (i%(K-1)) : (K-1) - i;
            chmax(right,0);
            auto right_cost = (right+K-2)/(K-1);
            cout << left_cost+right_cost << endl;
        }
    }
    assert("bugged");
}

void solve2() {
    int N,K; cin >> N >> K;
    vector<int> v(N);
    REP(i,N) cin >> v[i];
    // find min
    int mini = INF;
    REP(i,N) chmin(mini,v[i]);
    int cnt = 0;
    int ans = 0;
    int buf = 0;
    REP(i,N) {
        if (mini == v[i]) {
            if (cnt < (K-1)) {
                buf = K-1-cnt;
                ans++;
            } else {
                // 削除動作回数
                auto del = (cnt+K-2)/(K-1);
                ans += del;
            }
            cnt = 0;
        }
        else {
            if (buf) {
                buf--;
                continue;
            }
            cnt++;
        }
    }
    ans += (cnt+K-2)/(K-1);
    cout << ans << endl;
}

int main() {
    random_device rnd;
    mt19937 mt(rnd());
    auto H = mt()%2;
    if(H) solve();
    else solve2();
    return 0;
}

Measured memory_bytes: 3736
#include <iostream>
#include <algorithm>

using namespace std;

int N, K;
int candles[100005];

int main()
{
    cin >> N >> K;
    for (int i=0; i<N; i++)
    {
        cin >> candles[i];
    }
    int minval = abs(candles[0])+abs(candles[0]-candles[K-1]);
    for (int i=0; i+K-1<N; i++)
    {
        minval = min(minval, abs(candles[i])+abs(candles[i]-candles[i+K-1]));
        minval = min(minval, abs(candles[i+K-1])+abs(candles[i]-candles[i+K-1]));
    }
    cout << minval << "\n";
}

Measured memory_bytes: 640