akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <functional>
#include <iostream>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;

using vll = vector<ll>;

void solve();

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

  solve();

  return 0;
}

#define ini(...)   \
  int __VA_ARGS__; \
  in(__VA_ARGS__)

#define inl(...)  \
  ll __VA_ARGS__; \
  in(__VA_ARGS__)

#define ins(...)      \
  string __VA_ARGS__; \
  in(__VA_ARGS__);

void in() {}
template <typename T, class... U>
void in(T& t, U&... u) {
  cin >> t;
  in(u...);
}

void out() {
  cout << endl;
}
template <typename T, class... U>
void out(const T& t, const U&... u) {
  cout << t;
  if (sizeof...(u))
    cout << " ";
  out(u...);
}

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

void solve();
#ifndef ONLINE_JUDGE
#include "./lib.hpp"
#endif

void solve() {
    ini(N, Ma, Mb);
    vector<int> a(N), b(N), c(N);
    rep(i, N) cin >> a[i] >> b[i] >> c[i];

    vector<vector<vector<int>>> dp(N + 1, vector<vector<int>>(401, vector<int>(401, 1 << 20)));
    dp[0][0][0] = 0;

    rep(i, N) {
        for (int j = 0; j <= 400; j++) {
            for (int k = 0; k <= 400; k++) {
                if (j >= a[i] && k >= b[i])
                    dp[i + 1][j][k] = min(dp[i][j][k], dp[i][j - a[i]][k - b[i]] + c[i]);
                else
                    dp[i + 1][j][k] = dp[i][j][k];
            }
        }
    }

    int ret = 1 << 20;
    for (int i = 1; i * Ma <= 400 && i * Mb <= 400; i++)
        ret = min(ret, dp[N][i * Ma][i * Mb]);

    if (ret < (1 << 20))
        out(ret);
    else
        out(-1);
}


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

int main() {
  int Ans = -1;  // 回答：
  // string Ans = "Yes";  // 回答：
  int A; cin >> A; // ８％時の消費税
  int B; cin >> B; // １０％時の消費税

  int tmp_A,tmp_B;  // 消費税額（仮
  rep(i,1250){
    tmp_A = i * 0.08;
    tmp_B = i * 0.1;

    if ( tmp_A == A && tmp_B == B ) {
      Ans = i;
      break;
    }
  }

  cout << Ans << endl;

}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\n"

int main()
{
  i64 A;
  string B;
  cin >> A >> B;
  cout << A * stoi(B.substr(0, 1)) + A * stoi(B.substr(2, 2)) / 100 << endl;
  return 0;
}


Measured memory_bytes: 3624
while True:
    m,f,r = list(map(int,input().split()))
    ret = 'F'
    if m==f==r==-1: break
    elif -1 in (m,f): pass
    elif m + f >= 80: ret = 'A'
    elif m + f  >= 65: ret = 'B'
    elif m + f  >= 50: ret = 'C'
    elif m + f  >= 30: 
        ret = 'D'
        if r >= 50:ret = 'C'
    print(ret)

Measured memory_bytes: 7656
#include "stdio.h"
#include "stdlib.h"

int a[100];
int N;
int count;

void printResult(){
    for(int i=0; i<N; i++){
        if(i != N-1){
            printf("%d ", a[i]);
        }
        else{
            printf("%d\n", a[i]);
        }
    }
}

int main(){
    //freopen("D:\\zhouyu\\study\\codes\\BubbleSort.txt", "r", stdin);
    scanf("%d", &N);
    for(int i=0; i<N; i++){
        scanf("%d", &a[i]);
    }
    int flag = 1;
    int i=0;
    int j;
    count = 0;
    while(flag == 1){
        //printResult();
        flag = 0;
        for(j=N-1; j>i; j--){
            if(a[j] < a[j-1]){
                count++;
                flag = 1;
                a[j] = a[j] ^ a[j-1];
                a[j-1] = a[j] ^ a[j-1];
                a[j] = a[j] ^ a[j-1];
            }
        }
    }
    printResult();
    printf("%d\n", count);
    return 0;
}




