akhauriyash/Code-Regression huggingface dataset:
using DataStructures
const double = Float64
const int = Int64

parseint(x) = parse(int, x)
readint() = map(parseint, split(readline()))

function main()
  S = readline()

  sum = 0
  for s in S
    #println(s)
    sum += Int64(s-'0')
  end

  #println(sum)
  if sum%9==0
    println("Yes")
  else
    println("No")
  end

end

main()

Measured memory_bytes: 179184
#include <iostream>
int combi2(int n) { return n * (n - 1) / 2; }

int main(int argc, char *argv[]) {
  int N, M;
  std::cin >> N >> M;

  int sum{};
  if (N >= 2)
    sum += combi2(N);
  if (M >= 2)
    sum += combi2(M);

  std::cout << sum << std::endl;
}


Measured memory_bytes: 256
bfr = [[[0] * 10 for _ in range(3)] for _ in range(4)]
sep = '#' * 20

n = int(input())

for b, f, r, v in [map(int, input().split()) for _ in range(n)]:
    bfr[b - 1][f - 1][r -1] += v

for i, b in enumerate(bfr):
    for f in b:
        for r in f:
            print(f' {r}', end='')
        print()
    if i != 3:
        print(sep)
    
# print()


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

int main(){
int N,ans,c,p;
  cin>>N>>p;
  ans=0;
  vector<long long>b(N);
  for(int i=0;i<N;i++){
  cin>>b[i];
  }
  c=p;
  sort(b.begin(),b.end());
  for(int i=0;i<N;i++){
    if(c>=b[i]){
      c-=b[i];
      ans++;
      if(i==N-1&&c>0){
        ans--;
      }
    }
    else{
      break;
    }
  }
  cout<<ans<<endl;
}


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

using namespace std;

int main(void){
  int n,m,max,i,x;
  vector<int>time;

  while(cin >> n >> m){
    time.push_back(0);
    if(n==0 && m==0)break;
    for(i=0;i<n+m;i++){
      cin >> x;
      time.push_back(x);
    }
    sort(time.begin(),time.end());
    max=-1;
    for(i=0;i<n+m;i++){
      max= (max<time[i+1]-time[i])?time[i+1]-time[i]:max;
}
    cout << max << endl;
    time.clear();
  }

  return 0;
}

Measured memory_bytes: 0
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
import sys

N = int(input())
A = [int(x) for x in input().split()]

if len(A) != N:
  print("[ERROR] Number of Input integers is invalid")
  sys.exit()

swap_count = 0

for i in range(N):
  for j in range(N - 1, i, -1):
    if A[j] < A[j - 1]:
      A[j], A[j - 1] = A[j - 1], A[j]
      swap_count += 1

print(' '.join(map(str, A)))
print(swap_count)



Measured memory_bytes: 5612
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

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

const int INF = 1 << 29;
const ll LL_INF = 1LL << 60;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int N;
vector<int> A;
int main() {
  cin >> N;
  A.resize(N);
  for (auto &val : A) {
    cin >> val;
  }
  vector<int> B(A);
  sort(B.begin(), B.end());
  int m1 = N / 2;
  int m2 = m1 - 1;
  int v1 = B[m1];
  int v2 = B[m2];
  for (int i = 0; i < N; i++) {
    if (A[i] <= v2) {
      cout << v1 << endl;
      continue;
    } else {
      cout << v2 << endl;
      continue;
    }
  }

  return 0;
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
vector<int> e[3333];
int n,a[3333];
bool chk(int x,int fat){
	for(vector<int>::iterator it = e[x].begin(); it != e[x].end(); it++){
		int y = *it;
		if(y == fat)continue;
		if(!chk(y,x) && a[y] < a[x])return true;
	}
	return false;
}
int main(){
	scanf("%d",&n);
	for(int i=1; i<=n; i++)
		scanf("%d",&a[i]);
	for(int i=1; i<n; i++){
		int x,y;
		scanf("%d%d",&x,&y);
		e[x].push_back(y);
		e[y].push_back(x);
	}
	bool fir = false;
	for(int i=1; i<=n; i++){
		if(chk(i,i)){
			if(fir)printf(" ");
			fir = true;
			printf("%d",i);
		}
	}
	puts("");
	return 0;
}


Measured memory_bytes: 640
res1000=-1
res5000=-1
res10000=-1
n,y=map(int,input().split())
for x in range(n+1):
    for j in range(n+1-x):
        z=n-x-j
        if z>=0 and  y==10000*x+5000*j+1000*z:
            res10000=x
            res5000=j
            res1000=z
print(res10000,res5000,res1000)
       

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
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; }
int main()
{
    int A,B,C;
    cin >> A>>B>>C;

    int sum=0;
    for (int a = 0; a <= A*B ; a+=A){
        sum+=a;
        if(a%B==C){
            cout << "YES" << endl;
            return 0;
        }
    }
    
    cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))

int main(void){
    int n,x,y;
    scanf("%d %d %d",&n,&x,&y);
    int ky[n][n];
    x--;
    y--;
    for(int i = 0;i < n;i++)for(int j = 0;j < n;j++){
        int max = MAX(i,j);
        int min = MIN(i,j);
        if(max >= y && min <= x){//ショートカットを含む
            ky[i][j] = (max - min) - (y - x) + 1;
            continue;
        }
        if((max <= x || min >= y)){
            ky[i][j] = max - min;
            continue;
        }

        if(min >= x && max <= y){
            ky[i][j] = MIN(max-min,(min-x)+1+(y-max));
            continue;
        }

        if(min < x){//maxはショートカットの中
            ky[i][j] = MIN(max - min,(x-min)+1+(y-max));
            continue;
        }
        //minはショートカットの中
        ky[i][j] = MIN(max - min,(min-x) + 1 + (max-y));
    }
    int kc[n];
    for(int i = 0;i < n;i++)kc[i] = 0;
    for(int i = 0;i < n;i++)for(int j = 0;j < n;j++)kc[ky[i][j]]++;
    for(int i = 1;i < n;i++)printf("%d\n",kc[i]/2);
    return 0;
}

