akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

int main() {
    int a, b, c;
    std::cin >> a >> b >> c;

    int max = std::max(a, std::max(b, c));

    if(a + b + c - max == max) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<string.h>
#include<functional>
#include<set>
#include<string>
#include<bitset>
//aoj 0121
using namespace std;
char zzzt[8]={0,1,2,3,4,5,6,7};
char bj[8];
char vis[80000000/8];
#define ck(x)   (vis[(x)>>3]&(1<<((x)&7)))
#define sb(x)   (vis[(x)>>3]|=(1<<((x)&7)))
#define cb(x)   (vis[(x)>>3]&=~(1<<((x)&7)))
struct pt{
	int ztt;
	int lwz;
	int step;
};
int bs;
pt dl[1<<16];
int front=1,back=1;
int tt;
int ddd[8]={10000000,1000000,100000,10000,1000,100,10,1};
void bfs()
{
	tt=0;
	front=1;
	back=1;
	bs=0;
	memset(vis,0,sizeof(vis));
	
	int cs=atoi(bj);
	sb(cs);
	pt lsss;
	lsss.ztt=cs;
	lsss.lwz=strchr(bj,'0')-bj;
	lsss.step=0;
	dl[back]=lsss;
	back++;
	while(front<back)
	{
		pt ls1=dl[front];
		front++;
		if(ls1.ztt==1234567)
		{
			bs=ls1.step;
			tt=1;
			return;
		}
		pt lsjr;
		int kkk[4]={-1,1,-4,4};
		for(int i=0;i<4;i++){
			lsjr.lwz=ls1.lwz+kkk[i];
			if((ls1.lwz==3&&lsjr.lwz==4) || (ls1.lwz==4&&lsjr.lwz==3)) continue;
			if(lsjr.lwz>=0&&lsjr.lwz<=7){
					int  a,b;
					a=ls1.ztt/ddd[ls1.lwz]%10;
					b=ls1.ztt/ddd[lsjr.lwz]%10;
					lsjr.ztt=ls1.ztt+(b-a)*ddd[ls1.lwz]+(a-b)*ddd[lsjr.lwz];
					if(!ck(lsjr.ztt))
					{
						lsjr.step=ls1.step+1;
						sb(lsjr.ztt);
						dl[back]=lsjr;
						back++;
					}
			}
		}
	}
}
int main()
{
//	freopen("in","r",stdin);
	while(1)
	{
		if(scanf("%c",&bj[0])==EOF)
		{
			return 0;
		}
		scanf("%*c");
		for(int i=1;i<=6;i++)
		{
			scanf("%c%*c",&bj[i]);
		}
		scanf("%c",&bj[7]);
		bfs();
		if(tt)
		{
			printf("%d\n",bs);
		}else{
			printf("-1\n");
		}
		while(getchar()!='\n');
	}
	return 0;
}



Measured memory_bytes: 12656
#include <stdio.h>

int main(void){
    int n = 0;
    int co = 0;
    int i;
    
    scanf("%d", &n);
    int a[n+1];

    for(i = 1; i <=  n; i++){
        scanf("%d", &a[i]);
    }

    for(i = 1; i <= n; i++){
        if(i % 2 != 0 && a[i] % 2 != 0)
            co++;
    }

    printf("%d \n", co);

    return 0;
}

Measured memory_bytes: 1700
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <stdio.h>

using namespace std;

#define fo(i,n) for(int i=0; i<(int)n; i++)
#define rep(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
#define mp(a,b) make_pair(a,b)
#define pb(x) push_back(x)
#define pii pair<int,int>

set<pair<int,int> > s;

int main() {

    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

	int t;
	cin>>t;
	while (t--) {
		int n,m;
		cin>>n>>m;
		
		int k = n*n + m*m;
		
		int c = 0;
		s.clear();
		for (int i=0; i*i<=k; i++) {
			for (int j=0; i*i+j*j<=k; j++) {
				if (i*i+j*j<=1) continue;
				
				for (int x=-1; x<2; x+=2) for (int y=-1; y<=1; y+=2) {
					
					if (s.find(mp(x*i,y*j))!=s.end()) continue;
					s.insert(mp(x*i,y*j));
				
					int mod = i*i + j*j;
					int real = x*n*i - y*m*j;
					int im = x*n*j + y*m*i;
					
					if (real%mod==0 && im%mod==0) {
						c++;
						//cout<<x*i<<" "<<y*j<<endl;
					}
				}
			}
		}
		
		if (c>4) cout<<"C"<<endl;
		else cout<<"P"<<endl;
	}
	
    return 0;

}

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

using namespace std;

/**
 *  Name: Chris M. Perez
 *  University: Interamerican University Metro Campus
 *
**/

#define endl '\n'
#define MOD 10e18
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define gcd(x , y) __gcd(x , y)
#define all(x) (x).begin() , (x).end()
#define forn(i , a , b) for(int i=(a);i<(b);i++)
#define forrange(j , a , b) for(int j=(a);j<=(b);j++)
#define nestedforn(i , a , b , j , c , d) for(int i=(a);i<=(b);i++) for(int j=(c);j<=(d);j++)
#define sort_all(x) sort(all(x))
#define zeros_at_beginning(x) __builtin_clz(x)
#define zeros_at_end(x) __builtin_ctz(x)
#define ones(x) __builtin_popcount(x)
#define parity_even_or_odd_ones __builtin_parity(x)

typedef vector<int> vi;
typedef pair<int , int> pii;
typedef tuple<int , int , int> tiii;
typedef vector<pii> vpii;
typedef vector<tiii> vtiii;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef long long ll;
typedef long long int lli;


//template< typename T1, typename T2 > struct pair {
  //T1 first;
  //T2 second;
//};
               
inline int input(){
  int n;
  scanf("%d" , &n);
  return n;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(10);
  cout << fixed;

#ifdef LOCAL_DEFINE
  freopen("input.txt" , "rt" , stdin);
#endif
 
   string s; cin >> s;
   if(!(s.size() % 2 == 0)){
     reverse(all(s));
     cout << s << endl;
   }else{
     cout << s << endl;
   }

   
 
#ifdef LOCAL_DEFINE
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	int n;
	cin>>n;
	vector<int>arr(n);
	for(int i=0;i<n;i++)
		cin>>arr[i];
	ll prin=1000;ll stock=0;
	for(int i=0;i<n-1;i++){
		if(arr[i+1]-arr[i]<=0)continue;
		stock =prin/arr[i];
		prin-=stock*arr[i];
		prin+=stock*(arr[i+1]);
	}
	cout<<prin;
	return 0;
}



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

using namespace std;

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

#define ALL(obj)	(obj).begin(),(obj).end()

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;

typedef pair<int,int>			P;

#define LINF		((ll)1 << 63 -1)
#define INF 		2000000007
#define MINF		-2000000007
#define MAX 		100005

const int MOD = 1e9+7;
// テンプレ終了
//====================================================================//


//
int main(){
	int N;cin>>N;
	string s;cin>>s;

	int r=0;
	int suml=0;
	REP(i,N){
		if(s[i] == '('){
			if(suml < 0){r+=abs(suml);suml=1;}
			else suml++;
		}else{
			--suml;
		}
	}
	//cout << r << " " << suml << endl;
	if(suml<0){r+=abs(suml);suml=0;}
	REP(i,r)cout << '(';
	cout << s;
	REP(i,suml)cout << ')';

	return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD	1000000007
#define int	long long
#define pii pair<int,int> 
#define vi vector<int>
using namespace std;


double dp[3002][3002];

int32_t main(){
	int n;
	cin >> n;
	// prob of more heads
	dp[0][0] = 1;
	for(int i = 1; i <= n; i++){
		double p;
		cin >> p;
		for(int j = 0; j <= i; j++){
			if(j == 0){
				dp[i][0] = dp[i-1][0] * (1.0 - p);
			}
			else{
				dp[i][j] = dp[i-1][j] * (1.0 - p) + dp[i-1][j-1] * p;
			}
		}
	}
	double ans = 0.0;
	
	for(int i = (n+1)/2; i <= n; i++)
		ans += dp[n][i];
		
	cout << fixed << setprecision(10) << ans << endl;


	return 0;
}



Measured memory_bytes: 68992
package main

import (
	"fmt"
	"os"
	"bufio"
	"strconv"
)

var N int
var A [][]int
var t int
var color, d, f []int

const (
	WHITE = iota
	GRAY
	BLACK
)

func dfsVisit(u int) {
	color[u] = GRAY
	t ++
	d[u] = t
	for v:=0; v<N; v++ {
		if A[u][v] == 0 {
			continue
		}
		if color[v] == WHITE {
			dfsVisit(v)
		}
	}
	color[u] = BLACK
	t++
	f[u] = t
}

func dfs() {
	for u:=0; u<N; u++ {
		if color[u] == WHITE {
			dfsVisit(u)
		}
	}
	for u:=0; u<N; u++{
		fmt.Printf("%d %d %d\n", u+1, d[u], f[u])
	}
}


func nextInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	num, _ := strconv.Atoi(scanner.Text())
	return num
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	N = nextInt(scanner)
	color = make([]int, N)
	d = make([]int, N)
	f = make([]int, N)
	A = make([][]int, N)
	for i:=0; i<N; i++{
		A[i] = make([]int, N)
	}
	for i:=0; i<N; i++{
		index := nextInt(scanner) - 1
		cnt := nextInt(scanner)
		for j:=0; j<cnt; j++ {
			v := nextInt(scanner) - 1
			A[index][v] = 1
		}
	}
	dfs()
}





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

// const double PI = acos(-1.0); 

void solve();

void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
}

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

    // int t; 
    // cin >> t;

    // while (t--) 
    solve(); 

    return 0;
}