Measured memory_bytes: 2040
#include<bits/stdc++.h>
using namespace std;
int main() {
  int a,b,c,k;
  cin >> a >> b >> c >> k;
  if (a>=k){
    cout << k << endl;
  }
  else if (a+b>=k){
    cout << a << endl;
  }
  else{
    cout <<2*a+b-k<< endl;
  }
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<limits.h>
#define NIL -1
static const int MAX = 1005;
static const int INFTY = (1<<21);

main(){
  int n, i, j, v, c, u, k, minV;
  int M[MAX][MAX], A[MAX], key[MAX], p[MAX];
  /*your code*/

  scanf("%d", &n);
  for ( i = 0; i< n; i++ ){
    for ( j = 0; j < n; j++ ){
      M[i][j] = INFTY;
    }
  }

  for ( i = 0; i < n; i++ ){
    scanf("%d %d", &u, &k);
    for ( j = 0; j < k; j++ ){
      scanf("%d %d", &v, &c);
      M[u][v] = c;
    }
  }

  /*your code*/
  for(i = 0; i < n; i++){
    key[i] = INT_MAX;
    p[i] = NIL;
    A[i] = NIL;
  }
  
  key[0]=0;
  
  while(1){
    
    u = NIL;
    
    minV = INT_MAX;
    
    for(i = 0;  i < n; i++){
      
      if(key[i] < minV && A[i] == NIL){
	
	u = i;
	
	minV = key[i];
	
      }
      
    }  
    if(u == NIL)break;
    
    A[u] = u; 
    
    for(v = 0; v < n; v++){
      if((M[u][v]+key[u]) < key[v] && A[v] == NIL){
	key[v] = (M[u][v]+key[u]);
	p[v] = u;
      }
    }
  }
  
  for ( i = 0; i < n; i++ ){
    printf("%d %d\n", i, (key[i]==INFTY?-1:key[i]));
  }

  return 0;

}

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

int main(){
    int white_chain , black_chain, white, black;
    cin >> white_chain >> black_chain;

    char field[100][100] ; 
	white = 1;
	black = 1;
	cout << "100 100" << endl;
	for(int y = 48; y >= 0; y--) {
		for(int x = 0; x < 100; x++) {
			if( ((100*y+x)%3 == 0) && white < white_chain) {
				field[y][x] = '.' ;
				white++;
			} else {
				field[y][x] = '#' ;
			}
		}
	}
	
	for(int x = 0; x < 100; x++) {
	    field[49][x] = '#' ;
	    field[50][x] = '.' ;
	}

	for(int y = 51; y < 100; y++) {
		for(int x = 0; x < 100; x++) {
			if( ((100*y+x)%3 == 2) && black < black_chain) {
				field[y][x] = '#' ;
				black++;
			} else {
				field[y][x] = '.' ;
			}
		}
	}
	
	for(int y = 0; y < 100; y++) {
		for(int x = 0; x < 100; x++) {
		    printf("%c", field[y][x]);
		}
		printf("\n");
	}
	
    return 0;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    a_s = list(map(int,input().split()))
    answer = 999999999999999999999999999999999

    for i in range(-100,101):
        temp = sum([(a-i) ** 2 for a in a_s ])
        answer = min(answer,temp)
    print(answer)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class Main{
    public static void main(String[] args)throws Exception {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
        String a = input.readLine();
        String b = input.readLine();
        String s = null;
        if (a.length() < b.length())
            s = "LESS";
        else if (a.length() > b.length())
            s = "GREATER";
        else {
            for (int i = 0; i < a.length(); i++) {
                if (a.charAt(i) > b.charAt(i)){
                    s = "GREATER";
                    break;
                }else if (a.charAt(i) < b.charAt(i)) {
                    s = "LESS";
                    break;
                }
            }
        }
        if (s == null)
            s = "EQUAL";

        out.write(s);
        out.write("\n");
        out.close();

    }
}


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

int main(){
    int n,k,d, snuke, ans = 0;
    bool chSnuke[101] = {};
    cin >> n >> k;
    while(k--){
        cin >>  d;
        for(int snack = 1; snack <= d ; ++snack){
            cin >> snuke;
            chSnuke[snuke] = 1;
        }
    }
    for(int i = 1 ; i <= n ; ++i){
        ans += chSnuke[i] == 0 ? 1 : 0;
    }
    cout << ans;


    return 0;
}

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

int main()
{
    int a[5], k;
    for(int i = 0; i < 5; i++)
        cin >> a[i];
    cin >> k;
    for(int i = 0; i < 5; i++)
    {
        for(int j = i + 1; j < 5; j++)
        {
            if(abs(a[i] - a[j]) > k)
            {
                cout << ":(";
                return 0;
            }
        }
    }
    cout << "Yay!";
    return 0;
}


Measured memory_bytes: 3520
/*
AtCoder Library Practice Contest - C - Floor Sum
https://atcoder.jp/contests/practice2/tasks/practice2_c
*/

#include <bits/stdc++.h>
#include <atcoder/math>
using namespace std;
using namespace atcoder;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;

double EPS=1e-9;
int INF=1000000005;
long long INFF=1000000000000000005ll;
double PI=acos(-1);
int dirx[8]={ -1, 0, 0, 1, -1, -1, 1, 1 };
int diry[8]={ 0, 1, -1, 0, -1, 1, -1, 1 };
const ll MOD = 1000000007;

#define DEBUG fprintf(stderr, "====TESTING====\n")
#define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
#define OUT(x) cout << x << endl
#define OUTH(x) cout << x << " "
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define READ(x) for(auto &(z):x) cin >> z;
#define FOR(a, b, c) for (int(a)=(b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a)=(b); (a) <= (c); ++(a))
#define FORD(a, b, c) for (int(a)=(b); (a) >= (c); --(a))
#define FORSQ(a, b, c) for (int(a)=(b); (a) * (a) <= (c); ++(a))
#define FORC(a, b, c) for (char(a)=(b); (a) <= (c); ++(a))
#define EACH(a, b) for (auto&(a) : (b))
#define REP(i, n) FOR(i, 0, n)
#define REPN(i, n) FORN(i, 1, n)
#define MAX(a, b) a=max(a, b)
#define MIN(a, b) a=min(a, b)
#define SQR(x) ((ll)(x) * (x))
#define RESET(a, b) memset(a, b, sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define PERMUTE next_permutation
#define TC(t) while (t--)
#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)

void solve() {
	ll n, m, a, b;
	cin >> n >> m >> a >> b;
	OUT(floor_sum(n,m,a,b));
}

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

    int tc; cin >> tc;
    TC(tc) solve();

    return 0;
}


Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;



int main(){
double a,b,c,d,e,f;
cin >> a>>b>>c>>d>>e>>f;

double x,y,ans=0,s,r;

rep(i,100){
    rep(j,100){
        rep(k,100){
            rep(l,100){
                x=100*a*i+100*b*j;
                y=c*k+d*l;

                if(x+y<=f and y<=x*e/100){
                    if(y/(x+y)>=ans){
                        ans=y/(x+y);
                        s=x+y;r=y;
                    }
                }
            }
}}}

cout << s << " " << r <<endl;

return 0;

}
    


 


Measured memory_bytes: 256
program main
  implicit none
  integer :: n, i, res
  integer, allocatable :: p(:)
  read (*, *) n
  allocate (p(n))
  read (*, *) p
  i = 1
  res = 0
  do while (i <= n)
    if (p(i) == i) then
      res = res + 1
      i = i + 2
    else
      i = i + 1
    end if
  end do
  write (*, "(i0)") res
end program main


Measured memory_bytes: 1152
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
using namespace std;
using ll =long long;
int main() {
	int N, M;
	cin >> N >> M;
	int t=0;
	if (N - 1 > 0) {
		t += (N * (N - 1))/2;
	}
	if (M - 1 > 0) {

		t += (M * (M - 1))/2;
	}
	cout << t;

}

Measured memory_bytes: 384
import java.util.Scanner;
import java.util.Map;
import java.util.HashMap;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Map<Integer,Integer> a = new HashMap<>();
        for(int i = 0;i < n;i++){
            int x = sc.nextInt();
            if(a.containsKey(x)){
                a.put(x,a.get(x)+1);
                continue;
            }
            a.put(x,1);
        }
        int cnt = 0;
        for(Integer key : a.keySet()){
            int num = key;
            if(key > a.get(key)){
                cnt += a.get(key);
                continue;
            }
            cnt += a.get(key) - num;
        }
        System.out.println(cnt);
    }
}


