akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define fr first
#define sc second
typedef long long ll;
const int N=1e5+5;
const int p=1e9+7;
#define PI acos(-1)
ll qpow(ll a,ll n){ll res=1;while(n){if(n&1)res=res*a%p;a=a*a%p;n>>=1;}return res;}
void work()
{
    int n;
    scanf("%d",&n);
    printf("%.5f\n",n*2*PI);
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int T=1;
    //scanf("%d",&T);
    //cin>>T;
    while(T--){
        work();
    }
}

Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define rep(i,j,n)   for(ll i=j;i<n;i++)
#define scn(a)       scanf("%lld",&a)
#define nl           printf("\n")
#define scns(a,b)    scanf("%lld %lld",&a,&b)
#define print(a)     printf("%lld",a)
#define tc           ll t; scn(t); while(t--)
#define vec          vector<ll>
#define pb           push_back
#define pairs        pair<ll,ll>
#define fi            first
#define se            second
#define all(v)       v.begin(),v.end()
#define srt(v)       sort(v.rbegin(),v.rend())
#define mem(a,b)     memset(a,b,sizeof(a))
#define maxx         5000005
#define inf          LLONG_MAX
#define zer          LLONG_MIN
#define mp           make_pair
#define read(v)      vec v(n,0); rep(i,0,n) {cin>>v[i];}
#define write(a,n)     rep(i,0,n) {cout<<a[i]<<" ";}
#define All          rep(i,0,n)

int main()
{

ll n;
cin>>n;

ll k= 1;
while(k*1000 < n)
{
    k++;
}

cout << (k*1000 - n);
    

    return 0;
}

Measured memory_bytes: 3504
a,b,c = map(int, input().split())
if a % 2 == 0 or b % 2 == 0 or c % 2 == 0:
    print(0)
else:
    list_abc = [a,b,c]
    list_abc.sort()
    print(list_abc[0] * list_abc[1])


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main() {
    int K, A, B;
    cin >> K >> A >> B;
    if(B - B%K >= A){
        cout << "OK" << endl;
    }else{
       cout << "NG" << endl;
    };
    
}

Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
typedef long long int ll;

double ABS(double a,double b){
	if(a>b){
		return a-b;
	}
	else{
		return b-a;
	}
}

int main(){
	int n; cin >> n;
	vector<int> a(n);
	int sum=0;
	for(int i=0;i<n;i++){
		cin >> a[i];
		sum+=a[i];
	}
	double ave=1.0*sum/n;
	vector<double> b(n);
	for(int i=0;i<n;i++){
		b[i]=ABS(ave,(double)a[i]);
	}
	int ans=-1; double mi=1e9;
	for(int i=0;i<n;i++){
		if(mi>b[i]){
			mi=b[i];
			ans=i;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>


typedef long double ld;
typedef long long ll;

using namespace std;

int main() {
	int n;
	cin >> n;
	cout << (1000 - n % 1000) % 1000 << endl;
	return 0;
}


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

int main(){
    int N;
    cin>>N;
    vector<int> data;
    for(int i=0;i<N;i++){
        int x;
        cin>>x;
        data.push_back(x);
    }
    sort(data.begin(),data.end());

    cout<<data.at(N-1)-data.at(0)<<endl;
}

Measured memory_bytes: 256
n,k,c = map(int,input().split())
S = input()

left = [ -1 for i in range(k)]
right = [ -1 for i in range(k)]

pointer = 0
for l in range(k):

  for s in range(pointer,n):
    if S[s] == 'o':
      left[l] = s
      pointer = s+c+1
      break

pointer = n-1
for r in range(k):

  for s in range(pointer,-1,-1):
    if S[s] == 'o':
      right[r] = s
      pointer = s-c-1
      break

for l,r in zip(left, right[::-1]):
  if l==r:
    print(l+1)


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

using namespace std;

typedef long long ll;

#define debug(x) cout << #x << " : " << x << '\n';


// code //
const int N = 100100;
int n;
int h[N], dp[N];

int main() {
	cin >> n;
	for(int i = 0; i < n; ++i) 
		cin >> h[i];

	dp[0] = 0;
	dp[1] = abs(h[1] - h[0]);
	for(int i = 2; i < n; ++i) 
		dp[i] = min(dp[i-1] + abs(h[i-1] - h[i]), dp[i-2] + abs(h[i-2] - h[i]));

	cout << dp[n-1];
}

Measured memory_bytes: 4304
import java.util.*;
public class Main {

  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int para = s.nextInt();
    int n = s.nextInt();
    int[] arr = new int[n];

    for(int i=0;i<n;i++) {
      arr[i]=s.nextInt();
    }
    int[] d = new int[n];

    d[0]=arr[0]+para-arr[n-1];
    for(int i=1;i<n;i++) {
      d[i] =  arr[i]-arr[i-1];
    }
    int max = 0;
    for(int i=0;i<n;i++) {
      if(d[i]>max) 
        max = d[i];
    }
    System.out.println(para-max);
  }

 }

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

int main()
{
  int n;
  cin>>n;
  for(;n--;)
    {
      string s;
      cin>>s;
      string ans="";
      ans+=s[0];
      int now=0;
      if(s.size()>2 && s[1]=='-')
	now++;
      else
	now--;
      for(int i=3;i<s.size();i+=3)
	{	  
	  if(now<0)
	    {
	      ans=s[i]+ans;
	      now++;
	    }
	  else if(now>=ans.size())
	    {
	      ans+=s[i];	     
	    }
	  
	  if(i+1<s.size()-1)
	    {
	      if(s[i+1]=='-')
		now++;
	      else
		now--;
	    }
	}
      cout<<ans<<endl;
      
    }
}

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

int H, W, dp[55][55][55][55]; char c[55][55];

void init() {
	for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { for (int k = 0; k < H; k++) { for (int l = 0; l < W; l++) dp[i][j][k][l] = -(1 << 29); } } }
}

int solve(int px, int py, int qx, int qy) {
	if (px > qx || py > qy) return -(1 << 28);
	if (c[px][py] == '#' || c[qx][qy] == '#') return -(1 << 28);
	if ((qx - px) + (qy - py) == 0) return 0;
	if (dp[px][py][qx][qy] >= -(1 << 28)) return dp[px][py][qx][qy];

	int A1 = solve(px + 1, py, qx, qy);
	int A2 = solve(px, py + 1, qx, qy);
	int A3 = solve(px, py, qx - 1, qy);
	int A4 = solve(px, py, qx, qy - 1);

	int A5 = -(1 << 28);
	for (int i = px; i <= qx; i++) {
		for (int j = py; j <= qy; j++) {
			if ((i == qx && j == qy) || c[i][j] == '#' || c[i][j] == '.') continue;
			int t1 = solve(px, py, i, j) + solve(i, j + 1, qx, qy);
			int t2 = solve(px, py, i, j) + solve(i + 1, j, qx, qy);
			A5 = max({ A5, t1, t2 });
		}
	}
	int A6 = -(1 << 28);
	if (c[px][py] - c[qx][qy] == 32 && 'a' <= c[px][py] && c[px][py] <= 'z') {
		int B1 = solve(px + 1, py, qx - 1, qy);
		int B2 = solve(px + 1, py, qx, qy - 1);
		int B3 = solve(px, py + 1, qx - 1, qy);
		int B4 = solve(px, py + 1, qx, qy - 1);
		A6 = max({ B1, B2, B3, B4 }) + 1;
		if ((qx - px) + (qy - py) == 1) A6 = max(A6, 1);
	}

	int Score = max({ A1, A2, A3, A4, A5, A6 }); if (Score < 0) Score = -(1 << 28);
	dp[px][py][qx][qy] = Score;
	return Score;
}

int main() {
	while (true) {
		cin >> H >> W; if (H == 0 && W == 0) break;
		init();
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) cin >> c[i][j];
		}
		int ret = solve(0, 0, H - 1, W - 1);
		if (ret == -(1 << 28)) ret = -1;
		cout << ret << endl;
	}
	return 0;
}