void solve()
{
    vector <int> x(5);
    int ans;

    for (int i = 0; i < 5; ++i)
    {
        cin >> x[i];
        if (x[i] == 0)
        {
            ans = i + 1;
        }
    }


    cout << ans << "\n"; 

}

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

using namespace std;

#define long long long
#define INF (long) 1e18
#define MOD 1'000'000'007
#define mll map<long, long>
#define pll pair<long, long>
#define umap unordered_map
#define umll umap<long, long>
#define uset unordered_set
#define pb push_back
#define FOR(i, a, b) \
  for (long i = (a); i < (long) (b); i++)

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

  long n;
  cin >> n;

  mll d;
  while (n--) {
    string x;
    cin >> x;
    d[x[0]]++;
  }
  string s = "MARCH";
  sort(s.begin(), s.end());
  long total = 0;
  FOR (i, 0, 5) {
    FOR (j, i+1, 5) {
      FOR (k, j+1, 5) {
        long x = d[s[i]] * d[s[j]] * d[s[k]];
        total += x;
      }
    }
  }
  printf("%lld\n", total);
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;


int main(int argc, char* argv[])
{
    char str0[5]={0};
    char str1[5]={0};
    scanf("%s", str0);
    scanf("%s", str1);
    
    int cnt=0;
    int i;
    for(i=0; i<3; i++) {
        if(str0[i]==str1[i]) cnt++;
    }
    printf("%d\n", cnt);









    return 0;
}


Measured memory_bytes: 128
/*
Code by b21
Time: 19:08 Sun 01/03/2020
*/

#include <bits/stdc++.h>

using namespace std;

const int mn = 1 * (int)(1e5) + 10;
const int mod = 1 * (int)(1e9) + 7;
const int mm = 1 * (int)(1e3) + 10;
const int base = 1 * (int)(1e9);
const bool aNs = 0;

int tt, ntest = 1;
void docfile()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    if (ifstream("test.inp"))
    {
       freopen("test.inp", "r", stdin);
       if (!aNs) freopen("test.out", "w", stdout);
       else freopen ("test.ans", "w", stdout);
    }
   else if (ifstream("abc157_c.inp"))
    {
        freopen("abc157_c.inp", "r", stdin);
        freopen("abc157_c.out", "w", stdout);
    }
}

template <typename T>
void read(T& x)
{
    x = 0; T f = 1;
    char ch = getchar();
    while (!isdigit(ch)) f = ch == '-' ? - f : f, ch = getchar();
    while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
    x *= f;
}

