akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;
int main() {
    int dates[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    string days[] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};

    int m,d;
    while (cin >> m >> d && m != 0 || d != 0) {
        int day = 2;
        for (int i=0; i<m-1; ++i) {
            day = (day + dates[i]) % 7;
        }
        day = (day + d) % 7;

        cout << days[day] << endl;
    }
}

Measured memory_bytes: 1196
<?php
fscanf(STDIN,"%d",$n);
$srt=$org=explode(" ",fgets(STDIN));
sort($srt);
$cnt=0;
for($i=0,$len=count($org);$i<$len;$i++){
if($org[$i]!=$srt[$i])$cnt++;
}
echo $cnt<=2?'YES':'NO';


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

using namespace std;
using LL = long long;

int main(){
    int N,M;cin >> N  >> M;
    vector<LL> A;
    for(int a = 0;a < N;a++){
        LL b;cin >> b;
        A.push_back(b);
    }
    vector<pair<LL,LL>> way;
    for(int  a = 0;a < M;a++){
        LL b,c;cin >> b >> c;
        way.push_back({c,b});
    }
    for(int a = 0;a < N;a++){
        way.push_back({A.at(a),1});
    }
    sort(way.begin(),way.end(), greater<pair<LL,LL>>());
    LL ans = 0;
    int cnt = N;
    for(int a = 0;a < way.size();a++){
        if(cnt - way.at(a).second <= 0){
            ans += way.at(a).first * cnt;
            cnt = 0;
            break;
        }else{
            cnt -= way.at(a).second;
            ans += way.at(a).first*way.at(a).second;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 7280
#include <bits/stdc++.h>
using namespace std;
long long n,x=0,y;
int main()
{
    cin>>n;
    for (int i=1;i<=n;i++)
    {
        for (int j=2;j<=1000;j++)
        {
            if (pow (i,j)<=n)
            {
                y=pow (i,j);
                x=max (x,y);
            }
            else
                break;
        }
    }
    cout<<x;
    return 0;
}


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.Set;
 
 
public class Main {

	static long MOD = 1_000_000_007;
	static long[] fac;
	static long[] finv ;
	static long[] inv ;
	public static void main(String[] args) throws Exception {
		// TODO Auto-generated method stub
		//int N = Integer.parseInt(sc.next());
		//long L = Long.parseLong(sc.next());
		int INF = Integer.MAX_VALUE;
		Scanner sc = new Scanner(System.in);
		//char[] c = sc.next().toCharArray();
		//int N = A.length;
		int N = Integer.parseInt(sc.next());
		int K = Integer.parseInt(sc.next());
		
		int MAX = 510000;
		fac = new long[MAX];
		finv = new long[MAX];
		inv = new long[MAX];
		
		
	    fac[0] = fac[1] = 1;
	    finv[0] = finv[1] = 1;
	    inv[1] = 1;
	    for (int i = 2; i < MAX; i++){
	        fac[i] = fac[i - 1] * i % MOD;
	        inv[i] = MOD - inv[(int) (MOD%i)] * (MOD / i) % MOD;
	        finv[i] = finv[i - 1] * inv[i] % MOD;
	    }
		
		long ans=0;
		
		for(int i=1; i<K+1; i++){
			ans = COM(K-1,i-1)*COM(N-K+1,i)%MOD;

		    ans %= MOD;
			System.out.println(ans);
		}
	    
		
	}
	static long COM(int n, int k){
	    if (n < k) return 0;
	    if (n < 0 || k < 0) return 0;
	    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
	}
	
	static long lcm (long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return (c/b);
	}
}



Measured memory_bytes: 34644
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mst(a,b) memset((a),(b),sizeof(a))
#define pi acos(-1)
#define pii pair<int,int>
const int INF = 0x3f3f3f3f;
const long double eps = 1e-12;
const int MAXN = 2e4 + 10;
const int MAXM = 3e4 + 10;
const ll mod = 1e9 + 7;

int a[MAXN];
bool vis[MAXM];
int tot = 0,sum = 0;

bool judge(int num) {
    for(int i=0; i<tot; i++) {
        if(__gcd(a[i],sum-a[i]+num) == 1) return false;
    }
    return true;
}

int main()
{
#ifdef local
    freopen("data.txt","r",stdin);
//    freopen("data.txt","w",stdout);
#endif
    int n;
    scanf("%d",&n);
    for(int i=2; i<3e4&&tot<n-1; i++) {
        if(i%2 == 0 || i%3 == 0) a[tot++] = i,vis[i] = true;
    }
    for(int i=0; i<n-1; i++) sum += a[i];
    for(int i=2; i<=3e4; i++) {
        if(!vis[i] && __gcd(sum,i) != 1 && judge(i)) {
            a[tot++] = i;
            break;
        }
    }
    for(int i=0; i<tot; i++)
        printf("%d ",a[i]);
    return 0;
}


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

int n, m;
pair<long long int, long long int> z[200000];

int main() {
    cin >> n >> m;
    for(int i = 0; i < n; ++i)
        cin >> z[i].second, z[i].first = 1;
    for(int i = n; i < m + n; ++i)
        cin >> z[i].first >> z[i].second;
    sort(z, z + m + n, [](const pair<long long int, long long int> a, const pair<long long int, long long int> b){ return a.second < b.second;});
    long long int pr = n, sum = 0, i = m + n - 1;
    //cout << endl;
    //for(int i = 0; i < n + m; ++i)
    //    cout << z[i].first << " " << z[i].second << endl;
    while(pr != 0) {
        sum += min(z[i].first, pr) * z[i].second;
        pr -= min(z[i].first, pr);
        --i;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;


int main() {
  int n;
  cin >>n;
  vl a(n);
  rep(i,n) cin >> a[i];
  P ans;
  sort(a.begin(),a.end());
  ll r = a.back();
  ll l = -1;

  double m = (double)r/2;
  double tmp = 1001001001;
  rep(i,n-1){
    if(abs((double)a[i]-m) < tmp){
      l = a[i];
      tmp = abs((double)a[i]-m);
    }
  }
  cout<<r<<" "<<l<<endl;
  return 0;
}

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

int main() {
    int a, b, c;
    int count = 0;
    cin >> a >> b >> c;
    for (int n=a;n<=b;n++) {
        if (c % n==0) {
            count += 1;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 3096
import java.util.Scanner;

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

        long times = (x / 11) * 2;
        long rest = x % 11;

        if (rest == 0) {
            System.out.println(times);
        } else if (rest > 6) {
            times += 2;
            System.out.println(times);
        } else {
            times++;
            System.out.println(times);
        }
    }
}


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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll T[1005];

ll gcd(ll a, ll b) {
    if (a < b)
        swap(a, b);
    ll c = a % b;
    if (c == 0)
        return b;
    return gcd(b, c);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    REP(i, N) {
        cin >> T[i];
    }
    ll x = T[0];
    REP(i, N) {
        ll g = gcd(x, T[i]);
        x = x / g * T[i];
    }
    cout << x << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
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;
  }
}

Measured memory_bytes: 256
n = gets.to_i
as = gets.split(' ').map(&:to_i)
as.sort!
min_1 = as[1]

def solve(as, x)
    count = 0
    as.each do |a|
        count += 1 if a % x != 0
        return false if count == 2
    end
    return true
end

min_1.times do |i|
    ans = solve(as, min_1-i)
    if ans == true
        puts min_1 - i
        break
    end
end


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

std::string S;

bool f(){
    if(S[0] != 'A'){
        return false;
    }

    if(std::count(S.begin() + 2, S.end() - 1, 'C') != 1){
        return false;
    }

    return std::count_if(S.begin(), S.end(), [](char c){return std::islower(c);}) + 2 == S.size();
}

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

    if(f()){
        std::cout << "AC" << std::endl;
    }else{
        std::cout << "WA" << std::endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<cstdio>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#define pi 3.14159
#define Inf (int)pow(2., 12.)

using namespace std;
typedef std::pair<int, int> mypair;
queue<mypair> qu;
#define M 1000000
const int dy[4] = {0, 1, 0, -1}, dx[4] = {1, 0, -1, 0};
#define N 123456 
int num = 0;


int main(){
	int n;
	cin >> n;
	for(int i = 0; i < n; i++) {
		int y, m, d, count = 0;
		cin >> y >> m >> d;
		for(int j = m; j <= 10; j++) {
			if(y % 3 == 0 || j % 2 == 1) {
				if(j == m) {
					for(int k = d; k <= 20; k++) {
						count++;
					}
				} else {
					for(int k = 1; k <= 20; k++) {
						count++;
					}
				}
			} else if(j % 2 == 0) {
				if(j == m) {
					for(int k = d; k <= 19; k++) {
						count++;
					}
				} else {
					for(int k = 1; k <= 19; k++) {
						count++;
					}
				}
			}
		}
		for(int j = y+1; j < 1000; j++) {
			if(j % 3 == 0) count += 10*20;
			else count += 5*20 + 5*19;
		}
		cout << count <<endl;
	}

	
	return 0;
}

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

#define ll long long
ll dp[200][100005];

int main()
{
    int n,w;
    cin>>n>>w;
    int weight[n+5],value[n+5];
    for(int i=1;i<=n;i++){
        cin>>weight[i];
        cin>>value[i];
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=w;j++){
            if(weight[i]>j)
                dp[i][j]=dp[i-1][j];
            else
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-weight[i]]+value[i]);
        }
    }
    cout<<dp[n][w]<<endl;
}


Measured memory_bytes: 79360
# ＤＦＳ, グリッド で スタート から ゴール までの経路をを探索
 # ※ 要削除

n, q = map(int,input().split())

pic = [[] for _ in range(n+1)]
for _ in range(n-1): # 絵の取り込み
    x, y = map(int, input().split())
    pic[x].append(y)
    pic[y].append(x)
    
cnts = [0] * (n+1)
for _ in range(q):
    x, y = map(int, input().split())
    cnts[x] += y

visited = [0] * (n+1) # 訪問の記録、初期化
visited[0], visited[1] = 1, 1

stack = []
stack.append(1)

#print(n, q) # ※
#print(pic) # ※
#print(cnts)
#print(visited) # ※

while stack:
    tmp = stack.pop() # 探索候補を pop して...
    for i in pic[tmp]: # 次の探索候補を探索
        if visited[i] != 0: # 未訪問かどうかを確認...
            continue
        else: # 未訪問の場合...
            visited[i] = 1 # 現在地の訪問を記録
            cnts[i] += cnts[tmp] # 親の 'cnt' を自身の 'cnt' に加える
            stack.append(i) # 現在地を探索候補に積む

print(*cnts[1:])


Measured memory_bytes: 55828
import sys

n,k = list(map(int, input().split(" ")))
l = list(map(int, input().split(" ")))
l = [999999]*k + l
dp= [0]*(n+k)

for i in range( k + 1, n+k):
	dp[i] = min([ dp[i - j] + abs(l[i] - l[i - j]) for j in range(1, k + 1) ])

print(dp[n + k - 1])

Measured memory_bytes: 53712
#include <stdio.h>
#define max(X, Y) ((X) > (Y) ? (X) : (Y))

int main()
{
    int n;
    int a;
    int cnt = 0;
    int maxv = 0;
    int i;

    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d", &a);
        if (a == 0) {
            cnt = 0;
        } else {
            cnt++;
            maxv = max(maxv, cnt);
        }
    }

    printf("%d\n", maxv + 1);

    return 0;
}
        



Measured memory_bytes: 1992
#include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <string>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;

int main(){
  int N,M;
  cin >> N >> M;
  int L_max=0,R_min=N+1;
  int L,R;
  for(int i=0;i<M;i++){
    cin >> L >> R;
    L_max=max(L_max,L);
    R_min=min(R_min,R);
  }

  if(R_min<L_max){
    cout << 0 << endl;
  }
  else cout << R_min-L_max+1 << endl;
  
  return 0;
}


Measured memory_bytes: 256
using System;

class Program {
    static void Main(string[] args){
        int N = int.Parse(Console.ReadLine());
        string s = Console.ReadLine();
        string t = Console.ReadLine();
        
        for(int i=0;i<N;i++){
            bool b = true;
            for(int j=0;j<N-i;j++){
                b = b && (s[j+i]==t[j]);
            }
            if(b == true){
                Console.WriteLine(i+N);
                return;
            }
        }
        Console.WriteLine(2*N);
    }
}

Measured memory_bytes: 2776
def get_int_array
    gets.strip.split(' ').map(&:to_i)
end

n, m = get_int_array
ns = Array.new(n+1, true)

m.times{|_| ns[gets.strip.to_i] = false }

dp = Array.new(n+1, 0)
dp[0] = 1
(0...n).each{|i|
    ((i + 1)..[n, i+2].min).each {|j|
        if ns[j]
            dp[j] += dp[i]
            dp[j] %= 1_000_000_007
        end
    }
}
p dp[n]

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    int x, a, b;cin >> x >> a >> b;
    char ans = 'A';
    if(abs(x-b) < abs(x-a)) ans = 'B';
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
N,K,Q = map(int,input().split())
A = [int(input()) for _ in range(Q)]

points = [0] * N
for a in A:
    points[a-1] += 1
    
border = Q-K
for p in points:
    if p > border:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 8628
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
	int b = 1;
	int p = 2;
	double max = 0;
	double result;
	Scanner scanner = new Scanner(System.in);
	int x = scanner.nextInt();
	while (b < 1000) {
	    while (p < 1000) {
		result = Math.pow(b, p);
		if (result > x ) break;
		if (result >= max) max = result;
		p++;
	    }
	    p = 2;
	    b++;
	}
	System.out.println((int)max);
    }
    
}


