akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
#define N 200010
using namespace std;
int n,a[N],b[N],dxa[N],dxb[N],enr[4*N],ext[4*N];
int main(){
	int i,j,cnt=0;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(i=0;i<n;i++)
	{
		cin>>b[i];
	}
	for(i=0;i<n;i++)
	{
		dxa[i]=a[i]^a[(i+1)%n];
	}
	for(i=0;i<n;i++)
	{
		dxb[i]=b[i]^b[(i+1)%n];
	}
	for(i=0;i<n;i++)
	{
		enr[cnt++]=dxb[i];
	}
	enr[cnt++]=-INF;
	for(i=0;i<n;i++)
	{
		enr[cnt++]=dxa[i];
	}
	for(i=0;i<n;i++)
	{
		enr[cnt++]=dxa[i];
	}
	memset(ext,0,sizeof(ext));
	ext[0]=3*n+1;
	cnt=0;
	for(i=1;i<=3*n;)
	{
		while(i+cnt<=3*n)
		{
			if(enr[cnt]!=enr[i+cnt])
			{
				break;
			}
			cnt++;
		}
		ext[i]=cnt;
		j=1;
		if(cnt<=0)
		{
			i++;
			continue;
		}
		else
		{
			while(i+j<=3*n)
			{
				if(j+ext[j]>=cnt)
				{
					break;
				}
				ext[i+j]=ext[j];
				j++;
			}
		}
		i+=j;
		cnt-=j;
	}
	for(i=n+1;i<2*n+1;i++)
	{
		if(ext[i]==n)
		{
			cout<<i-n-1<<" "<<(a[i-n-1]^b[0])<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 12800
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
import collections
from operator import itemgetter
#以下てんぷら
def j(q):
    if q==1: print("Yes")
    else:print("No")
    exit(0)


def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")

def ip():
    return int(input())
def printrow(a):
    for i in range(len(a)):
        print(a[i])
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
n = ip()                                     #入力整数1つ
#a,b,c= (int(i) for i in input().split())       #入力整数横2つ以上
#a = [int(i) for i in input().split()]        #入力整数配列
a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#k = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(3)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#こっから本文
rb = 0
rw = 0
for i in range(n):
    if a[i] == '#':rb+=1
    else : rw+=1
lb = 0
lw = 0
s = rw
for i in range(n):
    if a[i] == '#':
        lb+=1
        rb-=1
    else :
        lw+=1
        rw-=1
    s = min(s,lb+rw)
print(s)

Measured memory_bytes: 23140
(defun in()
  (let ((s (read-char)))
	(if (or (eq s nil) (eq s #\space) (eq s #\newline))
	  (in)
	  s)))

(defun func (x)
  (when (< x 12)
	(progn
	  (when (eq x 4)
		(princ " "))
	  (princ (in))
	  (func (1+ x)))))

(func 0)
(princ #\newline)


Measured memory_bytes: 3432
n = int(input())
ten = 1
eight = 1
nine = 1
for i in range(n):
    ten *= 10
    ten = ten%(10**9 + 7)
    eight *= 8
    eight = eight%(10**9 + 7)
    nine *= 9
    nine = nine%(10**9 + 7)
print((ten+eight-(2*nine))%(10**9 + 7))

Measured memory_bytes: 63536
from sys import stdin


def main():
    _ = int(input())
    p_lists = [int(x) for x in stdin.readline().rstrip().split()]

    new_p_lists = sorted(p_lists)
    count = 0

    for p, new_p in zip(p_lists, new_p_lists):
        if p == new_p:
            pass
        else:
            count += 1

    if count == 0 or count == 2:
        print("YES")
    else:
        print("NO")


if __name__ == "__main__":
    main()


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

main(){
  int a , b , c , d;
  cin >> a >> b >> c >> d;
  if ( a + b > c + d )
    cout << "Left" << endl;
  else if ( a + b < c + d)
 	cout << "Right" << endl;
  else 
    cout << "Balanced" << endl;
}

Measured memory_bytes: 256
//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define pob pop_back
#define forr(x) for(int i = 0; i < x; i++)
#define forrr(x) for(int j = 0; j < x; j++)
#define F first
#define S second
#define endl '\n'
#define pi pair<ll, ll>
#define mp make_pair
const ll N = 3e5 + 5, inf = 1e9 + 5;

int n;
int h[N];
int dp[N];

int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin >> n;
	forr(n)
		cin >> h[i];
	dp[1] = abs(h[1] - h[0]);
	for(int i = 2; i < n; i++)
	{
		dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
	}
	cout << dp[n - 1] << endl;
	return 0;
}


Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(10**9)

N, M, Q = list(map(int, input().split()))
a, b, c, d = [0] * Q, [0] * Q, [0] * Q, [0] * Q
for i in range(Q):
    a[i], b[i], c[i], d[i] = list(map(int, input().split()))

def saiki(i, last, list):
    if(i == N):
        sum = 0
        for q in range(Q):
            if(list[b[q]-1] - list[a[q]-1] == c[q]):
                sum += d[q]
        return sum
    res = 0
    for x in range(last, M+1):
        list.append(x)
        res = max(res, saiki(i+1, x, list))
        list.pop(-1)
    return res

all = saiki(0, 1, [])
print(all)


Measured memory_bytes: 9244
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

typedef long long ll;
using namespace std;

vector<vector<ll>> comb;

void init_comb(int n) {
    comb = vector<vector<ll>>(n + 1, vector<ll>(n + 1));
    comb[0][0] = 1;
    for (int i = 1; i <= n; i++) {
        comb[i][0] = 1;
        for (int j = 1; j <= n; j++) {
            comb[i][j] = (comb[i - 1][j - 1] + comb[i - 1][j]);
        }
    }
}

int main() {
    int n;
    cin >> n;
    int size = 1 << n;
    map<ll, ll> ma;
    for (int i = 0; i < size; i++) {
        int tmp;
        cin >> tmp;
        ma[tmp]++;
    }
    vector<ll> v;
    for (auto x:ma)v.push_back(x.second);
    reverse(v.begin(), v.end());

    bool ret = true;
    ll remain = 0;
    init_comb(20);
    for (int i = 0; i < n; i++) {
        if (n >= v.size()) {
            ret = false;
            break;
        }
        remain += comb[n][i] - v[i];
        if (remain < 0)ret = false;
    }
    for (auto x:v) {
        if (x > size / 2)ret = false;
    }
    cout << (ret ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 18808
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<cmath>
#include<set>
#include<random>
#include<stdio.h>
#include<map>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 1000000007;
const long long inf = 11451419198109311;
const long double pi = 3.1415926535897932384626433;
typedef pair<int, int> P;
struct edge { int to, cost; };
int a[100001], b[100001];
signed main() {
	int n, m; cin >> n >> m;
	rep(i, n)cin >> a[i];
	rep(i, m)cin >> b[i];
	int suma = 0, sumb = 0;
	rep(i, n)suma += a[i];
	rep(i, m)sumb += b[i];
	cout << suma*sumb << endl;
}


Measured memory_bytes: 4652
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi=acos(-1.0);
const ll mod=pow(10,9)+7;
const ll INF=pow(2,31)-1;
using str=string;
typedef pair<int,int> P;
typedef vector<int> vi;

ll gcd(ll a,ll b){
    ll v0=a,v1=b,v2=a%b;
    while(v2!=0){
        v0=v1;
        v1=v2;
        v2=v0%v1;
    }
    return v1;
}

ll lcm(ll a,ll b){
    return (a*b/gcd(a,b));
}

int main(){
    ios::sync_with_stdio(false);
    ll n; cin >>n;
    cout << n*(n-1)/2 << endl;
    return 0;
}

Measured memory_bytes: 256
"""
N <= 5 * 10**3　なので、２重ループぐらいなら間に合うか？

例３
strangeorange
**range*range

他に２回以上出てくるものとして
r,a, みたいな単体
ra, nge みたいな最長の部分文字列の一部
みたいな感じなので
l,r (r=l+1~N-1)を持っておいて、S[l:r+1] = S[r+1:XX]になるものがあればさらに右をみて～みたいな？

"""


N = int(input())
S = input()


l = 0
r = 1
ans = 0
while True:
    if l == N-1:
        break
    while S[l:r] in S[r:]:
        r += 1

    ans = max(ans, r - l - 1)
    #print(l,r, S[l:r], S[r:], ans)
    l += 1
    if l == r:
        r = l + 1

print(ans)




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

using namespace std;

#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define REP3(i, m, n) for(int i = m, i##_len=(n);i < i##_len;i++)
#define FORVEC(i, v) for(int i = 0;i < v.size();i++)

#define INF 1000000000
#define pb(a) push_back(a)
#define llong long long
#define vi vector<int>
#define P pair<int,int>
#define all(vec) (vec.begin(),vec.end())

int main(){
	int n;
	set<int> se;
	
	cin>>n;
	REP(i,n){
		int t;
		cin>>t;
		if(se.find(t)!=se.end()){
			se.erase(t);
		}else{
			se.insert(t);
		}
	}
	cout<<se.size()<<"\n";
	
	return 0;
}

Measured memory_bytes: 4864
#include<iostream>
#include<vector>
using namespace std;
int n,h[128];
vector<int> v;
int solve(int a){
  int d = v[1] - v[0];
  for(int i = 2;i < v.size(); i++){
    if(v[i] - v[i-1] != d) return 0;
    if(i == v.size()-1){
      cout << h[a] << endl;
      return 1;
    }
  }
}
int main(void){
  while(cin >> n,n){
    for(int i = 0;i <= n; i++) cin >> h[i];
    for(int i = 0;i <= n; i++){
      v.clear();
      for(int j = 0;j <= n; j++){
	if(i == j) continue;
	v.push_back(h[j]);
      }
      if(solve(i)) break;
    }
  }
}


Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int a, b, c, d;
  cin >> N;
  a=N/1000;
  b = (N-a*1000)/100;
  c = (N-a*1000-b*100)/10;
  d = (N-a*1000-b*100-c*10);
  if(a==b &&b==c)
    cout << "Yes" <<endl;
  else if(b==c&&c==d)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a.at(i);
  
  if(a.at(0) != 0){
    cout << -1 << '\n';
    return 0;
  }
  
  for(int i = 0; i < n - 1; i++){
    if(a.at(i) + 1 < a.at(i + 1)){
      cout << -1 << '\n';
      return 0;
    }
  }
  
  long long ans = 0, keep;
  for(int i = n - 1; i >= 0; i--){
    keep--;
    if(a.at(i) > keep){
      ans += a.at(i);
      keep = a.at(i);
    }
  }
  
  cout << ans << '\n';
}

Measured memory_bytes: 1024
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int n;
V<int> w;
V< V<int> > dp;

int rec(ll l, ll r) {
    if (l == r) return 0;
    if (l + 1 == r) return (abs(w[l] - w[r]) <= 1 ? 2 : 0);
    if (dp[l][r] != -1) return dp[l][r];
    else {
        if (abs(w[l] - w[r]) <= 1 && rec(l + 1, r - 1) == r - l - 1) return dp[l][r] = r - l - 1 + 2;
        else {
            int ret = 0;
            for (int m = l; m < r; m++) chmax(ret, rec(l, m) + rec(m + 1, r));
            return dp[l][r] = ret;
        }
    }
    return 0;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(true) {
        cin >> n;
        if (n == 0) break;
        w.resize(n);
        for (int i = 0; i < n; i++) cin >> w[i];
        dp.resize(n, V<int>(n));
        for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) dp[i][j] = -1;
        cout << rec(0, n - 1) << '\n';
    }
    
    return 0;
}



Measured memory_bytes: 3408
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static readonly int[] root = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2, 1 };

        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            int n = int.Parse(Console.ReadLine());

            for (int i = 0; i < n; i++)
            {
                string[] input = Console.ReadLine().Split(' ');
                int s = int.Parse(input[0]);
                int t = int.Parse(input[1]);

                if (s > t && s <= 5)
                {
                    while (root[s] != root[t])
                    {
                        sb.Append(root[s] + " ");
                        s--;
                    }
                    sb.AppendLine(root[t].ToString());
                }
                else
                {
                    while (root[s] != root[t])
                    {
                        sb.Append(root[s] + " ");
                        s = (s + 1) % 15;
                    }
                    sb.AppendLine(root[t].ToString());
                }
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 9140
#include <stdio.h>

int main(void)
{
    while(1){
        int n;
        scanf("%d",&n);
        if( n<=0 ) break ;
        int n1=0,n2=0;
        for( int i=0;i<n;i++ ){
            int c1,c2;
            scanf("%d %d",&c1,&c2);
            if( c1>c2 ) n1+=c1+c2;
            else
            if( c1<c2 ) n2+=c1+c2;
            else
                n1+=c1,n2+=c2;
        }
        printf("%d %d\n",n1,n2);
    }
    return 0 ;
}

Measured memory_bytes: 1028
n,m=map(int,input().split())
s=[list(map(int,input().split())) for _ in range(m)]
*p,=map(int,input().split())
a=0
for i in range(2**n):
    a+=all(sum((i>>(k-1))&1 for k in s[j][1:])%2==p[j] for j in range(m))
print(a)

Measured memory_bytes: 3060
int main()
{
  int n;
  scanf("%d", &n);
  int a[n];
  int cnt = 0, num = 1;
  for (int i = 0; i < n; i++)
  {
    scanf("%d", &a[i]);
    if (num != a[i])
    {
      cnt++;
    }
    else if (num == a[i])
    {
      num++;
    }
  }
  if (cnt == n)
  {
    printf("-1");
    return 0;
  }
  printf("%d", cnt);
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
using P = pair<int,int>;
vector<double> p;
double dp[3300][3300];
int main()
{
    int n;
    cin >> n;
    p.resize(n);
    rep(i,n)cin >> p[i];
    dp[0][0] = 1;
    rep(i,n)rep(j,n){
            dp[i+1][j+1] += dp[i][j]*(1-p[i]);
      
            dp[i+1][j] += dp[i][j]*p[i];
        
    }
    double ans = 0;
    for(int i = 0;i<= n/2;i++)ans+=dp[n][i];
    printf("%.10lf\n",ans);


    return 0;
}

Measured memory_bytes: 78080
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <ctime>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 999999999

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

namespace std {
    bool operator<(const P a, const P b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int const MOD = 1000000007;

int main() {
    int W,N;
    int c = 0;
    while(cin >> W) {
        if(W == 0) break;
        c++;
        cin >> N;
        int v[1010], w[1010];

        rep(i,0,N) scanf("%d,%d",&v[i], &w[i]);
        int dp[1010][1010];
        rep(j,0,W+1) dp[0][j] = 0;
        rep(i,0,N) {
            rep(j,0,W+1) {
                if(j < w[i]) dp[i+1][j] = dp[i][j];
                else dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]] + v[i]);
            }
        }

        int a = 0, b = 0;
        rep(i,0,W+1) {
            if(dp[N][i] > a) {
                a = dp[N][i];
                b = i;
            }
        }

        printf("Case %d:\n", c);
        cout << a << endl;
        cout << b << endl;
    }

    return 0;
}

Measured memory_bytes: 5228
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<map>
#include<queue>
#include<set>

using namespace std;
typedef pair<int,int> PII;
typedef long long ll;

vector<string> decode;
vector<string> encode;
string character = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?";

void code(){
	decode.push_back("100101");
	decode.push_back("10011010");
	decode.push_back("0101");
	decode.push_back("0001");
	decode.push_back("110");
	decode.push_back("01001");
	decode.push_back("10011011");
	decode.push_back("010000");
	decode.push_back("0111");
	decode.push_back("10011000");
	decode.push_back("0110");
	decode.push_back("00100");
	decode.push_back("10011001");
	decode.push_back("10011110");
	decode.push_back("00101");
	decode.push_back("111");
	decode.push_back("10011111");
	decode.push_back("1000");
	decode.push_back("00110");
	decode.push_back("00111");
	decode.push_back("10011100");
	decode.push_back("10011101");
	decode.push_back("000010");
	decode.push_back("10010010");
	decode.push_back("10010011");
	decode.push_back("10010000");
	decode.push_back("101");
	decode.push_back("010001");
	decode.push_back("000011");
	decode.push_back("10010001");
	decode.push_back("000000");
	decode.push_back("000001");
	
	for(int i=0;i<32;i++){
		int k=i;
		string line = "";
		for(int j=0;j<5;j++){
			if(k%2)
				line = "1" + line;
			else
				line = "0" + line;
			k/=2;
		}
		encode.push_back(line);
	}
}

string CodeToNum(string line){
	string nums = "";
	for(int i=0;i<line.size();i++){
		nums = nums + encode[character.find(line[i])];
	}
	return nums;
}

string NumToText(string nums){
	string text = "";
	bool findch;
	while(true){
		int findnum;
		findch = false;
		for(findnum=0;findnum<32;findnum++){
			if(decode[findnum] == nums.substr(0,decode[findnum].size())){
				findch = true;
				break;
			}
		}
		if(!findch)break;
		text = text + character[findnum];
		nums = nums.substr(decode[findnum].size());
	}
	return text;
}

int main(){
	code();
	string line;
	while(getline(cin,line,'\n')){
		cout<<NumToText(CodeToNum(line))<<endl;
	}
  return 0;
}

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

int N;
int a[20];
int x[20][20];
int y[20][20];

int counter(int x) {
    if(x == 0) return 0;
    return counter(x >> 1) + (x & 1);
}

int main() {
    cin >> N;
    for(int i=1; i<=N; i++){
        cin >> a[i];
        for(int j=1; j<=a[i]; j++) cin >> x[i][j] >> y[i][j];
    }
    int ans = 0;
    for(int bits=1; bits<(1 << N); bits++){
        bool ok = true;
        for(int i=1; i <= N; i++){
            if(!(bits & (1 << (i-1)))) continue;
            for(int j=1; j <= a[i]; j++)
                if(((bits >> (x[i][j]-1)) & 1) ^ y[i][j]) ok = false;
        }
        if(ok) ans = max(ans, counter(bits));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <deque>
using namespace std;

int main()
{
    int a[5];
    for(int i=0;i<5;i++)
    {
        cin>>a[i];
        if(a[i]==0)
        {
            cout<<i+1;
        }
    }
}



Measured memory_bytes: 3576
N, M = map(int, input().split())
# 都市Aと都市Bを結ぶ路線M
A_B = [list(map(int, input().split())) for _ in range(M)]
ans = [0] * N

for a, b in A_B:
    ans[a-1] += 1
    ans[b-1] += 1
for a in ans:
    print(a)


Measured memory_bytes: 9148
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll mod=1e9+7;
int dy[]={1,-1,0,0};
int dx[]={0,0,1,-1};

int main(){
  double W,H,x,y;
  cin>>W>>H>>x>>y;

  printf("%.15f",W*H/2.00);

  if(x==W/2.0&&y==H/2.0){
    cout<<" "<<1<<endl;
  }else{
    cout<<" "<<0<<endl;
  }

  return 0;
}



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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

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

typedef long long ll;
typedef pair<int, int> p;

struct unko {
  int a;
  int b;
  int diff;
};

bool cmp(const unko &a, const unko &b)
{
  // desc
  return a.diff > b.diff;
}

int main(){
  int n;
  cin >> n;
  // vector<int> a(n, 0);
  // vector<int> b(n, 0);
  vector<unko> v(n);

  ll sumA = 0;
  ll sumB = 0;
  ll res = 0;

  for (int i = 0; i < n; i++)
  {
    cin >> v[i].a;
    sumA += v[i].a;
  }
  ll tmp = 0;
  for (int i = 0; i < n; i++)
  {
    cin >> v[i].b;
    v[i].diff = v[i].a - v[i].b;
    if(v[i].a < v[i].b){
      res++;
      tmp += abs(v[i].diff);
    }
    sumB += v[i].b;
  }

  sort(all(v), cmp);

  if(sumA < sumB){
    cout << -1 << endl;
    return 0;
  }


  ll count = 0;
  for (int i = 0; i < n; i++) {
    // int a = v[i].first;
    // int b = v[i].second;
    if(tmp > count && v[i].a > v[i].b){
      count += v[i].diff;
      res++;
    }
  }

  cout << res << endl;


}


Measured memory_bytes: 1408
#include <stdio.h>

//問題文より、入力される表の最大の大きさ(100)+1の大きさを要素数とする
#define MAX_ROW 101
#define MAX_COLUMN 101

//関数プロトタイプ宣言
void set_sum(long int body[MAX_ROW][MAX_COLUMN], int row, int column);

//表の構造体
typedef struct{
	int row;
	int column;
	long int body[MAX_ROW][MAX_COLUMN];
}Table;

int main(void)
{
	//メンバーを0で初期化
	Table new_table = {0, 0, 0};

	//ループ変数
	int i, j;

	//表の大きさを入力
	scanf("%d %d", &new_table.row, &new_table.column);

	//表のデータを入力
	for(i = 0; i < new_table.row; i++){
		for(j = 0; j < new_table.column; j++){
			scanf("%ld", &(new_table.body[i][j]));
		}
	}
	//各行列の合計値をセット
	set_sum(new_table.body, new_table.row, new_table.column);

	//表のデータを出力
	for(i = 0; i < (new_table.row + 1); i++){
		for(j = 0; j < new_table.column; j++){
			printf("%ld ", new_table.body[i][j]);
		}
		//最後の数値の後にスペースがある場合はエラーとなる
		printf("%ld\n", new_table.body[i][j]);
	}

	return 0;
}

//表に合計値を挿入する関数
void set_sum(long int body[MAX_ROW][MAX_COLUMN], int row, int column)
{
	//ループ変数
	int i, j;

	for(i = 0; i < row; i++){
		for(j = 0; j < column; j++){
			//行の合計値
			body[i][column] += body[i][j];
			//列の合計値
			body[row][j] += body[i][j];
		}
		//行列全体の合計値
		body[row][column] += body[i][column];
	}
}


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

int main(int argc, char const *argv[])
{
    int n,T;cin>>n>>T;
    vector<int> v;
    for(int i=0;i<n;++i){
        int c,t;
        cin>>c>>t;
        if(t<=T)v.push_back(c);
    }
    if(v.empty())cout << "TLE"<<endl;
    else{
        sort(v.begin(),v.end());
        cout<<v[0]<<endl;
    }
    
    return 0;
}


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

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
	/* your code */
	NodePointer cur = nil->next;
	while( cur != nil && cur->key != key ){
		cur = cur->next;
	}
	
	return cur;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  /* your code */
	t->prev->next = t->next;
	t->next->prev = t->prev;
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  /* your code */
	NodePointer t = nil->prev;
	if ( t == nil ) return;
	deleteNode(t);
}

void delete(int key){
  /* your code */
	NodePointer t = listSearch(key);
	if ( t == nil ) return;
	deleteNode(t);
}

void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  	x->key = key;
  	x->next = nil->next;
  	nil->next->prev = x;
 	nil->next = x;
 	x->prev = nil;
}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++; 
      }
      size--;
    }
  }

  printList();
  return 0;
}


Measured memory_bytes: 36092
#include<stdio.h>
#include<vector>
#define M 1000000007
using namespace std;
vector<int> a;
int l[200];
int r[200];
long long dp[200][200];

int main(){
	int n,i,j,k;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		char c;
		scanf(" %c",&c);
		if(c=='U')a.push_back(1);
		if(c=='D')a.push_back(0);
	}
	n=a.size();
	if(n==0){
		puts("1");
		return 0;
	}
	int s=0;
	for(i=n-1;i>=0;i--){
		r[i]=s;
		if(a[i]==0)s++;
	}
	s=0;
	for(i=0;i<n;i++){
		l[i]=s;
		if(a[i]==1)s++;
	}
	for(i=0;i<n;i++){
		for(j=0;j<s;j++){
			long long res=0;
			long long sum=1;
			for(k=i-1;k>=0;k--){
				if(j>0)res=(res+dp[k][j-1]*sum)%M;
				sum=sum*(r[k]-((n-k-1)-(s-j)))%M;
			}
			if(j>0)dp[i][j]=res*(l[i]-j)%M;
			else dp[i][j]=sum*l[i]%M;
		}
	}
	long long ans=0;
	long long sum=1;
	for(i=n-1;i>=0;i--){
		ans=(ans+dp[i][s-1]*sum)%M;
		sum=sum*(r[i]-(n-i-1))%M;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1356
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = replicateM 3 getLine >>= putStrLn . map ( uncurry ( flip (!!) ) ) . zip [ 0 .. ]


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

#define ll long long
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ff first
#define ss second

using namespace std;

const double pi = acos(-1);
const int N = 1e6 + 6, mod = 998244353, M = 1e7 + 7;
const ll MAX = 5e18;

int r;

int main()
{
    cin >> r;
    printf("%.9f", 2 * pi * r);
    return 0;
}


Measured memory_bytes: 3748
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int a[4];
  for(int i=0;i<4;i++) cin>>a[i];
  sort(a,a+4);
  if(!(a[0]-a[1]||a[2]-a[3])) cout<<"yes"<<endl;
  else cout<<"no"<<endl;
}

Measured memory_bytes: 3164
a =  input().split()  #[W, H, x, y, r]
a = list(map(int, a))

w = a[0]
h = a[1]
x = a[2]
y = a[3]
r = a[4]

if x >= r and y >= r and w >= x + r and h >= y + r:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
const int N = 1e3 + 11;
const int M = 5e3 + 11;
int dp[N], n, fa[N], x[N], f[M];
int head[N], to[N], nex[N], size;
void add(int x, int y){
    to[++size] = y;
    nex[size] = head[x];
    head[x] = size;
}
bool dfs(int u){
    for(int i = head[u];i;i = nex[i]){
        int v = to[i];
        if(!dfs(v))return 0;
    }
    memset(f, 127 / 9, sizeof(f));
    f[0] = 0;
    for(int i = head[u];i;i = nex[i]){
        int v = to[i];
        for(int j = x[u];j >= 0; j--){
            if(f[j] == f[x[u]+1])continue;
            int tmp = f[j];
            f[j] = dp[0];
            if(j + x[v] <= x[u]){
                f[j+x[v]] = min(f[j+x[v]], tmp + dp[v]);
            }
            if(j + dp[v] <= x[u]){
                f[j+dp[v]] = min(f[j+dp[v]], tmp + x[v]);
            }
        }
    }
    //printf("u=%d\n", u);
    for(int i = 0;i <= x[u]; i++){
        dp[u] = min(dp[u], f[i]);
        //printf("i=%d f=%d\n", i, f[i]);
    }
    if(dp[u] == dp[0])return 0;
    else return 1;
}
int main(){
    //freopen("arc083.in", "r", stdin);
    cin>>n;
    for(int i = 2;i <= n; i++){
        cin>>fa[i];
        add(fa[i], i);
    }
    for(int i = 1;i <= n; i++){
        cin>>x[i];
    }
    memset(dp, 127 / 9, sizeof(dp));
    if(!dfs(1))puts("IMPOSSIBLE");
    else puts("POSSIBLE");
    return 0;
}


Measured memory_bytes: 256
class UnionFind
  def initialize(n)
    @n = n
    @parent = Array.new(n){|i|i}
    @rank = Array.new(n, 0)
  end

  def find(x)
    if @parent[x] == x
      return x
    else
      return @parent[x] = find(@parent[x])
    end 
  end

  def unite(x, y)
    x = find(x)
    y = find(y)
    return if x == y
    if @rank[x] < @rank[y]
      @parent[x] = y
    else
      @parent[y] = x
      @rank[x] += 1 if @rank[x] == @rank[y]
    end
  end

  def same?(x, y)
    find(x) == find(y)
  end

  def num_of_cimponent
    h=Hash.new(0)
    @n.times{|i|
      h[find(i)]+=1
    }
    h.keys.size
  end
end

n,m=gets.split.map(&:to_i)
uf=UnionFind.new(n)
m.times{
  x,y,z=gets.split.map(&:to_i)
  uf.unite(x-1,y-1)
}

puts uf.num_of_cimponent

Measured memory_bytes: 10620
#gcdは3.4.3だとfractionsにある
from fractions import gcd

from math import factorial as f

from math import ceil,floor,sqrt

from sys import exit

from copy import deepcopy
import numpy as np

import bisect







def main():
    s = list(input())
    s = list(map(int, s))
    scopy = deepcopy(s)
    scopy[0] ^= 1

    cnt = 0
    cntc = 1
    for i in range(1,len(s)):
        if s[i] == s[i-1]:
            s[i] ^= 1
            cnt += 1
        if scopy[i] == scopy[i-1]:
            scopy[i] ^= 1
            cntc += 1
    print(min(cnt,cntc))







main()

Measured memory_bytes: 15436
#include <iostream>
#define llint long long

using namespace std;

llint h, w;
llint H, W;
llint s[1<<10][1<<10];

void calc(llint n)
{
	if(n == 0) return;
	
	calc(n-1);
	llint N = 1<<n;
	for(int y = 0; y < N; y++){
		for(int x = 0; x < N; x++){
			s[x][y] = s[x%(N/2)][y%(N/2)];
			if(x >= N/2 && y >= N/2) s[x][y] = 1 - s[x][y];
		}
	}
}

int main(void)
{
	cin >> h >> w;
	H = 1<<h, W = 1<<w;
	
	calc(10);
	
	for(int i = 1; i < H; i++){
		for(int j = 1; j < W; j++){
			cout << (s[i][j] ^ s[i-1][j] ^ s[i][j-1] ^ s[i-1][j-1]);
		}
		cout << endl;
	}
	
	return 0;
}

Measured memory_bytes: 9472
fn main() {
    let _ = read::<usize>();
    let v = read_vec::<u64>();
    const MOD: u64 = 1000000007;
    let d = 64;

    let mut cnt = vec![vec![0, 0]; d];
    for a in v.iter() {
        for j in 0..d {
            if (1 << j) & a != 0 {
                cnt[j][1] += 1;
            } else {
                cnt[j][0] += 1;
            }
        }
    }

    let mut ret = 0;
    for i in 0..d {
        ret += ((cnt[i][0] * cnt[i][1] % MOD) * exp2(i)) % MOD;
        ret %= MOD;
    }
    println!("{}", ret)
}

fn exp2(n: usize) -> u64 {
    const MOD: u64 = 1000000007;
    if n == 0 {
        1
    } else {
        let tmp = 2 * exp2(n - 1);
        tmp % MOD
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}


Measured memory_bytes: 14456
#include<stdio.h>

#define INFTY 2000000000
void margeSort(int, int);
void marge(int, int, int);

int a[500000], le[500000], ri[500000];
int cnt = 0;

int main(){
  int n, i;

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

  margeSort(0, n);

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

  return 0;
}

void margeSort(int l, int r){
  int m;
  if(l+1 < r){
    m = (l + r)/2;
    margeSort(l, m);
    margeSort(m, r);
    marge(l, m, r);
  }
}

void marge(int l, int m, int r){
  int n1 = m - l;
  int n2 = r - m;
  int i, j, k;

  for(i = 0; i < n1; i++) le[i] = a[l + i];
  for(i = 0; i < n2; i++) ri[i] = a[m + i];

  le[n1] = ri[n2] = INFTY;
  i = j = 0;

  for(k = l; k < r; k++){
    cnt++;
    if(le[i] <= ri[j]){
      a[k] = le[i];
      i++;
    }else{
      a[k] = ri[j];
      j++;
    }
  }
}



Measured memory_bytes: 5612
N=int(input())
A=[]
for i in range(N):
    A.append(int(input()))

B=sorted(A)

C=[]
D=[]

for i in range(N):
    if i%2==0:
        C.append(A[i])
        D.append(B[i])
        
print((N+1)//2-len(set(C) & set(D)))

Measured memory_bytes: 15564
S = input()
N = len(S) + 1
ans = [0] * N
lc, rc = 0, 0
for i in range(N - 1):
    if S[i] == '<':
        ans[i + 1] = ans[i] + 1

for i in range(N - 1):
    if S[N - i - 2] == '>' and ans[N - i - 2] <= ans[N - i - 1]:
        ans[N - i - 2] = ans[N - i - 1] + 1

print(sum(ans))


Measured memory_bytes: 46544
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;
 
#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll MAX_N = 100000;

int main(void){
    ll N, K;
    ll h[MAX_N];
    ll answer = 1e9;
    cin >> N >> K;
    rep(i, N) cin >> h[i];

    sort(h, h + N);
    rep(i, N - K + 1) answer = min(h[i + K - 1] - h[i], answer);

    cout << answer << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
const lint MOD = pow(10, 9) + 7;



int main() {
	int A, B;
	cin >> A >> B;
	int a = max(A, B);
	int b = min(A, B);
	rep(i, a) {
		cout << b;
	}
	cout << endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10000000)
input = sys.stdin.readline
from math import log
from collections import deque

def solve():
    N, Q = map(int, input().split())
    es = [[] for i in range(N+1)]
    for i in range(N-1):
        u, v, c, d = map(int, input().split())
        es[u].append([v, c, d])
        es[v].append([u, c, d])
    LOG_N = int(log(N, 2)) + 1
    parent = [[-1] * (N+1) for i in range(LOG_N)]
    level = [None] * (N+1)
    level[1] = 0
    dq = deque()
    dq.append(1)
    while dq:
        v = dq.popleft()
        p = parent[0][v]
        lv = level[v]
        for u, c, d in es[v]:
            if u != p:
                parent[0][u] = v
                level[u] = lv + 1
                dq.append(u)
    for k in range(LOG_N-1):
        parentk = parent[k]
        for v in range(1, N+1):
            if parentk[v] < 0:
                parent[k+1][v] = -1
            else:
                parent[k+1][v] = parentk[parentk[v]]

    def lca(u, v):
        if level[u] > level[v]:
            u, v = v, u
        for k in range(LOG_N)[::-1]:
            if (level[v] - level[u]) >> k & 1:
                v = parent[k][v]
        if u == v:
            return u
        for k in range(LOG_N)[::-1]:
            if parent[k][u] != parent[k][v]:
                u, v = parent[k][u], parent[k][v]
        return parent[0][u]

    qs = [[] for i in range(N+1)]
    for i in range(Q):
        x, y, u, v = map(int, input().split())
        qs[u].append([i, x, y, 1])
        qs[v].append([i, x, y, 1])
        a = lca(u, v)
        qs[a].append([i, x, y, -2])
    ds = [0] * N
    cnt = [0] * N
    query = [0] * Q

    def EulerTour(v, p, d):
        for id, col, y, f in qs[v]:
            query[id] += f * (d + y * cnt[col] - ds[col])
        for u, c, _d in es[v]:
            if u != p:
                ds[c] += _d
                cnt[c] += 1
                EulerTour(u, v, d + _d)
                ds[c] -= _d
                cnt[c] -= 1

    EulerTour(1, -1, 0)
    for res in query:
        print(res)

if __name__ == '__main__':
    solve()


Measured memory_bytes: 208992
N=int(input())
A=[int(x) for x in input().split()]

def solve(li,n):
  cnt=sum(li)
  s=((n+1)*n)//2
  if cnt % s !=0:
    print("NO")
    return
  
  cnt//=s
  
  ch=[cnt for x in range(n)]
  res=[]
  for i in range(n-1):
    res.append(li[i+1]-li[i])
  res.append(li[0]-li[-1])
  
  for i in range(n):
    if ch[i] != res[i]:
      if abs(ch[i]-res[i]) % n !=0:
        print("NO")
        return
      else:
        cnt-=abs(ch[i]-res[i])//n
  if cnt==0:
    print("YES")
    return
  else:
    print("NO")
    return

solve(A,N)

Measured memory_bytes: 14996
N, L, T = gets.split.map(&:to_i)
XW = N.times.map { gets.split.map(&:to_i) }

X0, W0 = XW.first
num = 0
rotate_count = T / L
rotate_len = T % L
1.upto(N - 1) do |i|
  x, w = XW[i]
  next if w == W0
  num += rotate_count * 2
  if W0 == 1
    d = x - X0
    num += 1 if rotate_len * 2 > d
    num += 1 if rotate_len * 2 > d + L
  else
    d = L + X0 - x
    num += 1 if rotate_len * 2 >= d
    num += 1 if rotate_len * 2 >= d + L
  end
end

new_x = XW.map do |x, w|
  x = x + rotate_len * (w == 1 ? 1 : -1)
  x %= L
end

new_x0 = new_x.first
new_x.sort!
pos = new_x.find_index(new_x0)
new_x = new_x.rotate(W0 == 1 ? pos - num : pos + num)
puts new_x


Measured memory_bytes: 22396
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()

cnt = 0

b_map = {}
c_index = 0
all = 0
for i in range(N):
    b = B[i]
    c = C[c_index]
    countable = True
    while(b >= c):
        if c_index == N-1:
            countable = False
            break
        c_index += 1
        c = C[c_index]
    if countable:
        b_map[i] = N-c_index
        all += b_map[i]
    else:
        b_map[i] = 0
m = {}
for i in range(N):
    if i > 0:
        m[i] = m[i-1] - b_map[i-1]
    else:
        m[i] = all

b_index = 0
for i in range(N):
    a = A[i]
    b = B[b_index]
    countable = True
    while(a >= b):
        if b_index == N-1:
            countable = False
            break
        b_index += 1
        b = B[b_index]
    if countable:
        cnt += m[b_index]

print(cnt)


Measured memory_bytes: 46488
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define ld long double
#define fo(i,v,e) for(v=i;v<e;v++)
#define rfo(i,v,e) for(v=i;v>e;v--)
#define pb(x) push_back(x)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fi first 
#define se second
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vl vector<ll>
#define sz(x) (int)x.size()
#define ull unsigned long long
#define vvi vector<vi>
#define vvl vector<vl>
#define vpi vector<pii>
#define vpl vector<pll>
ll mod = 1000000007;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define openfile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x);
#define fastio
#else
#define openfile
#define deb(x...)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#endif
void init()
{
    
}
void solve()
{
    ll n,i,j;cin>>n;
    cout<<(1000-n%1000)%1000;
}
int main()
{
    init();
    // openfile;fastio;
    int T = 1;
    // cin>>T;
    while(T--)
    {
        solve();
    }
}

Measured memory_bytes: 3636
n = int(input())
p = [int(x) for x in input().split()]

num = 0
for i in range(len(p) - 2):
    n3 = sorted([p[i], p[i + 1], p[i + 2]])
    if n3[1] == p[i + 1]:
        num = num + 1

print(num)



Measured memory_bytes: 2940
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<map>
#include<queue>
#include<set>
#include<bitset>
#include<stdio.h>
#include<deque>
#include<iomanip>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;

int main()
{
    const int d = 7, c = 4;
    int n, ans = 0;
    cin >> n;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(n == (i*c)+(j*d)){
                ans++;
            }
        }
    }
    if(ans != 0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
L = []
for i in range(m):
    a,b = map(int, input().split())
    L.append((a,b))

st,go = [],[]
for i in range(m):
    if 1 in L[i]:
        st.append(L[i][1])
    if n in L[i]:
        go.append(L[i][0])

if set(st)&set(go):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")


Measured memory_bytes: 39236
#include<stdio.h>

int main(void){
	int a, i, j;
	
	for(i=1;i<10;i++){
		for(j=1;j<10;j++){
			a = i * j;
			printf("%dx%d=%d\n", i, j, a);
		}
	}
	return 0;
}

Measured memory_bytes: 0
# bit 全探索
INF = 10 ** 7
n, m, x = gets.split.map(&:to_i)
books = []
n.times { books << gets.split.map(&:to_i) }
ans = INF
(2 ** n).times do |num|
  skill = Array.new(m, 0)
  price = 0
  n.times do |i|
    next if num[i] == 0
    book = books[i]
    price += book.first
    book[1..-1].each_with_index do |up, alg|
      skill[alg] += up
    end
  end
  ans = price if ans > price && skill.min >= x
end
puts ans == INF ? -1 : ans


Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;
ul over = 1000000007;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int a, b, c;
  cin >> a >> b >> c;
  if (a==b) cout << c << endl;
  else if (b==c) cout << a << endl;
  else cout << b << endl;
  return 0;
}


Measured memory_bytes: 256
MOD = 10**9 + 7

L = input()

dp1 = [0]*100010 # dp1[k]: 先頭からk桁について，A+B < L が確定している (A,B) の数
dp2 = [0]*100010 # dp2[k]: 先頭からk桁について，A+B と L が一致している (A,B) の数
dp1[1], dp2[1] = 1, 2

for i in range(1,len(L)):
    for digit_A, digit_B in [[0,0],[0,1],[1,0]]:
            dp1[i+1] += dp1[i]

            if digit_A + digit_B == int(L[i]):
                dp2[i+1] += dp2[i]
            elif digit_A + digit_B < int(L[i]):
                dp1[i+1] += dp2[i]
            
            dp1[i+1] %= MOD
            dp2[i+1] %= MOD

ans = dp1[len(L)] + dp2[len(L)]
print(ans % MOD)

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

int main(){
  int n,p;
  int per[50];
  int wan;
  int idx;
  while(cin>>n>>p,n|p){
    memset(per,0,sizeof(per));
    wan=p;
    idx=0;
    while(1){
      if(idx==n)idx=0;
      if(wan){
	wan--;
	per[idx]++;
	if(per[idx]==p)break;
      }
      else{
	wan=per[idx];
	per[idx]=0;
      }
      idx++;
    }
    cout<<idx<<endl;
  }
}

Measured memory_bytes: 1160
#coding:utf-8

def is_even(n):
    if n%2 == 0:
        return True
    else:
        return False


N = int(input())
A = list(map(int,input().split()))
 
c = 0
for i in range(N):
    if is_even(A[i]):
        tmp = A[i]

        while is_even(tmp):
            c += 1
            tmp = tmp / 2
            
            if is_even(tmp) == False:
                break

    else:
        continue
    
print(c)

Measured memory_bytes: 4148
n,m,p=map(int,input().split())
edge=[]
for i in range(m):
    a,b,c=map(int,input().split())
    edge.append((a,b,p-c))
INF=float('inf')
def bellmanford(s,n):
    d = [INF for i in range(n+1)]
    d[s]=0
    for i in range(n-1):
        for a,b,c in edge:
            if d[b]>d[a]+c:
                d[b]=d[a]+c
    for i in range(n-1):
         for a,b,c in edge:
            if d[b]>d[a]+c:
                d[b]=-INF
    return d
d=bellmanford(1,n)
if d[n]==-INF:
    print(-1)
elif d[n]>=0:
    print(0)
else:
    print(-d[n])

Measured memory_bytes: 50156
//****************************//
/**********  main *************/
//****************************//
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#include <math.h> 

using namespace std;
typedef long long ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i, n) for (i = 0; i < n; i++)
#define FOR(i, a, b) for (i = a; i < b; i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())

int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

int main()
{

    std::cin.tie(0);
    const double PPI=3.14159265358979323846;

    double r ;
    cin >> r ;

    double res;

    res = 2 * r * PPI;

    cout << res << endl;

    return 0;
}



Measured memory_bytes: 3788