Measured memory_bytes: 61588
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import random
import re
import string
import sys
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import lru_cache, reduce
from math import gcd
from operator import add, itemgetter, mul, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353



S = sys.stdin.buffer.readline().decode().rstrip()
if S=='ABC':
    print('ARC')
else:
    print('ABC')


Measured memory_bytes: 27216
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N;
	int A[200000+2] = {0};
	cin >> N;

	for(int i = 2; i <= N; i++){
		int a;
		cin >> a;
		A[a]++;
	}
	for(int i=1; i<=N; i++){
		printf("%d\n", A[i]);
	}
	return 0;
}

Measured memory_bytes: 4516
#include<bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> 
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define MOD 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed<<setprecision(n)
#define eps 0.000001
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define bolt ios::sync_with_stdio(0)
#define light cin.tie(0);cout.tie(0)
#define umll unordered_map<ll,ll>
#define mll map<ll,ll>
#define forr(i,p,n) for(ll i=p;i<(ll)n;i++)
#define test int t;cin>>t;while(t--)
#define MAXN 1000003
typedef long long ll;
using namespace std;
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;}
ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n%p; n = n * n%p;} return r;}
ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = MOD){ll m0 = m;ll y = 0, x = 1;if (m == 1)return 0;while (a > 1){ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}
using namespace __gnu_pbds;  
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>ordered_set; 
void solve() {
	ll n;
	cin>>n;
	ll dp[n][3];
	forr(i,0,n) {
		ll a,b,c;
		cin>>a>>b>>c;
		if(i==0) {
			dp[i][0]=a;
			dp[i][1] = b;
			dp[i][2]=c;
			continue;
		}
		dp[i][0] = a+max(dp[i-1][1],dp[i-1][2]);
		dp[i][1] = b+max(dp[i-1][0],dp[i-1][2]);
		dp[i][2] = c+max(dp[i-1][0],dp[i-1][1]);
	}
	cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}
int main(){
	bolt;
	light;
		solve();
 	return 0;
 }

Measured memory_bytes: 2560
/*    三玖天下第一！！！  */
#include<bits/stdc++.h>
using namespace std;
const int ng=30,maxn=1e5;
int n,L,x[maxn+5]={},f[ng+5][maxn+5]={};
inline int dread()
{
	int x=0;bool f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f^=1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	return f?x:-x;
}
inline void in(){n=dread();for(int i=1;i<=n;i++) x[i]=dread();L=dread();}
inline void work()
{
	for(int i=1;i<=n;i++) f[0][i]=upper_bound(x+i,x+1+n,x[i]+L)-x-1;
	for(int i=1;i<=ng;i++) for(int j=1;j<=n;j++) f[i][j]=f[i-1][f[i-1][j]];
}
inline void out()
{
	for(int q=dread(),a,b,ans;q;q--)
	{
		a=dread();b=dread();ans=0;if(a>b) swap(a,b);
		for(int i=ng;i>=0;i--) if(f[i][a]<b) ans+=(1<<i),a=f[i][a];
		printf("%d\n",ans+1);
	}
}
int main(){in();work();out();return 0;}


Measured memory_bytes: 13568
# -*- coding: utf-8 -*-
# 整数の入力
h, w = map(int, input().split())
s = [""]*h

for i in range(h):
    s[i] = list(input())

# 探索対象になっている上下左右のマス目との添字をあらかじめ記録する
dx = [-1, 0, 0, 1]
dy = [0, -1, 1, 0]

result = True
# 上下左右いずれかで2連続に塗り対象とできるマス
for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            continue
        else:
            can_drow = False
            for d in range(len(dx)):
                x = j + dx[d]
                y = i + dy[d]

                if not 0 <= x < w:
                    continue
                if not 0 <= y < h:
                    continue
                if s[y][x] == "#":
                    can_drow = True
                    break
            if not can_drow:
                result = False

if result:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1 for _ in range(n)]

    def root(self, x):
        '''
        xの根を返す
        '''
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.root(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        '''
        二つの木を合併する
        '''
        x = self.root(x)
        y = self.root(y)

        if x == y:
            return
        
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def size(self, x):
        '''
        xが属する木のサイズを返す
        '''
        return -self.parents[self.root(x)]

    def same(self, x, y):
        '''
        xとyが同じ木に属するかを調べる
        '''
        return self.root(x) == self.root(y)

    def members(self, x):
        '''
        xの木のリストを返す
        '''
        root = self.root(x)
        return [i for i in range(self.n) if self.root(i) == root]

    def roots(self):
        '''
        全ての根のリストを返す
        '''
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        '''
        木の数を返す
        '''
        return len(self.roots())

    def all_group_members(self):
        '''
        木の辞書を返す
        '''
        return {r:  self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, M, K = map(int, input().split())
if M:
    AB = [map(int, input().split()) for _ in range(M)]
    A, B = [list(i) for i in zip(*AB)]
if K:
    CD = [map(int, input().split()) for _ in range(K)]
    C, D = [list(i) for i in zip(*CD)]


friend = [[] for i in range(N)]
block = [[] for i in range(N)]

uf = UnionFind(N)

if M:
    for i in range(M):
        uf.union(A[i]-1, B[i]-1)
        friend[A[i]-1].append(B[i]-1)
        friend[B[i]-1].append(A[i]-1)

if K:
    for i in range(K):
        block[C[i]-1].append(D[i]-1)
        block[D[i]-1].append(C[i]-1)

for i in range(N):
    tmp = uf.size(i)-1
    for v in friend[i]:
        if uf.same(i, v):
            tmp -= 1
    for v in block[i]:
        if uf.same(i, v):
            tmp -= 1

    print(tmp)

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

int main(){
    string N; cin >> N;
    if((N[0] == N[1] && N[1] == N[2]) || (N[1] == N[2] && N[2] == N[3])){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}
    

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int i, n, sum = 0, cnt = 0;
  scanf("%d", &n);
  int a[n], box[100000]={};

  for(i=0;i<n;i++){
    scanf("%d", &a[i]);
    if(a[i] <= 100000)
      box[a[i]]++;
    else
      sum++;
  }

  for(i=0;i<100000;i++){
    if(box[i]<i) sum += box[i];
    else if(box[i]>i) sum += (box[i]-i);
  }
  printf("%d", sum);

  return 0;
}
  


Measured memory_bytes: 896
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		String[] inputs = new Scanner(System.in).nextLine().split(" ");
		String a = inputs[0];
		String b = inputs[1];
		
		if (a.equals("H")) {
			System.out.println(b);
		}
		else {
			System.out.println((b.equals("H") ? "D" : "H"));
		}
	}

}

