akhauriyash/Code-Regression huggingface dataset:
// #pragma GCC optimize("unroll-loops", "omit-frame-pointer", "inline")
// #pragma GCC option("arch=native", "tune=native", "no-zero-upper")
// #pragma GCC
// target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("tree-vectorize","openmp","predictive-commoning")
// #pragma GCC option("D_GLIBCXX_PARALLEL","openmp")

// #pragma GCC optimize("O3")
// #pragma GCC target("avx2")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

template <class T>
void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) a = b;
}

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

void solve() {
  string s;
  cin >> s;
  int cntg = 0, cntp = 0;
  int ans = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'g') {
      if (cntp == cntg) {
        cntg++;
      } else {
        cntp++;
        ans++;
      }
    } else {
      if (cntp == cntg) {
        cntg++;
        ans--;
      } else {
        cntp++;
      }
    }
  }
  cout << ans << endl;
  return;
}

signed main() {
  fastio();
  solve();
  //   int t;
  //   cin >> t;
  //   while (t--) solve();

  // int t; cin >> t;
  // for(int i=1;i<=t;i++){
  //   cout << "Case #" << i << ": ";
  //   solve();
  // }
  return 0;
}


Measured memory_bytes: 512
x, y = map(int, input().split())
g1 = [1, 3, 5, 7, 8, 10, 12]
g2 = [4, 6, 9, 11]

if ((x in g1) and (y in g1)) or ((x in g2) and (y in g2)):
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3060
import math

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

ans = 0.

for i in range(1, N + 1):
    if i < K:
        ans += (1 / N) * (1 / (2 ** math.ceil(math.log2(K / i))))
    else:
        ans += 1 / N

print(ans)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define pb push_back
#define SZ(x) ((int)(x.size()))
#define FOR(i,s,n) for (ll i = (s); (i) < (n); ++i)
#define FORD(i,s,l) for (ll i = (s); (i) >= l; --i)
#define F first
#define S second
#define TC int __tc; cin >> __tc; FOR(case_num,1,__tc+1)
#define TEST(x,i) ((x)&(1ll<<(i)))
#define SET(x,i) ((x)|(1ll<<(i)))
#define FLIP(x,i) ((x)^(1ll<<(i)))
#define CLEAR(x,i) ((x)&~(1ll<<(i)))

const double pi = 4 * atan(1);
using namespace std;
typedef long long ll;

const ll MOD = 1000000007;
const int MAXN = 200005;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	string s;
	cin >> n >> s;
	
	map<char,int> cnt;
	for(auto v : s) {
		cnt[v]++;
	}
	
	if (!cnt['R'] || !cnt['W']) {
		cout << "0\n";
		return 0;
	}
	
	map<char,int> l;
	for (int i = 0; i < cnt['R']; i++){
		l[s[i]]++;
	}
	
	map<char,int> r;
	r['R'] = cnt['R'] - l['R'];
	r['W'] = cnt['W'] - l['W'];
	
	int ans = r['R']+l['L'] - min(r['R'],l['L'] );
	cout << ans << "\n";

}


Measured memory_bytes: 3772
#include <stdio.h>
 
int main(){
    int n,x,count;
    while(true){
        scanf("%d %d",&n,&x);
        if(n == 0 && x == 0) break;
        count = 0;
        for(int min = 1; min < x/3 && min <= n-2;min++){
            for(int middle = min+1;middle < x - (min+middle) && middle <= n-1; middle++){
                if(x-(min+middle) <= n) count++;
            }
        }
        printf("%d\n",count);
    }
 
}


Measured memory_bytes: 2708
n,m=map(int,input().split())
j=[[0 for i in range(m+1)] for j in range(n+1)]
o=[[0 for i in range(m+1)] for j in range(n+1)]
i=[[0 for i in range(m+1)] for j in range(n+1)]
field=[]
roop=int(input())
for k in range(n):
    field.append(input())
for k in range(n):
    j_c,o_c,i_c=0,0,0
    for l in range(m):
        if field[k][l]=="J":
                j_c+=1
        if field[k][l]=="O":
                o_c+=1
        if field[k][l]=="I":
                i_c+=1
        j[k+1][l+1]=j[k][l+1]+j_c
        o[k+1][l+1]=o[k][l+1]+o_c
        i[k+1][l+1]=i[k][l+1]+i_c
for k in range(roop):
    x1,y1,x2,y2=map(int,input().split())
    j_c=j[x2][y2]-j[x2][y1-1]-j[x1-1][y2]+j[x1-1][y1-1]
    o_c=o[x2][y2]-o[x2][y1-1]-o[x1-1][y2]+o[x1-1][y1-1]
    i_c=i[x2][y2]-i[x2][y1-1]-i[x1-1][y2]+i[x1-1][y1-1]
    print(j_c,o_c,i_c)


Measured memory_bytes: 126764
#include<stdio.h>
void printAscending(int,int);
int main(void)
{
  int a,b;
  for(;;)
    {
      scanf("%d%d",&a,&b);
      if(a==0&&b==0) break;
      printAscending(a,b);
    }
  return 0;
}
void printAscending(int a,int b)
{
  if(a>b) printf("%d %d\n",b,a);
  else printf("%d %d\n",a,b);
}



Measured memory_bytes: 2056
from collections import defaultdict

