akhauriyash/Code-Regression huggingface dataset:
use std::io;

fn main() {
    let mut tmp_str = String::new();
    io::stdin().read_line(&mut tmp_str).expect( "no any input" );
    let ar_size: i32 = tmp_str.trim().parse().expect("Input val must be interger");

    tmp_str = String::new();
    io::stdin().read_line( &mut tmp_str ).expect( "no any input" );

    let mut numv: Vec<i32> = tmp_str.split_whitespace().filter_map( |k| k.parse().ok() ).collect::<Vec<i32>>();

    for i in 0..ar_size {
        for j in 0..i {
            if numv.get( i as usize ) < numv.get( j as usize ) {
                let tmp_num = numv[i as usize ];
                numv[i as usize] = numv[ j as usize ];
                numv[j as usize] = tmp_num;
            }
        }

        for j in 0..ar_size {
            if j == ar_size-1 {
                println!( "{}", numv[j as usize ] );
            } else {
                print!( "{} ", numv[j as usize ] );
            }

        }
    }
}



Measured memory_bytes: 5040
//ABC151 D

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

int H,W;
char S[20][20];
int chk[20][20];
int ans = 0;
queue<int> qx,qy;

void bfs(int x,int y){
  if(x > 0 && S[x-1][y] == '.' && chk[x-1][y] == 1000){
    qx.push(x-1);
    qy.push(y);
    chk[x-1][y] = chk[x][y] + 1;
  }
  if(x < H-1 && S[x+1][y] == '.' && chk[x+1][y] == 1000){
    qx.push(x+1);
    qy.push(y);
    chk[x+1][y] = chk[x][y] + 1;
  }
  if(y > 0 && S[x][y-1] == '.' && chk[x][y-1] == 1000){
    qx.push(x);
    qy.push(y-1);
    chk[x][y-1] = chk[x][y] + 1;
  }
  if(y < W-1 && S[x][y+1] == '.' && chk[x][y+1] == 1000){
    qx.push(x);
    qy.push(y+1);
    chk[x][y+1] = chk[x][y] + 1;
  }
  ans = max(ans,chk[x][y]);
}

int main() {
  cin >> H >> W;
  
  
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin >> S[i][j];
      chk[i][j] = 1000;
    }
  }

  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(S[i][j] == '.'){
        qx.push(i);
        qy.push(j);
        chk[i][j] = 0;
        while(!qx.empty()){
          bfs(qx.front(),qy.front());
          qx.pop();
          qy.pop();
        }
        for(int l=0;l<H;l++){
          for(int m=0;m<W;m++){
            chk[l][m] = 1000;
          }
        }
      }
    }
  }

  printf("%d\n",ans);
}


Measured memory_bytes: 256
def nc2(n):
  if n > 1:
    val = n * (n - 1) // 2
  else:
    val = 0
  return val

N = int(input())
A = [int(i) for i in input().split(" ")]

num_dict = {}
for a in A:
  if a in num_dict:
    num_dict[a] += 1
  else:
    num_dict[a] = 1

all_sum = 0
for num, count in num_dict.items():
  all_sum += nc2(count)
  
for a in A:
  org_count = num_dict[a]
  print(all_sum - (nc2(org_count) - nc2(org_count - 1)))
    

Measured memory_bytes: 32184
#include <algorithm>
#include <bitset>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/irange.hpp>
#include <cmath>
#include <map>
#include <numeric>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
namespace mp = boost::multiprecision;
typedef long long ll;
const ll M = 1000000007;

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

	if (s == "SUN") {
		cout << 7;
	} else if (s == "MON") {
		cout << 6;
	} else if (s == "TUE") {
		cout << 5;
	} else if (s == "WED") {
		cout << 4;
	} else if (s == "THU") {
		cout << 3;
	} else if (s == "FRI") {
		cout << 2;
	} else {
		cout << 1;
	} 

	return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

struct RollingHash{
    static const int MD = 2;
    static const vector<ll> hash_base, hash_mod;

    int n;
    vector<ll> hs[MD], pw[MD];

    RollingHash(){}
    RollingHash(const string &s){
        n = s.size();
        rep(i,MD){
            hs[i].assign(n+1,0);
            pw[i].assign(n+1,0);
            hs[i][0] = 0;
            pw[i][0] = 1;
            rep(j,n){
                pw[i][j+1] = pw[i][j]*hash_base[i] % hash_mod[i];
                hs[i][j+1] = (hs[i][j]*hash_base[i]+s[j]) % hash_mod[i];
            }
        }
    }

    // 1-index
    ll hash_value(int l, int r, int i){
        return ((hs[i][r] - hs[i][l]*pw[i][r-l])%hash_mod[i]+hash_mod[i])%hash_mod[i];
    }

    bool match(int l1, int r1, int l2, int r2){
        bool ret = true;
        rep(i,MD) ret &= (hash_value(l1-1,r1,i) == hash_value(l2-1,r2,i));
        return ret;
    }

    ll calc(int l, int r){
        ll ret = 0;
        rep(i,MD) ret |= (hash_value(l-1,r,i)<<(i*32));
        return ret;
    }
};
const vector<ll> RollingHash::hash_base{1009,1021};
const vector<ll> RollingHash::hash_mod{1000000009,1000000007};



using P = pair<string,int>;

