akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 3010;
int mod;

int mul(int x, int y) {
  return 1ll * x * y % mod;
}

void Mul(int &x, int y) {
  x = mul(x, y);
}

int add(int x, int y) {
  return (x += y) > mod ? x - mod : x;
}

void Add(int &x, int y) {
  x = add(x, y);
}

int sub(int x, int y) {
  return (x -= y) < 0 ? x + mod : x;
}

void Sub(int &x, int y) {
  x = sub(x, y);
}

int q_pow(int x, int y) {
  int ans = 1;
  for(; y; y >>= 1) {
    if(y & 1) Mul(ans, x);
    Mul(x, x);
  }
  return ans;
}

int f[N], g[N][N], ny[N], jc[N];

int C(int x, int y) {
  return mul(jc[x], mul(ny[y], ny[x - y]));
}

void init() {
  ny[0] = jc[0] = 1;
  for(int i = 1; i < N; ++i) jc[i] = mul(jc[i - 1], i);
  ny[N - 1] = q_pow(jc[N - 1], mod - 2);
  for(int i = N - 2; i >= 0; --i)
    ny[i] = mul(ny[i + 1], i + 1);
}

int pw[N * N], P[N];

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  mod = m;
  init();
  pw[0] = 1;
  for(int i = 1; i <= n * n; ++i) pw[i] = mul(pw[i - 1], 2);
  P[0] = 1;
  for(int i = 1; i <= n; ++i) P[i] = 1ll * P[i - 1] * 2 % (mod - 1); //zhishu!!!!! 2^n = 2 ^{n % (mod - 1)};
  for(int i = 0; i <= n; ++i) g[i][0] = 1;
  for(int i = 1; i <= n; ++i)
   for(int j = 1; j <= n; ++j) {
    g[i][j] = add(g[i - 1][j - 1], mul(g[i - 1][j], j + 1));
   }
  for(int i = 0; i <= n; ++i) {
    for(int j = 0; j <= i; ++j) {
      Add(f[i], mul(g[i][j], pw[(n - i) * j]));
    }
    Mul(f[i], q_pow(2, P[n - i]));
  }
  int ans = 0;
  for(int i = 0; i <= n; ++i) {
    if(i & 1) Sub(ans, mul(f[i], C(n, i)));
    else Add(ans, mul(f[i], C(n, i)));
  }
  printf("%d\n", ans);
  return 0;
}
// 50 111111113
//1456748

Measured memory_bytes: 70912
//بِسْمِ ٱللَّٰهِ ٱلرَّحْمَٰنِ ٱلرَّحِيمِ
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;

#define endl "\n"

const int MOD = 1000000007;

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

    int a, b;
    cin >> a >> b;
    if(a >= 13){
        cout << b << endl;
    }
    else if( a >= 6 && a <= 12){
        cout << b / 2 << endl;
            }
    else
        cout << "0" << endl;




    return 0;
}


Measured memory_bytes: 3500
x1,y1,x2,y2 = map(int,input().split())
x3 = x2-(y2-y1)
y3 = y2+(x2-x1)
x4 = x3-(y3-y2)
y4 = y3+(x3-x2)
print(x3,y3,x4,y4)


Measured memory_bytes: 2940
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<set>
#include<vector>
#include<map>

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=n; i--)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define v2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;
const ll inf = 1e18;


int main(){
    int n,l,ans=0,idx,min=1000;
	cin >> n >> l;
    vector<int> apple(n+1);
    REP(i,1,n+1){
        apple[i] = l+i-1;
        if(abs(l+i-1)<min){
            min=abs(l+i-1);
            idx=i;
        }
    }

    REP(i,1,n+1){
        if(idx==i)continue;
        ans+=apple[i];
    }

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

const double INF=1e15;

int main() {
    int N, A, B;
    cin >> N >> A >> B;
    
    vector<long long int> V(N);
    for(int n=0; n<N; n++) {
        cin >> V[n];
    }
    sort(V.begin(), V.end());
    
    double max_av=0;
    for(int a=0; a<A; a++) {
        max_av += (double)V[N-1-a];
    }
    max_av /= (double)A;
    
    cout << setprecision(20) << max_av << endl;
    
    long long int count=0;
    long long int same_nums=upper_bound(V.begin(), V.end(), V[N-1-A])\
    -lower_bound(V.begin(), V.end(), V[N-1-A]);
    long long int upper_nums=V.end()\
    -upper_bound(V.begin(), V.end(), V[N-1-A]);
    
    for(int r=A; r<=B; r++) {
        if(upper_nums>0 && r>A) {
            break;
        }

        long long int tmps=1, tmp=1;
        
        for(int i=0; i<r-upper_nums; i++) {
            tmps *= (same_nums-i);
            tmps /= (i+1);
        }
        // cout << tmps << " ";
        count += tmps;
        if(r>=same_nums) {
            break;
        }
    }

    cout << count << endl;

    return 0;
    
}

Measured memory_bytes: 256
from fractions import gcd

def FindAllDivisors(x):
    divList = []
    y = 1
    while y <= x**0.5:
        if x % y == 0:
            divList.append(y)
            divList.append(int(x / y))
        y += 1
    return sorted(list(set(divList)))

A, B = map(int, input().split())

max_divs = gcd(A, B)
divs = FindAllDivisors(max_divs)

results = []
for div in divs[1:]:
    flag = True
    for result in results:
        if div % result == 0:
            flag = False
            break
    if flag:
        results.append(div)

print(len(results) + 1)

Measured memory_bytes: 5984
n,q = map(int,input().split())
s = input()
lr = list(list(map(int,input().split())) for i in range(q))

x = [0]*(n)
for i in range(n-1):
    if s[i] == 'A':
        if s[i+1] == 'C':
            x[i+1] = x[i] + 1
        else:
            x[i+1] = x[i]
    else:
        x[i+1] = x[i]

for i in range(q):
    print(x[lr[i][1]-1]-x[lr[i][0]-1])


Measured memory_bytes: 30656
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, m, d;
	scanf("%d%d%d", &n, &m, &d);
	printf("%.9f\n", (d==0?1.0:2.0)*(m-1)/n*(n-d)/n);
	return 0;
}


