akhauriyash/Code-Regression huggingface dataset:
import sys
import time
import math
from collections import deque
import heapq
import itertools
from decimal import Decimal
import bisect
from operator import itemgetter
MAX_INT = int(10e18)
MIN_INT = -MAX_INT
mod = 1000000000+7
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
if N%1000 == 0:
  print(0)
else:
  print(1000 - N%1000)

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

string calcAddition( string a, string b )
{
    int as = a.size(), bs = b.size(), d = as > bs ? as - bs : bs - as;
    string s = "0", t = "0";
    for( int i = 0; i < d; i++ )
        as > bs ? t += "0" : s += "0";
    s += a; t += b;

    for( int i = s.size() - 1; i >= 1; i-- )
    {
        s[i] += t[i] - '0';
        if( s[i] > '9' )
        {
            s[i] -= 10;
            s[i-1]++;
        }
    }

    bool j = true;
    for( int i = 0; i < s.size(); i++ )
        if( s[i] != '0' )
            j = false;
    if( j )
        return "0";
    return s[0] == '0' ? s.substr( 1, s.size() ) : s;
}

string calcSubtraction( string a, string b )
{
    int as = a.size(), bs = b.size(), d = as > bs ? as - bs : bs - as;
    string s = "", t = "";
    for( int i = 0; i < d; i++ )
        as > bs ? t += "0" : s += "0";
    s += a; t += b;

    if( s < t )
    {
        string temp = s;
        s = t;
        t = temp;
    }

    for( int i = s.size() - 1; i >= 0; i-- )
    {
        if( s[i] < t[i] )
        {
            s[i] += 10;
            if( s[i-1] >= '1' )
                s[i-1]--;
            else
            {
                int j = i - 1;
                while( s[j] == '0' )
                    s[j--] += 9;
                s[j]--;
            }
        }
        s[i] -= ( t[i] - '0' );
    }
    if( s.size() == 1 )
        return s;
    return s[0] == '0' ? calcAddition( s.substr( 1, s.size() ), "0" ) : s;
}

int main()
{
    string a, b;

    cin >> a >> b;

    int as = a.size(), bs = b.size();
    string s = a.substr( 1, as ), t = b.substr( 1, bs );
    int ss = s.size(), ts = t.size();

    if( a[0] == '-' && b[0] == '-' )
    {
        if( ss > ts || ss == ts && s > t )
            cout << "-";
        cout << calcSubtraction( s, t ) << endl;
    }
    else if( a[0] >= '0' && b[0] >= '0' )
    {
        if( as < bs || as == bs && a < b )
            cout << "-";
        cout << calcSubtraction( a, b ) << endl;
    }
    else if( a[0] == '-' )
        cout << "-" << calcAddition( s, b ) << endl;
    else
        cout << calcAddition( a, t ) << endl;

    return 0;
}




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

int main() {
	int n, m;
	cin >> n >> m;
	multiset<int> cnt;
	for(int i = 0; i < n; ++i) {
		int r1;
		cin >> r1;
		cnt.insert(r1);
	}
	long long ans = 0;
	while(m--) {
		auto it = cnt.end();
		--it;
		int r1 = *it;
		cnt.erase(it);
		cnt.insert(r1/2);
	}
	for(auto it: cnt) ans = ans + (long long) it;
	cout << ans;
	return 0;
}

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

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for(int& i: a) cin >> i;
  
  vector<int> dp(k + 1, 0);
  
  for(int i=1;i<=k;++i)
  {
    for(int j: a)
      if(i - j >= 0)
      {
        dp[i] = max(dp[i], dp[i - j] ^ 1);
      }
  }
  
  if(dp[k]) cout << "First\n";
  else cout << "Second\n";
  
  return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		
		if(x < 1200) {
			System.out.println("ABC");
		} else {
			System.out.println("ARC");
		}
		
	}
}


Measured memory_bytes: 21844
#include <cstdio>
#include <string>
#include <set>
using namespace std;
set<string> ans;
int n;
void dfs(string s, int high)
{
    char temp;
    if (s.length() == n)
    {
        ans.insert(s);
        return;
    }
    for (int i = 0; i <= high; i++)
    {
        temp = 'a' + i;
        dfs(s + temp, high);
    }
    temp = 'a' + high + 1;
    dfs(s + temp, high + 1);
}
int main()
{
    scanf("%d", &n);
    string s;
    dfs(s, -1);
    for (set<string>::iterator i = ans.begin(); i != ans.end(); i++)
    {
        printf("%s\n", i->c_str());
    }
    return 0;
}

Measured memory_bytes: 12416
#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(){
   ll a,b,n;
   cin >> a >> b >> n;
   ll x,y;
   if(n>=b){
      x = (n/b)*b -1;
   }else{
      x = n;
   }
   y = (a*x)/b - a * (x/b);
   cout << y << endl;
   return 0;  
}

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

int main(void){
    int N, Abuf;
    vector<int> A;
    vector<int> B(200000, 0);
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> Abuf;
        A.push_back(Abuf);
        B[Abuf-1]++;
    }
    long long resbuf = 0;
    for(int i=0; i<N; i++){
        resbuf += (long long)B[i]*(B[i]-1)/2;
    }
    for(int i=0; i<N; i++){
        if(B[A[i]-1] > 1){
            cout << resbuf - B[A[i]-1] + 1 << endl;
        }else{
            cout << resbuf << endl;
        }
    }
    return 0;
}

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

class Que {
 public:
  string name;
  int time;
};

