akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N;
    cin >> N;
    int value[N];
    int cost[N];
    int ans = 0;
    
    for(int i = 0; i < N; i++){
        cin >> value[i];
    }
    for(int i = 0; i < N; i++){
        cin >> cost[i];
    }
    for(int i = 0; i < N; i++){
        if( value[i] - cost[i] > 0) {
            ans += value[i] - cost[i];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll i,j,k;

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

    int ans=0,unhappy=0;
    for(i=0;i<n-1;i++){
        if(s[i]==s[i+1]){ans++;}//最初の状態で幸福な人の数
        else if((i==0 && s[i]=='l')||(i==n-1 && s[i]=='r')||(s[i]!=s[i+1])){unhappy++;}//同じ向きでない　または　端　　の数(境界の数)
    }

    if(2*k>=unhappy){cout<<n-1<<endl;}
    else{cout<<(ans+2*k)<<endl;}

    return 0;
}

Measured memory_bytes: 512
n, k = map(int,input().split())
mod = 10**9+7
ans = 0

for i in range(k,n+2):
    num = ((n*(n+1)-(n-i+1)*(n-i)-(i-1)*i)//2+1)%mod
    ans = (ans+num)%mod

print(ans)


Measured memory_bytes: 9180
#include<iostream>
  #include<math.h>
  using namespace std;

  bool Prime_Numbers(size_t num){

       if(num == 2) return true;
      else if(num %2 == 0) return false;

      size_t sqrtNum = sqrt(num);
      for(size_t i=3 ;i<=sqrtNum ; i++){
        if(num% i == 0){
          return false;
        }
      }
      return true;

    }


    int main(){
      size_t num;
      size_t count=0;

      cin>> num;
      size_t vec[num];
      for(size_t i=0; i< num; i++ ){
        cin>> vec[i];
        if(Prime_Numbers(vec[i])== true){
          count++;
        }
      }

      cout<< count << endl;


      return 0;
    }



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
 ll a,b,c;
  cin>>a>>b>>c;
  if(a+b+c>=22){
cout<<"bust"<<endl;
  }
  else{
    cout<<"win"<<endl;
  }
}


Measured memory_bytes: 3628
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
const ll inf = 1LL << 62;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

template <typename T> inline void voutput(T &v){
    rep(i, v.size()){
        if (i) cout << " " << v[i];
        else cout << v[i];
    }
    cout << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N;
    ll D, A;
    cin >> N >> D >> A;
    vector<pair<ll, ll>> XH(N);
    rep(i, N) cin >> XH[i].first >> XH[i].second;
    sort(all(XH));
    vector<ll> cnt(N);
    int left = 0;
    ll cum = 0;
    rep(i, N) {
        while(XH[left].first + D * 2 < XH[i].first) {
            cum -= cnt[left];
            left++;
        }
        if(cum * A < XH[i].second) {
            cnt[i] = (XH[i].second - cum * A + A - 1) / A;
            cum += cnt[i];
        }
    }
    
    ll ans = 0;
    rep(i, N) ans += cnt[i];
    output(ans);
    
    return 0;
}


Measured memory_bytes: 4992
#include<iostream>
#include<cstring>
using namespace std;
char a[105],b[105],c[105];
int lena,lenb,lenc;
int check(char tmp){
	if(lena==0 && tmp=='a'){
		cout<<"A";
		return 0;
	}
	else if(lenb==0 && tmp=='b'){
		cout<<"B";
		return 0;
	}
	else if(lenc==0 && tmp=='c'){
		cout<<"C";
		return 0;
	}
	return -1;
}
int main(){
	cin>>a>>b>>c;
	lena=strlen(a);
	lenb=strlen(b);
	lenc=strlen(c);
	int a_i=0,b_i=0,c_i=0;
	char tmp='a';
	while(true){
		if(check(tmp)!=-1) break;
		if(tmp=='a'){
			tmp=a[a_i++];
			--lena;
			if(check(tmp)!=-1)	break;
		}
		if(tmp=='b'){
			tmp=b[b_i++];
			--lenb;
			if(check(tmp)!=-1)	break;
		}
		if(tmp=='c'){
			tmp=c[c_i++];
			--lenc;
			if(check(tmp)!=-1)	break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n=2;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    if(a[0]!=1)
        cout<<"1";
    else if(a[1]!=2) cout<<"2";
    else cout<<"3";
}


Measured memory_bytes: 3572
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    ll cnt[5] = {};
    rep(i,0,N){
        string s;
        cin >> s;
        string str = "MARCH";
        rep(j,0,5){
            if(s[0] == str[j]){
                cnt[j]++;
            }
        }
    }
    /*
    rep(i,0,5){
        cout << cnt[i] << endl;
    }
    */
    ll ans = 0;
    rep(i,0,5)rep(j,i+1,5)rep(k,j+1,5){
        ans += cnt[i] * cnt[j] * cnt[k];
    }
    cout << ans << endl;
}

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

int main(){
  long long int N,C;
  cin >> N >> C;
  double K;
  cin >> K;
  
  vector<double> A(N,0.0);
  
  for(long long int i = 0LL ; i < N; i++){
     cin >> A[i];
  }
  sort(A.begin(), A.end(), greater<long long int>());
  long long int p = 1LL;
  long long int b = 1LL;
  double dep = A[0];
  for(long long int i = 0LL ; i < N-1; i++){
     if(p == C || A[i+1] < dep - K){
       b++;
       dep = A[i+1];
       p = 1LL;
       continue;
     }
    p++;
  }
  cout << b;
}




Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795L
#ifndef DEBUG
#define debug(args...)
#else
#include "debug.h"
#endif
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
map<pll, ll> m; set<pll> u; ll zz=0;
inline ll fexp(ll b, ll e) {
  if (e==0) return 1;
  if (e==1) return b;
  ll r=fexp(b, e/2ll);
  r=(r*r)%MOD;
  if (e%2) r*=b, r%=MOD;
  return r;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
#ifdef DEBUG
  freopen("inp.txt", "r", stdin);
#endif
  int n;
  cin>>n;
  for (int i=0;i<n;i++) {
    ll a, b;
    cin>>a>>b;
    if (a==0&&b==0) {
      zz++;
      continue;
    }
    ll d=gcd(abs(a), abs(b));
    a/=d, b/=d;
    if (a<0||(a==0&&b<0)) {
      a=-a, b=-b;
    }
    m[{a,b}]++;
  }
  ll res=1;
  for (auto it=m.begin();it!=m.end();++it) {
    if (u.count(it->first)) continue;
    u.insert(it->first);
    ll x1=it->first.first, y1=it->first.second, cnt=it->second;
    ll x2=-y1, y2=x1;
    if (x2<0||(x2==0&&y2<0)) {
      x2=-x2, y2=-y2;
    }
    pll t={x2,y2};
    if (m.count(t)) {
      ll ad=fexp(2,cnt)+fexp(2,m[t])-1; ad%=MOD;
      res*=ad, res%=MOD;
      u.insert(t);
    } else {
      res*=fexp(2,cnt), res%=MOD;
    }
  }
  cout<<((res+zz-1)%MOD+MOD)%MOD<<'\n';
  return 0;
}


Measured memory_bytes: 28540
#include <stack>
#include <queue>
#include <cstdio>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
 
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n0,n) for(int i=n0;i<n;i++)
#define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<n;j++)
#define INF (1<<29)
 
int main (){
	long NN, KK;
	long length = 0;
	long length2 = 0;
	long ans = 0;
	cin >> NN >> KK;
	if (KK ==1){
		ans = NN * NN * NN;
	}else if(KK % 2 == 1){
		length = (NN-NN%KK)/KK;
		ans = length * length * length;
	}else {
		length = (NN-NN%KK)/KK;
		length2 = (NN-NN%(KK/2))/(KK/2) - length ;
		ans = length * length * length + length2 * length2 * length2;
	}
	cout  << ans << endl;
	return 0;	
}

Measured memory_bytes: 256
def read_int():
    return int(input())

def read_int_map():
    return map(int,input().split(' '))

def read_int_list():
    return list(map(int,input().split(' ')))

def read_s_list_loop(n):
    return [input() for _ in range(n)]

def bit_cal(n):
    return_list = ['']* (2 ** n)
    for i in range(2 ** n):
        for j in range(n):
            if ((i >> j) & 1):
                return_list[i] = return_list[i] + '1'
            else:
                return_list[i] = return_list[i] + '0'
    return return_list

N,M,X = read_int_map()
Cn = [list(read_int_map()) for _ in range(N) ]

ans = float('inf')
bit_list = bit_cal(N)
for bit in bit_list:
    m_list = [0]*M
    price = 0
    for i in range(N):
        if bit[i] == '1':
            price += Cn[i][0]
            for j in range(1,M+1):
                m_list[j-1] += Cn[i][j]
    flag = True
    for m in m_list:
        if m < X:
            flag = False
            break
    if flag:
        ans = min(price,ans)
if ans == float('inf'):
    print(-1)
else:
    print(ans)

Measured memory_bytes: 68800
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=998244353 ;
#define PI 3.141592653589793



int main(){
  int N; cin >> N; ll a[N]; int pla = 0;
  rep(i, N){
    cin >> a[i]; if(a[i]>=0) pla++;
  }
  if(pla==0) pla=1;
  if(pla==N) pla=N-1;
  sort(a, a+N, greater<>());
  ll ans = 0;
  rep(i, pla){
    ans+=a[i];
  }
  for(int i=pla; i<N; i++){
    ans-=a[i];
  }
  cout << ans << endl;
  ll x = a[N-1];
  rep(i, pla-1){
    cout << x << " " << a[i] << endl;
    x-=a[i];
  }
  ll xx = a[pla-1];
  rep(i, N-pla-1){
    cout << xx << " " << a[pla+i] << endl;
    xx-=a[pla+i];
  }
  cout << xx << " " << x << endl;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ll N, T;
    cin >> N >> T;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    vector<ll> B(N);
    ll maxv = 0;
    for (int i = N - 1; i >= 0; i--) {
        B[i] = maxv;
        maxv = max(maxv, A[i]);
    }
    vector<ll> gap(N);
    for (int i = 0; i < N; i++) {
        gap[i] = B[i] - A[i];
    }
    ll m = *max_element(gap.begin(), gap.end());
    ll c = count(gap.begin(), gap.end(), m);
    cout << c << endl;
}

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

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

    swap(n, m);

    vector<ll> arr(n), delta;

    for (int i = 0; i < n; i++) cin >> arr[i];

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

    for (int i = 1; i < n; i++) {
        delta.push_back(arr[i] - arr[i-1]);
    }

    if (n <= m) {
        cout << 0 << endl;
        return 0;
    }

    sort(delta.begin(), delta.end());
    
    ll max_x = arr.back() - arr.front(), max_delta = 0;
    for (int i = 0; i < m-1; i++) {
        max_delta += delta.back();
        delta.pop_back();
    }

    cout << max_x - max_delta << endl;
    return 0;
}