int main(){
    int n;
    scanf(" %d", &n);

    vector<P> s(n);
    rep(i,n){
        char tt[100010];
        scanf(" %s", tt);
        s[i] = {string(tt), i};
    }

    sort(all(s));

    vector<int> f(n),sz(n);
    rep(i,n){
        f[s[i].se] = i;
        sz[i] = s[i].fi.size();
    }

    vector<RollingHash> h(n);
    rep(i,n) h[i] = RollingHash(s[i].fi);

    auto check = [&](int a, int b){
        if(sz[a] > sz[b]) return false;

        ll va = h[a].calc(1,sz[a]);
        ll vb = h[b].calc(1,sz[a]);
        return va == vb;
    };

    set<int> active;
    int Q;
    scanf(" %d", &Q);
    while(Q--){
        int k,id;
        scanf(" %d %d", &k, &id);
        --id;

        if(k == 1) active.insert(f[id]);
        else if(k == 2) active.erase(f[id]);
        else{
            int ans = -1;
            auto itr = active.lower_bound(f[id]);
            if(itr != active.end()){
                int idx = *itr;
                if(check(f[id], idx)) ans = s[idx].se+1;
            }
            printf("%d\n", ans);
        }
    }

    return 0;
}



Measured memory_bytes: 59236
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
    int A, B;
    cin >> A >> B;
    if (A > 8 || B > 8) {
        cout << ":(" << endl;
    } else {
        cout << "Yay!" << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static long down_c(long index, long k){
		long counter = 0;
		while(true){
			counter++;
			index -= k-1;
			if(index <= 1)break;
		}
		return counter;
	}
	public static long up_c(long index, long k, long n){
		long counter = 0;
		while(true){
			counter++;
			index += k-1;
			if(index >= n)break;
		}
		return counter;
	}
	public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		long n = scanner.nextLong();
		long k = scanner.nextLong();
		if(n == k){
			System.out.println(1);
		}
		else{
			long x;
			long index = 1, counter = 0;
			while(true){
				x = scanner.nextLong();
				if(x == 1)break;
				index++;
			}
			if(index == 1)counter += up_c(index, k, n);
			else if(index == n)counter += down_c(index, k);
			else if(index < k){
				counter++;
				counter += up_c(k, k, n);
			}
			else if(index+k-1 > n){
				counter++;
				counter += down_c(n-k+1 ,k);
			}
			else if(n%(k-1) == 1 && (index%(k-1) != 1)){
				counter += up_c(index, k, n);
				counter += down_c(index, k);
				counter--;
			}
			else{
				counter += up_c(index, k, n);
				counter += down_c(index, k);
			}
			System.out.println(counter);
		}
	}
}


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

void swap(int& x, int& y){
   int tmp = x;
   x = y;
   y = tmp;
}

int main(){
  while(1){
     int x, y;
     cin >> x >> y;
     if ( x == 0 && y == 0 ){
        break;
     }
     if ( x > y ) { swap(x, y); }
     cout << x << " "<< y << endl;
  }
  return 0;
}


Measured memory_bytes: 3096
#include <stdio.h>

int main(void)
{
	int n;
	int a;
	int i;
	
	while (scanf("%d", &n) != 0){
		a = 0;
		if (n == 0){
			break;
		}
		while (n != 1){
			if (n % 2 == 0){
				n = n / 2;
				a += 1;
			}
			else {
				n = n * 3 + 1;
				a += 1;
			}
		}
		printf("%d\n", a);
	}
	
	return (0);
}

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

int 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 << "Balanced" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}  

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
const ll MAX_N=5e5;
ll N;
string S;
ll a[MAX_N];
ll dfs(ll i){
	if(a[i]!=-1){
		return a[i];
	}
	string s=S.substr(i,2);
	if(s=="<<"){
		a[i]=dfs(i-1)+1;
	}else if(s==">>"){
		a[i]=dfs(i+1)+1;
	}else if(s=="><"){
		a[i]=0;
	}else{
		a[i]=max(dfs(i-1),dfs(i+1))+1;
	}
	return a[i];
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>S;
	N=S.size()+1;
	S='>'+S;
	S.push_back('<');
	memset(a,-1,sizeof(a));
	REP(i,N){
		dfs(i);
	}
	ll ans=0;
	REP(i,N){
		ans+=a[i];
	}
	cout<<ans<<endl;
}


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

using namespace std;

int main(){
	int n;
    int* w;
    cin >> n;

    w = new int[n];

    int sum = 0;
    for(int i = 0; i < n; i++){
        cin >> w[i];
        sum += w[i];
    }

    int dif = sum;
    int sum2 = 0;
    for(int i = 0; i < n; i++){
        sum -= w[i];
        sum2 += w[i];
        if(dif > abs(sum - sum2)){
            dif = abs(sum - sum2);
        }else{
            break;
        }
    }

    cout << dif << endl;
}

Measured memory_bytes: 256
N = int(input())
H = list(range(N))
T = []

ctr = 0
L = 0
while ctr < N:
    L += 1
    ctr += L

if ctr != N:
    print('No')
    
else:
    print('Yes')
    print('{0}'.format(L+1))
    T = [[0 for _ in range(L)] for _ in range(L+1)]
    for i in range(L):
        for j in range(L-i):
            T[i][i+j] = int(i*L-i*(i-1)/2+j+1)
            T[i+j+1][i] = int(i*L-i*(i-1)/2+j+1)
    for i in range(L+1):
        print(L,*T[i])
        
        
    