Measured memory_bytes: 22100
#include <bits/stdc++.h>
using namespace std;
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; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


int main() {
    long long N;
    cin >> N;
    string res = "";
    while (N) {
        --N;
        res += (char)('a' + (N % 26));
        N /= 26;
    }
    reverse(res.begin(), res.end());
    cout << res << endl;
}

















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

/*** Template Begins ***/

typedef long long    ll;
typedef pair<ll,ll>  pll;
typedef pair<ll, pair<int, int> > plll;
typedef vector<long long>  vll;
typedef vector<pll>  vp;

#define pb           push_back
#define INF          INT_MAX/10
#define F            first
#define S            second
#define mp           make_pair
#define ios          ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define hell         1000000007
#define all(a)       (a).begin(),(a).end()
ll power(ll x, ll y, ll p){ ll res = 1;x = x % p;while (y > 0){ if (y & 1) res = (res*x) % p;y = y>>1;x = (x*x) % p;} return res; } 

// Debug //

#define trace(x)                 cerr << #x << ": " << x << endl;
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

// Constants //

const int N = 1e5+7;
const int xinc[] = {0, 0, 1, -1};
const int yinc[] = {1, -1, 0, 0};

/*** Template Ends ***/
std::vector<string> p;
void permute(string str, string out) 
{ 
    // When size of str becomes 0, out has a 
    // permutation (length of out is n) 
    if (str.size() == 0) 
    { 
        p.push_back(out);
        return; 
    } 
  
    // One be one move all characters at 
    // the beginning of out (or result) 
    for (int i = 0; i < str.size(); i++) 
    { 
        // Remove first character from str and 
        // add it to out 
        permute(str.substr(1), out + str[0]); 
  
        // Rotate string in a way second character 
        // moves to the beginning. 
        rotate(str.begin(), str.begin() + 1, str.end()); 
    } 
} 

   void solve()
{
    ll n,i,j,k;
    cin>>n;
    ll v[n+1][4],dp[n+1][4];
    for(i=1;i<=n;i++)
    {
      for(j=1;j<=3;j++)
        cin>>v[i][j];
    }
    for(i=1;i<=n;i++)
    {
      for(j=1;j<=3;j++)
        dp[i][j]=0;
    }
    for(i=1;i<=3;i++)
      dp[1][i]=v[1][i];
    for(i=2;i<=n;i++)
    {
      for(j=1;j<=3;j++)
      {
        for(k=1;k<=3;k++)
        {
          if(j!=k)
            dp[i][j]=max(dp[i][j],dp[i-1][k]+v[i][j]);
        }
      }
    }
    ll ans=0;
    for(i=1;i<=3;i++)
    {
      ans=max(dp[n][i],ans);
    }
    cout<<ans;
}
  
int main(){
  
  ios;
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  int t;
  //cin >> t;
  t = 1;
  while(t--)
    solve();

  return 0;
}

