akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define int long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(), (x).end()
#define capi(x) int x;cin>>x
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using vi = vector<int>;

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

int dp[3001][3001][3] = {0};

#define P (998244353)

signed main() {
    int n, s;
    cin >> n >> s;

    vi va;
    rep(i, n) {
        capi(a);
        va.push_back(a);
    }

    dp[0][0][0] = 1;

    rep(i, n) {
        rep(j, s + 1) {
            (dp[i + 1][j][0] += dp[i][j][0]) %= P;
            (dp[i + 1][j][1] += dp[i][j][1]) %= P;
            (dp[i + 1][j][2] += dp[i][j][2]) %= P;
            if (va[i] + j <= s) {
                (dp[i + 1][va[i] + j][1] += dp[i][j][1]) %= P;
                (dp[i + 1][va[i] + j][1] += dp[i][j][0] * (i + 1)) %= P;
                (dp[i + 1][va[i] + j][2] += dp[i][j][0] * (n - i) * (i + 1)) %= P;
                (dp[i + 1][va[i] + j][2] += dp[i][j][1] * (n - i)) %= P;
            }
        }
    }

    cout << dp[n][s][2];

    return 0;
}

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

int main(void) {
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	cout << max({ a[0],a[1],a[2] }) - min({ a[0],a[1],a[2] }) << endl;
	return 0;
}

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

#define debug(x) cerr << x << " = "(x) << endl;
#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

ll dp[31][31][31][31]; //a,b,c,dの操作回数
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    long double a,b,c,d,e,f;
    cin >> a>>b>>c>>d>>e>>f;
    long double ans = -1;
    int suger = 0;
    int suger_water = 0;
    rep(i,0,31){
        long double sw = i*a*100;
        if(sw>f)break;
        rep(j,0,31){
            sw += j*b*100;
            if(sw>f){ sw-=j*b*100;break; }
            rep(k,0,3000){
                sw += k*c;
                if(sw>f){sw-=k*c; break; }
                rep(l,0,3000){
                    sw += l*d;
                    if(sw>f || sw == 0){sw-=l*d; break; }
                    long double calc = (k*c + l*d) / sw;
                    if(calc <= e/(100.0+e) && ans<calc){
                        //cout << calc<<endl;
                        ans = calc;
                        suger = k*c + l*d;
                        suger_water = sw;
                    }
                    sw -= l*d;
                }
                sw -= k*c;
            }
            sw -= j*b*100;
        }
    }
    cout << suger_water << " " << suger << endl;
}

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



int main() {
  char c[3][3];
  rep(i, 3) rep(j, 3) cin >> c[i][j];
  rep(i, 3) cout << c[i][i];
  cout << endl;
  return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<long long>ans(N+1);
    ans[0]=2; ans[1]=1;
    for(int i=2; i<=N; i++){
	ans[i] = ans[i-1] + ans[i-2];
    }
    cout << ans[N] << endl;
}



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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

X = INT()

dp = [0] * (X+1)
dp[0] = 1
for i in range(X):
    for j in range(100, 106):
        if i+j > X:
            break
        dp[i+j] |= dp[i]
print(dp[X])


Measured memory_bytes: 3828
#include <bits/stdc++.h>
 
const double pi = 3.141592653589793238462643383279;
 
 
using namespace std;
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
 
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
 
//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
 
 
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const double EPS = 1E-8;
 
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