Measured memory_bytes: 16376
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int maxn = 105 ;
int n ;
char s[maxn] ;
int k ;
int a[5] , b[5] ; 
int ans = 0 ;
int q[maxn] , cur = 0 ;
bool f[5] ;
bool judge()
{
	if(b[1] == q[1] && a[1] > s[q[1]] - '0')  return 0 ;
	if(b[1] > q[1] || a[1] < s[q[1]] - '0')  return 1 ;
	if(k == 1)  return 1 ;

    if(cur < 2 && k >= 2)  return 0 ; 
	if(b[2] < q[2])  return 0 ;
	if(b[2] == q[2] && a[2] > s[q[2]] - '0')  return 0 ;
	if(b[2] > q[2] || a[2] < s[q[2]] - '0')  return 1 ;
	if(k == 2)  return 1 ;
	
	if(cur < 3 && k >= 3)  return 0 ; 
	if(b[3] < q[3])  return 0 ;
	if(b[3] == q[3] && a[3] > s[q[3]] - '0')  return 0 ;
	if(b[3] > q[3] || a[3] < s[q[3]] - '0')  return 1 ;
	
	return 1 ;
}
void dfs(int now , int step)
{
	if(now == n)
	{
		if(step < k)  return ;
		if(judge())  ans ++ ;
		return ;
	}
	if(step == k)
	{
		if(judge())  ans ++ ;
		return ;
	}
	for(int i = now + 1 ; i <= n ; i ++)
	  for(int j = 1 ; j <= 9 ; j ++)
	    a[step + 1] = j , b[step + 1] = i , dfs(i , step + 1) ;
}
int main()
{
   scanf("%s" , s + 1) ;
   scanf("%d" , &k) ;
   n = strlen(s + 1) ;
   for(int i = 1 ; i <= n ; i ++)
     if(s[i] > '0')  q[++ cur] = i ;
   dfs(0 , 0) ;	
   printf("%d\n" , ans) ;
   return 0 ;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int K, N;
    cin >> K >> N;
    vector<ll> A(2*N);
    REP(i,N) cin >> A[i];
    for(int i=N;i<2*N;i++) A[i] = A[i-N] + K;

    ll ans = LINF;
    for(int i=0;i<N;i++){
        chmin(ans, A[i+N-1] - A[i]);
    }
    for(int i=2*N-1;i>=N;i--){
        chmin(ans, A[i] - A[i-N+1]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
vector<int> pos[N];
int a[N];
ll ans[N];

ll cn2(ll n) {
	return n * (n - 1) / 2;
}

int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", a + i);
		pos[a[i]].push_back(i);
	}
	ll sum = 0;
	for (int i = 1; i <= n; i++) {
		sum += cn2(pos[i].size());
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < pos[i].size(); j++) {
			ans[pos[i][j]] = sum - cn2(pos[i].size()) + cn2(pos[i].size() - 1);
		}
	}
	for (int i = 1; i <= n; i++) {
		printf("%lld\n", ans[i]);
	}
	return 0;
}

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

int change(char *a,char **b){
	int n=1200;
	int eret;
	*b=(char*)malloc(strlen(a)+1); //?????¢????????????????¢????
	if(fgets(a,n,stdin)){ //??\???
		for(;*a;++a){ //??§???????°?????????????
			if(*a>='a'&&*a<='z'){
				*a-='a'-'A';
			}
			else if(*a>='A'&&*a<='Z'){
				*a+='a'-'A';
			}
			*b=a;
			printf("%c",**b); //??????
		}
		if(strlen(a)<n && a!=NULL && *b!=NULL){ //??¶?´????NULL?????????
			return 0;
		}
		else{
			eret=1;
			return (-1);
		}
	}
}

int main(){
	int n=1200;
	int eret;
	char *a=(char*)malloc(n+1);
	change(a,&a);
	if(eret==1){
		printf("over\n"); //?????????
		return 1;
	}
	else{
		return 0;
	}
}

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