Measured memory_bytes: 6528
#include<stdio.h>
int a[1000000];
int main(){
	int k,n,i,max;
	scanf("%d %d",&k,&n);
	for (i=1;i<=n;i++)
	  scanf("%d",&a[i]);
	max=a[1]+k-a[n];
	for (i=2;i<=n;i++)
	  if (a[i]-a[i-1]>max)
	    max=a[i]-a[i-1];
	printf("%d",k-max);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define PW 1000000007
using namespace std;

int main() {
	long long int power = 1;
	int N;
	
	cin >> N;
	for(int i = 1; i <= N; i++) {
		power = i * power % PW;
	}
	cout << power << endl;
}


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

// a quote from http://www.igaris.com/math/c.pdf

#define MOD (1000000000+7)

long long C[1001][1001];

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

	long long ans = 0;
	if( n >= k ) {
		// Pascal's triangle for combination
		C[0][0] = 1;
		for( int i = 1; i < 1001; i++ ) {
			for( int j = 0; j <= i; j++ ) {
				if( j == 0 || j == i ) {
					C[i][j] = C[i - 1][0];
				}
				else {
					C[i][j] = ( C[i - 1][j - 1] + C[i - 1][j] ) % MOD;
				}
			}
		}
		ans = C[n - 1][k - 1];
	}

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 10004
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b;
  cin >> a >> b;
  int c = a+b;
  if (a%3 == 0) {
    cout << "Possible" << endl;
  } else if (b%3 == 0) {
    cout << "Possible" << endl;
  } else if (c%3 == 0) {
    cout << "Possible" << endl;
  } else {
    cout << "Impossible" << endl;
  }
}

Measured memory_bytes: 256
import sys
import numpy as np
import math  # gcdもあるよ
from collections import deque
from collections import defaultdict
from copy import deepcopy
from itertools import accumulate #リストを与えると累積和を返す
def input(): return sys.stdin.readline().rstrip()
from functools import lru_cache #メモ化

def main():
    a, b, c = list(map(int,input().split()))
    ans = 0
    while(0 < a):
        ans += c
        a -= b
    print(ans)
    return 0

if __name__ == "__main__":
    main()

Measured memory_bytes: 26996
// In the name of God
#include <bits/stdc++.h>

using namespace std;
#define Size(x) ((int)(x).size())
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
const int INF = 1e9 + 10;
const int MN = 1e5 + 10;

ll n , arr[MN] , sm;
ll sigma;

int main()
{
	ios_base :: sync_with_stdio(false) ,cin.tie(0) , cout.tie(0);
	cin >> n;
	for(int i=0;i<n;++i) cin >> arr[i] , sm += arr[i];
	if(sm%(n*(n+1)/2)) return cout << "NO\n" , 0;
	sigma = sm / (n*(n+1)/2);
	for(int i=0;i<n;++i){
		ll bck = arr[(i-1+n)%n];
		if(((arr[i]-bck-sigma)%n+n)%n || (arr[i]-bck-sigma)>0) return cout << "NO\n" , 0;
	}
	cout << "YES\n";
	return 0;
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int k = scanner.nextInt();
        int t = scanner.nextInt();
        int max = 0;
        for (int i = 0; i < t; i++) {
            max = Math.max(max, scanner.nextInt());
        }
        System.out.println(Math.max(max - k + max - 1, 0));
    }
}

Measured memory_bytes: 21716
import java.util.Scanner;

public class Main{
	public static void main(String[] args)
	{
		Scanner sc =new Scanner(System.in);
		String a=sc.next();
		String b=sc.next();
		String c=sc.next();
		String x=a.toUpperCase();
		String y=b.toUpperCase();
		String z=c.toUpperCase();
		
		System.out.print(x.charAt(0));
		System.out.print(y.charAt(0));
		System.out.println(z.charAt(0));
	}
} 

Measured memory_bytes: 21844
#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>;

