akhauriyash/Code-Regression huggingface dataset:
// C - Maximal Value
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define rp(i,n) for(int i=0;i<(n);i++)

int main(){
	int N; cin>>N;
	vi B(N-1); rp(i,N-1) cin>>B[i];
	ll ans = B[0] + (N-2>=0? B[N-2]: 0);
	rp(i,N-2){
		int mini = min(B[i], B[i+1]);
		ans += mini;
	}
	cout<< ans <<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int x,y,z;
    scanf("%d%d%d",&x,&y,&z);
    if (y < x){
        if(z < y){
            printf("%d %d %d\n",z,y,x);
        }else if(z < x){
            printf("%d %d %d\n",y,z,x);
        }else{
            printf("%d %d %d\n",y,x,z);
        } }
    else if (z < x){
            printf("%d %d %d\n",z,x,y);}
    else if(z < y) {
        printf("%d %d %d\n",x,z,y);

    }
    else {
        printf("%d %d %d\n",x,y,z);
    }
    return 0;
        } 


Measured memory_bytes: 2708
#include<bits/stdc++.h>
#define mod 1e9+7
typedef long long ll;

int main()
{
	ll x;
	std::cin>>x;
	ll sum=100,yrs=0;
	while(sum<x)
	{
		sum+=(sum/100);
		yrs++;
	}

	std::cout<<yrs;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define pie 3.141592653589793238462643383279
#define int long long
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int kai(int x, int y, int m) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y, int m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

int n;
char ans[1010][1010];
string fo = "aacabbcaacbbacaa", fi = "aabbabcc.ab..dba..dbabbaa", se = "aa.aa.c..b..bc..b..bdaa.aa.d..b..bc..b..bcccddcc.";
int a, b, c;

signed main() {
	cin >> n;
	if (n == 2) {
		cout << -1 << endl;
		return 0;
	}
	if (n == 3) {
		cout << "aa." << endl << "..b" << endl << "..b" << endl;
		return 0;
	}
	if (n == 6) {
		cout << "aa...." << endl << "..b..." << endl << "..b..." << endl << "...aa." << endl << ".....b" << endl << ".....b" << endl;
		return 0;
	}
	for (int i = 1; i <= n; i++)for (int j = 1; j <= n; j++)ans[i][j] = '.';
	if (n % 4 == 0)a = n / 4;
	if (n % 4 == 1)a = n / 4 - 1, b = 1;
	if (n % 4 == 2)a = n / 4 - 2, b = 2;
	if (n % 4 == 3)a = n / 4 - 1, c = 1;
	int cnt = 1;
	for (int k = 0; k < a; k++) {
		for (int i = 0; i < 4; i++)for (int j = 0; j < 4; j++)ans[cnt + i][cnt + j] = fo[i * 4 + j];
		cnt += 4;
	}
	for (int k = 0; k < b; k++) {
		for (int i = 0; i < 5; i++)for (int j = 0; j < 5; j++)ans[cnt + i][cnt + j] = fi[i * 5 + j];
		cnt += 5;
	}
	for (int k = 0; k < c; k++) {
		for (int i = 0; i < 7; i++)for (int j = 0; j < 7; j++)ans[cnt + i][cnt + j] = se[i * 7 + j];
		cnt += 7;
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++)cout << ans[i][j];
		cout << endl;
	}
}

Measured memory_bytes: 2176
import java.util.Scanner;
import java.util.Stack;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();

    int removals = 0;

    Stack<Character> stack = new Stack<>();
    for (char c : s.toCharArray()) {
      if (stack.empty() || stack.peek() == c)
        stack.push(c);
      else {
        stack.pop();
        removals += 2;
      }
    }

    System.out.println(removals);
  }
}

Measured memory_bytes: 25636
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <cassert>
#include <fstream>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

const ll mod = 1e9 + 7;

vector<string> g;

int main() {

    
    ll n;
    cin >> n;
    vector<ll> s(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> s[i];
    }
    
    ll q;
    cin >> q;
    vector<ll> t(q);
    for (int i = 0; i < q; ++i)
    {
        cin >> t[i];
    }
    
    ll ret = 0;
    for (int i = 0; i < q; ++i)
    {
        auto itr = lower_bound(s.begin(), s.end(), t[i]);
        if (itr != s.end() && *itr == t[i])
        {
            ret++;
        }
    }
    
    cout << ret << endl;
    
    return 0;
}


Measured memory_bytes: 3784
isstr=input()
n,m = [int(i) for i in isstr.split(' ')]
l=[0]*m
r=[0]*m
for i in range(m):
    l[i],r[i]=[int(i)-1 for i in input().split(' ')]
x=min(r)-max(l)+1
x=x if x>0 else 0
print(x)   

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

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

int N, D;
vector<int> C;
vector<vector<int>> S;

int ans_score;
vector<int> ans;

void Read(bool local = false) {
  N = 26;
  if (local) {
    D = 365;
  } else {
    cin >> D;
  }
  C.resize(N);
  for (int i = 0; i < N; i++) {
    if (local) {
      C[i] = rnd() % 100;
    } else {
      cin >> C[i];
    }
  }
  S.resize(D);
  for (int i = 0; i < D; i++) {
    S[i].resize(N);
    for (int j = 0; j < N; j++) {
      if (local) {
        S[i][j] = rnd() % 20000;
      } else {
        cin >> S[i][j];
      }
    }
  }
  ans.assign(D, 0);
}

void Write() {
  for (auto i : ans) {
    cout << i + 1 << "\n";
  }
}

int Arithmetic(int n) {
  return n * (n - 1) / 2;
}