int main() {
  char c1, c2, c3, c4;
  cin >> c1 >> c2 >> c3 >> c4;

  if ((c1 == c2 && c2 == c3) || (c2 == c3 && c3 == c4)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
    ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cin >> n;
    vector <int> a(2 * n);
    for (int i = 0; i < 2 * n; i++) cin >> a[i];
    int res = 0;
    sort(a.begin(), a.end());
    for (int i = 2 * n - 1; i > 0; i -= 2)
        res += min(a[i], a[i - 1]);
    cout<< res;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
 
#define INF (1<<31)//INT_MAX/2
#define MOD 1000000007
 
using lli  = long long int;
using ull = unsigned long long;
 
int main(int argc, char *argv[])
{
    lli X, Y; 
    std::cin >> X >> Y;

    lli Z = X;

    int ans = 0;

    while (Z <= Y) {
        Z = 2*Z;
        ans++;
    }

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s;
		int count[] = new int[26];
		
		s = sc.next();
		
		sc.close();
		
		int n = s.length();
		String ans = "None";
		
		for(int i = 0; i < n; ++i) {
			int tmp = (int)(s.charAt(i) - 'a');
			count[tmp]++;
		}
		for(int i = 0; i < 26; ++i) {
			if(count[i] <= 0) {
				char tmp = (char)(i + 'a');
				ans = String.valueOf(tmp);
				break;
			}
		}
		System.out.println(ans);
	}

}


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

using namespace std;

typedef long long int ll;

int main(){
    string a, b;
    cin>>a;
    cin>>b;
    int a_n, b_n;
    cin>>a_n>>b_n;
    string u;
    cin>>u;
    if( u == a)a_n--;
    else b_n --;
    cout<<a_n<<' '<<b_n;
}

Measured memory_bytes: 256
def solve():
    n,m = map(int,input().split())
    l = [tuple(map(int,input().split())) for _ in range(m)]
    for i in range(1000):
        st = str(i)
        flag = True
        for j in l:
            if j[0]>len(st):
                flag = False
                break
            if st[j[0]-1]!=str(j[1]):
                flag = False
        if flag and len(st)==n:
            print(i)
            return
    print(-1)
if __name__ == "__main__":
    solve()

Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
using namespace std;

int main()
{
    int a,b,c;
    loop: while(scanf("%d",&a)==1){
           for(b=1;b<=9;b++){
            for(c=1;c<=9;c++){
                if(a==c*b){
                    printf("Yes\n");
                    goto loop;
                }

            }

           }
           if(b>9&&c>9){
            printf("No\n");
        }
    }
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll int64_t

using namespace std;

int main() {

	int n;
	cin >> n;
	if(n%1000 != 0){

		cout << 1000 - n%1000;
	}
	else{
		cout << 0;
	}

	return 0;
}

Measured memory_bytes: 3632
def add(a, b):
    mod = 1e9+7
    return (a+b) % mod
def subtract(a, b):
    mod = 1e9+7
    return (a-b) % mod

n, k = [int(x) for x in input().split()]

arr = [int(x) for x in input().split()]

dp = [0 for _ in range(k+1)]

fake = [0 for _ in range(k+2)]

dp[0] = 1

for num in arr:
    #new_dp = [dp[i] for i in range(k+1)]
    for i in range(k+1):
        temp = dp[i]
        L = i
        R = min(i+num, k)
        fake[L] = add(fake[L], temp)
        fake[R+1] = subtract(fake[R+1], temp)
        #for i in range(L, R+1):
        #    new_dp[i] += temp
        #for use in range(1, num+1):
        #    if i+use <= k:
        #        new_dp[i+use] += temp
    pref_sum = 0
    #print(fake)
    for i in range(k+1):
        pref_sum = add(pref_sum, fake[i])
        dp[i] = pref_sum
        fake[i] = 0
    #dp = new_dp

print(int(dp[k]))

Measured memory_bytes: 140540
#include <iostream>

int judge(int n, int s, int max)
{
    if(n == 1)
    {
        return 0 <= s && s <= max ? 1 : 0;
    }
    int ret = 0;
    for(int i = 0; i <= max; i++)
    {
        ret += judge(n-1, s-i*n-(n-1), max-i-1);
    }
    return ret;
}

int main()
{
    int n, s;
    while(std::cin >> n >> s, s || n)
    {
        std::cout << judge(n, s, 9) << std::endl;        
    }
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <functional>
#include <numeric>
#include <limits>
#include <iomanip>
#include <queue>
#include <cmath>
#include <math.h>
using namespace std;
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; }
const long long INF = 1LL << 60;
using pll = pair<long long, long long>;
#define min(a, b) ((a) < (b) ? (a) : (b))

vector<pair<long long, long long>> prime_factorize(long long n) {
	vector<pair<long long, long long>> res;
	for (long long p = 2; p * p <= n; ++p) {
		// とりあえず約数を出す。
		if (n % p != 0) continue;
		int num = 0;
		while (n % p == 0) ++num; n /= p;
		res.push_back(make_pair(p, num));
	}
	// 1との約数をまとめて追加する。
	if (n != 1) res.push_back(make_pair(n, 1));
	return res;
}

long long gcd(long long x, long long y) {
	return y ? gcd(y, x % y) : x;
}

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

	long long N; cin >> N;
	vector<long long> A(N);
	for (long long i = 0; i < N; ++i) {
		cin >> A.at(i);
	}

	vector<long long> left(N+1), right(N+ 1);
	left.at(0) = 0;
	right.at(N) = 0;

	for (long long i = 0; i < N; ++i) {
		if (left.at(i) > A.at(i)) left.at(i + 1) = left.at(i);
		else left.at(i + 1) = A.at(i);

		if (right.at(N - i) > A.at(N - i - 1)) right.at(N - i - 1) = right.at(N - i);
		else right.at(N - i - 1) = A.at(N - i - 1);
	}

	for (long long i = 0; i < N; ++i) {

		if(left.at(i) > right.at(i + 1)) cout << left.at(i) << endl;
		else cout << right.at(i + 1) << endl;
	}
}


Measured memory_bytes: 6272
import numpy as np
from numba import njit

@njit
def update(a):
  n = len(a)
  b = np.zeros_like(a)
  for i,x in enumerate(a):
    l = max(0, i-x)
    r = min(n-1, i+x)
    b[l] += 1
    if r+1 < n:
      b[r+1] -= 1
  b = np.cumsum(b)
  return b

n,k = map(int, input().split())
a = np.array(list(map(int, input().split())))

for _ in range(k):
  a = update(a)
  if np.all(a==n):
    break
    
print(' '.join(map(str, a)))

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

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

    int N;
    int temp;

    cin >> N;

    vector<int> V(N);

    rep(i, N) cin >> V[i];

    vector<int> V_CP(N);

    V_CP = V;

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

    int V_MAX = V[N-1];
    int V_SECOND = V[N-2];

    rep(i, N)
    {
        if(V_CP[i] != V_MAX)
        {
            cout << V_MAX << "\n";
        }
        else
        {
            cout << V_SECOND << "\n";
        }
    }

    return 0;
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,p[1001],ans,yoso;
  while(cin >> n >> m){
    if(n == 0 && m == 0) break;
    vector<int> vec;
    for(int i=0;i<n;i++) cin >> p[i];
    p[n] = 0;
    for(int i=0;i<=n;i++){
      for(int j=0;j<=n;j++){
	vec.push_back(p[i]+p[j]);
      }
    }
    sort(vec.begin(),vec.end());
    ans = 0;
    for(int i=0;i<=vec.size();i++){
      yoso = upper_bound(vec.begin(),vec.end(),m-vec[i])-vec.begin()-1;
      if(yoso >= 0) ans = max(ans,vec[i] + vec[yoso]);
    }
    cout << ans << endl;
  }
  return (0);
}