const int mod = 1'000'000'007;
int main() {
    int n;
    cin >> n;
    ll a = 1, b = 1, c = 1;
    rep(i,n) {
        a = (a * 10) % mod;
        b = (b * 9) % mod;
        c = (c * 8) % mod;
    }
    int ans = (a - b + mod) % mod;
    ans = (ans - b + mod) % mod;
    ans = (ans + c) % mod;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3640
h,w=gets.split.map(&:to_i)
a = ""
for i in 0...h do
  s = gets.split
  for j in 0...w do
    if s[ j ] == "snuke" then
      a = "#{('A'..'Z').to_a[ j ]}"+"#{i+1}"
    end
  end
end

puts a

Measured memory_bytes: 1788
#include<iostream>
#include<algorithm>
#include<cstdio>

using namespace std;

int main(){
    int N;
    cin >> N;
    long long a[N];
    int c=0;
    for(int i=0;i<N;i++) {
        scanf("%lld",a+i);
        if(a[i]%2) c++;
    }
    cout << (!(c%2)?"YES":"NO")<<endl;
}

Measured memory_bytes: 1024
N, M, X, Y = map(int, input().split())
Xi = list(map(int, input().split()))
Yi = list(map(int, input().split()))
Xi.append(X)
Yi.append(Y)
xm = max(Xi)
ym = min(Yi)

if xm < ym:
    print("No War")
else:
    print("War")

Measured memory_bytes: 3060
#include <stack>
#include <queue>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <set>
#include <tuple>
#include <cmath>
#include <random>
#include <algorithm>
#include <vector>
#include <iostream>
#include <fstream>
#include <chrono>
#include <numeric>

#define fio ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)
#define rng mt19937_64 rnd(chrono::system_clock::now().time_since_epoch().count())

#define ri(...) i64 __VA_ARGS__; rx(__VA_ARGS__)
#define rc(...) char __VA_ARGS__; rx(__VA_ARGS__)
#define rs(...) string __VA_ARGS__; rx(__VA_ARGS__)
#define rvi(x, n) vi x(n); cin >> x
#define rvvi(x, n, m) vvi x(n, vi(m)); cin >> x

#ifndef ONLINE_JUDGE
#define dbg(...) cerr << '[' << #__VA_ARGS__ << "]: "; dbg_log(__VA_ARGS__)
#else
#define dbg(...) ;;
#endif

#define fa(i, v) for (auto &i : v)
#define fi(i, n) for (i32 i = 0; i < n; i++)
#define fp(i, n) for (i32 i = 1; i < n; i++)
#define fr(i, n) for (i32 i = n - 1; i >= 0; i--)
#define fu(i) ri(_i); fi(i, _i)

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;

typedef uint32_t u32;
typedef int32_t i32;
typedef uint64_t u64;
typedef int64_t i64;
#ifdef __SIZEOF_INT128__
typedef __uint128_t u128;
typedef __int128_t i128;
#endif
typedef vector<i64> vi;
typedef vector<vi> vvi;

template<typename T>
inline istream &operator>>(istream &in, vector<T> &v) {
    fa(x, v) in >> x;
    return in;
}

template<typename T>
inline ostream &operator<<(ostream &out, const vector<T> &v) {
    fa(x, v) out << x << ' ';
    return out;
}

template<typename T>
inline void rx(T &x) {
    cin >> x;
}

template<typename T, typename... R>
inline void rx(T &x, R &... l) {
    cin >> x;
    rx(l...);
}

template<typename T>
inline void dbg_log(const T &x) {
    cerr << x << '\n';
}

template<typename T, typename... R>
inline void dbg_log(const T &x, const R &... l) {
    cerr << x << ", ";
    dbg_log(l...);
}

template<typename T>
inline void wl(const T &x) {
    cout << x << '\n';
}

template<typename T, typename... R>
inline void wl(const T &x, const R &... l) {
    cout << x << ' ';
    wl<R...>(l...);
}

int main() {
    fio;

    ri(x, k, d);
    if ((u64) k & 1u) {
        if (x < 0) x += d;
        else x -= d;
    }
    i64 u = min(abs(x) / (2 * d) + 1, k / 2);
    i64 v = u - 1;
    if (x < 0) u = -u;
    if (x < 0) v = -v;
    wl(min(abs(x - 2 * u * d), abs(x - 2 * v * d)));

    return 0;
}


Measured memory_bytes: 3608
/**
 *	author:   fractal
 *	timus:    288481RF
 *	created: 08/22/20 18:01:44
**/

#include <bits/stdc++.h>
using namespace std;

#define F first
#define S second 
#define mp make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define speed_up ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define sz(x) (int)x.size()
#define szc(x) (int)strlen(x)
#define all(x) x.begin(), x.end()
#define debug cerr << "OK\n";
#define ub upper_bound
#define lb lower_bound 
 
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef set <int> si;
typedef set <ll> sll;
typedef multiset <int> msi;
typedef multiset <ll> msll;
typedef map <int, int> mi;
typedef map <ll, int> mll;
 
const int N = 1e6 + 2;
const int M = 1e5;
const int mod = 0;
const int inf = 2e9 + 3;
const ll INF = 1e16;

int n, x, t;

int main() {
	scanf("%d %d %d", &n, &x, &t);
	int need = (n + x - 1) / x;
	printf("%d", need * t);
}


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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define int ll
#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(int i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで降順
#define pb push_back
#define eb emplace_back
#define fst first
#define snd second
using ll  = long long;
using vi  = vector<int>;
using vvi = vector<vi>;
using vs  = vector<string>;
using pii = pair<int,int>;
constexpr ll inf = 1ll<<61;
constexpr ll mod = 1e9+7;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>T add(const T &a, const T &b){return (a+b)%mod;}

signed main(){
  int w, h, x, y; cin >> w >> h >> x >> y;
  double ans = w*h;
  ans /= 2;
  bool f = (w == 2*x) and (h == 2*y);
  printf("%.10lf %d\n",ans,f);
}


Measured memory_bytes: 256
#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;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

const ll INF=(1LL<<50);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif
template<class T>
bool chmax(T& a,const T& b){
  if(a<b){
    a=b;
    return true;
  }
  return false;
}
template<class T>
bool chmin(T& a,const T& b){
  if(a>b){
    a=b;
    return true;
  }
  return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(long long N, std::vector<std::string> S){
  set<string> s;
  REP(N){
    s.insert(S[i]);
  }
  cout<<s.size()<<endl;
}

int main(){
  cout<<setprecision(1000);
    long long N;
    scanf("%lld",&N);
    std::vector<std::string> S(N);
    for(int i = 0 ; i < N ; i++){
        std::cin >> S[i];
    }
    solve(N, std::move(S));
    return 0;
}


Measured memory_bytes: 25132
#include<cstdio>
#include<functional>
#include<algorithm>
#define M -1
using namespace std;
int v[101],w[101],nn[10001];
int main(void)
{
	int N,W,i,j,mm;
	scanf("%d %d",&N,&W);
	for(i=0;i<N;i++) scanf("%d %d",&v[i],&w[i]);
	for(i=0;i<=W;i++){
		nn[i]=M;
	}
	nn[0]=0;
	for(i=0;i<N;i++){
		for(j=0;j<=W;j++){
			if(w[i]+j>W) break;
			if(nn[j]!=M){
				nn[w[i]+j]=max(nn[w[i]+j],nn[j]+v[i]);
			}
		}
	}
	mm=-2;
	for(i=0;i<=W;i++){
		if(mm<nn[i]){
			mm=nn[i];
		}
	}
	printf("%d\n",mm);
	return 0;
}

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

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

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

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

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cerr << head << " ";
  print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
  int val = ((a % mod) + (b % mod)) % mod;
  if (val < 0) { val += mod; }
  a = val;
}

template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

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

int N;
vec<int> A, B;

int calc(int b) {
  int ret = 0;
  for (int i = 1; i <= N; i++) {
    ret += abs(A[i-1] - (b + i));
  }
  return ret;
}

signed main() {
  cin >> N;
  A.resize(N);
  B.resize(N);
  rep (i, N) {
    cin >> A[i];
    B[i] = A[i] - (i + 1);
  }
  sort(all(B));

  cout << calc(B[N/2]) << endl;

  return 0;
}

Measured memory_bytes: 3328
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_C&lang=ja
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N,W,*vw = map(int, read().split())

    VW = []
    for v, w in zip(*[iter(vw)]*2):
        VW.append((v, w))

    dp = [[0] * (W+1) for _ in range(N+1)]

    for i in range(N):
        v_i, w_i = VW[i]
        for j in range(W+1):
            if j < w_i:
                dp[i+1][j] = dp[i][j]
            else:
                dp[i+1][j] = max(dp[i+1][j - w_i] + v_i, dp[i][j])

    print(dp[N][W])    


if __name__ == "__main__":
    main()


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

#define pb push_back
#define pf push_front
#define pp pop_back
#define sz(a) (int)(a.size())
#define mp make_pair
#define F first
#define S second
#define next _next
#define prev _prev
#define left _left
#define right _right
#define y1 _y1
#define all(x) x.begin(), x.end()
#define what_is(x) #x << " is " << (x)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int N = (int)1e6 + 123;
const ll INF = (ll)1e18 + 123;
const int inf = (int)1e9 + 123;
const int MOD = (int)1e9 + 7;

void megaRandom() {
	unsigned int FOR;
 	asm("rdtsc" : "=A"(FOR));
  srand(FOR);
}

int n, m;
int cnt[N];
bool can[N];

int main() {
	megaRandom();
	cin >> n >> m;
	for(int i = 1; i <= n;i ++)
		cnt[i] = 1;
	can[1] = 1;
	for(int i = 1, x, y; i <= m; i ++) {
 		cin >> x >> y;
		cnt[x] --, cnt[y] ++;
		if(can[x])
			can[y] = 1;
		if(cnt[x] == 0)
			can[x] = 0;
 	}
 	int res = 0;
 	for(int i = 1; i <= n; i ++)
 		res += can[i];
	cout << res;
	return 0;  
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007ll
#define mod1 998244353ll
#define endl "\n"
using namespace std::chrono;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll a,b,k;
    cin>>a>>b>>k;
    if(a>=k)
    {
        cout<<a-k<<" "<<b<<endl;
    }
    else
    {
        cout<<0<<" "<<max(0ll,b-(k-a))<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as C
import Data.Maybe ( fromJust )
import Data.List

cReadLn :: IO Int
cReadLn = fst . fromJust . C.readInt <$> C.getLine

getParms :: IO [Int]
getParms = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

main :: IO ()
main = do
  n  <- cReadLn
  as <- getParms
  print $ f as 

f :: [Int] -> Int
f = h 0
  where
    h :: Int -> [Int] -> Int
    h s []  = s+1
    h s [_] = s+1
    h s (i:is@(j:_))
      | i == j    = h s is
      | i <  j    = g s (<) is
      | otherwise = g s (>) is
    
    g :: Int -> (Int -> Int -> Bool) -> [Int] -> Int
    g s _ []  = s+1
    g s _ [_] = s+1
    g s op (i:is@(j:_))
      | i == j    = g s op is
      | i `op` j  = g s op is
      | otherwise = h (s+1) is

Measured memory_bytes: 2940
#include<stdio.h>
int main(){
  int n,m,o,j,k,max,mi,a,b[20],d[15][100010]={0};
  scanf("%d %d %d",&n,&m,&o);
  for(j=0;j<n;j++)scanf("%d",&b[j+1]);
  while(--m){//printf("m%d\n",m);
    for(j=1;j<=n;j++){
      scanf("%d",&a);//printf("%d\n",b[j]);
      for(k=0;k<=o;k++){
	d[j][k]=d[j-1][k];
	if(k<b[j])continue;
	if(d[j][k]<d[j][k-b[j]]+a)d[j][k]=d[j][k-b[j]]+a;
      }
      b[j]=a;
      //for(k=0;k<=o;k++)printf("%d ",d[j][k]);printf("\n");
    }
    for(k=max=0;k<=o;k++){
      if(max<d[n][k]-k)max=d[n][mi=k]-k;
    }
    o+=max;
  }//printf("\n");
  printf("%d\n",o);
  return 0;
}

Measured memory_bytes: 6464
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,N;
  cin >> N;
  b = N;
  
  while(b > 0){
    a += b % 10;
    b /= 10;
  }
  
  if(N % a == 0){
    cout << "Yes" << endl;
  }
  else if(N % a != 0){
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 256
#include<stdio.h>
#define UC 100001
int t[UC];
int main(){
	int a,n,m,s=0,i,j,x=1;
	scanf("%d%d",&n,&m);
	for(i=1;i<n;i++)scanf("%d",&t[i]);
	for(i=1;i<=m;i++){
		scanf("%d",&a);
		if(a>0)for(j=x;j<x+a;j++)s=s+t[j];
		else for(j=x+a;j<x;j++)s=s+t[j];
		x=x+a;
		s=s%100000;
	}
	printf("%d\n",s);
	return 0;
}



Measured memory_bytes: 2244
#include <algorithm>
#include <cmath>
#include <iostream>
#include <stack>
#include <string>
#include <vector>

int main() {
  uint32_t N = 0;
  std::cin >> N;

  std::vector<std::pair<int32_t, int32_t>> res_plus, res_minus;
  for (size_t i = 0; i < N; i++) {
    std::string S;
    std::cin >> S;
    int32_t min = 0, end = 0;
    for (auto &&s : S) {
      if (s == '(') {
        end++;
      } else {
        end--;
        min = std::min(min, end);
      }
    }
    if (end >= 0)
      res_plus.push_back({min, end});
    else
      res_minus.push_back({min - end, -end});
  }

  std::sort(res_plus.rbegin(), res_plus.rend());
  std::sort(res_minus.rbegin(), res_minus.rend());

  int64_t min_plus = 0, end_plus = 0;
  for (auto &&r : res_plus) {
    min_plus = std::min(min_plus, end_plus + r.first);
    end_plus += r.second;
  }

  int64_t min_minus = 0, end_minus = 0;
  for (auto &&r : res_minus) {
    min_minus = std::min(min_minus, end_minus + r.first);
    end_minus += r.second;
  }

  std::cout << ((min_plus == 0 && min_minus == 0 && end_plus == end_minus)
                    ? "Yes"
                    : "No")
            << std::endl;

  return 0;
}

Measured memory_bytes: 11228
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; --i)
#define FOR(i, n, m) for (int i = m; i < n; i++)
#define MM(i, n, m) for (int i = m; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

typedef long long ll;

/**
 * C問以降は ll を使う.
 * double型にするのを忘れない.
 * nC2の求め方 (1/2)*n*(n-1)
 * vector<型> 変数名(要素数, 初期値)
 * pair<型, 型> 変数名
 * map<型, 型> 変数名  // 連想配列
 * priority_queue<型> 変数名  // 最大値から出てくるヒープ
*/
int main()
{
    int N;
    cin >> N;
    cout << N / 2 + N % 2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main() 
{
 int A,B;
 int C,D;
 scanf("%d %d",&A,&B);
 scanf("%d %d",&C,&D);
 if(A*B>=C*D) {
 	printf(" %d\n",A*B);
 }else{
 	  printf(" %d\n",C*D);
 }
	 
 return 0;
}

 
 
	 


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1LL<<60;
const ll mod=1000000007;

ll n,m;
vector<ll> v[9];
bool seen[9]={};
ll ans=0;

void dfs(ll x,ll k){
    if(k==n){
        ans++;
        return;
    }
    seen[x]=true;
    for(auto z:v[x]){
        if(!seen[z]){
            dfs(z,k+1);
        }
    }
    seen[x]=false;
}

int main() {
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    dfs(1,1);
    cout<<ans<<endl;
}


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

using namespace std;

using ll = long long;
using T = tuple<int, int, int, int>;

int a[505][505];

void calc(int y1, int x1, int y2, int x2, vector<T>& ans) {
    if (x1 <= x2) {
        for (int i = x1; i < x2; i++) {
            ans.emplace_back(y1, i, y1, i + 1);
        }
    } else {
        for (int i = x1; i > x2; i--) {
            ans.emplace_back(y1, i, y1, i - 1);
        }        
    }

    if (y1 <= y2) {
        for (int i = y1; i < y2; i++) {
            ans.emplace_back(i, x2, i + 1, x2);
        }
    } else {
        for (int i = y1; i > y2; i--) {
            ans.emplace_back(i, x2, i - 1, x2);
        }       
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    vector<T> ans;
    int py = -1, px = -1;
    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            cin >> a[i][j];
        }
    }

    for (int i = H; i > 1; i--) {
        for (int j = 1; j <= W; j++) {
            if (a[i][j] % 2 == 1) {
                a[i-1][j]++;
                ans.emplace_back(i, j, i - 1, j);
            }
        }
    }

    for (int j = W; j > 1; j--) {
        if (a[1][j] % 2 == 1) {
            a[1][j-1]++;
            ans.emplace_back(1, j, 1, j - 1);
        }
    }

    assert((int)ans.size() <= H * W);
    cout << ans.size() << endl;
    for (T& t : ans) {
        int y1, x1, y2, x2;
        tie(y1, x1, y2, x2) = t;
        cout << y1 << " " << x1 << " " << y2 << " " << x2 << endl;
    }
    return 0;
}

Measured memory_bytes: 5232
N = int(input())
lst = list(map(int,input().split()))

swap=0
for i in range(len(lst)):
    min_i = i
    for j in range(i+1,len(lst)):
        if lst[j] < lst[min_i]:
            min_i = j
    lst[i],lst[min_i] = lst[min_i],lst[i]
    if lst[i]!=lst[min_i]:
        swap+=1

print(' '.join(map(str,lst)))
print(swap)


Measured memory_bytes: 5600
#include <iostream>
#include <cstdlib>
#include <list>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
 
int main(void)
{
    int64_t N;
    cin >> N;

    int64_t M = (1 + (N / 1000)) * 1000;

    cout << (M - N)%1000;
    
    return 0;
}


Measured memory_bytes: 3152