Measured memory_bytes: 4992
from collections import defaultdict
from itertools import accumulate
import heapq
n,m,s,t=map(int, input().split())
s-=1
t-=1
yen={}
snk={}
adj=defaultdict(list)
for _ in range(m):
    u,v,a,b=map(int, input().split())
    u-=1    
    v-=1    
    adj[u].append(v)
    adj[v].append(u)
    yen[(u,v)]=a
    yen[(v,u)]=a
    snk[(u,v)]=b
    snk[(v,u)]=b

def dijkstra(s, t, cost):
    q=[]
    d=[float('inf')]*n
    d[s]=0
    heapq.heappush(q, (d[s], s))
    prev={}
    while q!=[]:
        du, u=heapq.heappop(q)
        for v in adj[u]:
            if d[v]>du+cost[(u,v)]:
                d[v]=du+cost[(u,v)]
                prev[v]=u
                
                heapq.heappush(q, (d[v], v))
    return d

d1=dijkstra(s, t, yen)
d2=dijkstra(t, s, snk)
snuke=[]
for d1i, d2i in zip(d1,d2):
    snuke.append(d1i+d2i)
ans=list(accumulate(reversed([y+s for y,s in zip(d1, d2)]), min))
for ai in reversed(ans):
    print(10**15-ai)


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