Measured memory_bytes: 32796
S = int(input(""))
h = 0
m = 0
s = 0

if S >= 3600:
    h = int(S / 3600)
    S = S - (h * 3600)
    
if S >= 60:
    m = int(S / 60)
    S = S - (m * 60)
    
s = S

print(f"{h}:{m}:{s}")


Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
const ll longinf=1ll<<60;
const int inf=(1<<30)-1;

int main(){
    ll n;
    cin>>n;
    ll s[n];
    rep0(i,n){
        cin>>s[i];
    }
    ll ans=0;
    rep1(d,n-1){
        ll p=(n-1)/d;
        ll pos=0;
        rep0(i,p+1){
            if(n-d*i>=d&&d*i!=n-1-d*i&&d*(i-1)!=n-1-d*i){
                pos+=(s[d*i]+s[n-1-d*i]);
                ans=max(pos,ans);
            }
            else{
                break;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
from collections import deque
n, q = list(map(int, input().split()))
a = [deque([]) for i in range(n)]
for _ in range(q):
  q = list(map(int, input().split()))
  if q[0]==0:
    a[q[1]].append(q[2])
  elif q[0]==1:
    if len(a[q[1]])>0:
      print(a[q[1]][0])
  elif q[0]==2:
    if len(a[q[1]])>0:
      a[q[1]].popleft()


Measured memory_bytes: 14476
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

using namespace std;

int main() {
    int A, B, C, D; cin >> A >> B >> C >> D;
    cout << min(A, B) + min(C, D) << endl;
}


Measured memory_bytes: 256
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
lint a[2525];
lint dp[2525][2525];
int main()
{
	int n;lint x;
	cin>>n>>x;
	rep(i,n) cin>>a[i];
	rep(i,n) rep(j,n+10) dp[i][j]=a[i];
	rep(j,n) rep(i,n){
		int ne=i+1;if(ne>=n) ne-=n;
		dp[ne][j+1]=min(dp[ne][j],dp[i][j]);
	}
	lint out=1145141919810364364LL;
	rep(i,n){
		lint sum=i*x;
		rep(j,n) sum+=dp[j][i];
		out=min(out,sum);
	}
	//rep(i,n) cout<<dp[i][2]<<endl;
	cout<<out<<endl;
}


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

#define ull unsigned long long
#define endl '\n'
#define ll long long
const int N = 5e2 + 5;
ll a[N], b[N], n, k;
bool chk(ll x){
        for (int i = 1; i <= n; i++){
                b[i] = a[i] % x;
        }
        sort(b + 1, b + n + 1);
        ll l = 1, r = n;
        ll cnt = 0;
        while (l < r){
                if (b[l] == 0) {
                        l++;
                        continue;
                }
                if (b[l] == (x - b[r])){
                        cnt += b[l];
                        r--;
                        l++;
                }
                else if (b[l] < (x - b[r])){
                        cnt += b[l];
                        b[r] += b[l];
                        l++;
                } else {
                        cnt += (x - b[r]);
                        b[l] -= (x - b[r]);
                        r--;
                }
        }
        return (cnt <= k);
}
int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        if (fopen(".INP", "r")){
                freopen(".INP", "r", stdin);
                freopen(".OUT", "w", stdout);
        }
        ll sum = 0;
        cin >> n >> k;
        for (int i = 1; i <= n; i++){
                cin >> a[i];
                sum += a[i];
        }
        ll ans = 1;
        for (int i = 1; i * i <= sum; i++){
                if (sum % i == 0) {
                        ll x = sum / i;
                        if (chk(x)) ans = max(ans, x * 1ll);
                        if (chk(i)) ans = max(ans, i * 1ll);
                }
        }
        cout << ans;
}


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimize("O3")
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
#include<set>
#include<vector>
#include<sstream>
#include<queue>
#include <iomanip>
#include<unordered_set>
#include <stack>
#include <unordered_map>
#include <map>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i+=1)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i-=1)
#define endl '\n'
#define N 1000000007 // prime modulo value 
#define M 998244353
#define all(x) x.begin(),x.end()
#define vll vector<ll>
using namespace std;
struct custom_hash
{
	static uint64_t splitmix64(uint64_t x)
	{
		// http://xorshift.di.unimi.it/splitmix64.c
		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}
};
#define safe_map unordered_map<ll, ll, custom_hash>

inline int mex(unordered_set<int> st)
{
	int m = 0;
	while (st.find(m) != st.end())
	{
		m += 1;
	}
	return m;
}
inline int calculateGrundy(int n)
{
	if (n == 1)
		return 0;
	unordered_set<int> mexi;
	for (int i = 1; i <= sqrt(n); i += 1)
	{
		if (n % i == 0)
		{
			if (n / i != n)
				mexi.insert(calculateGrundy(n / i));
			mexi.insert(calculateGrundy(i));
		}
	}
	return mex(mexi);
}
inline ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
ll power(ll x, ll y)
{
	ll res = 1;

	x = x % N;
	if (x == 0) return 0;
	while (y > 0)
	{
		if (y & 1)
			res = (res * x) % N;
		y = y >> 1;
		x = (x * x) % N;
	}
	return res;
}
void decToBinary(int n)
{
	// Size of an integer is assumed to be 32 bits 
	for (int i = 7; i >= 0; i--) {
		int k = n >> i;
		if (k & 1)
			cout << "1";
		else
			cout << "0";
	}
}
double compute(ll n, ll h, ll c)
{
	double ans = ((n + 1.00000) * h + n * c);
	ans /= 2.0000000000000 * n + 1;
	return ans;
}
ll count(ll n)
{
	return (2 * n) + 1;
}
int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll a;
	string b;
	cin >> a >> b;
	ll ba = 100 * (b[0] - '0');
	ba += 10*(b[2] - '0');
	ba += (b[3] - '0');
	ll ans = (a * ba);
	ans /= 100;
	cout << ans;
	return 0;
}

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

#define int long long

int n;

vector<int> v(3009);

pair<int, int> memo[3009][3009][2];

pair<int, int> dp(int left, int right, int player){
    if(left > right){
        return {0,0}; //TO CHECK
    }
    if(memo[left][right][player] != make_pair((int)-1,(int)-1)) return memo[left][right][player];
    if(player){
        //MAX
        pair<int, int> p = {v[left],0};
        pair<int, int> p1 = {v[right],0};

        pair<int, int> t = dp(left+1, right, 0);
        pair<int, int> t1 = dp(left, right-1, 0);

        if(p.first+t.first-(p.second+t.second) > p1.first+t1.first-(p1.second+t1.second)){
            return memo[left][right][player] = {p.first+t.first,(p.second+t.second)};
        }else{
            return memo[left][right][player] ={p1.first+t1.first,(p1.second+t1.second)};
        }
    }else{
        pair<int, int> p = {0,v[left]};
        pair<int, int> p1 = {0,v[right]};

        pair<int, int> t = dp(left+1, right, 1);
        pair<int, int> t1 = dp(left, right-1, 1);

        if(p.first+t.first-(p.second+t.second) > p1.first+t1.first-(p1.second+t1.second)){
            return memo[left][right][player] ={p1.first+t1.first,(p1.second+t1.second)};
        }else{
            return memo[left][right][player] ={p.first+t.first,(p.second+t.second)};
        }
    }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> v[i];
    }
    for(int i = 0; i < 3009; i++){
        for(int j = 0; j < 3009; j++){
            for(int k = 0; k < 2; k++){
                memo[i][j][k] = {-1,-1};
            }
        }
    }
    pair<int, int> p= dp(1,n, 1);
    cout << p.first-p.second << endl;
}



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


int main(){
	ios::sync_with_stdio(0),cin.tie(0);
	int a, b, c;
	while (cin >> a >> b) {
		c = a / b;
		if (a % b) 
			c++;
		cout << c << '\n';
	}
	return 0;
}


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

int main() {
    int i,j,x,y,h,b,c[4],d[4];
    while(cin >> x >> y && x!=0) {
		for (i=1000,h=0;i>=1;i/=10,h++) {c[h]=x/i; x-=c[h]*i; d[h]=y/i; y-=d[h]*i;}
		h=b=0;
		for (i=0;i<4;i++) for (j=0;j<4;j++) {	if (c[i]==d[j]) { b++; if (i==j) h++;}}
		cout << h << ' ' << b-h << endl;
	} 
	return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define RREP(i,n) for(int i = n - 1; i >= 0; i--)

#define ALL(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

#define UNIQUE(v) do{sort(v.begin(), v.end()); v.erase( unique(v.begin(), v.end()), v.end() );} while(0)


#define y0 y3487465
#define y1 y8687969

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

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

int K;
const int MAX_K = 100000;
ll A[MAX_K];

int main(){
  cin >> K;
  REP(i, K) cin >> A[i];

  ll mi = 2, ma  = 2;
  RREP(i, K) {
    // mi = int(ceil(double(mi) / A[i])) * A[i];
    mi = (mi + A[i] - 1) / A[i] * A[i];
    if(mi > ma) {
      cout << -1 << endl;
      return 0;
    }
    ma = ma / A[i] * A[i] + A[i] - 1;
  }

  cout << mi << " " << ma << endl;
  
  return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
	int n;
	long long c=1;
	cin>>n;
	for(int i=1;i<=n;i++){
		c=c*i%1000000007;
	}
	cout<<c<<endl;
	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))
from bisect import bisect_left, insort

N = int(input())
src = list(map(int,input().split()))
ans = []
A, B = [], []

for i in range(N):
    a, b = src[i], src[-i-1]
    addA = False
    addB = False

    if a != b:
        j = bisect_left(B, a)
        if j != len(B) and B[j] == a:
            del B[j]
        else:
            addA = True

        j = bisect_left(A, b)
        if j != len(A) and A[j] == b:
            del A[j]
        else:
            insort(B, b)

        if addA:
            insort(A, a)

    if len(A) == len(B) == 0:
        ans.append(i+1)

print(*ans)



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


int main(){
  vector<int> r(3);
  rep(i,3) cin >> r[i];
  
  sort(r.begin(),r.end());
  cout << r[0] + r[1] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <climits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#define int long long
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
int mod = 1e9+7;

int32_t main(){
	#ifndef ONLINE_JUDGE
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	#endif

	string s,t;
	cin>>s>>t;
	int n = s.size();
	int ans = 0;
	for(int i = 0; i < n; i++){
		if(s[i]!=t[i])
			ans++;
	}
	

	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 3832
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>


constexpr long long int MOD = 1000000007;
int main() {
	int n, day; std::cin >> n >> day;
	std::vector<int> cookie(day); for (auto& a : cookie) std::cin >> a;
	std::vector<long long int> factorial(n + 1, 1), inv(n + 1, 1), inv_factorial(n + 1, 1), power(n + 1, 1); power[1] = 2;
	for (auto i = 2; i <= n; ++i) {
		factorial[i] = i * factorial[i - 1] % MOD;
		inv[i] = (MOD - MOD / i) * inv[MOD % i] % MOD;
		inv_factorial[i] = inv[i] * inv_factorial[i - 1] % MOD;
		power[i] = 2 * power[i - 1] % MOD;
	}
	std::vector<std::vector<long long int>> dp(day, std::vector<long long int>(n + 1, 0));
	for (auto i = 0; i <= cookie.front(); ++i) {
		dp[0][i] = factorial[n] * inv_factorial[cookie.front()] % MOD * inv_factorial[n - cookie.front()] % MOD * factorial[cookie.front()] % MOD * inv_factorial[i] % MOD * inv_factorial[cookie.front() - i] % MOD;
		dp[0][i] %= MOD;
	}
	for (auto i = 1; i < day; ++i) {
		for (auto j = 0; j <= cookie[i]; ++j) {
			for (auto k = 0; k + j <= n; ++k) {
				dp[i][j + k] += dp[i - 1][k] * 
					factorial[n - k] % MOD * inv_factorial[j] % MOD * inv_factorial[n - k - j] % MOD *
					factorial[n - j] % MOD * inv_factorial[cookie[i] - j] % MOD * inv_factorial[n - cookie[i]] % MOD;
				dp[i][j + k] %= MOD;
			}
		}
	}
	std::cout << dp.back().back() << std::endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;using ll=long long;using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;using vpl=vector<PL>;
constexpr const int INF=1<<30,MOD=1000000007;constexpr const ll LINF=1ll<<60;
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...)_ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n)for(int i=n-1;i>=0;--i)
#define REPA(i,v)REP(i,v.size())
#define all(v)(v).begin(),(v).end()
#define bit(n)(1ll<<(n))
#define uniq(v)sort(all(v));v.erase(unique(all(v)),v.end())
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b)cout<<((n)?a:b)<<endl
void YES(int n){cho(n,"YES","NO");}void Yes(int n){cho(n,"Yes","No");}void Poss(int n){cho(n,"Possible","Impossible");}
#ifndef LOCAL
struct osd{template<class T>osd&operator<<(const T&t){return*this;}};osd cer_;template<class...T>void _print(osd&a,T&&...t){}
#define cerr cer_
#endif
template<class T>ostream&operator<(ostream&o,const T&t){return o<<t;}template<class T>istream&operator>(istream&i,T&t){return i>>t;}
void _print(ostream&s){}template<class T,class...U>void _print(ostream&s,T&&t,U&&...u){s<t<(sizeof...(u)?' ':'\n');_print(s,u...);}
template<class...T>void print(T&&...t){_print(cout,t...);}template<class...T>void dprint(T&&...t){_print(cerr,t...);}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>ostream&operator<<(ostream&o,const vector<T>&v){for(auto&&i:v)o<i<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>j;return i;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<p.F<' '<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>p.F>p.S;}
template<class T>ostream&operator<<(ostream&o,const set<T>&v){for(auto&&i:v)o<i<' ';return o;}
template<class T>vector<T>&operator<<(vector<T>&v,const T&t){v.push_back(t);return v;}
template<class T>queue<T>&operator<<(queue<T>&q,const T&t){q.push(t);return q;}template<class T>queue<T>&operator<<(T&t,queue<T>&q){t=q.front();q.pop();return q;}
template<class T>deque<T>&operator>>(const T&t,deque<T>&q){q.push_front(t);return q;}template<class T>deque<T>&operator<<(T&t,deque<T>&q){t=q.front();q.pop_front();return q;}
template<class T>deque<T>&operator<<(deque<T>&q,const T&t){q.push_back(t);return q;}template<class T>deque<T>&operator>>(deque<T>&q,T&t){t=q.back(t);q.pop_back();return q;}
template<class T>stack<T>&operator<<(stack<T>&s,const T&t){s.push(t);return s;}template<class T>stack<T>&operator>>(stack<T>&s,T&t){t=s.top();s.pop();return s;}

int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    int n;
    cin>n;
    vi w(n);
    cin>w;
    int s=accumulate(all(w), 0);
    int c=0;
    int mi=INF;
    REP(i,n){
        chmin(mi,abs(s-c-c));
        c+=w[i];
    }
    chmin(mi,abs(s-c-c));
    cout<mi<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define vl          vector<ll>
#define vi          vector<int>
#define pi          pair<int,int>
#define pl          pair<ll,ll>
#define all(a)      a.begin(),a.end()
#define mem(a,x)    memset(a,x,sizeof(a))
#define pb          push_back
#define mp          make_pair
#define F           first
#define S           second
#define trace(x)     cerr<<#x<<":"<<x<<endl;
#define trace2(x,y) cerr<<#x<<":"<<x<<"|"<<#y<<":"<<y<<endl;
#define trace3(x,y,z) cerr<<#x<<":"<<x<<"|"<<#y<<":"<<y<<"|"<<#z<<":"<<z<<endl;
#define fast_io     std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
const int maxn = 2e3+7;

// && pos[0]>-1 && pos[1]>-1 &&pos[2]>-1
int main(){
	fast_io;
	int n;
	cin>>n;
	string s;
	cin>>s;
	ll r=0,g=0,b=0;
	for(int i=0;i<n;i++){
		if(s[i]=='R')r++;
		if(s[i]=='G')g++;
		if(s[i]=='B')b++;
	}
	ll ans = r*g*b;
	// if(ans==0){cout<<ans;return 0;}
	for(int i=0;i<n-1;i++){
		for(int j=i+1;j<n;j++){
			int d = j-i;
			if(s[i]!=s[j]){
				if(j+j-i<n && s[j+j-i] != s[j] && s[j+j-i]!=s[i])ans--;
			}
		}
	}
	// for(int i=0;i<n;i++){
	// 	for(auto k:adj[i]){trace2(i,k.F) trace2(col[i],col[k.F])}
	// }

	cout<<ans;
	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

Measured memory_bytes: 3640
open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let rec powerset e =
  match Enum.get e with
  | None -> Enum.singleton @@ Enum.empty ()
  | Some v ->
    let f = powerset e in
    let g = Enum.clone f in
    EnumL.map f ~f:(fun x -> let y = Enum.clone x in push y v; y)
    |>  Enum.append g

let permutations l =
  let rec aux l =
    let rec interleave x = function
      | [] -> [[x]]
      | (hd::tl) as lst ->
        (x::lst) ::
        (ListL.map ~f:(List.cons hd)  @@ interleave x tl)
    in
    match l with
    | [] -> [[]]
    | hd::tl -> List.concat @@ List.map (interleave hd) @@ aux tl in
  let l = List.sort (List.compare Int.compare) @@ aux @@ List.of_enum l in
  List.enum % ListL.map ~f:List.enum @@ l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let (n,m) = scan "%d %d" Tuple2.make
let ls = scan_list ~sep:' ' Int.of_string

let rec gcd a b =
  if b = 0 then a
  else gcd b (a mod b)

let () =
  let ns = ListL.map ls ~f:(fun x ->
      let rec div2 n = if n mod 2 = 0 then succ @@ div2 (n/2) else 0 in
      div2 x) in
  let ms = ListL.map ls ~f:(fun x -> x / 2) in
  List.reduce (fun a b -> a*b / gcd a b) ms
  |> (fun x ->
      if List.for_all ((=) @@ List.hd ns) ns then (m/x + 1) / 2
      else 0)
  |> Printf.printf "%d\n"


Measured memory_bytes: 15616
local n = io.read("n")
local prev = io.read("n") -- 1
local cur = io.read("n") -- 2
local count = 0
for i=3,n do
    local next = io.read("n")
    if (prev < cur and cur < next) or (next < cur and cur < prev) then
        count = count + 1
    end
    prev = cur
    cur = next
end
print(count)

Measured memory_bytes: 376
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>
#include <bitset>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

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

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

using mint = modint998244353;

/*
struct S { mint x; ll size; };
// セグメント木のデータ。合計値とデータサイズを保存
S op(S a, S b) { return S{a.x + b.x, a.size + b.size}; }
// 単位元。queryの範囲外の時に返す値
S e() { return {0, 0}; }
// データに対する作用（写像）。遅延伝播させる値
struct F { mint b, c; };
// 遅延評価時にdataを更新。dataに対してlazyを作用する
// a:=a*b+cの変換だと、x*b+c*sizeとなる。合計値にbを掛けてsize分のcを足す。sizeはそのまま
S mapping(F f, S x) { return S{f.b * x.x + f.c * x.size, x.size}; }
// g->fの順に作用する。lazy同士でlazyを更新する時に使う
// Sを(x, s), Fを(fb, fc)と(gb, gc)をして、
// fb*(gb*x + gc+s) + fc*s = (fb*gb)*x + (fb*gc+fc)*s
F composition(F f, F g) { return F{f.b * g.b, f.b * g.c + f.c}; }
// Fの単位元。遅延評価後にlazyに代入される
F id() { return F{1, 0}; }
*/

vector<mint> v11;   // v11[0] = 0, v11[1]=1, v11[2]=11..
struct S { mint x; ll size; };
S op(S a, S b) { return S{a.x * mint(10).pow(b.size) + b.x, a.size + b.size}; }
S e() { return S{0, 0}; }
using F = int;
S mapping(F f, S x) {
    if(f == -1) return x;
    else return S{v11[x.size] * f, x.size};
}
F composition(F f, F g) {
    if(f == -1) return g;
    else return f;
}
F id() { return -1; }

void solve() {
    ll n, q;
    cin >> n >> q;
    v11.assign(n + 1, 0);
    mint now = 1;
    for(int i = 1; i <= n; ++i) {
        v11[i] = now;
        now = 10 * now + 1;
    }
    vector<S> a(n, {1, 1});
    lazy_segtree<S, op, e, F, mapping, composition, id> seg(a);
    while(q--) {
        ll l, r, d;
        cin >> l >> r >> d;
        seg.apply(l - 1, r, d);
        cout << seg.all_prod().x.val() << endl;
    }
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

Measured memory_bytes: 16368
using System;

namespace ert89er8uer8
{
    class Program
    {
        static void Main(string[] args)
        {
			int N = int.Parse(Console.ReadLine());
			if (N <= 999)
			{
				Console.WriteLine("ABC");
			}
			else
			{
				Console.WriteLine("ABD");
			}
        }
    }
}


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

int main(){
    int x,n;
    cin>>x>>n;
    vector<int> p(n);
    for(int i=0;i<n;i++){
        cin>>p[i];
    }
    int ans;
    for(int x1=x,x2=x;x1>-1||x2<102;x1--,x2++){
        int flag=0;
        for(int i=0;i<n;i++){
            if(x1==p[i]){
                flag++;
            }
            if(x2==p[i]){
                flag++;
            }
        }
        if(flag<2){
            int flag1=0;
            for(int i=0;i<n;i++){
                if(x1==p[i]){
                    flag1=1;
                }
            }
            if(flag1){
                cout<<x2<<endl;
                return 0;
            }
            else{
                cout<<x1<<endl;
                return 0;
            }

        }
    }
}

Measured memory_bytes: 3596
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	vi a(n);
	rep(i, n) cin >> a[i];
	map<int, int> vis;
	rep(i, n){
		if(vis[a[i]]){
			cout << "NO" << endl;
			return 0;
		}
		vis[a[i]] = 1;
	}
	cout << "YES" << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


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


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for (auto i = rbegin(s); i != rend(s); ++i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
#define rall(f,x,...) [&](decltype(x)& whole) { return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e17;
ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) { return os.put(os.widen('\n')); }
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T> constexpr T pow2(const T a) { return a * a; }
template<class T, class ... Args> constexpr T mins(T& a, Args... args) { return a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr T maxs(T& a, Args... args) { return a = max<T>({ a,args... }); }
template<typename A, size_t N, typename T>
void fillArray(A(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); }

string s;
int q;
void solve() {
    cin >> s >> q;

    bool fron = true;
    auto n = sz(s);
    deque<char> dq;
    rep(i, n) dq.push_back(s[i]);

    rep(i, q) {
        int t;
        cin >> t;
        if (t == 1) {
            fron = !fron;
        }
        else {
            int f; char c;
            cin >> f >> c;

            if (fron && f == 1 || !fron && f == 2)
                dq.push_front(c);
            else
                dq.push_back(c);
        }
    }

    if (fron) {
        for (auto& d : dq)
            cout << d;
        cout << endn;
    }
    else {
        itrepd(d, dq)
            cout << *d;
        cout << endn;
    }

}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    cout << flush;
    return 0;
}


Measured memory_bytes: 976
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <algorithm>
#include <functional>

#include <vector>

using namespace std;

template<typename value_type>
class fast_mod_combination
{
public:
	value_type mod_value;

	vector<value_type> mod_inv;
	vector<value_type> fact;
	vector<value_type> fact_inv;

public:
	fast_mod_combination(const value_type& limit, const value_type& m)
		: mod_value(m), mod_inv(), fact(), fact_inv()
	{
		mod_inv.assign(limit + 1, 0);
		fact.assign(limit + 1, 0);
		fact_inv.assign(limit + 1, 0);

		mod_inv[1] = 1;
		fact[0] = 1;
		fact[1] = 1;
		fact_inv[0] = 1;
		fact_inv[1] = 1;

		for (value_type i = 2; i <= limit; i++)
		{
			mod_inv[i] = mod_value - ((mod_value / i) * mod_inv[mod_value % i] % mod_value);
			fact[i] = (fact[i - 1] * i) % mod_value;
			fact_inv[i] = (fact_inv[i - 1] * mod_inv[i]) % mod_value;
		}
	}

public:
	value_type process(const value_type& n, const value_type& r)
	{
		if (n < 0 || r < 0 || n < r) return 0;
		if (n == r || r == 0) return 1;

		return (fact[n] * (fact_inv[r] * fact_inv[n - r] % mod_value)) % mod_value;
	}
};

//fast_mod_combination<long long> fmc(N, MOD);
//long long result = fmc.process(n, r);

const long long MOD = 1e9 + 7;

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

	int N, K;
	cin >> N >> K;

	fast_mod_combination<long long> fmc(N, MOD);

	long long result = 0;
	for (int i = 0; i <= min(K, N - 1); i++)
	{
		result = (result + (fmc.process(N, i) * fmc.process(N - 1, i)) % MOD) % MOD;
	}

	cout << result;

    return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long int n=0,p=0,count=0,answer=0;



while(1){
cin >> n >> p;
vector<int> v(n,0);
if(n==0&&p==0)
  return 0;
  while(1){
    for(int i=0;i<n;i++){
      if(p==0){

        if(v[i]!=0){
          p+=v[i];
          v[i]=0;
          count=0;
        }else{
          count++;
        }

      }else{
        v[i]++;
        p--;
        count=0;
      }
      if(count==n-1){
      //  cout << count << endl;
        break;
      }
    }if(count==n-1){
    //  cout << count << endl;
      break;
    }


  }


  for(int i=0;i<n;i++){
    if(v[i]!=0){
      answer = i;
    }
  }

  cout<<answer<<endl;
}
}


Measured memory_bytes: 3012
#prag\
ma GCC optimize("O3")

#include <bits/stdc++.h>

using namespace std;

int n,h,a,b[100005];

inline bool cmp(int x,int y)
{
	return x>y;
}

int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);

	ios::sync_with_stdio(false);

	cin>>n>>h;

	int maxa=0;
	
	for (register int i=1;i<=n;++i)
	{
		cin>>a>>b[i];
		maxa=max(maxa,a);
	} 
	
	sort(b+1,b+n+1,cmp);
	
	int i=1,ans=0;
	
	while (h>0 && i<=n && b[i]>maxa)
	{
		h-=b[i];
		i++;
		ans++;
	}
	
	if (h>0)
	{
		if (h%maxa==0) ans+=h/maxa; else ans+=h/maxa+1;
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 640
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   int[] b = new int[N];
   for(int i=0;i<N;i++) b[i] = sc.nextInt();
   int ans = 1; 
   int tmp = b[0];
   for(int i =1; i<N;i++)
   {
     if(tmp > b[i])
     {
       tmp = b[i];
       ans++;
     }
   }
   System.out.println(ans);
 }
}