// ここから編集
template<typename T = int> struct BIT{
  vector<T> node;

  int N;
  BIT(int n){
    N = n;
    node.resize(N+1);
  }

  void add(int i, T x){
    i++;
    while(i <= N){
      node[i] += x;
      i += (i & -i);
    }
  }

  T sum(int i){
    T res = 0;
    while(i > 0){
      res += node[i];
      i -= (i & -i);
    }
    return res;
  }

  

};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    

    int N;
    cin >> N;

    vector<ll> A(N);
    REP(i,N) cin >> A[i];
    int Q; cin >> Q;
    map<ll,ll> mp;
    ll sum = 0;
    REP(i,N) mp[A[i]]++, sum += A[i];
    while(Q--){

      ll B, C; cin >> B >> C;
      ll num = mp[B];
      sum -= num*B;
      mp[B] = 0;
      mp[C] += num;
      sum += C*num;
      cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 9968
n = int(input())
d = [int(i) for i in input().split()]
out = 0
if d[0]:
    out = 1
d.sort()
k = [0]*100005
for i in d:
    k[i] += 1
c = 1
for i in range(d[n-1]):
    for j in range(k[i+1]):
        c *= k[i]
        c %= 998244353
if (k[0] >= 2 or out):
    print(0)
else:
    print(c)


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

typedef long long int ll;

int main()
{
	ll n;cin>>n;
  	set<ll> s;
  	for(int i=0;i<n;i++)
    {
      ll num;
    	cin>>num;
      s.insert(num);
    }
  if(s.size()==n)
    cout<<"YES";
  else
    cout<<"NO";
}

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

#define lli long long
#define FOR(i,a,b) for (lli i=(a);i<(b);i++)
#define REP(i,n) for (lli i=0;i<(n);i++)
#define rep(i,n) for (lli i=0;i<(n);i++)

#define INF INT_MAX/3
#define PB push_back
#define pb push_back
#define all(a) (a).begin(),(a),end()
#define pll pair<lli,lli>

int main(){
  lli H,W;

  while(1){
    cin>>H>>W;
    if(H==0 and W==0)break;

    rep(i,H){
      rep(j,W){
	if(i==0 or i==H-1 or j==0 or j==W-1)
	  cout<<"#";
	else
	  cout<<".";
      }
      cout<<endl;
    }
    cout<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 3056
#200322B
S = str(input())
N = len(S)
#print(N)
n = (N-1)//2
#print(n)
#print(type(n))
Sa = S[:n]
#print(Sa)
Sb = S[n+1:]
#print(Sb)


def Pal(x):
    flag = 1
    Lx = len(x)
    if Lx > 1:
        for i in range(Lx//2):
            #print(i)
            #print(x[i])
            #print(x[Lx-1-i])
            if x[i] != x[Lx-i-1]:
                flag = 0
    #print(flag)
    return flag

if Pal(S)*Pal(Sa)*Pal(Sb) == 1:
    print('Yes')
else:
    print('No')
                

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<numeric>
#include<iomanip>
#include<utility>
#include<cstdlib>
#include<typeinfo>
#include<stack>
#include<cassert>
#include<functional>
#define int long long int
#define double long double
using namespace std;
#define INT_MAX 1000000007
#define INF 1000000000000000007
const int MAX_N = 1 << 17;
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;

signed main()
{
int n;
std::cin >> n;
std::vector<int> a(n + 1,0);
std::vector<int> dis;
int sum = 0;
int div = 0;
for(int i = 1; i < n + 1; i++){
    int temp;
    std::cin >> temp;
    a[i] = temp;
    sum += temp;
    div += i;
}
int t = sum / div;
for(int i = 1; i < n; i++){
    dis.push_back(a[i + 1] - a[i] - t);
}
if(sum % div != 0){
    std::cout << "NO" << std::endl;
} else {
    int flag = 0;
    int counter = 0;
    for(int i = 0; i < n - 1; i++){
        if(dis[i] > 0 || abs(dis[i]) % n != 0){
            flag = 1;
        }
        counter += abs(dis[i]) / n;
    }   
    if(flag == 0 && counter <= t){
        std::cout << "YES" << std::endl;
    } else {
        std::cout << "NO" << std::endl;
    }
}


return 0;
}

Measured memory_bytes: 2168
function main(n) {
    for (var i = 1; i <= 9; i++) {
        if (n % i === 0 && n / i < 10) {
            console.log('Yes');
            return;
        }
    }
    console.log('No');
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
#include <iostream>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
int main(void) {
    int n;
    cin >> n;
    long long a[n];
    rep(i, n) cin >> a[i];
    
    long long s = 0, e = 0, c = 0;
    long long sa = 0;
    while (s < n) {
        while (e < n and (sa + a[e]) == (sa ^ a[e])) {
            sa ^= a[e];
            e++;
        }
        c += e-s;
        sa ^= a[s];
        s++;
    }

    cout << c << endl;
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long LL;
const int Maxn=30000+15;
const double INF=0x3f3f3f3f3f3f3f;
int n,sz=0,ans[10*Maxn][2];
double a[Maxn];
int main()
{
    scanf("%d",&n);
    double Min=INF,Max=-INF;
    int Mind,Maxd;
    for(int i=1;i<=n;i++)
    {
        scanf("%lf",&a[i]);
        if(Min>a[i])    Min=min(Min,a[i]),Mind=i;
        if(Max<a[i])    Max=max(Max,a[i]),Maxd=i;
    }
    if(Max+Min>=0)
    {
        for(int i=1;i<=n;i++)
        {
            if(i==Maxd) continue;
            ans[sz][0]=Maxd,ans[sz++][1]=i;
        }
        for(int i=1;i<n;i++)
            ans[sz][0]=i,ans[sz++][1]=i+1;
    }
    else
    {
        for(int i=1;i<=n;i++)
        {
            if(Mind==i) continue;
            ans[sz][0]=Mind,ans[sz++][1]=i;
        }
        for(int i=n;i>1;i--)
            ans[sz][0]=i,ans[sz++][1]=i-1;

    }
    printf("%d\n",sz);
    for(int i=0;i<sz;i++)
        printf("%d %d\n",ans[i][0],ans[i][1]);
    return 0;
}


Measured memory_bytes: 256
import string
import sys
import math

#??????????????\????????????ip?????\??????
ip = sys.stdin.readlines()
ip_list = {}

#?????????????????§?????????
for i in range(len(ip)):
    ip_list[i] = ip[i].strip("\n").split()

for i in range(1,len(ip)):
    for j in range(3):
        #?????????????????????
        for t in range(3):
            for k in range(3):
                if int(ip_list[i][t]) > int(ip_list[i][k]):
                    tmp = ip_list[i][t]
                    ip_list[i][t] = ip_list[i][k]
                    ip_list[i][k] = tmp  
                    
for i in range(1,len(ip)):   
    if int(ip_list[i][0])**2 == int(ip_list[i][1])**2 + int(ip_list[i][2])**2:
        print("YES")
    else:
        print("NO")

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

int main(void) {
    int N, K;
    cin >> N >> K;
    vector< int > A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < N - K; i++) {
        if (A[i] < A[i + K]) {
            printf("Yes\n");
        } else {
            printf("No\n");
        }
    }
    return 0;
}


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

int main()
{
    int N;
    cin>>N;
    vector<vector<int>> E(N), EI(N);
    for (int i=0; i<N-1; i++)
    {
        int a, b;
        cin>>a>>b;
        E[a-1].push_back(b-1);
        EI[a-1].push_back(i);
        E[b-1].push_back(a-1);
        EI[b-1].push_back(i);
    }

    function<long long(int, int, int, long long)> f = [&](int c, int p, int g, long long m)
    {
        if (c==g)
            return m;

        for (int i=0; i<(int)E[c].size(); i++)
            if (E[c][i]!=p)
            {
                long long r = f(E[c][i], c, g, m|1LL<<EI[c][i]);
                if (r!=-1)
                    return r;
            }
        return -1LL;
    };

    int M;
    cin>>M;
    vector<long long> C(M);
    for (long long &c: C)
    {
        int u, v;
        cin>>u>>v;
        c = f(u-1, -1, v-1, 0);
    }

    vector<long long> T(1<<M);
    T[0] = 1;
    for (int i=0; i<N-1; i++)
    {
        int x = 0;
        for (int j=0; j<M; j++)
            if (C[j]>>i&1)
                x |= 1<<j;

        vector<long long> P = T;
        for (int i=0; i<1<<M; i++)
            T[i|x] += P[i];
    }
    cout<<T[(1<<M)-1]<<endl;
}


Measured memory_bytes: 16640
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <fstream>
using namespace std;
long long mod=998244353;
int main(){
	long long n,x,m;
	cin>>n>>x>>m;
	long long a=x;
	set<long long> hoge;
	vector<long long> au;
	for(int i=0;i<n&&hoge.find(a)==hoge.end();i++){
		hoge.insert(a);
		au.push_back(a);
		a*=a;
		a%=m;
	}
	long long ans=0;
	if(au.size()==n){
		for(int i=0;i<n;i++){
			ans+=au[i];
		}
		cout<<ans<<endl;
		return 0;
	}
	long long mem;
	for(int i=0;i<au.size();i++){
		if(au[i]==a){
			mem=i;
			break;
		}
	}
	for(int i=0;i<mem;i++){
		ans+=au[i];
	}
	long long sum=0;
	for(int i=mem;i<au.size();i++){
		sum+=au[i];
	}
	n-=mem;
	for(int i=0;i<n%(au.size()-mem);i++){
		ans+=au[i+mem];
	}
	ans+=sum*(n/(au.size()-mem));
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 5560
/// Rustで競技プログラミングの入力をスッキリ記述するマクロ
///
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[inline]
#[allow(dead_code)]
fn gcd(mut m: u64, mut n: u64) -> u64 {
    if m < n {
        std::mem::swap(&mut m, &mut n);
    }

    loop {
        let k = m % n;
        if k == 0 {
            return n;
        }

        m = n;
        n = k;
    }
}

#[inline]
#[allow(dead_code)]
fn lcm(m: u64, n: u64) -> u64 {
    m / gcd(m, n) * n
}

macro_rules! eprint(
    ($($arg:tt)*) => { {
        use std::io::Write;
        let r = write!(&mut ::std::io::stderr(), $($arg)*);
        r.expect("failed printing to stderr");
    } }
);

macro_rules! eprintln(
    ($($arg:tt)*) => { {
        use std::io::Write;
        let r = writeln!(&mut ::std::io::stderr(), $($arg)*);
        r.expect("failed printing to stderr");
    } }
);

macro_rules! dbg {
    ($val:expr) => {
        // Use of `match` here is intentional because it affects the lifetimes
        // of temporaries - https://stackoverflow.com/a/48732525/1063961
        match $val {
            tmp => {
                eprintln!("[{}:{}] {} = {:#?}",
                          file!(), line!(), stringify!($val), &tmp);
                tmp
            }
        }
    }
}

fn main() {
    input!{
        s: String,
    }

    let mut s = s.as_str();
    while !s.is_empty() {
        let buf = s.clone();
        s = s.trim_right_matches("dream");
        s = s.trim_right_matches("dreamer");
        s = s.trim_right_matches("erase");
        s = s.trim_right_matches("eraser");
        if buf == s {
            println!("NO");
            return;
        }
    }

    println!("YES");
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>

using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))

typedef complex<double> P;
typedef long long ll;

const int MAX_SIZE = 10000;
const int MAX_PRIME = 30001;

int prime[MAX_PRIME+1];
bool isPrime[MAX_PRIME+1];
int p;

void erats(){
  // primeツδ環スツトツづーツ渉可甘コツ可サ
  fill(isPrime,isPrime+MAX_PRIME,true);
  p = 0;
  isPrime[0] = isPrime[1] = false;
  
  for(int i = 2; i <= MAX_PRIME; i++){
    if(isPrime[i]){
      prime[p++] = i;
    }
    else
      continue;
    
    // ツづ督づゥツつ「ツづ可つゥツつッツづゥ
    for(int j = 2*i; j <= MAX_PRIME; j+=i){
      isPrime[j] = false;
    }
    //cout << flush;
  }
}

int main(){

  int n;
  erats();
  //cout<<p<<endl;
  while(cin>>n&&n!=0){
    int cnt=0;
    int left=n;
    for(int i = 0; i < p; i++){
      int left=n-prime[i];
      if(left<prime[i])
	break;
      for(int j = i; j < p; j++){
	int lleft=left-prime[j];
	if(lleft>=prime[j]){
	  if(isPrime[lleft]){
	    if(prime[i]+prime[j]>lleft)
	      cnt++;
	  }
	}
	else
	  break;
      }
    }
    cout<<cnt<<endl;
  }

  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int n;
int now(int x)
{
    int sum=0;
    while(x)
    {
        sum+=x%10;
        x/=10;
    }
    return sum;
}
int ans=2147483647;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n-1;i++)
    {
        int x=now(i);
        int y=now(n-i);
        ans=min(ans,x+y);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
#define vall(x) (x).begin(), (x).end()
using namespace std;
using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2> bool chmin(T1 &l, const T2 &r);
template <class T1, class T2> bool chmax(T1 &l, const T2 &r);
template <class T1, class T2> void vadd(vector<T1> &v, T2 x);

#define int long long int
lli ans[30] = {};
int color[30] = {};

vector<int> a, b, c;
int N;
std::vector<long long> X; std::vector<long long> Y;
           std::vector<long long> P;
void f(int i){
    if (i == N) {
      lli al = 0;
      for (auto s : a) {
        auto tmp = P[s];
        lli ret = min(abs(X[s]), abs(Y[s])) * tmp;
        for (auto t : b)
          chmin(ret, abs(X[t] - X[s]) * tmp);
        for (auto t : c)
          chmin(ret, abs(Y[t] - Y[s]) * tmp);
        al += ret;
      }
      chmin(ans[b.size()+c.size()], al);
      return;
    }
    a.push_back(i);
    f(i+1);
    a.pop_back();
    b.push_back(i);
    f(i+1);
    b.pop_back();
    c.push_back(i);
    f(i+1);
    c.pop_back();
}
void solve(long long N_, std::vector<long long> X_, std::vector<long long> Y_,
           std::vector<long long> P_) {
             N = N_;
  X = X_; Y=Y_ ;P=P_;
  rep(i, 30) ans[i] = 1e18;
  f(0);
  rep(i, N+1){
    cout << ans[i] << endl;
  }
}

signed main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> X(N);
  std::vector<long long> Y(N);
  std::vector<long long> P(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &X[i]);
    scanf("%lld", &Y[i]);
    scanf("%lld", &P[i]);
  }
  solve(N, std::move(X), std::move(Y), std::move(P));
  return 0;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2> bool chmin(T1 &l, const T2 &r) {
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2> bool chmax(T1 &l, const T2 &r) {
  return (l < r) ? (l = r, true) : false;
}

template <class T1, class T2> void vadd(vector<T1> &v, T2 x) {
  for (auto &s : v)
    s += T2(x);
}


Measured memory_bytes: 3688
/*
	Created by : imay_10
	" It won't be EASY, but I'll make it "
*/

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

typedef long long int ll;
const int mod = 1e9+7;
const ll inf = 1e18;
const double pi = 3.1415926535897932384626;

// Utility for fast exponentiation
ll mpow(ll a,ll b,ll m){
    ll res=1;
    //a%=m;
    while(b){
    	if(b%2) res=res*a%m;
		a=a*a%m;
		b/=2;
	}
	return res;
}

// Utility for modular inverse
ll inv(ll a,ll m){
	return mpow(a,m-2,m);
}

// Utility for GCD Calculation
ll gcd(ll a,ll b){
	if(b==0) return a;
	return gcd(b,a%b);
}

void solve(){
	//code
	ll n,x=1;
	cin>>n;
	ll arr[n];
	vector<ll> v;
	for(ll i=0;i<n;i++){
		cin>>arr[i];
		if(x==arr[i]){
			v.push_back(arr[i]);
			x++;
		}
	}
	if(v.size()>0)
		cout<<n-v.size();
	else
		cout<<-1;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	solve();
 	return 0;
}


Measured memory_bytes: 6612
#include <bits/stdc++.h>
using namespace std;
long long q, x, y;
long long count(int x, int y){
	if(x==y)
		return 2*x-2;
	long long s = (long long)x*y;
	long long c = sqrt(s);
	if(c*c == s){
		return y-1+c-1+c-1-y;
	}
	else if(c*(c+1)<s){
		return y-1+c-y+c;
	}
	return	y-1+c-y+c-1;
	
}
int main() {
	cin>>q;
	while(q--){
		cin>>x>>y;
		if(y>x)	swap(x,y);
		cout<<count(x,y)<<'\n';
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	long long n,x,y,ans=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>x>>y;
		ans+=y-x+1;
	}
	cout<<ans;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;


ll modpow(ll N, ll P){
    if(P==0) return 1;
    if(P%2==0){
        ll t =modpow(N, P/2);
        return t*t % mod;
    }
    return N * modpow(N, P-1)%mod;
}

ll n;
ll com(ll k){
    ll u=1;
    for (int i = 0; i < k; ++i) {
        u*=n-i;
        u%=mod;
        if(u<0){
            u+=mod;
        }
    }
    ll d=1;
    for (int i = 0; i < k; ++i) {
        d*=(i+1);
        d%=mod;
        if(d<0){
            d+=mod;
        }
    }
    ll inv=modpow(d,mod-2);
    u=u*inv%mod;
    return u;
}

int main(){
    ll a,b;cin >>n>>a>>b;
    ll ans=modpow(2,n);
    ans-=com(a);
    ans-=com(b);
    ans--;
    ans%=mod;
    if(ans<0){
        ans+=mod;
    }
    cout <<ans <<endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define BIGINF (int) 4e18 + 7
#define MOD7 1000000007
#define MOD9 1e9 + 9
#define INF  (int)2e9 + 7
#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define MEM(a, b) memset(a, (b), sizeof(a))
typedef long long ll;
typedef long double ld;
typedef string str;
typedef double d;
typedef unsigned u;
typedef unsigned long long ull;

const int N = 305;

double ev[N][N][N], p[N][N][N];

int main () {
    //freopen("inputf.txt", "r", stdin);
    //freopen("outputf.txt", "w", stdout);
    //freopen("error.txt", "w", stderr);

    int n, num;
    int cnt[4] = {0};
    SCD(n);
    for (int i = 0; i < n; i++) {
    	SCD(num);
   		cnt[num]++;
    }
    p[cnt[1]][cnt[2]][cnt[3]] = 1;
    for (int c = n; c >= 0; c--) {
    	for (int b = n; b >= 0; b--) {
    		for (int a = n; a >= 0; a--) {
    			if (a == 0 && b == 0 && c == 0) continue;
    			if (a + b + c > n) continue;
    			double p_waste = (double) (n - (a + b + c)) / n;
    			double ev_waste = (double) p_waste / (1 - p_waste) + 1;
    			ev[a][b][c] += (double) ev_waste * p[a][b][c];


    			if (a != 0) { 
    				double p_go = (double) a / (a + b + c);
    				p[a - 1][b][c] += p[a][b][c] * p_go;
    				ev[a - 1][b][c] += ev[a][b][c] * p_go;
    			}
    			if (b != 0) {
    				double p_go = (double) b / (a + b + c);
    				p[a + 1][b - 1][c] += p[a][b][c] * p_go;
    				ev[a + 1][b - 1][c] += ev[a][b][c] * p_go;
    			}
    			if (c != 0) {
    				double p_go = (double) c / (a + b + c);
    				p[a][b + 1][c - 1] += p[a][b][c] * p_go;
    				ev[a][b + 1][c - 1] += ev[a][b][c] * p_go;
    			}
    		}
    	}
    }
    printf("%.10lf\n", ev[0][0][0]);

    return 0;
}



Measured memory_bytes: 438528
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD 1000000007

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

signed main() {
    int N;
    cin >> N;

    int ret = 0;
    vector<pair<int, int>> prs(N);
    rep(i, N) {
        cin >> prs[i].first >> prs[i].second;
        ret = max(ret, prs[i].second - prs[i].first + 1);
    }

    sort(all(prs));

    vector<int> v1, v2;
    vector<pair<int, int>> prs1, prs2;
    int low = 0;
    int high = INT_MAX;
    for (auto it = prs.begin(); it != prs.end(); it++) {
        low = max(low, it->first);
        high = min(high, it->second);
        v1.push_back(high - low + 1);
        prs1.push_back(mp(low, high));
    }

    low = 0;
    high = INT_MAX;
    for (auto it = prs.rbegin(); it != prs.rend(); it++) {
        low = max(low, it->first);
        high = min(high, it->second);
        v2.push_back(high - low + 1);
        prs2.push_back(mp(low, high));
    }
    reverse(all(v2));
    reverse(all(prs2));

    rep(i, N - 1) {
        ret = max(ret, v1[i] + v2[i + 1]);
    }

    REP(i, 1, N - 2) {
        int low = max(prs1[i - 1].first, prs2[i + 1].first);
        int high = min(prs1[i - 1].second, prs2[i + 1].second);
        ret = max(ret, prs[i].second - prs[i].first + 1 + max(0LL, high - low + 1));
    }

    cout << ret << endl;

    return 0;
}


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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL << 30)
#define LLINF (1LL << 60)
#define PI 3.14159265359
#define EPS 1e-12
#define int ll

int dp1[1000010], dp2[1000010];
signed main(void) {
  VL a, b;
  FOR(i, 1, 500) {
    int tmp = i * (i + 1) * (i + 2) / 6;
    if (tmp % 2)
      b.PB(tmp);
    a.PB(tmp);
  }
  //cout << a[100] << a[150] << " " << a[200] << endl;
  //cout << b.size() << endl;
  //a 200?????§???b 100?????§

  REP(i, 1000001) dp1[i] = dp2[i] = i;
  FOR(i, 1, 200) {
    FOR(j, a[i], 1000001) {
      dp1[j] = min(dp1[j], dp1[j-a[i]] + 1);
    }
  }
  FOR(i, 1, 100) {
    FOR(j, b[i], 1000001) {
      dp2[j] = min(dp2[j], dp2[j-b[i]] + 1);
    }
  }

  //REP(i, 50) cout << dp1[i] << " "; cout << endl;
  //REP(i, 50) cout << dp2[i] << " "; cout << endl;

  int n;
  while (true) {
    cin >> n;
    if(!n) break;
    cout << dp1[n] << " " << dp2[n] << endl;
  }

  return 0;
}

Measured memory_bytes: 18664
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <new>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<tuple>

typedef long long ll;

using namespace std;
using Graph = vector<vector<ll>>;

#define rep(i, N) for (ll i = 0; i < (ll)(N); ++i)
#define ALL(a) (a).begin(),(a).end()

const ll inf = 1e18+7;
const ll mod = 1e9+7;

ll GetDigit(ll num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

int main(){
    ll x,y,a,b,c,sum=0;
    cin >> x >> y >> a >> b >> c;
    vector<ll> p(a,0);
    vector<ll> q(b,0);
    vector<ll> r(c,0);

    rep(i,a) cin >> p[i];
    rep(i,b) cin >> q[i];
    rep(i,c) cin >> r[i];
    vector<ll> DP;

    sort(ALL(p));
    sort(ALL(q));
    sort(ALL(r));
    queue<ll> que;
    for(ll i=a-1;i>=a-x;i--){
        DP.push_back(p[i]);
    }
    for(ll i=b-1;i>=b-y;i--){
        DP.push_back(q[i]);
    }

    sort(ALL(DP));

    for(ll i=c-1;i>=0;i--){
        que.push(r[i]);
    }

    for(ll i=0;i<x+y;i++){
        if(DP[i]<que.front()){
            DP[i]=que.front();
            que.pop();
        }
        sum+=DP[i];
    }

    cout << sum << endl;

	return 0;
}



Measured memory_bytes: 4848
#include <bits/stdc++.h>
// #include <fstream>
using namespace std;
int main()
{
    // // 以降 cin の入力元が 'input.txt' になる
    // std::ifstream in("tests/sample-2.in");
    // std::cin.rdbuf(in.rdbuf());

    // ここにプログラムを記載
    int A, B, C;
    cin >> A >> B >> C;
    if (A + B >= C)
    {
        cout << B + C << endl;
    }
    else
    {
        cout << A + 2 * B + 1 << endl;
    }
}

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

long floor(long a,long b,long x){
	return (a*x/b)-a*(x/b);
}

int main(){
	long a,b,n;
	cin >> a >> b >> n;
	
	cout << floor(a,b,min(b-1,n));
	return 0;
}


Measured memory_bytes: 3548
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#include <iomanip>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int mx2[] = {1,0};
int my2[] = {0,1};

class DCardEater {
public:
	void solve(istream& in, ostream& out) {
        int n; in >> n;
        vector<int> a(n);
        rep(i,n) in >> a[i];
        sort(a.begin(),a.end());

        int cnt = 0;
        rep(i,n-1) {
            if(a[i+1] == a[i]) cnt++;
        }
        if(cnt % 2 == 0) out << n - cnt << endl;
        else out << n - cnt - 1 << endl;
	}
};

int main() {
	DCardEater solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

Measured memory_bytes: 640
#include <cstring>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <iostream>
#include <cstring>
using namespace std;
typedef long long int lli;
typedef pair<int,int> P;
const int INF=100000000;
const long long int INF_=1000000000000000000;

int main(){
	int A,B;
	map<int,int> Count;
	bool flag=true;
	while(cin >> A >> B){
		if(A==0&&B==0){
			for(auto it=Count.begin(); it!=Count.end(); ++it){
				if(((it->first==1||it->first==2)&&it->second%2!=1)||(!(it->first==1||it->first==2)&&it->second%2!=0)){
					flag=false;
					break;
				} 
			}
			cout << (flag?"OK":"NG") << endl;
			flag=true;
			Count.clear();
		} else {
			++Count[A];
			++Count[B];
		}
	}
	return 0;
}

Measured memory_bytes: 1188
n,m = map(int,input().split())
a = list(map(int,input().split()))

a.sort()
cost = [-1,2,5,5,4,5,6,3,7,6]

inf = -10 * n
dp = [[inf] * (n+1) for _ in range(m+1)]
dp[0][0] = 0

for i,ai in enumerate(a,1):
    ci = cost[ai]
    for j in range(n+1):
        if(j >= ci):
            dp[i][j] = max(dp[i-1][j], dp[i][j-ci] + 1)
        else:
            dp[i][j] = dp[i-1][j]

cnt = [0] * 10
j = n
for i in range(m,0,-1):
    if(dp[i][j] < 0):
        continue

    ai = a[i-1]
    ci = cost[ai]
    while(j>=ci):
        if(dp[i][j] - dp[i][j-ci] == 1):
            j -= ci
            cnt[ai] += 1
        else:
            break

ans = ''
for i in range(9,0,-1):
    ans += str(i) * cnt[i]

print(ans)

Measured memory_bytes: 70524
# include <cstdio>
# include <iostream>
using namespace std;
int num[4];

int fun( int x )
{
	int cnt = 0;
	while (x) {
		num[cnt] = x%10;
		cnt++;
		x/=10;
	}
	//for ( int i = 0;i < 4;i++ ) cout<<num[i]<<endl;
	int res = 1;
	for ( int i = 0;i < 4-1;i++ ) {
		if (num[i]==num[i+1]) {
			res++;
			if ( res >= 3) 
				return 1;
		}
		else {
			res = 1;
		}
	}
	if ( res >= 3 ) return 1;
	return 0;

}

int main(void)
{
	int n; scanf("%d",&n);
	int flag = fun(n);
	if ( flag ){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}


	return 0;
}

Measured memory_bytes: 256
n, m = list(map(int, input().split()))
lr_list = []

for _ in range(m):
    l, r = list(map(int, input().split()))
    lr_list.append((l, r))

card2canopen_dict = {i: True for i in range(1, n+1)}

# 重ね合わせの区間を調べれば良い気がする
kukan_min, kukan_max = 1, n

for i, lr in enumerate(lr_list):
    l, r = lr[0], lr[1]
    if l >= kukan_min:
        kukan_min = l
    if r <= kukan_max:
        kukan_max = r

if kukan_max < kukan_min:
    ans = 0
else:
    ans = len(range(kukan_min, kukan_max+1))

print(ans)


Measured memory_bytes: 28572
#include<bits/stdc++.h>
using namespace std;
int N;
int dp[10000005];
int solve(int n){
  
}
int main(){
  cin >> N;
  int res = 0;
  for(int i=1;i<=N;i++){
    res += i;
    if( res >= N ) {
      for(int j=1;j<=i;j++){
        if( res-N == j ) continue;
        cout << j << endl;
      }
      break;
    }
  }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
//One implementation to rule them all?
#define db              double
#define ll              long long int
#define ld                long long double
//#define int           long long int
#define ull             unsigned long long
#define fi              first
#define se              second
#define rep(i,a,n)      for(int i=a;i<n;i++)
#define repr(i,n,b)     for(int i=n;i>=b;i--)
#define endl            '\n'
#define mem(a,b)        memset(a, b, sizeof a)
#define mkp             make_pair
#define pb              push_back
#define max3(a,b,c)     max(a,max(b,c))
#define min3(a,b,c)     min(a,min(b,c))
#define w(t)            int t; cin>>t; while(t--)
#define all(a)          a.begin(), a.end()
#define sz(a)           int((a).size())
//Bitwise 
#define isOn(S, j) (S & (1<<j))
#define setBit(S, j) (S |= (1<<j))
#define clearBit(S, j) (S &= ~(1<<j))
#define toggleBit(S, j) (S ^= (1<<j))
#define lowBit(S) (S & (-S))
#define setAll(S, n) (S = (1<<n)-1)
#define turnOffLastBit(S) ((S) & (S-1))
#define turnOnLastZero(S) ((S) | (S+1))
//Can use tuples in C++17
using namespace std;
typedef vector < int > vii;
typedef vector < ll > vll;
typedef vector < vii > vvi;
typedef pair < int,int > pii;
template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
const db PI = 2*acos(0.0);
const int INF = 0x3f3f3f3f;
const ll LINF = (ll)2e18;
db eps       =          0.000001;
ll mod       =          (1e9+7);   //998244353
void print(vector <int> &arr){
    for(int i=0;i<arr.size();i++)
        cout<<arr[i]<<" ";
    
    cout<<endl;
}
void printll(vector <ll> &arr){
    for(int i=0;i<arr.size();i++)
        cout<<arr[i]<<" ";
    
    cout<<endl;
}

ll ncr(ll n, ll r)
{
    r=min(r,n-r);
    ll A[r],i,j,B[r];
    iota(A,A+r,n-r+1);  
    iota(B,B+r,1);     

    ll g;
    for(i=0;i<r;i++)
    for(j=0;j<r;j++)
    {
        if(B[i]==1)
            break;
        g=__gcd(B[i], A[j] );
        A[j]/=g;
        B[i]/=g;
    }
    ll ans=1;
    for(i=0;i<r;i++)
        ans=(ans*A[i]%mod);
    return ans;
}
const int SIZE=1e6+5;
bool judgePermutation(int a[], int n){
    static int used[SIZE+1];
    for(int i = 1; i <= n; i++) used[i] = 0;
    for(int i = 0; i < n; i++) used[a[i]] = 1;
    for(int i = 1; i <= n; i++) {
        if(!used[i]) return 0;
    }
    return 1;
}
vector<int> adj[1010]; 

int main(){ 
//CONDITION && cout << "YES" || cout << "NO"; cout << '\n';
//////////////////////////////////////////////////////////////////////
//  ios_base::sync_with_stdio(false);
//  cin.tie(NULL);
//  cout.tie(NULL);
//  cerr.tie(NULL);
//For fast IO
///////////////////////////////////////////////////////////////////// 
//  std::cout.unsetf ( std::ios::floatfield );  // floatfield not set
//  std::cout.precision(10);
//  freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
	long long a; 
    cin >> a;
    int x;
    cin >> x;
    char rubbish;
    cin >> rubbish;
    int y;
    cin >> y;
    x = x * 100 + y;
    cout << a * x / 100 << endl; 
	return 0;
}

Measured memory_bytes: 3608
n = int(input())
a = list(map(int, input().split(" ")))

b = [j - i for i, j in enumerate(a, start=1)]
# c = [-j - i for i, j in enumerate(a, start=1)]
count = {}
for i, j in enumerate(a, start=1):
    num = -i-j
    if num not in count:
        count[num] = 0
    count[num] += 1
result = sum([count.get(i, 0) for i in b])
print(result)


Measured memory_bytes: 47924
s = input()
t = input()

for i in range(len(s) - len(t) + 1)[::-1]:
    cnt = 0
    for ns, nt in zip(s[i:i+len(t)], t):
        cnt += 1
        if ns != nt and ns != '?':
            break
        if cnt == len(t):
            ans = s[:i] + t + s[i+len(t):]
            print(ans.replace('?', 'a'))
            exit()
print('UNRESTORABLE')


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

using namespace std;
int main(){

	int n;
	vector <int> a;

	cin >> n;


	int tmp;
	for(int i = 0; i < n; i++){
		cin >> tmp;
		a.push_back(tmp);	
	}	

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

	cout << a[n-1] - a[0] << endl;

	return 0;
}

Measured memory_bytes: 256
/*
Though leaves are many , the root is one.
Through all the lying days of my youth
I swayed my leaves and flowers in the sun.
Now I may wither into the truth.
	  	  	- William Butler Yeats
*/
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
#pragma comment("-Wl,--stack=1024000000")
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#ifndef LOCAL
#define cerr if(0)cout
#define eprintf(...) 0
#else
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#endif
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){int ret=1;do{if(y&1)ret=(ll)ret*x%md;x=(ll)x*x%md;}while(y>>=1);return ret;}
int n;
int a[22][2];
int dp[51][1<<18],cnt[1<<18];
inline void upd(int &x,int y){if(x>y)x=y;} 
int main(){
	cin>>n;
	for(int i=0;i<(1<<n);i++)cnt[i]=__builtin_popcount(i);
	for(int i=0;i<n;i++)cin>>a[i][0];
	for(int i=0;i<n;i++)cin>>a[i][1];
	memset(dp,inf,sizeof dp);
	dp[0][0]=0;
	for(int mask=0;mask<(1<<n);mask++){
		for(int lst=0;lst<=50;lst++)if(dp[lst][mask]<inf){
			for(int nxt=0;nxt<n;nxt++){
				if(mask&(1<<nxt))continue;
				int color=0,cost=0;
				for(int j=nxt+1;j<n;j++)color^=((mask>>j)&1);
				for(int j=0;j<nxt;j++){
					cost+=1-((mask>>j)&1);
					color^=1-((mask>>j)&1);
				}
				if(a[nxt][color]>=lst){
					upd(dp[a[nxt][color]][mask|(1<<nxt)],dp[lst][mask]+cost);
				}
			}
		}
	}
	int ans=inf;
	for(int i=0;i<=50;i++)ans=min(ans,dp[i][(1<<n)-1]);
	cout<<(ans==inf?-1:ans)<<endl;
	return 0;
}

Measured memory_bytes: 53632
#include <stdio.h>

int main(int argc, char const *argv[]) {
	char str[101];
	int n, m;

	fgets(str, 100, stdin);
	sscanf(str, "%s\n", str);

	int len;

	if (str[0] != 'A') {
		printf("WA\n");
		return 0;
	}

	for (len = 0; str[len] != 0; len++) {
	}

	int count = 0;

	if (str[1] < 'a' || 'z' < str[1]) {
		printf("WA\n");
		return 0;
	}

	for (n = 2; n < len-1; n++) {
		if ('a' <= str[n] && str[n] <= 'z') {
			continue;
		} else if (str[n] == 'C') {
			count++;
			break;
		} else {
			printf("WA\n");
			return 0;
		}
	}

	if (count != 1) {
		printf("WA\n");
		return 0;
	}

	for (n++; n < len; n++) {
		if ('a' <= str[n] && str[n] <= 'z') {
			continue;
		} else {
			printf("WA\n");
			return 0;
		}
	}

	printf("AC\n");

	return 0;
}


Measured memory_bytes: 128
var input=require('fs').readFileSync('/dev/stdin', 'utf8');
  var inputs=input.split(' ');
  var n=Number(inputs[0]),k=Number(inputs[1]);
  var rate=0;
  for(var i=1; i<=n; i++){
    var rate2=1,n2=i;
    while(n2<k){
      rate2/=2;
      n2*=2;
    }
    rate+=rate2;
  }
  console.log(rate/n);


Measured memory_bytes: 8140
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define powerof2 ()
#define mp make_pair
#define pi acos(-1)
using ll = long long;
const ll M = 1000000007;
const ll M1= 998244353;
using vl = vector<ll>;
using pll =  pair<ll,ll>;
ll power(ll x,ll y){
	if(y==0)
		return 1;
	ll res=power(x,y/2);
	res=(res*res);
	if(y&1)
		res=(res*x);
	return res;
}
 
ll powermod(ll x,ll y,ll mod){
	if(y==0)
		return 1;
	ll res=powermod(x,y/2,mod);
	res=(res*res)%mod;
	if(y&1)
		res=(res*x)%mod;
	return res;
}
/*ll binarysearch(ll va)
{
	ll n=1;
	ll l=va+1,u=n;
	ll st=num.order_of_key(va);
	while(l+1<u)
	{
		m=(l+u)/2;
		ll in=num.order_of_key(m);
		if(in-st==m-va)
		{
			l=m;
		}
		else
		{
            u=m;
		}
	}
	if(num1.find(l)==num1.end())
		return l;
	return u;
}*/
void solve(){
	int n,t;
	cin>>n;
	t=n;
	if(n%1000==0) cout<<0<<"\n";
	else{
		n/=1000;
		n+=1;
		n*=1000;
		cout<<n-t<<"\n";
	}
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    // cin>>t;
 
    for(int i=1;i<=t;i++)
    {//cout<<"Case #"<<i<<": ";
    solve();}
    return 0;
}


Measured memory_bytes: 3652
#include <cstdio>

int n; 
int b,f,r,v;
int k[4][3][10];
int main(){
	scanf("%d", &n);
	for(int i=0; i<n; ++i){
		scanf("%d%d%d%d", &b,&f,&r,&v);
		k[b-1][f-1][r-1]+=v;
	}
	for(int i=0; i<4; ++i){
		for(int j=0; j<3; ++j){
			for(int l=0; l<10; ++l){
				printf(" %d", k[i][j][l]);
			}
			printf("\n");
		}
		if(i!=3){
			printf("####################\n");	
		}
	}	
} 


Measured memory_bytes: 2716
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long ll;
typedef pair<ll,ll> P;


ll n, a[101010], b[101010];

int main(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i] >> b[i];
	}
	
	ll cnt = 0;
	for(int i = n-1; i >= 0; i--){
		cnt += ((cnt + a[i]) % b[i] ? b[i] - (cnt+a[i])%b[i] : 0);
	}
	
	cout << cnt << endl;
	
	return 0;
}

Measured memory_bytes: 1792
from collections import defaultdict

N = int(input())
X = [int(i) for i in input().split()]
D = defaultdict(int)
for x in X:
    D[x] += 1

B = []
for x in D:
    for _ in range(D[x] // 2):
        B.append(x)
B.sort()
ans = B[-1] * B[-2] if len(B) >= 2 else 0
print(ans)

Measured memory_bytes: 18592
#include <bits/stdc++.h>
using namespace std;
 
int main() {

 int A,B,C,K;
  cin>>A>>B>>C>>K;
  int ans = 0;
  if(A>=K){
  for (int i = 0; i < K; i++) {
 ans++;
}
  }
  else
  {
      for (int i = 0; i < A; i++) {
 ans++;
}
  }
    
  if(K-A-B>0){
  for (int i = 0; i < K-A-B; i++) {
 ans--;
}
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3672
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;

int main()
{
    int x, y;
    cin>>x>>y;
    cout<<x+y/2<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  char c;
  cin >> c;
  if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
    cout << "vowel" << endl;
  else
    cout << "consonant" << endl;
}


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

using namespace std;

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

	for (int i = 0; i < S.length(); i++) {
		if ((i + 1) % 2 == 1) {
			//奇数文字目
			if (S[i] == 'L') {
				cout << "No" << endl;
				return 0;
			}
		}
		else {
			//偶数文字目
			if (S[i] =='R') {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;

}


Measured memory_bytes: 3624
#include <cstdio>

int* card;

int n,m;

void init(){
	for(int i=0;i<200;i++){
		card[i] = i + 1;
	}
}

void printcard(){
	for(int i=0;i < n*2;i++){
		printf("%d\n",card[i]);
	}
}

void rihuru(){
	int* c = new int[200];
	for(int i=0;i<n*2;i++){
		c[i] =  card[(i / 2) + (i % 2) * n];
	}
	delete[] card;
	card = c;
}

void cut(int a){
	int* c = new int[200];
	int i = 0;
	for(int j = 0;j < 2 * n - a;j++){
		c[i] = card[a + j];
		i++;
	}
	for(int j=0;j<a;j++){
		c[i] = card[j];
		i++;
	}
	delete[] card;
	card = c;
}

int main(){
	card = new int[200];
	init();
	scanf("%d %d",&n,&m);
	int self;
	for(int i=0;i<m;i++){
		scanf("%d",&self);
		if(self == 0){
			rihuru();
		}else{
			cut(self);
		}
		
	}
	printcard();
	delete[] card;
}

Measured memory_bytes: 0
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        #[allow(unused_mut)]
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
            r: i32
        }

    let ans = 3 * r * r;

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


Measured memory_bytes: 4352