int main() {
  int num;
  int quantum;
  cin >> num >> quantum;
  deque<Que*> dq;
  for (int i = 0; i < num; i++) {
    Que* que = new Que();
    cin >> que->name >> que->time;
    dq.push_back(que);
  }
  int progress;
  while (dq.size() > 0) {
    Que* que = dq.front();
    dq.pop_front();
    if (que->time <= quantum) {
      progress += que->time;
      cout << que->name << " " << progress << endl;
      delete que;
    } else {
      progress += quantum;
      que->time -= quantum;
      dq.push_back(que);
    }
  }
  return 0;
}


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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))

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

constexpr int MOD = int(1e9 + 7);
constexpr int INF = int(1e9 + 1);
constexpr ll LLINF = ll(4 * 1e18 + 1);
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    ll n;
    vector<ll> a(5);
    cin >> n;
    for(int i = 0; i < 5; ++i){
        cin >> a[i];
    }
    sort(begin(a), end(a));
    cout << CEIL(n, a[0]) + 4 << "\n";
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	void hmw(){
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int x = s.nextInt();
		while(n != 0||x != 0){
			int cnt = 0;
			for(int i = 1;i <= n - 2;i++){
				for(int j = i + 1;j <= n - 1 && (i+j)*3 < x*2 ;j++){
					int k = x - (i + j);
					if(k <= n && k > j){
//System.out.println("#"+i + ":" + j + ":" + k);
						cnt++;
					}
				}
			}
			System.out.println(cnt);
			n = s.nextInt();
			x = s.nextInt();
		}
	}
	public static void main(String args[]){
		Main m = new Main();
		m.hmw();
	}
}

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

int main() {
  int N;
  cin>>N;
  vector<int> X(N);
  for(int i=0;i<N;i++){
    cin>>X[i];
  }
  int L=X[0];
  int R=X[0];
  for(int i=0;i<N;i++){
    L=min(L,X[i]);
    R=max(R,X[i]);
  }
  int ans=1000000000;
  for(int i=L;i<=R;i++){
    int P=0;
    for(int j=0;j<N;j++){
      P+=(X[j]-i)*(X[j]-i);
    }
    ans=min(ans,P);
  }
  cout<<ans<<endl;
}
    
    

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
signed main(){
  
  ll n,m;
  cin>>n>>m;
  vector<bool> broken(n+10,false);
  rep(i,m){
    ll a;cin>>a;
    broken[a]=true;
  }

  vector<ll> dp(n+10,0);
  const ll MOD=(ll)1e9+7;
  dp[0]=1LL;
  dp[1]=(broken[1]?0LL:1LL);
  for(ll i=2;i<=n+1;++i){
    if(broken[i])continue;
    dp[i]=dp[i-1]%MOD+dp[i-2]%MOD;
    dp[i]%=MOD;
  }
  cout<<dp[n]<<endl;  

  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

//二部グラフかぁ

pair<int, int> E[400001];
int H[100001], D[100001];
bool root[100001], dame[100001], nE[100001];
void dfs(int p, int d, int rt) {
	if (D[p]) {
		if ((d + D[p]) & 1) dame[rt] = true;
		return;
	}
	D[p] = d;
	int tmp = 0;
	for (int i = H[p]; i; i = E[i].second) {
		tmp++;
		dfs(E[i].first, d + 1, rt);
	}
	if (tmp == 0) nE[p] = true;
}

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


	int N, M;
	cin >> N >> M;
	rep(i, M) {
		int a, b;
		cin >> a >> b;
		E[i + i + 1] = mp(a, H[b]);
		H[b] = i + i + 1;
		E[i + i + 2] = mp(b, H[a]);
		H[a] = i + i + 2;
	}

	rep1(i, N) {
		if (!D[i]) {
			root[i] = true;
			dfs(i, 1, i);
		}
	}

	ll x = 0, y = 0, z = 0;
	rep1(i, N) {
		if (root[i]) {
			if (nE[i]) z++;
			else if (dame[i]) y++;
			else x++;
		}
	}

	ll kotae = x * x + (x + y) * (x + y) + 2 * N * z - z * z;
	co(kotae);



	Would you please return 0;
}

Measured memory_bytes: 6272
def main():
    M=10**9+7
    N=10**5*2
    fac=[0]*(N+1)
    fac[0]=b=1
    for i in range(1,N+1):fac[i]=b=b*i%M
    inv=[0]*(N+1)
    inv[N]=b=pow(fac[N],M-2,M)
    for i in range(N,0,-1):inv[i-1]=b=b*i%M
    n,*t=open(0).read().split()
    n=int(n)
    e=[[]for _ in range(n)]
    for a,b in zip(*[map(int,t)]*2):
        e[a-1]+=b-1,
        e[b-1]+=a-1,
    o=[]
    s=[0]
    f=[1]*n
    while s:
        v=s.pop()
        f[v]=0
        o+=v,
        l=[]
        for w in e[v]:
            if f[w]:
                l+=w,
                s+=w,
        e[v]=l
    sz1,sz2=[0]*n,[0]*n
    dp1,dp2=[0]*n,[0]*n
    c=[[]for _ in range(n)]
    for v in o[::-1]:
        s=b=1
        c1,c2=[1],[1]
        for w in e[v]:
            u=sz1[w]
            b=b*dp1[w]*inv[u]%M
            c1+=b,
            s+=u
        b=1
        for w in e[v][::-1]:
            b=b*dp1[w]*inv[sz1[w]]%M
            c2+=b,
        c[v]=c1,c2[::-1]
        sz1[v]=s
        dp1[v]=b*fac[s-1]%M
    # print(dp1)
    sz2[0]=1
    dp2[0]=1
    for v in o:
        l=len(e[v])
        c1,c2=c[v]
        uv=sz2[v]-1
        tv=dp2[v]*inv[uv]
        for i,w in enumerate(e[v]):
            tw=c1[i]*c2[i+1]%M
            uw=uv+sz1[v]-sz1[w]-1
            dp2[w]=tv*tw*fac[uw]%M
            sz2[w]=uw+2
    # print(dp2)
    a=[]
    for dp1,dp2,sz1,sz2 in zip(dp1,dp2,sz1,sz2):
        sz1-=1
        sz2-=1
        a+=str(dp1*dp2*inv[sz1]*inv[sz2]*fac[sz1+sz2]%M),
    print('\n'.join(a))