Measured memory_bytes: 23764
n = int(input())
x = list(map(int, input().split()))

min_x = 100 * 100 * 100 + 1
for p in range(1, 100+1, 1):
  total = 0
  for xi in x:
    total += (xi - p) ** 2

  min_x = min([min_x, total])

print(min_x)



Measured memory_bytes: 8960
N,K=map(int,input().split())
a=list(map(int,input().split()))
ans=float('inf')
for i in range(1<<(N-1)):
  cost,cnt,h=0,1,a[0]+1
  for j in range(N-1):
    x=a[j+1]
    if i>>j&1:
      cnt+=1
      if x>h:
        h=x+1
      else:
        cost+=h-x
        h+=1
    h=max(h,x+1)
  if cnt>=K:
    ans=min(ans,cost)
print(ans)

Measured memory_bytes: 9168
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = True

tmp = INT()
if tmp == 2:
    a = INT()
    b = INT()
    print(a + b)
else:
    print('Hello World')

Measured memory_bytes: 59628
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793




int main(){
    int A,B,m;
    cin >> A >> B >> m;
    VI a(A);
    VI b(B);
    rep(i,A)cin >> a.at(i);
    rep(i,B)cin >> b.at(i);
    VI x(m),y(m),c(m);
    rep(i,m){
        cin >> x.at(i) >> y.at(i) >> c.at(i);
    }
    ll ans=mm;
    rep(i,m){
        int X=a.at(x.at(i)-1);
        int Y=b.at(y.at(i)-1);
        ll cst=X+Y-c.at(i);
        ans=min(ans,cst);
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    ll cst=a.at(0)+b.at(0);
    ans=min(ans,cst);
    cout << ans << endl;

}



    
   


Measured memory_bytes: 5096
N, T = map(int, input().split())
A = [int(i) for i in input().split()]

c = 0
MAX = 0
a1 = A[0]
for i in range(N-1):
    if A[i] <= a1:
        a1 = A[i]
    a2 = A[i+1]
    if MAX == a2 - a1:
        c += 1
    elif MAX < a2 - a1:
        MAX = a2 - a1
        c = 1
print(c)


Measured memory_bytes: 19944
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(){

    int N;
    cin>> N;

    int t=0;
    if(N==2){
        cout<< 1<< endl;
        return 0;
    }
    while(N>=2){
        if(N%2==0){
            if(N%3==0){
                N/=3;
            }else{
                N=(N+3-1)/3;
            }
            t++;
        }else{
            if(N%3==0){
                N/=3;
            }else if(N%3==1){
                N=(N+3-1)/3;
            }else{
                N=(N+3-1)/3;
            }
            t++;
        }
    }

    cout<< t<< endl;
}

Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int a[100009];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
    if(a[i]%4==0)a[i]=2;
    else if(a[i]%2==0)a[i]=0;
    else a[i]=1;
  }
  sort(a,a+n);
  reverse(a,a+n);
  int x=0,y=0;
  bool f=0;
  for(int i=0;i<n;i++){
    if(a[i]==1)x++;
    if(a[i]==2)y++;
    if(a[i]==0)f=true;
  }
  if(f==1)x++;
  if(y+1>=x)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return(0);
}


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

