akhauriyash/Code-Regression huggingface dataset:
//#define _GRIBCXX_DEBUG
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;


// ?????¬???????????¬??????
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<double> vd;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<long, long> pil;


// Effective std
template<typename C, typename T>
constexpr int count(C& c, T t) { return count(ALL(c), t); }

template<typename C, typename F>
constexpr int count_if(C& c, F f) { return count_if(ALL(c), f); }

template<typename C, typename T, typename U>
constexpr void replace(C& c, T t, U u) { replace(ALL(c), t, u); }

template<typename C, typename F, typename U>
constexpr void replace_if(C& c, F f, U u) { (ALL(c), f, u); }

template<typename C>
constexpr void sort(C& c) { sort(ALL(c)); }

template<typename C, typename Pred>
constexpr void sort(C& c, Pred p) { sort(ALL(c), p); }


// ??°?????????????????¬??????
typedef int Weight;

struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) {}
};

bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight :
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

int main(void){
    int r,c;
    cin >> r >> c;
    int **a = new int*[r+1];
    for(int i = 0; i < r+1; i++ ){
        a[i] = new int[c+1];
    }
    for(int i = 0; i < r; i++ ){
        for(int j = 0; j < c; j++ ){
            cin >> a[i][j];
        }
    }
    for(int i = 0; i < r; i++ ){
        for(int j = 0; j < c; j++ ){
            a[i][c] += a[i][j];
        }
    }
    for(int j = 0; j < c; j++ ){
        for(int i = 0; i < r; i++ ){
            a[r][j] += a[i][j];
        }
    }
    for(int i = 0; i < r; i++ ){
        a[r][c] += a[i][c];
    }
    for(int i = 0; i < r+1; i++ ){
        for(int j = 0; j < c+1; j++ ){
            cout << a[i][j];
            if( j != c ) cout << " ";
            else cout << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3068
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner stdin = new Scanner(System.in);

		// Read Integer from standard input
		int number = stdin.nextInt();

		if (number >= 1 && number <= 100) {
			// calculate cube
			int result = number * number * number;
			// Write value to standard output
			System.out.println(result);
		}
	}
}

Measured memory_bytes: 26076
// 問題の URL を書いておく
// 

#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;

//#define ENABLE_PRINT

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

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

template<int Mod>
struct MintBase {
  int64_t x; // typedef long long int64_t;
  MintBase(int64_t x=0):x((x%Mod+Mod)%Mod){}
  MintBase operator-() const { return MintBase(-x);}
  MintBase& operator+=(const MintBase a) {
    if ((x += a.x) >= Mod) x -= Mod;
    return *this;
  }
  MintBase& operator-=(const MintBase a) {
    if ((x += Mod-a.x) >= Mod) x -= Mod;
    return *this;
  }
  MintBase& operator*=(const MintBase a) { (x *= a.x) %= Mod; return *this;}
  MintBase operator+(const MintBase a) const { return MintBase(*this) += a;}
  MintBase operator-(const MintBase a) const { return MintBase(*this) -= a;}
  MintBase operator*(const MintBase a) const { return MintBase(*this) *= a;}
  MintBase pow(int64_t t) const {
    if (!t) return 1;
    MintBase a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime Mod
  MintBase inv() const { return pow(Mod-2);}
  MintBase& operator/=(const MintBase a) { return *this *= a.inv();}
  MintBase operator/(const MintBase a) const { return MintBase(*this) /= a;}
};

//const int Mod = 1000000007;
//const int Mod = 998244353;

using mint = MintBase<1000000007>;

using ll = int64_t;

int main(int, const char**)
{
    int n, k;
    cin >> n >> k;
    vector<mint> divs(k + 1, 0);

    mint ans(0);
    rep(i, k)
    {
        auto tn = k - i;
        auto base = k / tn;
        auto t = mint(base).pow(n);
        auto muls = 2 * tn;
        while(muls <= k)
        {
            t -= divs[muls];
            muls += tn;
        }
        divs[tn] = t;
        ans += t * tn;
    }
    cout << ans.x << endl;
    return 0;
}


Measured memory_bytes: 4032
import java.math.BigInteger;
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		BigInteger ba = sc.nextBigInteger();
		sc.close();
		while (!ba.isProbablePrime(Integer.MAX_VALUE)) {
			ba = ba.add(BigInteger.ONE);
		}
		System.out.println(ba);
	}

	public static int arrayMax(int[] array) {
		int ans = Integer.MIN_VALUE;
		for (int i = 0; i < array.length; i++) {
			if (array[i] > ans)
				ans = array[i];
		}
		return ans;
	}

	public static int[] arrayInt(Scanner sc, int n) {
		int[] array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		return array;
	}

	public static long[] arrayLong(Scanner sc, int n) {
		long[] array = new long[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextLong();
		}
		return array;
	}

	public static double[] arrayDouble(Scanner sc, int n) {
		double[] array = new double[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextDouble();
		}
		return array;
	}
}


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

int main(){
  int N;
  int A[1000];
  int count = 0;
  int i, v, j;

  cin >> N;

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

  for(count = 0 ; count < N ; count++){
    if(count!=N-1){
      cout << A[count] << " ";
    }else{
      cout << A[count];
    }
  }
  cout << endl;

  for(i = 1 ; i < N ; i++){
    v = A[i];
    j = i - 1;
    while(1){
      if(j >= 0 && A[j] > v){
	A[j+1] = A[j];
	j--;
	A[j+1] = v;
      }else{
	break;
      }
    }
   
    for(count = 0 ; count < N ; count++){
      if(count!=N-1){
	cout << A[count] << " ";
      }else{
	cout << A[count];
      }
    }
      cout << endl;
  }

  return 0;
}