main()

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

#define INF 1000000000
int main(){
    ll n, m;
    cin >> n >> m;
    ll value[m], box[m];
    rep(i, m)box[i]=0;
    rep(i, m){
        ll b;
        cin >> value[i] >> b;
        rep(j, b){
            ll c;
            cin >> c;
            box[i] |= 1<<(c-1);
        }
    }
    ll dp[m+1][1<<n];
    rep(i, m+1)rep(j, 1<<n)dp[i][j]=INF;
    dp[0][0]=0;
    rep(i, m)rep(j, 1<<n){
        dp[i+1][j] = min(dp[i+1][j],dp[i][j]);
        dp[i+1][j|box[i]]=min(dp[i+1][j|box[i]], dp[i+1][j]+value[i]);
    }
    ll ans = dp[m][(1<<n)-1];
    if(ans==INF)ans=-1;
    cout << ans << endl;
}

Measured memory_bytes: 32256
#include<bits/stdc++.h>
using namespace std;
long long int a[200005];
const int mod=1e9+7;
int main()
{
	int n,m,i;
  scanf("%d %d",&n,&m);
  for(i=1;i<=n;i++)
  {
  	scanf("%lld",&a[i]);
  }
  long long int ans=1;
  sort(a+1,a+1+n);
  if(m==n||a[n]<0)
  {
  	if(m%2==0)
  	{
  	  for(i=1;i<=m;i++)
  	  ans=(ans*a[i])%mod;
	}
	else
	{
		for(i=n-m+1;i<=n;i++)
		ans=(ans*a[i])%mod;
	}
  }
  else
  {
  	int l=1,r=n;
  	if(m%2==1)
  	{
  	  ans=(ans*a[n])%mod;
	  r--;	
	  m--;
	}
	while(m)
	{
		if(a[l]*a[l+1]>a[r]*a[r-1])
		{
			ans=(ans*a[l]%mod*a[l+1]%mod)%mod;
			l+=2;
			m-=2;
		}
		else
		{
			ans=(ans*a[r]%mod*a[r-1]%mod)%mod;
			r-=2;
			m-=2;
		}
	}
	
  }
  ans=(ans%mod+mod)%mod;
  printf("%lld",ans);
} 

Measured memory_bytes: 5392
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>

using namespace std;

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

    for(int i = 0; i < n.size(); i++){
        if(n[i] == '1') n[i] = '9';
        else            n[i] = '1';
    }

    cout << n << endl;

    return 0;
}

Measured memory_bytes: 768
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
x,a,b = LI()
if b<=a:
    print("delicious")
elif b-a <= x:
    print("safe")
else:
    print("dangerous")
#B

#C

#D
"""
def root(x):
    if x == par[x]:
        return x
    par[x] = root(par[x])
    return par[x]

def same(x,y):
    return root(x) == root(y)

def unite(x,y):
    x = root(x)
    y = root(y)
    if rank[x] < rank[y]:
        par[x] = y
    else:
        par[y] = x
        if rank[x] == rank[y]:
            rank[x] += 1
n = I()
v = LIR(n)
l = [None for i in range(2*n-2)]
for i in range(n):
    v[i].append(i)
par = [i for i in range(n)]
rank = [0 for i in range(n)]
v.sort(key = lambda x:x[0])
for i in range(n-1):
    l[i] = [v[i][2],v[i+1][2],v[i+1][0]-v[i][0]]
v.sort(key = lambda x:x[1])
for i in range(n-1):
    l[i+n-1] = [v[i][2],v[i+1][2],v[i+1][1]-v[i][1]]
l.sort(key = lambda x:x[2])
k = 0
ans = 0
for i in range(2*n-2):
    x,y,c = l[i]
    if not same(x,y):
        k += 1
        ans += c
        unite(x,y)
    if k == n-1:break
print(ans)
"""
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 38512
//============================================================================
// Name        : ITP_1_6_C.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
using namespace std;

int main() {
	int a[4][3][10]={0},n,b,f,r,v;
	cin >> n;
	for(int i=0; i<n; ++i) {
		cin >> b >> f >> r >> v;
		a[b-1][f-1][r-1]+=v;
	}
	for(int i=0;i<4;++i) {
		for(int j=0;j<3;++j) {
			printf(" %d %d %d %d %d %d %d %d %d %d\n"
					,a[i][j][0]
					,a[i][j][1]
					,a[i][j][2]
					,a[i][j][3]
					,a[i][j][4]
					,a[i][j][5]
					,a[i][j][6]
					,a[i][j][7]
					,a[i][j][8]
					,a[i][j][9]);

		}
		if(i==3) break;
		printf("####################\n");
	}
	return 0;
}

Measured memory_bytes: 3188
using System;
using System.Collections.Generic;
using System.Linq;