Measured memory_bytes: 384
import numpy as np
n, m, c = list(map(int, input().split()))
b = np.array(list(map(int, input().split())))
ans = 0
for i in range(n):
    a = np.array(list(map(int, input().split())))
    res = sum(a * b) + c
    if res > 0:
        ans += 1

print(ans)

Measured memory_bytes: 18488
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)
#define MAX_G 110000
#define MAX_D 10

using namespace std;
typedef pair<int, int> ipair;

int D, G, p[MAX_D], c[MAX_D];

int solve() {
    //どの難易度を全完するか...2^D通り
    //残りは残っている配点の最も大きい難易度をいくつか解く
    int res = INF;

    for(int i = 0; i < (1 << D); ++i) {
        int problems = 0, score = 0;

        int highest = -1;
        for(int j = 0; j < D; ++j)
            if((i >> j) % 2 == 1) {
                score += (j + 1) * 100 * p[j] + c[j];
                problems += p[j];
            } else
                highest = j;
        
        if(highest != -1)
            for(int k = 0; k < p[highest] && score < G; ++k) {
                score += (highest + 1) * 100;
                problems++;
            }
        
        if(score >= G)
            res = min(res, problems);
    }
    return res;
}

int main(int argc, char **argv) {
    cin >> D >> G;
    for(int i = 0; i < D; ++i) {
        cin >> p[i] >> c[i];
    }
    cout << solve() << endl;
}

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

typedef long long LL;

int Total = 0;
int n;


void DPS(LL abc)
{
	if (abc > n)
		return;

	string check = to_string(abc);
	if (check.find('5') != string::npos && check.find('3') != string::npos&& check.find('7') != string::npos)
		Total++;
	DPS(abc * 10 + 5);
	DPS(abc * 10 + 3);
	DPS(abc * 10 + 7);
}

int main()
{
	cin >> n;
	DPS(0);
	cout << Total << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }

int main(){
    int N, K;
    cin >> N >> K;
    int ans = 0;
    for(int i = 0; i < N; i++){
        int h;
        cin >> h;
        ans += (h >= K);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k;
    string s;
    cin>>k;
    cin>>s;
    if(s.length()<=k){cout<<s<<endl;}
    else {
        for(int i=0;i<k;i++)
        {
            cout<<s[i];
        }
        cout<<"..."<<endl;
    }
    return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<functional>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
int a,b,c;
int main(){
    cin>>a>>b>>c;
    a-=c;
    cout<<a/(b+c)<<endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
ans = 1
for j in range (n) :
    if a[j] == 0 :
        print(0)
        exit()
for i in range (n) :
    ans *= a[i]
    if ans > 10**18 :
        print(-1)
        exit()
print(ans)

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

string s;

int main()
{
	cin>>s;
	int len,ans=0;
	len=s.size();
	for(int i=0;i<ceil(len/2);i++)
	{
		if(s[i]==s[len-i-1]) continue;
		else ans++;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	scanner.Split(bufio.ScanWords)
	L := readInt()
	R := readInt()
	res := 2019

	if R-L >= 2019 {
		res = 0
	} else {
		for i := L; i < R; i++ {
			for j := i + 1; j < R+1; j++ {
				calc := (i * j) % 2019
				if res > calc {
					res = calc
				}
			}
		}
	}
	fmt.Println(res)
}

/*-----------------------------------------*/

func checkError(err error) {
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
}

func read() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	res, err := strconv.Atoi(read())
	checkError(err)
	return res
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
  int X, Y, Z, K; // X種Y種Z種から一つずつ買う，K:選び方
  cin >> X >> Y >> Z >> K;

  vector<long> A, B, C; // 価格
  long a, b, c;
  for( int i = 0; i < X; i++ ){ cin >> a; A.push_back(a); }
  for( int j = 0; j < Y; j++ ){ cin >> b; B.push_back(b); }
  for( int k = 0; k < Z; k++ ){ cin >> c; C.push_back(c); }
  
  // 降順ソート
  sort(A.begin(), A.end(), greater<long>());
  sort(B.begin(), B.end(), greater<long>());
  sort(C.begin(), C.end(), greater<long>());
  
  tuple<long, int, int, int> d; // (delicious_score, i, j, k)
  priority_queue< tuple<long, int, int, int> > q; // scoreの最大値管理用コンテナ
  set< tuple<long, int, int, int> > s; // 重複したものをq.pushしないための検索用コンテナ
  int i = 0;
  int j = 0;
  int k = 0;
  
  // 一番美味しいケーキの組み合わせ
  d = make_tuple(A[i]+B[j]+C[k], i, j, k);
  if( !s.count(d) ){ q.push( d ); s.insert( d ); }
  auto qtop = q.top();
  i = get<1>(qtop);
  j = get<2>(qtop);
  k = get<3>(qtop);
  cout << get<0>(qtop) << endl;
  q.pop();
  K--;
 
  while(K > 0){
    // 次に一番美味しいケーキの組み合わせ
    if( i+1 < X ){ 
    	d = make_tuple(A[i+1]+B[j]+C[k], i+1, j, k);
    	if( !s.count(d) ){ q.push( d ); s.insert( d ); }
    }
    if( j+1 < Y ){ 
    	d = make_tuple(A[i]+B[j+1]+C[k], i, j+1, k);
    	if( !s.count(d) ){ q.push( d ); s.insert( d ); }
    }
    if( k+1 < Z ){ 
    	d = make_tuple(A[i]+B[j]+C[k+1], i, j, k+1);
    	if( !s.count(d) ){ q.push( d ); s.insert( d ); }
    }
    auto qtop = q.top();
    i = get<1>(qtop);
    j = get<2>(qtop);
    k = get<3>(qtop);
    cout << get<0>(qtop) << endl;
    q.pop();
    K--;
  }
  
  return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <string>

using namespace std;


int main() {

	int N, Q;
	cin >> N >> Q;

	string s;
	cin >> s;
	vector<int> a(N, 0);

	for(int i = 1; i < N; i++) {
		if(s[i-1] == 'A' && s[i] == 'C') {
			a[i] = a[i-1] + 1;
		} else {
			a[i] = a[i-1];
		}
	}

	for(int i = 0; i < Q; i++) {
		int l, r;
		cin >> l >> r;
		cout << a[r-1] - a[l-1] << endl;
	}
}


Measured memory_bytes: 1472
from time import time
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
L = [-1 for i in range(N)]

visited = []
now = 0
loopstarts = None
looplength = None
t0 = time()

for i in range(N):
    if L[now] != -1:
        break
    else:
        L[now] = i
        visited.append(now)
        now = A[now]-1

loopstarts = visited.index(now)
looplength = len(visited)-loopstarts

if K < loopstarts:
    print(visited[K]+1)
else:
    print(visited[loopstarts+(K-loopstarts)%looplength]+1)
# print(time()-t0)


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

long long a,b,c=0,d,e,g,h,i,j,k;
string arr;
cin>>a;
for(i=1;i<=a;i++)
{
arr=to_string(i);
if(arr.length()%2==1)
c++;

}
cout<<c;




}


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

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;

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

#define vint(v, n) vector<int> v(n); REP(i,n) cin >> v[i];
#define vvint(v, w, n) vector<int> v(n); vector<int> w(n); REP(i,n) cin >> v[i] >> w[i];
#define vlint(v, n) vector<ll int> v(n); REP(i,n) cin >> v[i];
#define vdouble(v, n) vector<double> v(n); REP(i,n) cin >> v[i];
#define vvdoube(v, n1, n2) vector<vector<double> > v(n1, vector<double>(n2, 0)); REP(i,n1) REP(j,n1) cin >> v[i][j];
#define string(x) string x; cin >> x;
#define vstring(v, n) vector<string> v(n); REP(i,n){string a; std::cin >> a; v.push_back(a); }

#define all(v) (v).begin(), (v).end()
#define rall(v) (v).begin(), (v).end(), std::greater<int>()
#define len(v) (v).length()
#define FIND(s, n) (s.find(n) != s.end())
#define SORT(a) sort(all(a))

static const string abet("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
static const long long int MOD = 1000000007;
static const double PI=3.1415926535897932;
static const int INF = 0x3f3f3f3f;
static const int INFTY = (1 << 29);
static const long long LINFTY = (1LL << 32);

static const int dy4[]={0, 0, 1, -1};
static const int dx4[]={1, -1, 0, 0};
static const int dx8[] = {1, 1, 1, 0, 0, -1, -1, -1};
static const int dy8[] = {-1, 0, 1, -1, 1, -1, 0, 1};


int longest_increasing_subsequence0(int N, vector<int> a){
    int dp[N];
    fill(dp, dp+N, INF);
    REP(i, N) *lower_bound(dp, dp+N, a[i]) = a[i];

    return lower_bound(dp, dp+N, INF) - dp;
}



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

  int N;
  cin >> N;

  vint(p, N);

  cout << longest_increasing_subsequence0(N, p) << endl;

}

Measured memory_bytes: 4196
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

int main(){
  double ans = 0.0;
  ll N; cin>>N;

  ans = N * 2 * 3.141592;

  cout<<ans<<endl;


}


Measured memory_bytes: 3792
#include<bits/stdc++.h>
using namespace std;
long long n,ans,a[400][400],pd[400][400];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	  for(int j=1;j<=n;j++) scanf("%d",&a[i][j]);
	memset(pd,0,sizeof(pd));
	for(int k=1;k<=n;k++)
	  for(int i=1;i<=n;i++)
	    for(int j=1;j<=n;j++)
	    {
	    	if(k!=i&&k!=j&&i!=j)
	    	{
	    		if(a[i][j]==a[i][k]+a[k][j]) pd[i][j]=1;
	    		if(a[i][j]>a[i][k]+a[k][j]) {cout<<"-1";return 0;}
			}
		}
	for(int i=1;i<=n;i++)
	  for(int j=1;j<=n;j++)
	    if(pd[i][j]==0) ans+=a[i][j];
	cout<<ans/2<<"\n";
	return 0;
}

Measured memory_bytes: 2432
#include <iostream>

using namespace std;

int main()
{
	int a[5000];
	int left[5000], right[5000];
	int n;
	
	while (true) {
		cin >> n;
		if (n==0) break;
		
		bool existsPos = false;
		for (int i=0; i<n; i++) {
			cin >> a[i];
			if (a[i] > 0) existsPos = true;
		}
		
		int maximum;
		
		if (existsPos) {
			int left_max = a[0];
			int left_max_pos = 0;
			left[0] = a[0];
			for (int i=1; i<n; i++) {
				left[i] = left[i-1] + a[i];
				if (left[i] > left_max) {
					left_max = left[i]; left_max_pos = i;
				}
			}
			int right_max = a[n-1];
			int right_max_pos = n-1;
			right[n-1] = a[n-1];
			for (int i=n-2; i>=0; i--) {
				right[i] = right[i+1] + a[i];
				if (right[i] > right_max) {
					right_max = right[i]; right_max_pos = i;
				}
			}
			
			maximum = 0;
			for (int i = right_max_pos; i <= left_max_pos; i++) maximum += a[i];
		}
		else {
			maximum = -100000;
			for (int i=0; i<n; i++) {
				if (a[i] > maximum) maximum = a[i];
			}
		}
		
		cout << maximum << endl;
	}
		
	return 0;
}

Measured memory_bytes: 3140
N = int(input())
v = list(map(int,input().split()))
v_even = [0 for i in range(max(v)+1)]
v_odd = [0 for i in range(max(v)+1)]
sum_even = 0
sum_odd = 0
for i in range(N):
    if i%2 :
        v_odd[v[i]] += 1
        sum_odd += 1
    else:
        v_even[v[i]] += 1
        sum_even += 1
max_odd = 0
odd = 0
max_even = 0
even = 0
for i in range(len(v_odd)):
    if v_odd[i] > max_odd:
        max_odd = v_odd[i]
        odd = i

for i in range(len(v_even)):
    if v_even[i] > max_even:
        max_even = v_even[i]
        even = i

if odd != even:
    ans = sum_even - max_even + sum_odd - max_odd
else:
    v_odd[odd] = 0
    v_even[even] = 0
    ans = min((sum_even - max_even + sum_odd - max(v_odd)), sum_even - max(v_even) + sum_odd - max_odd)

print(ans)


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

void solve(long long N, std::vector<long long> x, std::vector<long long> y)
{
    long double res = 0.0, dx = 0.0, dy = 0.0;

    for (size_t i = 0; i < N; i++)
    {
        for (size_t j = i + 1; j < N; j++)
        {
            dx = static_cast<long double>(x[i] - x[j]);
            dy = static_cast<long double>(y[i] - y[j]);
            res += sqrt(dx * dx + dy * dy);
        }
    }

    cout << setprecision(10) << 2.0 * res / static_cast<long double>(N) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long N;
    scanf("%lld", &N);
    std::vector<long long> x(N);
    std::vector<long long> y(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &x[i]);
        scanf("%lld", &y[i]);
    }
    solve(N, std::move(x), std::move(y));
    return 0;
}


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

int main() {
  double n,c=0;
  int d=0;
  cin >> n;
  
  
  vector<int> a(n);
  for(int i=0 ; i < n; i++){
    cin >> a.at(i);
    c += a.at(i);
  }
  c = round(c / n);
  sort(a.begin(),a.end());
  for(int i=0; i < n ; i ++){
    d += (a.at(i) - c ) * (a.at(i) - c );
  }
  cout << d ;
}


Measured memory_bytes: 3744
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define PI 				acos(-1)
#define mp				make_pair
#define pb				push_back
#define all(a)			(a).begin(), (a).end()
#define sz(a)			a.size()
#define srt(a)			sort(all(a))
#define mem(a, h)		memset(a, (h), sizeof(a))
#define f 				first
#define s 				second
#define MOD1			998244353
#define fore(i, b, e)	for(int i = b; i < e; i++)
#define forg(i, b, e, m)	for(int i = b; i < e; i+=m)
int in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
using namespace __gnu_pbds;

typedef long long 		ll;
typedef unsigned long long 		ull;
typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const int tam = 100010;
const int MOD = 1e9+7;
const double EPS = 1e-9;
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	//freopen("qwe.txt", "r", stdin);
	//freopen("asd.txt", "w", stdout);
	int n, k;
	cin>>n>>k;
	vector<int> iz, de;
	int a;
	fore(i, 0, n)
	{
		cin>>a;
		if(a < 0)
			iz.pb(a);
		else
			de.pb(a);
	}
	reverse(iz.begin(), iz.end());
	int res = min(iz.size() >= k? -iz[k-1] : MOD, de.size() >= k? de[k-1] : MOD);
	fore(i, 0, k)
	{
		if(i < de.size() && k - i - 1 <= iz.size() && k - i - 1 > 0)
		{
			res = min(res, de[i] + de[i] - iz[k - i - 2]);
		}
		if(i < iz.size() && k - i - 1 <= de.size() && k - i - 1 > 0)
		{
			res = min(res, -(iz[i] + iz[i] - de[k - i - 2]));
		}
	}
	cout<<res<<'\n';
	return 0;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS2

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

import sys
from operator import itemgetter

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

N = INT()
LR = []
for i in range(N):
    x, l = MAP()
    LR.append((x-l, x+l))

LR.sort(key=itemgetter(1))
cur = -INF
cnt = 0
for l, r in LR:
    if cur <= l:
        cur = r
        cnt += 1
print(cnt)


Measured memory_bytes: 18276
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int M;
  lint K;
  cin>>M>>K;
  lint temp=1;
  REP(i,M)temp*=2;
  if(K==0){
    REP(i,temp)cout<<i<<" "<<i<<" ";
    cout<<endl;
    return 0;
  }
  if(temp<=K){
    cout<<-1<<endl;
    return 0;
  }
  if(M==1 and K==1){
    cout<<-1<<endl;
    return 0;
  }
  cout<<K<<" ";
  REP(i,temp)if(i!=K)cout<<i<<" ";
  cout<<K<<" ";
  for(int i=temp-1;i>=0;i--)if(i!=K)cout<<i<<" ";
  cout<<endl;
  return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define Max 100005
using namespace std;
typedef long long LL;
const int Mod = 1000000007;
char s[Max];
LL dp[4][Max];///0 '?' 1 'A' 2 'AB' 3 'ABC'
int a,b;

int main() {
    scanf("%s", s + 1);
    dp[0][0] = 1;
    int n = strlen(s + 1);
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j <= 3; ++j) {
            dp[j][i] = dp[j][i - 1];
            if (s[i] == '?') {
                dp[j][i] = (dp[j][i] * 3) % Mod;
            }

            if (j && (s[i] == '?' || s[i] - 'A' + 1 == j)) {
                dp[j][i] = (dp[j][i] + dp[j - 1][i - 1]) % Mod;
            }
        }
    }

    printf("%lld\n", dp[3][n]);

    return 0;
}

