akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int i,j;
int count=0;


void Process(int A[ ], int n){
	for(i=0;i<n-1;i++)
		printf("%d ",A[i]);
	printf("%d\n",A[i]);
}


void BubbleSort(int A[ ], int n){
	int j,temp;
		for(i = 0; i < n-1; i++){
			for(j = n-1; j > i; j--)
			if(A[j-1] > A[j]){
				temp = A[j-1];
				A[j-1] = A[j];
				A[j] = temp;
				count++;
			}		
	}
}


int main(void){
	int N;
	scanf("%d",&N);
	int A[100];
	for(i=0;i<N;i++)
		scanf("%d",&A[i]);
	
	BubbleSort(A, N);
	Process(A, N);

	printf("%d\n",count);
	
	return 0;
}

Measured memory_bytes: 1772
<?php

$cups = array('A' => true, 'B' => false, 'C' => false);
while (true) {
    $t = explode(',', rtrim(fgets(STDIN)));
    if (feof(STDIN)) {
        break;
    }
    $tmp = $cups[$t[0]];
    $cups[$t[0]] = $cups[$t[1]];
    $cups[$t[1]] = $tmp;
}

foreach ($cups as $k => $v) {
    if ($v) {
        echo $k . PHP_EOL;
        break;
    }
}

Measured memory_bytes: 6604
import collections
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N = int(input())
s = [input() for _ in range(N)]
idx = 0
for i in s:
    t = sorted(i)
    s[idx] = "".join(t)
    idx += 1
s = collections.Counter(s)
ans = 0
for i in s:
    if s[i] > 1:
        ans += combinations_count(s[i], 2)
print(ans)


Measured memory_bytes: 19816
import java.util.Scanner;

public class Main {

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

		double wSide = (double)len/3;
		double tSide = (double)len/3;
		double hSide = (double)len/3;

		double result = wSide*tSide*hSide;

		System.out.print(result);
		sc.close();
	}
}


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

int main(){
    string strO, strE;
    string strA = "";
    cin >> strO >> strE;

    for(int i=0;i<(strO.size()+strE.size());++i){
        if(i%2==0){
            strA+=strO.at(i/2);
        }
        else
        {
            strA+=strE.at((i-1)/2);
        }
        
    }
    
    cout << strA << endl;

    return 0;
}

Measured memory_bytes: 256
var lines = [];

var readline = require('readline');
var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var v = [];
    var N = lines.shift();
    N = Number(N);

    for (var i = 0; i < 5; i++) {
        v[i] = Number(lines[i]);
    }

    var result = 0;
    var min = Infinity; var j = 0;

    for (var i = 0; i < 5; i++) { if (v[i] < min) { min = v[i]; j = i; } }

    result = Math.ceil(N / v[j]) + 4;
    console.log(result);

});

Measured memory_bytes: 8008
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

using namespace std;

int main(){
  long long int N;
	long long int sum = 0;
	long long int aiueo = 1;
	cin >> N;

	while(N / aiueo !=0){
		sum += (N / aiueo) % 10;
		aiueo *= 10;
	}
	if(N%sum==0)cout << "Yes" << endl;
	else cout << "No" << endl;

  return 0;
}




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

using namespace std;