namespace abc168a
{
    class Program
    {
        static void Main(string[] args)
        {
            //==========================================================================================================================
            //1) input
            string n = Console.ReadLine();

            int num = int.Parse(n.Last().ToString());

            //==========================================================================================================================
            //2) output
            string output = "hon";

            if (num == 3)
            {
                output = "bon";
            }else if (num == 0|| num == 1 || num == 6 || num == 8)
            {
                output = "pon";
            }
            else
            {

            }



            Console.WriteLine(output);
        }
    }
}


Measured memory_bytes: 27892
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<functional>
#include<stack>
#include<utility>
#include<map>
#include<queue>

using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	cout << (a + b) % 24 << endl;
	return 0;
}

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

#define fr first
#define sc second
#define mk make_pair

using namespace std;

int dsu[1000001], n, m, ar[200001];

int get_dsu(int x)
{
    if(dsu[x] == x)
        return x;

    return dsu[x] = get_dsu(dsu[x]);
}

int main()
{
    cin >> n >> m;
    for(int i = 1; i <= 1e5; i++)
        dsu[i] = i;
    for(int i = 1; i <= n; i++)
    {
        int k;
        cin >> k;
        for(int j = 1; j <= k; j++)
        {
            int x;
            scanf("%d", &x);
            if(ar[x] != 0)
                dsu[get_dsu(ar[x])] = get_dsu(i);
            ar[x] = i;
        }
    }

    int kol = 0;
    for(int i = 1; i <= n; i++)
        if(dsu[i] == i)
            kol ++ ;

    if(kol == 1)
        cout << "YES";
    else
        cout << "NO";
    return 0;
}


Measured memory_bytes: 1024
x=int(input())
gohyaku=0
goen=0
while x>5:
    x-=500
    gohyaku+=1
if x==5:
    goen+=1
elif 0<=x<5:
    pass
elif x<0:
    x+=500
    gohyaku-=1
    while x>=5:
        goen+=1
        x-=5
print(gohyaku*1000+goen*5)

Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using VI = vector<int>;
using VVI = vector<vector<int>>;

int main(){
  ll w,h,x,y;
  cin >> w >> h >> x >> y;
  
  ll area = w*h/2;
  int dec=0;
  if(w*h % 2 == 1) dec = 5;
  
  int flag=0;
  if(2*x==w && 2*y==h) flag = 1;
  
  cout << area << "." << dec << " " << flag;
  
  return 0;
}

Measured memory_bytes: 256
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

int main() {
    int n;
    cin >> n;
    
    vector<pii> zero;
    vector<pair<int, pii>> nonzero;
    REP(i, n){
        int x, y, h;
        cin >> x >> y >> h;
        if(h == 0)
            zero.push_back(make_pair(x, y));
        else
            nonzero.push_back(make_pair(h, make_pair(x, y)));
    }

    IFOR(i, 0, 100){
        IFOR(j, 0, 100){
            int nowh = -1;
            bool ng = false;
            for(int k=0;k<nonzero.size();k++){
                auto pos = nonzero[k].second;
                int dist = abs(i - pos.first) + abs(j - pos.second);
                int target_h = dist + nonzero[k].first;

                if(nowh != -1 && target_h != nowh){
                    ng = true;
                    break;
                }
                else {
                    nowh = target_h;
                }
            }
            if(nonzero.size() == 0)
                nowh = 1;

            for(int k=0;k<zero.size();k++){
                int dist = abs(i - zero[k].first) + abs(j-zero[k].second);
                if(dist < nowh){
                    ng = true;
                    break;
                }
            }


            if(ng)
                continue;

            printf("%d %d %d\n", i, j, nowh);
        }
    }


    return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.HashSet;
import java.util.NoSuchElementException;

public class Main {
	private static FastScanner sc = new FastScanner();

	public static void main(String[] args) {
		int n = sc.nextInt();
		
		HashSet<String> list = new HashSet<>();
		for(int i=1; i<=n; i++) {
			String cmd = sc.next();
			String str = sc.next();
			
			if(cmd.equals("insert")) {
				list.add(str);
			} else {
				if(list.contains(str)) {
					System.out.println("yes");
				} else {
					System.out.println("no");
				}
			}
		}
	}

	static class FastScanner {
	    private final InputStream in = System.in;
	    private final byte[] buffer = new byte[1024];
	    private int ptr = 0;
	    private int buflen = 0;
	    private boolean hasNextByte() {
	        if (ptr < buflen) {
	            return true;
	        }else{
	            ptr = 0;
	            try {
	                buflen = in.read(buffer);
	            } catch (IOException e) {
	                e.printStackTrace();
	            }
	            if (buflen <= 0) {
	                return false;
	            }
	        }
	        return true;
	    }
	    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
	    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
	    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
	    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
	    public String next() {
	        if (!hasNext()) throw new NoSuchElementException();
	        StringBuilder sb = new StringBuilder();
	        int b = readByte();
	        while(isPrintableChar(b)) {
	            sb.appendCodePoint(b);
	            b = readByte();
	        }
	        return sb.toString();
	    }
	    public long nextLong() {
	        return Long.parseLong(next());
	    }
	    public int nextInt(){
	    	return Integer.parseInt(next());
	    }
	}
}

Measured memory_bytes: 163036
#include<bits/stdc++.h>
using namespace std;
#define forn for(int i=0;i<n;i++)
#define pr pair<int,int>
#define ll long long int
const int mod=1e9+7;
vector<bool> taken;
int score[(int)1e6];
bool cmp(int a,int b)
{
	return score[a]>score[b];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,r;
    cin>>n>>r;
    if(n<10)
    {
    	cout<<r+100*(10-n);
	}
	else
	cout<<r;
}
 


Measured memory_bytes: 256
import java.util.*;

class Main {
  public static final int MOD = 1000000007;
  public static final int INF = 1000000000;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    Integer X[] = new Integer[N];
    for(int i=0; i<N; i++){
      X[i] = sc.nextInt();
    }
    Integer Y[] = new Integer[N];
    System.arraycopy(X,0,Y,0,X.length);
    Arrays.sort(Y);
    int a = Y[N/2 - 1];
    int b = Y[N/2];
    for(int i=0; i<N; i++){
      if(X[i] <= a) System.out.println(b);
      else System.out.println(a);
    }
  }

  public static int gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b, a%b);
  }
}

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

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

  int k, a, b;
  cin >> k >> a >> b;

  if(a % k != 0 && b % k != 0)
  {
    if ((b/k) - (a/k) == 0)
    {
      cout << "NG" << endl;
      return 0;
    }
  }
  cout << "OK" << endl;
  return 0;
}

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