Measured memory_bytes: 86284
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <set>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
    int N ;
    cin >> N ;
    int i = N / 1000 ;
    if(N % 1000 == 0){
        cout << 0 << endl;
    }else{
        cout << (i + 1) * 1000 - N << endl;
    }
  
}

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

int main() {
	int n, l;
	cin >> n >> l;
	vector<string> arr(n);
	for (int i = 0; i < n; ++i) cin >> arr[i];
	sort(arr.begin(), arr.end());
	for (int i = 0; i < n; ++i) cout << arr[i];
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int count = 0;
    for(int i = a; i<b+1; i++){
      if(c % i == 0){
        count++;
      }
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 26392
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
 
#include<bits/stdc++.h>
 
using namespace std;
#define ll long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define ull unsigned long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0); 
#define nl "\n"
#define sz(a) (int)(a).size() 
#define all(a) (a).begin(),(a).end()
#define fl(a,x) memset(a,x,sizeof(a));
#define pt(a,x) cout << get<x>(a) << " " ;  
#define mt make_tuple 
#define vec vector
 
#define int long long 
 
const int mod = (int) 1e9 + 7 ;
const int MOD = (int) 998244353 ;
const int INF = (int) 1e18 ;
 
typedef vector<int> vii;
typedef pair<int,int> pii;
typedef vector<pii> vpi;
typedef vector<vector<int> > vv;
 
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
 
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

const int N = 3e3 + 5;
int dp[N][N];

void solve(int test) {
	string a, b; cin >> a >> b ;
	int A = sz(a) ; int B = sz(b) ;

	rep(i,0,A+1) {
		rep(j,0,B+1) {
			if(i==0 or j == 0 ) dp[i][j] = 0 ;
			else if(a[i-1] == b[j-1]) dp[i][j] = 1 + dp[i-1][j-1] ;
			else dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
		}
	}

	string ans = "" ;

	int i = A, j = B ;

	while(i and j) {
		if(a[i-1] == b[j-1] ) ans += a[i-1] , --i ,--j ;
		else if(dp[i][j-1] > dp[i-1][j]) --j ;
		else --i ;
	}

	reverse(all(ans)) ;

	cout << ans ;
}
 
int32_t main() {
 
    fast;
	int t=1;
	// cin>>t;
	rep(i,1,t+1) {
		solve(i) ;
	}
 
	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

Measured memory_bytes: 74028
#include <iostream>
#include <vector>

using namespace std;

int main(){
  int N,Y;

  cin >>N>>Y;
  int x,y,z,flag=0;
  for(int i=0;i<=N;i++){
    for(int j=0;j<=N;j++){
      z=N-i-j;
      if((10000*i+5000*j+1000*z)==Y&&z>=0){
        x=i;y=j;flag=1;
        break;
      }
    }
    if(flag==1) break;
  }
 
  if(!flag){
    x=-1;y=-1;z=-1;
  }
   
  cout<<x<<" "<<y<<" "<<z<<endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        Map<String, Map<Integer, Integer>> gidebook = new TreeMap<>();

        for (int i = 1; i <= num; i++) {
            String inCity = sc.next();
            if (!gidebook.containsKey(inCity)) {
                gidebook.put(inCity, new TreeMap<Integer, Integer>(Comparator.reverseOrder()));
            }
            gidebook.get(inCity).put(sc.nextInt(), i);
        }

        for (String city : gidebook.keySet()) {
            for (Integer score : gidebook.get(city).values()) {
                System.out.println(score);
            }
        }

    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;



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

	string sr = s;
	std::reverse(sr.begin(), sr.end());

	bool flag = true;

	for (int i = 0; i < s.length(); i++) {
		if (s[i] != sr[i]) {
			flag = false;
		}
	}

	if (flag) {
		bool flag1 = true;
		string s1;
		s1 = s.substr(0, (s.length() - 1) / 2 );
		string s2 = s1;
		std::reverse(s2.begin(), s2.end());
		for (int i = 0; i < s1.length(); i++) {
			if (s1[i] != s2[i]) {
				flag1 = false;
			}
		}

		bool flag2 = true;
		s1;
		s1 = s.substr((s.length() + 3) / 2 - 1);
		s2 = s1;
		std::reverse(s2.begin(), s2.end());
		for (int i = 0; i < s1.length(); i++) {
			if (s1[i] != s2[i]) {
				flag2 = false;
			}
		}

		if (flag1 && flag2) {
			cout << "Yes";
		}
		else {
			cout << "No";
		}
	}
	else {
		cout << "No";
	}
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int pos[10010];
int main(){
        int N;
        string S, ans;
        string a;
        a="";
        cin>>N;
        cin>>S;
        ans = S;
        for(int i=0;i<N;i++){
                pos[i]=0;
        }
        bool flag;
        for(int i=N-1; i>=0; i--){
                if(S[i] == '('&&pos[i]==0){
                        ans += ')';
                }
                if(S[i]==')'){
                        flag = false;
                        for(int j=i; j>=0; j--){
                                if(S[j]=='('&&pos[j]==0){
                                        pos[j] = 1;
                                        flag = true;
                                        break;
                                }
                        }
                        if(flag==false){
                                ans = '(' + ans;
                        }
                }
        }
        cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int maxN = 2e5+3;
int nums[maxN];
int N, K;

int main()
{
    scanf("%d %d", &N, &K);
    for (int i = 0; i < N; ++i)
        scanf("%d", nums + i);
    for (int i = 0; i < N - K; ++i)
        if (nums[i] >= nums[i + K])
            printf("No\n");
        else
            printf("Yes\n");
}

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

using namespace std;

long d(const vector<long>& A)
{
    long num = 0;
    long min = 1;
    for (size_t i = 0; i < A.size(); ++i) {
        if (A[i] == min) {
            ++min;
        } else if (A[i] > min) {
            auto n = (A[i]-1) / min; 
            if (min == 1) ++min;
            num += n;
        }
    }
    return num;
}

int main()
{
    int N;
    cin >> N;
    vector<long> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
    cout << d(A) << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
 using namespace std;
 int main() 
    { 
    long long int n; 
    cin>>n; 
    long long int a[n],s=1; 
    for(int i=0;i<n;i++) 
        { 
        cin>>a[i];
         if(a[i]==0)
         { 
            cout<<"0"; 
            return 0;
          } 
        } 
    for(int i=0;i<n;i++)
     { 
        if(a[i]<=(long long int)1000000000000000000/s)
         { 
            s=s*a[i];
             } 
        else 
            {
             cout<<"-1";
             return 0; 
            } 
        } 
    cout<<s<<endl; 
    } 


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

int main(){
    int a, b, k;
    cin >> a >> b >> k;
    vector<int> data(b);
    int j = 0;
    for (int i = 1; i < a+1; i++){
        if(a % i == 0 && b % i == 0){
            data.at(j) = i;
            j++;
        }
    }
    sort(data.begin(), data.end());//小さい順に並べる
    reverse(data.begin(), data.end());//リバース
    cout << data.at(k-1) << endl;
}

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

int main() {
  int N,L;
  cin>>N>>L;
  vector<string> s(N);
  string word;
  for (int i=0; i<N; i++) cin>>s[i];
  sort(s.begin(), s.end());
  for (int i=0; i<N; i++) word = word + s[i];
  cout << word << endl;
}


Measured memory_bytes: 256