akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

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

        int N = sc.nextInt();
        String[] W = new String[N];
        W[0] = sc.next();

        loop:for(int i=1; i<N; i++){
            W[i] = sc.next();
            for(int j=0; j<i; j++){
                if(W[i].equals(W[j])){
                    System.out.println("No");
                    break loop;
                }
            }
            if(W[i].charAt(0)!=W[i-1].charAt(W[i-1].length()-1)){
                System.out.println("No");
                break;
            }
            if(i==N-1){
                System.out.println("Yes");
            }
        }
    }
}

Measured memory_bytes: 21716
#include<cstdio>
using namespace std;
#define N 15005
int a[N],b[N],n,s1,s2;
char s[N],t[N];
long long solve(int t)
{
	long long as=0;
	int fg=0;
	if(t<0){t=-t;fg=1;for(int i=1;i<=n;i++)a[i]^=b[i]^=a[i]^=b[i];s1^=s2^=s1^=s2;}
	int l1=1,r1=1-t;
	while(1)
	{
		int tp1=a[l1],tp2=r1<0?0:b[r1];
		if(l1>s1)tp1=n;if(r1>s2)tp2=n;
		as+=tp1<tp2?tp2-tp1:tp1-tp2;
		if(tp1==tp2&&tp1==n)break;
		l1++,r1++;
	}
	if(fg){for(int i=1;i<=n;i++)a[i]^=b[i]^=a[i]^=b[i];s1^=s2^=s1^=s2;}
	return as;
}
int main()
{
	scanf("%d%s%s",&n,s+1,t+1);
	for(int i=1;i<=n;i++)if(s[i]!=s[i+1])a[++s1]=i;
	for(int i=1;i<=n;i++)if(t[i]!=t[i+1])b[++s2]=i;
	solve(-1);
	long long mn=1e18;for(int i=s[1]==t[1]?-5000:-5001;i<=5000;i+=2){long long tp=solve(i);if(tp<mn)mn=tp;}
	printf("%lld\n",mn);
}//

Measured memory_bytes: 384
import numpy as np
n,m,x = map(int, input().split())

acq2 = 0
cost = []
skill = []
for i in range(n):
    ca = list(map(int, input().split()))
    cost.append(ca[0])
    skill.append(np.array(ca[1:]))

costmin = 0
for a in range(n):
    costmin += cost[a]

def tworaw(num):
    if (num % 2 == 0):
        return 0
    else:
        return 1

for j in range(2**n):
    buy = []
    cost_temp = 0
    skill_temp = np.zeros(m)
    acq = 1
    nn = j
    for k in range(n):
        buy.append(tworaw(nn))
        nn = nn // 2

    for l in range(n):
        if (buy[l] == 1):
            cost_temp += cost[l]
            skill_temp += skill[l]
    
    for b in range(m):
        if (skill_temp[b] < x):
            acq = 0
            break
    

    if (acq == 1):
        acq2 = 1
        if (cost_temp < costmin):
            costmin = cost_temp


if (acq2 == 1):
    print(int(costmin))
else:
    print('-1')

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

ba = a
bb = b
bc = c
ans = 0
while True:
    if a % 2 != 0 or b % 2 != 0 or c % 2 != 0:
        break

    ta = a//2
    tb = b//2
    tc = c//2
    a = tb+tc
    b = ta+tc
    c = ta+tb
    ans += 1

    if a == ba and b == bb and c == bc:
        ans = -1
        break

print(ans)


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

void input(vector<int>& rvnNum)
{
  for (int& rnElm : rvnNum)
    cin >> rnElm;
}

int calcSameNumOpe(const vector<int>& cnrvnNum)
{
  auto itMaxNum = max_element(begin(cnrvnNum), end(cnrvnNum));

  int  nSum = 0;
  for (int nElm : cnrvnNum)
    nSum += nElm;

  int nSameIntTimes;
  if (*itMaxNum * 3 % 2 == nSum % 2)               // ３数の最大値×３と３数の和のパリティが等しい
    nSameIntTimes = (*itMaxNum * 3 - nSum) / 2;      // ３数の最大値 ← ３数が等しくなる数
  else                                             //  上記以外
    nSameIntTimes = ((*itMaxNum + 1) * 3 - nSum) / 2;// ３数の最大値＋１ ← ３数の等しくなる数

  return nSameIntTimes;
}

int main()
{
  vector<int> vnNum(3);

  input(vnNum);
  cout << calcSameNumOpe(vnNum) << endl;

  return 0;
}

Measured memory_bytes: 3584
#include <string>
#include <sstream>
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <queue>
#include <list>
#include <vector>
#include <array>
#include <algorithm>
#include <iterator>


bool compare(const std::string& _lhs, const std::string& _rhs)
{
	for (int i = 0; i < _lhs.size(); i++)
	{
		if (i >= _rhs.size() ) return false;

		if (_lhs[i] < _rhs[i]) return true;
		else if (_lhs[i] > _rhs[i]) return false;
	}

	return _lhs.size() <= _rhs.size();
}

bool compare2(const std::string& _lhs, const std::string& _rhs)
{
	for (size_t i = 0; i < _lhs.size(); i++)
	{
		if (i >= _rhs.size()) return false;

		if (_lhs[i] != _rhs[i]) return (_lhs[i] < _rhs[i]);
	}

	return _lhs.size() <= _rhs.size();
}

bool compare3(const std::string& _lhs, const std::string& _rhs)
{
	
	for (size_t i = 0; i < _lhs.size(); i++)
	{
		if (_lhs[i] != _rhs[i]) return (_lhs[i] < _rhs[i]);
	}
}

