akhauriyash/Code-Regression huggingface dataset:
using System;

namespace abc138B
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            double[] a = new double[N];
            string[] str = Console.ReadLine().Split();
            for (int i = 0; i < N; i++)
            {
                a[i] = Double.Parse(str[i]);
            }
            double P = 0;
            for(int i = 0; i < N; i++)
            {
                P = P + (1 / a[i]);
            }
            double Q = 1 / P;
            Console.WriteLine(Q);
        }
    }
}


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

int main() {

    int L, R;
    cin >> L >> R;

    int d;
    cin >> d;

    int cnt = 0;
    FOR(i, L, R+1) if(i%d == 0) cnt++;

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3632
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use proconio::{input, marker::*};
use superslice::*;
fn main() {
    input! {
        s: String,
    }

    let mut dp = vec![0; 2019];
    dp[0] = 1;
    let mut ans = 0;
    let mut rem = 0;
    let mut ten = 1;
    for i in (0..s.len()).rev() {
        let ss = &s[i..i+1];
        let v = ten * ss.parse::<usize>().unwrap() + rem;
        rem = v % 2019;
        ten *= 10;
        ten %= 2019;
        ans += dp[rem];
        dp[rem] += 1;
    }

    println!("{}", ans);
}


Measured memory_bytes: 2448
#include<bits/stdc++.h>
using namespace std;
    int n, k; int t[200000];
    int sa[200000];
int main(){
    scanf("%d%d", &n, &k);
    for(int i = 0; i < n; i++)
        scanf("%d", &t[i]);
    for(int i = 1; i < n; i++){
        sa[i-1] = t[i]-t[i-1]-1;
    }
    sort(sa, sa+n-1);
    int sum = t[n-1]+1-t[0];
    //printf("%d\n", sum);
    //cout << sa[0] <<"\t"<< sa[1] <<"\t"<< sa[2] << endl;
    for(int i = 0; i < k-1; i++){
    //    printf("%d\n", sa[n-2-i]);
        sum -= sa[n-2-i];
    }
    printf("%d\n", sum);
    return 0;

}


Measured memory_bytes: 4068
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    long double l;
    cin >> l;
    long double a = l/3;

    long double ans = a * a * a;
    printf("%.9Lf\n",ans);

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
#define MAX 505
#define MOD 1000000007

typedef long long ll;

int main(int, char**)
{
    ll x;
    cin >> x;

    int count = 0;
    for (ll n = 100; n < x; n += n / 100) count++;

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

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

char table[9][6] = {
	{'.',',','!','?',' '} , // 5
	{'a','b','c','0','0'} ,
	{'d','e','f','0','0'} ,
	{'g','h','i','0','0'} ,
	{'j','k','l','0','0'} ,
	{'m','n','o','0','0'} ,
	{'p','q','r','s','0'} , // 4
	{'t','u','v','0','0'} ,
	{'w','x','y','z','0'} // 4
} ;

int main(){
	
	int n ;
	string s ;
	cin >> n ;
	for( int i=0 ; i<n ; i++ ){
		cin >> s ;
		for( int j=0 ; j<s.size() ; j++ ){
			int cnt = 0 , p = 3 ;
			char a = s[j] ;
			if( a == '0' ) continue ;
			if( a == '1' ) p = 5 ;
			if( a == '7' || a == '9' ) p = 4 ;
			for( j+=1 ; j<s.size() ; j++ ){
				if( s[j] == a ) cnt++ ;
				if( s[j] == '0' ) break ;
			}
			cout << table[a-'0'-1][cnt%p] ;
		}
		cout << endl ;
	}
	
return 0 ;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int main(){
  int n;
  cin >> n;
  vector<vector<int>> v(n,vector<int>(26,0));
  
  rep(i,n){
    string s;
    cin >> s;
    rep(j,s.size()){
      v[i][s[j] - 'a']++;
    }
  }
  
  int INF = 1 << 30;
  vector<int> v2(26,INF);
  rep(j,26){
    rep(i,n){
      v2[j] = min(v2[j], v[i][j]);
    }
  }
  
  rep(i,26){
    if(v2[i] != INF){
      rep(j,v2[i]){
        char ans = 'a' + i;
        cout << ans;
      }
    }
  }
  
  return 0;
}

Measured memory_bytes: 256
//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <vector>

namespace n91 {

using i8 = std::int_least8_t;
using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u8 = std::uint_least8_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

class rep {
  const usize f, l;

public:
  class itr {
    friend rep;
    usize i;
    constexpr itr(const usize x) noexcept : i(x) {}

  public:
    void operator++() noexcept { ++i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  constexpr rep(const usize first, const usize last) noexcept
      : f(first), l(last) {}
  constexpr itr begin() const noexcept { return itr(f); }
  constexpr itr end() const noexcept { return itr(l); }
};
class revrep {
  const usize f, l;

public:
  class itr {
    friend revrep;
    usize i;
    constexpr itr(usize x) noexcept : i(x) {}

  public:
    void operator++() noexcept { --i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  constexpr revrep(usize first, usize last) noexcept : f(--first), l(--last) {}
  constexpr itr begin() const noexcept { return itr(l); }
  constexpr itr end() const noexcept { return itr(f); }
};
template <class T> using vec_alias = std::vector<T>;
template <class T> auto md_vec(const usize n, const T &value) {
  return std::vector<T>(n, value);
}
template <class... Args> auto md_vec(const usize n, Args... args) {
  return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> constexpr T difference(const T &a, const T &b) {
  return a < b ? b - a : a - b;
}

} // namespace n91

#include <algorithm>
#include <iostream>
#include <string>
#include <utility>


namespace n91 {

void main_() {
  std::string s;
  std::cin >> s;
  const usize n = s.size();
  for (usize i = 0; i < n; i += 2) {
    s[i] ^= '0' ^ '1';
  }
  const usize c = std::count(s.cbegin(), s.cend(), '0');
  std::cout << std::min(c, n - c) << std::endl;
}

} // namespace n91

int main() {
  n91::main_();
  return 0;
}


Measured memory_bytes: 512
H, W, K = map(int, input().split())

S = [input() for _ in range(H)]

def calc(L):
    M = len(L)
    cnt = [0] * M
    ret = 0

    for w in range(W):
        for i, (t, b) in enumerate(zip(L, L[1:])):
            for j in range(t, b):
                if S[j][w] == '1':
                    cnt[i] += 1
        if max(cnt) > K:
            cnt = [0] * M
            ret += 1
            for i, (t, b) in enumerate(zip(L, L[1:])):
                for j in range(t, b):
                    if S[j][w] == '1':
                        cnt[i] += 1
        if max(cnt) > K:
            return 10**18

    return ret

ans = 10**18
for mask in range(1 << (H - 1)):
    L = [0] + [d + 1 for d in range(H - 1) if (mask & (1 << d)) > 0] + [H]
    ans = min(ans, len(L) - 2 + calc(L))
print(ans)


Measured memory_bytes: 49628
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String S = sc.nextLine();
    if("Sunny".equals(S)){
      System.out.println("Cloudy");
    }else if("Cloudy".equals(S)){
      System.out.println("Rainy");
    }else if("Rainy".equals(S)){
      System.out.println("Sunny");
    }
  }
}


Measured memory_bytes: 21588
# D

N = int(input())
a_list = list(map(int, input().split()))

def search(c):
    bar = N
    r = 0
    res_nega = 0
    dp_arr = [0]*(2*N+1)
    
    for i in range(N):
        dp_arr[bar] += 1
        if a_list[i] < c:
            r += dp_arr[bar]
            bar += 1
        else:
            r -= (dp_arr[bar-1])
            bar -= 1
        
        res_nega += r
    return res_nega

# binary search
a_sorted = sorted(a_list)

left = 0
right = N
mid = N // 2
C = N*(N+1) // 2

while True:
    if search(a_sorted[mid]) <= C // 2:
        if mid == N-1:
            break
        elif search(a_sorted[mid+1]) > C // 2:
            break
        else:
            left = mid
            mid = (mid + right) // 2
    else:
        right = mid + 1
        mid = (mid + left) // 2
        
print(a_sorted[mid])

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

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



Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
#include <queue>
#include <stack>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define drep(i, n) for(int i = n - 1; i >= 0; i--)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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 main() {
  string s;
  cin >> s;

  int flag = 1;
  rep (i, s.size()) {
    if (s[i] != 'B') {
      flag = 0;
      break;
    }
  }
  if (flag == 1) {
    P(0);
    return 0;
  }
  flag = 1;
  rep (i, s.size()) {
    if (s[i] != 'W') {
      flag = 0;
      break;
    }
  }
  if (flag == 1) {
    P(0);
    return 0;
  }

  int count = 0;
  rep (i, s.size()) {
    if (s[i] == 'B') {
      count++;
      int tmp = 0;
      for (int j = i + 1; j < s.size(); j++) {
        if (s[j] == 'B') tmp++;
        else break;
      }
      i += tmp + 1;
    }
  }
  int ans = count * 2 - 1;
  if (s[0] == 'W' && s[s.size() - 1] == 'W') ans++;
  if (s[0] == 'B' && s[s.size() - 1] == 'B') ans--;
  P(ans);
  return 0;
}


Measured memory_bytes: 512
/*
ID: tohoast1
TASK: transform
LANG: C++
*/
#include <bits/stdc++.h>
#include <bitset>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define speedup ios_base::sync_with_stdio(NULL)
#define fin freopen("transform.in", "r", stdin)
#define fout freopen("transform.out", "w", stdout)
#define FILENAME
#define PUBG push_back
#define p_b pop_back
#define mp make_pair
#define fi first
#define se second
#define cls clear
#define INF const int ci = 1e6 + 100
#define K_INF 1e9 + 7
#define time cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"

using namespace std;
typedef long long LL;
typedef long L;
typedef unsigned long long ULL;
typedef unsigned long UL;
typedef string STR;
LL a, b, k;

int main() {
    speedup;
    #ifdef FILENAMEs
        fin;
        fout;
    #endif // FILENAME
    cin.tie(0); cout.tie(0);
    cin >> a >> b >> k;
    if (a >= k) {
        cout << a - k << ' ' << b;
    }
    else {
        k -= a;
        cout << "0 " << max(LL(0), b - k);
    }
    ///time;
    return 0;
}


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

#define lli long long int
#define ld long double
#define DEFO(n) lli n = 0;
#define MAX_L lli max = 9000000000000000000;
#define MIN_L lli min = 9000000000000000000;
#define MAX_D ld max = 4500;
#define MIN_D ld min = -4500;
#define LLI(n) \
  lli n;       \
  cin >> n;
#define LD(n)  \
  ld n;        \
  cin > n;
#define LLIV(a, n)            \
  vector<lli> a(n);           \
  for (lli i = 0; i < n; i++) \
  {                           \
    cin >> a.at(i);           \
  };
#define LLIV2(a, b, n)            \
  vector<lli> a(n), b(n);           \
  for (lli i = 0; i < n; i++) \
  {                           \
    cin >> a.at(i) >> b.at(i);           \
  };
#define LDV(a, n)            \
  vector<ld> a(n);           \
  for (lli i = 0; i < n; i++) \
  {                           \
    cin >> a.at(i);           \
  };
#define STR(n) \
  string n;    \
  cin >> n;
#define SUM(n) accumulate(n.begin(), n.end(), 0);
#define SORT(n) sort(n.begin(), n.end());
#define REVE(n) reverse(n.begin(), n.end());
#define yes cout << "Yes" << endl; return 0;
#define no cout << "No" << endl; return 0;
#define C45(n) (n + 1) / 2
#define OUT(n) cout << n << endl;
#define SRC(n, c)                    \
  for (lli i = 0; i < s.size(); i++) \
  {                                  \
    if (s.at(i) == c)                \
    {                                \
      n++;                           \
    }                                \
  };
//こぴー
/*#define ZISYO(s, S)                  \
  for (lli i = 0; i < s.size(); i++) \
  {                                  \
    S.at(i) = s.at(i);               \
  }                                  \
  Sort(S) Reve(S) for (lli i = 0; i < s.size(); i++) { s.at(i) = S.at(i); };
*/

//素数
bool IsPrime(lli num)
{
  if (num < 2)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false;
  long double sqrtNum = sqrt(num);
  for (lli i = 3; i <= sqrtNum; i += 2)
  {
    if (num % i == 0)
      return false;
  }
  return true;
}
//各桁の和
lli KSum(lli n)
{
  lli sum = 0;
  if (n < 0)
    return 0;
  while (n > 0)
  {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

//数値反転
bool KReve(lli n)
{
  int reverse = 0;
  int remaind;
  int tmp = n;
  while (tmp != 0)
  {
    remaind = tmp % 10;
    reverse = reverse * 10 + remaind;
    tmp /= 10;
  }
  if (reverse == n) 
    return true;
  else
    return false;
}

int main(void)
{
  ios::sync_with_stdio(false);
  LLI(A) LLI(B) DEFO(flag)
  for(lli i = A;i <= B;i++) {
    if(KReve(i)==1) flag++;
  }
  OUT(flag)
}


Measured memory_bytes: 256
#include <iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
# define maxn 50
# define maxm 50
int main() {
  int n,m;
  long long a[maxn],b[maxn],c[maxm],d[maxm];
  cin>>n>>m;
  for (int i(0);i<n;i++){
    cin>>a[i]>>b[i];
  }
  for (int i(0);i<m;i++){
    cin>>c[i]>>d[i];
  }
  for (int i(0);i<n;i++){
    int minx(1000000000),mini(100);
    for (int j(0);j<m;j++){
      int dis=abs(a[i]-c[j])+abs(b[i]-d[j]);
      if (minx>dis){
        minx=dis;
        mini=j;
      }
    }
    cout<<mini+1<<endl;
  }
}


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

template <typename T> void chmax(T &x,const T &y)
{
	if(x<y)x=y;
}
typedef long long ll;
typedef unsigned int ui;
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)

int main()
{
	//freopen("1.in","r",stdin);
	int x,a,b;
	cin>>x>>a>>b;
	cout<<(x-a)%b;
}


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

int main(){
	std::string s;
	while(std::getline(std::cin,s)){
		while(s.find("the")==s.npos&&s.find("that")==s.npos&&s.find("this")==s.npos){
			for(int i=0;i<s.size();++i){
				if(s[i]>='a'&&s[i]<='y')s[i]++;
				else if(s[i]=='z')s[i]='a';
			}
		}
		std::cout<<s<<std::endl;
	}
	return 0;
}

Measured memory_bytes: 1176
import math
N, M = map(int,input().split())
P = [1]
for k in range(2,math.floor(math.sqrt(M))+1):
    if M % k == 0:
        P.append(k)
        P.append(M//k)
P = sorted(P)
if N == 1:
    print(M)
    exit(0)

ans = 1
for p in P:
    if p*N <= M:
        ans = p

print(ans)

Measured memory_bytes: 38768
n=int(input())
al=list('abcdefghijklmnopqrstuvwxyz')
d=[[0]*n for i in range(26)]
for i in range(n):
    s=list(input())
    for j in s:
        d[al.index(j)][i]+=1
ans=''
for i in range(26):
    m=min(d[i])
    for j in range(m):
        ans+=al[i]
print(ans)

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

using namespace std;

int n,a[100500],b[100500],c[100500],dpa[100500],dpb[100500],dpc[100500];

int main(){
     cin >> n;
     for(int i = 1; i <= n; i++){
     	cin >> a[i] >> b[i] >> c[i];
     }
     dpa[1] = a[1];
     dpb[1] = b[1];
     dpc[1] = c[1];
     for(int i = 2; i <= n; i++){
     	dpa[i] = max(dpb[i - 1],dpc[i - 1]) + a[i];
     	dpb[i] = max(dpa[i - 1],dpc[i - 1]) + b[i];
     	dpc[i] = max(dpa[i - 1],dpb[i - 1]) + c[i];
     }
     cout << max(dpa[n],max(dpb[n],dpc[n]));
	return 0;
}

Measured memory_bytes: 2560
N,M=map(int,input().split())
from collections import defaultdict
cnt=defaultdict(int)
for i in range(M):
    a,b=map(int,input().split())
    cnt[a-1]+=1
    cnt[b-1]+=1
for i in range(N):
    if cnt[i]%2==1:
        print('NO')
        exit()
print('YES')

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

int main(){
    ll n;
    cin>>n;
    ll flag=1;
    ll x;
    for(ll i=1e5;i>0;--i){
        if(n%i==0){
            if(abs(i-n/i)<abs(flag-n/flag)){
                flag=i;
            }
        }
    }
    ll ans = to_string(max(flag, n/flag)).size();
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
long long f(long long b, long long n) {
	if (n < b) {
		return n;
	}
	else {
		return f(b, n / b) + n%b;
	}
}
int main() {
	long long n, s, b, tmp, i;
	scanf("%lld%lld", &n, &s);
	if (s==n) {
		printf("%lld", n+1);
		return 0;
	}
	else if (s < n) {
		for (b = 2; b*b <= n; b++) {
			if (f(b, n) == s) {
				printf("%lld", b);
				return 0;
			}
		}
		for (i = b; i >= 1; i--) {
			b = (n - s) / i + 1;
			if (b>=2 && f(b, n) == s) {
				printf("%lld", b);
				return 0;
			}
		}
	}
	printf("-1");
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define FOREQ(i, s, n) for (ll i = (s); i <= (ll)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

ll n, m, w, t;
ll sell[100];
ll weight[100];
char str[1000];

vector<ll> goodBuy[100];
vector<ll> goodWeight[100];
ll px[100];
ll py[100];


ll dist(int i, int j) { return abs(px[i] - px[j]) + abs(py[i] - py[j]); }

ll memo[8][1 << 7];
ll CalcTime(int last, int rest) {
  if (memo[last][rest] != -1) { return memo[last][rest]; }
  ll ret = 1LL << 60;
  if (rest == 0) {
    ret = dist(last, n);
  } else {
    REP(i, n) {
      if (!((rest >> i) & 1)) { continue; }
      int nrest = rest & (~(1 << i));
      ret = min(ret, CalcTime(i, nrest) + dist(last, i));
    }
  }
  return memo[last][rest] = ret;
}

ll dp[10010];
ll CalcRieki(int use) {
  ll ret = 0;
  MEMSET(dp, 0);
  REP(i, n) {
    if (!((use >> i) & 1)) { continue; }
    REP(j, goodBuy[i].size()) {
      REP(k, w) {
        int nw = k + goodWeight[i][j];
        if (nw > w) { break; }
        dp[nw] = max(dp[nw], dp[k] + goodBuy[i][j]);
        ret = max(ret, dp[nw]);
      }
    }
  }
  return ret;
}

ll mainDP[10010];
int main() {
  while (scanf("%lld %lld %lld %lld", &n, &m, &w, &t) > 0) {
    MEMSET(mainDP, 0);
    MEMSET(memo, -1);
    REP(i, 100) { goodBuy[i].clear(); }
    REP(i, 100) { goodWeight[i].clear(); }

    map<string, ll> mapto;
    REP(i, m) {
      scanf("%s %lld %lld", str, &weight[i], &sell[i]);
      mapto[str] = i;
    }
    REP(i, n) {
      ll l;
      scanf("%lld %lld %lld", &l, &px[i], &py[i]);
      REP(j, l) {
        ll b;
        scanf("%s %lld", str, &b);
        ll index = mapto[str];
        goodWeight[i].push_back(weight[index]);
        goodBuy[i].push_back(max(sell[index] - b, 0LL));
      }
    }
    px[n] = 0;
    py[n] = 0;
    ll ans = 0;
    REP(i, 1 << n) {
      ll time = CalcTime(n, i);
      ll rieki = CalcRieki(i);
      REP(k, t) {
        ll nt = k + time;
        if (nt > t) { break; }
        mainDP[nt] = max(mainDP[nt], mainDP[k] + rieki);
        ans = max(ans, mainDP[nt]);
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 0
let N=Int(readLine()!)!
var C=[0],S=[0],F=[0]
for i in 1..<N{let i=readLine()!.characters.split(" ").map{Int(String($0))!};C+=[i[0]];S+=[i[1]];F+=[i[2]]}
for i in 0..<N{print((i+1..<N).reduce(0){max(S[$1],$0+(F[$1]-$0%F[$1])%F[$1])+C[$1]})}

Measured memory_bytes: 4208
class Get_set_num:
	def __init__(self):
		self.num = int()
		 
	def set_num(self,num):
		self.num = num

	def get_num(self):
		return self.num

		 
do  = Get_set_num()
Inp = input()
Inp = int(Inp)


#割れる回数が最大の数とその回数を記録するリスト
#max[0]が対象となる数、max[1]が割れた回数
max_list = [1,0]

for i in range(Inp , 1 , -1):
	count=0
	do.set_num(i)
	while i % 2 == 0:
		count += 1
		i= i/2
		if count > max_list[1]:
			max_list.clear()
			max_list.extend([do.get_num(),count])
			
print(max_list[0])

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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl

void vprint(vector<ll> A){
    if(A.size()==0){
        p("");
    }else{
        cout << A[0];
        FOR(i, 1, A.size()){
            cout << " " << A[i];
        }
        cout << endl;
    }
}

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

    // input
    ll N, Q;
    cin >> N >> Q;

    queue<ll> que[N];

    while(Q--){
        ll a;
        cin >> a;
        ll t, x;

        // enq
        if(a==0){
            cin >> t >> x;
            que[t].push(x);
        }
        // front
        else if(a==1){
            cin >> t;
            if(que[t].size()>0){
                p(que[t].front());
            }
        }
        // deq
        else{
            cin >> t;
            if(que[t].size()>0){
                que[t].pop();
            }
        }
    }
    
    return 0;
}


Measured memory_bytes: 5184
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;


int main(){
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i,n) cin >> p[i];
  int ans = 0;
  rep(i,n-2){
    if((p[i]>p[i+1]&&p[i+1]>p[i+2])||(p[i]<p[i+1]&&p[i+1]<p[i+2])) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n = input()
N = []
ans = 0
l = len(str(n))

for i in range(l):
    N.append(int(n[-i-1]))
N.append(0)

for i in range(l+1):
    if N[i]<5:
        ans += N[i]
    elif N[i]>5:
        ans += 10-N[i]
        N[i+1] += 1
    elif N[i+1]>4:
        ans += 10-N[i]
        N[i+1] += 1
    else:
        ans += N[i]

print(ans)


Measured memory_bytes: 119112
#[allow(dead_code)]
fn main() {
    let (a, b, h, m) = (i::f(), i::f(), i::f(), i::f());
    let mm = m + h * 60f64;
    let mx = (mm / 360f64 * PI).cos() * a;
    let my = (mm / 360f64 * PI).sin() * a;
    let mmx = (m / 30f64 * PI).cos() * b;
    let mmy = (m / 30f64 * PI).sin() * b;
    println!(
        "{}",
        ((mx - mmx) * (mx - mmx) + (my - mmy) * (my - mmy)).sqrt()
    );
    //dbg!(mx, my, mmx, mmy);
}

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, VecDeque};
use std::f64::consts::PI;
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::num::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(dead_code)]
mod i {
    use super::*;

    pub fn read<T: FromStr>() -> T {
        stdin()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }

    pub fn str() -> String {
        read()
    }

    pub fn s() -> Vec<char> {
        str().chars().collect()
    }

    pub fn i() -> i64 {
        read()
    }

    pub fn u() -> usize {
        read()
    }

    pub fn u2() -> (usize, usize) {
        (read(), read())
    }

    pub fn u3() -> (usize, usize, usize) {
        (read(), read(), read())
    }

    pub fn f() -> f64 {
        read()
    }

    pub fn c() -> char {
        read::<String>().pop().unwrap()
    }

    pub fn iv(n: usize) -> Vec<i64> {
        (0..n).map(|_| i()).collect()
    }

    pub fn iv2(n: usize) -> Vec<(i64, i64)> {
        (0..n).map(|_| iv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv(n: usize) -> Vec<usize> {
        (0..n).map(|_| u()).collect()
    }

    pub fn uv2(n: usize) -> Vec<(usize, usize)> {
        (0..n).map(|_| uv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv3(n: usize) -> Vec<(usize, usize, usize)> {
        (0..n).map(|_| uv(3)).map(|a| (a[0], a[1], a[2])).collect()
    }

    pub fn fv(n: usize) -> Vec<f64> {
        (0..n).map(|_| f()).collect()
    }

    pub fn cmap(h: usize) -> Vec<Vec<char>> {
        (0..h).map(|_| s()).collect()
    }
}


Measured memory_bytes: 2940
// https://atcoder.jp/contests/abc122/tasks/abc122_c

package main

import "fmt"
import "sort"

func main() {
	var N, Q int
	fmt.Scanf("%d %d", &N, &Q)

	var s string
	fmt.Scanf("%s", &s)

	indices := []int{}
	for i := 0; i < len(s)-1; i++ {
		if s[i] == 'A' && s[i+1] == 'C' {
			indices = append(indices, i)
		}
	}

	indicesRev := append([]int{}, indices...)
	sort.Sort(sort.Reverse(sort.IntSlice(indicesRev)))

	for i := 0; i < Q; i++ {
		var r, l int
		fmt.Scanf("%d %d", &l, &r)
		l--
		r--

		lp := sort.Search(len(indices), func(i int) bool { return l <= indices[i] })
		rp := sort.Search(len(indicesRev), func(i int) bool { return indicesRev[i]+1 <= r })
		if rp >= len(indicesRev) && lp >= len(indices) {
			fmt.Println(0)
			continue
		}

		rp = len(indicesRev) - (rp + 1)
		fmt.Println(rp - lp + 1)
	}
}


Measured memory_bytes: 7808
#include<iostream>
#include <algorithm>
#include <string>
#include<math.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
int main() {
    int a;
    cin >> a;
    if (a < 1200) {
        cout << "ABC" << endl;
    }
    else if (a < 2800) {
        cout << "ARC" << endl;
    }
    else {
        cout << "AGC" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
geta = lambda fn: map(fn, readline().split())
gete = lambda fn: fn(input())

# sys.setrecursionlimit(10**5)


def main():
    S=gete(str)[::-1]
    m=13
    mod=10**9 + 7
    prev, curr=[0]*m, [0]*m
    base,  wild=[], []

    s0, b=0, 1
    for i, c in enumerate(S):
        base.append(b)
        if c == "?":
            wild.append(i)
        else:
            s0=(s0 + b * int(c)) % m
        b=(b * 10) % m

    curr[s0]=1

    for wi in wild:
        prev, curr=curr, [0]*m

        for d in range(10):
            ad=d*base[wi]
            for r, p in enumerate(prev):
                curr[(r + ad) % m] += p

            for r, c in enumerate(curr):
                curr[r]=c % mod

    print(curr[5])


if __name__ == "__main__":
    main()


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

using namespace std;

#define    watch(x); cout << "\n" <<  #x << " is: " << x << "\n";
#define    all(a) (a).begin(), (a).end()
#define    fi first
#define    se second

template<class A, class B>
ostream& operator << (ostream& output, const pair<A, B>& p) {
    output << "(" << p.first << ", " << p.second << ")";
    return output;
}

template<class A>
ostream& operator << (ostream& output, const set<A>& s) {
    for(auto it = s.begin(); it != s.end(); ++it) {
        output << *it << endl;
    }
    return output;
}

template<class A, class B>
ostream& operator << (ostream& output, const map<A, B>& m) {
    for(auto it = m.begin(); it != m.end(); ++it) {
        output << "[" << it->first << ", " << it->second << "]" << endl;
    }
    return output;
}

template<class A>
ostream& operator << (ostream& output, const vector<A>& a) {
    output << "[";
    for(auto it = a.begin(); it != a.end(); ++it) {
        if(it != a.begin()) {
            output << ", ";
        }
        output << *it;
    }
    output << "]";
    return output;
}

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

//const int inf = 1e9;
//const int mod = 1e9 + 7;
//const double PI = acos(-1.0);
//const int mx = 1e5 + 5;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif

    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    const int inf = 1e9+10;
    vector<int> dp(n, inf);
    dp[0] = 0;
    dp[1] = abs(a[1] - a[0]);
    for(int i = 0; i < n; ++i) {
        if(i + 1 < n) dp[i + 1] = min(dp[i + 1], dp[i] + abs(a[i + 1] - a[i]));
        if(i + 2 < n) dp[i + 2] = min(dp[i + 2], dp[i] + abs(a[i + 2] - a[i]));
    }
    cout << dp[n - 1] << '\n';

    return 0;
}

Measured memory_bytes: 3984
N=int(input())
s=[0]*N
total=0
for i in range(N):
    s[i]=int(input())
    total+=s[i]
s.sort()
if total%10!=0:
    print(total)
else:
    for i in range(N+1):
        if i==N:
            print(0)
            break
        if (total-s[i])%10!=0:
            print(total-s[i])
            break

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
static const int INF = 2000000000;


int main(){
  int n, m;
  cin >> n >> m;
  vector<int> x, y;
  rep(i, m){
    int a, b;
    cin >> a >> b;
    if (a == 1) x.push_back(b);
    else if (b == n) y.push_back(a);
  }
  x.push_back(20000000);
  sort(ALL(x));
  bool ok = false;
  rep(i, y.size()){
    int v = lower_bound(ALL(x), y[i]) - x.begin();
    if (x[v] == y[i]) ok = true;
  }
  if (ok) cout << "POSSIBLE\n";
  else cout << "IMPOSSIBLE\n";
}

Measured memory_bytes: 1276
#include <cstdio>

int main() {
	int L, M, N;
	while (scanf("%d", &L)) {
		if (L == 0) break;
		int res = 0;
		bool flag = true;
		for (int i=0; i<12; i++) {
			scanf("%d%d", &M, &N);
			L -= (M - N);
			if (flag) {
				res++;
			}
			if (L <= 0) flag = false;
		}
		if (res == 12 && L > 0) {
			printf("NA\n");
		} else {
			printf("%d\n", res);
		}
	}
}

Measured memory_bytes: 0
#include<stdio.h>
#include<stdlib.h>

int main(void){
  int i,n,X;
  scanf("%d%d",&n,&X);
  int*x=malloc(sizeof(int)*n);
  for(i=0;i<n;i++){
    scanf("%d",&x[i]);
    x[i]-=X;
    if(x[i]<0)x[i]=-x[i];
  }
  for(i=0;i<n-1;i++){
    if(x[i]){
    if(x[i]<x[i+1]){
      int tmp=x[i];
      x[i]=x[i+1];
      x[i+1]=tmp;
    }
    int r=x[i]%x[i+1];
    while(r!=0){
      x[i]=x[i+1];x[i+1]=r;r=x[i]%x[i+1];
    }
  }
}
  printf("%d\n",x[n-1]);
}


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

int main(){
	
	ll n, s = 0;
	cin >> n;
	vector<ll> v(n);
	
	for(int i = 0; i < n; i++){
		cin >> v.at(i);
		s = s ^ v.at(i);
	}
	
	for(int i = 0; i < n; i++){
		cout << (s ^ v.at(i));
		if(i+1 < n) {
			cout << " ";
		}
	}
	
	cout << endl;
	
	return 0;
}


Measured memory_bytes: 4752
#include<stdio.h>

#define INF 0x7fffffff

int cnt = 0;
int L[500011 / 2], R[500011 / 2];

void merge(int A[], int left, int mid, int right)
{
	int n1, n2;
	n1 = mid - left;
	n2 = right - mid;
	for (int i = 0; i < n1; i++)
		L[i] = A[left + i];
	for (int i = 0; i < n2; i++)
		R[i] = A[mid + i];
	L[n1] = R[n2] = INF;

	for (int k = left, i = 0, j = 0; k < right; k++)
	{
		if (L[i] <= R[j])
			A[k] = L[i++];
		else
			A[k] = R[j++];
		cnt++;
	}
}

void mergeSort(int A[], int left, int right)
{
	if (left + 1 < right)
	{
		int mid = (left + right) / 2;
		mergeSort(A, left, mid);
		mergeSort(A, mid, right);
		merge(A, left, mid, right);
	}
}

int main()
{
	int A[500011];
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", &A[i]);
	mergeSort(A, 0, n);
	for (int i = 0; i < n; i++)
	{
		if (i)
			printf(" ");
		printf("%d", A[i]);
	}
	printf("\n%d\n", cnt);
}


Measured memory_bytes: 5568
#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define mod2 998244353
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define sz(v) ((ll)(v).size())
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define pb push_back
	#define f first
	#define s second
	#define dbg(a) cout<<#a<<" --> "<<(a)<<"\n";
	#define forn(i,n) for (ll i=0; i<(n); ++i)
	#define fornd(i,n) for (ll i=(n)-1; i>=0; --i)
	#define forab(i,a,b) for (ll i=(a); i<=(b); ++i)
	#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
	using namespace std;
	bool isPowerOfTwo(int x) {
    return x && (!(x & (x - 1)));
	}
	int takemod(int x) {
    return (x % mod + mod) % mod;
	}
 
	int fpow(int base, int power, int MOD) {
    int result = 1;
    base = base % MOD;
    while (power) {
        if (power & 1)
            result = (result * base) % MOD;
        base = (base * base) % MOD;
        power = power >> 1;
    }
    return result;
	}
 
	int modinv(int x) {return fpow(x, mod - 2, mod);}
	void solve()
	{
		ll n;
		cin>>n;
		if(n%1000!=0)
		{

		cout<<1000*(1+n/1000)-n<<endl;		
		}
		else
			cout<<0<<endl;
	}
	int main()
	{	
		#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		#endif
		fast_io;
		int T=1;
	//	cin>>T;
		// cin.ignore(); must be there when using getline(cin, s)
		while(T--)
		{
			solve();
		}
		return 0;
	}


Measured memory_bytes: 3644
n = gets.to_i
as = gets.split.map(&:to_i)
o = Hash.new(0)
e = Hash.new(0)

osum = 0
esum = 0
n.times do |i|
  if i.odd?
    o[as[i]] += 1
    osum += 1
  else
    e[as[i]] += 1
    esum += 1
  end
end

o = o.to_a.sort{|a,b| b[1] <=> a[1]}
e = e.to_a.sort{|a,b| b[1] <=> a[1]}

if o[0][0] == e[0][0]
  if o.size == 1
    ans = osum - o[0][1] + esum
  else
    case o[1][1] <=> e[1][1]
    when -1
      ans = osum - o[0][1] + esum - e[1][1]
    when 0
      ans = osum - o[1][1] + esum - e[0][1]
    when 1
      ans = osum - o[1][1] + esum - e[0][1]
    end
  end
else
  ans = osum - o[0][1] + esum - e[0][1]
end


puts ans


Measured memory_bytes: 20544
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    ll a ;
    double b;
    cin >> a >> b;
    ll c = b * 100 + 0.001;
    ll ans = a * c ;
    ans /= 100;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3680
#include<stdio.h>

int main(void)
{
int i,j,a,b;

while(1){
scanf("%d %d",&a,&b);
if(a==0&&b==0){
break;
}
for(i=1;i<=a;i++){
for(j=1;j<=b;j++){
if((i+j)%2==0){
printf("#");
}
else{
printf(".");
}
}
printf("\n");
}
printf("\n");
}
return 0;
}

Measured memory_bytes: 1000
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <math.h>
#include <ctype.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;
int main() {
	string s;
	cin >> s;

	int R = -1;
	int L = -1;

	int n = s.size();

	if (s[0] == 'L') {
		L = L + 2000;
	}

	for (int i = 1; i < n; i++) {
		if (i % 2 == 0) {
			if (s[i] == 'L') {
				R = R + 100;
			}
		}
		else {
			if (s[i] == 'R') {
				L = L + 100;
			}
		}
	}

	if (L == -1 && R == -1) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007
int main() {
    int n, a;
    cin >> n >> a;
    vector<int> x(n);
    for(size_t i = 0; i < n; i++) {
        cin >> x[i];
    }
    vector<vector<vector<ll>>> dp(51,
                                  vector<vector<ll>>(51, vector<ll>(2510, 0)));
    for(int i = 0; i <= n; i++) {
        for(int j = 0; j <= i; j++) {
            dp[i][j][0] = 1;
        }
    }

    for(int i = 1; i <= n; i++) {
        for(int j = 0; j <= i; j++) {
            for(int k = 0; k < 2510; k++) {
                if(k >= x[i - 1] && j > 0) {
                    dp[i][j][k] =
                        dp[i - 1][j - 1][k - x[i - 1]] + dp[i - 1][j][k];
                } else if(k >= x[i]) {
                    dp[i][j][k] = dp[i - 1][j][k];
                } else {
                    dp[i][j][k] = dp[i - 1][j][k];
                }
            }
        }
    }
    ll ans = 0;
    for(int i = 1; i <= n; i++) {
        ans += dp[n][i][i * a];
    }
    cout << ans << endl;
}


Measured memory_bytes: 52352
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
#define MOD (1000000007ll)
#define l_ength size
#define EPS (1e-10)

int main(void){
	ll a,b,c,x,y,ans;
	cin >> a >> b >> c >> x >> y;
	ans = a*(max(0ll,x-y))+b*(max(0ll,y-x))+min(x,y)*min(a+b,c*2);
	ans = min(ans,2*c*max(x,y));
	cout << ans << endl;
	return 0;
}


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

int main(){
	// sengen
	int n,r;
	// nyuryoku
	cin >> n >> r;
	// keisan
	if(n > 9){
		cout << r;
	}else{
		cout << r + 100*(10-n);
	}
	// syutsuryoku
}

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

#define pb            push_back
#define mp            make_pair
#define all(x)        x.begin(),x.end()
#define debug(X)      { cerr<<'\n'<<(#X)<<" = "<<(X)<<'\n'; }
//#define cerr if(0)cerr

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;


int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    char c;
    cin>>c;
    cout<<(char)(c+1)<<'\n';
}


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

using namespace std;

int main(){
  string s1, s2;
  cin>>s1>>s2;
  
  int n1=s1.size(), n2=s2.size();
  vector<vector<int>> dp(n1+1, vector<int>(n2+1));
  for(int i=1;i<=n1;i++){
    for(int j=1;j<=n2;j++){
      if(s1[i-1]==s2[j-1]){
        dp[i][j]=dp[i-1][j-1]+1;
      }else{
        dp[i][j]=max(dp[i][j-1], dp[i-1][j]);
      }
    }
  }

  // constructing the string
  string ans;
  int length=dp[n1][n2];
  int row=n1, col=n2;
  for(int i=0;i<length;i++){
    if(s1[n1-1]==s2[n2-1]){
      ans+=(s1[n1-1]);
      n1--;
      n2--;
    }else{
      // look for the maximum one
      if(dp[n1-1][n2]>dp[n1][n2-1]){
        // ans+=(s2[n2-1]);
        n1--;
      }else{
        // ans+=(s1[n1-1]);
        n2--;
      }
      i--;
    }
  }

  reverse(ans.begin(), ans.end());
  cout<<ans<<endl;
}

Measured memory_bytes: 38524
fun main() {
    val n = readLine()!!.split(" ").map(String::toInt)[0]
    val al = readLine()!!.split(" ").map(String::toInt)
    var sum = 0
    for (x in al) {
        sum += x
    }
    val p = n - sum
    if (p < 0) {
        println(-1)
    }
    else {
        println("${p}")
    }
}

Measured memory_bytes: 39616
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>

#define int long long
#define REP(i,l,r) REPEAT(i,l,r,true) //[l, r)
#define rep(i,n) REP(i,0,n)           //[0, n)
#define REPEAT(i,l,r,condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define fs first
#define sc second
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl
#define showslr(n,l,r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i];}cerr<<endl //[l, r)

#define yes puts("Yes")
#define no puts("No")
#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

inline void io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}

void _DEBUG(){cerr<<endl;}
template<typename H,typename... T> void _DEBUG(H a,T...b){cerr<<a<<",";_DEBUG(b...);}

template<typename T> inline void in(T &e){cin>>e;}
template<typename H,typename... T>void in(H &a, T&... b){in(a);in(b...);}
template<typename T> inline void out(T e){cout<<e<<endl;}
template<typename H,typename... T> void out(H a, T... b){out(a);out(b...);}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;

int n,i;

signed main(){
    io();

    in(n,i);

    out(n-i+1);

    return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
#define st first
#define nd second

using ll = long long ;
using namespace std;
using pii = pair<int,int>;
bool b[150];
int main(){
	int n;
	int k;
	scanf("%d %d", &n, &k);
	for(int i = 1; i <= k; i++){
		int m;
		scanf("%d", &m);
		for(int i = 1;  i <= m; i++){
			int x;
			scanf("%d", &x);
			b[x] = true;
		}
	}
	int ans = 0;
	for(int i = 1; i <= n ; i++){
		if(b[i] == false) ans++;
	}
	printf("%d", ans);


}

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

int n,s1=0,s2=0;
string s;
int main(){
	cin>>n;
	cin>>s;
	for(int i=0;i<n;i++)
	    if(s[i]!='R')
	       s1++;
	for(int i=n-s1;i<n;i++)
	    if(s[i]!='W')
	       s2++;
	    
	cout<<s2;
	return 0;
} 

Measured memory_bytes: 3732
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

const int MAXV = 10010;
const int MAXE = 10010;
struct Edge {
    int u, v, c;
    Edge(int x = 0, int y = 0, int z = 0) : u(x), v(y), c(z) {}
};
int V, E, root;
Edge edges[MAXE];
inline int newV() { return ++V; }
inline void addEdge(int u, int v, int c)
{
    edges[++E] = Edge(u, v, c);
}
bool con[MAXV];
int mnInW[MAXV], prv[MAXV], cyc[MAXV], vis[MAXV];
inline int DMST() {
    fill(con, con + V + 1, 0);
    int r1 = 0, r2 = 0;
    while (1) {
        fill(mnInW, mnInW + V + 1, INF);
        fill(prv, prv + V + 1, -1);
        for (int i = 1; i <= E; i++) {
            int u = edges[i].u, v = edges[i].v, c = edges[i].c;
            if (u != v && v != root && c < mnInW[v]){mnInW[v] = c; prv[v] = u;}
        }
        fill(vis, vis + V + 1, -1);
        fill(cyc, cyc + V + 1, -1);
        r1 = 0;
        bool jf = 0;
        for (int i = 1; i <= V; i++) {
            if (con[i]) continue;
            if (prv[i] == -1 && i != root) {
                return -1;
            }
            if (prv[i] > 0) r1 += mnInW[i];
            int s;
            for (s = i; s != -1 && vis[s] == -1; s = prv[s])
                vis[s] = i;
            if (s > 0 && vis[s] == i) {
                // get a cycle
                jf = 1; int v = s;
                do {
                    cyc[v] = s, con[v] = 1;
                    r2 += mnInW[v]; v = prv[v];
                } while (v != s);
                con[s] = 0;
            }
        }
        if (!jf) break;
        for (int i = 1; i <= E; i++) {
            int &u = edges[i].u;
            int &v = edges[i].v;
            if (cyc[v] > 0) edges[i].c -= mnInW[edges[i].v];
            if (cyc[u] > 0) edges[i].u = cyc[edges[i].u];
            if (cyc[v] > 0) edges[i].v = cyc[edges[i].v];
            if (u == v) edges[i--] = edges[E--];
        }
    }
    return r1 + r2;
}

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int e;
    cin >> V >> e >> root;
    root++;
    for(int i = 0; i < e;i++) {
        int a, b, c;
        cin >> a >> b >> c;
        a++; b++;
        addEdge(a, b, c);
    }
    cout << DMST() << endl;
    
    return 0;
}



Measured memory_bytes: 3356
import java.util.*;
public class Main {
   private static int h[];
   private static int dp[];
  public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		int k = sc.nextInt();

        h = new int[n];
        dp = new int[n];

        for (int i = 0; i < n; i++) {
          dp[i]=Integer.MAX_VALUE;
          h[i] = sc.nextInt();
        }

		// 30 10 60 10 60 50  
		dp[0] = 0;
		for (int i=1; i < n; i++) {
          for (int j=1;j <=k;j++){
            if (i<j) {}else{
			dp[i]=chmin(dp[i],dp[i-j]+Math.abs(h[i-j] - h[i]));
          }}
		}
		System.out.println(dp[n-1]);
	}

	private static int chmin(int i, int j) {
		return Math.min(i, j);
	}
}






Measured memory_bytes: 52016
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
const int N=1e5+3;
int a[N];
int32_t main()
{
  #ifndef ONLINE_JUDGE
    freopen("in","r",stdin);
    freopen("out","w",stdout);
  #endif
  int n;cin>>n;
  for(int i=1;i<=n;i++)cin>>a[i];

  int ans=0;
  for(int i=1;i<=n+1;i++)
    ans+=abs(a[i]-a[i-1]);

  for(int i=1;i<=n;i++)
  {
    int tmp=abs(a[i]-a[i-1])+abs(a[i+1]-a[i]);
    int add=abs(a[i-1]-a[i+1]);
    ans+=add;
    ans-=tmp;
    cout<<ans<<"\n";
    ans+=tmp;
    ans-=add;
  }
  


 

}

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

namespace ITP1_10_D
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            double[] x = Console.ReadLine().Split(' ').Select(s => double.Parse(s)).ToArray();
            double[] y = Console.ReadLine().Split(' ').Select(s => double.Parse(s)).ToArray();
            double D1 = 0.0;
            double D2 = 0.0;
            double D3 = 0.0;
            double D4 = 0.0;
            for(int i = 0; i < n; i++)
            {
                double xy = Math.Abs(x[i] - y[i]);
                D1 += xy;
                D2 += xy * xy;
                D3 += xy * xy * xy;
                D4 = Math.Max(D4, xy);
            }
            Console.WriteLine("{0}\n{1}\n{2}\n{3}",
                D1, Math.Sqrt(D2), Math.Pow(D3, 1.0 / 3.0), D4);
        }
    }
}

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

int sumDigit(int n){
    int sum = 0;
    for (sum = 0; n > 0; sum += n % 10, n /= 10); 
    return sum;
}

int main(){
    int n, min_sum = 1e7;
    cin >> n;
    for(int i = 1; i <= n/2; i++){
        int A = sumDigit(i);
        int B = sumDigit(n-i);
        min_sum = min(min_sum,A+B);
    }
    cout << min_sum << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int main() {
  char c;
  while (true) {
    scanf("%c", &c);
    if (c == '\n') break;
    if (c >= 65 && c <= 90)
      c += 32;
    else if (c >= 97 && c <= 122)
      c -= 32;
    printf("%c", c);
  }
  printf("\n");
  return 0;
}



Measured memory_bytes: 2612