template <typename T>
void write (T a)
{
    if (a < 0)
    {
        putchar ('-');
        write (-a);
        return;
    }
    if (a < 10)
    {
        putchar ('0' + a);
        return;
    }
    write (a / 10);
    putchar ((char)('0' + (a % 10)));
}

int ok[7];

void enter()
{
    int n, m;
    cin >> n >> m;
    memset (ok, - 1, sizeof (ok));
    for (int i = 0; i < m; ++ i) {
        int x, y;
        cin >> x >> y;
        -- x;
        if (ok[x] != - 1 && ok[x] != y) {
            cout << - 1;
            return;
        }
        ok[x] = y;
    }
    for (int i = 0; i < 1000; ++ i) {
        int x = i;
        vector<int> v;
        if (!x) v.emplace_back(0);
        while (x) {
            v.emplace_back(x % 10);
            x /= 10;
        }
        if (v.size() != n) continue;
        bool Ok = 1;
        reverse(v.begin(), v.end());
        for (int i = 0; i < v.size(); ++ i)
        if (ok[i] != - 1 && v[i] != ok[i]) Ok = 0;
        if (Ok) {
            cout << i;
            return;
        }
    }
    cout << - 1;
}

void solve()
{

}

void print_result()
{

}

main()
{
    docfile();
    //cin>>ntest;
    for (tt = 1; tt <= ntest; ++ tt)
    {
        enter();
        solve();
        print_result();
    }
}

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

using namespace std;

int main(){

	int m, d, d1, d2, ans=0;

	cin>> m >> d;

	for(int i=1;i<=m;i++){
		for(int j=1;j<=d;j++){
			d1=j%10;
			d2=j/10;
			if(d1<2 || d2<2) continue;
			if(i==d1*d2) ans++;
		}
	}

	cout<< ans << endl;

}

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

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main(){
  string s;
  int n,i,ans=0;
  cin >> n >> s;
  for(i=0;i<n-2;i++){
      if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
        ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3600
class Cmb:
    def __init__(self, N, mod=998244353):
        self.fact = [1,1]
        self.fact_inv = [1,1]
        self.inv = [0,1]
        
        """ 階乗を保存する配列を作成 """
        for i in range(2, N+1):
            self.fact.append((self.fact[-1]*i) % mod)
            self.inv.append((-self.inv[mod%i] * (mod//i))%mod)
            self.fact_inv.append((self.fact_inv[-1]*self.inv[i])%mod)
    
    """ 関数として使えるように、callで定義 """
    def __call__(self, n, r, mod=998244353):
        if (r<0) or (n<r):
            return 0
        r = min(r, n-r)
        return self.fact[n] * self.fact_inv[r] * self.fact_inv[n-r] % mod

n,m,k = map(int,input().split())
mod = 998244353
ans = 0
c = Cmb(N=n, mod=mod)
for x in range(k+1):
    if x==0:
        ans += m*pow(m-1, n-1, mod)
        ans %= mod
    else:
        ans += m*pow(m-1, n-1-x, mod)*c(n-1, x)%mod
        ans %= mod
print(ans%mod)

Measured memory_bytes: 112376
N,K = map(int,input().split())
A = list(map(int,input().split()))
n = 1
B = [0]*N
state = 0
for i in range(2*N+1):
    if i == K:
        state = 1
        break
    B[n-1] = i+1
    n = A[n-1]
    if B[n-1] != 0:
        t = i+2
        break
if state:
    print(n)
else:
    c = t-B[n-1]
    s = (K+1-t)%c
    for i in range(s):
        n = A[n-1]
    print(n)

Measured memory_bytes: 32300
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))



int main(){
    ll ans,n;
    cin>>n;
    string s,t;
    cin>>s>>t;

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

    cout <<endl;

    return 0;

}

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

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

  map<string,int> mp;
  for(int i=0; i<n; i++){
    string s;
    cin >> s;
    mp[s]++;
  }
  int mx = 0;
  for(auto p : mp) mx = max(mx, p.second);
  for(auto p : mp) {
    if(p.second != mx) continue;
    cout << p.first << endl;
  }
  
  return 0;
}

Measured memory_bytes: 25216
S = []
while len(S) < 1 or len(S) > 200000:
    S = raw_input()

Slist = list(S)
i=0
a = len(Slist)
z = -1
for s in Slist:
    if s == 'A':
        if a > i:
            a = i
    if s == 'Z':
        if z < i:
            z = i
    i += 1
            
if z > a:
    print z - a + 1

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

#ifndef ONLINE_JUDGE
#define debarr(a,x,y)cerr<<#a<<":";for(int i=x;i<=y;i++)cerr<<a[i]<<" ";cerr<<endl;
#define debmat(mat,row,col)cerr<<#mat<<":\n";for(int i=0;i<row;i++){for(int j=0;j<col;j++)cerr<<mat[i][j]<<" ";cerr<<endl;}
#define deb(...)dbs(#__VA_ARGS__,__VA_ARGS__)
template<class S, class T>ostream &operator<<(ostream &os, const pair<S, T> &p) {return os << "(" << p.first << "," << p.second << ")";}
template<class T>ostream &operator<<(ostream &os, const vector<T> &p) {os << "["; for (auto&it : p)os << it << " "; return os << "]";}
template<class T>ostream &operator<<(ostream &os, const set<T>&p) {os << "["; for (auto&it : p)os << it << " "; return os << "]";}
template<class T>ostream &operator<<(ostream &os, const multiset<T>&p) {os << "["; for (auto&it : p)os << it << " "; return os << "]";}
template<class S, class T>ostream &operator<<(ostream &os, const map<S, T>&p) {os << "["; for (auto&it : p)os << it << " "; return os << "]";}
template<class T>void dbs(string str, T t) {cerr << str << ":" << t << "\n";}
template<class T, class...S>void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << ":" << t << ","; dbs(str.substr(idx + 1), s...);}
#else
#define deb(...){}
#define debarr(a,x,y){}
#define debmat(mat,row,col){}
#endif
template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }
#define pr(x) {cout << x << "\n"; return;}