bool compare4(std::string& _lhs, std::string& _rhs)
{
	std::string::const_iterator it_lhs = _lhs.cbegin();
	std::string::const_iterator it_rhs = _rhs.cbegin();


	for (;it_lhs != _lhs.end(); it_lhs++, it_rhs++)
	{
		if (*it_lhs != *it_rhs)  return (*it_lhs < *it_rhs);
	}
}





int main()
{
	int N, L = -1;

	
	std::string first;
	std::getline(std::cin, first);
	std::istringstream ifst(first);

	ifst >> N >> L;
	{
		std::vector<std::string> inputVector(N);
		std::ostringstream os;

		for (int i = 0; i < N; i++)
		{
			std::string s;
			std::getline(std::cin, s);
			std::istringstream iss(s);
			inputVector.push_back(iss.str());
		}



		//std::sort(inputVector.begin(), inputVector.end(), compare);
		std::sort(inputVector.begin(), inputVector.end());

		//std::copy(inputVector.begin(), inputVector.end(), std::ostream_iterator<std::string>(os));
		//std::cout << os.str() << std::endl;

		for (const auto& e : inputVector)
		{
			std::cout << e;
		}

		std::cout << std::endl;
	}

	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    abc143d()
}

fun abc143d() {
    val n = readLine()!!.toInt()
    val lines = readLine()!!.split(" ").map { it.toInt() }
        .sorted().toIntArray()

    var answer = 0
    for (ai in 0 until n) {
        var right = 0
        for (bi in ai + 1 until n) {
            while (right < n && lines[right] < lines[ai] + lines[bi]) right++
            val left = bi + 1
            answer += right - left
        }
    }

    println(answer)
}


Measured memory_bytes: 37460
def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]


N, M = map(int, input().split())
A = [0] + list(map(int, input().split()))

imos = [0]*(N+1)
for i in range(1, N+1):
    imos[i] = (A[i] + imos[i-1]) % M

d = {}
for i in range(N+1):
    if imos[i] not in d:
        d[imos[i]] = 1
    else:
        d[imos[i]] += 1

ans = 0
for v in d.values():
    ans += (v * (v-1)) // 2

print(ans)


Measured memory_bytes: 17056
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <math.h>
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>

using namespace std;

#define REP(i,n) for (int i = 0; i < n; i++)