Measured memory_bytes: 3456
local n = io.read("*n")
local a = 0
for i = 1, 1000 do
  if i * (i + 1) == n * 2 then
    a = i
    break
  end
end
if a == 0 then
  print("No")
else
  print("Yes")
  print(a + 1)
  local t = {}
  for i = 1, a + 1 do
    t[i] = {}
    for j = 1, a do t[i][j] = 0 end
  end
  local cur = 1
  for i = 1, a do
    for j = i, a do
      t[i][j] = cur + j - i
      t[j + 1][i] = cur + j - i
    end
    cur = cur + a + 1 - i
  end
  for i = 1, a + 1 do
    print(a .. " " .. table.concat(t[i], " "))
  end
end


Measured memory_bytes: 6896
#include<iostream>
#include<algorithm>
int b[105];
int main()
{
	int x, n, ans1, ans2;
	int a[105];
	scanf("%d%d", &x, &n);
	if(n==0) {
	printf("%d", x);
	return 0;
    }
	for(int i=1;i<=n;i++)
	{
		scanf("%d", &a[i]);
		b[a[i]]=1;
	}
	for(int i=x;i>=0;i--)
	{
		if(b[i]==1) continue;
		else{
		 ans1=i;
		break;}
	}
	for(int j=x;j<=200;j++)
	{
		if(b[j]==1) continue;
		else
		{
			 ans2=j;
			break;
		}
	}
	if((x-ans1)<=(ans2-x)) printf("%d", ans1);
	else printf("%d", ans2);
 } 