#define int              long long
#define ll               long long
#define ld               long double
#define fi               first
#define se               second
#define mp               make_pair
#define pb               push_back
#define sz(x)            (int)x.size()
#define all(x)           x.begin(),x.end()
#define ini(x,y)         memset(x,y,sizeof(x))
#define rep(i,n)         for(int i=0;i<n;i++)
#define re(i,n)          for(int i=1;i<=n;i++)
#define fr(i,a,b)        for(int i=a;i<=b;i++)
#define fb(i,a,b)        for(int i=a;i>=b;i--)
typedef pair<int, int>   pii;
typedef vector<int>      vi;
typedef vector<pii>      vii;
typedef map<int, int>    mii;
typedef set<int>         si;
const int N = 2e5 + 10;

void solve(int tc)
{
	int n, k, t;
	cin >> n >> k >> t;
	cout << t * ((n + k - 1) / k) << endl;
}
signed main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int t = 1;
	//cin >> t;
	for (int i = 1; i <= t; i++) solve(i);
	return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
#define MAX 100001
#define INF 100000
#define ll long long
#define forall(i,a,b) for(int i = a; i < b; ++i)
#define sd(s) scanf("%d", &s);
#define ss(s) scanf("%s", )
#define sll(s) scanf("%lld", &s);

using namespace std;

struct edge {
	int dest;
	ll cost;
};

int N, Q, K;
bool Visit[MAX];
ll dist[MAX];
vector <edge> Edge[MAX];
queue <int> q;

int main() {
	int u, v;
	ll c;

	sd(N);
	forall(i, 0, N - 1) {
		sd(u);
		sd(v);
		sll(c);
		Edge[u].push_back(edge{ v, c });
		Edge[v].push_back(edge{ u, c });
	}

	sd(Q);
	sd(K);

	Visit[K] = true;
	dist[K] = 0;
	q.push(K);

	while (!q.empty()) {
		int n = q.front();
		q.pop();

		forall(i, 0, Edge[n].size()) {
			edge e = Edge[n][i];
			if (!Visit[e.dest]) {
				q.push(e.dest);
				dist[e.dest] = dist[n] + e.cost;
				Visit[e.dest] = true;
			}
		}
	}

	forall(i, 0, Q) {
		sd(u);
		sd(v);
		//cout << dist[u] << " " << dist[v] << endl;
		printf("%lld\n", dist[u] + dist[v]);
	}
}

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

int main(){
    string s; cin >> s;
    int max_len = 0;
    int a_ids =0, z_ids =0;
    bool flg = false;
    for(int i=0; i<s.length();i++){
        if(s.at(i)=='A' && flg==false){
            flg = true; a_ids = i;
        }
        if(s.at(i) == 'Z'){
            z_ids =i;
        }
    }
    max_len = z_ids - a_ids + 1;

    cout << max_len << endl;
    return 0;
}

Measured memory_bytes: 3776
#include <stdio.h>
#include <stdlib.h>
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

int asc(const void *a, const void *b) {
   return *(int *)a - *(int *)b;
}

int main(void){
   int N,K;
   int L[100000+1];
   int ans = 1000000010;
   scanf("%d%d", &N,&K);
   for (int i = 0; i < N; i++) {
      scanf("%d", &L[i]);
   }
   qsort(L,N,sizeof (int), asc);
   for (int i = 0; i < N - K +1; i++) {
      ans = MIN(ans,ABS(L[i]-L[i+(K-1)]));
   }
   printf("%d\n",ans);
   return 0;
}


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

using namespace std;

class Solution {
public:
	void solve() {
		while (1) {
			int n;
			cin >> n;
			if (n == 0) return;
			vector<int> d((n * (n - 1)) / 2, 0);
			for (int i = 0; i < (n * (n - 1)) / 2; i++) cin >> d[i];
			vector<int> _cnt(d[0] + 1);
			vector<int> _x(n, -1);
			for (int i = 0; i < (n * (n - 1)) / 2; i++) _cnt[d[i]]++;
			_x[0] = 0;
			_x[n - 1] = d[0];
			_cnt[d[0]]--;
			vector<vector<int> > ans;
			for (int i = 0; i < (1 << (n - 2)); i++) {
				bool ok = true;
				vector<int> x(_x.begin(), _x.end());
				vector<int> cnt(_cnt.begin(), _cnt.end());
				int l = 1, r = n - 2;
				int sh = n - 3;
				for (int j = d[0]; j > 0; j--) {
					while (cnt[j] > 0 && sh >= 0) {
						int id;
						if ((i >> sh) & 1) {
							id = r;
							x[r--] = j;
						} else {
							id = l;
							x[l++] = d[0] - j;
						}
						for (int k = 0; k < n; k++) {
							if (id == k || x[k] == -1) continue;
							if (!cnt[abs(x[id] - x[k])]--) {
								ok = false;
								break;
							}
						}
						sh--;
						if (!ok) break;
					}
					if (!ok) break;
				}
				if (!ok) continue;
				ans.push_back(x);
			}
			sort(ans.begin(), ans.end());
			ans.erase(unique(ans.begin(), ans.end()), ans.end());
			for (int i = 0; i < ans.size(); i++) {
				for (int j = 1; j < n; j++) {
					if (j == 1)
						cout << ans[i][j] - ans[i][j - 1];
					else
						cout << " " << ans[i][j] - ans[i][j - 1];
				}
				cout << "\n";
			}
			cout << "-----\n";
		}
		return;
	};
};

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


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

typedef long long ll;