int main() {
    string s;
    string t;
    cin >> s;
    cin >> t;
    bool ans = true;
    if (t.length() != s.length() + 1) {
        ans = false;
    }
    for (int i = 0; i < s.length(); i++) {
        if (s[i] != t[i]) {
            ans = false;
            break;
        }
    }
    if (ans) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3596
#include <stdio.h>

/*
回答の方針
1. gcc(A, B)を求める
2. gcc(A, B) * (A / gcc(A, B)) * (B / gcc(A, B)) が最小公倍数となる
*/

long int gcc(int a, int b){
    // Euclidean Algorithm
    if (a < b) {
       int tmp = b;
       b = a;
       a = tmp;
    }
    
    if (a % b == 0){
        return b;
    }else{
        return gcc(b, a % b);
    }
}

int main(void){
    int a, b;
    long int gc;
    
    scanf("%d %d", &a, &b);
    gc = gcc(a, b);
    printf("%ld", gc*(a/gc)*(b/gc));
    
    return 0;
}

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

int main(){
	for(int i=0;i<4000;i++){
	    int x,y;
	    cin >> x >> y;
	    if(x==0&&y==0)break;
	    cout << min(x,y) << " " << max(x,y) << endl;
	}
}


Measured memory_bytes: 3088
# -*- coding: utf-8 -*-
# 整数の入力
# スペース区切りの整数の入力
a, b, c = map(int, input().split())

if a == (b+c):
  print('Yes')
elif (a+b) == c:
  print('Yes')
elif (a+c) == b:
  print('Yes')
else:
  print('No')

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

int main(){
    vector<vector<int>> A(3, vector<int>(3));
    for(int i = 0; i < 3; ++i) {
        for(int k = 0; k < 3; ++k) {
            cin >> A[i][k];
        }
    }

    int N; cin >> N;
    vector<int> b(N); for(int i = 0; i < N; ++i) cin >> b[i];

    for(int m = 0; m < N; ++m) {
        for(int i = 0; i < 3; ++i) {
            for(int k = 0; k < 3; ++k) {
                if(b[m] == A[i][k]) {
                    A[i][k] = A[i][k] - b[m];
                }
            }
        }
    }

    if((A[0][0] == 0 && A[1][1] == 0 && A[2][2] == 0)
    || (A[2][0] == 0 && A[1][1] == 0 && A[0][2] == 0)

    || (A[0][0] == 0 && A[0][1] == 0 && A[0][2] == 0)
    || (A[1][0] == 0 && A[1][1] == 0 && A[1][2] == 0)
    || (A[2][0] == 0 && A[2][1] == 0 && A[2][2] == 0)

    || (A[0][0] == 0 && A[1][0] == 0 && A[2][0] == 0)
    || (A[0][1] == 0 && A[1][1] == 0 && A[2][1] == 0)
    || (A[0][2] == 0 && A[1][2] == 0 && A[2][2] == 0)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (n); i++)
#define ll long long
#define ull unsigned long long

ll gcd(ll a, ll b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

int main(){
    int n;
    cin >> n;
    ll T[n];
    rep(i, 0, n) cin >> T[i];

    ll ans = T[0];
    rep(i, 1, n){
        if(ans == T[i]) continue;
        ans = lcm(ans, T[i]);
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = { 1,0 }, dy[] = { 0,1 }, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge> >G;

long long mod_pow(long long a, long long b) {
	long long res = 1;
	while (b) {
		if (b & 1) { res = res * a%MOD; }
		a = a * a%MOD;
		b >>= 1;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

//↑template↑

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


Measured memory_bytes: 256
X, N = map(int,input().split())
li = set(list(map(int,input().split())))
li = list(set(range(102)) - li)

li.sort(reverse=True)
n = 102

for i in li:
    m = abs(X - i)
    if m <= n:
        n = m
        k = i
print(k)

Measured memory_bytes: 61876
#include<iostream>
#include<stdio.h>
#include<map>
#include<math.h>
using namespace std;
int a[100002];
int mins=0;
map<long long ,long long >ss;
int main()
{
    int x,y,t,i,n;
    double s;
    cin>>t>>x>>y;
    for(i=0;i<t;i++)
        cin>>a[i];
   double mins=x-a[0]*0.006-y;
   if(mins<0)
     mins=-mins;
    n=0;
    for(i=1;i<t;i++)
    {
       s=x-a[i]*0.006-y;
      if(s<0)
        s=-s;
      if(s<mins)
      {
          n=i;
          mins=s;
      }
    }
    cout<<n+1<<endl;
	return 0;
}


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

#define M 1000000007
typedef long long LL;

void fastIO_test(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

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

LL modFact(LL n, LL p) 
{ 
    if (n >= p) 
        return 0; 
  
    int result = 1; 
    for (int i = 1; i <= n; i++) 
        result = (result * i) % p; 
  
    return result; 
} 

LL power(LL n, LL p)
{
    LL res = 1;
    for(LL i=1; i<=n; i++)
    {
        res = (res*p)%M;
    }
    return res;
}

void solve(void)
{
    LL n;
    cin >> n;
    if(n==1)
    {
        cout << 0 << "\n";
        return;
    }
    if(n==2)
    {
        cout << 2 << "\n";
        return;
    }
    //LL facN = modFact(n, M);
    //cout << facN << endl;
    LL po10 = power(n, 10);
    LL po9 = power(n, 9);
    LL po8 = power(n, 8);
    //cout << poN << endl;
    //LL ans = ((facN%M)*(poN%M))%M;
    //cout << ans << "\n";
    //cout << (((n*(n-1))%M)*ans)%M << "\n"; 
    LL ans = (po10 - (((po9 - po8 + M)%M)*2)%M + M - po8 + M)%M;
    cout << ans << "\n";
}

int main()
{
    fastIO_test();

    LL t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define dd(x) cout << #x << "=" << x << ","
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i=(b-1);i>=a;--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl "\n"
#define lowbit(x) x&(-x)
const int N = 20000;
const int M = 1e9+7;

ll np[1000010];
ll f[1000010];

int main(){
//    ios::sync_with_stdio(false);
//    cin.tie(0);
    for (int i=1; i<=1000000; i++){
    	f[i]=f[i-1]+i;
	}
    ll n;
    cin>>n;
    np[1]=1;
    int ans=0;
    for (int i=1; i<=1000000; i++){
    	if (np[i]) continue;
    	if (n%i==0){
	    	int cnt=0;
	    	while (n%i==0){
	    		n/=i;
	    		cnt++;
			}
			int t=upper_bound(f+1,f+1000000+1,cnt)-1-f;
			ans+=t;	
		}
		for (int j=i+i; j<=1000000; j+=i)
    		np[j]=1;
	}
	if (n>1) ans++;
	cout<<ans;
    return 0;
}


Measured memory_bytes: 19260
#include<iostream>
#include<string>
using namespace std;
int main() {
  int cnt = 0;
  string s;
  cin >> s;
  for(int i = 0; i < 3; i++){
    if(s[i] == 'o'){
      cnt++;
    }
  }
  cout << 700 + cnt*100 << endl;
  return 0;
}

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

int main()
{
	int n[100];
	int i=0;
	while(cin >> n[i]){i++;};
	int s=0;
	for(int j=0;j<i;j++){
		int s=0;
	for (int a=0;a<10;a++){
		for(int b=0;b<10;b++){
			for(int c=0;c<10;c++){
				for(int d=0;d<10;d++){
					if(a+b+c+d==n[j]){s=s+1;}
				}
			}
		}
	}
	cout << s << endl;
	}
    return 0;
}

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

int main(){
string S;
cin>>S;
//cout<<S;

//S=wdsahiuh <- abcdefghijklmnopqrstuvwxyz
//num[i]　0〜25番目のカウントnum[S[i]];
int num[S.size()]={0};
int cnt;
int i=0;
// dhsua  if(d)->num[4]++ if(h)->num[10]++
//if a->1 b->2 .. z->26 S[i]=="a"
for(i=0;i<S.size();i++){
    char a = S[i];
    num[a-'a']++;
}
/*
    if(num[S[i]]){
        //num 0a 1b 2c 3d 4 ... 25z
        if(num[i]){
            cnt++;
        }
    }
}
*/
for(i=0;i<26;i++){
    if(num[i]==0){
        cout<<(char)(i+'a');
        exit(0);
    }
}
cout<<"None";
//cout << 
//if num[i]

}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define ROOP(i, N) for(int i=0; i++; i<N)
#define RVROOP(i, N) for(int i=N; i--; i>=0)
#define ALL(v) v.begin(), v.end()
const int INF = 1e9;
const int MAX = 2000000;
const int MOD = 1000000007;
using namespace std;
typedef long long ll;

/*DP使ったほうがよくない？？WOWWOW*/

ll fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  ll x, y; cin>>x>>y;
  ll ans;
  if((2*y-x)%3!=0 || (2*x-y)%3!=0){
    ans=0;
  }
  else if(2*x-y<0 || 2*y-x<0){
    ans=0;
  }
  else{
    ll k,l;
    k=(2*x-y)/3;
    l=(2*y-x)/3;
    COMinit();
    ans=COM(k+l, k);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 47104
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;
int X,Y,A,B,C;
vector<LL> p;
vector<LL> q;
vector<LL> r;
priority_queue<LL,vector<LL>,greater<LL> >que;
int main(){
	cin>>X>>Y>>A>>B>>C;
	REP(i,A){
		LL a;
		cin>>a;
		p.push_back(a);
	}
	REP(i,B){
		LL a;
		cin>>a;
		q.push_back(a);
	}
	REP(i,C){
		LL a;
		cin>>a;
		r.push_back(a);
	}
	sort(p.begin(),p.end());
	reverse(p.begin(),p.end());
	sort(q.begin(),q.end());
	reverse(q.begin(),q.end());
	sort(r.begin(),r.end());
	reverse(r.begin(),r.end());
	REP(i,X){
		que.push(p[i]);
	}
	REP(i,Y){
		que.push(q[i]);
	}
	REP(i,C){
		LL pp=que.top();
		que.pop();
		LL now=max(pp,r[i]);
		que.push(now);
	}
	LL ans=0;
	while(que.empty()==false){
		LL pp=que.top();
		que.pop();
		ans+=pp;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 4724
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=str(input())
c=int(0)
def get(x,c):
  if x=="r":
    c+=P
  elif x=="s":
    c+=R
  else:
    c+=S
  return c
n=len(T)
for i in range(n):
  if i<=K-1:
    c=get(T[i],c)
  else:
    if T[i-K]!=T[i]:
      c=get(T[i],c)
    if T[i-K]!="o" and T[i-K]==T[i]:
      T=T[:i]+"o"+T[i+1:]
print(c)

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

int main()
{
  ll N;
  cin >> N;
  ll max_h = 0;
  for (ll i = 0; i < N; ++i)
  {
    ll h;
    cin >> h;
    if (h < max_h - 1)
    {
      cout << "No" << endl;
      return 0;
    }
    max_h = max(max_h, h);
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int main(){
  int n, m;
  while((n = getInt()) + (m = getInt())){
    vector<int> v(n);
    int ans = 0;
    REP(i,n) v[i] = getInt();
    sort(v.rbegin(), v.rend());
    REP(i,n) if(i % m != (m - 1))
      ans += v[i];
    print(ans);
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define ll int64_t
#define _GLIBCXX_DEBUG
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int ans=1000000000;

void dfs(int i,vector<int> rikai,int kane,vector<vector<int>> a,vector<int>c,int m,int n,int k){
  if(i==n){
    rep(j,m){
      if(rikai.at(j)<k)
        return;
    }
    ans=min(ans,kane);
    return;
  }
  dfs(i+1,rikai,kane,a,c,m,n,k);
  rep(j,m){
    rikai.at(j)+=a.at(i).at(j);
  }
  kane+=c.at(i);
  dfs(i+1,rikai,kane,a,c,m,n,k);
  return;
}
  
int main(){
  
  int m,n,k;
  cin >> n >> m >> k;
  vector<vector<int>> a(n,vector<int>(m));
  vector<int> c(n);
  
  rep(i,n){
    cin >> c.at(i);
    rep(j,m)
      cin >> a.at(i).at(j);
  }
  vector<int> rikai(m);
  int kane=0;
  dfs(0,rikai,kane,a,c,m,n,k);
  if(ans==1000000000)
    cout << -1 << endl;
  else
    cout << ans << endl;
}

Measured memory_bytes: 3652
from itertools import product
N = int(input())
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
x = - 10 ** 10
for a in product((0, 1), repeat=10):
    if not any(a):
        continue
    num = 0
    for f, p in zip(F, P):
        c = sum(map(lambda z: z[0] * z[1], zip(a, f)))
        num += p[c]
    x = max(x, num)
print(x)


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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
clock_t startTime;
long double getTime(){
	return (long double)(clock()-startTime)/CLOCKS_PER_SEC;
}

int main(){
	startTime=clock();
	ll n,k;
	cin >> n  >> k;
	ll ans=0;
	
	if(k==0){
		cout << n*n;
	}
	else{ 
		for(int b=k+1;b<=n;b++){
			ans+=(b-k)*(n/b)+(int)((n%b < k)?0 : n%b-k+1);
		}
		cout << ans;
	}
	

	return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <map>
#include <vector>
#include <cstring>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <string>
#include <stack>
#include <set>
#include <deque>
#define mp make_pair
typedef long long ll;
using namespace std;
int a,b,c,u[505][505];
queue <pair<int,int> > que;
pair <int,int> xx,f;
int main(){
	cin>>a>>b>>c;
	f.first=b-a+251;
	f.second=c-b+251;
	que.push(f);
	u[f.first][f.second]=1;
	while (!que.empty()){
		xx=que.front();
		if (xx.first==251 && xx.second==251){
			cout<<u[xx.first][xx.second]-1<<endl;
			return 0;
		} 
		que.pop();
		if (!u[xx.first+1][xx.second]){
			u[xx.first+1][xx.second]=u[xx.first][xx.second]+1;
			que.push(mp(xx.first+1,xx.second)); 
		}
		if (!u[xx.first-1][xx.second+1]){
			u[xx.first-1][xx.second+1]=u[xx.first][xx.second]+1;
			que.push(mp(xx.first-1,xx.second+1)); 
		}
		if (!u[xx.first][xx.second-1]){
			u[xx.first][xx.second-1]=u[xx.first][xx.second]+1;
			que.push(mp(xx.first,xx.second-1));
		}
		if (!u[xx.first-2][xx.second]){
			u[xx.first-2][xx.second]=u[xx.first][xx.second]+1;
			que.push(mp(xx.first-2,xx.second)); 
		}
		if (!u[xx.first+2][xx.second-2]){
			u[xx.first+2][xx.second-2]=u[xx.first][xx.second]+1;
			que.push(mp(xx.first+2,xx.second-2)); 
		}
		if (!u[xx.first][xx.second+2]){
			u[xx.first][xx.second+2]=u[xx.first][xx.second]+1;
		que.push(mp(xx.first,xx.second+2)); 
		}
	}
} 

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include<vector>

using namespace std;

int main() {
    int n, t, a;
    cin >> n >> t >> a;
    a *= 1000;
    int h[1005];
    for (int i = 0; i < n; i++) {
        cin >> h[i];
        h[i] = t*1000 - (h[i] * 6);
    }
    int ans =abs(a- h[0]);
    int answer = 0;
    for (int i = 0; i < n; i++) {
        int c = abs(a - h[i]);
        if (c < ans) {
            ans = c;
            answer = i;
        }
    }
    cout << answer+1<< endl;
    return 0;
}

Measured memory_bytes: 256
sx,sy,tx,ty=map(int, input().split())
    
UD_dic={"U":ty-sy, "D":-(ty-sy)}
RL_dic={"R":tx-sx, "L":-(tx-sx)}

ans=""

ans+=max(UD_dic)*max(UD_dic.values())+max(RL_dic)*max(RL_dic.values())
ans+=min(UD_dic)*abs(min(UD_dic.values()))+min(RL_dic)*abs(min(RL_dic.values()))

ans+=min(RL_dic)+max(UD_dic)*(max(UD_dic.values())+1)+max(RL_dic)*(max(RL_dic.values())+1)+min(UD_dic)
ans+=max(RL_dic)+min(UD_dic)*abs(min(UD_dic.values())-1)+min(RL_dic)*abs(min(RL_dic.values())-1)+max(UD_dic)

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	int n;
	int c[500], s[500], f[500];
	cin >> n;
	for (int i = 0; i < n - 1; i++) {
		cin >> c[i] >> s[i] >> f[i];
	}
	for (int i = 0; i < n - 1; i++) {
		int now = 0;
		for (int j = i; j < n - 1; j++) {
			if (now <= s[j]) {
				now = s[j] + c[j];
			}
			else {
				int co1 = 0;
				for (;;) {
					co1 += f[j];
					if (now - co1 <= s[j]) {
						now = s[j] + c[j] + co1;
						break;
					}
				}
			}
		}
		cout << now << endl;
	}
	cout << "0" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1000000007;
const int INF = 1e+9;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

const int MAX_N = 110000;

int dp[MAX_N];

int main () {
  int N;
  string S;
  cin >> N >> S;

  int E_cnt = 0;
  int total_E = count(ALL(S),'E');

  vi turn_cnt(N);
  rep(i,N) {
    int LW = i - E_cnt;
    if (S[i] == 'E') E_cnt++;
    int RE = total_E - E_cnt;
    turn_cnt[i] = LW + RE;
  }

  cout << *min_element(ALL(turn_cnt)) << endl;
}

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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

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

    int X[10][10];

    REP(i,n) REP(j,d) cin >> X[i][j];

    int ans = 0;
    for(int i = 0;i < n;i++) for(int j=i+1;j<n;j++){
        double di = 0;
        REP(k,d) di += (X[i][k] - X[j][k])*(X[i][k] - X[j][k]);
        double dist = sqrt(di);
        if(floor(dist) == ceil(dist)) {
            ans++;
        }
    }

    pl(ans)

    return 0;
}


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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();

int main(int, char**) {
	int n; cin >> n;
	for (int i=1; i<10; i++) {
		if (n%i==0 && n/i < 10) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
import itertools
from collections import Counter

def main():
    l,r = map(int, input().split())
    if r-l > 2019:
        print(0)
        exit()
    ans = []
    for i in range(l,r+1):
        ans.append(i%2019)
    p = []
    ans = list(itertools.combinations(ans, 2))
    for k in ans:
        c = k[0]*k[1]
        p.append(c%2019)
    print(min(p))

if __name__=="__main__":
    main()


Measured memory_bytes: 283000
using System;


class AOJ
{

    public static void Main()
    {

        int n = int.Parse(Console.ReadLine());
        int[] a = new int[3];

        for (int i = 0; i < n; i++)
        {

            string[] s = Console.ReadLine().Split(' ');

            for (int j = 0; j < 3; j++)
            {
                a[j] = int.Parse(s[j]);
            }

            Array.Sort(a);
            Array.Reverse(a);


            if (Math.Pow(a[0],2) == Math.Pow(a[1],2)+Math.Pow(a[2],2))
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");
        }
    }
}

Measured memory_bytes: 5592
use std::io;

fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input).ok();
    let split: Vec<&str> = input.split(' ').collect();

    let a: i32 = split[0].trim().parse().unwrap();
    let b: i32 = split[1].trim().parse().unwrap();

    if -1000 <= a && a <= 1000 && -1000 <= b && b <= 1000 {
        if a < b {
            println!("a < b");
        }
        if a > b {
            println!("a > b");
        }
        if a == b {
            println!("a == b");
        }
    }
}



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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f=true){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f=true){cout<<(f?"YES":"NO")<<endl;}
#define ANS(a) cout<<a<<endl

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    int N; cin >>N;
    vector<int> a(N); cin >> a;
    
    auto mme = minmax_element(ALL(a));

    cout << *mme.second - *mme.first << endl;
}


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


int main()
{


                string s;

                cin>>s;


               int a=0,b=0,i=0;

               while(s[i]!='\0'){

                  if(s[i]=='A') a++;
                  else          b++;


                i++;
               }


             if(a==0 || b==0) cout<<"No"<<endl;
             else             cout<<"Yes"<<endl;



    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int N, M;
cin >> N >> M;
int tenbo[200010];
bool tenbocheck[200010];
for(int i = 0; i < N; i++){
tenbocheck[i] = 1;
}

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

for(int i = 0; i < M; i++){
int a, b;
cin >> a >> b;
a--;
b--;
if(tenbo[a] > tenbo[b]) tenbocheck[b] = 0;
else if(tenbo[a] < tenbo[b]) tenbocheck[a] = 0;
else{
    tenbocheck[a] = 0;
    tenbocheck[b] = 0;
}

}
int count = 0;
for(int i = 0; i < N; i++){
if(tenbocheck[i] == 1) count++;
}
cout << count << endl;

}

Measured memory_bytes: 4080
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = int_fast64_t;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  ll n; cin >> n;
  struct Block {
    ll w, s, v;
    Block(ll w_, ll s_, ll v_) : w(w_), s(s_), v(v_) {}
    bool operator<(const Block& rhs) const {
      return w + s < rhs.w + rhs.s;
    }
  };
  vector<Block> blocks;
  rep(i, n) {
    ll w, s, v; cin >> w >> s >> v;
    blocks.emplace_back(Block(w, s, v));
  }
  sort(ALL(blocks));
  vector<ll> dp(20020, 0), p(20020, 0);
  rep(i,n) {
    swap(p, dp);
    rep(j, 20010) {
      const Block& b = blocks[i];
      dp[j] = p[j];
      if(b.w <= j && b.s >= j-b.w) chmax(dp[j], p[j-b.w] + b.v);
    }
  }
  ll ans = 0;
  rep(j, 20010) chmax(ans, dp[j]);
  cout << ans << "\n";
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
  int paSize = printArray.size();
  for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
  if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int Len[55], Pat[55];

int rec(int level, int layer) {
  if (level == 0) return 1;

  if (layer <= 1) { // 1
    return 0;
  } else if (layer <= Len[level-1]+1) { // 2
    return rec(level-1, layer-1);
  } else if (layer <= Len[level-1]+2) { // 3
    return Pat[level-1] + 1;
  } else if (layer <= 2*Len[level-1]+2) { // 4
    return Pat[level-1] + 1 + rec(level-1, layer-Len[level-1]-2);
  } else { // 5
    return 2*Pat[level-1]+1;
  }
}

signed main() {
  int N, X;
  cin >> N >> X;

  Len[0] = Pat[0] = 1;
  for (int i = 1; i <= N; i++) {
    Len[i] = Len[i-1] * 2 + 3;
    Pat[i] = Pat[i-1] * 2 + 1;
  }

  cout << rec(N, X) << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = (1 << 26);

int dp[MAX_N];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    memset(dp, 0x3f, sizeof(dp));
    dp[0] = 0;
    int kp = 0, opt;
    rep(i,len(s)){
        kp ^= (1 << (s[i] - 'a'));
        opt = INF;
        cmn(opt, dp[kp]+1);
        rep(j,26) cmn(opt, dp[kp^(1 << j)]+1);
        cmn(dp[kp], opt);
    }
    cout << opt << "\n";
    return 0;
}


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

int main() {
  string a, b; cin >> a >> b;
  string ans;
  
  // 制約上、数値型で受け取るのは不可。文字列で受け取る。
  if (a.size() > b.size()) ans = "GREATER";
  else if (a.size() == b.size()) {
    for (int i = 0; i < a.size(); ++i) {
      int i_a = (int) a[i], i_b = (int) b[i];
      if (i_a > i_b) {
        ans = "GREATER";
        break;
      }
      else if (i_a == i_b) continue;
      else if (i_a < i_b) {
        ans = "LESS";
        break;
      }
    }
    if (ans.empty()) ans = "EQUAL";
  }
  else if (a.size() < b.size()) ans = "LESS";
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
N, A, B = map(int, input().split())

r = [0] * 40

for i in range(1, N + 1):
    si = str(i)
    t = 0
    for j in range(len(si)):
        t += int(si[j])

    r[t] += i

res = 0

for i in range(A, B + 1):
    res += r[i]

print(res)

Measured memory_bytes: 9172
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;
	
	public class Main {
	
		public static void main(String[] args) {
			execute17_3();
		}
		
		private static void execute17_3() {
			try 
			(Scanner sc = new Scanner(System.in)) {
				int n = sc.nextInt();
				int d = sc.nextInt();
				
				int ans=0;
				for(int i=0; i<n;i++) {
					int a = sc.nextInt();
					int b = sc.nextInt();
					if(Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2)) <= d) {
						ans++;
					}
				}
				System.out.println(ans);
			}
		}
    }

Measured memory_bytes: 48640
class UnionFind:
    def __init__(self, N):
        self.parent = [i for i in range(N)]
        self.rank = [0]*N
        self.count = 0
    def root(self, a):
        if self.parent[a]==a:
            return a
        else:
            self.parent[a]=self.root(self.parent[a])
            return self.parent[a]
    def size(x):
        return -par[root(x)]

    def is_same(self, a, b):
        return self.root(a)==self.root(b)
    def unite(self, a, b):
        ra = self.root(a)
        rb = self.root(b)
        if ra == rb: return

        if self.rank[ra] < self.rank[rb]:
            self.parent[ra] = rb
        else:
            self.parent[rb] = ra
            if self.rank[ra] == self.rank[rb]: self.rank[ra] += 1
        self.count += 1
if __name__ == '__main__':
    n, m=map(int, input().split())
    p=[int(i)-1 for i in input().split()]
    uf = UnionFind(n)
    for i in range(m):
        a,b=map(int, input().split())
        uf.unite(a-1,b-1)
    ans = 0
    for i in range(n):
        if uf.is_same(p[i], i):
            ans+=1
    print(ans)


Measured memory_bytes: 14452
def read(): return list(map(int, input().split()))


n = int(input())
a = read()

tot = sum(a)
for i in range(n - 1):
    a[i + 1] += a[i]

ans = 1145141919810893
for i in range(n-1):
    x = a[i]
    y = tot - x
    ans = min(ans, abs(x - y))

print(ans)


Measured memory_bytes: 24800
H,W = map(int,input().split())
if H == 1 or W ==1:
    print(1) 
elif  H % 2 == 1 and W % 2 ==1:
    print(int((H*W+1)/2))
elif H ==0 or W == 0:
    print(0)
else:
    print(int((H*W)/2))


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

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

        int whowin = 1;

        do
        {
                C -= B;
                if(C <= 0)
                {
                        whowin = 0;
                        break;
                }
                A -= D;

        }while(A > 0);

        if(whowin == 1) cout << "No" << endl;
        else    cout << "Yes" << endl;

        return 0;
}

Measured memory_bytes: 3596
import Control.Applicative

func _ 10 _ _ _ _ = 0
func _ _ 10 _ _ _ = 0
func _ _ _ 10 _ _ = 0
func _ _ _ _ 10 _ = 0
func n a b c d cur = if a+b+c+d == n
                    then 1
                    else if a+b+c+d>n 
                        then 0
                        else case cur of
                            0 -> (func n (a+1) b c d cur) + (func n a b c d (cur+1))
                            1 -> (func n a (b+1) c d cur) + (func n a b c d (cur+1))
                            2 -> (func n a b (c+1) d cur) + (func n a b c d (cur+1))
                            3 -> (func n a b c (d+1) cur) + (func n a b c d (cur+1))
                            _ -> 0
                            
func' n = func n 0 0 0 0 0

main=do{
    n <- map (read::String->Int) . lines <$> getContents;
    mapM_ print $ map func' n
}

Measured memory_bytes: 4304
#include <bits/stdc++.h>
using namespace std;
struct Edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    Edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int> >;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define mk make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
typedef unsigned int uint;
#include <bits/stdc++.h>
int main(){
  int n,k;
  std::cin >> n>>k;
  VEC(int,a,n);
  sort(all(a));
  int ans=INF;
  rep(i,n-k+1){
    ans=min(ans,a[i+k-1]-a[i]);
  }
  std::cout << ans << std::endl;
}

Measured memory_bytes: 640
#if defined(__GNUC__)
#include <bits/stdc++.h>
// __GNUC__
#else
#include "bits/stdc++.h"
#endif
using namespace std;

#define int long long

#if defined(__GNUC__)
#define __int32 __int32_t
#endif // __GNUC__

#define itn __int32
#define REP(i, n) for(itn (i) = 0; (i) < (n); ++(i))
#define REP2(i, x, n) for(itn (i) = x; (i) < (n); ++(i))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define SORT(x) std::sort(ALL(x))
#define RSORT(x, T) std::sort(ALL(x), greater<T>())
#define REVERCE(x) std::reverce(ALL(x))
#define ACM(x, y) std::accumulate(ALL(x), y)

#define INT_POW(x, y) [](int a, int b) -> int {if(b == 0){return 1;} int c = a; REP(i, b - 1){c *= a;} return c;}(x, y)
#define INT_POWM(x, y, m) [](int a, int b, int m) -> int {if(b == 0){return 1;} int c = a; REP(i, b - 1){c *= a; c %= m;} return c;}(x, y, m)

itn main() {
	std::ios::sync_with_stdio(false);

	int n;

	cin >> n;

	vector<pair<int, int>> rb(n);

	REP(i, n) {
		cin >> rb[i].first >> rb[i].second;
	}

	vector<pair<int, int>> arb(n);

	REP(i, n) {
		arb[i].first = rb[i].first + rb[i].second;
		arb[i].second = rb[i].first - rb[i].second;
	}

	SORT(arb);

	int btm = 0;
	int res1 = n;

	REP2(i, 1, n) {
		if ((arb[btm].first) > (arb[i].second)) {
			--res1;
		}else{
			btm = i;
		}
	}

	btm = n - 1;
	int res2 = n;

	REP2(i, 1, n) {
		if ((arb[btm].second) < (arb[n - 1 - i].first)) {
			--res2;
		}
		else {
			btm = n - 1 - i;
		}
	}

	cout << max(res1, res2);

	return 0;
}


Measured memory_bytes: 3328
N, M, S, T = map(int, input().split())
S, T = S - 1, T - 1
G_yen = [[] for i in range(N)]
G_snuuk = [[] for i in range(N)]
for i in range(M):
    u, v, a, b = map(int, input().split())
    u, v = u - 1, v - 1
    G_yen[u].append([v, a])
    G_yen[v].append([u, a])
    G_snuuk[u].append([v, b])
    G_snuuk[v].append([u, b])


def dijkstra(graph, start, inf=float('inf')):
    import heapq
    n = len(graph)
    distances = [inf] * n
    distances[start] = 0

    # 距離・頂点
    hq = [(0, start)]
    while hq:
        dist, fr = heapq.heappop(hq)
        if distances[fr] != dist:
            continue

        for to, cost in graph[fr]:
            new_dist = distances[fr] + cost
            if distances[to] > new_dist:
                distances[to] = new_dist
                heapq.heappush(hq, (new_dist, to))

    return distances


from_start_yen = dijkstra(G_yen, S)
from_goal_snuuk = dijkstra(G_snuuk, T)

ans = [0] * (N + 1)
for i, yen, snuuk in zip(reversed(range(N)), from_start_yen[::-1], from_goal_snuuk[::-1]):
    ans[i] = max(ans[i + 1], 10 ** 15 - (yen + snuuk))

print(*ans[:-1], sep='\n')


Measured memory_bytes: 126668
import Control.Applicative
import Data.Function
import Control.Monad

calc :: Int -> String -> Int -> Int
calc a "+" b = a + b
calc a "-" b = a - b
calc a "*" b = a * b
calc a "/" b = a `div` b

main :: IO ()
main = fix $ \loop -> do
    [a,op,b] <- words <$> getLine
    unless (op == "?") $ do
        putStrLn . show $ calc ((read :: String -> Int) a) op ((read :: String -> Int) b)
        loop


Measured memory_bytes: 3940
#include<stdio.h>
int main(void)
{
	int c1,c5,c10,c50,c100,c500;
	scanf("%d %d %d %d %d %d",&c1,&c5,&c10,&c50,&c100,&c500);
	if(c1*1+c5*5+c10*10+c50*50+c100*100+c500*500>=1000){
		printf("%d\n",1);
	}
	else {
		printf("%d\n",0);
	}
	return 0;
}
	


Measured memory_bytes: 2104
#include "bits/stdc++.h"
#define ll long long 
#define inf 1000000007 
#define sort(vec) sort((vec).begin(),(vec).end());
#define rever(vec) reverse((vec).begin(),(vec).end());
#define unsort(vec) sort((vec)); rever((vec));
using namespace std;

int main() {
	int n,d,x;
	cin>>n>>d>>x;
	int ans=x;
	for(int i=0;i<n;i++) {
		int a;
		cin>>a;
		int N=d-1;
		ans+=N/a;
	}
	cout<<ans+n<<endl;
}


Measured memory_bytes: 256
// AUTHOR: ROSHAN SRIVASTAVA
// WEBSITE: https://www.youtube.com/channel/UC6uQdd7kLLOdlHSVklhV7Cw

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007

ll a, b, c, d; 

int main(){

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

	cin >> a >> b >> c >> d;

	ll ans = a * c;
	ans = max(ans, a * d);
	ans = max(ans, b * c);
	ans = max(ans, b * d);
	cout << ans << endl;


	

	return 0;
}

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

int main(int argc, char** argv) {
	int n, m;
	cin >> n >> m;
	int l, r, lmax = 0, rmin = n;
	for (int i = 0; i < m; ++i) {
		cin >> l >> r;
		lmax = max(l, lmax);
		rmin = min(r, rmin);
	}

	if (lmax <= rmin) cout << rmin - lmax + 1 << endl;
	else cout << 0 << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
using namespace std;

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

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	cout << min(a,b) + min(c,d) << '\n';
}


Measured memory_bytes: 256
n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()

s = 0
num = 0
if x>sum(a):
  print(len(a)-1)
else:
  for i in range(len(a)):
      if x >= a[i]:
          x -= a[i]
          num += 1
      else:
          break

  print(num)


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

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;

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

constexpr long long mod = 1000000007;

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

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

    ll a, b, n;
    cin >> a >> b >> n;

    long long m = floor(n / b) * b;

    if(m==0){
        m = n;
    }else{
        m--;
    }

    cout << floor(a * m / b) - a * floor(m / b);
}

Measured memory_bytes: 3780
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;

signed main(){
    cin.tie(0); 
    ios::sync_with_stdio(false);
    string s;
    int w_b=0;
    int b_w=0;
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(s[i]=='0'){
            if(i%2==0){
                w_b++;
            }
            if(i%2==1){
                b_w++;
            }
        }
        if(s[i]=='1'){
            if(i%2==1){
                w_b++;
            }
            if(i%2==0){
                b_w++;
            }
        }
    }
    cout<<min(w_b,b_w)<<"\n";
    return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main() {
  int n, ans, k, t[6];
  vector< pair<int, int> > T;
  while (cin >> n, n) {
    for (int i = 0; i < n; ++i) {
      scanf("%d:%d:%d %d:%d:%d",&t[0],&t[1],&t[2],&t[3],&t[4],&t[5]);
      T.push_back(make_pair(t[0]*3600+t[1]*60+t[2], 1));
      T.push_back(make_pair(t[3]*3600+t[4]*60+t[5], -1));
    }
    ans = 0;
    k = 0;
    sort(T.begin(), T.end());
    for (int i = 0; i < 2*n; ++i) {
      k += T[i].second;
      ans = max(ans, k);
    }
    cout << ans << endl;
    T.erase(T.begin(), T.end());
  }
  return 0;
}

Measured memory_bytes: 3276