Measured memory_bytes: 3824
#include <iostream>
#include <vector>
#include <cstring>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <stack>
using namespace std;
#define ll long long
#define pb push_back
#define pp pair<long long,long long>
#define ppp pair<pair<long long,long long>,long long>
#define f firsta
#define s second
#define pd pair<double,long long>
int main() {
	ll t,n,i,j,k,l,m;
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll p;
	t=1;
	//cin>>t;
	while (t--) {
		cin>>j;
		if (j)
			cout<<0<<'\n';
		else
			cout<<1<<'\n';
	}
	return 0;
}

Measured memory_bytes: 3648
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<P> Graph;

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

  int n;
  cin >> n;
  
  int a[n][26] = {};
  REP(i,n){
    string s;
    cin >> s;
    REP(j,s.size()){
      a[i][s[j]-'a']++;
    }
  }
  
  REP(i,26){
    int x = MOD;
    REP(j,n){
      x = min(x,a[j][i]);
    }
    while(x != 0){
      cout << (char)(i+'a');
      x--;
    }
  }
  
  cout << endl;

  return 0;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    a_list = [-1]
    a_list += list(map(int, input().split()))

    bolls = [0] * (n + 1)
    m = 0
    for i in range(n, 0, -1):
        count = 0
        for j in range(2, n + 1):
            multiple = i * j
            if multiple > n:
                break
            else:
                count += bolls[multiple]
        temp = count % 2
        if a_list[i] != temp:
            bolls[i] = 1
            m += 1

    print(m)
    ans_list = []
    for i in range(1, n + 1):
        if bolls[i] >= 1:
            ans_list.append(i)
    print(' '.join(map(str, ans_list)))


if __name__ == '__main__':
    main()


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

using namespace std;

//FILE *fi=freopen("1.txt","r",stdin);

int n,a[200001],p[1000001],d[1000001];

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

void process()
{
    for (int i=1;i<=n;++i)
    {
        if (!p[a[i]])
        {
            for (int j=a[i]*2;j<=a[n];j+=a[i])
                p[j]=1;
        }
    }
    int dem=0;
    for (int i=1;i<=n;++i)
    {
        if (!p[a[i]] && d[a[i]]==1)
            dem++;
    }
    cout<<dem;
}

int main()
{
    nhap();
    process();
    return 0;
}


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N;
ll A[100100], B[100100];
std::priority_queue<ll> pq;

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

  std::cin >> N;

  ll Sb = 0;

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

      pq.emplace(A[i] + B[i]);
      Sb += B[i];
  }

  ll Sab = 0;

  until(pq.empty()){
      Sab += pq.top();
      pq.pop();
      unless(pq.empty()){
          pq.pop();
      }
  }

  ll res = Sab - Sb;
  std::cout << res << std::endl;
}


Measured memory_bytes: 2804
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;

const int N = 505;
int dis[N][N];
bool emp[N][N];
int n;