namespace C
{
    class Program
    {
        static long Solve2(int N, int A, int[] x)
        {
            var X = Math.Max(x.Max(), A);
            var dp = new long[N + 1, N + 1, N*X + 1];

            for (int j = 0; j < N+1; j++)
            {
                for (int k = 0; k < N+1; k++)
                {
                    for (int s = 0; s < N*X+1; s++)
                    {
                        if (j == 0 && k == 0 && s == 0)
                        {
                            dp[j, k, s] = 1;
                        }else if (j >= 1 && s < x[j])
                        {
                            dp[j, k, s] = dp[j - 1, k, s];
                        }else if (j >= 1 && k >= 1 && s >= x[j])
                        {
                            dp[j, k, s] = dp[j - 1, k, s] + dp[j - 1, k - 1, s - x[j]];
                        }
                        else
                        {
                            dp[j, k, s] = 0;
                        }
                    }
                }
            }
            var sum = 0L;
            var k2 = 1;
            while (k2 <= N && k2*A <= N*X)
            {
                sum += dp[N,k2,k2*A];
                k2++;
            }

            return sum;
        }

        static long Solve(int N, int A, int[] x)
        {
            var X = Math.Max(x.Max(), A);
            var dp = new long[N + 1, 2 * N * X + 1];
            var y = new int[x.Length];
            for (int i = 0; i < x.Length; i++)
            {
                y[i] = A - x[i];
            }

            for (int j = 0; j < N + 1; j++)
            {
                for (int t = 0; t < 2*N*X + 1; t++)
                    if (j == 0 && t == N*X)
                    {
                        dp[j, t] = 1;
                    }
                    else if (j >= 1 && (t - y[j - 1] < 0 || t - y[j - 1] > 2*N*X))
                    {
                        dp[j, t] = dp[j - 1, t];
                    }
                    else if (j >= 1 && 0 <= t - y[j - 1] && t - y[j - 1] <= 2*N*X)
                    {
                        dp[j, t] = dp[j - 1, t] + dp[j - 1, t - y[j - 1]];
                    }
                    else
                    {
                        dp[j, t] = 0;
                    }
            }
            return dp[N, N * X] - 1;


        }

        static void Main(string[] args)
        {
            var buff = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var N = buff[0];
            var A = buff[1];
            var x = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var ans = Solve(N, A, x);
            Console.WriteLine(ans);

        }
    }
}


Measured memory_bytes: 4824
package main

import (
	"fmt"
	"sort"
)

func scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}

func main() {
	a := 0
	b := 0
	var n int
	fmt.Scan(&n)
	nums := scanNums(n)
	sort.Sort(sort.Reverse(sort.IntSlice(nums)))
	for i := 0; i < len(nums); i++ {
		if i%2 == 0 {
			a += nums[i]
		} else {
			b += nums[i]
		}
	}
	fmt.Println(a - b)
}


Measured memory_bytes: 512
// Given an array of integers of size ‘n’.
// Our aim is to calculate the maximum sum of ‘k’
// consecutive elements in the array.