Measured memory_bytes: 1164
import sys
input = lambda: sys.stdin.readline()


class BIT:
    def __init__(self, n):
        self.n = n
        self.data = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.n:
            self.data[i] += x
            i += i & -i


n, m = map(int, input().split())
c = list(map(int, input().split()))
b = BIT(n)
for i in range(n):
    b.add(i + 1, c[i])

res = []
for i in range(m):
    t, x, y = map(int, input().split())
    if t == 1:
        res.append(b.sum(y) - b.sum(x))
    else:
        b.add(x + 1, y)
print("\n".join(map(str, res)))


Measured memory_bytes: 175732
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int n,m;
  cin>>n>>m;
  int a[n+1]={};
  for(int i=0;i<m;i++){
    int x,y;
    cin>>x>>y;
    a[x]^=1;
    a[y]^=1;
  }
  for(int i=1;i<=n;i++){
    if(a[i]){
      cout<<"NO"<<endl;
      return 0;
    }
  }

  cout<<"YES"<<endl;

  return 0;
}


Measured memory_bytes: 768
#include <iostream>

using namespace std;

int main(){
	int i, j, k, n, m, l;
	cin >> n >> m >> l;
	int A[n][m], B[m][l];

	for(i = 0; i < n; i++){
		for(j = 0; j < m; j++){
			cin >> A[i][j];
		}
	}

	for(i = 0; i < m; i++){
		for(j = 0; j < l; j++){
			cin >> B[i][j];
		}
	}

	for(i = 0; i < n; i++){
		long sum;
		for(j = 0; j < l; j++){
			sum = 0;
			for(k = 0; k < m; k++){
				sum += A[i][k] * B[k][j];
			}
			if(j == l-1) break;
			cout << sum << ' ';
		}
		cout << sum << endl;
	}
}

Measured memory_bytes: 3152
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
int w,h;
ll p[111111];
ll q[111111];
ll qr[111111];
int main(void){
  cin >> w >> h;

  ll sp = 0;
  for(int i = 0; i < w; i++){
    cin >> p[i];
    sp += p[i];
  }

  ll sq = 0;
  ll qma = -1;
  ll qmi = 1LL<<60;
  for(int i = 1; i <= h; i++){
    cin >> q[i];
    qr[i] = q[i];
    sq += q[i];
    qma = max(qma,q[i]);
    qmi = min(qmi,q[i]);
  }

  sort(p,p+w);
  sort(q,q+h+1);
  sort(qr,qr+h+1);
  for(int i = 0; i <= h; i++){
    qr[i+1] += qr[i];
  }

  ll ans = sp+sq;
  for(int i = 0; i < w; i++){
    // ans += min(p[i]*(w-1)+qmi,sq-qma+p[i]);

    int k = upper_bound(q,q+h+1,p[i])-q-1;
    ans += p[i]*(h-k) + qr[k];

  }
  cout << ans << endl;
}


Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        String N = scanner.next();
        char c = N.charAt(N.length() - 1);
        switch (c) {
            case '2':
            case '4':
            case '5':
            case '7':
            case '9':
                System.out.println("hon");
                break;
            case '0':
            case '1':
            case '6':
            case '8':
                System.out.println("pon");
                break;
            case '3':
                System.out.println("bon");
                break;
        }
    }
}


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

lt = len(t)

minc = 1000
for i in range(len(s)):
  ress = s[i:i + lt]
  if len(ress) != lt:
    break
  
  minc = min(minc, sum([1*(x != y) for x,y in zip(ress, t)]))
print(minc)

Measured memory_bytes: 67500
#include<iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1 << 21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

int prim() {
	int u, minv;
	int d[MAX], p[MAX], color[MAX];

	for (int i = 0; i < n; i++) {
		d[i] = INFTY;
		p[i] = -1;
		color[i] = WHITE;
	}

	d[0] = 0;

	while (true) {
		minv = INFTY;
		u = -1;
		for (int i = 0; i < n; i++) {
			if (minv > d[i] && color[i] != BLACK) {
				u = i;
				minv = d[i];
			}
		}
		if (u == -1)break;
		color[u] = BLACK;
		for (int v = 0; v < n; v++) {
			if (color[v] != BLACK&&M[u][v] != INFTY) {
				if (d[v] > M[u][v]) {
					d[v] = M[u][v];
					p[v] = u;
					color[v] = GRAY;
				}
			}
		}
	}
	int sum = 0;
	for (int i = 0; i < n; i++) {
		if (p[i] != -1)sum += M[i][p[i]];
	}

	return sum;	
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			int e; cin >> e;
			M[i][j] = (e == -1) ? INFTY : e;
		}
	}
	cout << prim() << endl;
	return 0;
}

Measured memory_bytes: 3116
//写経コード
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(int i= 0; i<n; i++)
static const int INF = (1<<29);
using namespace std;

vector<int> to[2505];
vector<int> rto[2505];
bool reachableFrom1[2505];
bool reachableToN[2505];
bool ok[2505];
//Bellman-Ford法・最大経路問題？→負の数をかけて最小経路問題
//Bellman-Ford法は負閉路検知もできる(n-1以内に収束しなければならない)
//ただしd[N]=d[2N]での判定は嘘

void dfs(int v){
    if(reachableFrom1[v]) return;
    reachableFrom1[v] = true;
    for(int u: to[v]){
        dfs(u);
    }
}

void rdfs(int v){
    if(reachableToN[v]) return;
    reachableToN[v] = true;
    for(int u: rto[v]){
        rdfs(u);
    }
}