void relax(int si, int sj) {
  deque<PII> ord;
  ord.emplace_back(si, sj);
  while (!ord.empty()) {
    auto [i, j] = ord.front(); ord.pop_front();
    for (int ii: {i - 1, i, i + 1}) {
      for (int jj: {j - 1, j, j + 1}) {
        if (abs(i - ii) + abs(j - jj) != 1) continue;
        if (ii < 1 || ii > n || jj < 1 || jj > n) continue;
        if (dis[ii][jj] > dis[i][j] + !emp[i][j]) {
          dis[ii][jj] = dis[i][j] + !emp[i][j];
          if (emp[i][j]) {
            ord.emplace_front(ii, jj);
          } else {
            ord.emplace_back(ii, jj);
          }
        }
      }
    }
  }
}

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      dis[i][j] = min({i - 1, j - 1, n - i, n - j});
    }
  }

  int ans = 0;
  for (int it = 0; it < n * n; it++) {
    int x; cin >> x;
    int i = ((x - 1) / n) + 1;
    int j = ((x - 1) % n) + 1;

    ans += dis[i][j];
    emp[i][j] = true;
    relax(i, j);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 5844
import itertools
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

all = []
for i in range(N):
    all.append(i+1)

p_list = list(itertools.permutations(all, N))


def check_eq(A, B):
    flag = True
    for i in range(len(A)):
        if A[i] == B[i]:
            pass
        else:
            flag = False
            break
    return flag

a_num = 0
b_num = 0
for i in range(len(p_list)):
    if check_eq(p_list[i], A):
        a_num = i + 1
    if check_eq(p_list[i], B):
        b_num = i + 1
print(abs(a_num - b_num))

Measured memory_bytes: 50908
from sys import stdin
import math
import bisect
import heapq
import numpy as np
from math import factorial

s = stdin.readline().rstrip()
t = stdin.readline().rstrip()

atama = t[0]
lent = len(t)
lens = len(s)

lin = []

for i in range(lens-lent+1):
    flag = 0
    for j in range(lent):
        if s[i+j] != t[j] and s[i+j] != "?":
            flag = 1
    if flag == 0:
        lin.append((s[:i]+t+s[i+lent:]).replace("?","a"))
if lin == []:
    print("UNRESTORABLE")
    exit()

lin.sort()
print(lin[0])

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

using namespace std;
using ll =long long;

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cout << #x << " = " << (x) << endl;
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}

const ll INF = 1LL << 60;

ll N,M,H,W,K,A,B;
string S;
//Write From this Line
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
vector<int> ans;
struct Edge {
	int to ;
	int id ;
};
vector<vector<Edge>> g;

void dfs(int v	,int c = -1 ,int bef= -1){
	//vertex,前の色,どこからきたか
	//今いる頂点と繋がってるところをゲットする。それは、g[v].toに入っている。g[v].sizeで何回やればいいか見る
	int k = 1; //淹れる色
	rep(i,g[v].size()){
		int next_vertex = g[v][i].to;
		//vとnext_vertexをつなぐ頂点の式のIDは、g[v][i].id
		int ei = g[v][i].id;//idが辺の番号で、next_vertexが、次行く頂点
		if(next_vertex == bef) {
			continue;
		}
		if(k == c) {
			k ++ ;
			ans[ei] = k;
			k++;
			dfs(next_vertex, k-1 , v);
		}else{
			ans[ei] = k; 
			k ++ ;
			dfs(next_vertex , k-1 , v);
		}
	}
}

int main()
{
	cout << setprecision(10);
	cin >> N ;
	g.resize(N);//to , id(辺の番号)
	ans.resize(N-1);
	rep(i,N-1){	
		int a , b ;
		cin >> a >> b;
		a--;b--;

		g[a].push_back((Edge){b,i});
		g[b].push_back((Edge){a,i});
	}
	dfs(0);

	//最大字数を取得したい。
	int mx = 0;
	rep(i,N-1){
		mx = max((int)mx,(int)g[i].size());
	}
	cout << mx << endl;
	rep(i,N-1){
		cout << ans[i] << endl;
	}

}


Measured memory_bytes: 8320
N=gets.to_i
A=gets.chomp.split.map(&:to_i)
m_cnt=0
sum=0
min=Float::INFINITY
A.each do |a|
  if a < 0
    m_cnt += 1
  end
  if min > a.abs
    min = a.abs
  end
  sum+=a.abs
end
if m_cnt.even?
  puts sum
else
  puts sum - 2 * min
end

Measured memory_bytes: 9732
#include<stdio.h>
#include<limits.h>
int c[20];
int memo[50010];

int f(int x){
    if(x==0)return 0;
    if(memo[x]!=0)return memo[x];
    int i,min=INT_MAX,a;
    for(i=0;i<20;i++){
        if(c[i]!=0&&x-c[i]>=0){
            a=f(x-c[i]);
            if(a<min)min=a;
        }
    }
    return memo[x]=min+1;
}
int main(void){
    int n,m,i;
    scanf("%d %d",&n,&m);
    for(i=0;i<m;i++)scanf("%d",&c[i]);
    printf("%d\n",f(n));
    return 0;
}

Measured memory_bytes: 3128
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    private static final Reader reader = new Reader();

    public static void main(String[] args) throws Exception{
        String str = reader.readLine();
        if(str.charAt(0)>='A' && str.charAt(0)<='Z')
            System.out.println('A');
        else
            System.out.println('a');
    }

    private static int difference(int n,int b1,int b2){
        int diff = Math.abs(b1-b2);
        return Math.min(n-diff,diff);
    }

    private static class Reader{
        private final BufferedReader br;
        public Reader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public int readInt() throws Exception{
            return Integer.parseInt(br.readLine());
        }
        public int readLong() throws Exception {
            return Integer.parseInt(br.readLine());
        }
        public double readDouble() throws Exception {
            return Double.parseDouble(br.readLine());
        }
        public String readLine() throws Exception{
            return br.readLine();
        }
        public int[] readIntArray() throws Exception{
            String[] tokens = br.readLine().split(" ");
            int[] nums = new int[tokens.length];
            for(int i=0;i<tokens.length;i++){
                nums[i] = Integer.parseInt(tokens[i]);
            }
            return nums;
        }
        public long[] readLongArray() throws Exception{
            String[] tokens = br.readLine().split(" ");
            long[] nums = new long[tokens.length];
            for(int i=0;i<tokens.length;i++){
                nums[i] = Long.parseLong(tokens[i]);
            }
            return nums;
        }
        public double[] readDoubleArray() throws Exception {
            String[] tokens = br.readLine().split(" ");
            double[] nums = new double[tokens.length];
            for(int i=0;i<tokens.length;i++){
                nums[i] = Double.parseDouble(tokens[i]);
            }
            return nums;
        }
        public String[] readWords() throws Exception {
            return br.readLine().split(" ");
        }
    }
}

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