Measured memory_bytes: 15744
#include<bits/stdc++.h>
#include <iostream>
#include <numeric>
#include <math.h>
#define ll long long 
#define ull long
#define mpa make_pair
#define pb push_back
#define ff first
#define pii pair<ll,ll>
#define dd long long
#define trace(x) cerr << #x << " : " << x << endl
#define ss second
#define boost ios_base::sync_with_stdio(0)
#define forp(i,a,b) for(ll i=a;i<=b;i++)
#define rep(i,n)    for(ll i=0;i<n;++i)
#define ren(i,n)    for(ll i=n-1;i>=0;i--)
#define forn(i,a,b) for(ll i=a;i>=b;i--)
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end();
#define sc(x) scanf("%lld",&x)
#define clr(x,val) memset(x,val,sizeof(x))
#define pr(x) printf("%lld\n",x) 
#define gc getchar
#define pdd pair<dd,dd>
#define prec(x) cout<<fixed<<setprecision(x)
#define fre freopen("input.txt","r",stdin),freopen("output.txt","w",stdout)
using namespace std;


int main(){
   //boost;
   ll n;
   cin>>n;
   ll ms=0;
   ll ans=0;
   for(ll i=1;i<=n;i++){
   	ll j;
   	cin>>j;
   	if(ms>j)ans+=(ms-j);	
   	ms=max(ms,j);
   }
   cout<<ans<<endl;
}

    


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

int main() {
  long long N,A;
  cin >> N >> A;
  vector<long long> x(N);
  for (int i=0; i<N; i++) {
    cin >> x[i];
  }
  sort(x.begin(),x.end());
  vector<vector<vector<long long>>> dp(N+1,vector<vector<long long>> (N+1,vector<long long> (2501,0)));
  for (int i=0; i<N+1; i++) {
    dp[i][0][0] = 1;
  }
  for (int i=1; i<N+1; i++) {
    for (int j=1; j<i+1; j++) {
      for (int k=0; k<x[i-1]; k++) {
        dp[i][j][k] = dp[i-1][j][k];
      }
      for (int k=x[i-1]; k<2501; k++) {
        dp[i][j][k] = dp[i-1][j][k] + dp[i-1][j-1][k-x[i-1]];
      }
    }
  }
  
  long long ans = 0;
  
  for (int i=1; i<N+1; i++) {
    ans += dp[N][i][i*A];
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 52224
N,K = map(int,input().split())

D = set(map(int,input().split()))
A = {1,2,3,4,5,6,7,8,9,0}
N_list = [int(c) for c in str(N)]

use = sorted(list(A - D))

ans = [max(use) for i in range(len(N_list))]
mapans = map(str,ans)
x = int(''.join(mapans))
if N == x:
    print(x)
elif N > x:
    if use[0]!= 0:
        ans = [use[0] for i in range(len(N_list)+1)]
    else:
        ans = [use[0] for i in range(len(N_list)+1)]
        ans[0] = use[1]

    mapans = map(str,ans)
    x = int(''.join(mapans))
    print(x)
else:
    if use[0]!= 0:
        ans = [use[0] for i in range(len(N_list))]
    else:
        ans = [use[0] for i in range(len(N_list))]
        ans[0] = use[1]

    mapans = map(str,ans)
    x = int(''.join(mapans))
    j = 0
    i = 0
    while x < N:
        if ans[j] > N_list[j]:
            for k in range(len(ans)-j-1):
                ans[k] = min(use)
        elif ans[j] == N_list[j]:
            i = 0
            j+=1
        else:
            i += 1
            ans[j] = use[i]
        mapans = map(str,ans)
        x = int(''.join(mapans))

    print(x)


Measured memory_bytes: 3188
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int INF=1e9;

int main(){
    int n,k; cin >> n >> k;
    char s[n];
    for(int i=0;i<n;i++) cin >> s[i];
    s[k-1]=s[k-1]+'a'-'A';
    for(int i=0;i<n;i++){
        cout << s[i];
    }
    cout << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			String[] line = sc.nextLine().split(" ");
			int H = Integer.parseInt(line[0]);
			int W = Integer.parseInt(line[1]);
			int[][] grid = new int[H][W];
			int[][] L = new int[H][W];
			int[][] R = new int[H][W];
			int[][] D = new int[H][W];
			int[][] U = new int[H][W];
			for (int i = 0; i < H; i++) {
				line = sc.nextLine().split("");
				for (int j = 0; j < W; j++) {
					if ("#".equals(line[j])) {
						grid[i][j] = -1;
						continue;
					}
					L[i][j] = j == 0 ? 1 : L[i][j - 1] + 1;
					U[i][j] = i == 0 ? 1 : U[i - 1][j] + 1;
				}
			}
			for (int i = H - 1; i >= 0; i--) {
				for (int j = W - 1; j >= 0; j--) {
					if (grid[i][j] < 0) continue;
					R[i][j] = j == W - 1 ? 1 : R[i][j + 1] + 1;
					D[i][j] = i == H - 1 ? 1 : D[i + 1][j] + 1;
				}
			}
			int max = 0;
			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++) {
					max = Math.max(max, L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3);
				}
			}
			System.out.println(max);
		}
	}
}

Measured memory_bytes: 217172
#include<stdio.h>

int main(){
    int h,w;
    int H,W;
    
    while(1){
        scanf("%d %d",&h,&w);
        if(h==0&&w==0) break;
        for(H=0;H<h;H++){
            for(W=0;W<w;W++){
            printf("#");
            }
            printf("\n");
            
        }
        printf("\n");
            
    }
    return 0;
}


