akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define INF INT_MAX 
#define mod 1000000007
using namespace std;
int main(){
    ll wan;
    ll N,P,i=0;
    vector<int> people(100,0);
    while(1){
        cin >> N >> P;
        if(N==0&&P==0) return 0;
        wan = P;
        for(int i=0;i<N;i++) people[i]=0;
        i=0;
        while(1){
            if(wan>0){
                people[i]++;
                wan--;
                if(people[i]==P){
                    cout << i << endl;
                    break;
                }
            }else{
                wan = people[i];
                people[i] = 0;
            }
            i++;
            if(i==N) i=0;
        }
    } 
}                                                                                                                         


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

long long ma(long long a,long long b)
{
	if (a>b)
	{
		return a;
	}
	else return b;
}

long long mi(long long a,long long b)
{
	if (a<b)
	{
		return a;
	}
	else return b;
}

long long ab(long long a)
{
	if (a<0)
	{
		a*=-1;
	}
	return a;
}

long long gcd(long long a,long long b)
{
	long long r=ma(ab(a),ab(b));
	long long l=mi(ab(a),ab(b));
	if (l==0LL)
	{
		return r;
	}
	return gcd(l,r%l);
}

long long lcm(long long a,long long b)
{
	return ab(a)*ab(b)/gcd(a,b);	
}