Measured memory_bytes: 10824
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
    cin >> first;
    IN(rest...);
    return;
}
#define SS(T, ...)      T __VA_ARGS__; IN(__VA_ARGS__);
#define SV(type,c,n) vector<type> c(n);for(auto& i:c)cin >> i;
/*--Output/////////////////////////////////////////////////*/
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
inline int p(void){cout << endl; return 0;}
template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))

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

ll MOD = 1000000007;

struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n,-1) { }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    int size(int x) {
        return -par[root(x)];
    }
};
int main() {
    vector<pair<int,int>>Q;
    SS(int,n,m)
    UnionFind uf(n);
    rep(i,m){
        SS(int,a,b);
        a--;b--;
        uf.unite(a,b);
    }
    int now=0;
    rep(i,n)Q.push_back(make_pair(uf.root(i),uf.size(i)));
    sort(rbegin(Q),rend(Q));
    for (auto V : Q) {
    if(now!=V.first)n-=V.second-1;
    now=V.first;
    }
    p(n-1);
    }

Measured memory_bytes: 4564
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
using namespace std;
using namespace __gnu_pbds;

#define sp << " " <<
#define mod 1000000007
#define PI 3.14159265358979323
#define y second
#define x first
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define pqueue priority_queue< ll >
//#define pdqueue priority_queue< ll,vector<ll> ,greater< ll > >
#define codejamDebug(x) cout<<"Case #"<<x<<": ";
#define debug(x) cout<<#x<<" :"<<x<<endl;
#define rep(i,n) for(long long i=0;i<n;i++)
#define f(i,a,b) for(long long i = a; i < b; i++)
#define fd(i,a,b) for(long long i = a; i >=b; i--)
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long int           ll;
typedef long double             ld;
typedef unsigned long long int ull;
typedef vector <int>            vi;
typedef vector <ll>            vll;
typedef pair <int, int>        pii;
typedef pair <ll, ll>          pll;
typedef vector < pii >        vpii;
typedef vector < pll >        vpll;
typedef vector <string>         vs;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

//Handle:cyber_rajat

int main(int argc, char const *argv[])
{
	sync;
	int x, y, a, b, c;
	cin>>x>>y>>a>>b>>c;
	ll p[a], q[b], r[c];
	rep(i, a)
	{
		cin >> p[i];
	}
	rep(i, b)
	{
		cin >> q[i];
	}
	rep(i, c)
	{
		cin >> r[i];
	}
	sort(p, p + a, greater<ll>());
	sort(q, q + b, greater<ll>());
	sort(r, r + c, greater<ll>());

	pair<int,int> ans[x+y];
	rep(i, x) ans[i] = {p[i], 1};
	rep(i, y) ans[i+x] = {q[i], 2};

	sort(ans, ans+x+y, greater<pair<int,int>>());

	priority_queue<pair<int,int> > pq;
	pq.push(ans[0]);
	pq.push({r[0], 3});

	int cnt = 0;
	ll res = 0;
	int i = 1, j = 1;

	while(cnt < x + y)
	{
		auto tp = pq.top();
		pq.pop();
		cnt++;
		res += tp.first;
		if (j < c && tp.second == 3) 
		{
			pq.push({r[j], 3});
			j++;
		}
		else if (i < x + y) 
		{
			pq.push(ans[i]);
			i++;
		}
	}
	cout << res <<endl;
	return 0;
}


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

typedef long long ll;
ll a, b, c, k;

