akhauriyash/Code-Regression huggingface dataset:
def partition(array, start, end):
    end_val = array[end]
    left_end = start - 1
    for search_idx in range(start, end):
        if array[search_idx] <= end_val:
            left_end += 1
            array[left_end], array[search_idx] = array[search_idx], array[left_end]
    array[left_end + 1], array[end] = array[end], array[left_end + 1]
    return left_end + 1


def main():
    n = int(input())
    array = list(map(int, input().split(" ")))
    partition_idx = partition(array, 0, n - 1)
    array = list(map(str, array))
    print(" ".join(array[:partition_idx]) +
          " [{}] ".format(array[partition_idx]) +
          " ".join(array[partition_idx + 1:]))


if __name__ == "__main__":
    main()



Measured memory_bytes: 16388
#include<bits/stdc++.h>
#define int long long
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;


const int maxn = 1e5 , MOD = 1e9 + 7;
vector<vector<int>>g(maxn+1);
int dp[maxn+1][2];
int n;
void dfs(int u=1,int p=0)
{
	dp[u][0]=1;
	dp[u][1]=1;
	
	for(auto v:g[u])
	{
		if(v!=p)
		{
			dfs(v,u);
			
			dp[u][0]*=dp[v][1];
			dp[u][1]*=dp[v][0]+dp[v][1];
			
			dp[u][0]%=MOD;
			dp[u][1]%=MOD;
		}
	}
}
	
int32_t main()
{
	IOS
	memset(dp,0,sizeof(dp));
	cin >> n ;
	for(int i=1;i<n;i++)
	{
		int u,v;cin>>u>>v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	
	dfs();
	
	cout << (dp[1][0]+dp[1][1])%MOD << endl;
}


Measured memory_bytes: 14208
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define float long double


int32_t main()
{
	
	IOS
	int n,ans=LLONG_MIN,g;cin>>n;
	vector<int>A(n+1),L(n+1),R(n+1);
	for(int i=1;i<=n;i++)cin>>A[i];
	g=A[1];
	for(int i=1;i<=n;i++)
	{
		g=__gcd(g,A[i]);
		L[i]=g;
	}
	g=A[n];
	for(int i=n;i>=1;i--)
	{
		g=__gcd(A[i],g);
		R[i]=g;
	}
	for(int i=2;i<=n-1;i++)
	{
		ans=max(ans,__gcd(L[i-1],R[i+1]));
	}
	cout<<max({ans,R[2],L[n-1]})<<endl;
	
			

	
	
			
	
		
			
	
		
	
	
}			
	
	
	
	
	

	

	

	
		


Measured memory_bytes: 2560
def main():
    N = int(input())
    is_able = False

    for i in range(1, 10):
        for j in range(1, 10):
            if i * j == N:
                is_able = True

    if is_able:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 9100
# -*- coding: utf-8 -*-
import math

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

digit_K = int(math.log(K, 2)) + 1 if not K == 0 else 0
d1s = [0]*digit_K
gain = []

ans = sum(A)
for i in range(digit_K):
    for j in range(N):
        d1s[i] += A[j] % 2
        A[j] = A[j] // 2
    gain.append((N - d1s[i] * 2) * 2**i)

pGain = [max(g, 0) for g in gain]
cK, kGain = K, []
for i in range(digit_K):
    cK, dK = divmod(cK,2)
    kGain.append(pGain[i] * dK)

maxgain = sum(kGain)
for i in range(digit_K):
    K, dK = divmod(K, 2)
    if dK == 1:
        sumgain = sum(pGain[:i] + kGain[i+1:])
        maxgain = max(maxgain, sumgain)

ans += maxgain
print(ans)


Measured memory_bytes: 14620
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>

using namespace std;

int main()
{
    /*
    cin>>x;
    cout<<x<<endl;
    */
    int n,m,i,j,ans;
    float mo,sum;
    string s;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>mo>>s;
        if(s.compare("JPY")==0)
            sum+=mo;
        else
            sum+=(mo*380000.0);
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
use std::cmp::{max,min};
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let n:i64 = read();
    let m:i64 = (n as f64).sqrt() as i64;
    let mut ans = 10;
    for j in 1..(m+ 1){
        if n % j == 0 {
            ans = min(ans,max(get_length(j,0),get_length(n/j,0)));
        }
    }
    println!("{}",ans );
}
fn get_length(x:i64,cnt:i64) -> i64{
    if x <= 0 {
        cnt
    } else {
        get_length(x/10, cnt+1)
    }
    // let mut cnt = 0;
    // while x > 0 {
    //     cnt += 1;
    //     x /= 10;
    // }
    // cnt
}

Measured memory_bytes: 4352
import java.util.*;
import javax.lang.model.util.ElementScanner6;
//import java.lang.Math;

public class Main {

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

        // 入力
        long n = sc.nextLong();
        long k = sc.nextLong();

        // 処理
        //nがkより大きいとき、n % kを求め、それをnとする
        n = n % k;

        long out = 0;
        long w1;
        long w2 = n;
        boolean flg = true;
        if ( k == 1){
            out = 0;
        } else {
            while(flg){
                w1 = w2 - k;
                w1 = w1 >= 0 ? w1 : -w1;
                if (w1 >= w2) {
                    out = w2;
                    flg = false;
                }
                w2 = w1;
            }
        }

        // while(out >= k){
        //     out = n > k ? n - k : k - n;
        // }

        // 出力
        System.out.println(out);
    }
}

Measured memory_bytes: 21972
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>
#include <cctype>
#include <map>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ll long long

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

    cout << (6 - a - b) << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
using namespace std;
int n;
string s;
vector<int> vec[26];
ll dp[2005][2005];