int main() {
    int x;
    cin>>x;
    if (x<1200) cout<<"ABC"<<endl;
    else cout<<"ARC"<<endl;
}


Measured memory_bytes: 256
//dp状态:dp(i,j)表示离第i个结点距离为j的结点的个数 
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

int n,in[2][21];
int res;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>in[0][i];
	}
	for(int i=0;i<n;i++){
		cin>>in[1][i];
	}
	res=0;
	for(int i=0;i<n;i++){
		if(in[0][i]>in[1][i]){
			res+=in[0][i]-in[1][i];
		}
	}
	cout<<res<<endl;
	return 0;
}

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

template <typename T> 
struct WeightedUnionFind{
  Int n;
  T d;
  vector<Int> r,p;
  vector<T> ws;
  WeightedUnionFind(){}
  WeightedUnionFind(Int sz,T d_):
    n(sz),d(d_),r(n,1),p(n),ws(n,d){iota(p.begin(),p.end(),0);}
  Int find(Int x){
    if(x==p[x]){
      return x;
    }else{
      Int t=find(p[x]);
      ws[x]+=ws[p[x]];
      return p[x]=t;
    }
  }
  T weight(Int x){
    find(x);
    return ws[x];
  }
  bool same(Int x,Int y){
    return find(x)==find(y);
  }
  void unite(Int x,Int y,T w){
    w+=weight(x);
    w-=weight(y);
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y),w=-w;
    r[x]+=r[y];
    p[y]=x;
    ws[y]=w;
  }
  T diff(Int x,Int y){
    return weight(y)-weight(x);
  }
};