Measured memory_bytes: 2064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ll ans=1e9;
	ll a,b;
	cin>>a>>b;
	b=min(b,a+4038);
	for(ll i=a;i<=b;i++){
		for(ll j=i+1;j<=b;j++){
			ans=min(ans,i*j%2019);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
h,w,k = map(int,input().split())

ans = 0

c = []

ab = 0

for i in range(h):
    c.append(list(input()))

for i in c:
    ab += i.count("#")

for s in range(2**h):
    for t in range(2**w):
        blk = ab
        ipaint = []
        jpaint = []
        for i in range(h):
            if (s >> i) & 1:
                ipaint.append(i)
        
        for j in range(w):
            if (t >> j) & 1:
                jpaint.append(j)

        for ip in ipaint:
            blk -= c[ip].count("#")

        for jp in jpaint:
            for ih in range(h):
                if c[ih][jp] == "#":
                    blk -= 1

        for iip in ipaint:
            for jjp in jpaint:
                if c[iip][jjp] == "#":
                    blk += 1

        if blk == k:
            ans += 1

print(ans)

        

Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793
ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g=gcd(a,b);
    return a/g*b;
}

ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t%mod;
    }
    return n*rep_jijo(n,x-1)%mod;
}
ll com(ll n,ll r){
    ll x=1,y=1;
    ll tmp=n;
    while(tmp>=n-r+1){
        x=x*tmp%mod;
        tmp--;
    }
    while(r>0){
        y=y*r%mod;
        r--;
    }
    return x*rep_jijo(y,mod-2)%mod;
}

int main (){
    ll n;
    ll ans=0;
    cin >> n;
    vector<ll>div_n;
    vector<ll>div_nm;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0) {
            div_n.push_back(i);
            if(i*i!=n) div_n.push_back(n/i);
        }
    }
    for(ll i=1;i*i<=n-1;i++){
        if((n-1)%i==0) {
            div_nm.push_back(i);
            if(i*i!=n-1) div_nm.push_back((n-1)/i);
        }
    }
    for(ll x:div_n){
        if(x==1) continue;
        ll tmp=n;
        while(tmp%x==0) tmp/=x;
        if(tmp%x==1) ans++;
    }
    ans+=div_nm.size()-1;
    cout << ans <<endl;
    return 0;
}



Measured memory_bytes: 384
from collections import deque
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
is_root = [False] + [True] * N
par_count = [0] * (N+1)
G = [[] for _ in range(N+1)]
for _ in range(N-1+M):
    A, B = map(int, input().split())
    G[A].append(B)
    par_count[B] += 1
    is_root[B] = False
root = is_root.index(True)
queue = deque()
queue.append(root)
parent = [0] * (N+1)
while queue:
    u = queue.popleft()
    for v in G[u]:
        if par_count[v] > 1:
            par_count[v] -= 1
        else:
            parent[v] = u
            queue.append(v)
for i in range(1, N+1):
    print(parent[i])


Measured memory_bytes: 59996
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  while (true) {
    int b; cin >> b;
    if (!b) break;
    auto chk = [&](int n) -> bool {
      if (n & 1) {
        if (b % n) return false;
        int m = b / n;
        int s = m - n / 2;
        if (s < 1) return false;
        cout << s << ' ' << n << '\n';
        return true;
      } else {
        if (b % (n / 2)) return false;
        int m = b / (n / 2);
        if (~m & 1) return false;
        int s = m / 2 - (n / 2 - 1);
        if (s < 1) return false;
        cout << s << ' ' << n << '\n';
        return true;
      }
    };
    for (int n = 2 * sqrt(b) + 10; ; --n) {
      if (chk(n)) break;
    }
  }
}


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

int main()
{
    vector<int> v(10);
    for (int i = 0; i < 10; i++)
    {
        cin >> v[i];
    }
    sort(v.rbegin(), v.rend());
    for (int i = 0; i < 3; i++)
    {
        cout << v[i] << endl;
    }
}


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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
const ll mod = 1e9+7;
int inf = 1000000000; //10e9

int main(){

    int n;
    cin >> n;
    vector<string> s(n);
    rep(i,n) cin >> s[i];

    int ac=0, wa=0, tle=0, re=0;
    rep(i,n){
        if(s[i]=="AC") ac++;
        if(s[i]=="WA") wa++;
        if(s[i]=="TLE") tle++;
        if(s[i]=="RE") re++;
    }

    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;

    return 0;

}