vector<set<int>> Build(vector<int> a) {
  vector<set<int>> occ(N);
  for (int i = 0; i < D; i++) {
    occ[a[i]].insert(i);
  }
  for (int i = 0; i < N; i++) {
    occ[i].insert(-1);
    occ[i].insert(D);
  }
  return occ;
}

int Evaluate(vector<int> a) {
  vector<int> last(N, -1);
  int score = 0;
  for (int i = 0; i < D; i++) {
    score += S[i][a[i]];
    last[a[i]] = i;
    for (int j = 0; j < 26; j++) {
      score -= C[j] * (i - last[j]);
    }
  }
  return score;
}

int Evaluate(int init_score, const vector<int> &a, const vector<set<int>> &occ, int d, int q) {
  if (a[d] == q) return init_score;
  const set<int> &cur = occ[a[d]];
  auto pos = cur.lower_bound(d);
  int lst = *prev(pos);
  int nxt = *next(pos);

  int score = init_score;
  score += C[a[d]] * (Arithmetic(nxt - d) + Arithmetic(d - lst) - Arithmetic(nxt - lst));

  pos = occ[q].upper_bound(d);
  lst = *prev(pos);
  nxt = *pos;
  score -= C[q] * (Arithmetic(nxt - d) + Arithmetic(d - lst) - Arithmetic(nxt - lst));

  score -= S[d][a[d]];
  score += S[d][q];

  return score;
}

void Change(int &init_score, vector<int> &a, vector<set<int>> &occ, int d, int q) {
  int new_score = Evaluate(init_score, a, occ, d, q);
  init_score = new_score;
  occ[a[d]].erase(d);
  a[d] = q;
  occ[a[d]].insert(d);
}

void Solve(int t) {
  ans_score = Evaluate(ans);

  vector<int> a(D);
  for (int i = 0; i < D; i++) {
    a[i] = (i + t) % N;
  }
  int score = Evaluate(a);
  vector<set<int>> occ = Build(a);

  double temp = 20000;
  double cooling_rate = 0.9997;
  double absolute_zero = 0.0001;

  while (temp > absolute_zero) {
    int d = rnd() % D;
    int q = rnd() % N;
    int delta = Evaluate(score, a, occ, d, q) - score;
    if (temp <= 0.01) {
      for (int i = 0; i < N; i++) {
        int new_delt = Evaluate(score, a, occ, d, i) - score;
        if (delta < new_delt) {
          delta = new_delt;
          q = i;
        }
      }
    }
    if (delta > 0 || exp(delta / temp)) {
      Change(score, a, occ, d, q);
      if (t > 0 && score > ans_score) {
        ans = a;
        ans_score = score;
      }
    }
    temp *= cooling_rate;
  }
  if (ans_score < score) {
    ans = a;
  }
}

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

  Read();
  for (int rep = 0; rep < 26; rep++) {
    Solve(rep);
  }
  Write();
  // cerr << Evaluate(ans) << "\n";
  return 0;
}


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

int main()
{
    int k,a,b;
    cin>>k>>a>>b;
    for(int i=a/k-1;i<=b/k+1;i++)
    {
        if(k*i>=a&&k*i<=b)
        {
            cout<<"OK"<<endl;
            return 0;
        }
    }
    cout<<"NG"<<endl;
    return 0;
}


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