//INSERT ABOVE HERE
signed main(){
  Int n,q;
  cin>>n>>q;
  WeightedUnionFind<Int> wuf(n,0);
  
  for(Int i=0;i<q;i++){
    Int t,x,y,z;
    cin>>t>>x>>y;
    //cout<<t<<":"<<x<<" "<<y<<endl;
    if(t){
      if(wuf.same(x,y)) cout<<wuf.diff(x,y)<<endl;
      else cout<<"?"<<endl;
    }else{
      cin>>z;
      wuf.unite(x,y,z);
    }
  }
  return 0;
}



Measured memory_bytes: 5208
#include <iostream>
#include <cmath>
#include <map>
#include <functional>
#include <algorithm>

#define SIZE 200000

using namespace std;

int main(void){
    int K, N;
    int a;
    int dif_a = 0;
    int cnt[SIZE] = {0};
    cin >> N >> K;
    for(int i=0; i<N; i++){
        cin >> a;
        cnt[a] += 1;
    }
    sort(cnt, cnt+N+1, greater<int>());
    int not_kakikae = 0;
    for(int i=0; i<K; i++){
        not_kakikae += cnt[i];
    }
    cout << N - not_kakikae;
    return EXIT_SUCCESS;
}

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

using namespace std;

#define int long long int
#define ld long double
#define F first
#define S second
#define P pair<int,int>
#define V vector
#define pb push_back
#define db(...) __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

const int N=100005;

int32_t main()
{
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    // int t;cin>>t;while(t--)
    {
        int i,j,k,n,m,ans=0,cnt=0,sum=0;
        int a,b,c;
        cin>>a>>b>>c>>n;
        for(i=0;i<=n;i++){
            for(j=0;j<=n;j++){
              if(i%a==0&&j%b==0&&(i+j)<=n&&(n-i-j)%c==0){
                ans++;
              }
            }        
        }
        cout<<ans;
    }
}

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