int main(int argc, char const *argv[])
{
	int k;
	cin>>k;
	long long ans=0;
	for (int i = 1; i <= k; ++i)
	{
		for (int j = 1; j <= k; ++j)
		{
			for (int l = 1; l <= k; ++l)
			{
				ans+=gcd(i,gcd(j,l));
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3636
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define INF (1000000007)
using namespace std;
typedef long long ll;
struct data{
	int a,b;
	int c;
	data(){}
	data(int aa,int bb,int cc){
		a=aa;
		b=bb;
		c=cc;
	}
	bool operator<(const data& d)const{
		if(a==d.a)return d.b<b;
		return a<d.a;
	}
};

int n;
data dri[200001];
int dp[200001];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d%d",&dri[i].a,&dri[i].b);
		dri[i+n].a=dri[i].b;
		dri[i+n].b=dri[i].a;
		dri[i+n].c=1;
	}
	sort(dri,dri+2*n);
	for(int i=0;i<2*n;i++){
		dp[i]=INF;
	}
	for(int i=0;i<2*n;i++){
		int val=dri[i].b,flag=dri[i].c;
		int num=lower_bound(dp,dp+2*n,val)-dp;
		if(num%2==flag)dp[num]=val;
	}
	printf("%d\n",(lower_bound(dp,dp+2*n,INF)-dp));
	return 0;
}

Measured memory_bytes: 6320
N,K = map(int,input().split())

if K&1:
  # 全部Kの倍数
  answer = (N//K) ** 3
else:
  KK = K//2
  # 全部KKの奇数倍 or 全部偶数倍
  even = N // K
  odd = (N//KK) - even
  answer = even ** 3 + odd ** 3

print(answer)

Measured memory_bytes: 2940
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <tuple>
#include <algorithm>

using namespace std;

int n, m;
int w[110000];
int cnt[110000];

int main() {
	scanf("%d%d", &n, &m);
	w[1] = 1;
	for (int i = 1; i <= n; i++) cnt[i] = 1;
	for (int i = 0; i < m; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		if (w[x] == 1) w[y] = 1;
		cnt[x]--;
		cnt[y]++;
		if (cnt[x] == 0) w[x] = 0;
	}
	int ans = 0;
	for (int i = 1; i<= n; i++) ans += w[i];
	printf("%d\n", ans);
	
	return 0;
}


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

namespace ABC113D
{
    class Program
    {
        static long[,] dp;
        static int[] fibonucchi = new int[9];
        static void Main(string[] args)
        {
            var HWK = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int H = HWK[0];
            int W = HWK[1];
            int K = HWK[2];
            dp = new long[W, H + 1];
            dp[0, 0] = 1;
            long div = 1000000007;

            fibonucchi[0] = 1;
            fibonucchi[1] = 1;
            for (int i = 2; i < fibonucchi.Length; i++) fibonucchi[i] = fibonucchi[i - 1] + fibonucchi[i - 2];
            for (int h = 1; h < H + 1; h++)
            {
                for (int w = 0; w < W; w++)
                {
                    long X = Fibonucchi(w - 1) * Fibonucchi(W - w - 1);
                    long Y = Fibonucchi(w) * Fibonucchi(W - w - 1);
                    long Z = Fibonucchi(w) * Fibonucchi(W - w - 2);
                    dp[w, h] = (X * DP(w - 1, h - 1) + Y * DP(w, h - 1) + Z * DP(w + 1, h - 1)) % div;
                }
            }

            long ans = dp[K - 1, H];
            Console.WriteLine(ans);
            Console.ReadKey();
        }

        static long Fibonucchi(int w)
        {
            if (w < 0) return 0;
            return fibonucchi[w];
        }

        static long DP(int w, int h)
        {
            if (w < 0 || h < 0) return 0;
            else if (w >= dp.GetLength(0) || h >= dp.GetLength(1)) return 0;
            return dp[w, h];
        }
    }
}


Measured memory_bytes: 13396
#include <iostream>

using namespace std;

int main()
{
    long long int N, K, a, A;
    cin >> N >> K;
    long long int sum = 0;
    for (long int i = K; i <= N + 1; i++){
        a = N * (N + 1) - (N - i) * (N - i + 1) - i * (i - 1);
        A = (a / 2 + 1) % (10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 + 7);
        sum += A;
    }
    long long int ans;
    ans = sum % (10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 + 7);
    cout << ans;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define X first
#define Y second

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;

const ll INF = 2e18;
const int inf = 1e9+10;
const int maxN = 2e5+10;
const int maxD = 15;
const int maxH = 100; 
const int MOD = 998244353;

ll a[maxN];
ll b[maxN],c[maxN];
ll ans[maxN];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	b[1] = a[1];
	for(int i=2;i<=n;i++)
	{
		b[i] = a[i] ^ b[i-1];
	}
	c[n] = a[n];
	for(int i=n-1;i>=1;i--)
	{
		c[i] = a[i] ^ c[i+1];
	}
	for(int i=1;i<=n;i++)
	{
		if(i == 1)
		{
			ans[i] = c[i+1];
		}
		else if(i==n)
		{
			ans[i] = b[i-1];
		}
		else
		{
			ans[i] = b[i-1] ^ c[i+1];
		}
	}
	for(int i=1;i<n;i++)
	{
		printf("%lld ",ans[i]);
	}
	cout<<ans[n]<<endl;
	return 0;
}

Measured memory_bytes: 9956
#include <iostream>

using namespace std;

int main()
{ int a,b,c;

  cin>>a>>b>>c;
  if (a==b&&a!=c)
  {
      cout<<c;
  }
  else if (b==c&&c!=a)
  {
      cout<<a;
  }
  else
    cout <<b;

    return 0;
}


Measured memory_bytes: 256
"""
tetrahedral = [i*(i+1)*(i+2)//6 for i in range(1,185)]
oddtetrahedral = [i*(i+1)*(i+2)//6 for i in range(1,185,4)]
INF = float("inf")
print(oddtetrahedral)"""
dp = [1e6+1]*(int(1e6)+1)
dpodd = [1e6+1]*(int(1e6)+1)

dp[0] = dpodd[0] = 0

for i in range(1, 181):
    num = i*(i+1)*(i+2)//6
    for j, tpl in enumerate(zip(dp[num:num*3+1], dp), start=num):
        a, b = tpl
        if (b+1 < a):
            dp[j] = b+1
    if (num&1):
        for j, tpl in enumerate(zip(dpodd[num:num*34+1], dpodd), start=num):
            a, b = tpl
            if (b+1 < a):
                dpodd[j] = b+1


"""
for i in range(int(1e6)):
    num = i*(i+1)*(i+2)//6
    if (num>=1e6):
        break
    for j in range(num, int(1e6)):
        dp[j] = min(dp[j], dp[j-num]+1)
        if (num&1):
            dpodd[j] = min(dpodd[j], dpodd[j-num]+1)


dp = [INF]*int(1e6+1)
dpodd = [INF]*int(1e6+1)

for a in tetrahedral:
    if (a > int(1e6)):
        break
    dp[a] = 1
for b in oddtetrahedral:
    if (b > int(1e6)):
        break
    dpodd[b] = 1

for i in range(int(1e6)+1):
    for a in tetrahedral:
        if (i+a <= int(1e6)):
            dp[i+a] = min(dp[i+a], dp[i]+1)
    for b in oddtetrahedral:
        if (i+b <= int(1e6)):
            dpodd[i+b] = min(dpodd[i+b], dpodd[i]+1)
"""

def solve(N):
    return (dp[N], dpodd[N])

"""
    dp = [INF]*(N+1)
    dpodd = [INF]*(N+1)
    for a in tetrahedral:
        if (a > N):
            break
        dp[a] = 1
    for b in oddtetrahedral:
        if (b > N):
            break
        dpodd[b] = 1

    def reca(n):
        if (n < 0):
            return INF
        if (dp[n] != INF):
            return dp[n]
        dp[n] = min([reca(n-a)+1 for a in tetrahedral if (n-a>=0)])
        return dp[n]

    def recb(n):
        if (n < 0):
            return INF
        if (dpodd[n] != INF):
            return dpodd[n]
        dpodd[n] = min([recb(n-b)+1 for b in oddtetrahedral])
        return dpodd[n]

    ret1 = reca(N)
    ret2 = recb(N)
    return (ret1, ret2)
"""

def main():
    ans = []
    while True:
        N = int(input())
        if (N == 0):
            break
        ans.append(solve(N))

    for i in ans:
        print(*i)

main()


"""
    for i in range(N+1):
        for a in tetrahedral:
            if (i+a <= N):
                dp[i+a] = min(dp[i+a], dp[i]+1)
        for b in oddtetrahedral:
            if (i+b <= N):
                dpodd[i+b] = min(dpodd[i+b], dpodd[i]+1)
    return (dp[N], dpodd[N])
"""


Measured memory_bytes: 29084
#include<iostream>
#include<stdio.h>
#include<vector>
#include<ctype.h>
#include<string>
#include<cmath>
using namespace std;

int n;
vector<int> x,y;

int main(){
    cin>>n;
    x.resize(n);
    y.resize(n);
    for(int j=0;j<n;++j){
        cin>>x[j];
    }
    for(int j=0;j<n;++j){
        cin>>y[j];
    }
    for(int i=1;i<=3;++i){
        long sum=0;
        for(int j=0;j<n;++j){
            int absoluteValue=sqrt((x[j]-y[j])*(x[j]-y[j]));
            int ExponentiationValue=pow(absoluteValue,i);
            sum+=ExponentiationValue;
            
        
        }
        double Dxy = pow(sum,1.0/i);
        printf("%.5lf\n",Dxy);
    }
    int max;
    for(int j=0;j<n;++j){
        int absoluteValue=sqrt((x[j]-y[j])*(x[j]-y[j]));
        if(j==0)max=absoluteValue;
        else if(absoluteValue > max)max=absoluteValue;
    }
    printf("%.5lf\n",(double)max);
    
    return 0;
}



Measured memory_bytes: 3356
#include <iostream>
#include <vector>
//#include <string>
#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1
//#define INFTY 1000000000000000000

int main(){
    LL n;
    cin >> n;
    vector<vector<LL>> dp(n+1, vector<LL>(3));
    vector<vector<LL>> abc(n+1, vector<LL>(3, 0));
    for(LL i=1; i<=n; i++){
        cin >> abc[i][0] >> abc[i][1] >> abc[i][2];
    }

    dp[0][0]=0;
    dp[0][1]=0;
    dp[0][2]=0;
    for(LL i=1; i<=n; i++){
        for(LL j=0; j<3; j++){
            for(LL k=0; k<3; k++){
                if(j==k){
                    continue;
                }
                dp[i][j]=max(dp[i][j], dp[i-1][k]+abc[i][j]);
            }
        }
    }

    LL ans=0;
    for(LL i=0; i<3; i++){
        ans=max(ans, dp[n][i]);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 14352
N = gets.to_i
dirs = gets.each_char.to_a
ww = Array.new(N,0)
ee = Array.new(N,0)
(N-1).times do |i|
  pos = i+1
  ww[pos] = ww[i] + (dirs[i] == 'W' ? 1 : 0)
  ee[N-pos-1] = ee[N-pos] + (dirs[N-pos] == 'E' ? 1 : 0)
end
# pp ww, ee
ret = N
N.times do |i|
  if ret > (ww[i] + ee[i])
    ret = (ww[i] + ee[i])
  end
end
puts ret


Measured memory_bytes: 31876
#include<bits/stdc++.h>
#define MAX 5002
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define Mod 1000000007
#define pii pair<ll,ll>
#define fi first
#define se second
#define pf push_front
#define endl "\n"
#define mp make_pair

using namespace std;

typedef long long ll;

int main(){
	ios_base::sync_with_stdio(false);
	
	ll n;cin>>n;
	ll a[n];
	For(i,0,n) cin>>a[i];
	ll b[n];For(i,0,n) b[i]=a[i];
	sort(b,b+n);
	deque<ll> q1,q2;
	
	ll s = 1,e=n-1;
	bool toggle=1;
	q1.pb(b[0]);
	while(s<=e){
		if(toggle){
			q1.pb(b[e--]);
			if(s>e) break;
			q1.pf(b[e--]);
		}else{
			q1.pb(b[s++]);
			if(s>e) break;
			q1.pf(b[s++]);
		}
		toggle = !toggle;
	}

	s = 0,e=n-2;
	q2.pb(b[n-1]);
	toggle=1; 
	while(s<=e){
		if(toggle){
			q2.pb(b[s++]);
			if(s>e) break;
			q2.pf(b[s++]);
		}else{
			q2.pb(b[e--]);
			if(s>e) break;
			q2.pf(b[e--]);
		}
		toggle = !toggle;
	}
	vector<ll> ans1,ans2;
	deque <ll> :: iterator it; 
    for (it = q1.begin(); it != q1.end(); ++it) ans1.pb(*it);
    for (it = q2.begin(); it != q2.end(); ++it) ans2.pb(*it);

    ll a1 = 0,a2=0;
	For(i,1,n){a1 += abs(ans1[i]-ans1[i-1]);}
	For(i,1,n){a2 += abs(ans2[i]-ans2[i-1]);}

	cout<<max(a1,a2)<<endl;

}

Measured memory_bytes: 5752
#include <iostream>
#include <string>

using namespace std;

int main(){
    
    // N : length of the string
    // S : string itself ()(((()()

    long N;
    string S;
    
    scanf("%ld", &N);
    cin >> S;
    char c;
    
    long cnt = 0;
    string ans = S;
    
    
    for(unsigned long i = 0; i<N; i++) {
        c = S[i];
        if(c=='('){
            cnt += 1;
        } else {
            cnt -= 1;
            if(cnt < 0){
                ans = '('+ans;
                cnt += 1;
            }
        }
    }
    
    
    for(long i = 0; i< cnt; i++){
        ans = ans+')';
    }
    
    cout << ans << endl;
    
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long M = 1e9+7;
int main() {
    int n,t;
    cin >> n >> t;
    vector<int> a(n);
    for(int i=0;i<n;i++)
        cin >> a[i];
        
    vector<vector<long long int> > dp(n+1,vector<long long int>(t+1,0));
    vector<vector<long long int> > prefix(n+1,vector<long long int>(t+1,0));
    

    
    for(int i = 0; i <= n;i++)
    {
        for(int j = 0;j <= t;j++)
        {
            if(j==0){
				dp[i][j]=1;
				prefix[i][j]=1;
			}else if(i==0){
				dp[i][j]=0;
				prefix[i][j]=prefix[i][j-1];
			}else if(j>a[i-1]){
				dp[i][j]=(prefix[i-1][j]-prefix[i-1][j-a[i-1]-1])%M;
				prefix[i][j]=(prefix[i][j-1]+dp[i][j]);
			}else{
				dp[i][j]=prefix[i-1][j]%M;
				prefix[i][j]=(prefix[i][j-1]+dp[i][j]);
			}
        }
    }
    cout << dp[n][t]%M << endl;
    return 0;
}

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

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

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;

  int x3, y3, x4, y4;
  int xDiff = x2 - x1;
  int yDiff = y2 - y1;
  x3 = x2 - yDiff;
  y3 = y2 + xDiff;
  x4 = x3 - xDiff;
  y4 = y3 - yDiff;
  cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <inttypes.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
    intmax_t A, B;
    char S[11], T[11], U[11];
    intmax_t ans = 0;

    scanf("%s%s", S, T);
    scanf("%jd%jd", &A, &B);
    scanf("%s", U);

    if (strcmp(S, U) == 0) {
        A -= 1;
    }
    if (strcmp(T, U) == 0) {
        B -= 1;
    }

    printf("%jd %jd\n", A, B);

    return 0;
}


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

template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};


const int MOD = 1000000007;
using mint = Fp<MOD>;


int modpow(int a,int x){
  if(a<0)a+=MOD;
  int ans=1;
  while(x>0){
    if(x&1) ans=ans*a%MOD;
      a=a*a%MOD;
      x>>=1;
  }
  return ans;
}
int gyaku(int n){
    return modpow(n,MOD-2);
}

map<int,int> prime;//素因数分解でそれぞれの素数がいくつ出てきたかを保存するmap

//O(√n)
//整列済み(mapはkeyで自動で整列される)
void prime_factorize(int n){
    if(n<=1) return;
    int l=sqrt(n);
    for(int i=2;i<=l;i++){
        if(n%i==0){
        prime_factorize(i);prime_factorize((int)(n/i));return;
        }
    }
    //mapでは存在しないkeyの場合も自動で構築される
    prime[n]++;return;
}
////////////////////////////////////////////////////////////////////////
signed main() {
  int a,b;
  cin>>a>>b;
  int n=gcd(a,b);
  prime_factorize(n);
  int ans=0;
  for(auto i:prime){
    ans++;
  }
  cout<<ans+1<<endl;
}


Measured memory_bytes: 3696
s=input()
n=len(s)
ans=0
for i in range(1<<n-1):
    num=s[0]
    for j in range(n-1):
        if i&(1<<j):
            num+="+"+s[j+1]
        else:
            num+="-"+s[j+1]
    if eval(num)==7:
        print(num+"=7")
        break

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

int main(){
    int n,mi=10000000,ma=-10000000;
    long long sum=0;
    cin >> n;
    
    int i,x;
    for(i=0;i<n;i++){
        cin >> x;
        if(i==0){
            mi = x;
            ma = x;
        }else if(mi>x){
            mi = x;
        }else if(ma<x){
            ma = x;
        }
        sum += x;
    }
    cout<<mi<<" "<<ma<<" "<<sum<<endl;
    return 0;
}


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

typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
    int n,k;cin>>n>>k;
    int ans = 0;
    rep(i,n){
        int tmp;cin>>tmp;
        ans += 2 * min(abs(tmp), abs(k-tmp));
    }
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <iomanip> //setprecision()
#include <vector>
#include <map>
using ll = long long;
using namespace std;

void monmo(){
    
}

int main() {
    int x,n;
    int num;
    map<int,int> m;
    cin>>x>>n;
    for(int i=0;i<n;i++){
        cin>>num;
        m[num]++;
    }
    for(int c=0;;c++){
        if(m[x-c]==0){
            cout<<x-c;
            exit(0);
        }
        if(m[x+c]==0){
            cout<<x+c;
            exit(0);
        }
    }
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <iomanip>
#include <queue>
using ll =long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;

int main() {
    int A, B;
    cin >> A >> B;

    cout << A*B << endl;
}

Measured memory_bytes: 3160
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(300000)


def solve(N: int, M: int, A: "List[int]"):
    s = sum(A)
    ret = N - s
    if ret < 0:
        ret = -1
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(M)]  # type: "List[int]"
    solve(N, M, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 68520
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <set>

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

using namespace std;


int main() {
	int a, b;
	cin >> a >> b;

	if (a >= 13) {
		cout << b << endl;
	}
	else if (a > 5) {
		cout << b / 2 << endl;
	}
	else {
		cout << 0 << endl;
	}


	return 0;
}


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

int main(){
  ll ans=0;
  ll n,i,j,a,c;
  ll b[1000001]={0};
  cin >> n;
  for(i=0;i<n;i++){
    cin >> a;
    if(b[a]==2){
      b[a]=1;
      ans-=1;
    }
    if(b[a]==0){
      ans+=1;
      b[a]=2;
      for(j=2;j*a<=1000000;j++){
        if(b[j*a]==2){
          ans-=1;
        }
        b[j*a]=1;
      }
    }
  }
  cout << ans;
}

Measured memory_bytes: 11448
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>

using namespace std;

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

int main() {
	int a[100000];
	int n, x;

	cin >> n >> x;
	
	long long ans = 0;
	REP(i, n) {
		scanf("%d", &a[i]);
		if (a[i] > x) {
			ans += a[i] - x;
			a[i] = x;
		}
	}
	
	REP(i, n - 1) {
		int sum = a[i + 1] + a[i];
		
		if (sum > x) {
			a[i + 1] = max(a[i + 1] - (sum - x), 0);
			ans += sum - x;
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

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

#define DEBUG 0

double distance(int x,int y){
  return sqrt( x*x+y*y );
}

int main(void){
  int n;  // 1<= n <= 400
  int fx[401],fy[401];
  char flag[401];

  char s1[50],s2[10];
  int i,j,k;

  int loop;
  int look1,look2;

  int x0,y0;
  int dx,dy;
  int min;
  double minth,minr;
  double th,r;

  double ans;

  while( 1 ){
    scanf( "%d ",&n );

    if( DEBUG==1 )
      printf("n=%d\n",n);
 
    if( !n )
      break;

    fx[0]=0;fy[0]=0;
    for( i=1;i<=n;i++ ){
      fgets(s1,50,stdin);
      for( j=0; s1[j]==' '||s1[j]=='\t' ;j++ ) ;
      for( k=0; '0'<=s1[j]&&s1[j]<='9' ;j++,k++ )
	s2[k]=s1[j];
      s2[k] = '\0';
      sscanf(s2,"%d ",&fx[i] );
      for(  ; s1[j]==' '||s1[j]=='\t';j++ ) ;
      for( k=0; '0'<=s1[j]&&s1[j]<='9' ;j++,k++ )
	s2[k]=s1[j];
      s2[k] = '\0';
      sscanf(s2,"%d ",&fy[i] );
      
      if( DEBUG==1 )
	printf(" %3d : %3d %3d\n",i,fx[i],fy[i]);
      
      flag[i] = 0;
    }

    look1=0; flag[0]=1;
    ans = 0.0;
    x0 = 0;     y0 = 1;

    while( 1 ){
      minth = 300.0;
      minr = 1000000000000.0;

      look2=-1;
      for(loop=1 ;loop<=n;loop++ ){
	if( flag[loop]!=0 )
	  continue;

	look2=loop;
	dx = fx[look2]-fx[look1];
	dy = fy[look2]-fy[look1];
	th = acos( ( dx*x0 + dy*y0 ) / 
		   ( distance(x0,y0)*distance(dx,dy) )  );

	if( DEBUG==1 ){
	  printf("%2d : (%3d,%3d)-(%3d,%3d) dx=%3d dy=%3d th=%f ans=%.1f\n",
		 look2,fx[look1],fy[look1],fx[look2],fy[look2],dx,dy,th,ans);
	  printf("\tx0=%d, y0=%d th[DEGREE]=%5.1f\n",x0,y0,th*180.0/3.14 );
	}
	if( th<minth ){
	  minth = th;
	  minr = distance(dx,dy );
	  min = look2;
	}else if( th==minth ){
	  r = distance(dx,dy);
	  if( r<minr ){
	    minth = th;
	    minr  = r;
	    min = look2;
	  }
	}
      }
      if( look2==-1 )
	break;

      dx = fx[min]-fx[look1];
      dy = fy[min]-fy[look1];
      ans += distance(dx,dy);
      flag[ min ]=1;
      x0 = dx;
      y0 = dy;

      look1 = min;
      if( DEBUG==1 )
	printf("CHOOSE : %d\tans=%.1f\n",min,ans);
    }
    printf("%.1f\n",ans);

  }

  return 0;
}

Measured memory_bytes: 0
import java.util.*;

public class Main {
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        
            int [] character = new int[26];
            while(sc.hasNextLine()){
                String text = sc.nextLine();
                           if (text.isEmpty()) {
                                    break;
                           }
                char [] ch = new char[text.length()];
                for (int i = 0; i < text.length(); i++) {
                    ch[i] = text.toLowerCase().charAt(i);
                }
                
                for (int c = 0; c < ch.length; c++) {
                    if ('a' <= ch[c] && ch[c] <= 'z') {
                        character[ch[c] - 'a']++; 
                    }
                    
                }
               
            }
            for (int i = 0; i < character.length; i++) {
                    System.out.println( (char)(i + 'a') + " : " + character[i]);
            }
    }
}



Measured memory_bytes: 30408
# -*- coding: utf-8 -*-
import math
 
abhm = list(map(int,input().split()))
A, B, H, M = abhm[0], abhm[1], abhm[2], abhm[3]

#print( S[:K] )

# 0時から見て時計回りを正とする、時針の角度をtheta_A, 分針の角度をtheta_Bとする。
#  0 <= theta_A,theta_B < 360
theta_A = H*30 + M*0.5
theta_B = M*6

# 時針と分針のなす角をthetaとする。
#  0 <= theta <= 180
if (  abs( theta_A - theta_B ) <= 180 ):
  theta = abs( theta_A - theta_B )
  
else:
  theta = 360 - abs( theta_A - theta_B )

#print(theta)

# 求める三角形の辺の長さCは、 C = √(A^2 + B^2 - 2AB*cosθ) なので、
C = math.sqrt( A**2 + B**2 - 2*A*B*math.cos( math.radians(theta) ) )

print(C)

Measured memory_bytes: 9572
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

signed main() {
    int a, b;
    cin >> a >> b;
    int d = __gcd(a, b);
    int _d = d;
    int result = 1;
    for(int i = 2; i * i <= _d; ++i) {
        if (d % i == 0) {
            result++;
            while (d % i == 0)
                d /= i;
        }
    }
    if (d != 1) result++;
    cout << result << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int N, mod=1e9+7; ll dp[3003][3003], ans; char s[3003];
int main(){
    scanf("%d %s", &N, s+1); dp[1][1] = 1;
    for(int i=2; i<=N; i++){
        for(int j=1; j<=i; j++){
            if(s[i-1] == '<') dp[i][j] = dp[i][j-1] + dp[i-1][j-1];
            else dp[i][j] = dp[i][j-1] + dp[i-1][i-1] - dp[i-1][j-1];
            dp[i][j] = (dp[i][j] + mod)%mod;
        }
    }
    printf("%lld\n", dp[N][N] % mod);
}


Measured memory_bytes: 68992
//
//  second.cpp
//  CoderTest
//
//  Created by yuya on 2019/07/25.
//  Copyright © 2019 yuya. All rights reserved.
//

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
#define all(x) (x).begin(), (x).end()
#define rep(i,n) for(int (i) = 0; (i) < (int)(n); i++)
#define rep1(i,n) for(int (i) = 1; (i) <= (int)(n); i++)
#define INF 1000000
#define MOD (ll)(1e9 + 7)





int main()
{
    string S;
    cin >> S;
    
    int Q;
    cin >> Q;
    
    int dir = 1;
    int T,F;
    char C;
    
    string S2;
    
    
    rep(i, Q){
        cin >> T;
        if (T == 1) {
            dir = !dir;
        } else if (T == 2) {
            cin >> F >> C;
            F--;
            if(dir ^ F) {
                S2.push_back(C);
            } else {
                S.push_back(C);
            }
        }
    }
        
    if(dir){
        reverse(all(S2));
        cout << S2 << S << endl;
    } else {
        reverse(all(S));
        cout << S << S2 << endl;
    }
    
    
    return 0;
}



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

int main(){
	int r, c, table[1000][1000], a;

	cin >> r >> c;

	for (int i = 0; i < r; i++){
		for (int j = 0; j < c; j++){
			table[i][j] = 0;
		}
	}

	for (int i = 0; i < r; i++){
		for (int j = 0; j < c; j++){
			cin >> table[i][j];
		}
	}

	for (int i = 0; i < r; i++){
		for (int j = 0; j < c; j++){
			table[i][c] += table[i][j];
		}
	}

	for (int i = 0; i < c; i++){
		for (int j = 0; j < r; j++){
			table[r][i] += table[j][i];
		}
	}

	for (int i = 0; i < r; i++){
		table[r][c] += table[i][c];
	}

	for (int i = 0; i < r + 1; i++){
		for (int j = 0; j < c; j++){
			cout << table[i][j] << " ";
		}
		cout << table[i][c]<< endl;
	}

	return 0;
}

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

int keta(int N){
  int counter = 1;
  while(N / 10 > 0){
    counter++;
    N /= 10;
  }
  return counter;
}

int main(){
  int N;
  cin >> N;
  int counter = 0;
  for(int i = 1; i <= N; i++){
    if(keta(i) % 2 == 1) counter++;
  }
  cout << counter << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); i++)
#define itrep(type, it, t) for(type::iterator it=t.begin(); it!=t.end(); it++)
using namespace std;


int main(void) {

    int N, M;
    cin >> N >> M;
    int p[M];
    string S[M];
    rep(i, M) {
        cin >> p[i] >> S[i];
        p[i]--;
    }
    int WA[N];
    bool AC[N];
    rep(i, N) {
        WA[i] = 0;
        AC[i] = false;
    }
    int ansWA = 0;
    int ansAC = 0;
    rep(i, M) {

        if(S[i] == "AC") {
            if(!AC[p[i]]) {
                AC[p[i]] = true;
                ansWA += WA[p[i]];
                ansAC ++;
            }

        } else if(S[i] == "WA") {
            if(!AC[p[i]]) {
                WA[p[i]]++;
            }
        }
    }

    cout << ansAC << " " << ansWA;
    return 0;
}

Measured memory_bytes: 6656
S=int(input())
X1=0
Y1=0
flag=True
if S<=10**9:
    X2=0
    Y2=1
    X3=S
    Y3=0
elif S%10**9==0:
    X2=0
    Y2=S//10**9
    X3=10**9
    Y3=0
else:
    t=S%(10**9)
    A=10**9-t#x2 , y3
    v=(S+A)//10**9#x3=10**9 , y2=v
    
    K=A
    if A<=10**9:
        X2=1
        Y3=A
        flag=False
        
    if flag:
        while A%2==0:
            A//=2
            if A<=10**9:
                X2=K//A
                Y3=A
            
        i=3
        while True:
            if A%i==0:
                A//=i
                if A<=10**9:
                    X2=K//A
                    Y3=A
                    break
                
            else:
                i+=2
    
    X3=10**9
    Y2=v
    
L=[X1,Y1,X2,Y2,X3,Y3]
print(" ".join([str(x) for x in L]))


Measured memory_bytes: 38632
#include<iostream>
#include<algorithm>
#include<functional>

using namespace std;

int main(){
	int n,m;
	int yasai[1000];
	int zenbu=0;
	int c=0;
	while(true){
		cin>>n>>m;
		if(n==0&&m==0)break;
		for(int i=0;i<n;i++){
			cin>>yasai[i];
		}
		sort(yasai,yasai+n,greater<int>());
		for(int i=0;i<n;i++){
			if(c==m-1)c=0;
			else {
				zenbu+=yasai[i];
				c++;
			}
		}
		cout<<zenbu<<endl;
		zenbu=0;
		c=0;
		for(int i=0;i<n;i++)yasai[i]=0;
	}
	return 0;
}

Measured memory_bytes: 1176
#include <iostream>
#include <algorithm>
#include <climits>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>

#define barsik ios::sync_with_stdio(false)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)

typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair <int, int> pii;
typedef std::unordered_set <int> u_si;

using namespace std;

double f(pii a, pii b){
    double ans = hypot(abs(a.first - b.first), abs(a.second - b.second));
    return ans;
}

void solve(){
    int n;
    cin >> n;
    pii a[10];
    int p[10];
    for(int i = 0; i < n; i++){
        cin >> a[i].first >> a[i].second;
        p[i] = i;
    }
    
    double len = 0;
    
    int cnt = 0;
    
    do{
        double dd = 0;
        for(int i = 0; i < n - 1; i++){
            len += f(a[p[i]], a[p[i + 1]]);
            dd = f(a[p[i]], a[p[i + 1]]);
        }
        cnt++;
    }
    while (next_permutation(p, p + n));
    
    cout << fixed << setprecision(6) << len / cnt;
    
}

int main(){
    barsik;
    int q = 1;

    //cin >> q;

    for(int i = 1; i <= q; i++){
        //cout << "Case " << i << ": ";
        solve();
    }
}


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


signed main()
{
    string s;
    cin >> s;
    if(s.size() <= 25){
        vector < int > used(26, 0);
        for(int i = 0; i < s.size(); ++i){
            used[s[i] - 'a'] = 1;
        }
        int f = -1;
        for(int i = 0; i < 26; ++i){
            if(used[i] == 0){
                f = i;
                break;
            }
        }
        cout << s << string(1, f + 'a');
        return 0;
    } else {
        vector < int > cur = {(int)(s[25] - 'a')};
        for(int i = 24; i >= 0; --i){
            cur.push_back(s[i] - 'a');
            int rs = -1;
            for(int j = 0; j < cur.size(); ++j){
                if((cur[j] > s[i] - 'a') && (rs == -1 || cur[j] < rs))rs = cur[j];
            }
            if(rs != -1){
                for(int j = 0; j < i; ++j){
                    cout << s[j];
                }
                cout << string(1, rs + 'a');
                return 0;
            }
        }
    }
    cout << -1;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<cmath>
#include<stdio.h>
#include<unordered_map>
#include<map>
#include<stack>
#include<queue>
#include<iterator>
#include<functional>
#include<climits>
#include<set>
#include<utility>

#define ll long long
#define MOD 1000000007

using namespace std;

const int mxN = 100005;

vector<int>vect[mxN];
bool visited[mxN];
int dp[mxN];
int maxLen = 0;

int dfs (int sv) {
	if (dp[sv] != -1) {
		return dp[sv];
	}
	visited[sv] = 1;
	int len = 0;
	for (int x:vect[sv]) {
		int currLen = dfs(x);
		len = max(len,currLen+1);	
	}
	maxLen = max(maxLen,len);
	dp[sv] = len;
	return dp[sv];
}

void solve () {
	int n,m,u,v;
	cin >> n >> m;
	for (int i = 0;i < m;++i) {
		cin >> u >> v;
		vect[u].push_back(v);
	}
	for (int i = 1;i <= n;++i) {
		dp[i] = -1;
	}
	for (int i = 1;i <= n;++i) {
		if (!visited[i]) {
			dfs(i);
		}
	}
	// for (int i = 1;i <= n;++i) {
	// 	cout << dp[i] << " ";
	// }
	// cout << '\n';
	cout << maxLen << '\n';
} 

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



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

#define ll long long int
using namespace std;

// recursion

ll func(ll wt, vector<ll> &val, vector<ll> &w, ll n) {
	if(n == 0 || wt == 0) return 0;
	if(w[n-1] > wt) return func(wt, val, w, n - 1);
	else return max(val[n-1] + func(wt-w[n-1], val, w, n - 1), func(wt, val, w, n - 1));
	
}

//dp
ll knapSack(ll wt, vector<ll> &val, vector<ll> &w, ll n) {
	if(n == 0 || wt == 0) return 0;
	vector<vector<ll>> dp(n+1, vector<ll>(wt+1,0));
	
	for(int i = 1;i <=n;i++) {
		for(int j = 1; j <=wt; j++) {
			if(w[i-1] <= j) {
				dp[i][j] = max(val[i-1] + dp[i - 1][j - w[i - 1]], dp[i - 1][j]);
			}
			else {
				dp[i][j] = dp[i-1][j];
				}
		}
	}
	return dp[n][wt];
}


int main() {
	ll n , wt;
	cin>>n>>wt;
	vector<ll> val(n), w(n);
	for(int i =0; i<n;i++) {
		cin>>w[i]>>val[i];
	}
	//cout<<func(wt, val, w, n)<<'\n';
	cout<<knapSack(wt, val, w, n)<<'\n';
	//cout<<knapSack(wt, w, val, n);
	return 0;

}

Measured memory_bytes: 80256
#include <iostream>
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
const int MAXN = 1000005;

int main(void){
    // Sieve of Eratosthenes
    int prime[MAXN];
    REP(i,MAXN) prime[i] = 1;
    prime[0] = prime[1] = 0;
    REP(i,1000)
        if (prime[i])
            for (int j=2*i; j < MAXN; j += i) prime[j] = 0;

    while (true){
        int n,x;
        cin >> n >> x;
        if (n == 0 && x == 0) break;
        int cost[n];
        REP(i,n) cin >> cost[i];

        // calc costs list
        int costs[MAXN] = {};
        REP(i,n) costs[cost[i]] = 1;
        REP(i,n)
            REP(j,MAXN-cost[i])
                if (costs[j]) costs[j+cost[i]] = 1;
                
        for (int i=x; i > 0; i--){
            if (prime[i] && costs[i]){
                cout << i << endl;
                break;
            }
            if (i == 1){
                cout << "NA" << endl;
                break;
            }
        }
    }
    return 0;
}

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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)        //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++)   //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)      //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define RANGE(i,v) for(auto &(i):v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

template<typename T> using V = vector< T >;
using Vi = V<int>;
using Vll = V<LL>;
using Vs = V<string>;

template<typename T1,typename T2> using P = pair< T1, T2 >;
using Pii = P<int,int>;

template<typename T>
T MIN(V<T> v){return *min_element(ALL(v));}

int main(){
    LL x,y,z,k;
    cin>>x>>y>>z>>k;
    Vll a(x),b(y),c(z);
    REP(i,x) cin>>a[i];
    REP(i,y) cin>>b[i];
    REP(i,z) cin>>c[i];

    sort(ALL(a),greater<LL>());
    sort(ALL(b),greater<LL>());
    sort(ALL(c),greater<LL>());

    Vll yummy;
    REP(l,x){
            REP(m,y){
                REP(n,z){
                    if((l+1)*(m+1)*(n+1)>k) break;
                    yummy.pb(a[l]+b[m]+c[n]);
                }
            }
        }

    sort(ALL(yummy),greater<LL>());

    REP(i,k) cout<<yummy[i]<<endl;

    return 0;
}

Measured memory_bytes: 1404
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

#define getchar getchar
#define putchar putchar
int32_t nextint(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); bool s=false; if(c=='-'){s=true;c=getchar();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); int s=0; if(c=='-'){s=1;c=getchar();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar(); while(c==' '||c=='\n') c=getchar(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar(); } *s='\0'; return len; }
void rsorta_u32(void *base, const int count, const int size, const int index){
	typedef uint32_t rsort_t;
	rsort_t (*a)[size] = (rsort_t(*)[size])base;
	rsort_t (*b)[size] = (rsort_t(*)[size])malloc(count*size*sizeof(rsort_t));
	int c[0x100];
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][index]>>(0<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][index]>>(0<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{rsort_t(*t)[size]=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][index]>>(1<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][index]>>(1<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{rsort_t(*t)[size]=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][index]>>(2<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][index]>>(2<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{rsort_t(*t)[size]=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][index]>>(3<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][index]>>(3<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{rsort_t(*t)[size]=a; a=b; b=t;}
	free(b);
}

int a[1000];
int main(void){
	int n=nextint();
	int k=nextint();
	for(int i=0; i<n; i++){
		a[i]=nextint();
	}
	rsorta_u32(a, n, 1, 0);
	int ans=0;
	for(int i=0; i<k; i++){
		ans+=a[i];
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 1552
from math import ceil
a, b = map(int, input().split())

mina = ceil(a/0.08)
minb = ceil(b/0.1)

la = []
lb = set()

flag = True
while flag == True:
    if int(mina * 0.08) == a:
        la.append(mina)
        mina += 1
    else:
        break
while flag == True:
    if int(minb * 0.1) == b:
        lb.add(minb)
        minb += 1
    else:
        break
for i in la:
    if i in lb:
        print(i)
        break
else:
    print(-1)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
using namespace std;
typedef long long ll;
// cd test ; rm -R ./*; cd .. 

int main(void) {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;

  string ans = "";

  rep (i, ty - sy) {
    ans = ans + 'U';
  }
  rep (i, tx - sx) {
    ans = ans + 'R';
  }
  int s1 = ans.size();
  rep (i, s1) {
    if (ans[i] == 'R') ans = ans + 'L';
    if (ans[i] == 'U') ans = ans + 'D';
  }

  ans = ans + 'L';
  rep (i, ty - sy + 1) {
    ans = ans + 'U';
  }
  rep (i, tx - sx + 1) {
    ans = ans + 'R';
  }
  ans = ans + 'D';
  
  ans = ans + 'R';
  rep (i, ty - sy + 1) {
    ans = ans + 'D';
  }
  rep (i, tx - sx + 1) {
    ans = ans + 'L';
  }
  ans = ans + 'U';
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
	int n;
	cin >> n;
	long double x[n], y[n];
	long double ans[4] = {};
	for (int i = 0; i < n; i++) cin >> x[i];
	for (int i = 0; i < n; i++) cin >> y[i];
	for (int i = 0; i < n; i++){
		ans[0] += abs(x[i]-y[i]);
		ans[1] += pow(abs(x[i]-y[i]), 2);
		ans[2] += pow(abs(x[i]-y[i]), 3);
		ans[3] = max(ans[3], abs(x[i]-y[i]));
	}
	ans[1] = pow(ans[1], (double)(1/2.0));
	ans[2] = pow(ans[2], (double)(1/3.0));
	for (int i = 0; i < 4; i++){
		printf("%.10Lf\n", ans[i]);
	}

	

}




Measured memory_bytes: 3464
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int mod=1000000007;
inline void add(int &x,int y){(x+=y)>=mod?x-=mod:0;}
inline int kpow(int a,int b)
{
	int s=1;
	for(;b;b>>=1,a=1ll*a*a%mod)
		if(b&1)s=1ll*s*a%mod;
	return s;
}
int n,m,jc[200020],jcv[200020],ans,dp[200020];
char s[200020];
void init()
{
	jc[0]=1;
	for(int i=1;i<=200000;++i)jc[i]=1ll*jc[i-1]*i%mod;
	jcv[200000]=kpow(jc[200000],mod-2);
	for(int i=200000;i;--i)jcv[i-1]=1ll*jcv[i]*i%mod;
}
inline int C(int a,int b)
{
	if(a<b)return 0;
	return 1ll*jc[a]*jcv[b]%mod*jcv[a-b]%mod;
}
int main()
{
	init();
	scanf("%d %d",&n,&m);
	scanf("%s",s+1);
	char r=s[1];
	for(int i=1;i<=m;++i)s[i]=s[i]==r?0:1;
	int last=0,mi=0x3f3f3f3f;
	for(int i=1;i<=m;++i)
		if(s[i]==1)
		{
			if(!last)
			{
				if(i&1)mi=min(mi,i);
				else mi=min(mi,i-1);
			}
			else if((i-last-1)&1)mi=min(mi,i-last-1);
			last=i;
		}
	if(!last)
	{
		for(int k=0;k<=n-2-k;++k)add(ans,C(n-2-k,k));
		add(ans,ans);
		for(int k=0;k<=n-1-k;++k)add(ans,C(n-1-k,k));
		printf("%d",ans);
		return 0;
	}
	if(n&1)return printf("0"),0;
	n>>=1;mi=mi+1>>1;
	int tmp=1;dp[0]=1;
	for(int i=1;i<=n;++i)
	{
		if(i-mi-1>=0)add(tmp,mod-dp[i-mi-1]);
		dp[i]=tmp;
		add(tmp,dp[i]);
	}
	for(int i=1;i<=mi;++i)ans=(ans+1ll*dp[n-i]*i)%mod;
	add(ans,ans);
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 2304
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>

#define MAX_W (100000L)
#define MAX_H (100000L)
#define INF (1000000000L)

using namespace std;

int main(int argc, char *argv[]) {
  // read inputs
  long W, H, ps[MAX_W + 1], qs[MAX_H + 1];
  scanf("%ld %ld", &W, &H);
  for (int i = 0; i < W; i++) {
    scanf("%ld", &ps[i]);
  }
  for (int j = 0; j < H; j++) {
    scanf("%ld", &qs[j]);
  }

  // sort inputs
  ps[W] = INF;
  qs[H] = INF;
  sort(ps, ps + W + 1);
  sort(qs, qs + H + 1);

  // solve
  long ans = 0, m = 0, n = 0;
  while (m < W || n < H) {
    const long p = ps[m], q = qs[n];
    if (p < q) {
      ans += p * (H + 1 - n);
      m++;
    } else {
      ans += q * (W + 1 - m);
      n++;
    }
  }
  printf("%ld\n", ans);

  return 0;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define hell  1000000007
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb   push_back


int main()
{
	ios;
	ll a[10];
	for(ll i=0;i<5;i++)cin>>a[i];
	for(ll i=0;i<5;i++)
	{
		if(a[i]==0)
			{
				cout<<i+1;
				break;
			}
	}
}

Measured memory_bytes: 3564
from bisect import bisect_left
import random
import time
import math


#入力
D = int(input())
C = [int(c) for c in input().split()]
S = []
for _ in range(D):
    s = [int(x) for x in input().split()]
    S.append(s)
#初期解
T = []
for _ in range(D):
    t = random.randrange(26)
    T.append(t)


last_day = [[-1] for _ in range(26)]
for d in range(D):
    test = T[d]
    last_day[test].append(d)
for i in range(26):
    last_day[i].append(D)


T0 = 4000
time_start = time.perf_counter()
while True:
    time_now = time.perf_counter()
    if time_now - time_start > 1.80:
        break
    #時間を正規化して温度を設定
    time_n = (time_now - time_start) / 1.80
    T1 = T0 ** (1 - time_n)
    for _ in range(100):
        #ランダムな日のテストをランダムに入れ替え
        d = random.randrange(365)
        q = random.randrange(26)
        old = T[d]
        T[d] = q
        #日程dでの元のテストold
        l = last_day[old]
        ind_old = l.index(d)
        dd_left = l[ind_old] - l[ind_old-1] - 1
        dd_right = l[ind_old+1] - l[ind_old] - 1
        dd = l[ind_old+1] - l[ind_old-1] - 1
        dif_old = C[old] * (((dd_left * (dd_left + 1)) // 2) + ((dd_right * (dd_right + 1)) // 2) - ((dd * (dd + 1)) // 2))
        #日程dでのテストq
        l = last_day[q]
        ind_q = bisect_left(last_day[q],d)
        dd_left = d - l[ind_q-1] - 1
        dd_right = l[ind_q] - d - 1
        dd = l[ind_q] - l[ind_q-1] - 1
        dif_q = C[q] * (((dd * (dd + 1)) // 2) - ((dd_left * (dd_left + 1)) // 2) - ((dd_right * (dd_right + 1)) // 2))
        #変更による差
        dif_s = dif_old + dif_q - S[d][old] + S[d][q]
        if (dif_s > 0) or (math.exp(dif_s / T1) > random.random()):
            del last_day[old][ind_old]
            last_day[q].insert(ind_q,d)
        else:
            T[d] = old
for d in range(365):
    print(T[d] + 1)



Measured memory_bytes: 83352