int main(){
    cin >> a >> b >> c >> k;
    ll ans = 0;
    if(k >= a){
        ans += a;
        k -= a;
        if(k >= b){
            k -= b;
            ans -= k;
        }
    }else{
        ans += k;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h> 
 
using namespace std;
 
 template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 

int main(){
    int N;
    cin>>N;
    LL na=-1,nb=-1;
    REP(i,N){
        LL a,b;
        cin>>a>>b;
        if(na==nb&&na==-1){
            na=a;
            nb=b;
        }else{
            LL hi=max((na/a+(na%a!=0)),(nb/b+(nb%b!=0)));
            na=a*hi;
            nb=b*hi;
        }
    }
    cout<<na+nb<<endl;
    return 0;
}


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

int s,t,n,m,a[100009],d[100009];
priority_queue<P,vector<P>,greater<P> >q;
vector<P>v[100009];

signed main(){
  r(i,100009)d[i]=1e15;
  cin>>n>>m>>s>>t; s--; t--;
  r(i,n)cin>>a[i];
  r(i,n-1)v[i+1].push_back(P(i,0));
  r(i,m){
    int q,w;
    cin>>q>>w; q--; w--;
    v[q].push_back(P(w,a[w]));
  }
  q.push(P(0,s));
  while(!q.empty()){
    P p=q.top();q.pop();
    int now=p.second;
    int cost=p.first;
    if(d[now]<cost)continue;
    r(i,v[now].size()){
      int nex=v[now][i].first;
      int ncos=cost+v[now][i].second;
      if(d[nex]<=ncos)continue;
      d[nex]=ncos;
      q.push(P(ncos,nex));
    }
  }
  cout<<d[t]<<endl;
}


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

const int64_t INF = 1e18;

struct Dinic{
    struct edge {
        int64_t to, cap, rev;
        edge(int64_t to, int64_t cap, int64_t rev):to(to), cap(cap), rev(rev){}
    };

    int N, S, T;
    int64_t flow = 0;
    vector<int> level, iter;
    vector<vector<edge>> G;

    Dinic(int N, int S, int T):N(N), S(S), T(T){
        flow = 0;
        level.resize(N);
        iter.resize(N);
        G.resize(N);
    }

    void add_edge(int from, int to, int64_t cap){
        G[from].emplace_back(to, cap, G[to].size());
        G[to].emplace_back(from, 0, G[from].size()-1);
    }

    void bfs(int s){
        fill(level.begin(), level.end(), -1);
        queue<int> que;
        level[s] = 0;
        que.push(s);
        while(que.size()){
            int v = que.front(); que.pop();
            for(auto& e : G[v]){
                if(e.cap > 0 && level[e.to] < 0){
                    level[e.to] = level[v] + 1;
                    que.push(e.to);
                }
            }
        }
    }

    int64_t dfs(int v, int t, int64_t f){
        if(v == t) return f;
        for(int& i=iter[v]; i<G[v].size(); i++){
            auto& e = G[v][i];
            if(e.cap > 0 && level[v] < level[e.to]){
                int64_t d = dfs(e.to, t, min(f, e.cap));
                if(d > 0){
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }

    int64_t max_flow(){
        while(true){
            bfs(S);
            if(level[T] < 0) return flow;
            fill(iter.begin(), iter.end(), 0);
            while(true){
                int64_t f = dfs(S, T, INF);
                if(f == 0) break;
                flow += f;
            }
        }
    }
};

int main(){
    int N, A[101];
    cin >> N;
    for(int i=1; i<=N; i++) cin >> A[i];

    int S = 101, T = 102;
    Dinic solver(T+1, S, T);

    int64_t pre_gain = 0;

    for(int i=1; i<=N; i++){
        if(A[i] >= 0){
            pre_gain += A[i];
            solver.add_edge(S, i, 0);
            solver.add_edge(i, T, A[i]);
        }else{
            solver.add_edge(S, i, -A[i]);
            solver.add_edge(i, T, 0);
        }
    }

    for(int i=1; i<=N; i++) for(int k=2; i*k<=N; k++){
        solver.add_edge(i, k*i, INF);
    }

    int64_t ans = pre_gain - solver.max_flow();
    cout << ans << endl;
}

Measured memory_bytes: 256
/* おまじない　*/
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
typedef long long ll;
typedef long double ld;
using namespace std;
const ll MOD=pow(10,9)+7;
const ll INF=(1LL<<62);
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
    cout<<fixed;
}
int main(){
    init();

    ll N;cin>>N;
    vector<ll>A(N);
    for(int i=0;i<N;i++)cin>>A[i];

    ll ans=0;
    for(int i=0;i<N;i++){
        ans+=A[i];
    }

    cout<<ans-N*(N+1)/2<<endl;
}


Measured memory_bytes: 3564
#include<iostream>
#include<string>
#include<vector>
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.txt"
 


int main() {
    string s;
    string t;
    string r;
    
    cin >> s;
    cin >> t;
    r = t.erase(t.size()-1);

    if(r == s) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3624
// 6/28 バーチャル参加
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

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

    int res = 0;
    for (int i = 0; i < S.size(); i++) {
        if (S[i] != T[i]) res++;
    }
    cout << res << endl;
}

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

#define LEN 100000

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN];
int head = 0, tail = 0, n;

void enqueue(P);
P dequeue(void);
int isFULL(void);
int isEMPTY(void);

int main(){
  int elaps = 0, i, q;
  P a, b;

  scanf("%d%d", &n, &q);

  n++;
  
  for(i = 0; i < n - 1; i++){
    scanf("%s%d", a.name, &a.t);
    enqueue(a);
  }

  while(head != tail){
    b = dequeue();
    if(b.t <= q){
      elaps += b.t;
      printf("%s %d\n", b.name, elaps);
    }
    
    else{
      elaps += q;
      b.t -= q;
      enqueue(b);
      }
  }

  return 0;
}

 void enqueue(P x){
   if(isFULL() == 0){
     printf("Buffer over flow!\n");
     exit(1);
   }
   
   Q[tail] = x;

   if(tail + 1 == n)
     tail = 0;

   else
     tail++;

}

P dequeue(){
  P x;

  if(isEMPTY() == 0){
    printf("Buffer under flow!");
  }
   
    x = Q[head];

  if(head + 1 == n)
    head = 0;

  else
    head++;

  return x;
}

int isFULL(){
  if(head == (tail + 1) % n)
    return 0;

  else
    return 1;
}

int isEMPTY(){
  if(head == tail)
    return 0;

  else
    return 1;
}
    


Measured memory_bytes: 6764
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i,n) cin >> s[i];
  sort(s.begin(),s.end());
  int ans = 0;
  rep(i,n-1){
    if(s[i] == s[i+1])ans++; 
  }
  cout << n-ans << endl;
}


Measured memory_bytes: 9528
#include<iostream>
#include<cstdlib>
#include<stack>
using namespace std;
int main()
{
	stack<int>s;
	int a,b,x;
	string y;
	while(cin>>y){
		if(y[0]=='+'){
			a=s.top();s.pop();
			b=s.top();s.pop();
			s.push(a+b);
		}
		else if(y[0]=='-'){
			b=s.top();s.pop();
			a=s.top();s.pop();
			s.push(a-b);
		}
		else if(y[0]=='*'){
			a=s.top();s.pop();
			b=s.top();s.pop();
			s.push(a*b);
		}
		else{
			s.push(atoi(y.c_str()));
		}
	}
	cout<<s.top()<<endl;
	return 0;
}

Measured memory_bytes: 3224
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <ctime>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <memory.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long double LD;
typedef long long LL;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#ifdef LOCAL
#define DEBUG(x) { cerr << "# " << #x << ": " << x << endl;}
#else
#define DEBUG(x)
#endif
mt19937_64 mt(time(0));
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/






int main() {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cout.precision(10); cout << fixed;
#ifdef LOCAL
  freopen("../test.txt", "r", stdin);
    // freopen("../output.txt", "w", stdout);
#endif
  string s; cin >> s;
  cout << s.substr(0, 3) << '\n';






/*---------------------------------------Coding Space End------------------------------------------*/
#ifdef LOCAL
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." << endl;
#endif
  return 0;
}
/* author:  txingml */
/* picture is from hamayanhamayan(CF handle) */


Measured memory_bytes: 3128
#include <iostream>
#include <string>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <utility>
using namespace std;

int main() {
    int N; cin >> N;
	vector<long long> A(N+1);
	vector<long long> B(N);

	for(int i = 0; i < N+1; i++){
		cin >> A[i];
	}
	for(int  i = 0; i < N; i++){
		cin >> B[i];
	}

	long long res = 0;
	for(int i = 0; i < N; i++){
		long long tmp1, tmp2;
		tmp1 = min(A[i], B[i]);
		res += tmp1;
		A[i] -= tmp1;
		B[i] -= tmp1;
		tmp2 = min(A[i+1], B[i]);
		res += tmp2;
		A[i+1] -= tmp2;
		B[i] -= tmp2;
	}

	cout << res << endl;
}

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

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

	if(a*b > c*d) cout << a*b << endl;
	if(a*b == c*d) cout << c*d << endl;
	if(a*b < c*d) cout << c*d << endl;

	return 0;
}