int a[200100][25];
int len[200100];
int b[25];

int main()
{
    int n;
    int i,j;
    ll res=0;

    scanf("%d",&n);
    for(i=1;i<=n;i++){
        scanf("%d",&j);
        while(j!=0){
            len[i]++;
            a[i][len[i]]=j%2;
            j=j/2;
        }
    }

    int l=1,r=1,fl=0;
    for(i=1;i<=21;i++)b[i]=a[1][i];
    while(l<=n){
        fl=0;
        r++;
        if(l==r&&l==n){
            res++;
            break;
        }
        if(r==n+1){
            ll k=r-l;
            res=res+k*(k+1)/2;
            break;
        }
        for(i=1;i<=len[r];i++){
            if(a[r][i]==1){
                if(b[i]==1){
                    ll k=r-l;
                    res=res+k;
                    for(i=1;i<=21;i++)b[i]=b[i]-a[l][i];
                    l++;
                    r--;
                    fl=1;
                    break;
                }
            }
        }
        if(fl==0){
            for(i=1;i<=21;i++)b[i]+=a[r][i];
        }
        //printf("%d %d %lld\n",l,r,res);
    }
    printf("%lld\n",res);




    return 0;
}


Measured memory_bytes: 20608
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, count1, count2, count3, count4;
  cin >> n;
  
  vector<string> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
  }
  
  count1 = 0;
  count2 = 0;
  count3 = 0;
  count4 = 0;
  for (int i = 0; i < n; i++) {
    if (vec.at(i) == "AC") count1++;
    else if (vec.at(i) == "WA") count2++;
    else if (vec.at(i) == "TLE") count3++;
    else if (vec.at(i) == "RE") count4++;
  }
  
  cout << "AC x " << count1 << endl;
  cout << "WA x " << count2 << endl;
  cout << "TLE x " << count3 << endl;
  cout << "RE x " << count4 << endl;
}


Measured memory_bytes: 6348
def solve(n, P):
    count = 0
    combo = False
    for i in range(n):
        if i == P[i] - 1:
            count += 1
            if not combo and i + 1 < n and i + 1 == P[i + 1] - 1:
                count -= 1
                combo = True
            else:
                combo = False
    return count

_n = int(input())
_P = list(map(int, input().split()))
print(solve(_n, _P))


Measured memory_bytes: 14008
# coding: utf-8

#import time
#import sys
#import numpy as np
def sign(x):
    if x>0: return 1
    elif x==0: return 0
    else: return -1

def f0035(p1,p2,p3):
    x1, y1 = p1
    x2, y2 = p2
    x3, y3 = p3
    return sign((y3-y1)*(x2-x1)-(y2-y1)*(x3-x1))

while True:
    try:
        dt =map(float, raw_input().split(","))
    except:
        break

    p1=dt[0:2]
    p2=dt[2:4]
    p3=dt[4:6]
    p4=dt[6:8]
    if f0035(p1,p3,p2) != f0035(p1,p3,p4) and f0035(p2,p4,p1) != f0035(p2,p4,p3): print "YES"
    else: print "NO"

Measured memory_bytes: 4256
import sys
input = sys.stdin.readline

S = [int(v) for v in input().strip()]
N = int(input())

for i in range(len(S)):
    v = S[i]
    
    if v == 1:
        if i + 1 == N:
            print(v)
            exit()
    else:
        print(v)
        exit()

Measured memory_bytes: 3060
x,n=map(int,input().split())
p=list(map(int,input().split()))
ans=0
num=0
while ans==0:
    if (x+num) not in p:
        ans=x+num
    if (x-num) not in p:
        ans=x-num
        if ans==0:
            break
    num+=1
print(ans)

Measured memory_bytes: 9064
#include<stdio.h>

int main(){
   int x[5];
   for(int i=0;i<5;i++){
      scanf("%d",&x[i]);
   }
   for(int i=0;i<5;i++){
      if(x[i]==0){
         printf("%d\n",i+1);
      }
   }
   return 0;
}
      


Measured memory_bytes: 1684
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n,a,b;scanf("%lld%lld%lld",&n,&a,&b);
    ll res=0;
    if((a&1)==(b&1))res=(b-a)/2;
    else {
        ll k1=n-b+1,k2=n-a+1;
        res=min(a+(b-a-1)/2,k1+(k2-k1-1)/2);
    }
    printf("%lld\n",res);
}

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