def main():
	s = int(input())
	f = defaultdict(bool)
	i = 1
	f[s] = True
	while True:
		s = s//2 if s%2==0 else 3*s+1
		i += 1
		if f[s]:
			print(i)
			break
		f[s] = True


if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
//
// Created by moono on 2018/10/27.
//

#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;



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

    int num = 0;
    if(a < c){
        if(b < d) num = b - c;
        else num = d - c;
    } else{
        if(b < d) num = b - a;
        else num = d - a;
    }

    if(num < 0) num = 0;

    cout << num << endl;

    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import io
import sys
import math
from decimal import Decimal, ROUND_HALF_UP


def format_multi_line_answer(lst):
    ans = ""
    ans += f"{len(lst)}\n"  # Line count
    for y in lst:
        ans += f"{y}\n"
    return ans

def solve(n,n_lst):
    # implement process
    
    #中央値を取り、四捨五入する
    target = Decimal(sum(n_lst)/n).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
    cost = 0
    for a in n_lst:
        cost += pow(a-target,2)
    return cost

def main():
    # input
    n = int(input())
    n_lst = list(map(int, input().split()))

    # process
    ans = str( solve(n,n_lst ) )
    
    # output
    print(ans)
    return ans
        
### DEBUG I/O ###
_DEB = 0   # 1:ON / 0:OFF

_INPUT = """\
4
-100 -100 -100 -100

"""
_EXPECTED = """\
8

"""

def logd(str):
    """usage:
    if _DEB: logd(f"{str}")
    """
    if _DEB: print(f"[deb] {str}")

### MAIN ###
if __name__ == "__main__":
    if _DEB:
        sys.stdin = io.StringIO(_INPUT)
        print("!! Debug Mode !!")

    ans = main()

    if _DEB:
        print()
        if _EXPECTED.strip() == ans.strip(): print("!! Success !!")
        else: print(f"!! Failed... !!\nANSWER:   {ans}\nExpected: {_EXPECTED}")

Measured memory_bytes: 9992
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let N = read!(usize);
    let a = read![[i64]];

    let mut m0 = 0;
    let mut m1 = 0;
    let mut m2 = 0;

    for i in 0..N {
        if a[i] % 4 == 0 {
            m2 += 1;
            continue;
        }

        if a[i] % 2 == 0 {
            m1 += 1;
            continue;
        }

        m0 += 1;
    }

    let ok = if m1 == 0 { m2 + 1 >= m0 } else { m2 >= m0 };

    println!("{}", if ok { "Yes" } else { "No" })
}


Measured memory_bytes: 8444
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = 0;
        while (scanner.hasNext()) {
            a += scanner.nextInt();
        }
        int x = a / 60;
        int y = a % 60;
        System.out.println(x);
        System.out.println(y);
    }
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i=0; i<N; i++){
    cin >> A.at(i);
  }
  int judge = 0;
  for (int i=0; i<N; i++){
    if (A.at(i) % 2 == 0){
      if (A.at(i) % 3 != 0 && A.at(i) % 5 != 0){
        judge++;
      }
    }
  }
  if (judge > 0){
    cout << "DENIED" << endl;
  }
  else{
    cout << "APPROVED" << endl;
  }
}



Measured memory_bytes: 256
const lines=readlines(open("/dev/fd/0"))
let
    state=0
    global input
    input()=lines[state+=1]
end
int(s::String)=parse(Int32,s)
intSub(s::SubString{String})=parse(Int32,s)
intLine()=map(intSub,split(input()))
function main()
    x=int(input())
    println(x==3||x==5||x==7 ? "YES" : "NO")
end
main()

Measured memory_bytes: 114852
/*********************************
                                                        *****          All is Well          *********
                                                        ******       Mehedi Hasan       ******
                                                        *******    Dept of ICE,IU           ****
                                                        *****************************/
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,m,i,j,c=0,ans,ans1,co,x[200005],y[200005];
  map<int,int>mp;
cin>>n>>m;
for(i=0;i<m;i++){
    cin>>x[i]>>y[i];
    if(x[i]==1)

      mp[y[i]]=1;
}

for(i=0;i<m;i++){
    if(y[i]==n){
        if(mp[x[i]]==1)
            c++;
    }
}
if(c==0)
    cout<<"IMPOSSIBLE"<<endl;
else
    cout<<"POSSIBLE"<<endl;
  return 0;
}