/*{{{*/
#include<bits/stdc++.h>
#define sz(X) ((int)(X).size())
#define all(X) (X).begin(), (X).end()
#define rep(I, A, B) for (int I = (A); I <= (B); ++I)
#define repr(I, A, B) for (int I = (A); I >= (B); --I)
#define fors(I, S) for (int I = 0; S[I]; ++I)
#define get_pos(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define mp make_pair
#define pb emplace_back
#define ms0(X) memset((X), 0, sizeof((X)))
#define ms1(X) memset((X), -1, sizeof((X)))
#define len(X) strlen(X)
#define in insert
#define cn count
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef set<int> si;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T, class U> void _W(const pair<T, U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
#define DEBUG(...) {printf("[DEBUG] ");W(__VA_ARGS__);}
#else
#define DEBUG(...)
#endif
int MOD = 1e9 + 7;
/*}}}*/

const int SIZE = 1e6 + 10;

void solve() {
	ll a, b;
	R(a, b);
	if (__gcd(a, b) == 1)
		W(a * b);
	else
		W(a * b / __gcd(a, b));
}

int main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

#define MULTITEST 0
#if MULTITEST
	CASET {
		solve();
	}
#else
	solve();
#endif
	return 0;
}


Measured memory_bytes: 3608
#include <stdio.h>
#include <math.h>
#include <vector>
#include <utility>

using namespace std;

#define lli long long int
#define ll pair<lli, lli>
#define pb push_back
#define mp make_pair