int main(){
  int a,b,c;
  
  cin >> a >> b >> c;
  
  if( a<c && c<b ) cout << "Yes" << endl;
  else if( b<c && c<a ) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
//Coded by tzc_wk
/*
数据不清空，爆零两行泪。
多测不读完，爆零两行泪。
边界不特判，爆零两行泪。
贪心不证明，爆零两行泪。
D P 顺序错，爆零两行泪。
大小少等号，爆零两行泪。
变量不统一，爆零两行泪。
越界不判断，爆零两行泪。
调试不注释，爆零两行泪。
溢出不 l l，爆零两行泪。
忘文件操作，爆零两行泪。
*/
#include <bits/stdc++.h>
using namespace std;
#define fi			first
#define se			second
#define fz(i,a,b)	for(int i=a;i<=b;i++)
#define fd(i,a,b)	for(int i=a;i>=b;i--)
#define foreach(it,v) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define all(a)		a.begin(),a.end()
#define giveup(...) return printf(__VA_ARGS__),0;
#define fill0(a)	memset(a,0,sizeof(a))
#define fill1(a)	memset(a,-1,sizeof(a))
#define fillbig(a)	memset(a,0x3f,sizeof(a))
#define fillsmall(a) memset(a,0xcf,sizeof(a))
#define mask(a)		(1ll<<(a))
#define maskx(a,x)	((a)<<(x))
#define _bit(a,x)	(((a)>>(x))&1)
#define _sz(a)		((int)(a).size())
#define filei(a)	freopen(a,"r",stdin);
#define fileo(a)	freopen(a,"w",stdout);
#define fileio(a) 	freopen(a".in","r",stdin);freopen(a".out","w",stdout)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define put(x)		putchar(x)
#define eoln        put('\n')
#define space		put(' ')
#define y1			y_chenxiaoyan_1
#define y0			y_chenxiaoyan_0
typedef pair<int,int> pii;
inline int read(){
	int x=0,neg=1;char c=getchar();
	while(!isdigit(c)){
		if(c=='-')	neg=-1;
		c=getchar();
	}
	while(isdigit(c))	x=x*10+c-'0',c=getchar();
	return x*neg;
}
inline void print(int x){
	if(x<0){
		putchar('-');
		print(abs(x));
		return;
	}
	if(x<=9)	putchar(x+'0');
	else{
		print(x/10);
		putchar(x%10+'0');
	}
}
inline int qpow(int x,int e,int _MOD){
	int ans=1;
	while(e){
		if(e&1)	ans=ans*x%_MOD;
		x=x*x%_MOD;
		e>>=1;
	}
	return ans;
}
int a[2],b[2];
signed main(){
	int cur=1;
	cin>>a[1]>>b[1]>>a[0]>>b[0];
	while(1){
		if(a[cur^1]-b[cur]<=0){
			if(cur==1)	puts("Yes");
			else		puts("No");
			break;
		}
		a[cur^1]-=b[cur];
		cur^=1;
	}
	return 0;
}

Measured memory_bytes: 3648
#include<iostream>
using namespace std;
int main (void)
{
  long long int a,b,c,n,ans;
  int i;
  cin>>n>>a>>b;
  c=0;
  i=0;
  ans=n/(a+b);
  ans=ans*a;
  //cout<<ans;
  
  if((n%(a+b))>a)ans+=a;
  else ans=ans+(n%(a+b));
  cout<<ans;
  
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
string alphabet="abcdefghijklmnopqrstuvwxyz";
int main(){
    int n;
    cin >> n;
    int a[n];
    int x = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        x ^= a[i];
    }
    for(int i = 0; i < n; i++)
        a[i] ^= x;
    for(int i = 0; i < n; i++)
        cout << a[i] << ' ';
    return 0;
}


Measured memory_bytes: 4368
#include <bits/stdc++.h>
typedef long long ll;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    char cc; 
    cin>>n;
    rep(i,n){
        cin>>cc;
        if(cc=='Y')ans=1;
    }
    if(ans==1)Cout("Four");
    else Cout("Three");
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
    int a,b,c;
    int j=0;
    scanf("%d %d %d",&a,&b,&c);
    for (int i=a;i<=b;i++){
        if (i%c==0){

            j++;
        }
    }
    printf("%d",j);

    return 0;
}

Measured memory_bytes: 1704
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define Rep(i, n) for (long long i = 0; i< (long long)(n); i++)
#define RRep(i,n) for (long long i = ((long long)(n)-1); i>=0; i--)
#define all(v) (v).begin(),(v).end()

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;

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

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