int main(void){
	cin >> s;
	n=s.size();
	for(int i=0;i<n;i++){
		int a=s[i]-'a';
		vec[a].push_back(i);
	}
	memset(dp,0,sizeof(dp));
	ll ans=0;
	dp[0][n]=1;
	for(int i=0;i<n;i++){
		for(int j=n;j>i;j--){
			if(dp[i][j]==0)continue;
			for(int k=0;k<26;k++){
				int v=lower_bound(vec[k].begin(),vec[k].end(),i)-vec[k].begin();
				if(v==vec[k].size())continue;
				int f=vec[k][v];
				//printf("%d %d %d %d\n",i,j,f,k);
				if(f>=j)continue;
				//printf("%d %d %d %d\n",i,j,f,k);
				ans+=dp[i][j];
				ans%=MOD;
				int v2=lower_bound(vec[k].begin(),vec[k].end(),j)-vec[k].begin();
				v2--;
				if(v2<0)continue;
				//printf("%d %d %d %d\n",i,j,k,v,v2);
				if(vec[k][v2]>f){
					dp[f+1][vec[k][v2]]+=dp[i][j];
					dp[f+1][vec[k][v2]]%=MOD;
				}
			}
		}
	}
	for(int i=1;i<n;i++){
		for(int j=0;j<=n;j++){
			ans+=dp[i][j];
			ans%=MOD;
		}
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 34796
object Main extends App {
    val in = io.Source.stdin.getLines.map(_.split(" ").map(_.toInt))
    for (Array(n, m) <- in if n != 0) {
        println(in.take(n).toSeq.transpose.zipWithIndex.sortWith((a, b) => a._1.sum > b._1.sum).map(_._2+1).mkString(" "))
    }
}

Measured memory_bytes: 146396
a,b,m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
xyc = [list(map(int,input().split())) for i in range(m)]
ans = min(a)+min(b)
for i in range(m):
    price_a = a[xyc[i][0]-1]
    price_b = b[xyc[i][1]-1]
    c = xyc[i][2]
    ans = min(ans,price_a+price_b-c)
print(ans)


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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  string s; cin >> s;
  s[3] = '8';
  cout << s << endl;
  
  return 0;
}


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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

int main()
{
    int N;
    cin >> N;
    vector<int> X(N);
    ll all = 0;
    rep(i,N)
    {
        cin >> X[i];
        all += X[i];
    }

    if( all%N == 0 ) all /= N;
    else
    {
        if( all%N > N/2 ) all = all/N+1;
        else all /= N;
    }
    ll ans = 0;
    rep(i,N)
    {
        ans += (all - X[i]) * (all - X[i]);
    }
    cout << ans << endl;



}


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

int main(void)
{
    string x1,x2,x3;
    cin>>x1>>x2>>x3;
    putchar(toupper(x1[0]));
    putchar(toupper(x2[0]));
    putchar(toupper(x3[0]));
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long ll;

 
int main() {
    int N; cin >> N;
    for(int i = 0; i < N; i++){
        int n; cin >> n;
        if(n%2 == 1) {
            cout << "first" << endl;
            return 0;
        }
    }
    cout << "second" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>/*toupperとかが入っている*/
#include<vector>/*可変長配列vectorのインクルード*/
using namespace std;/*標準名前空間を利用する。cinやcoutはこれによって利用可能になる*/

int n;
long long int a;
int b[200005];

int main(void) {
  cin >> n;
  for(int i=0; i<n; i++){
    cin >> a;
    b[i] = a;
  }
  
  /*前半部の出力*/
  for(int i=n-1; i>=0; i=i-2){
    cout << b[i] << " ";  
  }
  
  /*後半部の出力、要素が偶数の場合*/
  if(n%2==0){
    for(int i=0; i<n; i=i+2){
      cout << b[i] << " ";  
    }
  }else{
  /*後半部の出力、要素が奇数の場合*/
    for(int i=1; i<n; i=i+2){
      cout << b[i] << " ";  
    }
  }
  cout << endl;
  return 0;
}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"
#define int ll

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

  int N;
  cin>>N;
  vector<int>A(N);
  for(int i=0;i<N;i++)cin>>A[i];
  int Q;
  cin>>Q;
  vector<int>B(Q),C(Q);
  for(int i=0;i<Q;i++)cin>>B[i]>>C[i];
  map<int,int>m;
  for(int i=0;i<N;i++)m[A[i]]++;
  ll ans=0;
  for(auto it:m)ans+=it.first*it.second;
  for(int i=0;i<Q;i++){
    ans-=m[B[i]]*B[i];
    ans+=m[B[i]]*C[i];
    m[C[i]]+=m[B[i]];
    m[B[i]]=0;
    cout<<ans<<endl;
  }
  return 0;
}


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

int main(){
  int H,W;
  cin >> H >> W;
  char a[100][100],b[102][102];
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin  >> a[i][j];
    }
  }
  for(int i=0;i<H+2;i++){
    for(int j=0;j<W+2;j++){
      if(j!=0 && j!=W+1 && i!=0 && i!=H+1){
        b[i][j]=a[i-1][j-1];
      }
      else{
        b[i][j]='#';
      }
      cout << b[i][j];
    }
    cout << endl;
  }
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main{
	public static void main(String[] args)throws Throwable {
		MyScanner sc=new MyScanner();
		PrintWriter pw=new PrintWriter(System.out);
		
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();
		int d=sc.nextInt();
		int ans=0;
		for(int i=0;i<=100;i++)
			if(i>=a && i<b && i>=c && i<d)
				ans++;
		pw.println(ans);
		pw.flush();
		pw.close();
	}
	
	static class MyScanner {
		BufferedReader br;
		StringTokenizer st;
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		String next() {while (st == null || !st.hasMoreElements()) {
			try {st = new StringTokenizer(br.readLine());}
			catch (IOException e) {e.printStackTrace();}}
		return st.nextToken();}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());}
		double nextDouble() {return Double.parseDouble(next());}
		String nextLine(){String str = "";
		try {str = br.readLine();}
		catch (IOException e) {e.printStackTrace();}
		return str;}
	}
}

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

#define F first
#define S second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 510, M = 200010, INF = 0x3f3f3f3f;

int n, m, k;
int f[N][N];
vector<int> L[N], R[N];