int main(){
  int N;
  cin >> N;
  string tmp;
  vector<string> vec(N);
  for(int i=0; i < N;i++){
    cin >> tmp;
    sort(tmp.begin(), tmp.end());
    vec.at(i) = tmp;
    //cout << vec.at(i) << endl;
  }
  sort(vec.begin(), vec.end());
  vec.push_back("-1");

  
  string str_tmp = vec.at(0);
  long long int ans = 0;
  long long int cnt = 1;
  long long int ans_tmp;
  for(int i = 1; i <= N; i++){
    if(str_tmp == vec.at(i)){
      cnt += 1;
    } else {
      str_tmp = vec.at(i);
      ans_tmp = cnt * (cnt -1);
      ans += ans_tmp;
      cnt = 1;

    }
  }
  cout << ans/2<< endl;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<ll> T(n); rep(i, n) cin >> T[i];
  ll sum = accumulate(all(T), 0LL);
  int m; cin >> m;
  rep(i, m) {
    int p; ll x;
    cin >> p >> x; p--;
    cout << sum-T[p]+x << "\n";
  }
  return 0;
}


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

using namespace std;

#define int 		long long
#define endl		"\n"
#define mod			1000000007
#define inf			1e12
#define IOS			ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

void dfs(int src, vector<int>& dp, vector<vector<int>>& adj) {
	int mx = -1;

	for (auto to : adj[src]) {
		if (dp[to] == -1)
			dfs(to, dp, adj);
		mx = max(mx, dp[to]);
	}

	dp[src] = 1 + mx;
}