template <class T>
T gcd(T a, T b){
    if( b==0 ) return a;
    return gcd(b, a%b);
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

const int INF = 1e9+7;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

int main(){
    ll n;
    cin >> n;
    for(int i = 1; i<=3500; i++){
        for(int j = 1; j<=3500; j++){
            ll x = 4*i*j-n*i-n*j;
            ll y = n*i*j;
            if(x<=0) continue;
            if(y%x==0){
                ll ans = y/x;
                cout << i << " " << j << " " << ans << endl;
                return 0;
            }
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 256
n = int(input())
p = list(map(int,input().split()))
c = 0
for i in range(n-1):
    if p[i] == i+1:
        p[i],p[i+1] = p[i+1],p[i]
        c += 1
if p[n-1] == n:
    c += 1
print(c)

Measured memory_bytes: 13880
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <limits.h>
#include <assert.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <bitset>
#include <vector>
using namespace std;

#define LL long long

#define fi first
#define se second
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(a,b) (((a)+(b))>>1)
#define maxx(a,b) ((a)<(b)?(b):(a))
#define minx(a,b) ((a)<(b)?(a):(b))
#define absx(a) ((a)<0?-(a):(a))
#define mk(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define itr iterator
#define lowbit(x) ((x)&-(x))

typedef unsigned LL ULL;
typedef unsigned uint;
typedef map<int,int> mii;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<LL,LL> pLL;

template< typename T > inline void read(T &x) {
    bool f; char ch; f=0; x=0; ch=getchar();
    while(ch<'0' || ch>'9') {if(ch=='-') f=1; ch=getchar();}
    while(ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();}
    if(f) x=-x;
}

template< typename T > inline void Max(T &a, T b) {if(a<b) a=b;}
template< typename T > inline void Min(T &a, T b) {if(b<a) a=b;}
template< typename T > inline T Abs(T a) {if(a<0) return -a; else return a;}

const double pi=(double) acos(-1.0);
const int MOD=(int) 1e9+7;
const int INF=(int) 0x3f3f3f3f;
const LL  LINF=(LL) INF<<32|INF;
const int SINF=(uint) ~0>>1;
const LL  SLINF=(ULL) (-1)>>1;
const double DINF=(double) 1e50;
const double eps=(double) 1e-8;
const int maxn=(int) 3e5+20;
const int maxm=(int) 1e5+20;
const int maxk=(int) 5e2+20;

inline int sig(double x) {return x<-eps?-1:x>eps;}

//--------------start------------------

int n,k;
int ans[maxn],len;

void gao0()
{
    len=n;
    ans[0]=k/2;
    for(int i=1;i<len;i++) ans[i]=k;
}

void gao1()
{
    len=n;
    for(int i=0;i<len;i++) ans[i]=(k+1)/2;

    for(int i=0,p=len-1;i<n/2;i++)
    {
        if(ans[p])
        {
            ans[p]--;
        }
        else
        {
            ans[p-1]--;
            ans[p]=k;
            if(ans[p-1]) p=len-1;
            else p--;
        }

//        for(int i=0;i<len;i++) cout <<ans[i]; cout <<endl;
    }

    for(int i=len-1;~i;i--) if(ans[i]==0) len=i;
}

void work()
{
    read(k), read(n);

    if(k&1) gao1();
    else gao0();

    for(int i=0;i<len;i++)
    {
        if(i) putchar(' ');
        printf("%d",ans[i]);
    }
    putchar('\n');
}

//--------------end--------------------

int main()
{
#ifdef yukihana0416
freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
#endif // yukihana0416
    work();
    return 0;
}


Measured memory_bytes: 3456
n,m,x = map(int,input().split())
a = list(map(int,input().split()))
data = [0]*(n + 1)
cost_1 = 0
cost_2 = 0
for i in range(m):
    data[a[i]] = 1
for i in range(0,x):
    cost_1 += data[i]
for j in range(x,n):
    cost_2 += data[j]
print(min(cost_1,cost_2))

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

long long a[20];

long long dfs(int l, int r, int lx, int rx){
    if(l + 1 == r){
        return 0;
    }
    long long res = 200000000000000;
    for(int k = l+1; k < r; k++){
        res = min(res, dfs(l, k, lx, lx + rx) + dfs(k, r, lx + rx, rx) + a[k]*(lx+rx));
    }
    return res;
}

int main(){
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    cout << dfs(0, n-1, 1, 1) + a[0] + a[n-1] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n ,i,j,x,m,sum=1;
    cin>>n>>m;
    if(abs(n-m)>1){
        cout<<0<<endl;
        return 0;
    }
    for(i = 1 ;i<=n ;i++)
    {
        sum*=i;
        sum%=1000000007;
    }
    for(i = 1;i<=m ;i++)
    {
        sum*=i;
        sum%=1000000007;
    }
    if(n == m)
        sum= (sum*2)% 1000000007;
    cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;

ll fact(ll a){
    ll p = 1;
    while(a >= 2){
        p *= a--;
        p %= MOD;
    }
    return p;
}

int main(){
    int N, M;
    cin >> N >> M;
    if(N < M) swap(N, M);

    if(N == M){
        cout << (2 * fact(N) * fact(M)) % MOD << endl;
    }else if(N == M + 1){
        cout << (fact(N) * fact(M)) % MOD << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin >> n >> k;
    string s;
    cin >> s;
    int a[1001000] = {};
    int b = 0;
    int cnt = 1;
    for(int i = 1;i <= n;i++){
        if(s[i] != s[i-1] || i == n){
            a[b] = cnt;
            cnt = 1;
            b++;
        }
        else cnt++;
    }
    int l = (int)(s[0] - '0'),r = l;
    int now = 0,ans = 0;
    for(int i = 0;i < k;i++){
        now += a[r]+a[r+1];
        r += 2;
    }
    if(l == 1)now += a[0];
    //cout << "[" << l << ", " << r << "), " << now << endl;
    ans = now;
    while(true){
        now -= a[l];
        if(l-1 >= 0)now -= a[l-1];
        now += a[r];
        if(r+1 < b)now += a[r+1];
        
        l += 2, r += 2;
        
        //cout << "[" << l << ", " << r << "), " << now << endl;
        ans = max(now,ans);
        
        if(r >= b)break;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4352
import math
from fractions import gcd
n = int(input())
a = list(map(int, input().split()))
def lcm(x, y):
	return (x * y) // gcd(x, y)
b = a[0]
for i in a[1:]:
	b = lcm(b,i)

c = 0
for i in a:
	c += b//i
ans = b/c
print (ans)

Measured memory_bytes: 5048
loop {
	n = gets.to_i
	break if n == 0

	schedule = Array.new(30,0)
	(0..n-1).each{|i|
		gets.split(/\s+/).map(&:to_i)[1..-1].each{|day|
			schedule[day-1] |= (1 << i)
		}
	}

	x_day = -1
	(0..29).each{|d1|
		gathered = schedule[d1]
		(d1-1).downto(0){|d2|
			members = schedule[d2]
			gathered |= members if gathered & members > 0
		}
		if gathered + 1 == (1 << n)
			x_day = d1 + 1
			break
		end
	}

	puts x_day
}

Measured memory_bytes: 6148
#!/usr/bin/env python3
import sys
import itertools


def solve(N: int, M: int, P: "List[int]", Y: "List[int]"):

    L = []
    R = [""] * M
    for p,y,i in zip(P,Y,range(M)):
        L.append((i,p,y))
    L.sort(key=lambda x: x[1]*10**10+x[2])

    for k,g in itertools.groupby(L,key=lambda x: x[1]):
        for i,gg in enumerate(g):
            R[gg[0]] = str(gg[1]).zfill(6) + str(i+1).zfill(6)

    for r in R:
        print(r)




# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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
    P = [int()] * (M)  # type: "List[int]" 
    Y = [int()] * (M)  # type: "List[int]" 
    for i in range(M):
        P[i] = int(next(tokens))
        Y[i] = int(next(tokens))
    solve(N, M, P, Y)

if __name__ == '__main__':
    main()


Measured memory_bytes: 30700
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
int main()
{
    int N;
    std::cin >> N;
    std::vector<int> as{};
    for (int i = 0; i < N; i++) {
        int a;
        std::cin >> a;
        as.emplace_back(a);
    }
    std::sort(as.begin(), as.end());

    auto max_itr = std::max_element(as.begin(), as.end());
    int max = *max_itr;
    as.erase(max_itr);
    auto min_itr = std::min_element(as.begin(), as.end());
    int min = *min_itr;
    as.erase(min_itr);

    std::vector<int> ans{{min, max}};
    for (int i = 0; i < N - 2; i++) {
        int max_diff = -1;
        int choice = -1;  // 0~3
        if (std::abs(as.at(as.size() - 1) - ans.at(0)) > max_diff) {
            max_diff = std::abs(as.at(as.size() - 1) - ans.at(0));
            choice = 0;
        }
        if (std::abs(as.at(as.size() - 1) - ans.at(ans.size() - 1)) > max_diff) {
            max_diff = std::abs(as.at(as.size() - 1) - ans.at(ans.size() - 1));
            choice = 1;
        }
        if (std::abs(as.at(0) - ans.at(0)) > max_diff) {
            max_diff = std::abs(as.at(0) - ans.at(0));
            choice = 2;
        }
        if (std::abs(as.at(0) - ans.at(ans.size() - 1)) > max_diff) {
            max_diff = std::abs(as.at(0) - ans.at(ans.size() - 1));
            choice = 3;
        }

        if (choice == 0) {
            ans.insert(ans.begin(), as.at(as.size() - 1));
            as.erase(as.begin() + as.size() - 1);
        } else if (choice == 1) {
            ans.emplace_back(as.at(as.size() - 1));
            as.erase(as.begin() + as.size() - 1);
        } else if (choice == 2) {
            ans.insert(ans.begin(), as.at(0));
            as.erase(as.begin() + 0);
        } else if (choice == 3) {
            ans.emplace_back(as.at(0));
            as.erase(as.begin() + 0);
        }
    }

    unsigned long long result = 0;
    for (int i = 0; i < N - 1; i++) {
        result += std::abs(ans.at(i) - ans.at(i + 1));
    }
    std::cout << result << std::endl;

    return 0;
}

Measured memory_bytes: 1528
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

ll snuke(ll n){
    ll k = 0;
    for (auto &&i : to_string(n)) {
        k += i - '0';
    }
    return k;
}

ll f(ll n){
    ll ans = n+1;
    string s = to_string(ans);
    string t = s;
    for (int i = s.length()-1; i >= 0; --i) {
        while(t[i] != '9') {
            t[i]++;
            ll m = stoll(t), x = ans * snuke(m), y = m * snuke(ans);
            if (x > y) {
                ans = m;
            }
        }
    }
    return ans;
}
int main() {
    vector<ll> v{1};
    ll inf = 1000000000000001;
    ll x = 1;
    while(x < inf){
        x = f(x);
        v.emplace_back(x);
    }
    int k;
    cin >> k;
    for (int i = 0; i < k; ++i) {
        cout << v[i] << "\n";
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {



		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int Y = scanner.nextInt();


		String a = "-1";
		String b = "-1";
		String c = "-1";


		for(int i = 0; i <= N; i++) {
			for(int j = 0; i + j <= N; j++) {
				int need_c = N - i - j;
				int temporary_result = 10000*i + 5000*j + 1000*need_c;
				if(temporary_result == Y) {
					a = String.valueOf(i);
					b = String.valueOf(j);
					c = String.valueOf(need_c);
					break;
				}
			}
		}

		System.out.println(a + " " + b + " " + c);
	}

}


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

//短縮
#define rep(i,n) for(int i=0;i<(n);++i)
//sort()用
#define all(v) v.begin(), v.end()

#define PB(N) push_back(N)

using namespace std;

using Graph = vector<vector<int>>;

int main(){
  int N;cin >> N;
  int k=0;
  rep(i,8){
    if(N<400)break;
    N-=200;
    k=i;
  }
  cout << 8-k <<endl;
  return 0;
}


Measured memory_bytes: 3668
#include <iostream>
#include <set>
#include <string>

int main() {
    std::string s;
    std::cin >> s;
    
    const std::set<char> string_set(s.cbegin(), s.cend());

    std::string ret = "None";
    for (char x = 'a'; x <= 'z'; ++x) {
        if (string_set.find(x) == string_set.cend()) {
            ret = x;
            break;
        }
    }

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


Measured memory_bytes: 512
//QWsin
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,x,y) for(int i=x;i<=y;++i)
#define out(i,u) for(int i=first[u];i!=-1;i=nxt[i])
#define repvc(i,vc) for(int i=0,Sz=vc.size();i<Sz;++i)
using namespace std;
inline int read()
{
	char ch=getchar();int ret=0,f=1;
	while(ch<'0' || ch>'9') {if(ch=='-')f=-1;ch=getchar();}
	for(;ch>='0' && ch<='9';ch=getchar()) ret=ret*10+ch-'0';
	return ret*f;
}

inline void print(string name,int *arr,int len){
	rep(i,1,len) printf("%s[%d]=%d\n",name.c_str(),i,arr[i]);puts("");
}
inline void print(string name,int a){
	printf("%s=%d\n",name.c_str(),a);puts("");
}

typedef long long ll;
const int INF=1<<30;

const int maxn=100000+10;
const int maxm=100000+10;

struct Edge{int u,v;Edge(int u=0,int v=0):u(u),v(v){}}e[maxm];
int first[maxn],nxt[maxm],ecnt;

void add_edge(int u,int v){
	nxt[ecnt]=first[u];first[u]=ecnt;e[ecnt++]=Edge(u,v);	
}

int ind[maxn],fa[maxn];

int main()
{
	int n,m;cin>>n>>m;
	rep(i,1,n) first[i]=-1;
	rep(i,1,n-1+m)
	{
		int u=read(),v=read();
		add_edge(u,v);	
		++ind[v];
	}
	
	queue<int>q;
	rep(i,1,n) if(!ind[i]) q.push(i);
	
	while(!q.empty())
	{
		int u=q.front();q.pop();
		out(i,u)
		{
			int v=e[i].v;
			if(--ind[v]==0)
			{
				fa[v]=u;
				q.push(v);
			}
		}
	}
	
	rep(i,1,n) printf("%d\n",fa[i]);
	return 0;
}




Measured memory_bytes: 3584
#include<stdio.h>
#define NotFound -1
#define Found 1
int search(int *a,int n,int keyword);
int main()
  {
    int num1,num2,i,A[10001],keyword,sum=0;
    scanf("%d",&num1);
    for(i=0;i<num1;i++){
      scanf("%d",&A[i]);
    }
    scanf("%d",&num2);
    for(i=0;i<num2;i++){
      scanf("%d",&keyword);
      if(search(A,num1,keyword)==Found)sum++;
    }
    printf("%d\n",sum);

    return 0;
  }

int search(int *a,int n,int keyword){
  int i=0;
  a[n]=keyword;
  while(a[i]!=keyword)i++;
  if(i==n)return NotFound;
  else return Found;
}

Measured memory_bytes: 636
from itertools import permutations

N = int(input())
dist = [list(map(int, input().split())) for _ in range(N)]

ans = []
for case in permutations([i for i in range(N)]):
    total = 0
    for i in range(len(case)-1):        
        total += ((dist[case[i]][0]-dist[case[i+1]][0])**2 + (dist[case[i]][1]-dist[case[i+1]][1])**2)**(1/2)
    ans.append(total)

print(sum(ans)/len(ans))

Measured memory_bytes: 4376
#include <vector>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <iostream>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

const double PI = 3.141592653589793;

double toDegree(double rad) {
  return rad * (180 / PI);
}


int main() {
  double a, b, x;
  cin >> a >> b >> x;
  double A = x / a;
  if (A >= a * b / 2) {
    double h = (a * b - A) * 2 / a;
    double ans = toDegree(atan2(h, a));
    printf("%.10f\n", ans);
  } else {
    double w = A * 2 / b;
    double ans = toDegree(atan2(b, w));
    printf("%.10f\n", ans);
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    lint A, B, K;
    cin >> A >> B >> K;
    lint t = min(A, K);
    A -= t;
    K -= t;

    t = min(B, K);
    B -= t;
    K -= t;
    cout << A << " " << B << endl;
    return 0;
};

Measured memory_bytes: 256
#普通にソートしてから、配列のK個づつ区切ってパターンを調べればN - K + 1回の比較で行ける

N, K = map(int, input().split())
h = [int(input()) for _ in range(N)]
h.sort()

distances = [h[i + K -1] - h[i] for i in range(N -K + 1)]
ans = min(distances)
print(ans)

Measured memory_bytes: 17096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=200005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    if(N%1000==0) cout<<0<<endl;
    else cout<<1000-N%1000<<endl;
}


Measured memory_bytes: 3636
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main(){
  ll mod = 1000000007LL;
  int N;
  cin >> N;
  vector<int> A(N);
  ll sum = 0;
  for (int i=0; i<N; i++) {
    cin >> A[i];
    sum += A[i];
  }
  ll ans = 0;
  sum -= A[0];
  for (int i=0; i<N-1; i++) {
    ans = (ans + ((A[i]) * (sum%mod))%mod)%mod;
    sum -= A[i+1];
  }
  cout << ans << endl;
}


Measured memory_bytes: 4032
#include<stdio.h>
int main(void){
	int i,j,s,t;
	int H[300],W[300];
	for(s=0;s<300;s++){
		scanf("%d %d",&H[s],&W[s]);
		if(H[s]==0&&W[s]==0){
			break;
		}
	}
	for(t=0;t<s;t++){
		for(i=0;i<H[t];i++){
			for(j=0;j<W[t];j++){
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  while(1){
    cin >> n;
    if(n == 0) break;
    int count = 0;
    string back;
    for(int i=0; i<n; i++){
      string s;
      cin >> s;
      if(s == "lu" && back == "ru") count++;
      if(s == "ru" && back == "lu") count++;
      if(s == "ld" && back == "rd") count++;
      if(s == "rd" && back == "ld") count++;
      back = s;
    }
    cout << count << endl;
  }
  return 0;
}



Measured memory_bytes: 3156
def cmb(n, r, mod):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % mod

N = int(input())
mod = (10 ** 9) + 7
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % mod)
    inv.append((-inv[mod % i] * (mod // i)) % mod)
    factinv.append((factinv[-1] * inv[-1]) % mod)

count = 0
L = N // 3
for i in range(L):
  num = i + 1
  left = N - 3*num
  if left == 0:
    count += 1
  else:
    count += cmb(left+i, i, mod)
print(count % mod)

Measured memory_bytes: 65608
#include <cstdio>

using namespace std;

int n, d1, d2, n1, n2;

int main(){
	scanf("%d%d%d", &n, &d1, &d2);
	n1 = n2 = 0;
	
	while (d1 % (1 << (n1 + 1)) == 0) n1++;
	while (d2 % (1 << (n2 + 1)) == 0) n2++;
	int c = 0;
	
	for (int i = 0; i < 2 * n && c < n * n; i++){
		for (int j = 0; j < 2 * n && c < n * n; j++){
			if ((n1 % 2 == 0 ? (i >> (n1 / 2)) % 2 == (j >> (n1 / 2)) % 2:(i >> (n1 / 2)) % 2 == 0)
	 		  &&(n2 % 2 == 0 ? (i >> (n2 / 2)) % 2 == (j >> (n2 / 2)) % 2:(i >> (n2 / 2)) % 2 == 0)){
					printf("%d %d\n", i, j); c++;
				}
		}
	}
	
	return 0;
}

Measured memory_bytes: 896