int a[200010],n;
ll Xor[200010],Plus[200010];

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d",&a[i]);
	for(int i=0;i<n;i++){
		Xor[i+1]=Xor[i]^a[i];
		Plus[i+1]=Plus[i]+a[i];
	}
	ll ans=0;
	for(int start=0;start<n;start++){
		int low=start,high=n-1;
		while(low<high){
			int mid=low+(high-low+1)/2;
			int sum1=Xor[mid+1]^Xor[start];
			int sum2=Plus[mid+1]-Plus[start];
			if(sum1==sum2) low=mid;
			else high=mid-1;
		}
		ans+=low-start+1;
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 4096
#include<stdio.h>
int main(void)
{
    int h1[3],m1[3],s1[3],h2[3],m2[3],s2[3],i,j,k;
    int sum1[3]={0},sum2[3]={0},sa[3]={0};
    for(i=0;i<3;i++){
        scanf("%d %d %d %d %d %d",&h1[i],&m1[i],&s1[i],&h2[i],&m2[i],&s2[i]);
        sum1[i]=h1[i]*3600+m1[i]*60+s1[i];
        sum2[i]=h2[i]*3600+m2[i]*60+s2[i];
        sa[i]=sum2[i]-sum1[i];
        //printf("%d %d %d\n",sum1[i],sum2[i],sa[i]);
    }
    for(i=0;i<3;i++){
        printf("%d %d %d\n",sa[i]/3600,sa[i]%3600/60,sa[i]%3600%60);
        }

    return 0;
}

Measured memory_bytes: 1820
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<utility>
#include<functional>
#include<cfenv>
#include<cmath>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<set>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define vint vector<ll>
#define vvint vector<vint>
#define P pair<ll,ll>
#define INT_MAX 2147483647
#define MOD 998244353
#define PI 3.14159265358979323846
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;

#define MAX 1000000000000

int main(void) {
	int n; cin >> n;
	vector<int> d1(n);
	vector<int> d2(n);
	int cnt=0, ans=0;
	rep(i, n) {
		cin >> d1[i] >> d2[i];
	}
	rep(i, n) {
		if (d1[i] == d2[i]) {
			cnt++;
			ans = max(ans, cnt);
		}
		else {
			cnt = 0;
		}
	}
	if (ans>= 3) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


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

int main(){
    string b;
    cin >> b ;
    if (b == "A"){
        cout << "T" <<endl;
    }
    if (b == "T"){
        cout << "A" <<endl;
        
}
    if (b == "G"){
        cout << "C" << endl;
    }
    if (b == "C"){
        cout << "G" << endl;
    }
}


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

int Parse(string a) {
	int s = 0;
	for (int b = 0; b < a.length(); b++) {
		s *= 10;
		s += a[b] - 48;
	}
	return s;
}
int main() {
	string a;
	while (1) {
		getline(cin, a);
		if (a[0]=='0')break;
		vector<int>s;
		string c="";
		for (int b = 0; b < a.length(); b++) {
			if (a[b] == ' ') { s.push_back(Parse(c)); c = ""; }
			else c += a[b];
		}
		s.push_back(Parse(c));
		int m = 0;
		int n = 0;
		for (int d = 0; d < s.size(); d++) {
			if (s[d] > 9&&s[d]<14)m += 10;
			else if (s[d] > 1)m += s[d];
			else n++;
			if (m > 21) { cout << 0 << endl; goto l; }
		}
		if (m + 10 + n < 22&&n!=0)m += 10 + n;
		else m += n;
		if (m > 21)m = 0;
		cout << m << endl;
	l:;
	}
}

Measured memory_bytes: 3124
#include <iostream>

using namespace std;

long long int N, T[101] = {}, largest = 0, a;

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> T[i];
		if (largest < T[i]) {
			largest = T[i];
		}
	}
	a = largest;
	for (int i = 1; i <= N; i++) {
		while (1) {
			if (a%T[i] == 0) {
				largest = a;
				break;
			}
			a += largest;
		}
	}
	cout << a << endl;
	return 0;
}

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

using namespace std;

int main()
{
	long long a, b, x;
	cin >> a >> b >> x;
	cout << b / x + 1 - (a == 0 ? 0 : (a - 1) / x + 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 x=sc.nextInt();
      	int o=0;
      	int n=x/100;
      	if(x-n*100<=5*n){
        	o=1;
        }
      	System.out.println(o);
    }
}

Measured memory_bytes: 23636
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#define MOD 1000000007
typedef long long ll;
using namespace std;

ll N,A,B,C;

#define MAX_N 200020
ll inv[MAX_N+10],fac[MAX_N+10],ifac[MAX_N+10];

void setComb(){
  inv[0]=1;inv[1]=1;fac[1]=1;ifac[1]=1;fac[0]=1;ifac[0]=1;
  for(int i=2;i<MAX_N;i++){
    inv[i]=(-MOD/i)*inv[MOD%i]%MOD;
    fac[i]=fac[i-1]*i%MOD;
    ifac[i]=ifac[i-1]*inv[i]%MOD;
  }
  return;
}

ll comb(ll n,ll k){
  if(n<k||n<0||k<0) return 0;
  else return ((fac[n]*ifac[k]%MOD*ifac[n-k]%MOD+MOD)%MOD);
}

ll hcomb(ll n,ll r){
  if(n==0&&r==0) return 1;
  else if(n<0||r<0) return 0;
  else return comb(n+r-1,r);
}

int extgcd(int a,int b,int &x,int &y){
  int d=a;
  if(b!=0){
    d=extgcd(b,a%b,y,x);
    y-=(a/b)*x;
  }else{
    x=1;
    y=0;
  }
  return d;
}

int mod_inverse(int a,int m){
  int x,y;
  int z=extgcd(a,m,x,y);
  return(m+x%m)%m;
}


int main(){
  cin>>N>>A>>B>>C;

  setComb();

  int aa=A,bb=B;
  A=A*inv[aa+bb]%MOD;
  B=B*inv[aa+bb]%MOD;

  vector<ll> a(2*N,0),b(2*N,0),ten(2*N,0);
  a[0]=1;
  b[0]=1;
  ten[0]=1;
  for(int i=1;i<=2*N;i++){
      a[i]=a[i-1]*A%MOD;
      b[i]=b[i-1]*B%MOD;
      ten[i]=ten[i-1]*100%MOD;
  }

  ll ans=0;
  for(int i=N;i<=2*N-1;i++){
      ll res=comb(i-1,N-1);
      ll tmp1=a[N]*b[i-N]%MOD;
      ll tmp2=a[i-N]*b[N]%MOD;
      ll tmp=(tmp1+tmp2)%MOD;
      tmp=tmp*i%MOD;
      
      res=res*tmp%MOD;

      //int f=mod_inverse(ten[i-1]*(100-C)%MOD,MOD);
      //res=res*f%MOD;
      ans=(ans+res)%MOD;
  }

  ans=ans*inv[100-C]%MOD;
  ans=ans*100%MOD;

  //int f=mod_inverse(ten[N-1]*(100-C)%MOD,MOD);
  cout<<(ans+MOD)%MOD<<endl;

  return 0;
}


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