Measured memory_bytes: 11136
/**
 * @author torith
 * @date 2018-11-06
 */

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int N; cin >> N;
    vector<int> a;
    for (int i = 0; i < N; ++i) {
        int t; cin >> t;
        a.push_back(t);
    }

    sort(a.begin(), a.end());

    ll ans = 1e18;
    for (int i = -100; i <= 100; ++i) {
        ll tmp = 0;
        for(auto & sa : a){
            tmp += pow(sa-i,2);
        }
        ans = min(ans, tmp);
    }

    cout << ans << "\n";

    return 0;
}



Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations,product#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def binr(x): return bin(x)[2:]
def bitcount(x): #xは64bit整数
    x= x - ((x >> 1) & 0x5555555555555555)
    x= (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x= (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x+= (x >> 8); x+= (x >> 16); x+= (x >> 32) 
    return x & 0x7f

def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列


    if 400<=N<600:
        print('8')
    elif N<800:
        print(7)
    elif N<1000:
        print(6)
    elif N<1200:
        print(5)
    elif N<1400:
        print(4)
    elif N<1600:
        print(3)
    elif N<1800:
        print(2)
    elif N<2000:
        print(1)




if __name__ == "__main__":
    main()

Measured memory_bytes: 72708
#include <stdio.h>

int main (){
	
	char s[25];
	scanf ("%[^\n]", &s);
	
	for (int i= 0; i < s[i]; i++  ) {
		if ( s[i] == ','){
			printf (" ");
		}
		else {
			printf ("%c", s[i]);
		}
	}
	
	
	puts ("");
	return 0;
}

Measured memory_bytes: 1588
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define endl "\n" 
#define p pair<int, int>
#define arrinp(i, a, start, end); for(ll i = start; i <= end; i++) cin >> a[i];
#define arrout(i, a, start, end); for(ll i = start; i <= end; i++) cout << a[i] << " ";
#define swap(a, b) {a = a + b; b = a - b; a = a - b;
#define forfront(i, start, end) for(ll i = start; i <= end; i++)
#define forback(i, start, end) for(ll i = start; i >= end; i--)
#define out(x) cout << x << " "
#define outline(x) cout << x << endl;
#define sortvector(v) sort(v.begin(), v.end());
#define sortvectorrev(v) sort(v.rbegin(), v.rend());
int main()
{
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    ll *a = (ll *)malloc(1e7*sizeof(ll));
    for(int i = 1; i <= n; i++)
    {
        for(int j = i; j <= n; j+=i)
        {
            a[j - 1]++;
        }
    }    
    ll maxsum = 0;
    for(ll i = 1; i <= n; i++)
    {
        maxsum += i*a[i - 1];
    }
    outline(maxsum);
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int& ai : a) {
    cin >> ai;
  }

  int all = 0;
  for (int ai : a) {
    all ^= ai;
  }

  for (int i = 0; i < N; ++i) {
    int ret = a[i] ^ all;
    cout << ret;
    if (i != N - 1)
      cout << " ";
    else
      cout << endl;
  }

  return 0;
}

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

int main(void)
{
    int N;
    string S;
    int K;

    cin >> N >> K >> S;

    S.at(K - 1) -= ('A' - 'a');
    cout << S << endl;
    return (0);
}

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

int main(){
    char temp;
    int c;
    cin >> temp;
    c = temp - 'A';
    
    switch(c){
        case 'A' - 'A':
            cout << "T\n";
            break;
        case 'T' - 'A':
            cout << "A\n";
            break;
        case 'C' - 'A':
            cout << "G\n";
            break;
        case 'G' - 'A':
            cout << "C\n";
            break;
        defalst:
            break;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    int a, b, c[5], ans = 0;
    cin >> a >> b;
    for(int i = a; i <= b; i++){
        for(int j = 0; j < 5; j++){
            int k = i / pow(10, j);
            c[j] = k % 10;
        }
        if(c[4] == c[0] && c[3] == c[1]) ans += 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
let swap a x y =
  let temp = a.(x) in
  a.(x) <- a.(y);a.(y) <- temp
;;
let () =
  let rec generate n a q =
    if n = 1 then Queue.push (Array.copy a) q
    else
      let rec loop i =
        generate (n-1) a q;
        if i = (n-1) then ()
        else
          begin
            if n mod 2 = 0 then
              swap a i (n-1)
            else
              swap a 0 (n-1)
           ;loop (i+1)
          end
      in loop 0
  in  
  let get_op i = match i with
    0 -> "+"
    |1 -> "-"
    |2 -> "*"
    |_ -> "undefined"
  in  let calc a b c d =
    let ops = [|(+);(-);( * )|] in
    let rec loop = function
      (-1, 2, 2) -> (0,"","","")
    | (i,j,k) -> if j = -1 then loop (i-1,2,2)
                 else if k = -1 then loop (i, j-1, 2)
                 else if (ops.(k) (ops.(j) (ops.(i) a b) c) d) = 10 then (1,get_op i,get_op j,get_op k)
                 else if (ops.(j) (ops.(i) a b) (ops.(k) c d)) = 10 then (2,get_op i,get_op j,get_op k)
                 else loop (i,j,k-1)
    in loop (2,2,2)
  in
  let rec read () =
    let (w,x,y,z) = Scanf.scanf "%d %d %d %d\n" (fun w x y z -> (w,x,y,z)) in
    if w = 0 then ()
    else
      begin
        let q = Queue.create () in
        generate 4 [|w;x;y;z|] q;
        let rec loop () =
          if Queue.is_empty q then Printf.printf "0\n"
          else
            begin
              let a = Queue.pop q in
              let (n,op1,op2,op3) = calc a.(0) a.(1) a.(2) a.(3) in
              if n = 1 then
                Printf.printf "(((%d %s %d) %s %d) %s %d)\n" a.(0) op1 a.(1) op2 a.(2) op3 a.(3)
              else if n = 2 then
                Printf.printf "((%d %s %d) %s (%d %s %d))\n" a.(0) op1 a.(1) op2 a.(2) op3 a.(3)
              else
                loop ()
            end
        in loop ();
        read ()
      end
  in read ()
;;

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

int main(){
    int N,K; cin >> N >> K;
    vector<long double> P(N+1,0) , S(N+1,0);
    long double res=0;
    rep(i,N){
        double x; cin >> x;
        P[i]=(1+x)/2;
        S[i+1]=S[i]+P[i];
    }
    for(int i=0;i+K<=N;i++){
        res = max(res, (S[i+K]-S[i]) );
    }

    cout << fixed << setprecision(15) << res << endl; 
}

Measured memory_bytes: 9536
#include<iostream>
//#include<algorithm>
using namespace std;
int m,n,book[100];
bool ok(int x){
  int h=0,d=1;
  for(int i=0;i<n;i++){
    h += book[i];
    if(h>x){
      d++;
      if(d>m) return false;
      h = 0;
      i--;
    }
  }
  return true;
}
int main(){
  while(cin>>m>>n){
    int max=1500000,min=0,s;
    if(m==0&&n==0) break;
    for(int i=0;i<n;i++) cin >> book[i];
    /*if(m>=n){
      sort(book,book+n,greater<int>());
      cout << book[0] << endl;
      }
      else{*/
      while(1){
	s = (max + min) / 2;
	if(ok(s)) max = s;
	else min = s+1;
	if(min==max){
	  cout << max << endl;
	  break;
	}
      }
    }
  //}
  return 0;
}

Measured memory_bytes: 1160
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
using namespace std;

int main(){
  int n,C;
  cin >> n >> C;
  int s[n], t[n], c[n];
  for(int i = 0; i < n; i++){
    cin >> s[i] >> t[i] >> c[i];
  }
  int channels[200002] = {};
  for(int i = 0; i < C; i++){
    int temp[200002] = {};
    for(int j = 0; j < n; j++){
      if(c[j]-1==i){
        temp[s[j]*2-1]++;
        temp[t[j]*2]--;
      }
    }
    for(int j = 1; j < 200002; j++){
      temp[j] += temp[j-1];
    }
    for(int j = 0; j < 200002; j++){
      if(temp[j]>0) channels[j]++;
    }
  }
  int ans = channels[0];
  for(int i = 1; i < 200002; i++){
    if(channels[i] > ans) ans = channels[i];
  }
  cout << ans << endl;
}


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

typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define MAX 77

ll mod=1e9+9;

ll H,W,N;
ll B[MAX][MAX];

ll tmp[MAX][MAX];
void mul(ll a[MAX][MAX],ll b[MAX][MAX]){
  for(int i=0;i<W;i++)
    for(int j=0;j<W;j++)
      tmp[i][j]=0;
  

  for(int i=0;i<W;i++){
    for(int k=0;k<W;k++){  
      for(int j=0;j<W;j++){
        tmp[i][j]+=(a[i][k]*b[k][j]);
        tmp[i][j]%=mod;
      }
    }
  }
  for(int i=0;i<W;i++)
    for(int j=0;j<W;j++)
      a[i][j]=tmp[i][j];
}


ll nans[MAX];
ll ans[MAX];
          
ll met[MAX][MAX];
void mpow(ll a[MAX][MAX],ll n){
  while(n){
    if(n&1LL){
      for(int i=0;i<W;i++){
        nans[i]=0;
        for(int j=0;j<W;j++){
          nans[i]+=(a[i][j]*ans[j]);
          nans[i]%=mod;
        }
      }

      for(int i=0;i<W;i++)ans[i]=nans[i];
    }
    mul(a,a);
    n=(n>>1LL);
  }
  for(int i=0;i<W;i++)
    for(int j=0;j<W;j++)
      a[i][j]=met[i][j];
}

int main(){
  for(int tc=1;;tc++){
    scanf("%lld %lld %lld",&W,&H,&N);
    
    if(W==0&&H==0&&N==0)break;
    
    vector<ll> v;
    unordered_map< ll , vector<ll> >G;

    memset(ans,0,sizeof(ans));
    ans[0]=1;

    memset(B,0,sizeof(B));
    for(int i=0;i<W;i++){
      if(i+1<W)B[i][i+1]++;
      B[i][i]++;
      if(i-1>=0)B[i][i-1]++;
    }
    

    for(int i=0;i<N;i++){
      ll x,y;
      cin>>x>>y;
      v.push_back(y);
      G[y].push_back(x);
    }

    v.push_back(H);
    sort(v.begin(),v.end());
    v.erase( unique(v.begin(),v.end()) , v.end() );

    ll C[MAX][MAX];

    
    ll last=1;
    for(int I=0;I<(int)v.size();I++){
      ll h=v[I];
      ll dist=h-last;


      for(int i=0;i<W;i++)
        for(int j=0;j<W;j++)
          C[i][j]=B[i][j];

      mpow(C,dist);

      
      last=h;

      if(G.count(h)==0)continue;
      for(int j : G[h] ){
        ans[j-1]=0;
      }
    }
    cout<<"Case "<<tc<<": "<<ans[W-1]<<endl;
  }
  return 0;
}

Measured memory_bytes: 3348
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    N=int(input())
    A=[0]+list(map(int,input().split()))
    ans=[0]*(N+1)
    s=[0]*(N+1)

    for i in reversed(range(1,N+1)):
        cnt=0
        for j in range(i+i,N+1,i):
            cnt^=s[j]
        if (A[i]==1 and cnt!=1) or (A[i]==0 and cnt!=0): s[i]=1
    
    print(sum(s))
    for i in range(1,N + 1):
        if s[i]==1:
            print(i)






    

resolve()

Measured memory_bytes: 72668
import math

n, d = map(int, input().split())
x = []
cnt = 0
sum = 0
for _ in range(n):
    tmp = list(map(int, input().split()))
    x.append(tmp)

for i in range(n):
    for j in range(i + 1, n):
        sum = 0
        for k in range(d):
            sum += (x[i][k] - x[j][k]) ** 2
        distance = math.sqrt(sum)
        if distance.is_integer():
            cnt += 1

print(cnt)


Measured memory_bytes: 3316
import heapq
import sys
input = sys.stdin.readline

N, Q = (int(i) for i in input().split())
L = [0] * 2 * N
for i in range(N):
    S, T, X = (int(i) for i in input().split())
    L[2 * i] = (S-X, X, 1)
    L[2 * i + 1] = (T-X, X, 0)

L.sort(reverse=True)

Xs = set([])
XH = []
heapq.heapify(XH)
for i in range(Q):
    D = int(input())
    ans = 0
    while True:
        if L:
            t, X, f = L.pop()
            if t <= D:
                if f == 1:
                    Xs.add(X)
                    heapq.heappush(XH, X)
                else:
                    Xs.remove(X)
            else:
                L.append((t, X, f))
                break
        else:
            break
    if Xs:
        while XH[0] not in Xs:
            X = heapq.heappop(XH)
        print(XH[0])
    else:
        print("-1")

Measured memory_bytes: 67524
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner((os.Stdin))

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	l := nextLine()
	i, e := strconv.Atoi(l)
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	N, H := nextInt(), []int{}
	for i := 0; i < N; i++ {
		H = append(H, nextInt())
	}

	fmt.Printf("%d\n", ABC116C(N, H))
}

// ABC116C ...
func ABC116C(N int, H []int) int {
	res := 0

	c := []int{}
	for i := 0; i < len(H); i++ {
		c = append(c, 0)
	}

	l := 0
	for l != N-1 || c[N-1] < H[N-1] {
      	did := false
		for r := l; r < len(H); r++ {
			if H[r] > c[r] {
				c[r]++
              	did = true
			} else {
				break
			}
		}
		if did {
			res++
		}

		for i := l; i < len(H); i++ {
			if H[i] > c[i] || i == len(H)-1 {
				l = i
				break
			}
		}
	}

	return res
}


Measured memory_bytes: 1788
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<map>
#include<set>
#include<functional>
#include<queue>
#define int long long
using namespace std;

signed main() {
	char a, b, c;
	cin >> a >> b >> c;
	string d;
	d += a;
	d += b;
	d += c;
	int e = stoi(d);
	if (e % 4) {
		puts("NO");
	}
	else {
		puts("YES");
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n, c, k;
  cin >> n >> c >> k;
  vl t(n);
  rep(i, n) cin >> t[i];
  sort(all(t));
  ll ans = 0, now = -1e18, cnt = 0;
  rep(i, n) {
    if(cnt >= c || t[i] - now > k) {
      ans++;
      now = t[i];
      cnt = 1;
    } else
      cnt++;
  }
  cout << ans << endl;
}

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

int main() {
    int N, M;
    cin >> N >> M;
    int x[M], y[M];
    vector<int> adj[N];
    for (int i = 0; i < M; i++) {
        cin >> x[i] >> y[i];
        x[i]--;
        y[i]--;
        adj[x[i]].push_back(y[i]);
    }
    int indeg[N]{};
    int flag[N]{};
    
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < adj[i].size(); j++) {
            int u = adj[i][j];
            indeg[u]++;
        }
    }
    deque<int> q;
    vector<int> id;
    for (int i = 0; i < N; i++) {
        if (indeg[i] == 0 && flag[i] == 0) {
            q.push_back(i);
            while (!q.empty()) {
                int u = q.front();
                id.push_back(u);
                q.pop_front();
                flag[u] = 1;
                for (int j = 0; j < adj[u].size(); j++) {
                    int v = adj[u][j];
                    indeg[v]--;
                    if (indeg[v] == 0 && flag[v] == 0) {
                        flag[v] = 1;
                        q.push_back(v);
                    }
                }
            }
        }
    }
    
    int ans = 0;
    int k = 0;
    int dp[N]{};
    reverse(id.begin(), id.end());
    for (int i : id) {
        for (int j = 0; j < adj[i].size(); j++) {
            dp[i] = max(dp[i], dp[adj[i][j]] + 1);
        }
        ans = max(ans, dp[i]);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 8184
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int r = sc.nextInt();
		int d = sc.nextInt();
		int x2000 = sc.nextInt();
		int xi = x2000;

		for (int i = 1; i <= 10; i++) {
			xi = r * xi - d;
			System.out.println(xi);
		}

		sc.close();
	}

}


Measured memory_bytes: 21844
#include <iostream>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  float all = 0.0f;
  for (int i = 1; i <= N; i++) {
    float A;
    cin >> A;
    all += 1/A;
  }
  cout << 1/all << endl;
}

Measured memory_bytes: 256
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;

template<typename T>
vector<T> make_vec_nd(T init, size_t size) {
    return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, size_t size, Args... rest) {
    auto inner = make_vec_nd(init, rest...);
    return vector<decltype(inner)>(size, inner);
}

int main() {
    ll N;
    cin >> N;
    auto values = make_vec_nd((ll)0, N, 3);
    for (ll i = 0; i < N; i++) {
        for (ll a = 0; a < 3; a++) {
            ll v;
            cin >> v;
            values[i][a] = v;
        }
    }
    auto dp = make_vec_nd(numeric_limits<ll>::min(), N, 3);
    for (ll act = 0; act < 3; act++) {
        dp[0][act] = values[0][act];
    }
    for (ll day = 0; day < N - 1; day++) {
        for (ll act = 0; act < 3; act++) {
            for (ll act_diff = 1; act_diff <= 2; act_diff++) {
                ll next_act = (act+act_diff)%3;
                dp[day+1][next_act] = max(dp[day+1][next_act], dp[day][act] + values[day+1][next_act]);
            }
        }
    }
    cout << max(dp[N-1][0], max(dp[N-1][1], dp[N-1][2])) << endl;
}



Measured memory_bytes: 11136
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
    int h,a;
    scanf("%d%d",&h,&a);
    if(h%a==0)
    {
        printf("%d",h/a);
    }
    else
    {
        printf("%d",h/a+1);
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<bitset>
using namespace std;
int W[10] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512};

main(){
    int weight;
    bitset<10> B;

    while ( cin >> weight ){
	B = weight;
	bool isFirst = true;
	for ( int i = 0; i < 10; i++ ) {
	    if ( B[i] ) {
		if ( isFirst ) isFirst = false;
		else cout << " ";
		cout << W[i];
	    }
	}
	cout << endl;
    }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<31)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
//int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int n,m;

int main(){
	while(1){
		cin>>n>>m;
		if(n==0&&m==0)break;
		int a[n]={};
		int plate=m;
		while(1){
			for(int i=0;i<n;i++){
				if(plate){
					plate--;
					a[i]++;
				}else{
					plate+=a[i];
					a[i]=0;
				}
				if(a[i]==m){
					cout<<i<<endl;
					goto A;
				}
			}
		}
		A:;
	}
}


Measured memory_bytes: 3004
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto np = readln.split.to!(int[]);
    auto N = np[0];
    auto P = np[1];
    int even, odd;
    foreach (a; readln.split.to!(int[])) {
        if (a%2 == 0)  {
            ++even;
        } else {
            ++odd;
        }
    }
    long r = 2L^^even;
    if (odd == 0) {
        writeln(P == 1 ? 0 : r);
    } else {
        writeln(r * 2^^(odd-1));
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int H, W;
string grid[10];
bool marked[10][10];

bool solve() {
    int curi = 0, curj = 0;
    while (true) {
        marked[curi][curj] = true;
        if (grid[curi][curj] != '#')
            return false;
        if (curi == H - 1 && curj == W - 1)
            break;
        bool movei = curi + 1 < H && grid[curi + 1][curj] == '#';
        bool movej = curj + 1 < W && grid[curi][curj + 1] == '#';
        if (movei && movej)
            return false;
        if (!movei && !movej)
            return false;
        if (movei)
            curi++;
        if (movej)
            curj++;
    }
    for (int i = 0; i < H; i++)
        for (int j = 0; j < W; j++)
            if (grid[i][j] == '#' && !marked[i][j])
                return false;
    return true;
}

int main() {
    cin >> H >> W;
    for (int i = 0; i < H; i++)
        cin >> grid[i];

    if (solve())
        cout << "Possible" << endl;
    else
        cout << "Impossible" << endl;
}


Measured memory_bytes: 256
open Printf
open Scanf

let id x = x

let solve n k =
  let ht = Hashtbl.create n in
  for i = 1 to k do
    let d = scanf "%d " id in
    for j = 1 to d do
      scanf "%d " @@ fun x -> Hashtbl.replace ht x true
    done
  done;
  n - Hashtbl.length ht

let () =
  scanf "%d %d " solve |> printf "%d\n"


Measured memory_bytes: 5820
import sys
sys.setrecursionlimit(10**6)
n = int(input())
readline = sys.stdin.readline
A = [int(i)-1 for i in readline().split()]
B = [int(i) for i in readline().split()]
C = [int(i) for i in readline().split()]

ans = 0
a_prev = -100
for a in A:
    ans += B[a]
    if a == a_prev+1:
        ans += C[a-1]
    a_prev = a
print(ans)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define db(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl
#define ll long long
#define ld long double
#define pll pair<ll, ll>
#define MOD 1000000007
using namespace std;
const long long INF = 3*1e18;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll a, b, c;
    cin >> a >> b >> c;
    if(c - a - b <= 0) cout << "No\n";
    else{
        ll rhs = (c - a - b) * (c - a - b);
        ll lhs = 4 * a * b;
        if(lhs < rhs) cout << "Yes\n";
        else cout << "No\n";
    } 
}

Measured memory_bytes: 256
//Double Factorial

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll, string>;
using garph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    int n;cin>>n;
    if(n%2==1){
        cout<<0<<nnn;
    }else{
        int ans = 0;
        int go = 1;
        rep(i,0,25){
            ans+=n/(go*10);
            go*=5;
        }
        cout<<ans<<nnn;
    }
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
int main(){
for(int i=0;;i++){
int a,s;
cin>>a>>s;
if(a==0) break;
for(int j=0;j<a;j++){
for(int k=0;k<s;k++){
if(j%2==0 && k%2==0){
cout<<'#';
}
else if(j%2==0 && k%2==1){
cout<<'.';
}
else if(j%2==1 && k%2==0){
cout<<'.';
}
else if(j%2==1 && k%2==1){
cout<<'#';
}

}
cout<<endl;
}
  cout<<endl;
}
}


Measured memory_bytes: 3084
#include <iostream>
#include <fstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdio>
#include <stack>

using namespace std;

int main()
{
	int D, N; cin >> D >> N;
	int ans = 0;

	if (D == 0) ans = N;
	if (D == 1) ans = 100 * N;
	if (D == 2) ans = 10000 * N;

	//Nが100だと割り切れてしまうので101を使う
	if (N == 100) {
		if (D == 0) ans = N+1;
		if (D == 1) ans = 100*(N+1);
		if (D == 2) ans = 10000*(N+1);
	}	
	cout << ans << endl;

	return 0;
}

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

int main(){
    int memo[10][10] = {};
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++){
        int ma = to_string(i)[0]-'0';
        int mi = i%10;
        memo[ma][mi]++;
    }
    ll ans = 0;
    for(int i = 1; i <= n; i++){
        int ma = to_string(i)[0]-'0';
        int mi = i%10;
        ans += memo[mi][ma];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define reg register
typedef long long ll;
using namespace std;
const int MN=1e5+5;
int to[MN<<1],nxt[MN<<1],deg[MN],h[MN],cnt;
inline void ins(int s,int t){
	to[++cnt]=t;nxt[cnt]=h[s];h[s]=cnt;deg[t]++;
	to[++cnt]=s;nxt[cnt]=h[t];h[t]=cnt;deg[s]++;
}
bool t[MN],vis[MN];
char ch[MN];
int n,ans,sum,que[MN],f[MN];
void dfs(int st,int fa=0){
	sum+=deg[st];sum+=(deg[st]=(!t[st])^(deg[st]&1));
	for(reg int i=h[st];i;i=nxt[i])
		if(!vis[to[i]]&&to[i]!=fa){
			dfs(to[i],st);ans=min(ans,f[st]+f[to[i]]);
			f[st]=min(f[st],f[to[i]]-2*deg[st]);
		}
}
int main(){
	scanf("%d",&n);reg int he=0,ta=0;
	for(reg int i=1,s,t;i<n;i++)scanf("%d%d",&s,&t),ins(s,t);
	scanf("%s",ch+1);
	for(reg int i=1;i<=n;i++)t[i]=(ch[i]=='B');
	for(reg int i=1;i<=n;i++)if(deg[i]<2&&t[i])que[ta++]=i;
	while(he<ta){
		reg int v=que[he++];vis[v]=true;
		for(reg int i=h[v];i;i=nxt[i])if((--deg[to[i]]==1)&&t[to[i]])que[ta++]=to[i];
	}
	if(ta==n)return 0*puts("0");
	for(reg int i=1;i<=n;i++)
		if(!vis[i]){
			dfs(i);return 0*printf("%d\n",sum+ans);
		}
	return 0;
}

Measured memory_bytes: 7296
import std.stdio;
import std.algorithm;
import std.conv;
import std.string;

void main()
{
	auto tokens = split(chomp(readln()));
	auto x1   = to!int(tokens[0]);
	auto y1   = to!int(tokens[1]);
	auto x2   = to!int(tokens[2]);
	auto y2   = to!int(tokens[3]);

	int dx = x2 - x1;
	int dy = y2 - y1;
	int x3 = x2 + -1 * dy;
	int y3 = y2 + dx;
	int dx2 = x3 - x2;
	int dy2 = y3 - y2;
	int x4 = x3 + -1 * dy2;
	int y4 = y3 + dx2;
	
	writeln(x3, " ", y3, " ", x4, " ", y4);
	stdout.flush();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vi  = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(int i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
const ll INF = 1000000000000000;
const ll MOD = 1000000007;
const double PI = acos(-1);
//||
#define DBG(a,b,c,d) //cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl
//DBG("","","","");

int main(){
	IO_STREAM;
	int N;	cin>>N;
	int ans;
	ans=N%1000;
	if(ans) ans=1000-ans;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3644
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define se second
#define pi 2*acos(0)
#define PI 3.14159265358979323846264338

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

const int N = 100010;
const int MX = 123456;
const int mod = (int)1e9 + 7;
const int base = 97;
const ull BS1 = 10000019ULL;
const int INF = (1 << 29);

template < class T > inline void fastScan(T &x){
    register char c = getchar();
    int neg = 0; x = 0;
    for(   ; (c < 48 || c > 57) && (c != '-'); c = getchar());
    if(c == '-') { neg = 1; c = getchar(); }
    for(   ; c > 47 && c < 58; c = getchar()){
        x = (x << 1) + (x << 3) + c - 48;
    }
    if(neg) x = -x;
}

int inp[N + N];

int main(){
  int n;
  fastScan(n);
  for(int i = 1; i <= n; i++){
    fastScan(inp[i]);
  }
  int d = 0, curr = 1;
  for(int i = 1; i <= n; i++){
    if(inp[i] == curr){
      curr++;
    } else {
      d++;
    }
  }
  if(d >= n){
    d = -1;
  }
  printf("%d\n", d);
  return 0;
}


Measured memory_bytes: 1024
#!/usr/bin/python

def main():
    K = int(input())
    if K % 2 == 0:
        k = K/2 * K/2
    else:
        k = int(K/2)*(int(K/2)+1)
    print(int(k))
    
        

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
ll ok[12345678];
signed main() {
	for (int z = 0; z < 11; z++) {
		ll n, m, a, ans = 0; cin >> n >> m;
		if (n == 0 && m == 0) { return 0; }
		for (int h = 0; h < n; h++) {
			cin >> ok[h];
		}
		vector<ll> v;
		//最後の二本
		for (int h = 0; h <= n; h++) {
			for (int i = 0; i <= n; i++) {
				v.push_back(ok[h] + ok[i]);
			}
		}
		sort(v.begin(), v.end());
		//最初の二本+最後の二本の二分探索
		for (int h = 0; h <= n; h++) {
			for (int i = 0; i <= n; i++) {
				ll sum = ok[h] + ok[i];
				if (sum > m) { continue; }
				ll ng = lower_bound(v.begin(), v.end(), m - sum) - v.begin();
				if (ng == 0) { continue; }
				ans = max(ans, sum + v[ng - 1]);
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 18940
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
using ll = long long;
const ll mod = 1000000007;
const ll INF = 100000000000000000LL;
signed main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(abs(a-c)<=d||(abs(a-b)<=d&&abs(b-c)<=d))cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
'''
????????£????????????????????????

'''

import queue
v,e,s=map(int,input().split())
edge=[]
inf =1000000100
for i in range(v):
    edge.append([])

for i in range(e):
    vs,vt,d=map(int,input().split())
    edge[vs].append((vt,d))
    
dis=[]
for i in range(v):
    dis.append(inf)

dis[s]=0

q = queue.PriorityQueue()
q.put((0,s))

'''
while(not q.empty()):
    now=q.get()

    nowv=now[1]
    for (vt,d) in edge[nowv]:
        if dis[vt]>dis[nowv]+d:
            dis[vt]=dis[nowv]+d
            q.put((dis[vt],vt))
'''
finished=0
while(finished<v and not q.empty()):
    now=q.get()
    nowv=now[1]
    if now[0]>dis[nowv]: continue
    for (vt,d) in edge[nowv]:
        if dis[vt]>dis[nowv]+d:
            dis[vt]=dis[nowv]+d
            q.put((dis[vt],vt))
    finished+=1       

for i in range(v):
    if dis[i]>=inf:
        print("INF")
    else:
        print(dis[i])

Measured memory_bytes: 90452
public class Main{

	public static void main(String[] args) {
		java.util.Scanner scanner = new java.util.Scanner (System.in);
		int A=scanner.nextInt() ;
		int B=scanner.nextInt() ;
		int C=scanner.nextInt() ;
		if(A<=C&&B>=C){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}

}

Measured memory_bytes: 23252
/*
Author : Vidish Joshi
*/

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

//#include<boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

#define ll long long int
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define mod 1000000007
#define FOR1(i, m, n) for(i=m; i<n; i++)
#define FOR2(i, n, m) for(i=n-1; i>=m; i--)
#define re(v) ll v; cin>>v
#define mod 1000000007
#define mod2 998244353
#define mp make_pair
#define pb push_back
#define fill(a) memset(a, 0, sizeof(a))
#define start ll t; cin>>t; while(t--)
#define br "\n"

int main(){
    FIO;
    ll k; cin>>k;
    ll a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
   

    cout<<a[k-1]<<br;

    

    return 0;
}


Measured memory_bytes: 256
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		PriorityQueue <Integer>d=new PriorityQueue<Integer>(new MyComparator());
		int N=stdIn.nextInt();
		int M=stdIn.nextInt();
		int A[]=new int[N];
		int z=0;
		long ans=0;
		while(z<N){
			int a=stdIn.nextInt();
			d.add(a);
			z++;
		}z=0;
		while(z<M){
			int a=d.poll();
			a/=2;
			d.add(a);
			z++;
		}z=0;
		while(z<N){
			ans+=d.poll();
			z++;
		}
		System.out.println(ans);
	}
}
class MyComparator implements Comparator {
	 
    public int compare(Object obj1, Object obj2) {
         
        int num1 = (int)obj1;
        int num2 = (int)obj2;
         
        if(num1 < num2) {
            return 1;
        } else if(num1 > num2) {
            return -1;
        } else{
            return 0;
        }
    }
}

Measured memory_bytes: 62512
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>
#include <fstream>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using ll = long long;
using pLL = std::pair<ll, ll>;
#define SORT(v) std::sort(v.begin(), v.end())
int gcd(int x, int y) {
    if (x < y)gcd(y, x);
    int r;
    while ((r=x%y)) {
        x = y;
        y = r;
        
    }
    return y;
}
ll LCM(int a, int b) {
    ll r = gcd(a, b);
    return (ll)a * (ll)b / r;
}
int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    
    int a, b;
    cin >> a >> b;
    cout << LCM(a, b) << endl;
    return 0;
}


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

using namespace std;

int main() {
    int N, X;
    cin >> N >> X;
    vector<int> A(N);
    int sum = 0;
    for (size_t i = 0; i < N; i++)
    {
        cin >> A.at(i);
        sum += A.at(i);
    }
    sort(A.begin(),A.end());
    X -= sum;
    int ans  = N + X/A.at(0);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3508