int main()
{
	scanf("%d%d%d", &n, &m, &k);
	for (int i = 0; i < m; i ++ )
	{
		int a, b;
		scanf("%d%d", &a, &b);
		L[a].push_back(b);
		R[b].push_back(a);
	}
	
	for (int i = 1; i <= n; i ++ )
	{
		sort(L[i].begin(), L[i].end());
		sort(R[i].begin(), R[i].end());
	}
	
	for (int len = 1; len <= n; len ++ )
		for (int l = 1; l + len - 1 <= n; l ++ )
		{
			int r = l + len - 1;
			if (r - 1 >= l + 1) f[l][r] += f[l + 1][r - 1];
			
			int i = lower_bound(L[l].begin(), L[l].end(), r) - L[l].begin();
			f[l][r] += i;
			int j = upper_bound(R[r].begin(), R[r].end(), l) - R[r].begin();
			f[l][r] += (int)R[r].size() - j;
			i = lower_bound(L[l].begin(), L[l].end(), r) - L[l].begin();
			j = upper_bound(L[l].begin(), L[l].end(), r) - L[l].begin();
			f[l][r] += j - i;
		}
	
	while (k -- )
	{
		int p, q;
		scanf("%d%d", &p, &q);
		printf("%d\n", f[p][q]);
	}
	return 0;
}

Measured memory_bytes: 4480
#include<bits/stdc++.h>
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define popcnt(x) __builtin_popcount(x)
#define inf 0x3f3f3f3f
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rand() (rand() << 15 | rand())
using namespace std;
typedef long long  ll;
#define EPS 1e-9
#define PI acos(-1.0)

int main() {
   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
   int n , k;
   cin >> n >> k;
   vector<int> a(n);
   for(int &x : a)
      cin >> x;
   sort(all(a));
   ll sum = 0;
   for(int i = 0 ; i < n - k ; ++i){
      sum += a[i];
   }
   cout << sum << "\n";
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
const int MAX_D_DIG=9;
ll D;
int d[MAX_D_DIG];
ll pw10[MAX_D_DIG*2];
int hL,L;
ll dfs(int i,ll sm){
	ll ret=0;
	if (i==hL){
		if (sm==D){
			ret=1;
			REP(j,hL){
				int temd=d[j];
				if (j==0){
					if (temd>=0){
						ret*=9-temd;
					}else{
						ret*=10-abs(temd);
					}
				}else{
					temd=abs(temd);
					ret*=(10-temd);
				}
			}
		}else{
			ret=0;
		}
	}else if ((L&1) && i==hL-1){
		d[i]=0;
		ret=dfs(i+1,sm);
	}else{
		ll dif=D-sm;
		ll md=dif%pw10[i+1];
		md+=pw10[i+1];
		md%=pw10[i+1];
		md/=pw10[i];
		if (md==0){
			d[i]=0;
			ret=dfs(i+1,sm);
		}else{
			d[i]=-md;
			ret=dfs(i+1,sm+(pw10[L-1-i]-pw10[i])*d[i]);
			d[i]=10-md;
			ret+=dfs(i+1,sm+(pw10[L-1-i]-pw10[i])*d[i]);
		}
	}
	return ret;
}
int main(){
	pw10[0]=1;
	FOR(i,1,MAX_D_DIG*2){
		pw10[i]=pw10[i-1]*10;
	}
	cin>>D;
	int ld=0;
	{
		ll tem=D;
		while(tem){
			ld++;
			tem/=10;
		}
	}
	ll ans=0;
	FOR(l,ld,2*ld+1){
		hL=(l+1)/2;
		L=l;
		ans+=dfs(0,0);
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;
using int64 = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

void fastin(int64 &num) {
  bool negative = false;
  int64 c;
  num = 0;
  c = getchar_unlocked();
  if (c == '-') {
    negative = true;
    c = getchar_unlocked();
  }
  for (; (c > 47 && c < 58); c = getchar_unlocked()) num = (num << 3) + (num << 1) + c - 48;
  if (negative) num *= -1;
}

void fastout(int64 &n) {
  int64 N = n, rev, count = 0;
  rev = N;
  if (N == 0) { 
    putchar_unlocked('0');
    putchar_unlocked('\n');
    return;
  }
  while ((rev % 10) == 0) { 
    ++count; rev /= 10;
  }
  rev = 0;
  while (N != 0) { 
    rev = (rev << 3) + (rev << 1) + N % 10;
    N /= 10;
  }
  while (rev != 0) { 
    putchar_unlocked(rev % 10 + '0');
    rev /= 10;
  }
  while (count--) putchar_unlocked('0');
  putchar_unlocked('\n');
}

int main(){
    int64 n, m; fastin(n); fastin(m);
    int64 x[m];
    rep(i, m) fastin(x[i]);

    sort(x, x + m);

    int64 diff[m - 1];
    rep(i, m - 1){
        diff[i] = x[i + 1] - x[i];
    }

    sort(diff, diff + m - 1);

    int64 ans = 0;

    for (int i = 0; i < (m - n); ++i){
        ans += diff[i];
    }

    fastout(ans);
    
    return 0;
}


Measured memory_bytes: 1792
import java.util.*;

class Main{

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

	int m = sc.nextInt();//f[^Zbg

	while(m!=0){
	    String train = sc.next();//ñÔÌÒ¬
	    System.out.println(solve(train));
	    m--;
	}
    }

    public static int solve(String train){
	List<String> hensei = new ArrayList<String>();//Ò¬ðd¡ÈµÅL^
	for(int i=0; i<train.length()-1; i++){
	    String mae = train.substring(0,i+1);//ªµ½Æ«ÌO¼ª
	    String ushiro = train.substring(i+1,train.length());//ã¼ª
	    String[] type = new String[4];
	    for(int k=0; k<2; k++){
		type[0] = mae + ushiro;//OF»ÌÜÜ@ãF»ÌÜÜ
		type[1] = mae + hanten(ushiro);//OF»ÌÜÜ@ãF½]
		type[2] = hanten(mae) + ushiro;//OF½]@ãF»ÌÜÜ
		type[3] = hanten(mae) + hanten(ushiro);//OF½]@ãF½]
		for(int j=0; j<type.length; j++)
		    if(!hensei.contains(type[j])){hensei.add(type[j]);}
		String tmp = mae;//OãüêÖ¦
		mae = ushiro;
		ushiro = tmp;
	    }
	}
	return hensei.size();
    }

    //¶ñð½]·é
    public static String hanten(String s){
	String hanten = "";
	for(int i=s.length()-1; i>=0; i--){
	    String last = s.substring(i,i+1);//êÔãë©çæèo·
	    hanten += last;//æª©çüêé
	}
	return hanten;
    }
}

Measured memory_bytes: 16000
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vector< P > v;
    for( int i = 0; i < n; ++i ) {
        int a, b;
        cin >> a >> b;
        v.pb( MP( b, a ) );

    }
    sort( v.begin(), v.end() );
    int time = 0;
    bool flg = true;
    for( int i = 0; i < v.size(); ++i ) {
        time += v[i].S;
        if( time > v[i].F ) {
            flg = false;

        }
    }
    if( flg ) cout << "Yes";
    else cout << "No";
    cout << endl;
    return 0;
}



Measured memory_bytes: 2420
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from heapq import heappush, heappop

def dijkstra(graph:list, node:int, start:int) -> list:
    # 未探索のノードは距離INF
    INF = float("inf")
    dist = [INF]*node
    
    # 始点ノードの距離を0とし、dfsのためのpriority queを作成
    dist[start] = 0
    heap = [(0,start)]
    
    # 未探索のノードをpriority queueに入れる
    while heap:
        cost, cur_node = heappop(heap)
        
        for nex_cost, nex_node in graph[cur_node]:
            dist_cand = dist[cur_node] + nex_cost
            if dist_cand < dist[nex_node]:
                dist[nex_node] = dist_cand
                heappush(heap, (dist[nex_node], nex_node))
    
    return dist

n,m = li()

edges = []
graph = [[] for _ in range(n)]
adj_mat = [[0]*n for _ in range(n)]

for _ in range(m):
    a,b,c = li()
    a -= 1
    b -= 1
    graph[a].append((c,b))
    graph[b].append((c,a))
    edges.append((a,b,c))
    
# 各点からの最短dist
for i in range(n):
    adj_mat[i] = dijkstra(graph, n, i)
    
    
# 最短路とedgeの比較
ans = 0
for ai, bi, ci in edges:
    if adj_mat[ai][bi] < ci:
        ans += 1
        
print(ans)

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

using namespace std;
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vint;
typedef vector<ll> vll;

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


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

	return 0;
}