using namespace std;

typedef long long ll;
#define fi first
#define se second
#define pb push_back
#define md ((st + nd) >> 1)
#define lc (1 + (idx << 1))
#define rc (2 + (idx << 1))

const int N = 200005;
vector <int> v[N];
ll tree[4*N], lazy[4*N];

int len(int x, int y) {
    return y - x + 1;
}

void prop(int idx, int st, int nd) {
    int temp = lazy[idx];
    lazy[idx] = 0;
    lazy[lc] += temp;
    lazy[rc] += temp;
    int mid = md;
    tree[lc] += (ll)temp * len(st, mid);
    tree[rc] += (ll)temp * len(mid + 1, nd);
}

int l, r, val;
void upd(int idx, int st, int nd) {
    if (l <= st && nd <= r) {
        tree[idx] += (ll)val * len(st, nd);
        lazy[idx] += val;
    } else {
        prop(idx, st, nd);
        int mid = md;
        if (r <= mid) {
            upd(lc, st, mid);
        } else if (l > mid) {
            upd(rc, mid + 1, nd);
        } else {
            upd(lc, st, mid);
            upd(rc, mid + 1, nd);
        }
        tree[idx] = tree[lc] + tree[rc];
    }
}

ll get(int idx, int st, int nd) {
    if (l <= st && nd <= r) {
        return tree[idx];
    }
    prop(idx, st, nd);
    int mid = md;
    if (r <= mid) {
        return get(lc, st, mid);
    }
    if (l > mid) {
        return get(rc, mid + 1, nd);
    }
    return get(lc, st, mid) + get(rc, mid + 1, nd);
}

int main() {
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    scanf("%d", &n);
    for (int i = 1; i < n; i++) {
        int x, y;
        scanf("%d %d", &x, &y);
        if (x < y) swap(x, y);
        v[x].pb(y);
    }
    for (int i = 1; i <= n; i++) {
        sort(v[i].begin(), v[i].end());
        reverse(v[i].begin(), v[i].end());
    }
    ll res = 0;
    for (int i = 1; i <= n; i++) {
        int hold = 1;
        r = i - 1;
        for (auto j : v[i]) {
            l = j + 1;
            val = hold;
            if (l <= r) {
                upd(0, 1, n);
                res += get(0, 1, n);
            }
            hold--;
            r = j;
        }
        l = 1;
        val = hold;
        //printf("%d\n", val);
        if (l <= r) {
            upd(0, 1, n);
            res += get(0, 1, n);
        }
        l = i;
        r = i;
        val = 1;
        upd(0, 1, n);
        res += get(0, 1, n);
    }
    printf("%lld", res);
    return 0;
}


Measured memory_bytes: 22940
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <algorithm>
using namespace std;

int main(){
    int a, b;
    cin >> a >> b;
    if (a > 12){
        cout <<  b;
    }
    else{
        if(a < 6){
            cout << 0;
        }
        else{
        cout << b/2;
        }
    }

}
    // for (int i = 0; i < ; i++){
        
        //         if(!(i+offset < n)) break;
        // int c = i + offset;
        // if(n/c == n%c){
        //     res += i;
        //     offset += 
        // }
    // }


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

int main(){
  int a,b,array[101],c=0,i=0,d=1;
  cin>>a>>b;
  while(i!=a&&d<=b){
    d+=d;
    i++;
  }
  while(i!=a){
    d+=b;
    i++;
  }
  cout<<d<<endl;
}
      
  


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

int main(){
  int M, D;
  cin >> M >> D;
  
  int d_10, d_01;
  int count = 0;
  
  for(int i=1; i<=M; i++){
    for(int j=1; j<=D; j++){
      d_10 = j / 10;
      d_01 = j % 10;
      if(d_10 >= 2 && d_01 >= 2 && i == d_10 * d_01){
        count++;
      }
    }
  }

  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repi(i, a, b) for (int i = (int)(a) ; i < (int)(b) ; i++)
#define rep(i, n) repi(i, 0, n)
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
// using P = pair<int, int>;
struct Vec{
    double x, y;
};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
     return false;
}
using namespace std;

int dp[100001];
int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    // cout << fixed << setprecision(15);

    int N;
    cin >> N;
    vector<int> h(N);
    rep(i, N) cin >> h[i];
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    repi(i, 2, N){
        dp[i] = min(dp[i - 1]+abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
    }
    cout << dp[N - 1] << endl;
    return 0;
}

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int main() {
	int n, tbl[15][15];
	
	while (cin >> n, n) {
		for_(i,0,n) for_(j,0,n) cin >> tbl[i][j];
		
		tbl[n][n] = 0;
		for_(i,0,n) {
			int sumi = 0, sumj = 0;
			
			for_(j,0,n) {
				sumi += tbl[i][j];
				sumj += tbl[j][i];
			}
			
			tbl[i][n] = sumi;
			tbl[n][i] = sumj;
			tbl[n][n] += sumi;
		}
		
		for_(i,0,n+1) {
			for_(j,0,n+1) printf("%5d", tbl[i][j]);
			cout << endl;
		}
	}
}

Measured memory_bytes: 1192
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

k = INT()
x = 0
for i in range(k):
    x = ( x * 10 + 7 ) % k
    if x % k == 0:
        print(i+1)
        exit()
print(-1)

Measured memory_bytes: 10276
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S, T;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;


const int MAX_N = (4e+5)+10;
vec fact(MAX_N+1,0),fact_inv(MAX_N+1,0);

ll fastpow(ll a, ll pw) {
	ll res = 1;
	while (pw) {
		if (pw & 1) res = res * a % MOD;
		a = a * a % MOD;
		pw >>= 1;
	}
	return res;
}
void makefact(ll n){//MODは素数かつnより大きい
    ll ans = 1;
    fact.at(0) = ans;
    fact_inv.at(0) = ans;
    reps(i,1,n+1){
        (ans *= i)%=MOD;
        fact.at(i) = ans;
        fact_inv.at(i) = fastpow(ans,MOD-2);
    }
    return;
}

