akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] h = new int[N];
        for(int i = 0; i < N; i++){
            h[i] = sc.nextInt();
        }
        sc.close();
        Arrays.sort(h);
        int a = N;
        for(int i = 0; i < N; i++){
            if(h[i] >= K){
                a = i;
                break;
            }
        }
        System.out.println(N-a);
    }
}

Measured memory_bytes: 49484
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <chrono>
#include <random>
#include <cmath>
using namespace std;
using namespace __gnu_pbds;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define uid uniform_int_distribution<lli>
#define lli long long int
#define ff first
#define ss second
#define pb push_back
#define popf pop_front()
#define popb pop_back()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define forr(x,arr) for(auto& x:arr)
#define sz(x) (x.size())
#define mod 1000000007
#define INF 1000000000000000010
#define vi vector<int>
#define vlli vector<lli>
#define endl "\n"
#define ofk order_of_key
#define fbo find_by_order
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

template<class my>
using indexed_set = tree<my,null_type,less<my>,rb_tree_tag,tree_order_statistics_node_update>;

template <class my>
inline my aabs (const my &a)   { return (a > 0)  ? a : -a;         }
inline lli gcd(lli a, lli b)   { return (b == 0) ? a : gcd(b,a%b); }
inline lli LSOne(lli k)        { return (k&(-k));                  }