Measured memory_bytes: 256
use std::cmp::{min, Reverse};
use std::collections::BinaryHeap;

const X: [(usize, usize); 4] = [(!0, 0), (1, 0), (0, 1), (0, !0)];

const INF: u64 = 1 << 50;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let h: usize = sc.read();
    let w: usize = sc.read();
    let k: u64 = sc.read();
    let si: usize = sc.read::<usize>() - 1;
    let sj: usize = sc.read::<usize>() - 1;
    let ti: usize = sc.read::<usize>() - 1;
    let tj: usize = sc.read::<usize>() - 1;
    let board: Vec<Vec<char>> = (0..h).map(|_| sc.chars()).collect();
    let mut dist = vec![vec![vec![(INF, INF); 4]; w]; h];

    let mut heap = BinaryHeap::new();
    for d in 0..4 {
        dist[si][sj][d] = (0, k);
        heap.push((Reverse((0, k)), si, sj, d));
    }

    while let Some((_, i, j, cur_d)) = heap.pop() {
        let (cur_dist, cur_k) = dist[i][j][cur_d];
        for nd in 0..4 {
            let (di, dj) = X[nd];
            let ni = i.wrapping_add(di);
            let nj = j.wrapping_add(dj);
            if ni >= h || nj >= w {
                continue;
            }
            if board[ni][nj] != '.' {
                continue;
            }

            let next_dist = if cur_d != nd || cur_k == k {
                (cur_dist + 1, 1)
            } else {
                (cur_dist, cur_k + 1)
            };
            if dist[ni][nj][nd] > next_dist {
                dist[ni][nj][nd] = next_dist;
                heap.push((Reverse(next_dist), ni, nj, nd));
            }
        }
    }

    let mut ans = INF;
    for i in 0..4 {
        ans = min(ans, dist[ti][tj][i].0);
    }
    if ans == INF {
        println!("-1");
    } else {
        println!("{}", ans);
    }
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        Self(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 117868
#include <bits/stdc++.h>
using namespace std;
int a,b,c;
int gcd(int a,int b)
{
	if(b==0)return a;
	else return gcd(b,a%b);
}
int main()
{
    cin>>a>>b>>c;
    int aa;
    if(b>a)
    {
    	int p=a;
    	a=b;
    	b=p;
	}
	aa=gcd(a,b);
//	cout<<aa<<endl;
	int f=1;
	if(c==1)
	{
		cout<<aa<<endl;
	}
	else
	{
		for(int j=2;j<=aa;j++)
		{
			if(aa%j==0)
			{
			f++;
			if(f==c)
			{
				aa/=j;
				cout<<aa<<endl;
				break;
			}
			}
		}
	}
}

Measured memory_bytes: 256
import math
s = list(map(int,input().split()))

a = s[0]
b = s[1]
n = s[2]
x = 0
if b-1 <= n:
    x = b-1
    ans = math.floor(a*x/b)-n*math.floor(x/b)
else:
    x = n
    ans = math.floor(a*x/b)-n*math.floor(x/b)
print(ans)

Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
#define ff        first
#define ss        second
#define ll        long long
#define int       long long
#define inf       ((ll)1e18)
#define double    long double
#define ull       unsigned long long
#define mod       1000000007
#define vi        vector<ll>
#define ppi       pair<int,int>
#define pii       pair<pair<int,int>,int>
#define pb        push_back
#define pi        2*acos(0.0)
#define pr(a,x,y) for(int i=x;i<y;i++){cout<<a[i]<<" ";}
#define p(a)      cout<<a;
#define sp(x,y)   fixed<<setprecision(y)<<x
#define w(x)      ll x; cin>>x; while(x--)
#define all(v)    v.begin(), v.end()
#define rall(v)   v.rbegin(), v.rend()
#define test      cout<<"THIS_AND_THIS"<<endl;
#define str       string
#define endl      '\n'
#define e         cout<<'\n';
void kehsihba(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	/*#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif*/
}
void solve(){
	ll n;cin>>n;
	if(n%1000==0){cout<<0;return;}
	ll x=(n/1000)+1;
	cout<<(x*1000)-n;
}
int32_t main(){
	kehsihba();
	ll t=1;
	//cin>>t;
	while(t--){
		solve();
	}
}




Measured memory_bytes: 3644
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <type_traits>

using namespace std;

int main(int argc, const char * argv[]) {
    string s;
    long long int k;
    cin >> s >> k;
    long long int a = min(k, (long long int)s.size());
    for(int i = 0; i < a; i++){
        if(s[i] != '1'){
            cout << s[i] << endl;
            return 0;
        }
    }
    cout << 1 << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;

const int MAXN = 2031;
const ll INF = 1e18;

void update(ll& x, ll y)
{
    x = min(x, y);
}
int main()
{
    ll dp[331][331][2];
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<ll> h(n);
    for (int i = 0; i < n; i++)
    {
        cin >> h[i];
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j <= k; j++)
        {
            dp[i][j][0] = dp[i][j][1] = INF;
        }
    }
    dp[0][0][0] = INF;
    dp[0][0][1] = h[0];
    dp[0][1][0] = INF;
    dp[0][1][1] = INF;
    int moreZero = (h[0] > 0);
    for (int i = 1; i < n; i++)
    {
        for (int j = 0; j <= k; j++)
        {
            if (h[i - 1] >= h[i])
            {
                update(dp[i][j][1], dp[i - 1][j][1]);
            } else {
                update(dp[i][j][1], dp[i - 1][j][1] + (h[i] - h[i - 1]));
            }
            for (int last = i - 1; last >= max(0, i - j - 1); last--)
            {
                int toChange = i - last;
                if (j - toChange >= 0) update(dp[i][j][0], dp[last][j - toChange][1]);
                if (j - toChange >= 0) update(dp[i][j][0], dp[last][j - toChange][0]);
                if (h[last] >= h[i])
                {
                    update(dp[i][j][1], dp[last][j - toChange + 1][1]);
                } else {
                    update(dp[i][j][1], dp[last][j - toChange + 1][1] + (h[i] - h[last]));
                }
            }
            if (j >= moreZero) update(dp[i][j][1], h[i]);
//            cerr << "i=" << i << " j=" << j << " dp=" << dp[i][j][0] << " " << dp[i][j][1] << endl;
        }
        moreZero += (h[i] > 0);
    }
    ll ans = INF;
    for (int j = 0; j <= k ;j++)
    {
        ans = min({ans, dp[n - 1][j][0], dp[n - 1][j][1]});
    }
    if (moreZero <= k) ans = 0;
    cout << ans;
    return 0;
}


Measured memory_bytes: 1792
N = int(input())

A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
result = 0

for i in range(N):
  result += B[A[i] - 1]
  if(i < N - 1 and A[i] + 1 == A[i + 1]):
    result += C[A[i] - 1]

print(result)

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

int main() {
    int n,x;
    while (true) {
        int count = 0;
        cin >> n >> x;
        if (n == 0 && x == 0) {
            break;
        }
        int start = n ? n < x : x;
        for (int a = n; a > 2; a--) {
            for (int b = a-1; b > 1; b--) {
                if (a + b > x) {
                    continue;
                }
                for (int c = b-1; c > 0; c--) {
                    int s = a + b + c;
                    if (s == x) {
                        count++;
                        break;
                    } else if (s < x) {
                        break;
                    }
                }
            }
        }
        cout << count << endl;
    }
}

Measured memory_bytes: 1160
/*
    Written by Nitrogens
    Desire for getting accepted!!
*/
#include <cstdio>
#include <ctime>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <bitset>
#include <stack>
#include <set>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

const int maxn = 1e5+5;
const int Mod = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e = exp(1);
const db PI = acos(-1);
const db ERR = 1e-10;

#define Se second
#define Fi first
#define pb push_back
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl

int a[105];
ll dp[105][100005];
ll prefix[2][100005];

int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);

    int n, k;
    scanf("%d%d", &n, &k);

    for(int i = 1; i <= n; i++) scanf("%d", &a[i]);

    dp[0][0] = 1;
    prefix[0][0] = 1;
    for(int i = 1; i <= k; i++) prefix[0][i] = prefix[0][i - 1];
    for(int i = 1; i <= n; i++)
    {
        for(int j = 0; j <= k; j++)
        {
            /*
            for(int l = 0; l <= a[i]; l++)
            {
                if(j - l >= 0)  dp[i][j] = (dp[i][j] + dp[i - 1][j - l]) % Mod;
                //dbg3(i, j, dp[i][j]);
            }
            */
            if(j >= a[i] - 1)   dp[i][j] = (prefix[0][j] - prefix[0][j - a[i] - 1] + Mod) % Mod;
            else                dp[i][j] = prefix[0][j];
            //dbg3(i, j, dp[i][j]);
            if(j == 0)  prefix[1][j] = dp[i][j];
            else        prefix[1][j] = (prefix[1][j - 1] + dp[i][j]) % Mod;
        }
        memcpy(prefix[0], prefix[1], sizeof(prefix[1]));
    }
    printf("%lld\n", dp[n][k]);

    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


Measured memory_bytes: 81024
n = int(input())
c = [0] * n
s = [0] * n
f = [0] * n
for i in range(n - 1):
    c[i], s[i], f[i] = map(int, input().split())

for i in range(n - 1):
    total = 0
    for j in range(i, n - 1):
        if total < s[j]:
            total = s[j]
        elif (total - s[j]) % f[j]:
            total += f[j] - total % f[j]
        total += c[j]
    print(total)
print(0)


Measured memory_bytes: 3064