using namespace std;
using ll = long long;

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

  string s;
  cin >> s;
  int n = s.size();

  auto f = [](string s) {
    int n = s.size();
    for (int i = 0; i < n; i++) {
      if (s[i] != s[n - 1 - i])
        return false;
    }
    return true;
  };

  if (!f(s)) {
    cout << "No" << endl;
    return 0;
  }
  if (!f(s.substr(0, n / 2))) {
    cout << "No" << endl;
    return 0;
  }
  if (!f(s.substr(n / 2 + 1, n / 2))) {
    cout << "No" << endl;
    return 0;
  }

  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 3644
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int ans = Math.max(a + b, Math.max(a - b, a * b));
		System.out.println(ans);

	}

}


Measured memory_bytes: 23764
#include <stdio.h>
int main(){

    char s[15] ,t[15];
    scanf("%s%s", s, t);
    int a=0;
    for(int i=0;i<10;++i)
    {
        if(s[i]==t[i]){continue;}
        else if(s[i]==0){break;}
        else if(s[i]!=t[i]){a+=1;}
    }
    if(a>0){printf("No");}
    else printf("Yes");
    
    return 0;
}

Measured memory_bytes: 1704
#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ins insert
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define up_b upper_bound
#define low_b lower_bound
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,a,b) for(int i=b;i>=a;i--)
#define boost ios_base::sync_with_stdio(NULL),cin.tie(NULL),cout.tie(NULL)
#define nl '\n'

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<pii> vii;

const int N=1501;
const int MXN=1501;

int main(){
  int r;
  cin>>r;
  cout<<r*r;
}


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

int main() {
	int n,q,i,j,query,c,l,r,ans;
	string s;
	char ch1,ch2;
	vector<set<int>> a(26);
	cin >> n >> s >> query;
	for(i=1; i<=n; i++){
		c=s[i-1]-'a';
		a[c].insert(i);
	}
	
	for(c=0; c<26; c++){
		a[c].insert(500001);
	}
	
	for(q=0; q<query; q++){
		cin >> l;
		if(l==1){
			cin >> r >> ch2;
			c=s[r-1]-'a';
			a[c].erase(r);
			s[r-1]=ch2;
			c=ch2-'a';
			a[c].insert(r);
		}else{
			cin >> l >> r;
			ans=0;
			for(c=0; c<26; c++){
				auto itr=a[c].begin();
				itr=a[c].lower_bound(l);
				if(*itr<=r){
					ans++;
				}
			}
			cout << ans << endl;
		}
		
	}
	return 0;
}

Measured memory_bytes: 24196
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <functional>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vec;
typedef pair<int, int> P;
#define rep(n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define out(a) cout << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define INF 100000000

int arr[999999] = { 0 };

void Eratosthenes(int N) {
	for (int i = 0; i <= N; i++) {
		arr[i] = 1;
	}
	for (int i = 2; i <= sqrt(N); i++) {
		if (arr[i]) {
			for (int j = 0; i * (j + 2) <= N; j++) {
				arr[i *(j + 2)] = 0;
			}
		}
	}
	int res = 0;
	for (int i = (N/2)+1; i <= N; i++) {
		if (arr[i]) {
			res++;
		}
	}
	cout << res << endl;
}

int main() {
	while (true) {
		int n;
		cin >> n;
		if (n == 0) return 0;
		Eratosthenes(2 * n);
	}
	return 0;
}



Measured memory_bytes: 4000
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

using namespace std;

int my_abs(int num) {
    if (num > 0)
        return num;
    else
        return -num;
}

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

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

int main() {
    char C;
    cin >> C;
    int N = 1;
    C = C + N;
    cout << C << endl;
}


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