int main() {

	for (;;) {
		int N, M;
		int X[1234];
		int D[1234];

		scanf("%d %d", &N, &M);
		if (!N && !M) break;
		REP(i, N) scanf("%d", &X[i]);
		REP(j, M) scanf("%d", &D[j]);

		int p = 0;
		int c = 0;

		while (p < N - 1) {
			p += D[c];
			if(p < N - 1) p += X[p];
			c++;
		}

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

	return 0;
}

Measured memory_bytes: 2696
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Solver {
    Scanner sc = new Scanner();

    public void Solve() {
        int N = sc.nextInt();
        int M = sc.nextInt();

        long ans = 1;
        var prime = PrimeFactors(M).GroupBy(i => i);
        foreach (var g in prime) {
            var cnt = g.Count();
            ans *= Combination.Calc(N + cnt - 1, cnt);
            ans %= 1000000007;
        }

        WriteLine(ans);
    }

    class Combination {
        static int mod = 1000000007;

        public static long Calc(int a, int b) {
            if (b > a - b) return Calc(a, a - b);

            long ansMul = 1;
            long ansDiv = 1;
            for (int i = 0; i < b; i++) {
                ansMul *= (a - i);
                ansDiv *= (i + 1);
                ansMul %= mod;
                ansDiv %= mod;
            }
            return ansMul * ModPow(ansDiv, mod - 2) % mod;
        }

        private static long ModPow(long a, int p) {
            if (p == 0) return 1;
            if (p % 2 == 0) {
                long half = ModPow(a, p / 2);
                return half * half % mod;
            } else {
                return a * ModPow(a, p - 1) % mod;
            }
        }
    }


    IEnumerable<int> PrimeFactors(int n) {
        int i = 2;
        int tmp = n;
        while (i * i <= n) {
            if (tmp % i == 0) {
                tmp /= i;
                yield return i;
            } else {
                i++;
            }
        }
        if (tmp != 1) yield return tmp;
    }
}



class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Program {
    static void Main(string[] args) {
        Solver s = new Solver();
        s.Solve();
    }
}

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

int main() {
	int N;
	cin >> N;
	
	vector<int> A(N + 1);
	vector<int> B(N);
	
	rep(i, N + 1) {
		cin >> A[i];
	}
	
	rep(i, N) {
		cin >> B[i];
	}
	
	ll ans = 0;
	ll temp = 0;
	
	rep(i,N){
		ans += min(A[i],B[i]);
		
		B[i] -= min(A[i],B[i]);
		ans += min(A[i+1],B[i]);
		A[i+1] -= min(A[i+1],B[i]);
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define all(a)                      a.begin(), a.end()
#define pb                          push_back
#define ll							long long
#define index(a)            		order_of_key(a)
#define value(a)					find_by_order(a)
#define count_1 					__builtin_popcount
#define mod(x, m)					((((x) % (m)) + (m)) % (m))
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
int a[1000000];
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,A,B;
	cin>>n>>A>>B;
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	
	int l= upper_bound(a,a+n,A)-a;
	int r= upper_bound(a,a+n,B)-a;
	
	cout<<min({l,r-l,n-r});
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main () {
  ll X, K, D;
  cin >> X >> K >> D;
  X = max(X, -X);
  ll fl = K % 2;
  ll wan = X / D;
  wan = min(K - 1, wan);
  ll a, b;
  if (wan % 2 == fl) {
    a = wan;
    b = wan + 2;
  }
  else {
    a = wan - 1;
    b = wan + 1;
  }
  ll a_ = X - (a * D);
  a_ = max(a_, -a_);
  ll b_ = X - (b * D);
  b_ = max(b_, -b_);
  cout << min(a_, b_) << endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(a,b) for(ll i=a;i<b;i++)

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s; cin >> s;
	ll sum = 0;
	f(0,s.length()){
		sum += (s[i]-'0');
	}
	if(sum%9==0)
		printf("Yes");
	else
		printf("No");
	return 0;
}

Measured memory_bytes: 3832
#include<bits/stdc++.h>
#define lg long long int
#define loop(i,s,e) for(lg i=s;i<=e;i++)
#define iloop(i,s,e) for(lg i=e;i>=s;i--)
#define pb push_back
#define mp make_pair
#define mod 1000000007


using namespace std;

lg min(lg a,lg b)
{return a<b?a:b;}
lg max(lg a,lg b)
{return a>b?a:b;}
lg lcm(lg a ,lg b)
{
    return (a*b)/__gcd(a,b);
}
lg n,m,k,ans;
int main()
{
    cin>>n;
    vector<lg>nums(100001,0);
    ans = 0;
    for(lg i=0;i<n;i++)
    {
        lg in;
        cin>>in;
        ans+=in;
        nums[in]++;
    }
    cin>>k;
    for(lg i = 0;i<k;i++)
    {
        lg b,c;
        cin>>b>>c;
        if(nums[b]>0)
        {
            lg co=nums[b];
            nums[b]=0;
            nums[c]+=co;
            ans+=(c-b)*co;
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 3984
N = int(input())
A = list(map(int,input().strip().split()))
A = sorted(A)[::-1]

if N == 1:
    print(0)
else:
    cur = N-2
    temp = max(A)
    for i in range(1,len(A)):
        if cur == 0:
            break
        temp += A[i]
        cur -= 1
        if cur == 0:
            break  
        temp += A[i]
        cur -= 1
    print(temp)
        
        

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

ll n,m;
vector<vector<ll>> v(100100);
bool used[100100];
ll c[100100];

bool dfs(ll p,ll black){
    used[p]=true;
    bool ret=true;
    if(black){
        if(c[p]==0) c[p]=1;
        else if(c[p]!=1) ret=false;
    }
    else {
        if(c[p]==0) c[p]=2;
        else if(c[p]!=2) ret=false;
    }
    for(auto i:v[p]){
        if(c[i] && c[i]==c[p]) ret=false;
        if(c[i]==0){
            bool res=dfs(i,black^1);
            if(!res) ret=false;
        }
    }
    return ret;
}

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

    
    cin>>n>>m;
    for(ll i=0;i<m;i++){
        ll a,b;
        cin>>a>>b;
        a--,b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }

    ll ans = n*(n-1)/2 - m;
    bool pos=dfs(0,1);
    if(!pos){
        cout<<ans<<endl;
    }
    else{
        ans=0;
        ll b=0,w=0;
        for(ll i=0;i<n;i++){
            if(c[i]==1) b++;
            else w++;
        }
        ans = b*w-m;
        cout<<ans<<endl;
    }


 
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

ll dp[200010][2][3] = {};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vec<ll> A(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    ll inf = 1e18;
    for(int i=0;i<=N;i++) for(int j=0;j<2;j++) for(int k=0;k<3;k++) dp[i][j][k] = -inf;
    dp[0][0][0] = 0;
    for(int i=0;i<N;i++){
        //選ぶ
        for(int k=0;k<3;k++){
            dp[i+1][1][k] = max(dp[i+1][1][k],dp[i][0][k]+A[i]);
        }
        //選ばない
        if(i!=0){
            for(int k=0;k<3;k++){
                dp[i+1][0][k] = max(dp[i+1][0][k],dp[i][1][k]);
            }
            for(int k=0;k<2;k++) dp[i+1][0][k+1] = max(dp[i+1][0][k+1],dp[i][0][k]);
        }else {
            dp[i+1][0][1] = 0;
        }
    }
    ll ans = -inf;
    if(N%2==1) ans = max(dp[N][1][2],dp[N][0][1]);
    else ans = max(dp[N][1][1],dp[N][0][0]);
    cout << ans << "\n";
}

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

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

  int ans = 0;
  for(int i = 0; i < N; i++){
    int l,r;
    cin >> l >> r;
    ans += r - l + 1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N, M = map(int, input().split())

uf = UnionFind(N)
# check = set()

for i in range(M):
    a, b = map(int, input().split())
    uf.union(a-1, b-1)
    # check.add(a-1)

# ans = 0
# for i in check:
#     ans = max(ans, uf.size(i))

print(min(uf.parents)*(-1))

# print(ans)




Measured memory_bytes: 75120
/****************************************************
*   Template for coding contests                    *
*   Author    :    Sanjeev Sharma                   *
*   Email     :    thedevelopersanjeev@gmail.com    *
*****************************************************/
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")
#pragma GCC target ("sse4")
#pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

#define deb(x) cout << #x << " is " << x << "\n";
#define int long long
#define mod 1000000007

const double PI = 2 * acos(0.0);
const long long INF = 1e18L + 5;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void solve() {
	int n;
	cin >> n;
	vector<int> arr(n);
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	for (int i = 0; i < n; i++) {
		if (arr[i] == 0) {
			cout << 0;
			return;
		}
	}
	long double ans = 1.0;
	for (int i = 0; i < n; i++) {
		ans *= arr[i];
		if (ans > 1e18) {
			cout << -1;
			return;
		}
	}
	cout << (int) ans;
}

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
	return 0;
}


Measured memory_bytes: 3996
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define ll long long
using namespace std;
const int INF=0x3f3f3f3f;
const double pi=acos(-1),eps=1e-8;

int main()
{
//	ios::sync_with_stdio(false);
//	cin.tie(0);cout.tie(0);
	int n;
	cin>>n;
	int tmp,cnt=0;
	for(int i=0;i<n;i++){
		cin>>tmp;
		if(i%2==0&&tmp&1){
			cnt++;
		}
	}
	cout<<cnt<<endl;
 	return 0;
}










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

int main(){
    int n, m; //nは学生の数、mはチェックポイントの数
    cin >> n >> m;
    //学生の位置
    vector<int64_t> a(n);
    vector<int64_t> b(n);
    rep(i,n){
        cin >> a.at(i);
        cin >> b.at(i);
    }
    //チェックポイントの位置
    vector<int64_t> c(m);
    vector<int64_t> d(m);
    rep(i,m){
        cin >> c.at(i);
        cin >> d.at(i);
    }

    vector<int> ans(n);
    rep(i,n){
        int64_t dis;
        int64_t ansdis = 10000000000;
        rep(j,m){
            dis = abs(a.at(i) - c.at(j)) + abs(b.at(i)-d.at(j));
            if(dis < ansdis){
                ansdis = dis;
                ans.at(i) = j + 1;
            }
        }
    }
    rep(i,n){
        cout << ans.at(i) << endl;
    }
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
#define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<ii> vii;

#define deb(x) cout << #x": " << (x) << endl;


// ---- コーディングはここから！ ('-')7

void solve(){
	lli x; cin>>x;
	vi d(x,0);
	lli sum = 0;
	for(int i = 1; i<x; i++)for(int j = i; j<x; j+=i)d[j]++;
	fore(j,1,x)sum+=d[j];
	cout<<sum<<ENDL;

}
int main(){_
	//int t; cin>>t; while(t--)
	solve();
}


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

int main()
{
    int rates[9] = {0}, N, a, ans;
    cin >> N;
    REP(i, N) cin >> a, a < 3200 ? rates[a / 400]++ : rates[8] ++;
    ans = count_if(&rates[0], &rates[8], [](int x) { return 0 < x; });
    cout << ans + bool(rates[8]) * !bool(ans) << " " << ans + rates[8] << endl;

    return 0;
}


Measured memory_bytes: 256
N = int(input())
a = [0] * N
b = [0] * N
c = [0] * N
for i in range(N):
    a[i], b[i], c[i] = map(int, input().split())

dp=[[0 for i in range(3)] for j in range(N)] 
dp[0][0]=a[0]
dp[0][1]=b[0]
dp[0][2]=c[0]

for i in range(1,N):    
    dp[i][0]=max(dp[i-1][1]+a[i],dp[i-1][2]+a[i])
    dp[i][1]=max(dp[i-1][0]+b[i],dp[i-1][2]+b[i])
    dp[i][2]=max(dp[i-1][0]+c[i],dp[i-1][1]+c[i])

print(max(dp[-1][0],dp[-1][1],dp[-1][2]))

Measured memory_bytes: 89928
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef set<int> si;
typedef map<int, int> mii;
#define INF 1e16


int main(){
    int n;
    ll x=0,sum=0,ans=INF;
    cin>>n;
    vll a(n);

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

    for(int i=0; i<n-1; i++){
        x += a[i];
        if(i+1<n) ans=min(ans,abs(sum-2*x));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1920
n = int(input())
otoshidama = []
for i in range(n):
	a = list(input().split())
	a[0] = float(a[0])
	otoshidama.append(a)

def calc_value(l):
	if l[1] == "BTC":
		l[0] = 380000.0 * l[0]
	return l[0]
	
total = 0
for i in range(n):
	total += calc_value(otoshidama[i])

print(total)

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int ans = 0;
  while(n--){
    int a;
    cin >> a;
    if(a % 2) continue;
    while(a % 2 == 0){
      a /= 2;
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CADDi_A solver = new CADDi_A();
        solver.solve(1, in, out);
        out.close();
    }

    static class CADDi_A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            char[] n = Integer.toString(in.nextInt()).toCharArray();

            int ans = 0;
            for (char c : n) {
                if (c == '2') {
                    ans++;
                }
            }

            out.print(ans);

        }

    }
}



Measured memory_bytes: 22096
culPerimeter :: (Num a) => a -> a -> a
culPerimeter a b = (a + b) * 2

culArea :: (Num a) => a -> a -> a
culArea a b = a * b

main = do
    line <- getLine
    let [a, b] = map read $ words line
    putStrLn $ show (culArea a b) ++ " " ++ show (culPerimeter a b) 



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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m;
    cin >> n >> m;
    if(n <= 8 && m <= 8)
        cout << "Yay!";
    else
        cout << ":(";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<cmath>

using namespace std;

int main(){
    int n, w[150], rsum=0, mn = 10000;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> w[i];
        rsum+=w[i];
    }
    int lsum=0;
    for(int i=0;i<n;i++){
        lsum+=w[i];
        rsum-=w[i];
        mn = min(mn, abs(lsum-rsum));
    }
    cout << mn << endl;
}


Measured memory_bytes: 256
#include <cstdio>

#include <vector>
#include <queue>
#include <cstdint>
#include <cassert>
#include <tuple>

template<typename t> t inf() { assert(0); return t(); }
template<> double inf() { return (1LL << 50); }
template<> long inf() { return (1LL << 50); }
template<> int inf() { return (1LL << 31)-1; }

namespace Graph {
  template<typename tEdge>
  struct Graph {
    Graph() : v(0) {}
    std::vector<tEdge> edges;
    uint32_t v;
  };
  template<typename tEdge>
  void addEdge(Graph<tEdge>& graph, tEdge edge) {
    assert( edge.from < graph.v );
    assert( edge.to   < graph.v );
    graph.edges.push_back(edge);
  }
  template<typename tEdge>
  void setV(Graph<tEdge>& graph, uint32_t v) {
    graph.v = v;
  }
};

namespace Graph {
  namespace Dijkstra {
    template<typename tEdge>
    struct DijkstraInfo {
      std::vector<typename tEdge::wType> dists;
    };
    template<typename tEdge>
    static DijkstraInfo<tEdge> dijkstra(const Graph<tEdge>& graph, uint32_t start) {
      std::vector< std::pair<uint32_t, typename tEdge::wType> > *adj = new std::vector< std::pair<uint32_t, typename tEdge::wType> >[graph.v];
      int n = graph.edges.size();
      for(uint32_t i = 0; i < graph.v; ++i) adj[i].reserve(16);
      for(int i = 0; i < n; ++i) {
        adj[graph.edges[i].from].push_back(std::make_pair(graph.edges[i].to, graph.edges[i].w));
      }
      DijkstraInfo<tEdge> info;
      info.dists.resize(graph.v);
      for(auto &x : info.dists) x = inf<typename tEdge::wType>();
      info.dists[start] = 0;
      std::priority_queue< std::pair<typename tEdge::wType, uint32_t> > q;
      q.push(std::make_pair(0, start));
      while( not q.empty() ) {
        typename tEdge::wType w;
        uint32_t id;
        std::tie(w, id) = q.top(); q.pop(); w = -w;
        for(auto I : adj[id]) {
          uint32_t next;
          typename tEdge::wType nw;
          std::tie(next, nw) = I; nw += w;
          if( info.dists[next] <= nw ) continue;
          info.dists[next] = nw;
          q.push(std::make_pair(-nw, next));
        }
      }
      delete [] adj;
      return info;
    }
  };
};


struct Edge {
  uint32_t from;
  uint32_t to;
  typedef int wType;
  wType w;
};

int main() {
  Graph::Graph<Edge> graph;
  int v, e, r;
  scanf("%d %d %d", &v, &e, &r);
  setV(graph, v);
  for(int i = 0; i < e; ++i) {
    Edge edge;
    scanf("%u %u %d", &edge.from, &edge.to, &edge.w);
    addEdge(graph, edge);
  }
  auto res = Graph::Dijkstra::dijkstra(graph, r);
  int n = res.dists.size();
  for(int i = 0; i < n; ++i) {
    printf("%s\n", res.dists[i] == inf<int>() ? "INF" : std::to_string(res.dists[i]).c_str());
  }
  
  return 0;
}

Measured memory_bytes: 25972
import java.util.*;
class Main
{
  public static void main(String []args)
  {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int z[]=new int[n];
    float c=0.0f;
    for(int i=0;i<n;i++)
    {
      z[i]=sc.nextInt();
    }
    Arrays.sort(z);
    c=z[0];
    for(int i=1;i<n;i++)
    {
      c=(c+z[i])*0.5f;
    }
    System.out.println(c);
  }
}

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

int solve(int start, const vector<int> &t){
  int n = t.size();
  int top = start;
  int bottom = start + 1;
  int res = n;

  while(0 <= top && bottom < n){
    int kind = t[top]; //今から消えるであろうキャラクタの色
    int cnt = 0;

    //kindと同じ色である間、上に向かって数える
    while(0 <= top && t[top] == kind){
      cnt++;
      top--;
    }

    //kindと同じ色である間、下に向かって数える
    while(bottom < n && t[bottom] == kind){
      cnt++;
      bottom++;
    }

    //4個未満なら、消えない＝終わり
    if(cnt < 4) break;

    //4個以上なら、消える
    res -= cnt;
  }

  return res;
}

int main(){
  while(1){
    int n;
    cin >> n;
    if(n == 0) break;

    vector<int> t(n);

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

    //答えは最大でもn個
    int ans = n;

    //色を変える場所を決める
    for(int i = 0; i < n; i++){
      vector<int> nt = t;

      //[i]を何色に変えるかを決める
      for(int j = 1; j <= 3; j++){
        nt[i] = j;
        ans = min(ans, solve(i, nt));
      }
    }

    cout << ans << endl;
  }
}

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

using namespace std;

int main(int argc, const char *argv[]) {
  vector<int> va(3);
  for (int i = 0; i < va.size(); ++i) {
    cin >> va[i];
  }

  sort(va.begin(), va.end());

  cout << va[0] + va[1] << '\n';
  return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000000000000009
//#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl


signed main(){
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a,a+3);
    cout << a[2]-a[0] << endl;
    return 0;
}      


Measured memory_bytes: 256
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
	static void Main()
	{
		long n = long.Parse(Console.ReadLine());//int.Parseは文字列を整数に変換。
    long[] nums = new long[n];
    long[] minNum = new long[n-1];
    long[] maxNum = new long[n-1];
    long minMemo = 0;//ここまでの最大値
    long maxMemo = 0;//ここまでより右にある最小値
    long answer = long.MinValue;
		for(long i = 0; i < n; i++)
    {
      nums[i] = long.Parse(Console.ReadLine());
    }
    minMemo = nums[0];
    maxMemo = nums[n-1];
    for(long i = 0; i < n-1; i++)
    {
      if(nums[i] < minMemo) minMemo = nums[i];
      if(nums[n-1-i] > maxMemo) maxMemo = nums[n-1-i];
      minNum[i] = minMemo;
      maxNum[n-2-i] = maxMemo; 
      //Console.WriteLine(maxNum[(int)i]+" "+ minNum[(int)(n-2-i)]);
    }
    for(long i = 0; i < n-1; i++)
    {
      //Console.WriteLine(maxNum[i] +" "+ minNum[i]);
      answer = Math.Max(answer, maxNum[i] - minNum[i]);
    }
		Console.WriteLine(answer);
	}
}


Measured memory_bytes: 24224
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		var tot = A.Sum();
		
		int idx = -1;
		int diff = (int) 1e9;
		for(int i=0;i<N;i++){
			if(Math.Abs(N * A[i] - tot) < diff){
				idx = i;
				diff = Math.Abs(N * A[i] - tot);
			}
		}
		Console.WriteLine(idx);
		
		
	}
	int N;
	int[] A;
	public Sol(){
		N = ri();
		A = ria();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,-1,0,1},dy={1,0,-1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a.at(i);
	int ans=0;
	map<int,int> m;
	m[a.at(0)]++;
	ans++;
	for(int i=1;i<n;i++){
		auto next = m.lower_bound(a.at(i));
		if(next==m.begin()){
			ans++;
			m[a.at(i)]++;
		}
		else{
			next--;
			next->second--;
			if(next->second==0) m.erase(next->first);
			m[a.at(i)]++;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 5248
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
#include <time.h>
#include <iterator>
//#include "util.h"

using namespace std;
typedef unsigned uint;
typedef long long lint;
typedef unsigned long long ulint;



//呪文
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { cout << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { cout << "{ }"; return ostr;	} cout << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { cout << "{ }"; return ostr; }	cout << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { cout << "{ }"; return ostr; } cout << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
//template <typename T> void print(T* v, int N) { if (N == 0) cout << "{ }"; cout << "{" << v[0]; for (int i = 1; i < N; i++) cout << ", " << v[i]; cout << "}"; }
#define PI 3.14159265358979323846
#define EPS 1e-8
#define all(x) (x).begin(), (x).end()


#define INF ((lint)4000000000000000010)
typedef pair<lint, lint> pii;


int problemD()
{
	lint N, K;
	lint ans = INF;
	cin >> N >> K;
	vector<pii> ps;

	lint x, y;
	for (lint i = 0; i < N; i++) {
		cin >> x >> y;
		ps.push_back(pii(x, y));
	}

	sort(all(ps));

	// 間に K 個以上の点を含む 2 点を選択 [i, j]
	for (lint i = 0; i <= ps.size() - K; i++) {
		for (lint j = i + K - 1; j < ps.size(); j++) {

			// 横幅
			lint width = ps[j].first - ps[i].first;
			//cout << "width = " << width << endl;

			vector<lint> ys;
			for (int k = i; k <= j; k++) {
				ys.push_back(ps[k].second);
			}

			sort(all(ys));

			// 間に K 個以上の点を含む 2 点を選択
			for (lint ii = 0; ii <= ys.size() - K; ii++) {
				for (lint jj = ii + K - 1; jj < ys.size(); jj++) {

					lint height = ys[jj] - ys[ii];
					lint area = width * height;

					if (ans > area) ans = area;

				}
			}

		}
	}

	cout << ans << endl;

	return 0;
}

int main()
{
	//clock_t start, end;
	//start = clock();

	problemD();
	
	//end = clock();
	//printf("%d msec.\n", end - start);

	return 0;
}

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

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

  vector<string> s(n);
  for(int i = 0; i < n; i++) cin >> s[i];

  int q;
  cin >> q;

  int cnt = 0;

  vector<string> t(q);
  for(int i = 0; i < q; i++){
    cin >> t[i];

    for(int j = 0; j < n; j++){
      if(t[i] == s[j]){
        cnt++;
        break;
      }
    }
  }

  cout << cnt << endl;

  return 0;

}



Measured memory_bytes: 3484
# coding:utf-8

def main():
    s = input()
    one_start = 0
    zero_start = 0

    for i in range(len(s)):
        if i%2 == 0:
            if s[i] != "0":
                one_start += 1
        else:
            if s[i] != "1":
                one_start += 1

    for i in range(len(s)):
        if i%2 == 0:
            if s[i] != "1":
                zero_start += 1
        else:
            if s[i] != "0":
                zero_start += 1

    print(min(one_start,zero_start))

if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
#include <algorithm>
#include <iostream>
#include <numeric>
using namespace std;

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

    int a[m] = {};
    for (auto i = 0; i < m; i++) cin >> a[i];

    cout << max(-1, n - accumulate(a, a + m, 0));
}

Measured memory_bytes: 3664
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;


/** 累乗
    O(log n)
*/
template<typename T, T M>
T power(T x, T y)
{
    T ret = 1;
    for (; y != 0; y /= 2) {
        if (y % 2 != 0) {
            ret = (ret * x) % M;
        }
        x = (x * x) % M;
    }
    return ret;
}

/** 素数P を法とする逆元

    O(log n)
*/
template<typename T, T P>
T mod_inv(T x) {
    return power<T, P>(x, P-2);
}

/** 素数Pを法とする  static なメモ付きべき乗
 */
template<typename T, T P>
std::pair<T, T> memo_flactional(T val)
{
    static std::vector<T> memo{1};
    static std::vector<T> inv_memo{1};

    if (memo.size() <= val) {
        memo.reserve(val+1);
        inv_memo.reserve(val+1);
        for (T i = memo.size(); i <= val; ++i) {
            memo.push_back((memo[i-1] * i) % P);
            inv_memo.push_back((inv_memo[i-1] * mod_inv<T, P>(i)) % P);
        }
    }

    return std::make_pair(memo[val], inv_memo[val]);
}

// http://hos.ac/slides/20130319_enumeration.pdf

/** 素数P を法とする組み合わせ
 */
template<typename T, T P = 1000000007ULL>
T choose(T n, T r)
{
    T ret = memo_flactional<T, P>(n).first;
    ret *= memo_flactional<T, P>(r).second;
    ret %= P;
    ret *= memo_flactional<T, P>(n - r).second;
    ret %= P;

    return ret;
}


int main()
{
    int64_t H, W, A, B;
    std::cin >> H >> W >> A >> B;

    constexpr int64_t DIV = 1000000007;

    memo_flactional<int64_t, DIV>(H+W);

    int64_t ret = 0;
    for (int64_t i = B; i <= W - 1; ++i) {
        ret += choose(i + H-A-1, H-A-1) * choose( W - i -1 + A-1, A-1);
        ret %= DIV;
    }

    // choose(B, H-A-1, H-A-1) *    choose(W-B-1     + A-1, A-1);
    // choose(B+1 + H-A-1, H-A-1) * choose(W-B-1 -1  + A-1, A-1);
    // choose(W-1 + H-A-1, H-A-1) * choose(0 +       A-1, A-1);

    std::cout << ret << std::endl;

    return 0;
}


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

int main(){
    int N; cin >> N;
    int A[N];
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        cout << A[i] << ((i != N-1) ? " " : "");
    }
    cout << endl;
    int i, j;
    
    for(i = 1; i < N; ++i){
        j = i - 1;
        int tmp = A[i];
        while(j>=0 && A[j] > tmp){
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = tmp; 
        
        for(int k = 0; k < N; ++k) cout << A[k] << ((k != N-1) ? " " : "");
        cout << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3092
#include<stdio.h>

int main()
{
  int i, j;

  scanf("%d",&i);

  for(j = 3; j <= i ; j++){
    //3の倍数の表示
    if( (j / 10) % 10 == 3 || (j / 100) % 10 == 3 || (j / 1000) % 10 == 3){
       printf(" %d", j);
    }
    //13,23,33,...
    else if((j-3) % 10 == 0){
      printf(" %d", j);
    }
    //30,300,3000がふくまれる時表示する
    else if(j % 3 == 0){
      printf(" %d", j);
    }
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 600
import java.util.Scanner;

public class Main {
	Scanner sc;
	private Main(){
		sc = new Scanner( System.in );
	}

	private void run(){
		while ( true ){
			int n = sc.nextInt();
			int p = sc.nextInt();
			int winner;
			if( n == 0 && p == 0 ){ break; }
			int[] player = new int[ n ];
			for( int i = 0; i < player.length; i++ ){
				player[ i ] = 0;
			}
			for( int i = 0; ; i = ( ++i ) % n ){
				if( p > 0 ){
					p--;
					player[ i ]++;
				}else if( player[ i ] > 0){
					boolean end = true;
					for( int j = 0; j < n; j++ ){
						if( j == i ){ continue; }
						if( player[ j ] != 0){
							end = false;
							break;
						}
					}
					if( end ){
						winner = i;
						break;
					}
					p += player[ i ];
					player[ i ] -= player[ i ];
				}
			}
			System.out.println( winner );
		}
	}

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

Measured memory_bytes: 12000
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	try {
    		final int N = sc.nextInt();
    		int[] Hi = new int[N];
    		for (int i=0; i<N; i++) {
    			Hi[i] = sc.nextInt();
    		}

    		int count = 0;
    		int maxCount = 0;
    		for (int i=0; i<N-1; i++) {
    			if (Hi[i] >= Hi[i+1]) {
    				count++;
    			} else {
    				count = 0;
    			}
    			if (count >= maxCount) {
    				maxCount = count;
    			}
    		}

    		System.out.println(maxCount);

    	} finally {
    		sc.close();
    	}
    }
}



Measured memory_bytes: 50692
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstdlib>
using namespace std;
typedef long long ll;
int L, a[200005];
ll sum1[200005], sum2[200005], sum3[200005], sum[200005];
ll f1[200005], f2[200005], ans;
int main(){
    scanf("%d", &L);
    sum[0] = sum1[0] = sum2[L + 1] = sum3[0] = 0;
    for(int i = 1; i <= L; ++i){
        scanf("%d", &a[i]);
        sum[i] = sum[i - 1] + a[i];
        if(a[i] == 0){
            sum1[i] = sum1[i - 1] + 2;
            sum3[i] = sum3[i - 1] + 1;
        }else{
            sum1[i] = sum1[i - 1] + (a[i] & 1);
            sum3[i] = sum3[i - 1] + ((a[i] - 1) & 1);
        }
    }
    for(int i = L; i >= 1; --i){
        if(a[i] == 0){
            sum2[i] = sum2[i + 1] + 2;
        }else{
            sum2[i] = sum2[i + 1] + (a[i] & 1);
        }
    }
    ll mini = 0;
    for(int i = 1; i <= L; ++i)
        mini = min(mini, sum[i] - sum1[i]), f1[i] = sum1[i] + mini;
    mini = sum1[L] - sum[L];
    for(int i = L; i >= 0; --i)
        mini = min(mini, sum1[i] - sum[i]), f2[i] = sum[L] - sum1[i] + mini;
    ans = sum[L];
    mini = 0;
    for(int i = 0; i <= L; ++i){
        mini = min(mini, f1[i] - sum3[i]), ans = min(ans, f2[i] + sum3[i] + mini);
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 10368
#include<stdio.h>
int main(void){
  int a,b,sum=0;
  scanf("%d %d\n",&a,&b);
  if(a>b){
    sum+=a;
    a--;
  if(a>b){
      sum+=a;
    }else if(a<b){
      sum+=b;
    }else if(a==b){
    sum+=a;
  }
  }else if(b>a){
sum+=b;
    b--;
  if(a<b){
    sum+=b;
  }
    else if(a>b){
      sum+=a;
    }else if(a==b){
      sum+=a;
    }
  }else if(a==b){
    sum=a+b;
  }
  printf("%d",sum);
  return 0;
}
 

Measured memory_bytes: 128
from bisect import bisect
A, B, Q = map(int, input().split())
S, T =[None] * (A+2), [None] * (B+2)
S[0], T[0] = -10**20, -10**20
for i in range(A):
    S[i+1] = int(input())
for i in range(B):
    T[i+1] = int(input())
S[A+1] = 10**20
T[B+1] = 10**20

lenS, lenT = len(S), len(T)
for _ in range(Q):
    x = int(input())
    si, ti = bisect(S, x, 0, lenS), bisect(T, x, 0, lenT)
    sLength0, sLength1 = x - S[si-1], S[si] - x
    tLength0, tLength1 = x - T[ti-1], T[ti] - x
    Ans = (max(sLength0, tLength0), max(sLength1, tLength1), sLength0 + tLength1 + min(sLength0, tLength1), sLength1 + tLength0 + min(sLength1, tLength0))
    print(min(Ans))

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

int main() {
  int64_t N,D;
  cin >> N >> D;
  int ans = 0;
  int64_t X,Y;
  for (int i = 0; i < N ; i++){
    cin >> X >> Y;
    if ( X*X + Y*Y <= D*D ){
      ans++;
    }
  }
    cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;

const ll MOD = 1000000000 + 7;

ll add(ll a, ll b) {
  a %= MOD;
  b %= MOD;
  ll ans = (a + b) % MOD;
  return ans;
}

ll mul(ll a, ll b) {
  a %= MOD;
  b %= MOD;
  ll ans = (a * b) % MOD;
  ans += MOD;
  ans %= MOD;
  return ans;
}

/*
// Iterative Function to calculate (x^y) % MOD in O(log y)
ll power(ll x, int y) {
  ll res = 1;
  x %= MOD;
  while(y > 0) {
    if(y % 2 == 1) {
      res = mul(res, x);
    }
    y /= 2;
    x = mul(x, x);
  }
  return res;
}

// Returns n^(-1) mod p (Fermat's little theorem)
ll modInverse(ll n) {
  return power(n, MOD - 2);
}

ll fact[N_MAX];

// Returns nCr % p using Fermat's little theorem.
ll comb(ll a, ll b) {
  if(b == 0) return 1;
  return mul(mul(fact[a], modInverse(fact[b])), modInverse(fact[a - b]));
}
*/

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

  int N;
  ll K;
  cin >> N >> K;

  vector<ll> A(N);
  ll sum = 0ll;
  ll mx = 0ll;
  for(int i = 0; i < N; ++i) {
    cin >> A[i];
    sum += A[i];
    mx = max(mx, A[i]);
  }
  
  if(K == 0) {
    cout << mx << "\n";
    return 0;
  }

  ll l = 1ll, r = sum;
  while(l < r) {
    ll m = l + (r - l) / 2;

    ll cnt = 0ll;
    for(ll a: A) {
      if(a < m) continue; // already shorter than m

      ll cut = a / m;
      if(a % m == 0) --cut; // because a >= m, cut >= 0
      cnt += cut;
    }

    if(cnt > K) { // too many cuts. Go bigger
      l = m + 1;
    } else { // this is good, but can we go smaller?
      r = m;
    }
  }

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


Measured memory_bytes: 4748
# import sys
# import math
# import itertools
# from collections import deque
# from collections import defaultdict
# import heapq
# import copy
# import bisect
# import numpy as np
# from scipy.special import comb

# def my_input(): return sys.stdin.readline().rstrip()
# sys.setrecursionlimit(100000)
# INF = 1001001001001
# MOD = 1000000007

def main():

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

    if len(A) == len(set(A)):
        print('YES')
    else:
        print('NO')


if __name__ == '__main__':
    main()


Measured memory_bytes: 26808
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main(){
	int n,m;
	cin >> n >> m;
	int a[m];
	REP(i,m) cin >> a[i];
	bool broken[n + 1] = {};
	REP(i,m) broken[a[i]] = true;
	ll dp[n + 1] = {};
	dp[0] = 1;
	for(int now = 0; now < n; now++){
		if(broken[now + 1] == false){
			dp[now + 1] += dp[now];
			dp[now + 1] %= MOD;
		}
		if(broken[now + 2] == false){
			dp[now + 2] += dp[now];
			dp[now + 2] %= MOD;
		}
	}
	cout << dp[n] << endl;
}

Measured memory_bytes: 1536
N, M = map(int, input().split())
h_list = list(map(int, input().split()))

# 隣接する展望台より低い時点でbad
bad_set = set()
for _ in range(M):
    src, dst = map(int, input().split())
    src_h = h_list[src - 1]
    dst_h = h_list[dst - 1]
    if src_h < dst_h:
        bad_set.add(src)
    elif dst_h < src_h:
        bad_set.add(dst)
    else:
        bad_set.add(src)
        bad_set.add(dst)

print(N - len(bad_set))

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

signed main()
{
	int r,D,x0;
	while(cin>>r>>D>>x0){
		ll x=x0;
		for(int i=0;i<10;i++){
			x=r*x-D;
			cout<<x<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256