ll nCm(ll n, ll m){
    ll res = fact[n];
    (res *= fact_inv[m])%=MOD;
    (res *= fact_inv[n - m])%=MOD;
    return res;
}
int main() {
    cin>>N>>K;
    makefact(4e+5 + 5);
    ll ans = nCm(N*2 - 1, N);
    //cout<<ans<<endl;
    if(K < N - 1){
        /*reps(i, 1, N - K){
            (ans += ((i + N - K)&1 ? MOD - ((nCm(N + i - 1, N) * nCm(N, i))%MOD)
                    : (((nCm(N + i - 1, N) * nCm(N, i))%MOD))))%=MOD;
        }*/
        reps(i, 1, N - K){
            (ans += MOD - (nCm(N - 1, i - 1) * nCm(N, i)%MOD))%=MOD;
        }
    }
    cout<<ans<<endl;
}

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

typedef long long ll;

ll n;

int main(){
	scanf("%lld",&n);
	ll ans = 1e15;
	for(ll i=1;i*i<=n;i++){
		if(n%i==0){
			ll x = i;
			ll y = n/i;
			ans = min(ans,x+y-2);
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
//#define _USE_MATH_DEFINES
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic ignored "-Wmissing-declarations"
#define FINAL_OUT(x) {cout << (x) << '\n'; exit(0); }
inline int safe_mul(const int x, const int y) __attribute__ ((warn_unused_result));


int main()
{
//    freopen("in.txt","r", stdin);
//    freopen("floor4.out", "w", stdout);
//    cout << fixed << setprecision(20);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);


    int n;
    cin >> n;
    vector<int> a(n + 1);
    for (int& x : a)
        cin >> x;

    int64_t res = 0;
    for (int i = 1; i <= n; ++i) {
        int cur = 0;
        cin >> cur;
        int t = min(cur, a[i - 1]);
        res += t;
        cur -= t;
        a[i - 1] -= t;
        t = min(a[i], cur);
        res += t;
        a[i] -= t;
        cur -= t;
    }
    cout << res << endl;
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SORT(i) sort((i).begin(),(i).end())
constexpr int INF = 2000000000;
constexpr int mod = 1000000007;

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

int main() {
	int N; cin >> N;
	cout << "ABC" << N << "\n";

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
ll ceilVal(ll a,ll b)
{
return (a / b) + ((a % b) != 0);
}
vector<ll> adj[1000000] ;
ll vis[1000000]={0} ;
void dfs(ll w)
{
    vis[w] = 1;
    for(ll u=0;u<adj[w].size();u++)
     {
      if(!vis[adj[w][u]])
            dfs(adj[w][u]) ;
	  }
}
ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    else if (y % 2 == 0) 
        return power(x, y / 2) * power(x, y / 2); 
    else
        return x * power(x, y / 2) * power(x, y / 2); 
}
int main()
{
 ios_base::sync_with_stdio(false);                      
 cin.tie(NULL);
 ll i,j,k,n,ans;
 cin>>n;
 ans=ceilVal(n,1000);
 ans=(1000*ans)-n;
 cout<<ans;
return(0);
}


Measured memory_bytes: 26992
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>
#include <set>
#include <map>

using namespace std;

typedef long long ll;

int main()
{
  int n;
  cin >> n;
  vector<ll> a(n), b(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < n; ++i) cin >> b[i];

  vector<ll> wins;
  ll sumLosses = 0;
  int result = 0;
  for (int i = 0; i < n; ++i) {
    if (a[i] >= b[i]) {
      wins.push_back(a[i] - b[i]);
    } else {
      sumLosses += b[i] - a[i];
      result++;
    }
  }
  sort(wins.rbegin(), wins.rend());
  for (int x : wins) {
    if (sumLosses > 0) {
      result++;
      sumLosses -= x;
    }
  }

  if (sumLosses > 0) result = -1;

  cout << result << endl;

  return 0;
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 q;
  cin >> q;
  priority_queue<int32> l;
  priority_queue<int32,vector<int32>,greater<int32>> r;
  l.push(-INF);
  r.push(INF);
  int64 f = 0;
  REP(i,q){
    int32 t;
    cin >> t;
    if(t == 1){
      int32 a,b;
      cin >> a >> b;
      f += b;
      if(a < l.top()){
        f += l.top() - a;
      }else if(r.top() < a){
        f += a - r.top();
      }
      l.push(a);
      r.push(a);
      if(l.top() > r.top()){
        l.push(r.top());
        r.push(l.top());
        l.pop();
        r.pop();
      }
    }else{
      cout << l.top() << " " << f << "\n";
    }
  }
  return 0;
}

Measured memory_bytes: 4588
#include<cstdio>
#include<algorithm>

using namespace std;

int main(){
	int n, l[200];
	scanf("%d", &n);
	for(int i = 0; i < 2 * n; i++) scanf("%d", &l[i]);
	sort(l, l + 2 * n);
	int s = 0;
	for(int i = 0; i < n; i++) s += l[2 * i];
	printf("%d\n", s);
	return 0;
}

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

int main(){
 while(true){
  int m, n_min, n_max;
  cin >> m >> n_min >> n_max;
  if(m==0 && n_min==0 && n_max==0) break;

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

  int gap = -1;
  int n = -1;
 
  for(int i=n_min; i<=n_max; i++){
   int g = P[i-1]-P[i];
   if(gap<=g){
    gap = g;
    n = i;
   }
  }
  
  cout << n << endl;
 }

 return 0;
}
   


Measured memory_bytes: 3012
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int n,k,a[55],i,ans=0;
  cin >> n >> k;
  for(i=0;i<n;i++){
  cin >> a[i];
  }
  sort(a,a+n,greater<int>());
  for(i=0;i<k;i++){
  ans=ans+a[i];
  }
  cout << ans << endl;
  return 0;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

ll dp[25][2101001];

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll n; cin>>n;
  vvll a(n, vll(n));
  rep(i,n) rep(j,n) cin>>a[i][j];
  
  dp[0][0]=1;
  
  rep(i,n){
    rep(s,1<<n) if(dp[i][s]){
      rep(j,n) if((s>>j&1)==0){
        if(a[i][j]) (dp[i+1][s|(1<<j)]+=dp[i][s])%=MOD;
      }
    }
  }
  
  ll ans=dp[n][(1<<n)-1];
  cout<<ans<<endl;
  
}

Measured memory_bytes: 311552
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define scn(n) scanf("%d",&n)
#define scnll(n) scanf("%lld",&n)
#define nl printf("\n")
#define YES printf("YES\n")
#define Yes printf("Yes\n")
#define yes printf("yes\n")
#define NO printf("NO\n")
#define No printf("No\n")
#define no printf("no\n")
using namespace std;
int main(){
    int n;scn(n);
    int h[n+1],dp[n+1];
    for(int i=1;i<=n;i++) scn(h[i]);
    dp[n]=0;
    dp[n-1]=abs(h[n-1]-h[n]);
    for(int i=n-2;i>0;i--){
        dp[i]=min(dp[i+1]+abs(h[i]-h[i+1]),dp[i+2]+abs(h[i]-h[i+2]));
    }
    printf("%d\n",dp[1]);
}


Measured memory_bytes: 4592
package main
 
import (
	"fmt"
)

func main() {
  var a, b, h int
  fmt.Scanf("%d", &a)
  fmt.Scanf("%d", &b)
  fmt.Scanf("%d", &h)
  
  ans := (a+ b) *h / 2  
  fmt.Printf("%d", ans)
}

Measured memory_bytes: 1832
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;

const int MAXN = 100000 + 1000;
const int MOD = 1000000000 + 7;
const int INF = 0x1f1f1f1f;

int n, p[MAXN];
int ans = 1;
vector<int> redg[MAXN];
vector<int> vc, vl;
bool vis[MAXN], onc[MAXN];
int cnt[MAXN], f[MAXN];

int get_len(int x)
{
	vis[x] = true;
	int ret = 0;
	for(int i = 0; i < redg[x].size(); i++)
		if(!onc[redg[x][i]])
			ret = ret == 0 ? get_len(redg[x][i]) + 1 : -INF;
	return ret;
}

int find_circle(int x)
{
	vis[x] = true;
	int y = p[x], t = vis[y] ? y : find_circle(y);
	if(t)
		onc[x] = true, vc.push_back(x);
	return t == x ? 0 : t;
}

void work()
{
	for(int i = 1; i <= n; i++)
		redg[p[i]].push_back(i);
	for(int i = 1; i <= n; i++)
		if(!vis[i])
		{
			vc.clear(), vl.clear();
			find_circle(i);	
			reverse(vc.begin(), vc.end());
			int last = -1;
			for(int j = 0; j < vc.size(); j++)
			{
				int x = vc[j], t = get_len(x);
				if(t < 0)
				{
					ans = 0; return ;
				}
				else if(t > 0)
					last = j;
				vl.push_back(t);
				// cerr << vc[j] << ' ' << vl[j] << endl;
			}
			// cerr << endl;
			if(last < 0)
			{
				cnt[vc.size()]++;
				continue;
			}
			else
			{
				for(int j = 0; j < vc.size(); j++)
					if(vl[j] > 0)
					{
						int l1 = vl[j], l2 = (j - last + vc.size() - 1) % vc.size() + 1;
						// cerr << l1 << ' ' << l2 << endl;
						if(l1 < l2)
							ans = (ans * 2) % MOD;
						else if(l1 == l2)
							ans = (ans * 1) % MOD;
						else
							ans = 0;
						last = j;
					}
			}
		}
	for(int i = 1; i <= n; i++)
		if(cnt[i])
		{
			int lam = (i == 1 || i % 2 == 0 ? 1 : 2);
			f[0] = 1;
			for(int j = 1; j <= cnt[i]; j++)
			{
				f[j] = (long long)f[j - 1] * lam % MOD;
				if(j - 2 >= 0)
					f[j] = (f[j] + (long long)f[j - 2] * (j - 1) % MOD * i) % MOD;
			}
			ans = (long long)ans * f[cnt[i]] % MOD;
		}
}

int main()
{
	ios::sync_with_stdio(false);
	// freopen("1.in", "r", stdin);
	// freopen("1.out", "w", stdout);

	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> p[i];

	work();
	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 10620
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
  int A,B;
  double T;
  int cnt=0,i=1;
  cin >> A >> B >> T;
  while (i*A < T + 0.5){
    cnt += B;
    i++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
use v5.18;
use warnings;
use Data::Dumper;
use List::Util qw( max );
sub line { chomp(my $str = <STDIN>); $str }

main();

sub main {
  my ($blue_cards, $red_cards) = input();
  say solve($blue_cards, $red_cards);
}

sub input {
  my $n = line;
  my @blue_cards = map { line } 0 .. $n - 1;
  my $m = line;
  my @red_cards = map { line } 0 .. $m - 1;
  (\@blue_cards, \@red_cards);
}

sub solve {
  my ($blue_cards, $red_cards) = @_;
  my %blue_count_table;
  for my $card (@$blue_cards) {
    $blue_count_table{$card}++;
  }
  my %red_count_table;
  for my $card (@$red_cards) {
    $red_count_table{$card}++;
  }
  my %words_table = (
    ( map { $_ => 1 } keys %blue_count_table ),
    ( map { $_ => 1 } keys %red_count_table ),
  );
  my @words = keys %words_table;
  my %words_money_table = (dummy_dummy => 0);
  for my $word (@words) {
    $words_money_table{$word} = ($blue_count_table{$word} // 0) - ($red_count_table{$word} // 0);
  }
  my $money = max values %words_money_table;
}


Measured memory_bytes: 1920
def main():
    n = int(input())
    center = (n+1)//2
    x_s = list(map(int,input().split()))
    sorted_x_s = sorted(x_s)
    center_num = sorted_x_s[center]

    for i in x_s:
        if i < center_num:
            print(sorted_x_s[center])
        else:
            print(sorted_x_s[center-1])






if __name__ == '__main__':
    main()


Measured memory_bytes: 25620
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,x;
    vector<int>v;
    map<int,int>m;
    cin>>n>>k;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        m[x]++;
    }
    map<int,int>::iterator it;
    for(it=m.begin();it!=m.end();it++)
    {
        v.push_back(it->second);
    }
    sort(v.begin(),v.end());
    int t=v.size()-k,ans=0;
    for(int i=0;i<t;i++)
    {
        ans+=v[i];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 10748