int main(){
    int n,m,p;
    cin >> n >> m >>p;
    vector<tuple<int,int,int>> edges;
    
    rep(i,m){
        int a,b,c;
        cin >> a >> b >> c;
        a--;b--;
        c -= p;//先にポイントを引いておく
        c = -c;//負の値に
        edges.emplace_back(a,b,c);
        to[a].push_back(b);
        rto[b].push_back(a);
    }
    dfs(0);
    rdfs(n-1);
    rep(i,n) ok[i] = reachableFrom1[i]&reachableToN[i];
    {  //bellman-ford
        vector<int> d(n,INF);
        d[0] = 0;
        bool upd = true;
        int step = 0;
        while(upd){
            upd = false;
            rep(i,m){
                int a,b,c;
                tie(a,b,c) = edges[i];
                if(!ok[a]) continue;
                if(!ok[b]) continue;
                int newD= d[a]+c;
                if(newD < d[b]){
                    upd = true;
                    d[b] = newD;
                }
            }
        step++;
        if(step>n){
            puts("-1");
            return 0;
        }
        }
        int ans = -d[n-1];
        ans = max(ans,0);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
#define pb push_back
#define eb emplace_back
int main()
{

ll n;

cin>>n;
  string str;

  cin>>str;
  ll w=0,bw=0;

  ll j=n-1;
  ll i=0;
  ll cnt=0;

while(i<j)
  {
      if(str[i]=='W' && str[j]=='R')
      { cnt++;
          swap(str[i],str[j]);
      }
      if(str[i]=='R')i++;
      if(str[j]=='W')j--;


  }


  cout<<cnt<<endl;



}


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

typedef long long int ll;

int main(){
	int n, k; scanf("%d %d",&n,&k);
	int mx = (n-1)*(n-2)/2;
	if(k>mx){
		printf("-1");
		return 0;
	}
	printf("%d\n",n*(n-1)/2-k);
	int yet = 0;
	for(int i=1;i<n;i++){
		printf("%d %d\n",i,n);
	}
	for(int i=1;i<n-1;i++){
		for(int j=i+1;j<n;j++){
			yet++;
			if(yet>k) printf("%d %d\n",i,j);
		}
	}
}


Measured memory_bytes: 256
sel='B'
#A
if sel=='A':
    N,M=map(int,input().split())
    ans=0
    ans+=M*(M-1)//2
    ans+=N*(N-1)//2
    print(ans)

#B
if sel=='B':
    def ispal(s):
        for i in range(len(s)//2+1):
            if s[i]!=s[-(i+1)]:
                return False
        return True

    S=input()
    N=len(S)
    if ispal(S) and ispal(S[:(N-1)//2]) and ispal(S[(N+3)//2-1:]):
        print('Yes')
    else:
        print('No')

#C
if sel=='C':
    L=int(input())
    print((L**3)/27)

#D
if sel=='D':    
    N=int(input())
    A=[int(i) for i in input().split()]
    kin=list(set(A))
    cnt={}
    for k in kin:
        cnt[k]=0
    for a in A:
        cnt[a]+=1
    SUM=0
    for k in kin:
        SUM+=cnt[k]*(cnt[k]-1)//2
    for a in A:
        if cnt[a]>=2:
            print(SUM-cnt[a]+1)
        else:
            print(SUM)
        
#E
if sel=='E':
    a=0

#F
if sel=='F':
    N,S=map(int,input().split())
    A=[int(i) for i in input().split()]

    for l in range(N):
        for r in range(l,N):
            print(tab[l][r])



Measured memory_bytes: 3064
using System;

class Program
{
    static void Main()
    {
        var a = Console.ReadLine();
        var b = Console.ReadLine();
        bool greater = true;
        if (a.Length == b.Length)
        {
            for (int i = 0; i < a.Length; i++)
            {
                if (a[i] > b[i])
                {
                    greater = true;
                    break;
                }
                else if (a[i] < b[i])
                {
                    greater = false;
                    break;
                }
            }
        }
        else if (a.Length < b.Length) greater = false;
        if (a == b) Console.WriteLine("EQUAL");
        else Console.WriteLine(greater ? "GREATER" : "LESS");
    }
}


Measured memory_bytes: 11092
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

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

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

    // input
    ll N, C;
    cin >> N >> C;

    vector<ll> X(N+1);
    vector<ll> V(N+1);

    X[0] = 0;
    V[0] = 0;

    FOR(i, 1, N+1){
        cin >> X.at(i);
        cin >> V.at(i);
    }

    // 価値の累積和
    vector<ll> Ac(N+1);

    // i個目まで食べたときの満腹度
    vector<ll> f(N+1);

    // iまで行けるときのMax満腹度
    vector<ll> g(N+1);

    ll max_value = 0;

    // mode 0 : Bで折り返す
    // mode 1 : Aで折り返す
    FOR(mode, 0, 2){
        // br();
        // cout << "mode " << mode << "---------------------------------" << endl;

        if(mode==1){
            reverse(X.begin()+1, X.end());
            FOR(i, 1, N+1){
                X[i] = C - X[i];
            }
            reverse(V.begin()+1, V.end());
        }

        Ac[0] = V[0];
        FOR(i, 1, N+1){
            Ac[i] = Ac[i-1] + V[i];
        }

        // p("Ac");
        // vprint(Ac);

        FOR(i, 0, N+1){
            f[i] = Ac[i] - X[i];
        }

        // br();
        // p("f");
        // vprint(f);

        g[0] = f[0];
        FOR(i, 1, N+1){
            g[i] = max(g[i-1], f[i]);
        }

        // br();
        // p("g");
        // vprint(g);

        // xbを固定する
        FOR(i, 0, N+1){
            ll xb = X[i];
            // br();
            // pn(i);
            // pn(xb);

            ll b_eat;
            ll b_walk;
            if(i==0){
                b_eat = 0;
                b_walk = 0;
            }else{
                b_eat = Ac[N] - Ac[i-1];
                b_walk = C - xb;
            }
            ll b_value = b_eat -  2 * b_walk;
            // pn(b_value);

            ll a_value;
            if(i==0){
                a_value = g[N];
            }else{
                a_value = g[i-1];
            }
            // pn(a_value);

            ll value = a_value + b_value;
            // pn(value);
            max_value = max(max_value, value);
        }
    }

    p(max_value);
    
    return 0;
}

Measured memory_bytes: 4224
from time import time
start = time()
import random
from sys import stdin
input = stdin.readline
D = int(input())
*c, = map(int, input().split())
S = []
for _ in [None] * D:
    *s, = map(int, input().split())
    S += s,
INF = float("inf")

def Tread(D):
    return [int(input()) for i in [None] * D]

def check(T):
    M = 0
    MM = []
    last = [-1] * 26
    for d, t in enumerate(T):
        M += S[d][t] - sum((d - last[i]) * c[i] for i in range(26) if i != t)
        last[t] = d
        # MM += M,
    return M # MM

def 貪欲():
    M = 0
    T = []
    last = [-1] * 26
    for d in range(D):
        m = -INF
        for j in range(26):
            Q = S[d][j] - sum((d - last[i]) * c[i] for i in range(26) if i != j)
            if m < Q:
                t, m = j, Q
        T += t,
        last[t] = d
        M += m
        # print(M)
    return T, M

def 局所探索():
    T, M = 貪欲()
    # print(T, M)
    while time() - start < 1.91:
        d, q = random.randrange(D), random.randrange(26)
        Check = T[:]
        Check[d] = q
        C = check(Check)
        if C > M:
            M, T = C, Check
    for s in T:print(s + 1)
    # print(M)

局所探索()


Measured memory_bytes: 84676
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
using namespace std;
typedef pair<int, int> P;
typedef vector<int> vi;

signed main(){
    int n, t;
    cin >> n >> t;
    vector<int> a(n);
    rep(i, 0, n){
        cin >> a[i];
    }
    int MIN = a[0], MAXdiff = 0, cnt = 0;
    rep(i, 1, n){
        if(MIN > a[i]){
            MIN = a[i];
        }else if(MAXdiff == a[i] - MIN){
            cnt++;
        }else if(MAXdiff < a[i] - MIN){
            MAXdiff = a[i] - MIN;
            cnt = 1;
        }
    }
    o(cnt);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF INT_MAX
#define eps LDBL_EPSILON
#define moder 100000
#define pie 3.141592653589793238462643383279
#define P std::pair<int,int>
#define prique priority_queue
using namespace std;
int h,w,d,a[310][310],q,l,r;
map<int,P> mp;
vector<int> vec[90010];
signed main(){
	cin>>h>>w>>d;
	rep(i,h){
		rep(j,w){
			cin>>a[i][j];
			mp[a[i][j]]={i,j};
		}
	}
	for(int i=1;i<=d;i++){
		vec[i%d].push_back(0);
		for(int j=i%d+d;j<=h*w;j+=d){
			vec[i%d].push_back(abs(mp[j].first-mp[j-d].first)+abs(mp[j].second-mp[j-d].second));
		}
		for(int j=1;j<vec[i%d].size();j++){
			vec[i%d][j]+=vec[i%d][j-1];
		}
	}
	cin>>q;
	rep(i,q){
		cin>>l>>r;
		cout<<vec[l%d][r/d]-vec[l%d][l/d]<<endl;
	}
	return 0;
}

Measured memory_bytes: 11776
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>
#include <unordered_map>
#include <unordered_set>
#include <assert.h>
using namespace std;


#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

vector<char> ans;

void solve(ll & a, ll & b, char c) {
	a++;
	b--;
	ans.push_back(c);
}

bool move(ll &a, ll &b, char ca, char cb, ll an, ll bn, vector<ll> &s) {
	if (a == 0 and b == 0) return false;
	else if (a == 1 and b == 1) {
		if (s[an] < s[bn])solve(a, b, ca);
		else solve(b, a, cb);
	}
	else if (a < b) solve(a, b, ca);
	else solve(b, a, cb);
	return true;
}

int main() {
	ll n, a, b, c;
	cin >> n >> a >> b >> c;
	vector<string> s(n);
	REP(i, n) cin >> s[i];
	bool ok = true;
	vector <vector<ll>> v(n + 1, vector<ll>(3));
	REPR(i, n - 1) {
		REP(j, 3)v[i][j] = v[i + 1][j] + 1;
		if (s[i] == "AB") v[i][0] = 0;
		if (s[i] == "AC") v[i][1] = 0;
		if (s[i] == "BC") v[i][2] = 0;
	}
	REP(i, n) {
		if (s[i] == "AB") if (!move(a, b, 'A', 'B', 1, 2, v[i])) ok = false;
		if (s[i] == "AC") if (!move(a, c, 'A', 'C', 0, 2, v[i])) ok = false;
		if (s[i] == "BC") if (!move(b, c, 'B', 'C', 0, 1, v[i])) ok = false;
	}
	if (!ok) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	REP(i, n) cout << ans[i] << endl;
}



Measured memory_bytes: 11940
import java.io.*;
import java.util.*;
 
public class Main{
	int N;
	int M;
	boolean[] A;
	long[] memo;
	long MOD = 1000000007;
		 
	void solve() {
		N = nextInt();
		M = nextInt();
		A = new boolean[N + 1];
		for(int i = 0; i < M; i++) {
			int a = nextInt();
			A[a] = true;
		}
		memo = new long[N + 1];
		memo[0] = 1;
		for(int i = 1; i < N + 1; i++) {
			if(A[i]) {
				memo[i] = 0;
			}else {
				memo[i] = memo[i - 1];
				if(i > 1) {
					memo[i] = (memo[i] + memo[i - 2]) % MOD;
				}
			}
		}
		out.println(memo[N]);
	}
	
	
	
	private static PrintWriter out;
	public static void main(String[] args){
		out = new PrintWriter(System.out);
		new Main().solve();
		out.flush();
	}
	
	
	
	public static int nextInt(){
		int num = 0;
		String str = next();
		boolean minus = false;
		int i = 0;
		if(str.charAt(0) == '-'){
			minus = true;
			i++;
		}
		int len = str.length();
		for(;i < len; i++){
			char c = str.charAt(i);
			if(!('0' <= c && c <= '9')) throw new RuntimeException();
			num = num * 10 + (c - '0');
		}
		return minus ? -num : num;
	}
	
	public static long nextLong(){
		long num = 0;
		String str = next();
		boolean minus = false;
		int i = 0;
		if(str.charAt(0) == '-'){
			minus = true;
			i++;
		}
		int len = str.length();
		for(;i < len; i++){
			char c = str.charAt(i);
			if(!('0' <= c && c <= '9')) throw new RuntimeException();
			num = num * 10l + (c - '0');
		}
		return minus ? -num : num;
	}
	public static String next(){
		int c;
		while(!isAlNum(c = read())){}
		StringBuilder build = new StringBuilder();
		build.append((char)c);
		while(isAlNum(c = read())){
			build.append((char)c);
		}
		return build.toString();
	}
	
	
	private static byte[] inputBuffer = new byte[1024];
	private static int bufferLength = 0;
	private static int bufferIndex = 0;
	private static int read(){
		if(bufferLength < 0) throw new RuntimeException();
		if(bufferIndex >= bufferLength){
			try{
				bufferLength = System.in.read(inputBuffer);
				bufferIndex = 0;
			}catch(IOException e){
				throw new RuntimeException(e);
			}
			if(bufferLength <= 0) return (bufferLength = -1);
		}
		return inputBuffer[bufferIndex++];
	}
	
	private static boolean isAlNum(int c){
		return '!' <= c && c <= '~';
	}
}

Measured memory_bytes: 33336
#include <stdio.h>

int main(void){
	int p[1000], n, m, total, temp, i, j;
	while (1){
		scanf("%d%d", &n, &m);
		if (n == 0) break;
		total = 0;
		for (i = 0; i < n; i++){
			scanf("%d", &p[i]);
			total += p[i];
		}
		for (i = 0; i < n - 1; i++){
			for (j = n - 1; j > i; j--){
				if (p[j] > p[j-1]){
					temp = p[j];
					p[j] = p[j-1];
					p[j-1] = temp;
				}
			}
		}
		for (i = m - 1; i < n; i += m){
			total -= p[i];
		}
		printf("%d\n", total);
	}
	return 0;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  
  vector<int> roads(N);
  int city;
  rep(i, M*2) {
    cin >> city;
    roads.at(city-1)++;
  }
  
  rep(i, roads.size()) {
    cout << roads.at(i) << endl;
  }
}

Measured memory_bytes: 256
S = input()
if S[0] == S[1] == S[2] == S[3]:
    print("No")
elif S[0] == S[1] and S[2] == S[3]:
    print("Yes")
elif S[0] == S[2] and S[1] == S[3]:
    print("Yes")
elif S[0] == S[3] and S[1] == S[2]:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
using namespace std;

int main(){
	long long N,M;
	
	cin >> N >> M;
	
	long long ans=0,nokori_c,ans_c;

	ans = ans + N;

	nokori_c = M - 2*N;
	if(nokori_c >= 0){
		ans_c = nokori_c/4;
		ans = ans + ans_c;
	}
	else if(nokori_c < 0){
		ans_c = M/2;
		
		ans = ans + ans_c -N;		
	}



	if(M < 2){
		ans =0;
	}


	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#define RI register int
#define CI const int&
#define CL const LL&
using namespace std;
typedef long long LL;
const int N=200005;
struct point
{
	LL x,y;
	inline point(CL X=0,CL Y=0) { x=X; y=Y; }
	friend inline point operator - (const point& A,const point& B)
	{
		return point(A.x-B.x,A.y-B.y);
	}
}p[N],stk[N]; LL n,m,a[N],b[N],c[N],pos,ans;
inline LL Cross(const point& A,const point& B)
{
	return A.x*B.y-A.y*B.x;
}
inline int Convex_Hull(point *p,CI n)
{
	RI i,top=0; for (i=1;i<=n;++i)
	{
		while (top>1&&Cross(stk[top]-stk[top-1],p[i]-stk[top])>0) --top;
		stk[++top]=p[i];
	}
	for (i=1;i<=top;++i) p[i]=stk[i]; return top;
}
int main()
{
	RI i; for (scanf("%lld",&n),i=1;i<=n;++i) scanf("%lld",&a[i]);
	for (i=1;i<=n;++i) scanf("%lld",&b[i]),a[i]>a[pos]&&(pos=i);
	for (i=pos;i<=n;++i) c[++m]=a[i]; for (i=1;i<=pos;++i) c[++m]=a[i];
	for (i=1;i<=m;++i) a[i]=c[i]; m=0;
	for (i=pos;i<=n;++i) c[++m]=b[i]; for (i=1;i<=pos;++i) c[++m]=b[i];
	for (i=1;i<=m;++i) b[i]=c[i]; c[1]=0; ++n;
	for (i=2;i<=n;++i) c[i]=2LL*(b[i-1]+c[i-1])-c[i-2];
	for (i=1;i<=n;++i) p[i]=point(i,a[i]-c[i]);
	for (m=n,n=Convex_Hull(p,n),i=2;i<=n;++i)
	ans+=(p[i].x-p[i-1].x)*(p[i].y+p[i-1].y);
	for (ans+=p[1].y+p[n].y,i=1;i<=m;++i) ans+=2LL*c[i];
	return ans-=2LL*a[1],printf("%.12lf",0.5*ans/(m-1)),0;
}

Measured memory_bytes: 12628
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) b.begin(), v.end()
#define fi first
#define se second
const int MAXN = 1e5 + 5;
int vec[MAXN], pref[MAXN], n , t;


int main()
{
	int w, h, n;
	scanf("%d %d %d", &w, &h, &n);
	int x1 = 0, xn = w, y1 = 0, yn = h;
	for(int i = 1; i <= n; i++)
	{
		int x, y, r;
		cin >> x >> y >> r;
		if(r == 1) x1 = max(x1, x);
		if(r == 2) xn = min(xn, x);
		if(r == 3) y1 = max(y1, y);
		if(r == 4) yn = min(yn, y);
	}
	
 	int a  = yn - y1;
	int b  = xn - x1;
	if(a < 0 or b < 0) return puts("0"), 0;
	else cout << a*b;
	return 0;
	
}

Measured memory_bytes: 256
n,m = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(n)]


from operator import itemgetter
def main():
    AB.sort(key = itemgetter(0))
    cnt = 0
    ans = 0
    for a,b in AB:
        if b + cnt < m:
            cnt += b 
            ans += b*a
        else:
            ans += (m - cnt)*a
            print(ans)
            return



if __name__ == "__main__":
    main()

Measured memory_bytes: 29032
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n; cin>>n;
	int ret=0;
	for (int i=1; i<=n; i++)	{
		if (to_string(i).size()%2)
			ret++;
	}
	cout<<ret<<"\n";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;


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

	string s;
	cin >> s;
	s.erase(s.begin() + s.size()-1);
	int a = s.size();
	rep(i, a) {
		if (s.size() % 2 == 0) {
			string t = s.substr(0, s.size() / 2);
			if (s == t + t) {
				cout << s.size() << endl;
				return 0;
			}
		}
		s.erase(s.begin() + s.size()-1);
	}
	
	return 0;
}



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

int main() {
	int n;
	cin >> n;
	vector<int> f(n);
	vector<vector<int>> p(n, vector<int>(11));
	rep(i, n) {
		int now = 0;
		rep(j, 10){
			int tmp;
			cin >> tmp;
			now += tmp<<j;
		}
		f[i] = now;
	}
	rep(i, n) rep(j, 11) {
		cin >> p[i][j];
	}
	int ans = -1001001001;
	for(int bit = 1; bit < (1<<10); bit++) {
		int now = 0;
		rep(i, n) {
			int same = 0;
			rep(j, 10) {
				if(((bit>>j) & 1) && ((f[i]>>j) & 1)) {
					same++;
				}
			}
			now += p[i][same];
		}
		ans = max(ans, now); 
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
vector<ll> sh, tem;
int a,b,q;
ll get_near(ll x, vector<ll>&tem) {
    auto nt = lower_bound(tem.begin(),tem.end(),x);
    ll ret = LONG_LONG_MAX;
    if(nt != tem.end()) {
        ret=*nt-x;
    }
    if(nt!=tem.begin()){
        nt--;
        ret=min(ret,x-*nt);
    }
    return ret;
}
int main()
{
    cin>>a>>b>>q;
    for(int i=1;i<=a;++i)
    {
        ll loc;
        cin>>loc;
        sh.push_back(loc);
    }
    for(int i=1;i<=b;++i)
    {
        ll loc;
        cin>>loc;
        tem.push_back(loc);
    }
    while(q--)
    {
        ll x;
        cin>>x;
        auto ptr = lower_bound(sh.begin(),sh.end(),x);
        ll out = LONG_LONG_MAX;
        if(ptr != sh.end()) {
            ll t1 = *ptr - x;
            t1 += get_near(*ptr,tem);
            out = min(out,t1);
        }
        if(ptr != sh.begin()) {
            ptr--;
            ll t1 = x - *ptr;
            t1 += get_near(*ptr,tem);
            out = min(out,t1);
        }
        ptr = lower_bound(tem.begin(),tem.end(),x);
        if(ptr != tem.end()) {
            ll t1 = *ptr - x;
            t1 += get_near(*ptr,sh);
            out = min(out,t1);
        }
        if(ptr != tem.begin()) {
            ptr--;
            ll t1 = x - *ptr;
            t1 += get_near(*ptr,sh);
            out = min(out,t1);
        }
        cout<<out<<endl;
    }
}

Measured memory_bytes: 3060
def main():
    import sys
    from collections import deque
    input = sys.stdin.readline
    N, K = [int(x) for x in input().strip().split()]
    P = [int(x)-1 for x in input().strip().split()]
    C = [int(x) for x in input().strip().split()]
    ans = -float('inf')
    f_cnt = [0] * N
    f_score = [0] * N
    for i in range(N):
        if f_cnt[i]:
            continue
        flag = [False] * N
        q = deque([])
        j = i
        cnt = 0
        score = 0
        while not flag[j]:
            flag[j] = True
            q.append(j)
            score += C[j]
            cnt += 1
            j = P[j]
        for j in q:
            f_cnt[j] = cnt
            f_score[j] = score
    # print(*f_cnt)
    # print(*f_score)

    def f(cur, cnt):
        ret = -float('inf')
        ret_ = 0
        if f_score[cur] >= 0:
            ret_ += f_score[cur] * (cnt // f_cnt[cur] - 1)
            cnt = cnt % f_cnt[cur] + f_cnt[cur]
            ret = ret_
        else:
            cnt = min(cnt, f_cnt[cur])

        while cnt:
            # print('  cur = {}, cnt = {}, ret = {}'.format(cur, cnt, ret_))
            cur = P[cur]
            ret_ += C[cur]
            ret = max(ret, ret_)
            cnt -= 1

        return ret

    for i in range(N):
        # print('i = {}'.format(i))
        ans = max(ans, f(i, K))
    
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 70152
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let a: i64 = itr.next().unwrap().parse().unwrap();
    let b: i64 = itr.next().unwrap().parse().unwrap();
    let _: i64 = itr.next().unwrap().parse().unwrap();
    let mut k: i64 = itr.next().unwrap().parse().unwrap();

    let mut ans = 0;
    if k <= a {
        println!("{}", k);
        return;
    }
    k -= a;
    ans += a;
    if k <= b {
        println!("{}", ans);
        return;
    }
    k -= b;
    println!("{}", ans - k);
}


Measured memory_bytes: 2152
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    long n;
    scanf("%ld", &n);
    char str[n+1];
    scanf("%s", str);
    
    long nCount = 0;
    for(long i = 0; i < n; i++){
        if(str[i] == 'R'){
            nCount++;
        }
    }
    long nAns = 0;
    for(long i = 0; i < nCount; i++){
        if(str[i] == 'W'){
            nAns++;
        }
    }
  
    printf("%ld", nAns);
    return 0;
}


Measured memory_bytes: 1904
# include <iostream>
# include <cstdio>
# include <algorithm>
# include <queue>
# include <map>
# include <cmath>
# include <sstream>
# include <vector>
# include <string>
# include <cstring>
# include <set>
# include <ctype.h>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
char s1[110], s2[110], s3[110];
int main ()
{
    while (cin >> s1 >> s2 >> s3)
    {
        printf ("%c%c%c\n", toupper(s1[0]), toupper(s2[0]), toupper(s3[0]));
    }

    return 0;
}



Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

var n int
var G map[int][]int

func initGraph() {
	G = make(map[int][]int, n)
}

func add(x, y int) {
	if _, ok := G[x]; !ok {
		G[x] = make([]int, 0, n)
	}
	G[x] = append(G[x], y)
}

var seen map[int]bool
var ba, bb int

func dfs(v int) {
	seen[v] = true
	for _, nv := range G[v] {
		if seen[nv] {
			continue
		}
		if (v == ba && nv == bb) || (v == bb && nv == ba) {
			continue
		}
		dfs(nv)
	}
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n = readInt()
	m := readInt()
	initGraph()

	type bridge struct{ a, b int }
	bs := make([]bridge, m)
	for i := 0; i < m; i++ {
		a, b := readInt(), readInt()
		add(a, b)
		add(b, a)
		bs[i] = bridge{a, b}
	}

	ans := 0
	for _, bv := range bs {
		ba, bb = bv.a, bv.b
		seen = make(map[int]bool, n)
		dfs(1)
		if len(seen) != n {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 768
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")

from collections import Counter


def factorial(n):
    prime_count = Counter()

    for i in range(2, int(n**0.5) + 2):
        while n % i == 0:
            n /= i
            prime_count[i] += 1
    if n > 1:
        prime_count[int(n)] += 1

    return prime_count


def num_divisors(prime_count):
    num = 1

    for prime, count in prime_count.items():
        num *= (count + 1)

    return num


def divisors(n):
    ret = set()
    for i in range(1, int(n ** 0.5) + 1):
        d, m = divmod(n, i)
        if m == 0:
            ret.add(i)
            ret.add(d)
    return sorted(ret)


def solve(N: int):

    f = factorial(N-1)
    ans = num_divisors(f)-1

    divs = divisors(N)
    for k in divs:
        if k == 1:
            continue
        n = N
        while n % k == 0:
            n = n//k
            if n == 1:
                break
        if n % k == 1:
            ans += 1
    print(ans)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)


if __name__ == '__main__':
    main()


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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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; }

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}


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

  int n;
  cin >> n;

  int b = n % 1000;

  if(b == 0){
    cout << 0 << endl;
  }else{
    cout << 1000 - b << endl;
  }
  return 0;
}


Measured memory_bytes: 3544
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
using namespace std; //std::の省略のため
using ll = long long;

ll MOD = 1000000007;

int main()
{
    ll n;
    cin >> n;

    ll a[n];
    ll cnt[n] = {};

    bool judge = true;

    for(int i=0; i<n; i++)
        cin >> a[i];

    if(n%2 == 0){
        for(int i=0; i<n; i++){
            cnt[a[i]]++;
            if(cnt[a[i]] > 0 && a[i] == 0){
                judge = false;
                break;
            }
            else if(cnt[a[i]] > 2){
                judge = false;
                break;
            }
        }
        
    }
    else{
        for(int i=0; i<n; i++){
            cnt[a[i]]++;
            if(cnt[a[i]] > 1 && a[i] == 0){
                judge = false;
                break;
            }
            else if(cnt[a[i]] > 2){
                judge = false;
                break;
            }
        }
    }

    ll ans = 1;

    for(int i=0; i<(n/2); i++){
        ans *= 2;
        ans %= MOD;
    }

    if(judge){
        cout << ans << endl;
    }
    else{
        cout << 0 << endl;
    }

    }


Measured memory_bytes: 5108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=105,INF=1<<30;
map<string,ll> MA;

ll solve(string &S){
    if(MA[S]) return MA[S];
    int N=si(S);
    if(N==1) return (S[0]-'0'+1);
    vector<ll> dp(N+1,0);
    dp[0]=1;
    
    for(int i=0;i<N;i++){
        dp[i+1]+=dp[i]*(S[i]-'0'+1);
        dp[i+1]%=mod;
        
        for(int plus=2;i+plus<=N;plus++){
            for(int x=1;x<plus;x++){
                if(plus%x) continue;
                string T=S.substr(i,x);
                for(int y=i;y+x-1<i+plus;y+=x){
                    string U=S.substr(y,x);
                    for(int z=0;z<x;z++){
                        if(T[z]=='0'||U[z]=='0') T[z]='0';
                    }
                }
                
                dp[i+plus]+=dp[i]*solve(T);
                dp[i+plus]%=mod;
            }
        }
    }
    
    return MA[S]=dp[N];
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string S;cin>>S;
    
    cout<<solve(S)<<endl;
    
}


Measured memory_bytes: 1536
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
    
int main(){
    long long int N,A,B;
    cin >> N >> A >> B;
    long long int num=0,mod=0;
    if(A==0){
        cout << 0 << endl;
    }
    else{
        num=N/(A+B);
        mod=N-(num*(A+B));
        if(mod>A){
            long long int ans=(num*A)+A;
            cout << ans << endl;
        }
        else{
            long long int ans=(num*A)+mod;
            cout << ans << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int A, B, C;
	cin >> A >> B >> C;
	C = max(0, C - A + B);

	co(C);

	Would you please return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
 
using namespace std;
int v[200004];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<n;i++){
        int x;
        cin>>x;
        v[x]++;
    }
    for(int i=1;i<=n;i++){
        cout<<v[i]<<"\n";
    }
    return 0;
}

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

bool islower(char c)
{
  return (c>='a' && c<='z');
}

bool isupper(char c)
{
  return (c>='A' && c<='Z');
}

char to_upper(char c)
{
  return c-0x20;
}

char to_lower(char c)
{
  return c+0x20;
}

int main()
{
  string s;
  while(true)
  {
    char c;
    scanf("%c",&c);
    if(c=='\n') break;
    s.push_back(c);
  }

  for (int i = 0; i < s.size(); ++i)
  {
    if(islower(s[i])) s[i]=to_upper(s[i]);
    else if(isupper(s[i])) s[i]=to_lower(s[i]);
  }
  cout<<s<<endl;
}


Measured memory_bytes: 3252
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <queue>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fst first
#define snd second
const ll mod = 1000000007;
const ll INF = (1LL << 59);
const int iINF = (1 << 31)-1;
const double dINF = 1000000000000000000.0;
const int MAX_N = 1 << 17;

int main(){
	int sx, sy, tx, ty; cin >> sx >> sy >> tx >> ty;
	int x, y;
	x = tx - sx; y = ty - sy;
	for (int i = 0; i < y; i++) {
		cout << 'U';
	}
	for (int i = 0; i < x; i++) {
		cout << 'R';
	}
	for (int i = 0; i < y; i++) {
		cout << 'D';
	}
	for (int i = 0; i < x; i++) {
		cout << 'L';
	}
	cout << 'L';
	for (int i = 0; i < y+1; i++) {
		cout << 'U';
	}
	for (int i = 0; i < x+1; i++) {
		cout << 'R';
	}
	cout << 'D';
	cout << 'R';
	for (int i = 0; i < y+1; i++) {
		cout << 'D';
	}
	for (int i = 0; i < x+1; i++) {
		cout << 'L';
	}
	cout << 'U';

	return 0;
}

Measured memory_bytes: 256
# include <stdio.h>
int main()
{
int A,B,C;
  A <= 100 ;
  B <= 100 ;
  C <= 100 ;
 A >= -100 ;
B >= -100 ;
C >= -100 ;



scanf(" %d %d %d ",&A,&B,&C);
if(C>=A && C<=B){printf("Yes");}
else {printf("No");}
return 0;}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  vector<long> h(n);
  for(int i=0;i<n;i++) cin>>h[i];
  sort(h.begin(),h.end());
  if(n>k){
    for(int i=0;i<k;i++) h.pop_back();
    long count=0;
    for(int j=0;j<h.size();j++) count+=h[j];
    cout<<count<<endl;
  }else{
    cout<<0<<endl;
  }
}

Measured memory_bytes: 1792
#include <cstring>
#include <cstdio>
#include <algorithm>
#define ll long long
const int MAXN = 2010;
const int MAXLOG = 11;
const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;
using namespace std;

int N, X, minv[MAXLOG][MAXN], log2[MAXN];
inline int rmq(int l, int r) {
	int len = log2[r - l + 1];
	return min(minv[len][l], minv[len][r - (1 << len) + 1]);
}
inline int radq(int x, int d) {
	int ret, l = x - d;
	ret = rmq(max(1, l), x);
	if(l < 1) ret = min(ret, rmq(N - (1 - l) + 1, N));
	
	return ret;
}

int main() {
	int i;
	scanf("%d%d", &N, &X);
	for(i = 1; i <= N; i++) scanf("%d", &minv[0][i]);

	//rmq
	log2[1] = 0; for(i = 2; i <= N; i++) log2[i] = log2[i >> 1] + 1;
	for(int k = 1; (1 << k) <= N; k++) for(i = 1; i + (1 << k) - 1 <= N; i++)
		minv[k][i] = min(minv[k - 1][i], minv[k - 1][i + (1 << (k - 1))]);

	//getans
	ll Ans = INFLL;
	for(int r = 0; r <= N; r++) {
		ll CurAns = (ll)X * r;
		for(i = 1; i <= N; i++) CurAns += radq(i, r);

		Ans = min(Ans, CurAns);
	}
	printf("%lld", Ans);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<set>
using namespace std;
int main() {
	int n; cin >> n;
	set<int> s;
	for (int i = 0; i < n; i++) {
		int k; cin >> k;
		s.insert(k);
	}cout << s.size() << endl;
	return 0;
}

Measured memory_bytes: 256