using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)

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

    ll n;
    cin>>n;

    ll ans = 0;
    if(n >= 10) ans+=9;
    else ans += n;
    if(n >= 1000) ans += 900;
    else if(n >= 100){
      ans += n%100 + 1;
      ans += (n/100-1) * 100;
    }
    if(n >= 100000) ans += 90000;
    else if(n >= 10000){
      ans += n%10000 + 1;
      ans += (n/10000 -1) * 10000;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;

// エラストテネスの篩, o(n)程度
// n以下の素数の数を返す, prime[i]: i番目の素数, is_prime[i]: iが素数であるか
int sieve(int n, int prime[] = nullptr, bool is_prime[] = nullptr){
	bool flag0 = false, flag1 = false;
	if(prime == nullptr){
		flag0 = true; prime = new int[n];
	}
	if(is_prime == nullptr){
		flag1 = true; is_prime = new bool[n + 1];
	}

	int p = 0;
	fill(is_prime, is_prime + n + 1, true);
	is_prime[0] = is_prime[1] = false;

	for(int i = 2; i <= n; i++){
		if(is_prime[i]){
			prime[p++] = i;
			for(int j = 2*i; j <= n; j+=i) is_prime[j] = false;
		}
	}

	if(flag0) delete prime;
	if(flag1) delete is_prime;

	return p;
}

const int MAX_N = (int)1e6;
int prime[MAX_N];
bool is_prime[MAX_N + 1];

int main(void){
	int num = sieve(MAX_N, prime, is_prime);

	int n;
	while(scanf("%d", &n) != EOF){
		cout << upper_bound(prime, prime + num, n) - prime << '\n';
	}

	return 0;
}



Measured memory_bytes: 4496
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define shandom_ruffle random_shuffle

using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
const int nax=1000*1007;

int n;
ll pocz[nax];
ll kon[nax];

ll wyn;

int main()
{
	scanf("%d", &n);
	for (int i=0; i<n; i++)
		scanf("%lld", &pocz[i]);
	for (int i=0; i<n; i++)
		scanf("%lld", &kon[i]);
	queue <int> kol;
	for (int i=0; i<n; i++)
		kol.push(i);
	while(!kol.empty())
	{
		int v=kol.front();
		kol.pop();
		int l=(v-1+n)%n;
		int r=(v+1)%n;
		ll s=kon[l]+kon[r];
		
		ll ile=max((kon[v]-pocz[v])/s, 0LL);
		wyn+=ile;
		kon[v]-=ile*s;
		if (ile)
		{
			kol.push(v);
			kol.push(l);
			kol.push(r);
		}
	}
	
	
	
	for (int i=0; i<n; i++)
		if (pocz[i]!=kon[i])
			wyn=-1;
	printf("%lld\n", wyn);
	return 0;
}


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

//Function Macros:
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

//Type Definitions:
typedef long long ll;
typedef unsigned long long ull;

//Constants:
const int INF = 2e9;
const int MOD = 1e9 + 7;

//Global Variables:

//Prototype Declarations:
int gcd(int, int);

//================ Main Loop ================
int main() {
    int n;
    string s;
    cin >> n >> s;
    rep(i, s.size()) {
        s[i] += n;
        if(s[i] > 'Z') s[i] -= 26;
    }
    cout << s << endl;
    return 0;
}
//===========================================

//Functions:
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

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

int main() {
  string S;
  cin >> S;
  
  int size = S.size();
  string o = "Yes";

  for(int i = 0; i <= S.size() / 2; i++){
    if(S.at(i) != S.at(size - i - 1)){
      o = "No";
    }
  }

  for(int i = 0; i <= S.size() / 4; i++){
    if(S.at(i) != S.at((size - 1) / 2 - i - 1)){
      o = "No";
    }
  }
  
  
  cout << o << endl;
  
}


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

using namespace std;

int main()
{
    string S;
    int day;

    cin >> S;

    if(S == "SUN") cout << "7" << endl;
    else if(S == "MON") cout << "6" << endl;
    else if(S == "TUE") cout << "5" << endl;
    else if(S == "WED") cout << "4" << endl;
    else if(S == "THU") cout << "3" << endl;
    else if(S == "FRI") cout << "2" << endl;
    else if(S == "SAT") cout << "1" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define Mod 998244353
#define pi 3.14159265358979323846
#define endl '\n'
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<char> vc;

int main()
{
    int n;cin>>n;
    string s;
    map<string,int> MP;
    for(int i=0;i<n;i++)
    {
        cin>>s;
        MP[s]++;
    }
    cout<<"AC x "<<MP["AC"]<<endl;
    cout<<"WA x "<<MP["WA"]<<endl;
    cout<<"TLE x "<<MP["TLE"]<<endl;
    cout<<"RE x "<<MP["RE"]<<endl;
    return 0;
}


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

#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

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

int main(int argc, char const *argv[])
{	
	int n,s[100];
	int max = 0,min = 0x7F,pat,sum = 0;
	scanf("%d",&n);
	for (int i = 0; i < n; ++i){
		scanf(" %d",&s[i]);
		sum += s[i];
	}
	if(sum % 10 != 0){
		printf("%d\n",sum);
		return 0;
	}
	else{
		qsort(s,n,sizeof(int),ASC);
		for (int i = 0; i < n; ++i)
		{
			if(s[i] % 10 != 0){
				sum -= s[i];
				break;
			}
		}
		sum = (sum % 10 == 0) ? 0 : sum;
		printf("%d\n", sum);
	}
}

Measured memory_bytes: 128
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define rando mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define fi first
#define se second
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define debugii(x) cerr << " - " << #x << ": " << x.fi<<","<<x.se << endl;
#define sep() cerr << "--------------------" << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ld long double
#define ll long long
#define int ll
#define ii pair<int,int>
#define v vector<int>
#define vii vector<ii>
#define vv vector<vector<int> >
#define mp make_pair
#define INF 1000000000
#define pb push_back
#define EPS 1e-9
const int MOD = 1000000007; // 998244353
int fac[100005];
int invGeneral(int a, int b) {
    a %= b; if (a == 0) return b == 1 ? 0 : -1;
    int x = invGeneral(b,a); 
    return x == -1 ? -1 : ((1-(ll)b*x)/a+b)%b;
}
int b_c(int n, int k) {
    return (((fac[n] * invGeneral(fac[k],MOD))%MOD) * (invGeneral(fac[n - k],MOD) % MOD))%MOD;
}
int32_t main(){
    boost;
    int n,k;
    cin>>n>>k;
    fac[0] = 1;
    for (int i = 1; i <= n; i++) 
        fac[i]=(fac[i-1]*i)%MOD;
    v vec(n);
    for(auto& it:vec)cin>>it;
    sort(all(vec));
    int ans=0;
    for (int i = k-1; i < n; ++i)
        ans=(ans+(vec[i]*b_c(i,k-1))%MOD)%MOD;
    reverse(all(vec));
    for (int i = k-1; i < n; ++i)
        ans=(ans+MOD-(vec[i]*b_c(i,k-1))%MOD)%MOD;
    cout<<ans;
    return 0;
}
//long long
//array bounds
//special cases
//binary search

Measured memory_bytes: 1792
#include<iostream>

using namespace std;

int main() {
	int N;
	unsigned long long int K;
	cin >> N >> K;
	int a[2000];
	
	for (int i = 0; i < N; i++)
		cin >> a[i];

	int t_1 = 0;
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			if (a[i] > a[j])
				t_1++;
		}
	}

	int t_2 = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (a[i] > a[j])
				t_2++;
		}
	}

	unsigned long long int ans = 0;
	ans = (K * K - K) / 2;
	//cout << ans<<'\n';
	
	ans %= 1000000007;
	ans *= t_2;
	//cout << ans << '\n';

	ans += t_1 * K;
	//cout << ans << '\n';

	ans %= 1000000007;

	cout << ans;

	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