int main(){
    using namespace std;
    long N, K; cin >> N >> K;
    string s; cin >> s;
    vector<long> cusum, zero_num;
    cusum.push_back(0);
    zero_num.push_back(0);
    long cnt = 0, zero_cnt = 0;
    for (long i = 0; i < N; i++)
    {
        if(s[i]=='0') zero_cnt++;
        if(s[i]=='0' && s[i+1]=='1'){
            cusum.push_back(i+1); 
            zero_num.push_back(zero_cnt);
            zero_cnt = 0;
        }
    }
    cusum.push_back(N); 
    zero_num.push_back(zero_cnt);
    cusum.push_back(N); 
    zero_num.push_back(0);
    //for(int i : cusum) cout << i << " ";
    //cout << endl;
    long r = 0;
    long ans = 0;
    for (long i = 0, cusize = cusum.size(); i < cusize; i++)
    {
        while(r<cusize-1 && r-i <= K){ 
            r++;
            ans = max(ans, cusum[r] - cusum[i] - zero_num[r]);
        }
        ans = max(ans, cusum[r] - cusum[i] - zero_num[r]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1404
import java.util.*;
public class Main
{
    public static void main(String[] args)
    {
        //Compute c1 = new Compute();//calc
        int count = 0;
        boolean sw = false;
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        double dMax = Double.MIN_VALUE;
        double dMin = Double.MAX_VALUE;
        //StringBuilder answer=new StringBuilder();
        //input
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        String ans[] = {"ABC","ARC"};
        //long n = sc.nextLong();

        if(n<1200)
        {
            System.out.println(ans[0]);
        }else
        {
            System.out.println(ans[1]);
        }

        sc.close();
    }
}

Measured memory_bytes: 23380
#!/usr/bin/env python3
import sys


def solve(X: int, N: int, p: "List[int]"):
    forbidden = set(p)
    for i in range(1000):
        if X - i not in forbidden:
            print(X-i)
            exit()
        if X + i not in forbidden:
            print(X+i)
            exit()
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(X, N, p)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9208
// 深さ優先探索（Bredth First Search）の問題
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) ((v).begin(),(v).end())

using namespace std;
// using Graph = vector< vector<int> >;
vector<int> to[100005];
const int INF = 1001001001;

int main(){
    int n,m;
    cin >> n >> m;
    
    // グラフ入力受付
    // Graph to(n);
    REP(i,m){
        int a,b;
        cin >> a >> b;
        --a;
        --b;
        to[a].push_back(b);
        to[b].push_back(a);
    }

    // 幅優先探索
    queue<int> q;       // 発見済みだが未訪問なノードを格納
    vector<int> dist(n, INF);   // スタートノードからノードVまでなんSTEPで到達できるか
    vector<int> pre(n, -1);     // 経路復元用

    // 初期条件
    q.push(0);
    dist[0] = 0;

    while(!q.empty()){
        int v = q.front();
        q.pop();

        // ノードuから辿れる頂点をすべて調査
        for(int u: to[v]){
            // ノードuが探索済みの場合はスルー
            if(dist[u]!=INF)
                continue;
            
            // ノードuについて距離更新＆キューに追加
            dist[u] = dist[v] + 1;
            pre[u] = v;     // 直前の部屋番号を記録
            q.push(u);
        }
    }

    cout << "Yes" << endl;
    REP(i,n){
        if(i==0) 
            continue;
        
        int ans = pre[i];
        ++ans;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 10692
#=
B:
- Julia version:0.5.2
- Author: abap
- Date: 2020-01-12
=#
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
N = parseInt(readline())
P = parseMap(split(readline()))
#P = []
#=for i in 1:N
	push!(P,(i,p[i]))
end
sort!(P,by=x->x[2])
count = 0
for (key,value) in P
		println(key," ",value)
		count += 1
end=#

#println(count)
not = 0
min = P[1]
for i in 1:N
	p = P[i]
	if p > min
		not += 1
	else
		min = p
	end
end
println(N - not)

Measured memory_bytes: 166972
#include <stdio.h>
#define INFINITY 2000000000
#define N 101
int min(int a,int b)
{
  if(a>b)return b;
  else return a;
}
int main()
{
  int n,p[N],m[N][N],h,i,j,k;
  scanf("%d",&n);

  for(i=1;i<=n;i++)
  {
    scanf("%d%d",&p[i-1],&p[i]);
  }
  for(i=1;i<=n;i++)m[i][i]=0;
  for(h=2;h<=n;h++)
  {
    for(i=1;i<=n-h+1;i++)
    {
      j=i+h-1;
      m[i][j]=INFINITY;
      for(k=i;k<j;k++)
      {
        m[i][j]=min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
      }
    }
  }
  printf("%d\n",m[1][n]);
  return 0;
}



Measured memory_bytes: 2052
def linearSearch(n, S, q, T):
    count = 0
    if n <= q:
        for i in S:
            if i in T:
                count += 1
        print(count)
                
    else:
        for k in T:
            if k in S:
                count += 1
        print(count)
                
    

n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))

linearSearch(n, S, q, T)

Measured memory_bytes: 8656
import java.io.*;
import java.util.Scanner;
class Main {
	public static void main(String[] args)throws IOException {
		 Scanner scn = new Scanner(System.in);
		    int a = scn.nextInt();
		    int b = scn.nextInt();
		
		  System.out.print(a*b +" ");
		  System.out.println(2*(a+b));
		
	}

}

Measured memory_bytes: 26208
#include <bits/stdc++.h>
using namespace std;
vector<long long> c[100000];
long long ans;

int main(){
	ios::sync_with_stdio(0);
	int n , m;
	cin >> n >> m;
	for (int i = 0; i < n; i++){
		long long a , b;
		cin >> a >> b;
		if (a > m){
			continue;
		}
		c[a - 1].push_back(b);
	}	
	priority_queue<long long> q;
	for (int i = 0; i < m; ++i){
		for (long long b : c[i]){
			q.push(b);
		}
		if (!q.empty()){
			ans += q.top();
			q.pop();
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 5632
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#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--)
#define mp make_pair
#define fi first
#define sc second
ll n;

ll cou (ll n) {
	ll ret = 0;
	while(n > 0){ ret++; n /= 10;}
	return ret;
}

int main(){
	cin >> n;

	ll a = 1;
	for(int i = 2;i <= sqrt(n);i++) {
		if(n % i == 0)
			a = i;
	}
	ll b = n / a;

	cout << max(cou(a),cou(b)) << endl;
	return 0;
}


Measured memory_bytes: 256
# Problem: https://atcoder.jp/contests/abc061/tasks/abc061_b
# Python 3rd Try

import sys
# from collections import defaultdict
# import heapq,copy
# from collections import deque
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solver(cityCount, roadCount, fromCity, toCity):
    result = [0]*(cityCount+1)
    roadRange = range(0, roadCount, +1)
    for j in roadRange:
        city = fromCity[j]
        result[city] = result[city] + 1
        city = toCity[j]
        result[city] = result[city] + 1
    # algorithm
    # print("RESULT {}".format(result[1:cityCount+1]))
    return result[1:cityCount+1]


if __name__ == "__main__":
    N, M = MI()
    fromCity = []
    toCity = []
    roadRange = range(0, M, +1)
    for _ in roadRange:
        tmp_i, tmp_j = MI()
        fromCity.append(tmp_i)
        toCity.append(tmp_j)
    solveList = solver(N, M, fromCity, toCity)
    # print("{}".format(solver()))
    for j in range(0, N, +1):
        print(solveList[j])


Measured memory_bytes: 9176
#include <stdio.h>

int A, B;

int main( int argc, char *argv[] )
{
    int i;
    int r = -1;

    scanf( "%d%d", &A, &B );

    for( i=0; i<15000; i++ ) {
        if( ((int)(i * 0.08))  == A && ((int)(i * 0.1)) == B ) {
            r = i;
            break;
        }
    }

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


Measured memory_bytes: 128
#include <iostream>

using namespace std;

int
main()
{
        int n, i, j, total, max;

        cin >> n;
        int up[n], down[n];
        max = 0;
        for (i = 0; i < n; i++) {
                cin >> up[i];
        }
        for (i = 0; i < n; i++) {
                cin >> down[i];
        }

        for (i = 0; i < n; i++) {
                total = 0;
                for (int ii = 0; ii <= i; ii++) {
                        total += up[ii];
                }
                for (int jj = i; jj < n; jj++) {
                        total += down[jj];
                }
                if (total > max) {
                        max = total;
                }
        }

        cout << max << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <string>
#include <limits.h>
#include <iomanip>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <set>
#include <bitset>
#include <unordered_map>
#include <string.h>
#define fastIo                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL)
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define MOD 1000000007

using namespace std;
bool ch[1000001];
bool pairwise(int arr[], int n)
{
    int d;
    for (int j = 0; j < n; j++)
    {
        d = arr[j];
        if(d%2==0)
        {
            if(ch[2])
                return false;
            while(d%2==0)
                d/=2;
            
            ch[2] = true;
        }
        for (int i = 3; i * i <= (arr[j]); i+=2)
        {
            if (d % i == 0)
            {
                while (d % i == 0)
                {
                    d /= i;
                }

                if (ch[i] == true)
                {
                    return false;
                }

                else
                {
                    ch[i] = true;
                }
            }
        }

        if (d != 1)
        {
            if (ch[d]==true)
            {
                return false;
            }

            ch[d] = true;
        }
    }

    return true;
}
bool setWise(int arr[], int n)
{
    int g = arr[0];
    for (int i = 1; i < n; i++)
        g = __gcd(g, arr[i]);
    if(g==1)
        return true;
    return false;
}

int main()
{
    fastIo;

    int n;
    cin >> n;

    int arr[n];
    for (int i = 0; i < n; i++)
        cin >> arr[i];
    if (pairwise(arr, n))
        cout << "pairwise coprime";
    else if (setWise(arr, n))
        cout << "setwise coprime";
    else
    {
        cout << "not coprime";
    }

    return 0;
}


Measured memory_bytes: 7548
s = input()
q = int(input())

for i in range(q):
    input_value = list(input().split())
    if len(input_value) == 4:
        c, a, b, p = ' '.join(input_value).split()
    else:
        c, a, b = ' '.join(input_value).split()

    a = int(a)
    b = int(b)
    
    if c == 'replace':
        s = s[:a] + p + s[b+1:]
    
    elif c == 'reverse':
        s = s[:a] + ''.join(list(reversed(s[a:b+1]))) + s[b+1:]

    
    elif c == 'print':
        print(s[a:b+1])    


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

int main(){
    int n, res = 0;
    scanf("%d", &n);
    int a[n];
    for(int i = 0; i < n; i++)
        scanf("%d", &a[i]);
    for(int i = 0; i < n - 1; i++){
        if(a[i] > a[i + 1] && a[i + 1] > a[i + 2] && i + 2 < n){
            res++;
        }
        if(a[i] < a[i + 1] && a[i + 1] < a[i + 2] && i + 2 < n){
            res++;
        }
    }
    printf("%d", res);
    return 0;
}


Measured memory_bytes: 3808
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <tuple>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <random>
#include <cstdlib>
//#include "toollib.h"
//#include "puzzle.h"
#define INT_MAX 2147483647
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#pragma warning (disable:4018)
#pragma warning (disable:4244)
#pragma warning (disable:4996)

using namespace std;
typedef long long int lint;


//***** Main Program *****

int main() {
	map<string, bool> mp;
	int n;
	cin >> n;
	Loop(i, n) {
		char query[10], cword[20];
		string word;
		scanf("%s %s", query, cword);
		word = cword;
		if(query[0]=='i'){
			mp[word] = true;
		}
		else {
			if (mp[word]) printf("yes\n");
			else printf("no\n");
		}
	}
	return 0;
}

Measured memory_bytes: 47556
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define fir first
#define sec second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const int INF=1e9;
vector<int>c[10];
int N,K;
int dp[3000];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>N>>K;
	REP(i,N){
		int a,b;
		cin>>a>>b;b--;
		c[b].PB(a);
	}
	REP(i,10)sort(ALL(c[i]),greater<int>());
	REP(i,10){
		int sum=0;
		REP(j,c[i].size()){
			sum+=c[i][j];
			c[i][j]=sum+j*(j+1);
		}
	}
	memset(dp,-1,sizeof(dp));
	dp[0]=0;
	REP(i,10){
		for(int j=2000;j>=0;j--){
			if(dp[j]!=-1){
				REP(k,c[i].size()){
					dp[j+k+1]=max(dp[j+k+1],dp[j]+c[i][k]);
				}
			}
		}
	}
	cout<<dp[K]<<endl;
}

Measured memory_bytes: 1256
n = int(input())
places = list(map(int, input().split()))
def cost(point):
    res = 0
    for i in places:
        res += ((i-point) * (i-point))
    return res
ans = float('inf')
for i in range(1, 101):
    ans = min(ans, cost(i))
print(ans)

Measured memory_bytes: 3060
a, b, c = map(int,input().split())

if a <= b <= c:
    print(a, b, c)
elif a <= c <= b:
    print(a, c, b)
elif b <= a <= c:
    print(b, a, c)
elif b <= c <= a:
    print(b, c, a)
elif c <= a <= b:
    print(c, a, b)
elif c <= b <= a:
    print(c, b, a)


Measured memory_bytes: 5596
/*
20:29 - 20:48
 */

#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cassert>
#include<climits>
#include<sstream>
#include<cstdlib>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define IINF (INT_MAX)

using namespace std;

typedef long long ll;

long long extgcd(long long a,long long b,long long& x,long long& y)
{
  long long d = a;
  if(b != 0){
    d = extgcd(b,a%b,y,x);
    y -= (a/b)*x;
  }
  else
    x = 1,y = 0;
  return d;
}

long long mod_inv(long long a,long long m)
{
  long long x,y;
  extgcd(a,m,x,y);
  return (m+x%m)%m;
}

ll expression();
string text;
int pos;
ll MOD;
bool out;

ll fact(){
  if(out)return 0;
  ll res = 0;
  if(text[pos] == '('){
    ++pos;
    res = expression();
    ++pos;
  } else {
    while( '0' <= text[pos] && text[pos] <= '9' ){
      res *= 10LL;
      res += (text[pos] - '0');
      pos++;
    }
  }
  return res%MOD;
}

ll term(){
  if(out)return 0;
  ll b = fact();
  while(text[pos] == '*' || text[pos] == '/'){
    if(text[pos] == '*'){
      ++pos;
      b = ( (b%MOD) * (fact()%MOD) ) % MOD;
    } else {
      ++pos;
      ll tmp = fact();
      if(tmp == 0){
	out = true;
	return b;
      }
      b = ( (b%MOD) * (mod_inv(tmp,MOD))%MOD ) % MOD;
    }
  }
  return b;
}

ll expression(){
  if(out)return 0;
  ll a = term();
  while(text[pos] == '+' || text[pos] == '-'){
    if(text[pos] == '+'){
      ++pos;
      a = ( a + term() ) % MOD;
    } else {
      ++pos;
      a = ( a - term() + MOD) % MOD;
    }
  }
  return a;
}

int main(){
  string tmp;
  while(getline(cin,tmp)){
    if(tmp[0] == '0')break;
    rep(i,tmp.size())if(tmp[i] == ':'){
      tmp[i] = ' ';
      break;
   } 
    pos = 0;
    text.clear();
    stringstream ss;
    ss << tmp;
    ss >> tmp;
    MOD = (atol)(tmp.c_str());
    while(!(ss >> tmp).fail()){
      text += tmp;
    }

    out = false;
    ll ans = expression();
    if(out) cout << "NG" << endl;
    else    cout << text << " = " << ans << " (mod " << MOD << ")" << endl;


  }

  return 0;
}

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

int main(){
    int k, x;
    cin >> k >> x;
    for(int i = x - k + 1; i <= x + k - 1; i++){
        cout << i << " ";
    }
    cout << endl;
   return 0;
}

Measured memory_bytes: 3584
n = gets.to_i
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)

count = 0
n.times do |i|
  if a[i] >= b[i]
    count += b[i]
    next
  end

  count += a[i]
  b[i] -= a[i]
  if a[i+1] <= b[i]
    count += a[i+1]
    a[i+1] = 0
    next
  end

  count += b[i]
  a[i+1] -= b[i]

end

puts count

Measured memory_bytes: 15500
# Contest No.: ABC170
# Problem No.: B
# Solver:      JEMINI
# Date:        20200614

import sys
import heapq

def main():
    a, b = map(int, input().split())
    n, m = 0, 0
    
    n = (4 * a - b)
    m = (b - 2 * a)

    if n < 0 or m < 0 or n % 2 or m % 2:
        print("No")
    else:
        print("Yes")
    
    return

if __name__ == "__main__":
    main()

Measured memory_bytes: 62340
using System;
using System.Collections.Generic;
using System.Linq;

class Procon
{
    public Procon() { }
    static void Main(string[] agrs)
    {
        new Procon().Do();
    }

    Scanner cin;

    public void Do()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int X = cin.nextInt();
        int d = 0;
        for (int i = 1; i <= N; i++)
        {
            d += cin.nextInt();
            if (d > X)
            {
                Console.WriteLine(i);
                return;
            }
        }
        Console.WriteLine(N + 1);
    }
}

class Scanner
{
    string[] s;
    int i;
    int max_i;

    public Scanner()
    {
        s = new string[0];
        max_i = 0;
        i = 0;
    }

    public string nextString()
    {
        if (i >= s.Length)
        {
            s = Console.ReadLine().Split(' ');
            max_i = s.Length;
            i = 0;
            if (max_i == 0)
            {
                return "";
            }
            return s[i++];
        }
        else
        {
            return s[i++];
        }
    }

    public int nextInt()
    {
        return int.Parse(nextString());
    }


    public long nextLong()
    {
        return long.Parse(nextString());
    }

    public double nextDouble()
    {
        return double.Parse(nextString());
    }

    public string[] arrayString()
    {
        return Console.ReadLine().Split(' ');
    }

    public int[] arrayInt()
    {
        string[] str = Console.ReadLine().Split(' ');
        int[] array = new int[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = int.Parse(str[i]);
        }
        return array;
    }

    public long[] arrayLong()
    {
        string[] str = Console.ReadLine().Split(' ');
        long[] array = new long[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = long.Parse(str[i]);
        }
        return array;
    }

    public double[] arrayDouble()
    {
        string[] str = Console.ReadLine().Split(' ');
        double[] array = new double[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = double.Parse(str[i]);
        }
        return array;
    }
}



Measured memory_bytes: 13140
/** "Ever tried.
         Ever failed.
               No matter.
                   Try Again.
                        Fail again.
                             Fail better.**/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define bp  __builtin_popcount
#define endl "\n"
#define oo 0x3f3f3f3f3f3f3f3fLL
#define pb push_back
#define loop(i,n) for(int i = 0;i < int(n);i++)
#define sz(s) (int)(s.size())
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define setdp memset(dp,-1,sizeof(dp))
#define db(x) cout<<" LOOK "<<(#x)<<" = "<<x <<'\n'
#define NumofDigits(n)   ((long long)log10(n)+1)

using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const int maxn=1e5+5;
const  double EPS = 1e-9;
const int MOD = 1e9+7;
/*
ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
ll fastpow(ll b, ll p)
{if(!p)return 1;ll ret = fastpow(b, p >> 1);ret *= ret;if(p&1)ret*= b;return ret;}
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};*/
inline void File()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
}

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    //File();
    int n;
    cin>>n;
    int arr[105];
    for(int i=0; i<n; i++)
        cin>>arr[i];
    int cnt=0;
    for(int i=0; i<n; i++)
    {
        bool ok=true;
        for(int j=0; j<i; j++)
            if(arr[i] < arr[j])
            {
                ok=false;
                break;
            }
        if(ok)
            cnt++;
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 3596
H, W = map(int,input().split())
S = [input() for _ in range(H)]

for i in range(H):
  rs = ''
  for j in range(W):
    if(S[i][j] == '#'):
      rs += '#'
    else:
      tmp = 0
      for s in S[max(0, i-1): min(H, i+2)]:
        tmp += s[max(0, j-1): min(W, j+2)].count('#')
      rs += str(tmp)
  print(rs)

Measured memory_bytes: 3064
#include "bits/stdc++.h"

#define REP(i, a) for (int i = 0; i < (b); ++i)
#define FORV(a, A) for (auto &a : A)

using namespace std;

using ll = long long;

void Main() {
  int N;
  cin >> N;
  cout << (double)((N + 1) / 2) / N;
}

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


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>
#include <memory>

using namespace std;

struct before_main {before_main() {cin.tie(0); ios::sync_with_stdio(false);}} before_main;

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

typedef long long ll;

typedef shared_ptr<struct tree> tree_ptr;

struct tree {
  string s;
  vector<tree_ptr> children;
  ll num = 1;
  tree() = default;
  tree(string s, ll num): s(s), num(num) {}
};

ll read_k(string& s) {
  stringstream ss(s);
  int x; string t; ss >> x >> t;
  s = t;
  return x;
}

string read_s(string& s) {
  int n = s.size();
  string t;
  int last = -1;
  bool br = 0;
  rep(i, n) {
    last = i;
    if (!isalpha(s[i])) { br = 1; break; }
    t.push_back(s[i]);
  }
  if (br) s = s.substr(last);
  else s = "";
  return t;
}

void consume(string& s, char expected) {
  if (s[0] != expected) {
    cout << "Expected: " << expected << endl;
    cout << "Remain: " << s << endl;
    assert(0);
  }
  s = s.substr(1);
}

void dfs(string& s, tree_ptr curr) {
  for (; !s.empty();) {
    if (isdigit(s[0])) {
      ll ck = read_k(s);
      if (isalpha(s[0])) {
        auto c = make_shared<tree>();
        c->num = ck;
        c->s = read_s(s);
        curr->children.push_back(c);
      }
      else {
        consume(s, '(');
        auto c = make_shared<tree>();
        curr->children.push_back(c);
        c->num = ck;
        dfs(s, c);
        consume(s, ')');
      }
    }
    else {
      auto c = make_shared<tree>();
      c->s = read_s(s);
      c->num = 1;
      curr->children.push_back(c);
      if(!s.empty() && !isdigit(s[0])) { return; }
    }
  }
}

string ans;

void visit(tree_ptr curr) {
  if(ans.size() >= 1000001) { return; }
  rep(i, curr->num) {
    if (curr->children.empty()) {
      ans += curr->s;
      if(ans.size() >= 1000001) { return; }
    }

    rep(i, curr->children.size()) {
      visit(curr->children[i]);
    }
  }
}

char solve(string& s, int idx) {
  auto root = make_shared<tree>();
  dfs(s, root);
  ans.clear();
  visit(root);
  if(ans.size() <= idx) { return '0'; }
//  cout << ans << endl;cout << ans.size() << " / " << idx << endl;
  return ans[idx];
}

int main() {

  while (1) {
    string s; cin >> s;
    int idx; cin >> idx;
    if (s == "0" && idx == 0) { break; }
    cout << solve(s, idx) << endl;
  }

  return 0;
}

Measured memory_bytes: 3960
#include <bits/stdc++.h>
#define int long long
#define double long double
const int INF = (int)1e18 + 18;
const int maxn = (int) 1e6 + 6; 
using namespace std;
 
int l, r, minn = 2020;
 
signed main() {

	cin >> l >> r;

	if(l/2019 != r/2019){
		cout << "0" << endl;
	}

	else{
		for(int i = l; i < r + 1; i++){
			for(int j = i + 1; j < r + 1; j++){
				minn = min(minn, (i*j) % 2019);
			}
		}

		cout << minn << endl;
	}


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define MAX 128
#define fst first
#define sec second
#define pb push_back
#define mp make_pair
#define ALL(x) (x).begin(), (x).end()
#define bit(n) (1LL << (n))
#define int long long
const double PI = 3.141593;
const int MOD = (int)1e9 + 7;
const int INF = 100100100;
const double EPS = 1e-9;
template <class T>
bool chmax(T &a, const T &b){if (a < b){a = b;return 1;}return 0;}
template <class T>bool chmin(T &a, const T &b){if (b < a){a = b;return 1;}return 0;}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }     //最小公倍数
ll combination(ll n, ll r){if (r * 2 > n)r = n - r;ll dividend = 1;ll divisor = 1;for (ll i = 1; i <= r; ++i){dividend *= (n - i + 1);divisor *= i;}return dividend / divisor;}


signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;
    int a[n]={0};
    int tmp;
    rep(i, n-1)
    {
        cin >> tmp;
        a[tmp - 1]++;
    }
    rep(i, n){
        cout << a[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 5188
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define pb push_back
#define fi first`
#define se second
const int N = 1e5 + 500;
void solve()
{
 ll a, b;
    cin >> a >> b;
    ll l=0,r=1e12,mid,ans=-1;
    while(l<=r)
    {
    	mid=l+r>>1;
    	if(floor(mid*0.08)>=a and floor(mid*.1)>=b)
    	{
    		ans=mid;
    		r=mid-1;
    	}
    	else
    		l=mid+1;
    }
    if(ans!=-1)
    {
    	if(floor(ans*0.08)!=a or floor(ans*.1)!=b)
    		ans=-1;

    }
    
    cout<<ans;
}

int main()
{
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    int t = 1;
    // cin >> t;
    while(t--)
    {
        solve();
        // cout << endl;
    }

}




Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var a int
	var b int
	fmt.Scanf("%d %d", &a, &b)
	x := a + b
	y := a - b
	z := a * b

	if x > y {
		if x > z {
			fmt.Printf("%d", x)
		} else {
			fmt.Printf("%d", z)
		}
	} else {
		if z > y {
			fmt.Printf("%d", z)
		} else {
			fmt.Printf("%d", y)
		}
	}
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int Cnter(string a,string b){
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  int ret = 0;
  for(int i = 'a'; i <= 'z'; ++i){
    ret += binary_search(a.begin(),a.end(),i)&&binary_search(b.begin(),b.end(),i);
  }
  return ret;
}

int main(){
  int d,n; cin >> d >> n;
  if(n < 100)cout << n;
  else cout << 101;
  for(int i = 0; i < d; ++i)cout << "00";
  cout << endl;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RNG(i,from,to) for(int i=(from); i<(int)(to); i++)
#define gcd(i,j) __gcd((i), (j))
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vecll;
template<typename S, typename T> string to_string(pair<S, T> p) { return "("+to_string(p.first)+","+to_string(p.second)+")"; }
template<typename T> string to_string(T p[2]) { return "["+to_string(p[0])+","+to_string(p[1])+"]"; }
template<typename T> void println(T e){ cout << to_string(e) << endl; }
template<typename T> void println(const vector<T>& v){ cout << "[";for(const auto& e : v){ cout << to_string(e) << ","; }cout << "]";cout << endl; }
template<typename T> void println(const vector<vector<T>>& vv){ for(const auto& v : vv){ println(v); } }
template<typename Iter> void println(Iter first, Iter last){ for(auto it=first; it != last; it++){ cout << *it << " "; }; cout << endl; }
template<typename T> T mod_pow(T x, T n, const T &p) { T ret = 1; while(n > 0) { if(n & 1) (ret *= x) %= p; (x *= x) %= p; n >>= 1; } return ret; }
template<typename T> T mod_inv(T x, const T &p) { return mod_pow(x, p-2, p); }
const ll DVSR = 1e9+7;


int main(int argc, char const *argv[])
{
  string S;
  cin >> S;
  ll SZ = S.size(), D = 2019;
  vecll DP(D);
  REP(i, D) DP[i] = 0;
  DP[0] = 1;
  ll buf = 0, coef = 1;
  REP(i, SZ) {
    buf += (S[SZ-i-1]-'0')*coef;
    buf %= D;

    DP[buf] += 1;
    coef *= 10;
    coef %= D;
  }
  // println(DP);
  ll res = 0;
  REP(i, D) res += DP[i]*(DP[i]-1)/2;
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 3756
A = int(input())
B = int(input())
C = int(input())
X = int(input())
count = 0
for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if a*500+b*100+c*50==X:
                count += 1
print(count)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int A,B,C;
	cin >> A >> B >> C;
	if (B/A > C){
		cout << C << endl;
	}
	else{
		cout << B/A << endl;
	}
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;

namespace Atcoder
{
    class Program
    {
        static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        static void Main(string[] args)
        {
            try
            {
                SetOut(sw);
                Solve.Answer();
                Out.Flush();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var ab = IO.RSInt;
            if (ab[0] > 0)
            {
                WriteLine("Positive");
                return;
            }
            if (ab[0] <= 0 && ab[1] >= 0)
            {
                WriteLine("Zero");
                return;
            }
            int t = -(ab[0] - ab[1]) + 1;
            WriteLine(t % 2 == 0 ? "Positive" : "Negative");
        }
    }

    public class IO
    {
        #region Input
        public static int RInt => int.Parse(ReadLine());
        public static long RLong => long.Parse(ReadLine());
        public static double RDouble => double.Parse(ReadLine());

        public static string[] RSString => ReadLine().Split();
        public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray();
        public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray();
        #endregion

        #region Output
        public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
        public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");
        public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO");
        #endregion
    }

    public class Mod
    {
        #region
        private readonly static long M = 1000000007;

        public static long Add(long a, long b) => (a * b) % M;
        public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
        public static long Multi(long a, long b) => (a * b) % M;
        #endregion
    }
}

Measured memory_bytes: 13396
unittest
{
	assert( [ "1 1" ].parse.expand.solve == 1000000 );
	assert( [ "3 101" ].parse.expand.solve == 100000 );
	assert( [ "4 4" ].parse.expand.solve == 0 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto xy = input.front.split.to!( long[] );
	return tuple( xy[ 0 ], xy[ 1 ] );
}

auto solve( long x, long y )
{
	return max( 0, 400000 - 100000 * x ) + max( 0, 400000 - 100000 * y ) + ( 400000 * ( x == 1 && y == 1 ) );
}


Measured memory_bytes: 256
import java.io.*;
import java.util.ArrayList;

public class Main {

	static int person = 5;

	public static void main(String args[]) throws IOException {
		boolean flg = true;

		while (flg) {
			BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
			ArrayList<String> fivehands = new ArrayList<String>();

			for (int i = 0; i < person; i++) {

				fivehands.add(bf.readLine());
				if (fivehands.get(0).equals("0")) {
					person = -1;
					flg = false;
				}

				if (person == i + 1) {
					judge(fivehands);

					// ?????°????????????
					fivehands.removeAll(fivehands);
					i = -1;
				}

			}
		}
	}

	private static void judge(ArrayList<String> fivehands) {
		int sum = 1000;

		for (String a : fivehands) {
			if (a.equals("1")) {
				sum = sum + 100;
			} else if (a.equals("2")) {
				sum = sum + 10;
			} else if (a.equals("3")) {
				sum = sum + 1;
			}
		}

		String judgeSum = String.valueOf(sum);

		if (judgeSum.contains("0") && !judgeSum.contains(String.valueOf(person))) {
			if (judgeSum.charAt(1) == '0') {
				judgeDetail(fivehands, "2", "3");
			} else if (judgeSum.charAt(2) == '0') {
				judgeDetail(fivehands, "3", "1");
			} else if (judgeSum.charAt(3) == '0') {
				judgeDetail(fivehands, "1", "2");
			}
		} else {
			for (int i = 0; i < person; i++) {
				System.out.println("3");
			}
		}
	}

	private static void judgeDetail(ArrayList<String> fivehands, String win, String lose) {

		for (String a : fivehands) {
			if (a.equals(win)) {
				System.out.println("1");
			} else if (a.equals(lose)) {
				System.out.println("2");
			} else {
				System.out.println("-1");
			}
		}
	}
}

Measured memory_bytes: 24928
#include <stdio.h>
#define CHANGES_MAX 30
#define X_MAX 30

int main(void){
	int changes_num = 0;
	int y_num = 0;
	int line = 0;
	int argnum = 0;
	int changes[CHANGES_MAX][2];
	int state[X_MAX+1];
	
	int i,k;
	char c;
	for(i = 1; i <= X_MAX; i++){
		state[i] = i;
	}
	for(i = 0; i < CHANGES_MAX; i++){
		changes[i][0] = 0;
		changes[i][1] = 0;
	}
	
	while(1){
		c = getchar();
		if(c == EOF){
			break;
		}else if(c == '\n'){
			argnum = 0;
			line++;
		}else if(c == ','){
			argnum++;
		}else{
			if(line == 0){
				y_num = y_num * 10 + (c -'0');
			}else if(line == 1){
				changes_num = changes_num * 10 + (c -'0');
			}else if(line-2 < y_num){
				changes[line-2][argnum] = changes[line-2][argnum] * 10 + (c -'0');
			}
		}
	}
	
	for(i = 0; i < changes_num; i++){
		k = state[changes[i][0]];
		state[changes[i][0]] = state[changes[i][1]];
		state[changes[i][1]] = k;
	
	}
	for(i = 1; i <= y_num; i++){
		printf("%d\n",state[i]);
	}
	return 0;

}

Measured memory_bytes: 0
let ND: [Int] = readLine()!.split(separator: " ").map { Int($0)! }
var count: Int = 0
for _ in 1...ND[0] {
    let xy: [Int] = readLine()!.split(separator: " ").map { Int($0)! }
    let dist: Int = xy[0]*xy[0] + xy[1]*xy[1]
    if dist <= ND[1]*ND[1] { count += 1}
}
print(count)	// (๑•ૅㅁ•๑)

Measured memory_bytes: 8208
N, M, Q = map(int, input().split())
LR = [tuple(map(int, input().split())) for _ in range(M)]
PQ = [tuple(map(int, input().split())) for _ in range(Q)]

# 二次元累積和
# A[i1, j1] -> A[i2, j2] :=
# Acum[i2 + 1][j2 + 1] - Acum[i1][j2 + 1] - Acum[i2 + 1][j1] + Acum[i1][j1]
def two_dim_accumulate(a) -> list:
  h, w = len(a), len(a[0])
  acum = [[0 for _ in range(h + 1)] for _ in range(w + 1)]
  for i in range(h):
    for j in range(w):
      acum[i + 1][j + 1] = a[i][j]
  for i in range(1, h + 1):
    for j in range(1, w + 1):
      acum[i][j] += acum[i][j - 1]
  for j in range(1, w + 1):
    for i in range(1, h + 1):
      acum[i][j] += acum[i - 1][j]
  return acum

A = [[0 for _ in range(N)] for _ in range(N)]
for l, r in LR:
  A[l - 1][r - 1] += 1
Acum = two_dim_accumulate(A)
  
for p, q in PQ:
  print(Acum[q][q] - Acum[p - 1][q] - Acum[q][p - 1] + Acum[p - 1][p - 1])

Measured memory_bytes: 106992
import sys

n = int(input())
blocks = []
for line in sys.stdin.readlines():
    w, s, v = map(int, line.split())
    blocks.append((w + s, w, s, v))
blocks.sort()

dp = [-1] * 20001
dp[0] = 0
for _, w, s, v in blocks:
    for i in range(min(s, 20000 - w), -1, -1):
        dp[i + w] = max(dp[i + w], dp[i] + v)
print(max(dp))


Measured memory_bytes: 42204