Measured memory_bytes: 6424
#include<bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define rep(i,n) for(int i = 0;  i < n ; ++i)
#define REP(i,a,b) for(int i = a ; i <= b ; ++i)
#define filei freopen("input.txt", "r", stdin);
#define fileo freopen("output.txt", "w", stdout);
#define gooi cout<<"Case #"<<i+1<<" :";
#define s(n) scanf("%d",&n)
#define rev(i,n) for(int i = n ; i >= 0 ; --i)
#define REV(i,a,b) for(int i = a ; i >= b ; --i)
#define miN(a,b) (((a)<(b))?(a):(b))
#define sc(n) scanf("%c",&n)
#define tr(c,i) for(typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define INF 1000000000
#define pii pair<long long int,long long int>
#define pb(a) push_back(a)
#define F first
#define S second
typedef long long ll;
using namespace std;
void pre(){}
void solve(){
    ll n;cin>>n;
    map<long long int,long long int>m;
    for(int i=1;i<=100;i++){
        for(int j=1;j<=100;j++){
            for(int k=1;k<=100;k++){
                m[i*i+j*j+k*k+i*j+k*i+k*j]++;
            }
        }
    }
    for(int i=1;i<=n;i++){
        cout<<m[i]<<"\n";
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    pre();
    long long int num = 1;
    //cin>>num;
    for(long long int i=0;i<num;i++){
       	solve();
    }   
}





Measured memory_bytes: 5956
n = int(input())
for _ in range(n):
    x1, y1, x2, y2, x3, y3 = map(float, input().split())
    px = ((y1-y3) * (y1**2-y2**2+x1**2-x2**2) -
          (y1-y2) * (y1**2-y3**2+x1**2-x3**2)) / (2*(y1-y3)*(x1-x2)-2*(y1-y2)*(x1-x3))
    py = ((x1-x3) * (x1**2-x2**2+y1**2-y2**2) -
          (x1-x2) * (x1**2-x3**2+y1**2-y3**2)) / (2*(x1-x3)*(y1-y2)-2*(x1-x2)*(y1-y3))
    r = ((x1 - px)**2 + (y1 - py)**2)**0.5
    print('{0:.3f} {1:.3f} {2:.3f}'.format(px, py, r))

Measured memory_bytes: 5664
import math

N, D = map(int, input().split())

# 2次元リストの用意
X =  [[0 for i in range(D)] for j in range(N)]

# 2次元リストに格納
for i in range(N):
    tmp = [int(j) for j in input().split()]
    for k in range(len(tmp)):
        X[i][k] = tmp[k]

# print(X)
ans = 0
for i in range(N):

    for j in range(i+1, N):

        total = 0
        for k in range(D):
            total += (X[i][k] - X[j][k]) ** 2
        
        sq = math.sqrt(total)
        if sq  == int(sq): ans += 1


print('{}'.format(ans))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll cnt[214514];
int main(){
	string s;
	ll k;
	cin>>s>>k;
	ll ans=0,cnt=1,l=0,r=0;
	bool f=0,g=1;
	for(int i=1;i<s.size();i++){
		if(s[i-1]==s[i])cnt++;
		else{
			g=0;
			if(!f){
				l=cnt;
				f=1;
			}
			ans+=cnt/2;
			cnt=1;
		}
	}
	r=cnt;
	ans+=cnt/2;
	ans*=k;
	if(g)ans=s.size()*k/2;
	else if(s[0]==s[s.size()-1])ans+=((l+r)/2-l/2-r/2)*(k-1);
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <list>
#include <map>
#include <deque>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
#define for1(i,n) for (ll i=0;i<(n);i++)
#define for2(i,m,n) for (ll i=(m);i<(n);i++)
#define for3(i,m,n,d) for (ll i=(m);i<(n);i+=(d))
#define DEBUG 0

ll N;
pair<ll,ll> A[51];

ll calc(ll dx, ll dy)
{
    bool used[50] = {0};
    ll used_count = 0;
    ll ret = 0;
    ll tx,ty;
    while (used_count < N) {
        for1(i,N) {
            if (used[i]) continue;
            used[i] = true;
            used_count += 1;
            ret += 1;
            tx = A[i].first + dx;
            ty = A[i].second + dy;
            for2(j,i+1,N) {
                if (used[j]) continue;
                if (tx == A[j].first && ty == A[j].second) {
                    used[j] = true;
                    used_count += 1;
                    tx = A[j].first + dx;
                    ty = A[j].second + dy;
                }
            }
        }
    }
    return ret;
}
void solve()
{
    cin >> N;
    for1(i,N) {
        ll x, y;
        cin >> x >> y;
        A[i] = make_pair(x, y);
    }
    sort(&A[0], &A[N]);
    ll p = 0;
    ll q = 0;
    if (N <= 2) {
        cout << 1 << endl;
        return;
    }
    ll ans = N - 1;
    bool flag = false;
    for1 (i1,N-2) {
        for2 (i2,i1+1,N-1) {
            ll dx = A[i2].first - A[i1].first;
            ll dy = A[i2].second - A[i1].second;
            for2 (i3,i2+1,N) {
                if ((A[i3].first - A[i2].first == dx)
                &&  (A[i3].second - A[i2].second == dy)) {
                    flag = true;
                    ans = min(ans, calc(dx,dy));
                }
            }
        }
    }
    if (!flag) {
        for1 (i1,N-1) {
            for2 (i2,i1+1,N) {
                ll dx = A[i2].first - A[i1].first;
                ll dy = A[i2].second - A[i1].second;
                ans = min(ans, calc(dx,dy));
            }
        }
    }
    cout << ans << endl;
}

int main()
{
    do {
        solve();
    } while (DEBUG);
}


Measured memory_bytes: 256
N=int(input())
h=input().split()
H=[int(a) for a in h]
numbers=[0]*N
numbers[1]=abs(H[0]-H[1])
if N==2:
    print(numbers[1])
elif N==3:
    print(min(abs(H[0]-H[1]),abs(H[2]-H[0])))
else:
    for a in range(2,N):
        numbers[a]=min(numbers[a-1]+abs(H[a]-H[a-1]),numbers[a-2]+abs(H[a]-H[a-2]))
    print(numbers[-1])
    

Measured memory_bytes: 52208
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using f80 = __float80;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef v(i64) vi;
typedef v(vi) vvi;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(i64 i = 0; i < (i64) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

void Main()
{
  i64 X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;

  vi P(A), Q(B), R(C);
  cin >> P >> Q >> R;

  sort(rrng(P));
  rep(i,X) R.emplace_back(P[i]);
  sort(rrng(Q));
  rep(i,Y) R.emplace_back(Q[i]);

  sort(rrng(R));
  cout << accumulate(R.begin(),R.begin()+X+Y,0LL) << endl;
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}

Measured memory_bytes: 6512
x = input().split()
 
a = int(x[0])
b = int(x[1])
k = int(x[2])
 
if(a-k > 0):
  print(a-k,b)
  exit()
elif(a-k == 0):
  print(0,b)
  exit()
elif(a-k < 0 and b-(k-a) > 0):
  print(0,b-(k-a))
  exit()
elif(a-k < 0 and b-(k-a) == 0):
  print(0,0)
  exit()
elif(a-k < 0 and b-(k-a) < 0):
  print(0,0)
  exit()

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

using namespace std;

int main(int argc, char *argv[]) {
    int64_t N;
    cin >> N;

    map<int64_t, int64_t> m;
    int64_t cur;
    for (int i = 0; i < N; i++) {
        cin >> cur;
        m[cur] += 1;
    }

    int64_t first = -1;
    int64_t second = -1;

    for (auto ite = m.rbegin(); ite != m.rend(); ite++) {
        if (ite->second > 1 && first == -1) {
            first = ite->first;
            if (ite->second >= 4) {
                second = ite->first;
            }
            continue;
        }
        if (first != -1 && second == -1 && ite->second > 1) {
            second = ite->first;
        }
        if (first != -1 && second != -1) {
            int64_t ans = first * second;
            cout << ans << endl;
            return 0;
        }
    }

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


Measured memory_bytes: 6528
from math import ceil
a,b=[int(x) for x in str(input()).split()]
ab=[[0,0]]

ma=0  #max weild
ms=[]  #number of max weild
for j in range(1,a+1):
  A=[int(x) for x in str(input()).split()]
  ma=max(ma,A[0])
  ab.append(A)


throws=[]
for i in range(1,a+1):
  if ab[i][1]>=ma:
    throws.append(ab[i][1])
throws.sort(reverse=True)


count=0
for i in throws:
  if b>0:
    b-=i
    count+=1
if b>0:
  count+=(ceil(b/ma))
print(count)





Measured memory_bytes: 22332
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <complex>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <stack> 
#include <bitset>
#include <queue>
#include <assert.h>
#include <unordered_map>
using namespace std;

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


Measured memory_bytes: 3144
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

signed main(){
	int L,R;
	cin>>L>>R;
	if(R/2019>L/2019||L%2019==0||R%2019==0){
		cout<<0<<endl;
		return 0;
	}
	int ans=INF;
	for(int i=L;i<=R;i++){
		for(int j=i+1;j<=R;j++){
			int t=1;
			t*=i%2019;
			t*=j%2019;
			t%=2019;
			ans=min(ans,t);
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int n, s, a, l[10];
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", l + i);
		s += l[i];
	}
	for (int i = 0; i < n; i++) {
		if (l[i] * 2 >= s)a = 1;
	}
	if (a)printf("No\n");
	else printf("Yes\n");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,int> pdi;
typedef pair<double,double> pdd;
typedef pair<double,ll> pdl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<pdd> vdd;
typedef vector<pdi> vdi;
typedef vector<pdl> vdl;
typedef vector<string> vs;
#define fi first
#define se second
const ll INFLL=LLONG_MAX;
const int INF=INT_MAX;
const ll MAXLL=0x3f3f3f3f3f3f3f3f;
const int MAX=0x3f3f3f3f;
const ll MOD=1000000007;
const ll mod=998244353;
#define eb emplace_back
#define emp emplace
#define mp(a,b) make_pair(a,b)
template<class T> using min_heap=priority_queue<T,vector<T>,greater<T> >;
template<class T>
void sort(vector<T>& v){
	sort(v.begin(),v.end());
}
template <class T, class U>
void sort(vector<T>& v,U func){
	sort(v.begin(),v.end(),func);
}
template<class T>
void rsort(vector<T>& v){
	sort(v.rbegin(),v.rend());
}
template <class T>
int lb_index(vector<T>& v,T k){
	return lower_bound(v.begin(),v.end(),k)-v.begin();
}
template <class T>
int ub_index(vector<T>& v,T k){
	return upper_bound(v.begin(),v.end(),k)-v.begin();
}
template<class T>
bool is_sorted(vector<T>& v){
	return is_sorted(v.begin(),v.end());
}
template<class T>
bool sorted(vector<T>& v){
	return is_sorted(v);
}
void precompute(){

	return;
}
void solve(){
	deque<char>d;
	string s;
	cin>>s;
	bool flipped=0;
	for(int i=0;i<s.size();i++){
		d.push_back(s[i]);
	}
	int q;
	cin>>q;
	while(q--){
		int t;
		cin>>t;
		if(t==1)flipped=!flipped;
		else{
			char c;
			cin>>t>>c;
			if(t==1){
				if(flipped){
					d.push_back(c);
				}
				else d.push_front(c);
			}
			else{
				if(!flipped){
					d.push_back(c);
				}
				else d.push_front(c);
			}
		}
	}
	if(flipped){
		while(!d.empty()){
			cout<<d.back();
			d.pop_back();
		}
	}
	else{
		while(!d.empty()){
			cout<<d.front();
			d.pop_front();
		}
	}
	return;
}

int main(){
	ios::sync_with_stdio(0);
	int numberofsubtestcases=1;
//	cin>>numberofsubtestcases;
	precompute();
	for(int looping=1;looping<=numberofsubtestcases;looping++){
//		cout<<"Case #"<<looping<<": ";
		solve();
	}
	return 0;
}




Measured memory_bytes: 3980
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> vec(n);
  for(int i=0;i<n;i++){
    cin>>vec.at(i);}
  sort(vec.begin(),vec.end());
  cout<<vec.at(n-1)-vec.at(0)<<endl;}
  

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

const int MOD = 1000000007;

int main()
{
    int n;
    cin >> n;
    vector<vector<bool> > v(n, vector<bool>(n));
    for(int i=0; i<n; ++i){
        for(int j=0; j<n; ++j){
            int a;
            cin >> a;
            v[i][j] = (a != 0);
        }
    }

    vector<int> dp(1<<n, 0);
    dp[0] = 1;
    for(int i=0; i<(1<<n)-1; ++i){
        bitset<32> bs(i);
        int a = bs.count();
        for(int b=0; b<n; ++b){
            if(v[a][b] && !bs[b]){
                bs[b] = true;
                dp[bs.to_ulong()] += dp[i];
                dp[bs.to_ulong()] %= MOD;
                bs[b] = false;
            }
        }
    }
    cout << dp.back() << endl;

    return 0;
}


Measured memory_bytes: 8448
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <map>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

int a, b;
int main() {
	cin >> a >> b;
	if (a == 0 || b == 0 || (a < 0 && b > 0)) cout << "Zero" << endl;
	else if (a > 0 || (abs(b) - abs(a)) % 2 != 0) cout << "Positive" << endl;
	else cout << "Negative";
	
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    bool t=true;
    for(int i=0;i<3;i++){
        if(n % 10==7){
            cout << "Yes" << endl;
            t=false;
            break;
        }
        else{
            n=n/10;
        }    
    }
    if(t){
        cout << "No" << endl;
    }
}





Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long int x;cin>>x;
  long long int y=x/11;
  long long int z=x%11;
  if(z==0) cout<<2*y<<endl;
  else if(z<=6) cout<<2*y+1<<endl;
  else cout<<2*y+2<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (ll i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define pii pair<int, int>
#define vc vector
#define a first
#define b second
#define pb pusu_back
#define INF (1000000000)
#define MOD (1000000007)
#define MAX (100000)

/////////////////////////////////////////////////////////

class XY{
public:
  ll x, y;
  XY() {x = y = 0;}
  XY(ll u, ll v) {x = u; y = v;}
};

template<typename T1, typename T2>
void chmin(T1 &a, T2 b) {if(a > b) a = b;}
template<typename T1, typename T2>
void chmax(T1 &a, T2 b) {if(a < b) a = b;}

template<typename T1, typename T2>
ll mypow(T1 a, T2 n){
  if(n == 0) return 1;
  if(n == 1) return a;
  if(n % 2) return a * mypow(a, n - 1);
  ll tmp = mypow(a, n / 2);
  return tmp * tmp;
}

template<typename T>
int BS(vector<T> &V, int left, int right, T key){
  int mid = (left + right) / 2;
  if(V[mid] <= key) left = mid;
  else right = mid;
  if(right - mid == 1) return left;
  else return BS(V, left, right, key);
}

ll comb(ll n, ll r){
	ll res = 1;
  rep(i, 0, r){
    res *= n - i;
    res /= i + 1;
  }
  return res;
}

template<typename T>
T euclid(T a, T b){
  if(b == 0) return a;
  else return euclid(b, a % b);
}

vector<ll> fact(MAX, 0), fact_inv(MAX, 0);

/////////////////////////////////////////////////////////

//MOD of Combination

ll pow_mod(ll a, ll b){
	ll res = 1;
	while(b > 0){
		if(b & 1) res = res * a % MOD;
		a = a * a % MOD;
		b >>= 1;
	}
	return res;
}

void prepare_comb_mod(ll n){
	fact[0] = 1LL;
	for(ll i = 0; i < n; i++) fact[i+1] = fact[i] * (i + 1) % MOD;
	fact_inv[n] = pow_mod(fact[n], MOD - 2);
	for(ll i = n - 1; i >= 0; i--) fact_inv[i] = fact_inv[i + 1] * (i + 1) % MOD;
}

ll comb_mod(ll n, ll r){
	return (fact[n] * fact_inv[r]) % MOD * fact_inv[n - r] % MOD;
}

/////////////////////////////////////////////////////////

//Union-Find Tree

int UFT_par[MAX];
int UFT_rank[MAX];

void UFT_init(int n){
  rep(i, 0, n){
    UFT_par[i] = i;
    UFT_rank[i] = 0;
  }
}

int UFT_find(int x){
  if(UFT_par[x] == x){
    return x;
  }else{
    return UFT_par[x] = UFT_find(UFT_par[x]);
  }
}

void UFT_unite(int x, int y){
  x = UFT_find(x);
  y = UFT_find(y);
  if(x == y) return;
  if(UFT_rank[x] < UFT_rank[y]){
    UFT_par[x] = y;
  }else{
    UFT_par[y] = x;
    if(UFT_rank[x] == UFT_rank[y]) UFT_rank[x]++;
  }
}

bool UFT_same(int x, int y){
  return UFT_find(x) == UFT_find(y);
}

/////////////////////////////////////////////////////////

bool comp(pii p, pii q){
  if(p.b == q.b) return p.a < q.a;
  return p.b < q.b;
}

void Main() {
  int N, M; cin >> N >> M;
  vc<pii> B(M);
  rep(i, 0, M) cin >> B[i].a >> B[i].b;
  sort(all(B), comp);
  int res = 0;
  int cur = 0;
  rep(i, 0, M){
    if(cur <= B[i].a){
      res++;
      cur = B[i].b;
    }
  }
  cout << res << endl;
}

/////////////////////////////////////////////////////////

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << std::fixed << std::setprecision(15);

  Main();
}


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

int main(){
	string top;
	while( cin >> top , top != "-" ){
		string left, right, bottom, result;
		cin >> left >> result;
		
		char center=0;
		while( !top.empty() || !left.empty() ){
			if( center == 0 ){
				if( !left.empty() ){
					center = left[ 0 ];
					left.erase( 0 , 1 );
				}else if( !top.empty() ){
					center = top[0];
					top.erase( 0 , 1 );
				}
			}else{
				if( result.find( center , 0 ) != string::npos && !top.empty() ){
					bottom.push_back( center );
					center = top[ 0 ];
					top.erase( 0 , 1 );
				}else if( !left.empty() ){
					right.push_back( center );
					center = left[ 0 ];
					left.erase( 0 , 1 );
				}
			}
		}
		if( result.find( center , 0 ) != string::npos ){
			bottom.push_back( center );
		}else{
			right.push_back( center );
		}
		cout << right << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
using namespace std;
 
int main(){
    int N,M;
    cin>>N>>M;

    int a[M],b[M];
    for(int i=0;i<M;++i)cin>>a[i]>>b[i];
    int road[N+1];
    for(int i=0;i<=N;++i)road[i]=0;
    for(int i=0;i<M;++i){
        road[a[i]]++;
        road[b[i]]++;
    }
    for(int i=1;i<=N;i++)cout<<road[i]<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define reup(a, b) for(int i = a; i <= b; ++i)

int main(void) {
    int n, m;
    while(cin >> n >> m) {
        cout << (1900 * m + 100 * (n - m)) * (1 << m) << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define repp(i, m, n) for(int i = m; i < n; i++)
#define reps(i, n) for(int i = 1; i <= n; i++)
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int, int> pai;
typedef pair<ll,ll> pal;



int main()
{
	int n, k, a[100010];
	cin >> n >> k;
	rep(i, n) cin >> a[i];
	ll sei[100010], hu[100010], sum[100010];
	sei[0]=0;
	hu[0]=0;
	sum[0]=0;
	reps(i, n)
	{
		if(a[i-1]>=0)
		{
			sei[i]=sei[i-1]+a[i-1];
			hu[i]=hu[i-1];
		}
		else
		{
			sei[i]=sei[i-1];
			hu[i]=hu[i-1]+a[i-1];
		}
		sum[i]=sum[i-1]+a[i-1];
	}
	int nuru=0, nuran=0;
	rep(i, n-k+1)
	{
		if((hu[nuru+k]-hu[nuru])<(hu[i+k]-hu[i])) nuru=i;
		if((sei[nuran+k]-sei[nuran])>(sei[i+k]-sei[i])) nuran=i;
	}
	ll ans=sei[n];
	cout << max(ans+hu[nuru+k]-hu[nuru], ans-(sei[nuran+k]-sei[nuran])) << endl;
	return 0;
}

Measured memory_bytes: 2176
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		HashSet<String> set = new HashSet<>();
		for (int i = 0; i < n; i++) {
		    set.add(sc.next());
		}
		System.out.println(set.size());
	}
}



Measured memory_bytes: 76896
from collections import deque

n,q = map(int,input().split())
l = [input().split() for _ in range(n)]

d = deque()
for i in l:
    d.append((i[0],int(i[1])))
t = 0

while d:
    x = d.popleft()
    if x[1]<=q:
        print(x[0], t+x[1])
        t = t+x[1]
    else:
        t += q
        d.append((x[0],x[1]-q))


Measured memory_bytes: 20876
#include <bits/stdc++.h>
#define rep(i,l,r) for (int i=l,i##end=r;i<=i##end;++i)
#define per(i,r,l) for (int i=r,i##end=l;i>=i##end;--i)
#define ll long long
using namespace std;
int a[1003];
bool Q(int l1,int r1,int l2,int r2,int x){
    cout<<"? ";
    rep(i,l1,r1) cout<<i<<" ";
    if (l2) rep(i,l2,r2) cout<<i<<" ";
    if (x) cout<<x<<" "; cout<<endl;
    string s; cin>>s;
    cout.flush();
    return s[0]=='R';
}
int main(){
    int n,t=sqrt(n); cin>>n;
    int x=Q(1,n,0,0,0),l=2,r=n+1;
    while (l<=r){
        int m=l+r>>1;
        if (Q(m,m+n-1,0,0,0)==x) l=m+1;
        else r=m-1;
    }
    rep(i,1,2*n)
        if (i<l||i>=l+n-1) a[i]=Q(l,l+n-2,i,i,0);
        else a[i]=Q(1,l-2,l+n,2*n,i);
    cout<<"! ";
    rep(i,1,2*n) cout<<(a[i]?'R':'B');
    return 0;
}


Measured memory_bytes: 724
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    FastScanner in;
    PrintWriter out;

    void solve() {
        int n = in.nextInt();
        int[] a = new int[n];
        int xorAll = 0;
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
            xorAll ^= a[i];
        }
        for (int i = 0; i < n; i++) {
            out.print((a[i] ^ xorAll) + " ");
        }
    }

    final int mod = 998244353;

    int mul(int x, int y) {
        return (int) ((x * 1L * y) % mod);
    }

    int add(int x, int y) {
        x += y;
        return x >= mod ? (x - mod) : x;
    }

    void run() {
        try {
            in = new FastScanner(new File("Main.in"));
            out = new PrintWriter(new File("Main.out"));

            solve();

            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    void runIO() {

        in = new FastScanner(System.in);
        out = new PrintWriter(System.out);

        solve();
        out.close();
    }

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }

    public static void main(String[] args) {
        new Main().runIO();
    }
}

Measured memory_bytes: 59984
#include<stdio.h>
int main()
{
	int A,B,C,D,n,m;
	scanf("%d %d %d %d",&A,&B,&C,&D);
	n=A*B;
	m=C*D;
	if(n>=m)
	printf("%d",n);
	else 
	printf("%d",m);
	return 0;
 } 

Measured memory_bytes: 128
N = int(input())
X, Y = zip(*[[int(a) for a in input().split()] for _ in range(N)])

L = [(x, y, x + y, y - x) for x, y in zip(X, Y)]

L.sort(key = lambda a : a[2])  # x+yでソート
ans = abs(L[0][0] - L[-1][0]) + abs(L[0][1] - L[-1][1])

L.sort(key = lambda a : a[3])  # y-xでソート
ans = max(ans, abs(L[0][0] - L[-1][0]) + abs(L[0][1] - L[-1][1]))
print(ans)

Measured memory_bytes: 163936
n, c = map(int, input().split())
r = []
for i in range(n):#h:高さ
    r.append([int(m) for m in input().split()])

r.sort(key=lambda x:(x[0], x[1],x[2]))

xli = []
p = 0
for i in range(n):
    if i == 0:
        xli.append(r[i])
    else:
        for jnum, j in enumerate(xli, 0):
            if (j[1] < r[i][0]) or (j[1] <= r[i][0] and j[2] == r[i][2]):
                p = 1
                xli[jnum] = r[i]
                break
        if p == 0:
            xli.append(r[i])
        p = 0

print(len(xli))

Measured memory_bytes: 29980
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
int main()
{
	int n;
	cin>>n;
	if(n%1000==0)	cout<<0;
	else
	cout<<1000-(n%1000);
}


Measured memory_bytes: 3560
// PKU 3325
#include<algorithm>
#include<cstdio>
#define rep( i, a ) for( int i = 0; i != (a); ++i )

int main()
{
	int n;
	while( scanf( "%d", &n ), n )
	{
		int ma = 0, mi = 1 << 30, sum = 0;
		rep( i, n )
		{
			int a;
			scanf( "%d", &a );

			sum += a;
			ma = std::max( ma, a );
			mi = std::min( mi, a );
		}

		printf( "%d\n", (sum - ma - mi) / (n - 2) );
	}

	return 0;
}

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

using namespace std;
using ll = long long;

#define int ll
#define all(x) x.begin(), x.end()
#define mp make_pair
#define mt make_tuple
#define x first
#define y second
#define pb push_back
#define sz(x) int(x.size())

const int N = 1e6 + 100;

int n;
int m;
int v;
int k;
int a[N];
int p[N];

int sum(int l, int r) {
	assert(l <= r);
	return p[r + 1] - p[l];
}

signed main() {
#ifdef LC
	assert(freopen("input.txt", "r", stdin));
#endif
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m >> v >> k;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	sort(a, a + n);
	for (int i = 0; i < n; ++i) {
		p[i + 1] = p[i] + a[i];
	}
	int answer = 0;
	for (int i = 0; i < n; ++i) {
		if (a[i] + m < a[n - k]) {
			continue;
		}
		int x = 0;
		if (i >= n - k) {
			x = m * (n - k);
		} else {
			x = m * (n - k) - sum(i + 1, n - k) + (n - k - (i + 1) + 1) * a[i];
		}
		if (m * (v - k) <= x) {
			//cerr << i + 1 << endl;
			++answer;
			//cerr << m * (v - k) << " " << x << endl;
		}
		//return 0;
	}
	cout << answer << "\n";
	return 0;
}


Measured memory_bytes: 5120
#include <iostream>
#include <math.h>

const int D = 1e5 + 7;

int a[D], dp[D];

int main()
{
    int n;
    std::cin >> n;
    for (int i = 1; i <= n; i++)
        std::cin >> a[i];

    dp[2] = abs(a[2] - a[1]);
    for (int i = 3; i <= n; i++)
        dp[i] = std::min(dp[i - 1] + abs(a[i - 1] - a[i]), dp[i - 2] + abs(a[i - 2] - a[i]));
    std::cout << dp[n] << std::endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] ans = new int[n];
        for (int i = 1; i < n; i++) {
            ans[scanner.nextInt()-1]++;
        }
        for (int i = 0; i < n; i++) {
            System.out.println(ans[i]);;
        }
    }
}


Measured memory_bytes: 62044
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int n,a;
  	cin >> n >> a;
  	if (a >= n % 500  && a >= 0){
    	cout << "Yes" << endl;
    }
  	else if (a == 0 && n % 500 == 0){
    	cout << "Yes" << endl;
    }
    else {
    	cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>

typedef long long ll;
using namespace std;

int main(){
    ll i,j;
    ll n,k;
    cin>>n>>k;
    ll a[n];
    for(i=1;i<=n;i++){
        cin>>a[i];
    }
    ll dp[n+1][k+1];
    for(i=0;i<=n;i++){
        for(j=0;j<=k;j++){
            dp[i][j]=0;
        }
        dp[i][0]=1;
    }
    

    for(i=1;i<=n;i++){
        for(j=1;j<=k;j++){
            if(j-a[i]-1>=0) {
                dp[i][j]=dp[i][j-1]+dp[i-1][j]-dp[i-1][j-a[i]-1]+1000000007;
            } else{
                dp[i][j]=dp[i][j-1]+dp[i-1][j];
            }
            dp[i][j]%=1000000007;
        }
    }
    cout<<dp[n][k]<<endl;

   
    return 0;
}

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

int toSec(int h, int m, int s) {
  return (h*60+m)*60+s;
}

vector<int> toHms(int sec) {
  vector<int> v;
  v.push_back(sec/(60*60));
  sec -= v[0]*60*60;
  v.push_back(sec/60);
  v.push_back(sec - v[1]*60);
  return v;
}

int main() {
  int h, m, s;
  while(cin >> h >> m >> s) {
    if(h == -1 && m == -1 && s == -1) break;
    int sec = toSec(h,m,s);
    vector<int> v[2];
    v[0] = toHms(toSec(2,0,0)-sec);
    v[1] = toHms((toSec(2,0,0)-sec)*3);
    for(int i = 0; i < 2; ++i) {
      printf("%02d:%02d:%02d\n", v[i][0], v[i][1], v[i][2]);
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>

using namespace std;

int n,d;
const int INF=1000000000;
int main(){

	while(cin>>n>>d&&(n|d)){
		vector<stack<int> > vsi;
		vector<int> sums;
		int minSum=INF;
		int maxSum=-1;
		for(int i=0;i<n;i++){
			int m;
			cin>>m;
			stack<int> s;
			int sum=0;
			for(int j=0;j<m;j++){
				int a;
				cin>>a;
				sum+=a;
				s.push(a);
			}
			vsi.push_back(s);
			sums.push_back(sum);
			minSum=min(minSum,sum);
			maxSum=max(maxSum,sum);
		}
		while(1){
			// ðð½³È¢
			if(maxSum-(minSum)>d){
				cout<<"No"<<endl;
				break;
			}
			bool fin=true;
			for(int i=0;i<n;i++){
				if(vsi[i].empty())continue;
				else fin=false;
			}
			if(fin){
				cout<<"Yes"<<endl;
				break;
			}
			int idx=-1;
			int num=-1;
			int band=INF;
			// æè¯éàÌÌ¤¿AÅ¬lÆÅålÌðÅà¬³­·éàÌðÌð
			for(int i=0;i<n;i++){
				if(vsi[i].empty())continue;
				int tmpMax=-1;
				int tmpMin=INF;
				int a=vsi[i].top();
				vsi[i].pop();
				sums[i]-=a;
				for(int j=0;j<n;j++){
					tmpMax=max(tmpMax,sums[j]);
					tmpMin=min(tmpMin,sums[j]);
				}
				sums[i]+=a;
				vsi[i].push(a);
				// àµÅålÆÅ¬lÌª¬³¯êÎ
				if(band>tmpMax-tmpMin){
					idx=i;
					band=tmpMax-tmpMin;
					num=vsi[i].top();
				}
			}
			sums[idx]-=num;
			vsi[idx].pop();
			maxSum=-1;
			for(int i=0;i<n;i++)maxSum=max(sums[i],maxSum);
			minSum=INF;
			for(int i=0;i<n;i++)minSum=min(sums[i],minSum);
		}
	}

	return 0;
}

Measured memory_bytes: 976