def solve():
    N, M = map(int, input().split())
    if M%2:
        return '-1'
    E = [set() for _ in range(N+1)]
    for _ in range(M):
        a,b = map(int, input().split())
        E[a].add(b)
        E[b].add(a)
    q = [(0,1,1)]
    v = set()
    T = []
    while q:
        n_, n, d = q.pop()
        if n not in v:
            T.append((d,n_,n))
            E[n].discard(n_)
            E[n_].discard(n)
            v.add(n)
            if E[n]-v:
                q.extend([(n,u, d+1) for u in E[n]-v])

    A = [0 for _ in range(N+1)]
    res = []
    c = set()
    for d,a,b in sorted(T, reverse=1)[:-1]:
        F = E[b]-c
        if A[b]%2 == 0 or len(E[b])%2:
            res.extend([(u,b) for u in F])
            for u in F:
                A[u] += 1
                E[u] -= {b}
        else:
            res.extend([(b,u) for u in F])
            for u in F:
                A[b] += 1
                E[u] -= {b}

        E[a] -= {b}
        if A[b]%2:
            A[b] += 1
            res.extend([(b,a)]) 
        else:
            A[a] += 1
            res.extend([(a,b)])

    return '\n'.join(['{} {}'.format(*e) for e in res])


if __name__ == '__main__':
    print(solve())

Measured memory_bytes: 61344
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,sum;
  sum=0;
  double dash=0.1; 
  cin >> N;
  for (int i=0; i<N; i++){
    dash *=10;
    int phy;
    phy = N/dash;
    sum += phy%10;
  }
  
  if (N%sum == 0){
  cout << "Yes" <<endl;
  }
  else{
  cout << " No " << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<queue>
#include<map>
#include<vector>
#include <cstdlib>
#include<algorithm>
#include <cstdio>
#include <cctype>
using namespace std;
const long long INF=10000000000000LL;
typedef long long ll;
typedef pair<ll,ll> P;
ll N,Ma,Mb,K=0,C[45];
ll A,B;
ll T,a,b,c,d;
ll ans=0;
bool h,o;
//bool D[100005];
string str,str2[55][55];
map<string,int> m;
vector<int> v[10];
ll X[100005];
int main(){
	cin>>N>>A>>B;
	cin>>X[0];
	for(int i=1;i<N;++i){
		cin>>X[i];
		ans+=min(B,(X[i]-X[i-1])*A);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <float.h>
#include <stdlib.h>
#include <functional>
#include <limits>
#include <numeric>
#include <type_traits>
#include <queue>
#include <fstream>
#include <bitset>
#include <cmath>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i <= (int)(n); i++)
#define sort1(v) sort(v.begin(),v.end())
#define reverse(v) reverse(v.begin(),v.end())
#define all(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> p;
bool paircom (pair<int,int> p,pair<int,int> q){
return p.second<q.second;
}

void count(vector<int> v,vector<int>& ans){
    sort1(v);
    int n=v.size();
  int k=1;
  int i=1;
  bool bl=true;
    while(true){
    while(bl){
        if(v[i-1]==v[i]){
        k++;    
      }else{
          bl=false;
      }
      i++;
      }
      ans.push_back(k);
      if(i>=(n-1))break;
      k=1;
      bl=true;
    }
    }




int main() {
    int n,k;
    cin >> n>>k;
    vector<ll> a(n);
for(int i=0;i<n;i++){
    cin >> a[i];
}
for(int i=k;i<=n-1;i++){
    if(a[i-k]<a[i]){cout <<"Yes"<<endl;}else{cout <<"No"<<endl;}

}

}

    

Measured memory_bytes: 4840
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        char[] input = scanner.next().toCharArray();
        scanner.close();

        for (int i = 0; i < input.length; i++) {
            if (input[i] == '?') {
                if (i != 0 && input[i - 1] == 'P') {
                    input[i] = 'D';
                } else if (i + 1 != input.length && input[i + 1] == 'D') {
                    input[i] = 'P';
                } else if (i + 1 != input.length && input[i + 1] == '?' ) {
                    input[i] = 'P';
                    input[i + 1] = 'D';
                } else {
                    input[i] = 'D';
                }
            }
        }

        System.out.println(String.valueOf(input));
    }
}


Measured memory_bytes: 41264
#include <stdio.h>
int main()
{
    int x, i;
    i = 1;
    x = 0;
    
    while (i > 0) {
        scanf ("%d", &x);
        if (x == 0 || x < 1 || x > 10000) {
            break;
        }
        printf ("Case %d: %d\n", i, x);
        i++;
    }
    
    return 0;
}

Measured memory_bytes: 600
def calculate_money():
    input_list = input().split()
    N = int(input_list[0])
    Y = int(input_list[1])

    for x_num in range(0, N + 1):
        for y_num in range(0, N + 1 - x_num):
            z_num = N - x_num - y_num
            if 10000 * x_num + 5000 * y_num + 1000 * z_num == Y:
                print(x_num, " ", y_num, " ", z_num)
                return
    print("-1 -1 -1")


if __name__ == '__main__':
    calculate_money()


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

using namespace std;

constexpr int INF = (1 << 29);

int main()
{
    int N;
    while (cin >> N, N) {
        vector<int> a(N);
        for (int i = 0; i < N; i++) {
            cin >> a[i];
        }
        int res = INF;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                res = min(res, abs(a[i] - a[j]));
            }
        }
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 3036