inline int inv(lli o, int m = mod) {
  int b = m, u = 0, v = 1, t, a=o%m;
  while (a) {
    t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  if (u < 0) u += m;
  return u;
}
inline int add(const int &a, const int &b, int m=mod) { return ( a + b ) % m;           }
inline int sub(const int &a, const int &b, int m=mod) { return ( a - b + m ) % m;       }
inline int mul(const int &a, const int &b, int m=mod) { return int ( 1LL * a * b % m ); }
inline int mpow(int a, int b, int m=mod) {
    int ans = 1;
    a=((a%m)+m)%m;
    while (b) {
        if (b & 1) ans = mul(ans, a, m);
        a = mul(a, a, m);
        b >>= 1;
    }
    return ans;
}

void tejas_919()
{
    lli n, k, m, q, u=0, v=0, temp=1, a, b, val=0;
    cin>>n;
    fol(i,1,n+1)
    {
        cin>>temp;
        if(temp!=i) val++;
    }
    if(val<=2) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

int main()
{
    fastio
    cout << fixed << setprecision(10);
    int t=1;
    //cin>>t;
    while(t--)
        tejas_919();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;

int main(void)
{
    int D;
    cin >> D;

    if (D == 25)
    {
        cout << "Christmas" << endl;
    }
    else if (D == 24)
    {
        cout << "Christmas Eve" << endl;
    }
    else if (D == 23)
    {
        cout << "Christmas Eve Eve" << endl;
    }
    else
    {
        cout << "Christmas Eve Eve Eve" << endl;
    }
    return (0);
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
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 int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.out


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

    int d,g;
    cin>>d>>g;
    vi p(d),c(d);
    rep(i,d)cin>>p[i]>>c[i];
    //貪欲解法
    int tmp=g;
    int place=d-1;
    int greedy=0;
    while(tmp>0){
        if(p[place]*(place+1)*100+c[place]>tmp){
            while(tmp>0){
                tmp-=(place+1)*100;
                greedy++;
            }
        }
        else{
            tmp-=p[place]*(place+1)*100+c[place];
            greedy+=p[place];
            place--;
        }
    }
    ll ans=greedy;

    //ここからbit全探索
    for (int bit=0;bit<(1<<d);++bit){
        /* bit で表される集合の処理を書く */

        /* きちんとできていることを確認してみる */
        // bit の表す集合を求める
        tmp=g;
        ll bitnum=0;
        vector<int> S;
        for(int i=0;i<d;++i) {
            if(bit&(1<<i)){ // i が bit に入るかどうか
                S.push_back(i);
            }
        }

        for(int i=0;i<S.size();i++){
            tmp-=p[S[i]]*(S[i]+1)*100+c[S[i]];
            bitnum+=p[S[i]];
        }
        if(tmp<=0)ans=min(ans,bitnum);/*
        cout<<tmp<<" "<<ans<<" "<<bitnum<<endl;

        // bit の表す集合の出力
        cout<<bit<<": {";
        for(int  i=0;i<(int)S.size();++i) {
            cout<<S[i]<< " ";
        }
        cout <<"}"<< endl;*/
    }
    cout<<ans<<endl;

//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
typedef long long ll;
const ll INF = 1LL<<60;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
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; }
using namespace std;

int a, b;

int main() {
    cin >> a >> b;
    if (a > 9 || b > 9) cout << "-1" << endl;
    else cout << a * b << endl;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int x,y;
    cin >> x;
    if(x < 10 || x%1000 == 0) {
        cout << "Yes" << endl;
    } else {
        y = x % 10;
        if(y == (x % 100 /10) 
            && y == (x % 1000 /100))
            cout << "Yes" << endl;
        else {
            y = x % 100 /10;
            if(y == (x % 1000 /100)
                && y == (x / 1000))
                cout << "Yes" << endl;
            else
                cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
import math

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n
    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]
    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

z = 10**9+7

X, Y = map(int, input().split())
x = (-X+2*Y)/3
y = (2*X-Y)/3
if x.is_integer() and y.is_integer() and x>=0 and y>=0:
    x = int(x)
    y = int(y)
    maximam = max(x,y)
    minimam = min(x,y)
    print(cmb(x+y,minimam)%z)
else:
    print(0)

Measured memory_bytes: 102028
//question is based on parity.
#include<iostream>
using namespace std;
int main()
{
	long long int n,a,b;
	cin>>n>>a>>b;
	if(((b-a)%2)==0)
	{
		cout<<"Alice"<<endl;
	}
	else
	{
		cout<<"Borys"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
N,K=map(int,input().split())
D=[1]*10
for i in map(int,input().split()):
  D[i]=0
ans=''
while N>0:
  n=N%10
  N=N//10
  while D[n%10]==0:
    n+=1
  if n>9:
    N+=1
  elif N>0 and D[N%10]==0:
    for i in range(n):
      if D[i]==1:
        n=i
        break
  ans+=str(n%10)
if ans=='':
  print(N)
else:
  print(ans[::-1])

Measured memory_bytes: 3064
/******************************************
*    AUTHOR:         Atharva Sarage       *
*    INSTITUITION:   IIT HYDERABAD        *
******************************************/
#include<bits/stdc++.h>
#warning Check Max_Limit,Overflows
using namespace std;
# define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
# define ff first
# define ss second
# define pb push_back
# define mod 1000000007
# define ll int long long 
# define db double
# define inf (long long)1e15
# define mx2 100005
# define mx 405
ll dp[mx][mx],a[mx],pre[mx];
ll solve(ll i,ll j)
{
	if(i>j)
		return inf;
	if(i==j)
		return 0;
	ll &w=dp[i][j];
	if(w!=-1)
		return w;
	w=inf;
	for(ll l=i;l<j;l++)
		w=min(w,solve(i,l)+solve(l+1,j));
	w+=pre[j]-pre[i-1];
	return w;
}
int main()
{
	memset(dp,-1,sizeof(dp));
	IOS;
	ll n;
	cin>>n;
	for(ll i=1;i<=n;i++)
		cin>>a[i];
	pre[0]=0LL;
	for(int i=1;i<=n;i++)
		{pre[i]=pre[i-1]+a[i];}
	cout<<solve(1,n)<<endl;
}


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

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a.at(i);
    rep(i,min(k,1000)){
        vector<int> x(n);
        vector<int> y(n);
        rep(j,n){
            x.at(max(0,j-a.at(j)))++;
            y.at(min(n-1,j+a.at(j)))++;
            // cout << j << " " << a.at(i) << " " << min(n-1,j+a.at(j)) << endl;
        }
        rep(j,n-1)
        {
            x.at(j+1) = x.at(j) + x.at(j+1);
            y.at(n-2-j) = y.at(n-2-j) + y.at(n-2-j+1);
        }
        // rep(j,n) cout << x.at(j) << " ";
        // cout << endl;

        rep(j,n){
            a.at(j) = x.at(j) + y.at(j) - n;
        }
    }
    rep(i,n) cout << a.at(i) << " ";
    cout << endl;
    return 0;
}

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

int main(){
  int a,b;
  cin >> a >> b;
  
  int count=0;
  while(a){
    count++;
    a /=b;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;
    vector<vector<int>> edges(n);
    for (int i = 0; i < n - 1; ++i) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        edges[u].emplace_back(v);
        edges[v].emplace_back(u);
    }
    vector<lint> dp(n, 0);
    for (int i = 0; i < q; ++i) {
        int p, q;
        cin >> p >> q;
        p--;
        dp[p] += q;
    }
    function<void(int, int)> dfs = [&](int c, int p) {
        for (auto &v : edges[c]) {
            if (v == p)
                continue;
            dp[v] += dp[c];
            dfs(v, c);
        }
    };
    dfs(0, -1);
    for (int i = 0; i < n; ++i) {
        if (i != 0)
            cout << " ";
        cout << dp[i];
    }
    cout << endl;
    return 0;
}

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

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

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define MMP(a, b, c) make_pair(make_pair(a, b), c)
#define MAX 1000000000
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define PI 3.14159265359

int main(){
    iostream::sync_with_stdio(false);

    int W,H,N;
    cin >> W >> H >> N;
    int x_min = W;
    int x_max = 0;
    int y_min = H;
    int y_max = 0;
    for(int i=0; i<N; i++){
        int x,y,a;
        cin >> x >> y >> a;
        if(a == 1){
            x_max = max(x_max, x);
        }
        if(a == 2){
            x_min = min(x_min, x);
        }
        if(a == 3){
            y_max = max(y_max, y);
        }
        if(a == 4){
            y_min = min(y_min, y);
        }
    }
    cout << max(0, x_min-x_max) * max(0, y_min-y_max) << endl;
    
    return 0;
}

Measured memory_bytes: 256
from itertools import product
N, A, B, C = map(int, input().split())
abc = [C, B, A]
lst = [int(input()) for _ in range(N)]

ans = []
for l in product([0, 1, 2, 3], repeat=N):
    cnt = [[], [], [], []]
    for i, ll in enumerate(l):
        cnt[ll].append(lst[i])
    mp = 0
    p = []
    for i in cnt[:3]:
        if len(i) != 0: mp += (len(i) - 1) * 10
        p.append(sum(i))
    p.sort()
    if p[0]!=0:
        for i in range(3):
            mp += abs(p[i] - abc[i])
        ans.append(mp)
print(min(ans))

Measured memory_bytes: 10924
/*Saurav Paul*/
#include<bits/stdc++.h>
using namespace std;

int main()
{
  int n, m;
  cin >> n >> m;
  int x = n, y = m;
  if (n > m){
    swap(x, y);
  }
  for (int i = 0; i < y ; i++)
    cout << x;
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace Myatcoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            int[] A = Console.ReadLine().Split().Select(a => int.Parse(a)).ToArray();
            int n = A[0], m = A[1], x = A[2], y = A[3];
            int[] X = Console.ReadLine().Split().Select(a => int.Parse(a)).ToArray();
            int[] Y = Console.ReadLine().Split().Select(a => int.Parse(a)).ToArray();
            Array.Sort(X);
            Array.Sort(Y);
            if (X[n - 1] < Y[0] && x < Y[0] && X[n - 1] < y) Console.WriteLine("No War");
            else Console.WriteLine("War");
        }
    }
}

Measured memory_bytes: 13396
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define pb push_back
#define vl vector
#define ff first
#define ss second
using namespace std;
int main()
{
    ll a,b,i,j,n,t;
    cin>>a>>b;
    a*=3;
    a+=b;
    cout<<a/2;
}

Measured memory_bytes: 3532
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
const int mo=1e9+7;
int n,m,f[301][301][301];
bool v[301][301][301];
void Update(int i,int j,int k) {
    v[i][j][k]=v[i][k][j]=v[j][i][k]=0;
    v[k][i][j]=v[j][k][i]=v[k][j][i]=0;
}
int main() {
    scanf("%d%d",&n,&m);
    memset(v,1,sizeof(v));
    for (int i=1;i<=m;i++) {
        int li,ri,xi;
        scanf("%d%d%d",&li,&ri,&xi);
        if (xi==1) {
            for (int j1=li;j1<ri;j1++)
                for (int j2=0;j2<j1;j2++) Update(ri,j1,j2);
        }
        else if (xi==2) {
            for (int j1=0;j1<li;j1++)
                for (int j2=0;j2<=j1;j2++) Update(ri,j1,j2);
            for (int j1=li;j1<ri;j1++)
                for (int j2=j1+1;j2<ri;j2++) Update(ri,j1,j2);
        }
        else {
            for (int j1=0;j1<li;j1++)
                for (int j2=j1;j2<ri;j2++) Update(ri,j1,j2);
        }
    }
    f[0][0][0]=1;
    int ans=0;
    for (int i1=0;i1<=n;i1++)
        for (int i2=0;i2<=n;i2++)
            for (int i3=0;i3<=n;i3++) {
                if (v[i1][i2][i3]==0) f[i1][i2][i3]=0;
                int k=max(i1,max(i2,i3));
                if (k==n) {
                    ans=(ans+f[i1][i2][i3])%mo;
                    continue;
                }
                f[k+1][i2][i3]=(f[i1][i2][i3]+f[k+1][i2][i3])%mo;
                f[i1][k+1][i3]=(f[i1][i2][i3]+f[i1][k+1][i3])%mo;
                f[i1][i2][k+1]=(f[i1][i2][i3]+f[i1][i2][k+1])%mo;
            }
    printf("%d\n",ans);
    return 0;
}


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

int main(){
    vector<int> l(3);
    for(int i=0;i<3;i++) cin>>l.at(i);
    sort(l.begin(),l.end());
    int x=l.at(2),y=l.at(0)+l.at(1),k;cin>>k;
    int ans=x*pow(2,k)+y;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/

	coding: utf-8
	lang: C (GCC 5.4.1)
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long
#define TBMod 1000000007

// fact(n)
int fact(int n){
	if(n == 1)	return 1;
	else return (n * fact(n - 1));
}

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

// lcm(a,b)
int lcm(int a,int b){
	return (a * b) / gcd(a,b);
}

// nCr(n,r) & utility
int nCrVal[5003][5003];
int nCrSetUp(int n){
	for(int i = 0; i <= n; ++i){
		for(int j = 0; j <= i / 2 + 1; ++j){
			if(j == 0)  nCrVal[i][j] = 1;
			else  nCrVal[i][j] = nCrVal[i - 1][j - 1] + nCrVal[i - 1][j];
			nCrVal[i][i - j] = nCrVal[i][j];
 		}
	}
}

int nCr(int n, int r){
	if(nCrVal[n][r] == 0)	nCrSetUp(n + 1);
	return nCrVal[n][r];
}

// swap(&a, &b);
void swap(int *a,int *b){
	int tmp;
	tmp = *a;	*a = *b;	*b = tmp;
	return;
}

// qsort(array, size, sizeof(int),comp);
int ASC(const int *a,const int *b){
	return (*a - *b);
}

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

// append(array,*size,addNum)
void append(int *array,int *size,int num){
	realloc(array, sizeof(int) * (*size + 1));
	array[(*size)] = num;
	++(*size);
}

// pop(array,*size) & nongetpop(array,*size)
int pop(int *array,int *size){
	int temp = array[(*size - 1)];
	realloc(array,sizeof(int) * (*size - 1));
	--(*size);
	return temp;
}

int main(int argc, char const *argv[])
{
	int n;
	char s[100003];
	TLong ans = 1, charcnt[26] = { 0 };

	scanf("%d", &n);
	scanf("%s", s);

 	for(int i = 0; i < n; ++i)	++charcnt[s[i] - 'a'];
 	for(int i = 0; i < 26; ++i) ans = ans * (charcnt[i] + 1) % TBMod;
 	printf("%lld\n", (ans + TBMod - 1) % TBMod);
}


Measured memory_bytes: 256
// 20:44 - 21:13
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define lch (o << 1)
#define rch (o << 1 | 1)

typedef double db;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pint;

const int N = 2e5 + 5;
const int INF = 0x3f3f3f3f;
const ll INF_LL = 0x3f3f3f3f3f3f3f3f;

struct Point {
	int x, y, dir;
};
Point p[N];
vector<int> diag[N * 2][4], sdiag[N * 2][4], xaxis[N * 2][4], yaxis[N * 2][4];

const int CDIR[] = {'U', 'R', 'D', 'L'};
const int DIR[] = {3, 2, 1, 0};

int main() {
	ios::sync_with_stdio(0);

	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int x, y;
		char c;
		cin >> x >> y >> c;
		int dir = 0;
		for (int d = 0; d < 4; d++)
			if (c == CDIR[d])
				dir = d;
		p[i] = (Point){x, y, dir};

		diag[y - x + N][dir].push_back(x);
		sdiag[x + y][dir].push_back(x);
		if (dir % 2 == 1)
			xaxis[y][dir].push_back(x);
		else
			yaxis[x][dir].push_back(y);
	}

	for (int d = 0; d < 4; d++) {
		for (int i = 0; i < 2 * N; i++) {
			sort(diag[i][d].begin(), diag[i][d].end());
			sort(sdiag[i][d].begin(), sdiag[i][d].end());
			sort(xaxis[i][d].begin(), xaxis[i][d].end());
			sort(yaxis[i][d].begin(), yaxis[i][d].end());
		}
	}

	ll minT = INF_LL;
	for (int i = 1; i <= n; i++) {
		int x = p[i].x, y = p[i].y;
		int dir = p[i].dir;
		int ndir = (dir + 2) % 4;
		int diagDir = DIR[dir];
		int sdiagDir = (diagDir + 2) % 4;

		auto &_diag = diag[y - x + N][diagDir];
		auto &_sdiag = sdiag[x + y][sdiagDir];
		auto o = lower_bound(_diag.begin(), _diag.end(), x);
		auto q = lower_bound(_sdiag.begin(), _sdiag.end(), x);

		if ((diagDir == 2 || diagDir == 3) && o != _diag.end())
			minT = min(minT, abs(*o - x) * 10LL);
		if ((diagDir == 0 || diagDir == 1) && o != _diag.begin())
			minT = min(minT, abs(*(o - 1) - x) * 10LL);

		if ((sdiagDir == 3 || sdiagDir == 0) && q != _sdiag.end())
			minT = min(minT, abs(*q - x) * 10LL);
		if ((sdiagDir == 1 || sdiagDir == 2) && q != _sdiag.begin())
			minT = min(minT, abs(*(q - 1) - x) * 10LL);

		// parallel to x axis
		if (dir % 2 == 1) {
			auto &_xaxis = xaxis[y][ndir];
			auto r = lower_bound(_xaxis.begin(), _xaxis.end(), x);
			if (dir == 1 && r != _xaxis.end())
				minT = min(minT, abs(*r - x) * 5LL);
			if (dir == 3 && r != _xaxis.begin())
				minT = min(minT, abs(*(r - 1) - x) * 5LL);
		}

		// parallel to y axis
		if (dir % 2 == 0) {
			auto &_yaxis = yaxis[x][ndir];
			auto r = lower_bound(_yaxis.begin(), _yaxis.end(), y);
			if (dir == 0 && r != _yaxis.end())
				minT = min(minT, abs(*r - y) * 5LL);
			if (dir == 2 && r != _yaxis.begin())
				minT = min(minT, abs(*(r - 1) - y) * 5LL);
		}
	}

	if (minT == INF_LL)
		cout << "SAFE";
	else
		cout << minT << endl;

	return 0;
}


Measured memory_bytes: 174712
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(x)    (x).begin(),(x).end()
typedef long long ll;
const int MOD = (int)1e9 + 7;

int main(){
  int n;
  cin >> n;
  vector<pair<int,int> > student(n);
  rep(i,n){
    int order;
    cin >> order;
    student[i] = make_pair(order, i+1);
  }
  sort(all(student));
  rep(i,n){
    cout << student[i].second << " ";
  }
  cout << endl;
}



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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

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

    vector<string> S(N);
    rep(i, N) cin >> S[i];

    map<char, int> mp;
    for (char c = 'a'; c <= 'z'; ++c) mp[c] = INF;
    for (char c = 'a'; c <= 'z'; ++c) {
        int res = INF;
        rep(i, N) {
            int cnt = 0;
            for (auto &j : S[i]) {
                if (c == j) cnt++;
            }
            res = min(res, cnt);
        }
        mp[c] = res;
    }

    for (auto &i : mp) {
        if (i.second != INF) {
            rep(j, i.second) cout << i.first;
        }
    }
    cout << endl;
}

Measured memory_bytes: 256
f = true
loop do
  n = gets.to_i
  break if n.zero?
  puts unless f
  f = false
  n.times.map {|i|
    c, *xs = gets.split
    w, l, d = xs.map(&:to_i)
    [3 * w + 0 * l + 1 * d, -i, c]
  }.sort.reverse.each {|p, _, c| puts "#{c},#{p}" }
end

Measured memory_bytes: 8728
// ConsoleApplication1.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//


#include <iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
using namespace std;
#define rep(i, n) for(long i = 0; i < n; i++)
#define erep(i, n) for(long i = 1; i <= n; i++)
#define show(ans) cout << ans << endl
const long MOD = 1000000007;

unsigned euclidean_gcd(unsigned a, unsigned b) {
	if (a < b) euclidean_gcd(b, a);
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}

int main() {
	long N;
	long ans;
	cin >> N;
	vector<long> a(N + 1);
	erep(i, N) {
		cin >> a[i];
	}
	ans = a[1];
	for (long i = 2; i <= N; i++) {
		ans = euclidean_gcd(ans, a[i]);
	}
	show(ans);
	return 0;

}
// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


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

int main() {
  string s;
  cin >> s;
  for(int i=0; i < 3; i++) {
    if(s[i] == s[i+1]) {
      cout << "Bad" << endl;
      return 0;
    }
  }
  cout << "Good" << endl;
  return 0;
}

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

struct Edge {
  int to, id;
};
vector<vector<Edge>> g;
vector<int> ans;

void dfs(int v, int c = -1, int p = -1) {
  int k = 1;
  rep(i, g[v].size()) {
    int u = g[v][i].to, ei = g[v][i].id;
    if(u == p) continue;
    if(k == c) k++;
    ans[ei] = k; k++;
    dfs(u, ans[ei], v);
  }
}

int main(){
  int n;
  cin >> n;
  g.resize(n);
  ans = vector<int>(n-1);
  rep(i, n-1){
    int a, b;
    cin >> a >> b;
    a--; b--;
    g[a].push_back((Edge){b, i});
    g[b].push_back((Edge){a, i});
  }
  dfs(0);
  int mx = 0;
  rep(i, n) mx = max(mx, int(g[i].size()));
  cout << mx << endl;
  rep(i, n- 1){
    cout << ans[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 8320
#include<iostream>
#include<algorithm>
#include<vector>
#include<limits>

using namespace std;

template<typename T>
class MaxHeap{
  public:
    vector<T> a;
    const T INF;
    MaxHeap(int n):INF(numeric_limits<T>::max()/2){a.resize(n+1, INF);}
    MaxHeap():INF(numeric_limits<T>::max()/2){a.resize(1,INF);}
    T findMax(){return a[1];}
    T findMin(){ return a.size() > 3? min(a[2], a[3]): a[1+(a.size()==3)];}
    bool empty() { return a.size() == 1; }
    void insert(T x){a.push_back(x);rmx(a.size()-1);}
    void buildMaXHeap(){for(int i = (a.size()-1)/2; i > 0; --i) mx(i);}
    T pop(){
      T tmp = a[1];
      a[1] = a.back();
      a.pop_back();
      mx(1);
      return tmp;
    }

    // i?????????????´????????????????????????????
    void mx(int i){
      int l = i*2;
      int r = i*2+1;
      T largest = INF;

      if(l < a.size() && a[l] > a[i]){
        largest = l;
      }else{
        largest = i;
      }

      if(r < a.size() && a[r] > a[largest])
          largest = r;

      if(largest != i){
        swap(a[i], a[largest]);
        mx(largest);
      }
    }

    // i?????????????´????????????????????????????
    void rmx(int i){
      while(a[i/2] < a[i]){
        swap(a[i/2], a[i]);
        i/=2;
      }
    }
};




int main(void){
  int n, a;
  string str;
  MaxHeap<int> hp(0);

  while(1){
    cin >> str;
    if(str == "insert"){
      cin >> a;
      hp.insert(a);
    }else if(str == "extract"){
      cout << hp.pop() << endl;
    }else{
      break;
    }
  }
  return 0;
}

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

typedef unsigned long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;

#define INF (int)(1e9)

#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,start,end) for(int i=(start);i<=(end);i++)
#define all(n) begin(n),end(n)

#define DEBUG

int main()
{
	string s;
	cin >> s;
	int ans = 0;
	rep(i,4)
	{
		if(s[i] == '+') ans++;
		else ans--;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl "\n"
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define REP(i, n) for(int i = 0; i < n; i++)
using Graph = vector<vector<int>>;

int main(){
    ll ai,ao,at,aj,al,as,az;
    cin>>ai>>ao>>at>>aj>>al>>as>>az;
    ll ans = 0;

    ll three = min({ai,aj,al});
    ans = three*3 + (ai-three)-(ai-three)%2 + 
        (aj-three)-(aj-three)%2 + (al-three)-(al-three)%2;

    three = min({ai,aj,al})-1;
    if(three < 0) three = 0;
    ll tmp = three*3 + (ai-three)-(ai-three)%2 + 
        (aj-three)-(aj-three)%2 + (al-three)-(al-three)%2;

    ans = max(ans,tmp);

    ans += ao;
    
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int cnt,m;
int G[100];
void printfa(int G[],int m){
	int i;
	for(i=m-1;i>-1;i--){
		if(i<m-1){
			printf(" ");
		}
		printf("%d",G[i]);
		if(i==0){
			printf("\n");
		}
	}
}
void insertionSort(int A[], int n,int g){
	int i,j,v;
	for (i=g;i<n;i++){
		v = A[i];
		j = i - g;
		while(j >= 0 && A[j] > v){
			A[j+g] = A[j];
			j = j - g;
			cnt++;
		}
		A[j+g] = v;
	}
}

void shellSort(int A[],int n){
	int i;
	int h=1;
	for(i=0;i<n;i++){
		if(h>n){
			break;
		}
		G[i]=h;
		h=3*h+1;
		m++;
	}
	for(i=m;i>=0;i--){
		insertionSort(A, n, G[i]);
	}
}
int main(void){
	int A[1000000];
	int i,n;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf(" %d",&A[i]);
	}
	shellSort(A,n);
	printf("%d\n",m);
	printfa(G,m);
	printf("%d\n",cnt);
	for(i=0;i<n;i++){
		printf("%d\n",A[i]);
	}
	return 0;
}


Measured memory_bytes: 5636
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;

int main(){
    ll x;
    cin>>x;
    cout<<(x>=30?"Yes":"No")<<endl;
    return 0;
}

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

const int inf = 1000;
const int maxlen = 5;
int Shuffle_pre[6][120][1<<maxlen];
int fac[6];

inline int shuffle_bitmask(int len,const vector<int>& p, int x){
	int y=0;for(int i=0;i<len;i++)if(x&(1<<i))y^=1<<p[i];
	return y;
}

void init(){
	fac[0]=fac[1]=1;for(int n=2;n<=maxlen;n++){
		int z=0;
		fac[n]=fac[n-1]*n;
		vector<int> p(n);
		for(int i=0;i<n;i++)p[i]=i;
		while(next_permutation(p.begin(),p.end())){
			for(int b=0;b<1<<n;b++){
				Shuffle_pre[n][z][b]=shuffle_bitmask(n,p,b);
			}++z;
		}
	}
}

bool check(int len,vector<int> c){
	static bool arr[1<<maxlen];
	for(int i=0;i<1<<len;i++)arr[i]=0;
	for(size_t i=0;i<c.size();i++)arr[c[i]]=1;
	for(int i=0;i<fac[len]-1;i++){
		bool w=1;for(size_t j=0;j<c.size();j++){
			w&=arr[Shuffle_pre[len][i][c[j]]];
		}
		if(w)return 0;
	}
	return 1;
}


inline int dfs(int len,int q,int last,vector<int>& cur){
	if(q==0)return check(len,cur);
	int ret=0;for(int i=last+1;i<(1<<len) && ret/fac[len] <= inf;i++){
		cur.push_back(i);
		ret+=dfs(len,q-1,i,cur);
		cur.pop_back();
	}
	return ret;
}
typedef long long ll;
inline int solve(ll k, ll n){
	if(k>n)swap(k,n);
	if(n>(1ll<<k)-n)return solve(k, (1ll<<k)-n);
	if(k>maxlen)return -1;
	vector<int> cur= vector<int>();
	int res=dfs(k,n,-1,cur)/fac[k];
	return res>inf?-1:res;
}

inline int g(ll n){
	if(n==1)return 0;
	for(int k=0;k<=n;k++)if((1ll<<k)>=n && (1ll<<k)-g(k)>=n)return k;
	return -1;
}

int main()
{
	init();
	ll n;
	cin >> n;
	ll ret=solve(g(n), n);
	if(n==4)ret++;
	if(n==7)ret+=2;
	cout << ret << endl;
}


Measured memory_bytes: 3648
sum = []
ava = []
while line = gets
line = line.split(",").map{|i| i.to_i}
sum << line[0]*line[1]
ava << line[1]
end
sum = sum.inject{|sum,n| sum+n}
ava_sum = 0
count = 0
for i in ava do
ava_sum += i
count += 1
end
ava_sum = (ava_sum/count.to_f).round

puts sum
puts ava_sum


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

#define MAXN 110000
ll n,m;
vector<vector<int>>edges(MAXN, vector<int>());

ll dp1[MAXN];
void dfs1(int x, int p=-1){
  dp1[x]=1;
  for(auto c:edges[x]){
    if(c==p)continue;
    dfs1(c,x);
    dp1[x] *= dp1[c];
    dp1[x] %= m;
  }
  dp1[x]++;
  dp1[x] %= m;
}

ll dp2[MAXN];
void dfs2(int x, int p=-1){
  if(p==-1)dp2[x]=1;
  int ec=edges[x].size();

  vector<ll> lprod;
  rep(i, ec){
    int c = edges[x][i];

    if(c==p){
      if(lprod.size())lprod.push_back(lprod.back());
      else lprod.push_back(1);
      continue;
    }


    if(lprod.size()){
      lprod.push_back(lprod.back());
    }else{
      lprod.push_back(1);
    }

    lprod.back() *= dp1[c];
    lprod.back() %= m;
  }

  vector<ll> rprod;
  rrep(i, ec){
    int c = edges[x][i];

    if(c==p){
      if(rprod.size())rprod.push_back(rprod.back());
      else rprod.push_back(1);
      continue;
    }

    if(rprod.size()){
      rprod.push_back(rprod.back());
    }else{
      rprod.push_back(1);
    }

    rprod.back() *= dp1[c];
    rprod.back() %= m;
  }
  reverse(rprod.begin(), rprod.end());

//for(auto c: lprod)cout<<c<<' ';cout<<endl;
//for(auto c: rprod)cout<<c<<' ';cout<<endl;


  rep(i, ec){
    int c = edges[x][i];
    if(c==p)continue;
    dp2[c] = dp2[x];
    if(i)dp2[c] *= lprod[i-1];
    dp2[c] %= m;
    if(i<ec-1)dp2[c] *= rprod[i+1];
    dp2[c] %= m;
    dp2[c]++;
    dp2[c]%=m;
    dfs2(c, x);
  }
}

ll ans[MAXN];
void dfs3(int now, int p=-1){
  ans[now] = dp2[now];
  for(auto c:edges[now]){
    if(c==p)continue;
    ans[now] *= dp1[c];
    ans[now] %= m;
    dfs3(c, now);
  }
}

int main(){
  cin>>n>>m;
  rep(i, n-1){
    int x,y;cin>>x>>y;x--,y--;
    edges[x].push_back(y);
    edges[y].push_back(x);
  }

  dfs1(0);
  dfs2(0);
  dfs3(0);
 
  rep(i, n)cout<<ans[i]<<endl;

  return 0;

  rep(i, n)cout<<dp1[i]<<' ';cout<<endl;
  rep(i, n)cout<<dp2[i]<<' ';cout<<endl;

  return 0;
}


Measured memory_bytes: 27284
using System;

class Program
{
	static void Main(string[] args)
	{
		var value_1 = Console.ReadLine().Split(' ');
		var value_2 = Console.ReadLine().Split(' ');
		var H = int.Parse(value_1[0]);
		var W = int.Parse(value_1[1]);
		var h = int.Parse(value_2[0]);
		var w = int.Parse(value_2[1]);
		
		Console.WriteLine(H * W - (h * W + (H - h) * w));
		
	}
}

Measured memory_bytes: 13140
n=int(input())
suit = ["S","H","C","D"]
card = {i:[] for i in suit}
for i in range(n):
   tmp = ([c for c in input().split()])
   card[tmp[0]].append(tmp[1])

for i in suit:
    for j in range(1,14):
        if not (str(j) in card[i]):
            print("%s %s" % (i,j))

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

int main(){
  int n;
  int total = 0;
  cin >> n;
  vector<int> d(n,0);
  rep(i,n) cin >> d.at(i);

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


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define MP(a,b) make_pair(a,b)
typedef long long LL;
typedef pair<int, int> PI;
typedef pair<LL, int> PLL;
typedef vector<int> VI;
const LL MOD = 1000000007LL;
LL comb[51][51];
int main() {
	comb[0][0] = 1;
	for (int i = 1; i <= 50; i++) {
		comb[i][0] = comb[i][i] = 1;
		for (int j = 1; j <= i - 1; j++) {
			comb[i][j] = comb[i - 1][j] + comb[i - 1][j - 1];
		}
	}
	int N, P;
	cin >> N >> P;
	int odd = 0, even = 0;
	rep(i, N) {
		int A;
		cin >> A;
		if (A % 2 == 0) even++;
		else odd++;
	}
	LL ans = 1LL << even;
	LL sum = 0;
	for (int i = P; i <= odd; i += 2) sum += comb[odd][i];
	ans *= sum;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#define MAXN 1006
#include<cstring>
#include<algorithm>
#define MOD 1000000007
using namespace std;
long long k,ud,lr,v,eh,ev;
int n,m;
char G[MAXN][MAXN];
long long ksm(long long a,long long b)
{
	if(!b) return 1;
	long long nex=ksm(a,b/2);
	nex=(nex*nex)%MOD;
	if(b%2==1) nex=(nex*a)%MOD;
	return nex;
}
struct node
{
	long long a[4][4];
}a,b;
node operator *(node a,node b)
{
	node re;
	memset(re.a,0,sizeof re.a);
	for(int i=1;i<=2;i++)
		for(int j=1;j<=2;j++)
			for(int k=1;k<=2;k++)
			{
				re.a[i][j]+=(a.a[i][k]%MOD)*(b.a[k][j]%MOD);
				re.a[i][j]%=MOD;
			}
	return re;
}
node matksm(node a,long long k)
{
	if(k==1) return a;
	node nex=matksm(a,k/2);
	nex=nex*nex;
	if(k%2==1) nex=nex*a;
	return nex;
}
int main()
{
	scanf("%d%d%lld",&n,&m,&k);
	for(int i=1;i<=n;i++)
		scanf("%s",G[i]+1);
	if(k==1||k==0)
	{
		printf("1");
		return 0;
	}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		{
			if(G[i][j]=='#')
			{
				v++;
				if(G[i][j+1]=='#') eh++;
				if(G[i-1][j]=='#') ev++;
				if(i==1)
				{
					if(G[n][j]=='#') ud++;
				}
				if(j==1)
				{
					if(G[i][m]=='#') lr++;
				}
			}
		}
	if(lr>0&&ud>0)
	{
		printf("1");
		return 0;
	}
	if(lr==0&&ud==0)
	{
		printf("%lld",ksm(v,k-1));
		return 0;
	}
	if(lr>0)
	{
		swap(lr,ud);
		swap(ev,eh);
	}
	a.a[1][1]=ud;
	a.a[2][1]=ev;
	a.a[1][2]=0;
	a.a[2][2]=v;
	b.a[1][1]=0;
	b.a[1][2]=1;
	b=b*matksm(a,k-1);
	printf("%lld",((b.a[1][2]-b.a[1][1])%MOD+MOD)%MOD);
}

Measured memory_bytes: 1280
//コンパイラ最適化用
#pragma GCC optimize("Ofast")

//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<chrono>//実行時間計測
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm,accumulate
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//順序保持しないmap
#include<unordered_set>//順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

// clang++ main.cc -std=c++11 -stdlib=libc++

signed main(){
  int res = 0;
  int N;
  cin >> N;
  if (N >= 30)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 3592
n=int(input())
a=list(map(int,input().split()))
import collections as c
d=c.Counter(a)
d=list(d.items())
d=sorted(d,reverse=True)
x,y=0,0
for i in d:
    if i[1]>=4 and x==0 and y==0:
        print(i[0]**2)
        exit()
    if x==0 and i[1]>=2:
        x=i[0]
        continue
    if y==0 and i[1]>=2:
        y=i[0]
        break
print(x*y)

Measured memory_bytes: 21384
#include <bits/stdc++.h>
#define SpeeD ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define ll long long
#define endl '\n'
//pair<int, int> *p=new pair<int, int>[n];
//std::vector<pair<int,int>> vp;
//v.push_back(make_pair(x,y))
//pair<int, int> p[1000001];
//string *s=new string [n];
//int freq[e];
//freq[a[i]-'a']++; freq[a[i]]++;
using namespace std;
ll n, t, m, c1, c2, c, x, y, sum, mn = 999999999, avg, pos, dif,k, mx, xi, yi, q;
const int MXN=1e5+7;
ll pre[MXN];
bool prime[MXN];

bool PE ( ll x )
{
    for ( ll i = 2; i * i <= x; i+=1+(i&1))
    if ( x % i == 0 )
    return false;
    return true;
}
ll dist[MXN];
void sieve()
{
    memset(prime , 1 , sizeof prime);

    for ( ll i = 2; i * i <= MXN; i+=1+(i&1))
    if (prime[i])
    {
          for (ll j = i * i; j < MXN; j +=i)
         prime[j] = false;
    }
}

bool PR ( string s )
{
    int n = s.length();
    for ( ll i = 0; i < n / 2; i++ )
    if ( s[i] != s[n - i - 1] )
    return false;
    return true;
}

int main (void){
    SpeeD;

   cin >> n; 
   t = n;
   c = 0;
    if (n %1000 != 0)
    c++;
    
    n/=1000;
     n += c;
    n*=1000;
    cout << abs(t - n);
}












Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define oo 0x3f3f3f3f
#define ooLL 0x3f3f3f3f3f3f3f3f
#define mod 1e9+7
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef long long ll;
typedef vector<pair<int,int>> vii;
typedef pair<int,int> pii;
 
int main(){
    int n;
    map<string, int> m;
    cin >> n;
    for(int i = 0; i < n ; ++i){
        string s;
        cin >> s;
        m[s]++;
    }

    printf("%d\n", m.size());
}

Measured memory_bytes: 19352
#include <iostream>

using namespace std;

int main(void)
{
   int n;
   int a[100];
   float sum;

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

   for(int i = 0; i < n; i++){
      sum += (float)1.0 / a[i];
   }

   cout << 1.0 / sum;

   return 0;
}

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

int main() {
    ll N,K;
    cin >> N >> K;
    ll edgeNum = (N-1)*(N-2)/2;
    if(edgeNum<K){
        cout << -1 <<endl;
        return 0;
    }
    cout << N-1 +edgeNum -K <<endl;
    for(int i=1;i<N;i++){
        cout << i <<" "<< N <<endl; 
    }
    if(edgeNum == K){
        return 0;
    }
    int t = 1;
    while(true){
        for(int i=1;i<N;i++){
            if(i+t >= N){
                cout << i <<" " <<i+t-(N-1) << endl;
            }else{
                cout << i <<" "<< i+t << endl;
            }
            edgeNum--;
             if(edgeNum == K){
                return 0;
            }
        }
        t++;
    }

    return 0;
}

Measured memory_bytes: 256
N = int(input())
n = map(int, input().split())
an = sorted(n, reverse=True)
i = 0
A = 0
B = 0
while i != N:
  A += an[i]
  i += 1
  if i != N:
    B += an[i]
    i += 1
print(A - B)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repb(i, n) for(ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define reprb(i, a, b) for(ll i = (b)-1; i >= (a); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
const ld EPS = 1e-12L;
const ld PI = 3.1415926535897932385L;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class S, class T>inline bool chmax(S &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class S, class T>inline bool chmin(S &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n;
    cin >> n;
    vld x(n), y(n);
    rep(i, n){
        cin >> x[i] >> y[i];
    }
    vll pm(n);
    rep(i, n){
        pm[i] = i;
    }
    ld ans = 0;
    ll cnt = 0;
    do{
        rep(i, n-1){
            ans += sqrt((x[pm[i+1]]-x[pm[i]])*(x[pm[i+1]]-x[pm[i]])+(y[pm[i+1]]-y[pm[i]])*(y[pm[i+1]]-y[pm[i]]));
        }
        cnt++;
    }while(next_permutation(ALL(pm)));
    cout << ans/cnt << endl;
    return 0;
}

Measured memory_bytes: 256
// In the name of Allah
// #Isart

#include<bits/stdc++.h>

#define pii pair<int, int>
#define pb push_back
#define F first
#define S second
#define ll long long
#define ld long double

using namespace std;

const int MAXN = 1e5 + 10, mod = 1e9 + 7;

int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	int n, m;
	cin >> n >> m;
	ll ans = 1;
	if(abs(n - m) > 1) return cout << 0, 0;
	if(n == m) ans *= 2;
	for(int i = 1; i <= n; i ++) ans *= i, ans %= mod;
	for(int i = 1; i <= m; i ++) ans *= i, ans %= mod;
	cout << ans << endl;
	return 0;	
}

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

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
void output(bool g[5][5][5]){
  REP(z, 5){
    REP(y, 5){
      REP(x, 5){ printf("%d", (g[z][y][x])? 1 : 0); }
      printf("\n");
    }
    if(z != 4) printf("\n");
  }
}

int main(){
  int N;
  int case_num = 1;
  while(cin >> N && N){
    bool g[5][5][5];
    REP(z, 5)REP(y, 5){
      string line;
      cin>>line;
      REP(x, 5){
        g[z][y][x] = (line[x] == '1') ? true : false;
      }
    }
    int M1; cin>>M1;
    set<int> birth;
    REP(i, M1){
      int t; cin>>t;
      birth.insert(t);
    }
    int M2; cin>>M2;
    set<int> alive;
    REP(i, M2){
      int t; cin>>t;
      alive.insert(t);
    }
    REP(iter, N){
      bool ng[5][5][5];
      REP(z, 5)REP(y, 5)REP(x, 5){
        int cnt = 0;
        FOR(dz, -1, 2) FOR(dy, -1, 2) FOR(dx, -1, 2){
          int nz = z + dz;
          int ny = y + dy;
          int nx = x + dx;
          if(!(0 <= nz && nz < 5)) continue;
          if(!(0 <= ny && ny < 5)) continue;
          if(!(0 <= nx && nx < 5)) continue;
          if(dx == 0 && dy == 0 && dz == 0) continue;
          if(g[nz][ny][nx]) cnt++;
        }
        if(g[z][y][x]){
          if(alive.count(cnt)) ng[z][y][x] = true;
          else ng[z][y][x] = false;
        }else{
          if(birth.count(cnt)) ng[z][y][x] = true;
          else ng[z][y][x] = false;
        }
      }
      REP(z, 5)REP(y, 5)REP(x, 5) g[z][y][x] = ng[z][y][x];
    }
    if(case_num > 1) cout << endl;
    printf("Case %d:\n", case_num++);
    output(g);
  }
  return 0;
}

Measured memory_bytes: 1228
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  long long x, a = 1, ans = 5, b = 0;
  cin >> x;
  b += (x / 11) * 2;
  x %= 11;
  while(x > 0) {
    if(ans == 5) {
      ans = 6;
      x -= 6;
   
    } else {
      ans -= 6;
      ans += 5;
      x -= 6;
    }
    b++;
  }
  cout << b << endl;

  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdlib>
using namespace std;
 
int main() {
  int a,b,k;
  cin >> k >> a >> b;
  for(int i = a; i<=b;i++){
    if(i%k==0){
      cout << "OK" << endl;
      return 0;
    }
  }
   cout << "NG" << endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;

int main(){
    ll n,a;
    cin>>n;
    ll ans=0;
    rep(i,n){
        cin>>a;
        if(i%2==0&&a%2) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

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

int main()
{
    char s[101];

    while(scanf("%s", s) != EOF)
    {
        int len = strlen(s);

        int frequency[26] = {0};

        for(int i=0; i<len; i++) frequency[s[i] - 'a']++;

        bool beautiful = true;

        for(int i=0; i<26; i++)
        {
            if(frequency[i] % 2!=0)
            {
                beautiful = false;
                break;
            }
        }

        if(beautiful) cout << "Yes\n";
        else cout << "No\n";
    }

    return 0;
}



Measured memory_bytes: 256
arr = [1]
num = gets.to_i
time = 0
40.times do |i|
	tmp = arr[-1] * 2
	if tmp == num
		time = i + 2	
      	break
	elsif tmp > num
		time = i + 1
      	break
	end
	arr << tmp
end

def factorial(n)
    return 1 if n == 1
    return factorial(n-1) * 2 + 1
end

p factorial(time)

Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

ll mypow(ll a, ll b) {
    ll ret = 1;
    while (b--) {
        ret *= a;
    }
    return ret;
}

ll keta(ll a) {
    ll ret = 0;
    while (a) {
        ret++;
        a /= 10;
    }
    return ret;
}

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a + b > c + d) {
        cout << "Left\n";
    } else if (a + b == c + d) {
        cout << "Balanced\n";
    } else {
        cout << "Right\n";
    }

    return 0;
}

Measured memory_bytes: 3520