int main() {
	lli n, p, divisor = 2, cnt, gcd = 1, akar;
	vector<ll> hasil;
	scanf("%lld %lld", &n, &p);
	while (p > 1) {
		akar = sqrt(p);
		if (divisor > akar)
			break;
		cnt = 0;
		while (p % divisor == 0) {
			cnt++;
			p /= divisor;
		}
		if (cnt > 0)
			hasil.pb(mp(cnt, divisor));
		divisor++;
	}
	if (p > 1)
		hasil.pb(mp(1, p));
	for (lli i = 0; i < (lli) hasil.size(); i++)
		for (lli j = 0; j < (lli) (hasil[i].first / n); j++)
			gcd *= hasil[i].second;
	printf("%lld\n", gcd);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define ld double
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define pll pair <ll,ll>
#define nl "\n"
 
int main()
{
	ios_base::sync_with_stdio(false);
	ll d,t,s;
	cin>>d>>t>>s;
	if(s*t>=d)
		cout<<"Yes\n";
	else
		cout<<"No\n";
	return 0;
}

Measured memory_bytes: 3648
#include <stdio.h>
  
int G[100][100],d[100],v[100];
int MST(int);
  
int MST(int n){
  int i,j,k=1,min,minp,sum=0;
    
  d[0]=0;
  v[0]=1;
  
  for(i=1;i<n;i++) v[i]=0;
  
  while(1){
    min = 2001;
    for(i=0;i<k;i++){
      for(j=0;j<n;j++){
    if(G[d[i]][j]<min && G[d[i]][j] != -1 && v[j] != 1){
      min = G[d[i]][j];
      minp = j;
    }
      }
    }
      
    if(k==n) break;
    d[k] = minp;
    v[minp] = 1;
    sum += min;
    k++;
  }
  
  return sum;
}

int main(){
  int num,i,j;
    
  scanf("%d",&num);
  
  for(i=0;i<num;i++){
    for(j=0;j<num;j++){
      scanf("%d",&G[i][j]);
    }
  }
  printf("%d\n",MST(num));
  
  return 0;
}
  

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

long long N, K, b, i, r, m, n, a[20], f[20];

main(){
    scanf("%d%d", &N, &K);
    for(i = 0; i < N; ++i){
        scanf("%d", a + i);
        f[i] = (i < K);
    }
    n = 1LL << 40;
    do{
        r = 0;
        m = *a;
        for(i = 1; i < N; ++i){
            if(m >= a[i]){
                if(f[i]){
                    ++m;
                    r += m - a[i];
                }
            }else{
                m = a[i];
            }
        }
        n = min(r, n);
    }while(prev_permutation(f, f + N));
    cout << n << endl;
    return 0;
}


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

using ull = unsigned long long;
constexpr int MAXN = 1e2 + 1;
constexpr int MAXW = 1e5 + 1;
int w[MAXN], v[MAXN];
ull table[MAXN][MAXW];

// table[i][j]: maximum value after considering ith item when j weight was available.

int main(void)
{
    int N, W;
    cin >> N >> W;

    for (int i = 1; i <= N; i++)
        cin >> w[i] >> v[i];

    for (int i = 1; i <= N; i++)
        for (int j = 1; j <= W; j++)
        {
            if (w[i] > j) // can't take
                table[i][j] = table[i - 1][j];
            else
                table[i][j] = max(table[i - 1][j],                // don't take
                                  table[i - 1][j - w[i]] + v[i]); // take
        }

    cout << table[N][W] << "\n";
}

Measured memory_bytes: 78336
#include <cstdio>

using namespace std;

long long p[100001];

int main()
{
  unsigned int n, q;
  unsigned long long k;

  scanf("%d %lld %d", &n, &k, &q);

  for (int i = 0; i < q; i++) {
    unsigned int a;
    scanf("%d", &a);
    p[a - 1]++;
  }

  for (int i = 0; i < n; i++) {
    if ((long long)k - (long long)q + p[i] > 0)
      printf("Yes\n");
    else
      printf("No\n");
  }

  return 0;
}

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


long long X, K, D;

void read() {
    cin >> X >> K >> D;
}


void work() {
    if (K > llabs(X) / D) {
        if ((K - llabs(X) / D) % 2 == 0) {
            cout << llabs(X) % D << endl;
        } else {
            cout << D - llabs(X) % D << endl;
        }
    } else {
        cout << llabs(X) - K * D << endl;
    }
}


int main() {
    read();
    work();
    return 0;
}


Measured memory_bytes: 3576
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;// ;//1000000000 + 7 998244353 924844033 1000000000 + 9;
constexpr long long INF = numeric_limits<LL>::max();
constexpr long long DINF = 1000000000000;
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
struct Edge { LL to, cost; };
struct edge {
	LL from, to, cost;
};
vector<vector<Edge>>g;
vector<edge>ed;
vector<Pll>pv;
map<LL, LL>ma;
set<LL>st;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
LL n, m, k, p, q, w, h, ans, cnt, sum[310000], a[310000];
Pll b[310000], c[310000];
string str;
bool f;
//char c[1100][1100];
int main() {
	cin >> n >> m;
	rep(i, n) {
		cin >> b[i].fir;
		b[i].sec = 1;
	}
	rep(i, m) {
		cin >> b[i+n].sec >> b[i+n].fir;
	}
	sort(b,b+n+m);
	LL num = n;
	Rrep(i, n+m) {
		if (num > b[i].sec) {
			ans += b[i].fir*b[i].sec;
			num -= b[i].sec;
		}
		else {
			ans += b[i].first*num;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4352
N = int(input())
S = list(input())
d = []


i = 0
while i < N - 1:
	if S[i] == S[i + 1]:
		d.append(2)
		i += 1
	else:
		d.append(1)
	i += 1

if N - 1 - i == 0:
	d.append(1)
n = len(d)

if d[0] == 1:
	dp = 3
else:
	dp = 6

for i in range(n - 1):
	if d[i] == 1:
		dp = dp * 2
	elif d[i] == 2 and d[i + 1] == 2:
		dp = dp * 3
	else:
		pass
	dp = dp % 1000000007

print(dp)



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

#define fo1(i, n) for (int i = 0; i < n; i++)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int((x).size())
using ll = long long; using vi = vector<int>; using ii = pair<int,int>;
const int oo = 0x3f3f3f3f; const ll OO = ll(oo)*oo; const int N = 1005;
#ifndef DEBUG
#define endl '\n'
#define debugf(...)
#else
#define debugf(...) printf(__VA_ARGS__)
#endif

int dp[1<<12];

int unlocks[N];
int cost[N];

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

  int n, m;
  cin >> n >> m;

  rep(i, 1, m+1) {
    int a, b; cin >> a >> b;
    cost[i] = a;
    fo1(j, b) {
      int c; cin >> c;
      --c;
      unlocks[i] |= 1<<c;
    }
  }

  int k = 1<<n;

  memset(dp, oo, sizeof dp);
  dp[0] = 0;

  rep(i, 1, m+1) {
    fo1(j, k) {
      dp[j | unlocks[i]] = min(dp[j | unlocks[i]], dp[j] + cost[i]);
    }
  }

  cout << (dp[k-1] >= oo ? -1 : dp[k-1]) << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int max = Integer.MIN_VALUE;
		if ((a + b) > max) {
			max = a + b;
		}
		if ((a - b) > max) {
			max = a - b;
		}
		if ((a * b) > max) {
			max = a * b;
		}
		
		System.out.println(max);
	}
	
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) (v).begin(),(v).end()
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int main() {
    int s, w;
    cin >> s >> w;
    if (w>=s) puts("unsafe");
    else puts("safe");
    return 0;
}

Measured memory_bytes: 3580
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N;
	cin >> N;
	vector<int> A(N);

	rep(i, 0, N)
	{
		cin >> A[i];
	}

	sort(all(A));
	A.erase(unique(all(A)), A.end());

	if (N == SZ(A))
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 1792
S = input()
rev = S[::-1]
half = len(S)//2
str1 = S[0:half]
str1_rev = str1[::-1]
str2 = S[half+1:]
str2_rev = str2[::-1]
if S != rev or str1 != str1_rev or str2 != str2_rev:
    print('No')
    exit()
print('Yes')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
    int n;
    cin>>n;
    string s;
    cin>>s;
    if(s.size()%2!=0)
    {
        cout<<"No"<<endl;
    }
    else
    {
        int p=0;
        for(int i=0;i<s.size()/2;i++)
        {
            if(s[i]!=s[s.size()/2+i])
            p=1;
        }
        if(p==1)
        cout<<"No"<<endl;
        else
        cout<<"Yes"<<endl;
    }
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
const int MAXN = 105;
int main()
{
    int k,a,b,f=1;
    scanf("%d%d%d",&k,&a,&b);
    for(int i=a;i<=b;i++){
        if(i%k==0){
            printf("OK\n");
            f=0;
            break;
        }
    }
    if(f)printf("NG\n");
    return 0;
}


Measured memory_bytes: 3684
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int bitcount(int n){
  int sum = 0;
  while(n>0){
    if(n&1)++sum;
    n>>=1;
  }
  return sum;
}
VEC<int> bitpos(int n){
  VEC<int> ans;
  int i=0;;
  while(n>0){
    if(n&1)ans.push_back(i);
    n>>=1;
    ++i;
  }
  return ans;

}
int main() {
  int n;
  cin>>n;
  map<char, LL>m;
  REP(i,0,n){
    string s;
    cin>>s;
    ++m[s[0]];
  }
  VEC<char>march={'M','A','R','C','H'};
  
  LL sum = 0;
  REP(i,0,1<<6){
    if(bitcount(i)==3){
      auto on = bitpos(i);
      LL tmp = 1;
      for(auto v:on){
        tmp*=m[march[v]];
      }
      sum+=tmp;
    }
  }
  cout<<sum<<endl;

  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


int n;
string s;

char ans[100001];

bool check(int i) {
	if (ans[i] == 'S') {
		if(s[i]=='o')return ans[(i + n - 1) % n] == ans[(i + 1) % n];
		else return ans[(i + n - 1) % n] != ans[(i + 1) % n];
	}
	else {
		if (s[i] == 'o')return ans[(i + n - 1) % n] != ans[(i + 1) % n];
		else return ans[(i + n - 1) % n] == ans[(i + 1) % n];
	}
}

bool check(char a,char b) {
	ans[0] = a;
	ans[1] = b;
	for (int i = 1; i < n - 1; i++) {
		if (ans[i]=='S') {
			if (s[i] == 'o')ans[i + 1] = ans[i - 1];
			else ans[i + 1] = ans[i - 1] == 'S' ? 'W' : 'S';
		}
		else {
			if (s[i] == 'o')ans[i + 1] = ans[i - 1] == 'S' ? 'W' : 'S';
			else ans[i + 1] = ans[i - 1];
		}
	}
	return check(n - 1) && check(0);
}


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> s;

	rep(i,4) {
		if (check((i & 2) ? 'S' : 'W', (i & 1) ? 'S' : 'W')) {
			cout << ans << endl;
			return 0;
		}
	}
	cout << -1 << endl;

	return 0;
}

Measured memory_bytes: 720
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef pair<pair<int, int>, int> PP;
typedef long long ll;
typedef priority_queue<int> pq;
int main(void) {
    int N, K;
    cin >> N >> K;
    vector<int> list;
    rep(i, N){
        int a;
        cin >> a;
        list.push_back(a);
    }
    sort(list.begin(), list.end());
    int mini = 1000000001;
    for(int i = 0; i < N-K+1; i++){
        int tmp = abs(list[i] - list[i+K-1]);
        mini = min(tmp, mini);
    }
    cout << mini << endl;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int N;
cin >> N;
double a;
double ansinv = 0;
for(int i=0;i<N;i++){
cin >> a;
ansinv += 1/a;
}
double ans;
ans = 1 / ansinv;
cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
int main(){
    ll a,b,c,A,B,C,ans=0;
    cin >> A>>B>>C;
    a=A;b=B;c=C;
    bool flag=false;
    while(1){
        if(a%2==1|| b%2==1 || c%2==1){
            break;
        }else if(flag==true && a==A && b==B & c==C){//INFなら戻ってくる
            cout << -1 << endl;
            return 0;
        }
        flag=true;
        ll x,y;
        x=(b+c)/2;
        y=(a+b)/2;
        b=(a+c)/2;a=x;c=y;
        ans++;
    }
    cout << ans << endl;
}



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

double area3(double x1, double y1, double x2, double y2, double x3, double y3)
{
    double a, b, c, z;
    
    a = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
    b = sqrt((x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3));
    c = sqrt((x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3));
    z = (a + b + c) / 2.0;
    
    return sqrt(z * (z - a) * (z - b) * (z - c));
}

int main(void)
{
    double x0, y0, x1, y1, x2, y2;
    double s = 0.0;
    
    scanf("%lf,%lf\n", &x0, &y0);
    scanf("%lf,%lf\n", &x1, &y1);
    
    while(scanf("%lf,%lf", &x2, &y2) == 2){
        s+=area3(x0, y0, x1, y1,x2, y2);
        x1 = x2;
        y1 = y2;
    }
    printf("%.6lf\n", s);
    
    return 0;
}


Measured memory_bytes: 2108
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
 
 
int main() {
    int N, M;
    cin >> N >> M;
    vector<ll> x(N), y(N), z(N);
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i] >> z[i];
    }

    ll ans = 0;
    for (int mask = 0; mask < 8; mask++) {
        vector<ll> data(N);
        for (int i = 0; i < N; i++) {
            if (mask & 1) {
                data[i] += x[i];
            } else {
                data[i] -= x[i];
            }

            if (mask & 2) {
                data[i] += y[i];
            } else {
                data[i] -= y[i];
            }

            if (mask & 4) {
                data[i] += z[i];
            } else {
                data[i] -= z[i];
            }
        }
        sort(data.begin(), data.end(), greater<ll>());
        ll tmp = 0;
        for (int i = 0; i < M; i++) {
            tmp += data[i];
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
a = [int(x) for x in input().split()]
from collections import defaultdict
d = defaultdict(int)
ans = 0
for i in range(N):
    d[a[i]] += 1
for i in range(1,1000001):
    if d[i] == 1:
        ans += 1
        for j in range(2,2+10**6//i):
            d[j*i] = 0
    elif d[i] >= 2:
        for j in range(2,2+10**6//i):
            d[j*i] = 0
print(ans)

Measured memory_bytes: 176132
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for (int i=a; i<b; ++i)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll H,W,M;
    cin >> H >> W >> M;
    set < pair <ll, ll> > targets;
    map < ll, ll> heights, widths;
    ll maxheight=0, maxwidth=0;
    loop(i,0,M)
    {
        int h,w;
        cin >> h >> w;
        targets.insert({h,w});
        heights[h]++;
        widths[w]++;
        maxheight=max(maxheight, heights[h]);
        maxwidth=max(maxwidth, widths[w]);
    }
    vector <ll> maxheight_rows, maxwidth_columns;
    for (auto z: heights) if (z.second==maxheight) maxheight_rows.push_back(z.first);
    for (auto z: widths) if (z.second==maxwidth) maxwidth_columns.push_back(z.first);
    ll ans=maxheight+maxwidth-1;
    if (maxheight_rows.size() * maxwidth_columns.size() > M)
    {
        ans=maxheight+maxwidth;
    }
    else 
    {
        for (auto x: maxheight_rows)
        {
            for (auto y: maxwidth_columns)
            {
                if (targets.find({x,y})==targets.end())
                {
                    ans=maxheight+maxwidth;
                }
            }
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 67772
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    X = I()

    if X in (7, 5, 3):
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 10088
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

bool compare_pair(pair<ll, ll> a, pair<ll, ll> b){
    if(a.first == b.first){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

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

    vector<pair<ll, ll>> arry(n);
    rep(i, n)cin >> arry[i].first >> arry[i].second;
    sort(ALL(arry), compare_pair);

    ll pos = 0;
    rep(i, n){
        pos += arry[i].second;
        if(pos >= k){
            cout << arry[i].first;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
const long long INF = 1LL << 60;
// const int INF=1010101010;
using Graph = vector<vector<int>>;

int main() {
  int x, y, z, k;
  cin >> x >> y >> z >> k;
  vector<ll> a(x);
  vector<ll> b(x);
  vector<ll> c(x);
  rep(i, x) cin >> a[i];
  rep(i, y) cin >> b[i];
  rep(i, z) cin >> c[i];
  SORT(a);
  SORT(b);
  SORT(c);
  RSORT(a);
  RSORT(b);
  RSORT(c);
  vector<ll> ans;
  for (int i = 0; i < x; i++) {
    if (i > k) break;
    for (int j = 0; j < y; j++) {
      if (i * j > k) break;
      for (int t = 0; t < z; t++) {
        if (i * j * t > k) break;
        ans.push_back(a[i] + b[j] + c[t]);
      }
    }
  }
  SORT(ans);
  RSORT(ans);
  for (int i = 0; i < k; i++) {
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 35176
import sys
from collections import defaultdict, deque

def dfs():
  queue = deque()
  queue.append([0,0])
  done = set([0])
  ans =[0] + [-1]*(N-1)
  while len(queue) != 0:
    prv_node, prv_edge = queue.pop()
    for node, edge in graph[prv_node]:
      if node in done: continue
      if (prv_edge + edge)%2==0:ans[node] = '0'
      else:ans[node] = '1'
      
      queue.append([node, prv_edge+edge])
      done.add(node)
  [print(a) for a in ans]
    
input = sys.stdin.readline

N = int(input())
graph = defaultdict(list)
for _ in range(N-1):
  u,v,w = map(int,input().split())
  graph[u-1].append([v-1,w])
  graph[v-1].append([u-1,w])

dfs()

Measured memory_bytes: 100700
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1e9+7
#define PI acos(-1.0)
#define ll long long

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

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int N,K;cin>>N>>K;
  int a[200001]={};
  set<int> s;
  int b[200001]={};
  REP(i,N){
    cin>>a[i];
    s.insert(a[i]);
  }
  sort(a,a+N);
  int s_size=s.size();
  if(s_size<=K){
    P(0);
    return 0;
  }
  for(int j=1;j<=N;j++){
    int t1=lower_bound(a,a+N,j)-a;
    int t2=upper_bound(a,a+N,j)-a;
    int t=t2-t1;
    b[j]=t;
  }
  sort(b+1,b+N+1);
  // bはゼロ含む列
  int ans=0;
  int su=0;
  for(int i=N;i>N-K;i--){
    su+=b[i];
  }
  for(int i=1;i<=N;i++){
    ans+=b[i];
  }
  P(ans-su);
  return 0;
}


Measured memory_bytes: 11264
#include<stdio.h>
main(){
int s[9000],n,m,t,f,i;
while(scanf("%d%d",&n,&m),i=t=f=1,n){
	while(i<=n+m){
		if(scanf("%d",&s[i]),i>n&&(t+=s[t+=s[i]],t>=n&f==1))
				printf("%d\n",i-n,f=0);
				i++;
	}
}
	
}

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

using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int b[100010] = {};
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    
    int a[100010] = {};
    a[0] = b[0];
    for (int i = 1; i < n-1; i++)
    {
        a[i] = min(b[i-1], b[i]);
    }
    a[n-1] = b[n-2];
    int res = 0;
    for (int i = 0; i < n; i++)
    {
        res += a[i];
    }
    
    cout << res << "\n";
    

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,t,c,T;
    cin>>n>>t;
    int ans=100000;
    for (int i=0;i<n;i++) {
        cin>>c>>T;
        if (T<=t) {
            if (ans>c) {
                ans=c;
            }
        }
    }
    if (ans!=100000) {
        cout<<ans<<endl;
    } else {
        cout<<"TLE"<<endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include<cstdlib>
int main(){
    int x,n;
    cin>>x>>n;
    vector<int> a(112);
    vector<int> b(n);
    for(int i=0;i<a.size();i++){
        a.at(i)=i-10;
    }
    for(int i=0;i<n;i++){
        cin>>b.at(i);
    }
    for(int i=0;i<n;i++){
        remove(a.begin(),a.end(),b.at(i));
    }
    int min=100;
    int ans=0;
    for(int i=a.size()-1;i>=0;i--){
        int f=abs(a.at(i)-x);
        if(f<=min){
            min=f;
            ans=a.at(i);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N, M; cin >> N >> M; 
	int H[100010]; 
	for(int i = 0; i < N; i++) cin >> H[i]; 
	vector<int> E[100010]; 
	for(int i = 0; i < M; i++){
		int a, b; cin >> a >> b; 
		a--; b--; 
		E[a].push_back(b); E[b].push_back(a); 
	}
	int ans = 0; 
	for(int i = 0; i < N; i++){
		bool ok = true; 
		for(int v : E[i]){
			if(H[v] >= H[i]) ok = false; 
		}
		if(ok) ans ++; 
	}
	cout << ans << endl; 
}

Measured memory_bytes: 9136
#include <iostream>
using namespace std;
int main() {
    int n;
    cin >> n;
    if (n % 1000 == 0) {
        cout << 0 << endl;
        return 0;
    }
    cout << ((n - n % 1000) / 1000 + 1) * 1000 - n << endl;
    return 0;
}

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

int main() {
    int n,k;
    
    scanf(" %d %d",&n,&k);
    
    int cnt=k;
    
    for(int i=1;i<n;i++){
        cnt*=k-1;
    }
    
    cout << cnt << endl;
    
    return 0;
}


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

int d[1000][1000],ans[1000][1000];
int dx[]{1,-1,0,0},dy[]{0,0,1,-1};
int main(){
	int r,c,x1,y1,x2,y2;cin>>r>>c>>x1>>y1>>x2>>y2;
	queue<P>que;
	memset(d,-1,sizeof(d));
	ans[x1][y1]=1;d[x1][y1]=0;que.push(P(x1,y1));
	while(!que.empty()){
		P p=que.front();que.pop();
		rep(i,4){
			int nx=(p.first+dx[i]+r)%r,ny=(p.second+dy[i]+c)%c;
			if(d[nx][ny]==-1){
				d[nx][ny]=d[p.first][p.second]+1;
				que.push(P(nx,ny));
			}
			if(d[nx][ny]==d[p.first][p.second]+1)
				(ans[nx][ny]+=ans[p.first][p.second])%=MOD;
		}
	}
	printf("%d\n",ans[x2][y2]);
}

Measured memory_bytes: 11112
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int N;
    cin >> N;
    int T[N+10];
    for(int i=0;i<N;i++) cin >> T[i];
    int M;
    cin >> M;
    int P[M+10],X[M+10];
    for(int i=0;i<M;i++) cin >> P[i] >> X[i];

    int sum=0;
    for(int i=0;i<N;i++) sum += T[i];

    for(int i=0;i<M;i++){
        cout << sum - T[P[i] - 1] + X[i] << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAXN 505
#define INF 1000000000000000000LL
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n;
int a[MAXN][MAXN];
ll sum[2][MAXN][MAXN];
ll dp[MAXN][MAXN];
ll getcost(int id,int fromx,int fromy,int tox,int toy)
{
    if(fromx>fromy||tox>toy) return 0;
    return sum[id][fromy][toy]-sum[id][fromx-1][toy]-sum[id][fromy][tox-1]+sum[id][fromx-1][tox-1];
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
        {
            if(i==j) continue;
            scanf("%d",&a[i][j]);
        }
    for(int k=0;k<2;k++)
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
            {
                int add=(i<j?1:0)^(k==0?1:0);
                sum[k][i][j]=sum[k][i][j-1]+a[i][j]*(1-add);
            }
    for(int k=0;k<2;k++)
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
                sum[k][i][j]=sum[k][i][j]+sum[k][i-1][j];
    for(int i=0;i<=n;i++)
        for(int j=0;j<=n;j++)
            dp[i][j]=INF;
    //
    dp[0][0]=0;
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=n;j++)
        {
            if(dp[i][j]==INF) continue;
            for(int k=i+1;k<=n;k++)
                dp[k][i]=min(dp[k][i],dp[i][j]+getcost(1,k+1,n,j+1,i)+getcost(0,i+1,k,i+1,k));
        }
    }
    ll ans=INF;
    for(int i=0;i<=n;i++) ans=min(ans,dp[n][i]);
    printf("%lld\n",ans);
    return 0;
}


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

int main()
{
    string s, t;
    cin >> s;
    cin >> t;
    if( s.length() + 1 == t.length() && t.substr(0, s.length()) == s)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
}

Measured memory_bytes: 3608
#include<stdio.h>
int main(void)
{
    long long int a[200001],n,i,sum1 = 0,sum2 = 0,mod = 1000000007,sum = 0;
    scanf("%lld",&n);
    for(i = 0 ; i < n ; i++)
    {
        scanf("%lld",&a[i]);
        sum1 += a[i] ;
        sum1 = sum1 % mod;
    }
    for(i = 0 ; i < n ; i++)
    {
        sum1 -= a[i];
        while(sum1 < 0)
        {
            sum1 += mod;
        }
        sum += a[i] * sum1 ;
        sum = sum % mod;
    }
    while(sum < 0 )
    {
        sum += mod;
    }
    printf("%lld\n",sum % mod);
    return 0;
}

Measured memory_bytes: 3268