Measured memory_bytes: 256
import sys

def main():
    input = sys.stdin.readline
    M, K = map(int, input().split())

    if K >= 2**M:
        return [-1]

    if M == 1:
        if K == 0:
            return [0, 0, 1, 1]
        else:
            return [-1]

    # [0, 1, ..., 2**M - 1] excepting K
    a = list(range(K)) + list(range(K+1, 2**M))

    # [2**M - 1, 2**M - 2, ..., 1, 0] excepting K
    b = a[::-1]

    return a + [K] + b + [K]


if __name__ == '__main__':
    print(*main())


Measured memory_bytes: 14324
def main():
  mod=10**9+7
  n=int(input())
  dp=[[0]*(n+1) for _ in range(4)]
  dp[0][0]=1
  for i in range(4):
    for j in range(n):
      dp[i][j]%=mod
      dp[i][j+1]+=dp[i][j]*8
      dp[i|1][j+1]+=dp[i][j]
      dp[i|2][j+1]+=dp[i][j]
  print(dp[3][n]%mod)
main()

Measured memory_bytes: 95600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;
/* ちゃんと考えてわかって実装 */

int main(void){
    int n, x, y;
    cin >> n >> x >> y;

    int dist[n+1][n+1];
    vector<int> d(n);
    for(int i=1; i<=n; i++){
        for(int j=i+1; j<=n; j++){
            // x, y間を通過する場合と通過しない場合の小さい方
            // 通過しない -> j - i
            // 通過する -> abs(i-x) + 1 + abs(j-y)
            int path = min(j-i, abs(i-x) + 1 + abs(j-y));
            dist[i][j] = path;
            d[path]++;
        }
    }

    for(int i=1; i<=n-1; i++){
        cout << d[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 15744
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>

using namespace std;


int main(){
  int A, B;
  cin >> A >> B;
  if(B % A == 0)  cout << A+B << endl;
  else cout << B-A << endl;
  return 0;
}


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


int main(void) {
int N;
scanf("%d",&N);
int arr[N];
int res[N+1];
memset(arr,0,N*sizeof(*arr));
memset(res,0,(N+1)*sizeof(*res));

for (int i=1;i<=N-1;i++)
scanf("%d",&arr[i]);
for (int i=1;i<=N;i++)
res[i]=arr[i];
res[N]=arr[N-1];

for (int i=1;i<=N-1;i++)
if (arr[i]<arr[i+1]) res[i+1]=arr[i];

res[N]=arr[N-1];

int sum =0;

for (int i=1;i<=N;i++)
sum+=res[i];

printf("%d",sum);
return EXIT_SUCCESS;
}


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

int main(){
  int N, f = 0;
  cin >> N;
  int n = N;
  
  for (int i = 0; i < 8; i++){
    f += N % 10;
    N /= 10;
  }
  
  if (n % f == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
     


Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10**7)

N = int(readline())
ABC = (tuple(int(x) for x in line.split()) for line in readlines()) 

graph = [[] for _ in range(N+1)]
for a,b,c in ABC:
    a -= 1; b -= 1
    graph[a].append((b,c))
    graph[b].append((a,c))

# トポロジカル順序で頂点のリストを作る
V = [0]
parent = [None]
visited = [True] + [False] * (N-1)
q = [0]
while q:
    x = q.pop()
    for y,_ in graph[x]:
        if visited[y]:
            continue
        q.append(y)
        V.append(y)
        parent.append(x)
        visited[y] = True    

size = [[] for _ in range(N)] # 部分木の大きさのリスト
centroid = []
for v,p in zip(V[::-1],parent[::-1]):
    size[v].append(N-1-sum(size[v]))
    if all(x<=N//2 for x in size[v]):
        centroid.append(v)
    if p is not None:
        size[p].append(N-size[v][-1])

v0 = centroid[0]
dist = [None] * N
dist[v0] = 0
q = [v0]
while q:
    x = q.pop()
    for y,wt in graph[x]:
        if dist[y] is None:
            dist[y] = dist[x] + wt
            q.append(y)

if len(centroid) == 1:
    dist.sort()
    answer = sum(dist) * 2 - dist[0] - dist[1]
else:
    answer = sum(dist) * 2 - dist[centroid[0]] - dist[centroid[1]]
print(answer)

Measured memory_bytes: 63084
#include <iostream>
#include<cstdio>
#include<cstdlib>
#include<queue>
#include<cstring>
#include<map>
using namespace std;
map<string,int> d;//d[s]表示"01234567"到s的移动次数
queue<string> q;
int _x[4]={-1,1,-4,4};//一维数组和‘0’相邻，相差1（左右）或4（上下）。‘0’位于第一行最后一个和第二行第一个时除外
int swaped;
int a[8];

bool no_over(int x)
{
	if(x>=0&&x<=7) return true;
	else return false;
		
}
//广搜+dp 我傻了
void bfs()
{
	while(!q.empty()) q.pop();
	q.push("01234567");
	d["01234567"]=0;
	while(!q.empty())
	{
		string s=q.front();
		q.pop();
		//找到“0”的位置
		int i,j;
		for(i=0;i<8;i++)
		{
			if(s[i]=='0') break;
		}
		for(j=0;j<4;j++)
		{
			swaped=i+_x[j];
			if((i==3&&swaped==4)||(i==4&&swaped==3)) continue;
			if(no_over(swaped)){
			string new_s=s;
			swap(new_s[i],new_s[swaped]);//c++居然自带swap
			if(d.find(new_s)==d.end())//不存在映射
			{
				d[new_s]=d[s]+1;
				q.push(new_s);
			}}
		}
		
	}
}
int main()
{
	bfs();
	while(scanf("%d",&a[0])!=EOF)
	{
		string s;
		s+=a[0]+'0';
		for(int i=1;i<8;i++)
		{
			cin>>a[i];
			s+=a[i]+'0';
		}
		cout<<d[s]<<endl;
	}
	return 0;
}


Measured memory_bytes: 5508
s=0
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
for i in range(N-1):
  if A[i]+1==A[i+1]:
    s+=C[A[i]-1]
s+=sum(B)
print(s)

Measured memory_bytes: 61780
<?php
  fscanf(STDIN, "%d", $n);
	$hon = array(2,4,5,7,9);
	$pon = array(0,1,6,8);
	
	if (in_array($n%10, $hon)) {
      	echo "hon\n";
    } else if (in_array($n%10, $pon)) {
      	echo "pon\n";
    } else {
      	echo "bon\n";
    }

Measured memory_bytes: 16140
#include <stdio.h>
int main(void)
{
  int n,k;
  int sum=0;
  scanf("%d %d",&n,&k);
  while(n-->0){
    int x;
    scanf("%d",&x);
    sum+=x<k-x?2*x:2*(k-x);
  }
  printf("%d\n",sum);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main() {
	string s,t;
	cin>>s>>t;
	ll a,b;
	cin>>a>>b;
	string u;
	cin>>u;
	if(u==s)
	cout<<a-1<<" "<<b;
	else
	cout<<a<<" "<<b-1;
	return 0;
}

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

const int INF = 100000000;
//typedefで決めておくと便利
typedef pair<int, int> P;
//入力
int h, w;//height, width
int maxr = 1000, maxc = 1000;
vector<vector<char> > maze(maxr, vector<char>(maxc));//迷路を表す
int sx, sy;//start point
long long minute;//かかった時間
int bfs(){
    //dx,dyの初期化   
    vector<int> dx(4);
    vector<int> dy(4);
    dx.at(0) = 1;
    dx.at(1) = 0;
    dx.at(2) = -1;
    dx.at(3) = 0;
    dy.at(0) = 0;
    dy.at(1) = 1;
    dy.at(2) = 0;
    dy.at(3) = -1;
    queue<P> que;
    vector<vector<int> > d(maxr, vector<int>(maxc));//最短距離の配列
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            d.at(i).at(j) = INF;//距離をINFで初期化
        }
    }
    que.push(P(sy, sx));
    d.at(sy).at(sx) = 0;//startは0
    //queが空になるまでroop
    while (que.size()){
        P p = que.front();
        que.pop();//queの最初を取り出す
        if(sy == h - 1 && sx == w - 1) {//goal到達時
            break;//もし取り出してきた状態がgoalなら探索をやめる
        }
        //移動4方向をroop
        for(int i = 0; i < 4; i++){
            int ny = p.first + dy.at(i), nx = p.second + dx.at(i);
            if(0 <= nx && nx < w && 0 <= ny && ny < h && maze.at(ny).at(nx) != '#' && d.at(ny).at(nx) == INF){
                //移動できるならqueに入れ、その点の距離をpからの距離+1で確定する
                que.push(P(ny, nx));
                d.at(ny).at(nx) = d.at(p.first).at(p.second) + 1;
            }
        }
    }
    return d.at(h - 1).at(w - 1);
}
void solve(){
    cin >> h >> w;
    int white = 0;
    sx = 0, sy = 0;
    for(int i = 0; i < h; i++){
        string s;
        cin >> s;
        for(int j = 0; j < w; j++){
            maze.at(i).at(j) = s.at(j);
            if(s.at(j) == '.')
            white++;
        }
    }//入力完了
    if(bfs() == INF)
        cout << -1 << endl;
    else 
    cout << white - bfs() - 1 << endl;//全体の白の数-移動距離-スタートの1
}
int main(){
    solve();
    return 0;
}

Measured memory_bytes: 5248
#include<iostream>
#include<cstdio>
#include<new>
#include<cstdlib>
#include<cstring>
using namespace std;
typedef struct node;
typedef node * tree;
int bianliang=0;
struct node
{
       int data;
       tree lchild,rchild;
};
tree root;
void build(tree &p,int n)
{
     if(p)
     {
          if(n<p->data)
          build(p->lchild,n);
          if(n>p->data)
          build(p->rchild,n);
     }
     else
     {
         p=new node;
         p->data=n;
         p->lchild=NULL;
         p->rchild=NULL;
     }
}    
void find(tree w,int x)
{
     if(w==NULL)bianliang=-1;
     else if(x==w->data)
       bianliang=1;
     else if(x<w->data)
       find(w->lchild,x);
     else if(x>w->data)
       find(w->rchild,x);
}
void beforeorder(tree q)
{
   if(q==NULL)return;
     cout<<" "<<q->data;
     beforeorder(q->lchild);
     beforeorder(q->rchild);
}
void midorder(tree q)
{
     if(q==NULL)return;
       midorder(q->lchild);
       cout<<" "<<q->data;
       midorder(q->rchild);    
}
int main()
{
    int num;
    cin>>num;
    root=NULL;
    for(int i=1;i<=num;i++)
    {  
       string order;
       cin>>order;
       if(order=="insert")
       {
            int leaf;
            cin>>leaf;
            build(root,leaf);
       }
       else if(order=="find")
       {
            int puzzle;
            cin>>puzzle;
            find(root,puzzle);
            if(bianliang==1)cout<<"yes"<<endl;
            else if(bianliang==-1)cout<<"no"<<endl;
       }
       else if(order=="print")
       {
            midorder(root);
            cout<<endl;
            beforeorder(root);
            cout<<endl;
       } 
    }
    return 0;
}

Measured memory_bytes: 15504
"use strict"
 
function Main(s) {
  s = s.trim().split('\n');
  s.shift();
  const robos = s;
 
  const l = robos.map(robo => {
    let t = robo.split(' ').map(Number);
    return [t[0]-t[1], t[0]+t[1]];
  })
  l.sort((a, b) => a[1] - b[1]);

  let range =-1e10;
  let cnt = 0;
  for(let i=0; i <l.length; ++i){
    const min = l[i][0];
    const max = l[i][1];

    if(range <= min) {
      range = max;
      cnt++;
    }
  }
 
  console.log(cnt);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 52724
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <bitset>
using namespace std;
typedef long long int lli;
int main(void)
{
    int a[3];
    for (int i = 0; i < 3; i++)
    {
        cin >> a[i];
    }
    sort(a, a + 3);
    cout << a[1] - a[0] + a[2] - a[1] << endl;
    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define INF (ll)1000000000

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

    int w[N], v[N];
    for(int i=0; i<N; i++){
        cin >> w[i] >> v[i];
    }

    ll max_v = v[0];
    for(int i=1; i<N; i++){
        max_v += v[i];
    }

    ll val[N+1][max_v+1];
    for(int i=0; i<N+1; i++){
        for(int j=0; j<max_v+1; j++){
            val[i][j] = INF;
        }
    }

    for(int i=0; i<N+1; i++){
        val[i][0] = 0;
    }

    for(int i=0; i<N; i++){
        for(int j=0; j<max_v; j++){
            if(j-v[i]+1 >= 0)
                chmin(val[i+1][j+1], val[i][j-v[i]+1]+w[i]);
            
            chmin(val[i+1][j+1], val[i][j+1]);
        }
    }

    ll ans = 0;
    for(ll v=0; v<max_v; v++){
        if(val[N][v+1] <= W){
            chmax(ans, v+1);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
typedef vector<vi> vvi;
typedef vector<ll> vl;
 
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
	string s;cin>>s;
  	if(s=="ABC")cout<<"ARC";
  else cout<<"ABC";
}

Measured memory_bytes: 3664
#include<iostream>
#include<algorithm>
using namespace std;
const int mod=1000000007;
long dp[201][100001];

int main(){
	int n;
	int x;
	cin >> n >> x;
	int s[n];
	for(int i=0;i<n;i++) cin >> s[i];
	sort(s,s+n);
	reverse(s,s+n);
	
	dp[0][x]=1;
	for(int i=0;i<n;i++){
		for(int j=0;j<=x;j++){
			(dp[i+1][j%s[i]]+=dp[i][j])%mod;
			(dp[i+1][j]+=dp[i][j]*(n-1-i)%mod)%mod;
		}
	}
	long ans=0;
	for(int i=0;i<=x;i++) (ans+=dp[n][i]*i%mod)%mod;
	cout << ans%mod << endl;
	return 0;
}


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

int main() {
    string str;
    cin >> str;
    if(str == "SUN")
    {
        cout << 7;
    }
    else if(str == "MON")
    {
        cout << 6;
    }
    else if(str == "TUE")
    {
        cout << 5;
    }
    else if(str == "WED")
    {
        cout << 4;
    }
    else if(str == "THU")
    {
        cout << 3;
    }
    else if(str == "FRI")
    {
        cout << 2;
    }
    else if(str == "SAT")
    {
        cout << 1;
    }
    
	
	return 0;
}


Measured memory_bytes: 256
use proconio::input;

#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::ops::*;

#[derive(Clone, Debug, Default)]
struct Struct;

//#[proconio::fastout]
fn main() {
    input! {
        s: usize,
        w: usize,
    }

    println!("{}", if s <= w { "unsafe" } else { "safe" });
}


Measured memory_bytes: 2140
package main

import (
	"fmt"
)

func getNum(n, k int) int {
	if n <= k {
		return 1
	} else {
		return 1 + getNum(n-k+1, k)
	}
}

func main() {
	var N, K int
	fmt.Scan(&N, &K)
	A := make([]int, N)
	tmp := 0
	for i := 0; i < N; i++ {
		fmt.Scan(&tmp)
		A = append(A, tmp)
	}
	fmt.Println(getNum(N, K))
}


Measured memory_bytes: 8576
#include <bits/stdc++.h>
#define N 12
using namespace std;
typedef long long ll;
bool used[N];
  
ll SumD(ll a,ll d,ll n){return (n*(2*a+(n-1)*d))/2;}
  
bool mark(ll n){
  bool res=1;
  for(ll i=1;i*i<=N;i++)res&=!used[i],used[i]=1;
  return res;
}
  
int main(){
  while(1){
    ll n,m,p[21];
    cin>>n>>m;
    if(!n&&!m)break;
    for(int i=0;i<m;i++)cin>>p[i];
    sort(p,p+m);
    
    ll sum=0,cnt=0;
    for(int i=0;i<m;i++){
      sum+=SumD(p[i],p[i],n/p[i]);
      cnt+=n/p[i];
      memset(used,0,sizeof(used));
      for(int j=0;j<i;j++){
    ll lcm=(p[i]/__gcd(p[i],p[j]))*p[j];
    if(!mark(lcm))continue;
    sum-=SumD(lcm,lcm,n/lcm);
    cnt-=(n/lcm);
      }
    }
    printf("%.8f\n",(1.0*SumD(1,1,n)-sum)/max(1LL,(n-cnt)));
  }
  return 0;
}

Measured memory_bytes: 3184
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <tuple>
using namespace std;

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

#define max_n 100

int N;
vector<int> A;
vector<int> B;
vector<int> C;

long long d[100005];

int main() {

	cin >> N;

	rep(i, N) {
		int j;
		cin >> j;
		A.push_back(j);
	}
	rep(i, N) {
		int j;
		cin >> j;
		B.push_back(j);
	}
	rep(i, N) {
		int j;
		cin >> j;
		C.push_back(j);
	}

	int ans = 0,pre = -10;
	rep(i, N) {
		ans += B.at(A.at(i) - 1);
		if (pre + 1 == A.at(i))ans += C.at(pre-1);
		pre = A.at(i);
	}
	//get<0>(t);
	cout << ans <<endl;

	return 0;	
}

Measured memory_bytes: 256
/* *****fireice**** */

#include<bits/stdc++.h>

#define ll long long int
#define ld long double
#define vi vector<int>
#define vc vector<char>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define vll vector<pair<ll,ll>>
#define pii pair<int,int>
#define pb push_back
#define eb emplace_back
#define el '\n'
#define N 1000000007
#define re return
#define F first
#define S second
#define L length
#define deb(x) cout<<#x<<" "<<x<<el;
#define mp make_pair
#define PI 3.14159265
#define all(a) (a).begin(),(a).end()
#define forup(i,n) for(int i=0;i<n;i++)
#define forf(i,x,n) for(int i=x;i<n;i++)
#define ford(i,n) for(int (i)=(n)-1;i>=0;(i)--)
#define take(a,n) forup(i,n) cin>>a[i];
using namespace std;

int gcdExtended(int a, int b, int *x, int *y)
{
    // Base Case
    if (a == 0)
    {
        *x = 0, *y = 1;
        return b;
    }

    int x1, y1; // To store results of recursive call
    int gcd = gcdExtended(b%a, a, &x1, &y1);

    // Update x and y using results of recursive
    // call
    *x = y1 - (b/a) * x1;
    *y = x1;

    return gcd;
}

ll modInverse(int a, int m)
{
    int x, y;
    int g = gcdExtended(a, m, &x, &y);
        // m is added to handle negative x
    ll res = ((ll)x%m + (ll)m) % m;

    return res;
}

ll poww(ll x,ll n)
{
    if(n==0)
        return 1;
    else if(n==1) return x;
    else if(n%2 == 0)        //n is even
        return poww(x*x,n/2);
    else                              //n is odd
        return x*poww(x*x,(n-1)/2);
}

ll modularExponentiation(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}

template<typename T>
T maxx(T a,T b)
{
  if(a<b) re b;
  re b;
}
template<typename T, typename... Args>
T maxx(T a,T b, Args... args)
{
    re(maxx(maxx(a,b),args...));
}

template<typename T>
T minn(T a,T b)
{
  if(a<b) re a;
  re b;
}
template<typename T, typename... Args>
T minn(T a,T b, Args... args)
{
    re(minn(minn(a,b),args...));
}

template<typename T>
void read(T& a)
{
  cin>>a;
}
template<typename T, typename... Args>
void read(T& a,Args&... args)
{
  cin>>a; read(args...);
}

template<typename T>
void write(T a)
{
  cout<<a<<' ';
}
template<typename T, typename... Args>
void write(T a,Args... args)
{
  cout<<a<<' '; write(args...);
}

inline ll min(ll a,ll b)
{
  if(a<b) re a;
  else re b;
}
inline ll max(ll a,ll b)
{
  if(a<b) re b;
  else re a;
}

ll gcd(ll a, ll b)
{
    if (a == 0)
       return b;
    if (b == 0)
       return a;

    if (a == b)
        return a;

    if (a > b)
        return gcd(a-b, b);
    else return gcd(a, b-a);
}

ll ncr(int n,int r)
{
  ll ans=1;
  r=min(r,n-r);
  forup(i,r)
  {
    ans=((ans*((n-i)%N))%N*modInverse(i+1,N))%N;
  }
  re ans;
}

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

  int t=1;
  //cin>>t;
  while(t--)
  {
    ll n,m,k;
    cin>>n>>m;k=0;
    forup(i,m)
    {
      int a;
      cin>>a;
      k+=a;
    }
    cout<<max(-1,n-k);

  }


  return 0;
}


Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();

        String ans = "";
        int tmp1 = y - 2 * x;
        int tmp2 = 4 * x - y;
        if (tmp1 % 2 == 0 && x - (tmp1 / 2) >= 0 && tmp2 % 2 == 0 && (x - tmp2 / 2) >= 0) ans = "Yes";
        else ans = "No";

        System.out.println(ans);
    }
}

Measured memory_bytes: 35768
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>pii;
typedef vector<int>vi;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define fi first
#define se second
#define de(x) cout<<#x<<"="<<x<<endl;
#define dd(x) cout<<#x<<"="<<x<<" " ;
#define pb(x) push_back(x)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
const int N=2e6+5;
int n;
ll a[N],b[N];
int main()
{

	cin>>n;
	
	rep(i,1,n+2)
		cin>>b[i];
	rep(i,1,n+1)
		cin>>a[i];
	ll ans=0;
	rep(i,1,n+1){
		ans+=min(b[i],a[i]);
		a[i]-=min(b[i],a[i]);
		ans+=min(b[i+1],a[i]);
		b[i+1]-=min(b[i+1],a[i]);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 5120
#include<stdio.h>
#include<iostream>
using namespace std;

int commondiviser(int n, int m) {
  while(m != 0) {
    int t = 0;
    if (m > n) {
      t = m;
      m = n;
      n = t;
    }
    n = n - m;
  }
  return n;
}

int main() {
  int a, b, c;
  cin >> a >> b;
  c = commondiviser(a, b);
  cout << c << endl;
  return 0;
}


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

int main()
{
	string S, T;

	cin >> S >> T;
	bool b = true;
	for (int i = 0; i < S.size(); ++i)
	{
		if (S[i] != T[i])
		{
			b = false;
			break;
		}
	}

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

	return 0;
}

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

int main(){
    int n, a, b; cin >> n;
    vector<int>s;

    while(n){
        cin >> a;
        if(a==0){
            cin >> b;
            s.push_back(b);
        } else if (a==1) {
            cin >> b;
            cout << s.at(b) << endl;
        } else {
            s.pop_back();
        }
        n--;
    }

    return 0;
}


Measured memory_bytes: 3868
def main():
    S = input()
    ans = "AKIHABARA"
    ls1 = ["AKIHABARA","KIHABARA","AKIHBARA","AKIHABRA","AKIHABAR"]
    ls2 = ["KIHBARA","KIHABRA","KIHABAR","AKIHBRA","AKIHBAR","AKIHABR"]
    ls3 = ["KIHBRA","KIHABR","KIHBAR","AKIHBR"]
    ls4 = ["KIHBR"]
    ls = ls1+ls2+ls3+ls4

    if S in ls:
        print("YES")
    else:
        print("NO")
if __name__ == "__main__":
    main()

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

void solve_abc151() {
	ll N, M;
	string C;
	char ans;
	cin >> C;

	ans = C[0] + 1;

	cout << ans << "\n";
}

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

	solve_abc151();

	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    static class Node {
        final int id;

        final List<Node> links = new ArrayList<>();

        Node(int id) {
            this.id = id;
        }

        void connect(Node n) {
            this.links.add(n);
            n.links.add(this);
        }
    }

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();

        Node[] nodes = new Node[n];
        for (int i = 0; i < n; ++i) {
            nodes[i] = new Node(i);
        }

        for (int i = 0; i < m; ++i) {
            int a = scan.nextInt() - 1;
            int b = scan.nextInt() - 1;

            nodes[a].connect(nodes[b]);
        }

        int fullbits = (1 << n) - 1;
        int count = dfs(nodes[0], 0, fullbits);
        System.out.println(count);
    }

    public static int dfs(Node n, int bits, int fullbits) {
        int count = 0;
        int bits1 = bits | (1 << n.id);
        if (bits1 == fullbits) {
            return 1;
        }
        for (Node n1 : n.links) {
            if ((bits1 & (1 << n1.id)) == 0) {
                count += dfs(n1, bits1, fullbits);
            }
        }
        return count;
    }

}


Measured memory_bytes: 22356
import sys, math
from collections import defaultdict
from copy import deepcopy
import itertools
input = sys.stdin.readline
# 文字列の場合は普通のinput()を使うか下を使う
# input = sys.stdin.readline().rstrip()

N = int(input())
A = list(map(int, input().split()))
for i, a in enumerate(A):
    a = bin(a)[2:]
    l = len(a)
    A[i] = '0' * (60 - l) + a
mod = 10**9 + 7

ans = 0
for i in range(60):
    num_0 = 0
    num_1 = 0
    for a in A:
        if a[-i-1] == '1':
            num_1 += 1
        else:
            num_0 += 1
    ans += (num_0 * num_1) * (2 ** i)
    ans %= mod

print(ans)        
    

Measured memory_bytes: 134712
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int n;
int a[200010],b[200010];
int x,ans,posa,posb,c[200010];
int calc(int x)
{
	long long tot=0;
	int nw=n;
		for (int i=1;i<=n;i++)
		{
			while (nw&&a[i]+b[nw]>=x) nw--;
			tot+=n-nw;
		}
	return tot%2;
}
void gba(int pos)
{
	int l1=1,l2=pos,cnt=0;
	while (l1<pos&&l2<=n)
	{
		if (a[l1]<a[l2]) c[++cnt]=a[l1],l1++;
		else c[++cnt]=a[l2],l2++; 
	}
	while (l1<pos) c[++cnt]=a[l1],l1++;
	while (l2<=n) c[++cnt]=a[l2],l2++;
	for (int i=1;i<=n;i++) a[i]=c[i];
}
void gbb(int pos)
{
	int l1=1,l2=pos,cnt=0;
	while (l1<pos&&l2<=n)
	{
		if (b[l1]<b[l2]) c[++cnt]=b[l1],l1++;
		else c[++cnt]=b[l2],l2++; 
	}
	while (l1<pos) c[++cnt]=b[l1],l1++;
	while (l2<=n) c[++cnt]=b[l2],l2++;
	for (int i=1;i<=n;i++) b[i]=c[i];
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=1;i<=n;i++) scanf("%d",&b[i]);
	sort(a+1,a+1+n);sort(b+1,b+1+n);
	for (int len=28;len>=0;len--)
	{
		posa=posb=n+1;
		for (int i=1;i<=n;i++)
		{
			if (((a[i]>>len+1)&1)&&(posa==n+1)) posa=i;
			if (((b[i]>>len+1)&1)&&(posb==n+1)) posb=i;
			a[i]=a[i]-((a[i]>>len+1)<<len+1);
			b[i]=b[i]-((b[i]>>len+1)<<len+1);
		}
		gba(posa),gbb(posb);
		//cout<<posa<<endl;
		//for (int i=1;i<=n;i++) cout<<a[i]<<" ";cout<<endl; 
		if ((calc(1<<len)+calc(1<<len+1)-calc((1<<len)*3)+2)%2) ans+=1<<len;
		
	}
	printf("%d",ans);
} 

Measured memory_bytes: 2560