int32_t main() {

	IOS;

	int n, m;
	cin >> n >> m;

	vector<vector<int>> adj(n + 1, vector<int>());
	vector<int> dp(n + 1, -1);
	int x, y, ans = 0;

	for (int i = 0; i < m; i++) {
		cin >> x >> y;
		adj[x].push_back(y);
	}

	for (int i = 1; i <= n; i++) {
		if (dp[i] == -1) {
			dfs(i, dp, adj);
		}
		ans = max(ans, dp[i]);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 13456
/*		Author : Kaustubh Gangwar
		||S||A||M||R||A||T||
*/
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ld long double
#define pb push_back
#define gcd __gcd
#define vii vector<int>
#define vll vector<long long>
#define all(x) x.begin(),x.end()
#define f(i,a,b) for(int i=a;i<b;i++)
#define fe(i,a,b) for(int i=a;i<=b;i++)
#define nl '\n'
typedef long long  ll;
typedef pair<int,int> pii;

ll bpow(ll a, ll b) {
	a=a; ll res = 1;
    while(b){
        if (b & 1)
        res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

int32_t main()
{	ios_base::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	ll test=1;
	//cin>>test;
	while(test--)
	{
		ll n; cin>>n;
		if(n%1000)
		cout<<1000 - n%1000<<nl;
		else
		cout<<0;
		
	}
return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int read( ){
	int x=0,y=1;char ch=' ';
	for(;(ch!='-' && (ch>'9' || ch<'0'));ch=getchar( ));
	if(ch=='-')y=-1,ch=getchar( );
	for(;ch>='0' && ch<='9';ch=getchar( ))x=x*10+ch-48;
	return x*y;
}
int n;
char s[5010];
int main( ){
	int x,y,z,k;
	n=read( );
	scanf("%s",s);
	if(n>=3200)printf("%s",s);
	else printf("red\n");
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    vector<ll> a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];
    ll ans = 0;
    rrep(i, n) {
        ll sur = (a[i] + ans) % b[i];
        if (sur != 0) ans += b[i] - sur;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
from sys import exit, stderr, stdin
input = stdin.readline


def main():
    MOD = 10**9 + 7
    S = input()[:-1]
    L = len(S)
    # 余り
    memo = [0 for _ in range(13)]
    memo[0] = 1

    for i in range(L):
        memo_prev = [x for x in memo]
        memo = [0 for _ in range(13)]
        # 数字なら以前までの余りにたす
        if S[i].isnumeric():
            n = int(S[i])
            for m in range(13):
                cur = (10*m+n)%13
                memo[cur] += memo_prev[m]
        # ?なら1~10の余りのケース全てをためす
        else:
            for n in range(10):
                for m in range(13):
                    cur = (10*m+n)%13
                    memo[cur] += memo_prev[m]
            for m in range(13):
                memo[m] %= MOD
    print(memo[5])


if __name__ == "__main__":
    main()


Measured memory_bytes: 44780
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <chrono>
#include <queue>
#include <functional>

using namespace std;

typedef long long ll;

int main() {
    //cin.tie(0);
    //ios::sync_with_stdio(false);
    int N, Q;
    cin >> N >> Q;
    
    string S; cin >> S;

    vector<int> ac(N + 1);
    ac[0] = 0;
    for (int i = 1; i <= N; ++i) {
        ac[i] += ac[i - 1];

        if (i <= N - 1 && S[i - 1] == 'A' && S[i] == 'C') {
            ac[i] += 1;
        }
    }

    vector<int> ans(Q);

    for (int i = 0; i < Q; ++i) {
        int l, r;
        cin >> l >> r;

        ans[i] = ac[r] - ac[l - 1];

        if (r <= N - 1 && S[r - 1] == 'A' && S[r] == 'C') ans[i]--;
    }

    for (int i = 0; i < Q; ++i) {
        cout << ans[i] << std::endl;
    }


    return 0;
}

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

import sys

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

N=INT()
S=input()

sm1=[0]*(N+2)
for i in range(N):
    sm1[i+1]=sm1[i]
    if S[i]=='#':
        sm1[i+1]+=1
sm2=[0]*(N+2)
for i in range(N+1, 1, -1):
    sm2[i-1]=sm2[i]
    if S[i-2]=='.':
        sm2[i-1]+=1

ans=INF
for i in range(N+1):
    ans=min(ans, sm1[i]+sm2[i+1])
print(ans)


Measured memory_bytes: 14820
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
using namespace std;
vector<vector<long long>> v;
vector<long long> dp;
long long rec(long long in)
{
	if (dp[in] != -1) {
		return dp[in];
	}
	if (v[in].size() == 0) {
		dp[in] = 0;
		return 0;
	}
	long long ans = 0;
	for (int i = 0; i < v[in].size(); i++) {
		ans = max(ans, rec(v[in][i])+1);
	}
	dp[in] = ans;
	return dp[in];
}

int main()
{
	int N, M;
	cin >> N >> M;
	vector<long long> x(M), y(M);
	for (int i = 0; i < M; i++) {
		cin >> x[i] >> y[i];
		x[i]--;
		y[i]--;
	}
	v.resize(N);
	dp.resize(N,-1);
	for (int i = 0; i < M; i++) v[x[i]].push_back(y[i]);
	long long ans = 0;
	for (int i = 0; i < N; i++) {
		ans = max(ans, rec(i));
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 10112
#include<cstdio>
#include<cmath>
#include<vector>
#include<cstring>
#include<string>
#include<algorithm>

using namespace std;

int main()
{
	char input[200001];
	string str;
	int i, n;
	int dp[200000][2];

	scanf("%s", input);

	str = input;

	n = str.size();

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

	for (i = 1; i < n; i++)
	{
		dp[i][0] = dp[i - 1][1];

		if (str[i - 1] != str[i] && dp[i - 1][0] + 1 > dp[i][0])
		{
			dp[i][0] = dp[i - 1][0] + 1;
		}

		if (i > 1 && dp[i - 2][1] + 1 > dp[i][0])
		{
			dp[i][0] = dp[i - 2][1] + 1;
		}

		dp[i][1] = dp[i - 1][0] + 1;
	}

	printf("%d\n", dp[n - 1][0]);

	return 0;
}

Measured memory_bytes: 2176
fn main() {
    solve_b();
}
fn solve_b() {
    let mut buf = String::new();
    let handle = std::io::stdin();
    let n: usize = {
        handle.read_line(&mut buf).unwrap();
        let tmp = buf.trim().parse().unwrap();
        buf.clear();
        tmp
    };
    let mut a: String = {
        handle.read_line(&mut buf).unwrap();
        let tmp = buf.trim().parse().unwrap();
        buf.clear();
        tmp
    };
    let mut b: String = {
        handle.read_line(&mut buf).unwrap();
        let tmp = buf.trim().parse().unwrap();
        buf.clear();
        tmp
    };
    let mut c: String = {
        handle.read_line(&mut buf).unwrap();
        let tmp = buf.trim().parse().unwrap();
        buf.clear();
        tmp
    };
    let mut sum = 0;
    for i in 0..n {
        sum += b_diff(a.pop().unwrap(), b.pop().unwrap(), c.pop().unwrap());
    }
    println!("{}", sum);
}
fn b_diff(a: char, b: char, c: char) -> usize {
    if a == b && b == c {
        return 0;
    } else if a == b || b == c || c == a {
        return 1;
    } else {
        return 2;
    }
}


fn solve_a() {
    let mut buf = String::new();
    let handle = std::io::stdin();
    let config: Vec<usize> = {
        handle.read_line(&mut buf).unwrap();
        let tmp = buf
            .trim()
            .split_whitespace()
            .map(|a| a.parse().unwrap())
            .collect();
        buf.clear();
        tmp
    };
    let mut max;
    let mut min;
    if config[1] + config[2] > config[0] {
        min = config[1] + config[2] - config[0];
    } else {
        min = 0
    }
    max = {
        if config[1] < config[2] {
            config[1]
        } else {
            config[2]
        }
    };
    println!("{} {}", max, min);
}


Measured memory_bytes: 4352
#include<stdio.h>
#include<math.h>

int main(){
	double a, b, c, d, e, f;
	double x, y;
	int k;
	while(scanf("%lf %lf %lf %lf %lf %lf", &a, &b, &c, &d, &e, &f) != EOF){
		y = (c * d - a * f) / (b * d - e * a);
		y *= 1000;
		if(y > 0) y += 0.5;
		if(y < 0) y -= 0.5;
		k = y;
		y = k;
		y /= 1000;
		x = (c - b * y) / a;
		x *= 1000;
		if(x > 0) x += 0.5;
		if(x < 0) x -= 0.5;
		k = x;
		x = k;
		x = floor(x);
		x /= 1000;
		printf("%.3f %.3f\n", x, y);
	}
	return 0;
}

Measured memory_bytes: 652
#include <bits/stdc++.h>
#define FIO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;
typedef long long ll;

ll a[1000001];

int main() {
  /**
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
  **/
	FIO
	int n, k; cin >> n >> k;
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = k+1; i <= n; i++) {
		if (a[i] > a[i-k]) cout << "Yes" << "\n";
		else cout << "No" << "\n";
	}
	return 0;
}

Measured memory_bytes: 5196