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

int main(){
    init();
    ll N;cin>>N;
    vector<ll>A(N);
    for(int i=0;i<N;i++)cin>>A[i];
    sort(A.begin(),A.end());
    ll right=N;
    ll left=-1;
    while(right-left>1){
        ll mid=(right+left)/2;
        //midが全て食べれる?
        ll num=A[mid];
        bool isOK=true;
        for(int i=0;i<N;i++){
            if(i==mid)continue;
            if(num*2>=A[i]){
                //食べれる
                num+=A[i];
            }else isOK=false;
        }
        if(isOK)right=mid;
        else left=mid;
    }
    cout<<N-1-left<<endl;

}

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

typedef long long ll;

using namespace std;

#define swap(a, b)    do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while(0)
#define repd(i, a, b) for(typeof(b) i = a; i < (b); ++i)
#define rep(i, n)     repd(i, 0, n)
#define dump(x)       cerr << #x << " = " << (x) << endl
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define YesNo(x) cout << ((x) ? "Yes" : "No") << endl
#define YESNO(x) cout << ((x) ? "YES" : "NO") << endl

int main(int argc, const char* argv[]) {
	ll a, b, t;
	cin >> a >> b >> t;

	ll ret = 0;
	for(ll i = a; i <= t; i += a) {
		ret += b;
	}

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[1005][1005];
int main(){
	int n,k;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		int x,y,b;
		char c;
		cin>>x>>y>>c;
		if(c=='W')
		y+=k;
		b=x/k%2==y/k%2?1:-1;
		if(b>0) a[0][0]++;
		int l=x%k+1,r=y%k+1;
		a[l][0]-=b;
		a[0][r]-=b;
		a[l][r]+=b*2;
	}
	for(int i=0;i<=k;i++)
	for(int j=0;j<k;j++)
	a[i][j+1]+=a[i][j];
	for(int i=0;i<=k;i++)
	for(int j=0;j<k;j++)
	a[i+1][j]+=a[i][j];
	int s=0;
	for(int i=0;i<k;i++)
	for(int j=0;j<k;j++)
	s=max(max(s,a[i][j]),n-a[i][j]);
	cout<<s;
}

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

int main() {
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  
  int Left =a+b;
  int Right =c+d;
  
  if(Left>Right){
    cout<<"Left"<<endl;
  }
  
  else if(Left==Right){
    cout<<"Balanced"<<endl;
  }
  
  else{
    cout<<"Right"<<endl;
}
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int a[100002],as[100002];char c[100002],cs[100002],sc[250002],tc[250002];
int p(int u,int v){
	int x=a[v],i=u-1,j;
	for(j=u;j<v;j++){
		if(a[j]<=x){
			swap(a[j],a[++i]);
			swap(c[j],c[i]);
		}
	}
	swap(a[i+1],a[v]);
	swap(c[i+1],c[v]);
	return i+1;
}
void q(int u,int v){
	if(u<v){
		int s=p(u,v);
		q(u,s-1);
		q(s+1,v);
	}
}
void me(int left,int d,int right){
	int n1=d-left,n2=right-d,i,j,s[250002],t[250002];
	for(i=0;i<n1;i++){
		s[i]=as[left+i];
		sc[i]=cs[left+i];
	}
	for(i=0;i<n2;i++){
		t[i]=as[d+i];
		tc[i]=cs[d+i];
	}
	s[n1]=2000000002;
	t[n2]=2000000002;
	i=0;
	j=0;
	for(int k=left;k<right;k++){
		if(s[i]<=t[j]){
			as[k]=s[i];
			cs[k]=sc[i];
			i++;
		}
		else{
			as[k]=t[j];
			cs[k]=tc[j];
			j++;
		}
	}
}
void ms(int left,int right){
	if(left+1<right){
		int d=(left+right)/2;
		ms(left,d);
		ms(d,right);
		me(left,d,right);
	}
}
int main(){
	int n,i;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>c[i]>>a[i];
		cs[i]=c[i];
		as[i]=a[i];
	}
	q(0,n-1);
	ms(0,n);
	for(i=0;i<n;i++){
		if(cs[i]!=c[i])
		break;
	}
	if(i!=n)
	cout<<"Not stable\n";
	else
	cout<<"Stable\n";
	for(i=0;i<n;i++)
	cout<<c[i]<<' '<<a[i]<<endl;
	return 0;
}


Measured memory_bytes: 4576
#include <ctime>
#include <iomanip>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <list>
#include <queue>
#include <stack>
#include <numeric>
using namespace std;

#define int long long
#define INF 1e18
#define EPS 1e-9
#define NIL -1
#define N 100

signed main() {
    int n; cin >> n;
    string  ans = "";

    while(n != 0) {
        if(n % 2 != 0) {
            n--;
            ans = "1" + ans;
        } else {
            ans = "0" + ans;
        }
        n /= -2;
    }

    if(ans == "") ans = "0";

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
function Main(input) {
	input = input.split("\n");
	var mem = input[0].split(" ").map(Number);
	var sum = 0;
	for(var i=1;i<input.length;i++){
		var n = input[i].split(" ").map(Number);
		if(n[0]>=mem[1]&&n[1]>=mem[2]) sum++;
	}
	console.log(sum)
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

Measured memory_bytes: 7740
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

int main()
{
    int a, b, c; cin >> a >> b >> c;
    if ((a == b || b == c || c == a) && !(a == b && b == c))
        cout << "Yes" << '\n';
    else
        cout << "No" << '\n';
    return 0;
}


Measured memory_bytes: 3596
H,W=map(int,input().split())
c=[list(map(int,input().split())) for _ in range(10)]
A=[list(map(int,input().split())) for _ in range(H)]
#print(H,W,c,A)
to1=[0]*10
for i in range(10):
    dp=[[float("inf") for _ in range(10)] for _ in range(11)]
    dp[0][i]=0
    for j in range(10):
        for k in range(10):
            for l in range(10):
                dp[j+1][k]=min(dp[j+1][k],dp[j][l]+c[l][k])
        #print(dp)
        #input()
    to1[i]=dp[10][1]
    #print(to1)
mi=min(to1)
cnt=0
for i in range(H):
    for j in range(W):
        if A[i][j]==-1:
            cnt=cnt+mi
        else:
            cnt=cnt+to1[A[i][j]]
print(cnt)

Measured memory_bytes: 42972
N = int(input())
L = list(map(int, input().split()))

if N < 3:
    print(0)
    exit()

ans = 0
for i in range(0, N - 2):
    for j in range(i + 1, N - 1):
        for k in range(j + 1, N):
            arr = [L[i], L[j], L[k]]
            arr.sort()
            if (arr[0] != arr[1] & arr[1] != arr[2]):
                if (arr[2] < arr[0] + arr[1]):
                    ans = ans + 1

print(ans)

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

using namespace std;
using ll = long long;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define INF 9223372036854775807
#define all(x) (x).begin(), (x).end()

ll ts = 1000000007;

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

  ll n, a, b;
  cin >> n >> a >> b;
  cout << (n * a > b ? b : n * a) << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

vector<int> v(4);

void rec(string s) {
    if(s.size() >= 3) {
        int tmp = v[0];
        for(int i = 0; i < 3; i++)
            if(s[i] == '0')
                tmp += v[i + 1];
            else
                tmp -= v[i + 1];
        if(tmp == 7) {
            for(int i = 0; i < 3; i++) {
                cout << v[i];
                if(s[i] == '0')
                    cout << '+';
                else
                    cout << '-';
            }
            cout << v[3] << "=7";
            exit(0);
        }
    } else {
        rec(s + '0');
        rec(s + '1');
    }
}
int main() {
    cin >> v[0];
    for(int i = 0; i < 3; i++) {
        v[3 - i] = v[0] % 10;
        v[0] /= 10;
    }
    rec("");
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
MOD = 10**9+7
num_one_for_digit = [0]*61
for i in range(N):
    b = bin(A[i])[2:].zfill(61)
    for d in range(61):
        if b[d] == "1":
            num_one_for_digit[d] += 1
ans = 0
t = 1
for d in range(60, -1, -1):
    n_1 = num_one_for_digit[d]
    ans += n_1 * (N - n_1) * t % MOD
    ans %= MOD
    t *= 2
print(ans%MOD)

Measured memory_bytes: 124524
#include"bits/stdc++.h"
using namespace std;
int main(){
	string s;
	cin>>s;
	string t=s;
	reverse(s.begin(),s.end());
	for(auto &i:s){
		if(i=='b')
			i='d';
		else if(i=='d')
			i='b';
		else if(i=='p')
			i='q';
		else if(i=='q')
			i='p';
	}
	if(s==t)
		cout<<"Yes";
	else
		cout<<"No";
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    ll x;
    cin >> x;
    ll ans = 0;
    ans += (x / 11) * 2;
    if(x - (x / 11) * 11 > 6) ans += 2;
    else if(x - (x / 11) * 11 > 0) ans += 1;
    cout << ans << endl;
}

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

#define mod 1000000007

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

using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;
 
int main(void){
	
	int N;
    string S;
    cin >> N >> S;
    int ans = 0;
    rep(i, N - 2){
        if(S[i] == 'A' && S[i+1] == 'B' && S[i+2] == 'C'){
            ans++;
        }
    }

    cout << ans << endl;
	
	return 0;
}


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

int main(){
	int n;
    string str;
  	cin>> n >>str;
    int count;
    count = 0;
	for(int i=0;i<str.length()-1;i++){
    	if (str.at(i) != str.at(i+1))
        	count++;
    }
    count++;
    cout<<count;
	return 0;
}



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

def calc(x):
    n = x // 2 % 2
    if x % 2 :
        if n : return 0
        else: return 1 # 実質(x -1) ^ x の結果
    else:
        return x ^ n 

print(calc(b) ^ calc(a-1))

Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
int N, M;
int INF = (int)1 << 60;
vector<int> solve(vector<vector<int> > &g , vector<vector<int> > &A, int s) {
	vector<int> res(N, INF);
	priority_queue<pair<int,int > > pq;
	res[s] = 0;
	pq.emplace(0, s);
	while (pq.size()) {
		int a = pq.top().second; pq.pop();
		for (int i = 0; i < g[a].size(); i++) {
			if (res[g[a][i]] > res[a] + A[a][i]) {
				res[g[a][i]] = res[a] + A[a][i];
				pq.emplace(-res[g[a][i]], g[a][i]);
			}
		}
	}
	return res;
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int S, T;
	cin >> N >> M >> S >> T;
	S--;
	T--;
	vector<vector<int>  >g(N);
	vector<vector<int>  >a(N);
	vector<vector<int>  >b(N);
	int u, v, aa, bb;
	for (int i = 0; i < M; i++) {
		cin >> u >> v >> aa >> bb;
		u--;
		v--;
		g[u].push_back(v);
		g[v].push_back(u);
		a[u].push_back(aa);
		a[v].push_back(aa);
		b[u].push_back(bb);
		b[v].push_back(bb);
	}
	vector<int> A, B;
	A = solve(g, a, S);
	B = solve(g, b, T);
	vector<int> res(N);
	
	res[N - 1] = A[N - 1] + B[N - 1]; 
	for (int i = N - 2; i >= 0; i--) {
		res[i] = min(res[i + 1], A[i] + B[i]);
	}
	int z = (int)(1e15);
	for (int i = 0; i < N; i++) {
		cout << z - res[i] << endl;
	}
}

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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	long long H;
	cin >> H;
	long long ans = 0, cnt = 1;
	while (H > 0) {
		H /= 2;
		ans += cnt;
		cnt *= 2;
	}
	cout << ans << '\n';
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define pb push_back
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    vector<ll> L(86);
    L.at(0)=2; L.at(1)=1;
    int N; cin>>N;
    for(int i = 2; i <= N; i++) {
        L.at(i) = L.at(i-1) + L.at(i-2);
        L.pb(L.at(i));
    }
    cout<<L.at(N)<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
    long long int a,b;
    cin >> a >> b;
    if (a == 1) {
        if (b == 2) {
            cout << "3";
        } else {
            cout << "2";
        }
    }
    if (a == 2) {
        if (b == 1) {
            cout << "3";
        } else {
            cout << "1";
        }
    }
    if (a == 3) {
        if (b == 1) {
            cout << "2";
        } else {
            cout << "1";
        }
    }
    cout << endl;
    return 0;
    
    
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void)
{
    int N, K, i, x[101], ans=0;

    cin >> N;
    cin >> K;

    for(i=1; i<=N; i++){
        cin >> x[i];

        if(x[i] < K-x[i]){
            ans += (2*x[i]);
        }
        else{
            ans += (2*(K-x[i]));
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
S = list(input())
T = list(input())

s, t = len(S), len(T)
ans = s

for i in range(s-t+1):
    tmp = S[i:i+t]

    cnt = 0
    for i, j in zip(T, tmp):
        if i != j:
            cnt += 1

    ans = min(ans, cnt)

print(ans)

Measured memory_bytes: 9128
import java.util.Scanner;

public class Main {
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		int count = scan.nextInt();
		int[][][] house = new int[4][3][10];
		int b = 0;
		int f = 0;
		int r = 0;
		int v = 0;
		for(int i = 0;i < count;i++)
		{
			b = scan.nextInt();
			f = scan.nextInt();
			r = scan.nextInt();
			v = scan.nextInt();
			house[b - 1][f - 1][r - 1]+= v;
		}
		
		for(int i = 0;i < 4;i++)
		{
			for(int j = 0;j < 3;j++)
			{
				for(int k = 0;k < 10;k++)
				{
					System.out.print(" " + house[i][j][k]);
				}
				System.out.println("");
			}
			if(i != 3)
			{
				System.out.println("####################");
			}
		}
			
	}
}

Measured memory_bytes: 21068
#include <iostream>

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

    if((abs(a - b) <= d && abs(b - c) <= d) || abs(c - a) <= d){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    } 
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fo(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define umap unordered_map
#define minHeap(t) priority_queue<t, vector<t>, greater<t>>
#define maxHeap(t) priority_queue<t>

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

    int t=1;
    //cin>>t;
    while(t--){
        int x,n;
        cin>>x>>n;
        set<int> s;
        while(n--){
            int t;
            cin>>t;
            s.insert(t);
        }
        int diff = INT_MAX;
        int ans = x;
        for (int i = 0; i < 102; i++)
        {
            if(s.count(i)) continue;
            int d = abs(x-i);
            if(diff>d){
                diff = d;
                ans = i;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <climits>
#include <string>
#include <stdlib.h>
#include <algorithm>

using namespace std;
 
int ascSort(const void* v1, const void* v2) {
    const int _v1 = *((const int*)v1);
    const int _v2 = *((const int*)v2);
 
    if ( _v1 < _v2 ) {
        return 1;
    } else if ( _v1 > _v2 ) {
        return -1;
    } else {
        return 0;
    }
}
int solve(int a,int b,int c){
	return max(max(a,b),c)-min(min(a,b),c);
}


int main() {
	int x,a,b;
	cin >> x>>a>>b;
	if(a>=b){
		cout << "delicious" << endl;
	}else if(b-a>x){
		cout << "dangerous" << endl;
	}else{
		cout << "safe" << endl;
	}
	return 0;
}

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

import sys

################ DANGER ################
test = ""
#test = \
"""
1000000000000000000
124999999999999995
"""
########################################
test = list(reversed(test.strip().splitlines()))
if test:
    def input2():
        return test.pop()
else:
    def input2():
        return input()
########################################
        

n = int(input2())
if n % 2:
    print(0)
    sys.exit()
    
    
ans = 0
i = 0
while (10 * 5**i) <= n:
    ans += n // (10 * 5**i)
    i += 1

print(ans)




Measured memory_bytes: 3064
#include <stdio.h>

int henkan(char,char);

main(){
  char input[10], temp;
  int i, j, in[3], dk, ans, a;
  int data[8][3]={0,0,0,0,0,255,0,255,0,0,255,255,255,0,0,255,0,255,255,255,0,255,255,255};


  while(1){
    scanf("%c", &temp);
    if(temp=='0') break;

    scanf("%s", input);
    getchar();
    for(i=0,j=0;i<6;i+=2,j++){
      in[j]=henkan(input[i], input[i+1]);
    }

    dk=-1;

    for(i=0;i<8;i++){
      a=(in[0]-data[i][0])*(in[0]-data[i][0])+(in[1]-data[i][1])*(in[1]-data[i][1])+(in[2]-data[i][2])*(in[2]-data[i][2]);
      if(dk==-1 || a<dk){
	dk=a;
	ans=i;
      }
    }

    if(ans==0) printf("black");
    else if(ans==1) printf("blue");
    else if(ans==2) printf("lime");
    else if(ans==3) printf("aqua");
    else if(ans==4) printf("red");
    else if(ans==5) printf("fuchsia");
    else if(ans==6) printf("yellow");
    else if(ans==7) printf("white");
    printf("\n");
  }
  return 0;
}

int henkan(char a, char b){
  int x,y;

  if(a>='a' && a<='f') x=(a-'a'+10)*16;
  else x=(a-'0')*16;
  if(b>='a' && a<='f') y=b-'a'+10;
  else y=b-'0';

  return x+y;
}

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

// 計算効率が良い方法も自力で実装できるが、趣旨的に全探索で実装する
vector<int> x, y;
double dist(int i, int j) {
    double dx = x[i] - x[j];
    double dy = y[i] - y[j];
    return pow(dx * dx + dy * dy, 0.5);
}

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

  rep(i, n) {
    int a, b;
    cin >> a >> b;
    x.push_back(a);
    y.push_back(b);
  }
  
  vector<int> v(n);
  for(int i = 0; i < n; i++) v[i] = i;

  double ans = 0.0;
  do {
    for(int i = 0; i < n - 1; i++) ans += dist(v[i], v[i + 1]);
  } while(next_permutation(v.begin(), v.end()));
  int Factorial = 1;
  for(int i = 2; i <= n; i++) Factorial *= i;
  ans /= Factorial;

  printf("%.10f\n", ans);
  return 0;
}


Measured memory_bytes: 4256
// https://atcoder.jp/contests/abc122/tasks/abc122_a

#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

int main()
{
  string b, r;
  r = "";
  cin >> b;

  for (auto &c : b)
  {
    switch (c)
    {
    case 'A':
      r += "T";
      break;
    case 'C':
      r += "G";
      break;
    case 'G':
      r += "C";
      break;
    case 'T':
      r += "A";
      break;
    default:
      break;
    }
  }

  cout << r << '\n';

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define sz 200009
#define mx 10000000000008
#define mod 998244353
ll n,arr[sz],brr[sz],k,t[4*sz],laz[4*sz];
void done(ll node)
{
     laz[2*node]=(laz[node]+laz[2*node])%mod;
     laz[2*node+1]=(laz[node]+laz[2*node+1])%mod;
    t[2*node]=(laz[node]+t[2*node])%mod;
     t[2*node+1]=(laz[node]+t[2*node+1])%mod;
    laz[node]=0;
    return;
}
ll query(ll node,ll l,ll r,ll le,ll ri)
{
    if(le>ri || l>ri || r<le)
        return 0;
    if(le<=l && r<=ri)
        return t[node];
    done(node);
    ll mid=(l+r)/2;
    return ((query(2*node,l,mid,le,ri)+query(2*node+1,mid+1,r,le,ri))%mod);
}
void update(ll node,ll l,ll r,ll indl,ll indr,ll val)
{
    if(indl>indr || indl>r || indr<l)
        return;
    if(l>=indl && r<=indr)
    {
        t[node]=(t[node]+val)%mod;
       laz[node]=(laz[node]+val)%mod;
        return;
    }
    done(node);
    ll mid=(l+r)/2;
    update(node*2,l,mid,indl,indr,val);
    update(node*2+1,mid+1,r,indl,indr,val);
    t[node]=(t[2*node]+t[2*node+1])%mod;
    return;
}
int main()
{
   scanf("%lld %lld",&n,&k);
   for(int i=1;i<=k;i++)
   {
       scanf("%lld %lld",&arr[i],&brr[i]);
   }
   update(1,1,n,1,1,1);
   for(int i=1;i<=n;i++)
   {
       ll val=query(1,1,n,i,i);
    //   printf("    %lld\n",val);
       for(int j=1;j<=k;j++)
       {
        update(1,1,n,i+arr[j],i+brr[j],val);
       }
   }
   printf("%lld\n",query(1,1,n,n,n));
    return 0;
}


Measured memory_bytes: 12032
#include <bits/stdc++.h>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;

int main()
{
  int a,b,t;
  cin>>a>>b>>t;
  int cnt = t / a;
  cout << (cnt * b) << endl;
  return 0;
}


Measured memory_bytes: 256
# coding:utf-8
import sys 
def main():
    n,y = map(int, input().split())
    for i in range(0,n+1):
        for j in range(0,n-i+1):
            k = (n-(i+j))
            if k <= 0:
                k = 0
            total = (10000*i) + (5000*j) + (1000*k)
            if total == y :
                print(str(i)+' '+str(j)+ ' '+str(k))
                sys.exit()

    print(str(-1)+' '+str(-1)+ ' '+str(-1))
             



if __name__ == '__main__' :
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
using namespace std;
map <string,int> cost;
multimap <string,string>  rule;
set <string> his;
void update(string a){
  multimap<string,string>::iterator it=rule.find(a);
  while(it != rule.end() && it->first == a) {
    if(cost[it->second]>cost[a])cost[it->second]=cost[a], update(it->second);
    it++;
  }
}
int mk_rule(string a){
  if(his.count(a) == 0){
    his.insert(a);    
    multimap<string,string>::iterator it=rule.find(a);
    while(it != rule.end() && it->first == a) cost[a]= min(cost[a],mk_rule(it->second)),it++;
    update(a);
  }
  return cost[a];
}
int main(){
  int n,m,b;
  cin >> n;
  string a,c,ls[5002];
  for(int i=0;i<n;i++) cin >> ls[i] >> b, cost[ls[i]] = b;
 
  cin >> m;
  for(int i=0;i<m;i++){
    cin >> a >> c;
    rule.insert(pair<string,string>(a,c));
    rule.insert(pair<string,string>(c,a));
  }
  int ans=0;
  for(int i=0;i<n;i++) ans += mk_rule(ls[i]);
  cout << ans <<endl;
  return 0;
}

Measured memory_bytes: 2244
#include<iostream>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)

bool IsPrime(int N)
{
	if (N == 2)return true;
	else if (N % 2 == 0)return false;
	for (int i = 3; i*i <= N; i+=2)
	{
		if (N%i == 0)return false;
	}
	return true;
}

int main()
{
	int n, ans = 0;
	cin >> n;
	REP(i, n)
	{
		int temp;
		cin >> temp;
		if (IsPrime(temp))ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i <= (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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 (a>b) { a=b; return 1; } return 0; }



int main() {
  int r, g, b, n;
  cin >> r >> g >> b >> n;

  int ans = 0;
  rep(i, n / r) {
    rep(j, n / g) {
      if (i * r + j * g > n) break;
      if ((n - i * r - j * g) % b == 0) ans++;
    }
  }
  cout << ans << endl;

  
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

const int MAX_N = 5000;
const long long inf = 1e15;

int N;
vector<int> G[MAX_N];

int A[MAX_N];

void input(){
	scanf("%d", &N);
	for(int i = 0; i < N; ++i) scanf("%d", A + i);
	for(int i = 0; i < N - 1; ++i){
		int u, v;
		scanf("%d%d", &u, &v);
		u--;
		v--;
		G[u].push_back(v);
		G[v].push_back(u);
	}
}

vector<long long> dp1[MAX_N], dp2[MAX_N];

vector<long long> tr(vector<long long> dp, vector<long long> ch1, vector<long long> ch2, bool flg){
	int a = dp.size(), b = ch1.size();
	vector<long long> ans(a + b - 1);
	for(int i = 0; i < ans.size(); ++i) ans[i] = inf;
	for(int i = 0; i < dp.size(); ++i){
		if(dp[i] == inf) continue;
		for(int j = 0; j < ch1.size(); ++j){
			if(i + j - 1 >= 0){
				if(ch1[j] != inf) ans[i + j - 1] = min(ans[i + j - 1], dp[i] + ch1[j]);
				if(ch2[j] != inf && (!flg)) ans[i + j - 1] = min(ans[i + j - 1], dp[i] + ch2[j]);
			}
			if(ch1[j] != inf) ans[i + j] = min(ans[i + j], dp[i]);
			if(ch2[j] < 0) ans[i + j] = min(ans[i + j], dp[i]);
		}
	}
	return ans;
}

void dfs(int v, int p){
	dp1[v].push_back(inf);
	dp1[v].push_back(A[v] > 0 ? A[v] : inf);
	dp2[v].push_back(inf);
	dp2[v].push_back(A[v]);
	for(int i = 0; i < G[v].size(); ++i){
		int u = G[v][i];
		if(u == p) continue;
		dfs(u, v);
		dp1[v] = tr(dp1[v], dp1[u], dp2[u], true);
		dp2[v] = tr(dp2[v], dp1[u], dp2[u], false);
	}
}

int solve(){
	dfs(0, -1);
	/*if(N <= 10){
		for(int i = 0; i < N; ++i){
			for(int j = 0; j < min(3, (int)dp2[i].size()); ++j){
				printf("%lld,%lld ", dp1[i][j], dp2[i][j]);
			}
			printf("\n");
		}
	}*/
	for(int i = 0; i <= N; ++i){
		if(dp1[0][i] < inf) return i - 1;
		if(dp2[0][i] < 0) return i - 1;
	}
	return -1;
}

int main(){
	input();
	int ans = solve();
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 179072
#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 < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

using namespace std;

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  rep(i,N){
    cin >> a[i];
  }
  sort(all(a));
  int head = 0,tail = N-2;
  deque<int> bigA;
  bigA.push_back(a[N-1]);
  int i = 0;
  while(head <= tail ){
    if(i%2 == 1){
      bigA.push_front(a[tail]);
      tail--;
      if(head > tail) break;
      bigA.push_back(a[tail]);
      tail--;
    }else{
      bigA.push_front(a[head]);
      head++;
      if(head > tail) break;
      bigA.push_back(a[head]);
      head++;
    }
    i++;
  }

   int current; long long score = 0;
   int prev = bigA.front();
  bigA.pop_front();
  while(bigA.empty() == false){
    current = bigA.front();
    bigA.pop_front();
    score += abs(prev - current);
    prev = current;
    //cout << "null " << bigA.size() << endl;
  }


  // min
  head = 1; tail = N-1;
  deque<int> smallA;
  smallA.push_back(a[0]);
  i = 0;
  while(head <= tail){
    if(i%2 == 0){
      smallA.push_front(a[tail]);
      tail--;
      if(head > tail) break;
      smallA.push_back(a[tail]);
      tail--;
    }else{
      smallA.push_front(a[head]);
      head++;
      if(head > tail) break;
      smallA.push_back(a[head]);
      head++;
    }
    //cout << smallA.front() << ' ' << smallA.back() << endl;
    i++;
  }

  long long score2 = 0;
  //cout << smallA.size() << endl;
  prev = smallA.front();
  smallA.pop_front();
  //cout << prev << ' ';
  while(smallA.empty() == false){
    //cout << current << ' ';
    current = smallA.front();
    smallA.pop_front();
    score2 += abs(prev - current);
    prev = current;
  }
  //cout << endl;
  cout << max(score , score2) << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
static const int MAX = 1000000;

int a[MAX] = {0};

int func(int n)
{
    if (n % 2 == 0)
    {
        return n / 2;
    }
    else
    {
        return 3 * n + 1;
    }
    return 0;
}

int main()
{
    int s;
    int a_tmp;
    cin >> s;
    a_tmp = s;
    a[a_tmp - 1] = 1;
    for (int i = 1; i <= MAX; i++)
    {
        a_tmp = func(a_tmp);
        if (a[a_tmp - 1] == 1)
        {
            cout << i + 1;
            break;
        }
        else
        {
            a[a_tmp - 1] = 1;
        }
    }

    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline


def read():
    S = input().strip()
    return S,


def solve(S):
    N = len(S)
    ans = [0, 0]  # 偶数番目、奇数眼目の1の個数
    for i in range(N):
        if S[i] == "1":
            ans[i % 2] += 1
    return min(ans[0]+N//2-ans[1], N//2+N%2-ans[0]+ans[1])


if __name__ == '__main__':
    inputs = read()
    print(solve(*inputs))


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

int main(){
  int H,W,N;
  cin>>H>>W>>N;
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin>>a.at(i);
  }

  int h=0;
  int w=0;
  int color=0;
  int flow=0;
  vector<vector<int>> c(H,vector<int>(W));
  while(h<H){
    if(flow==0){
      while(w<W){
        while(a.at(color)>0){
          c.at(h).at(w)=color+1;
          a.at(color)--;
          w++;
          if(w==W){
            flow=1;
            h++;
            break;
          }
        }
        if(a.at(color)==0){
          color++;
        }
      }
      w--;
    }else{
      while(w>=0){
        while(a.at(color)>0){
          c.at(h).at(w)=color+1;
          a.at(color)--;
          w--;
          if(w==-1){
            flow=0;
            h++;
            break;
          }
        }
        if(a.at(color)==0){
          color++;
        }
      }
      w++;
    }
  }

  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cout<<c.at(i).at(j)<<" ";
    }
    cout<<endl;
  }
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

v ans;
vv edges;

queue<ll> q;

int main(){
    ll N,M;
    cin>>N>>M;
    ans.resize(N);
    rep(i,0,N)ans[i] = -1;
    edges.resize(N);
    v A(M),B(M);
    rep(i,0,M){
        cin>>A[i]>>B[i];
        A[i]--;B[i]--;
        edges[A[i]].PB(B[i]);
        edges[B[i]].PB(A[i]);
    }
    q.push(0);
    while(!q.empty()){
    ll now = q.front();q.pop();
        for(ll nxt: edges[now]){
            if(ans[nxt] == -1){
                ans[nxt] = now;
                q.push(nxt);
            }
        }
    }
    cout<<"Yes"<<endl;
    rep(i,1,N)cout<<ans[i]+1<<endl;
    return 0;
}

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

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

int cnt[13] = {};
int place[24];

int Ans(int n) {
  int place2[24];
  copy(place, place+n, place2);
  sort(place2, place2+n);
  int ans = 12;
  REP(i, n-1) { ans = min(ans, place2[i+1] - place2[i]); }
  ans = min(ans, 24 - place2[n-1]);
  return ans;
}

int Set(int di, int i) {
  if (di == 0) {
    if (cnt[0] == 0) {
      place[0] = 0;
      return Set(1, 1);
    } else {
      return 0;
    }
  } else if (di == 12) {
    if (cnt[12] == 1) {
      place[i++] = 12;
    } else if (cnt[12] > 1) {
      return 0;
    }
    return Ans(i);
  } else {
    if (cnt[di] == 0) {
      return Set(di+1, i);
    } else if (cnt[di] == 1) {
      place[i] = di;
      int a = Set(di+1, i+1);
      place[i] = 24 - di;
      int b = Set(di+1, i+1);
      return max(a, b);
    } else if (cnt[di] == 2) {
      place[i] = di;
      place[i+1] = 24 - di;
      return Set(di+1, i+2);
    } else if (cnt[di] > 2) {
      return 0;
    }
  }
  return 0;
}

int main() {
  int n;
  cin >> n;
  REP(i, n) {
    int tmp;
    cin >> tmp;
    cnt[tmp]++;
  }

  cout << Set(0, 0) << endl;

  return 0;
}


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

using namespace std;

#define int long long

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, W;
    cin >> n >> W;
    vector <int> w(n), v(n);
    for(int i = 0; i < n; i++) {
        cin >> w[i] >> v[i];
    }
    int dp[W + 1];
    memset(dp, 0, sizeof dp);
    dp[0] = 1;
    for(int i = 0; i < n; i++) {
        for(int j = W; j >= 0; j--) {
            if(j - w[i] >= 0) {
                if(dp[j - w[i]] != 0) {
                    dp[j] = max(dp[j], v[i] + dp[j - w[i]]);
                }
            }
        }
    }
    int ans = 0;
    for(int i = 0; i <= W; i++) {
        ans = max(ans, dp[i]);
    }
    cout << ans - 1 << '\n';
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

bool flag[3001][3001] = {};
int n;
ll dp[3001][3001] = {};
ll a[3000] = {};

// [i,j)
ll memo(int i, int j)
{
  if (i >= j)
    return 0;
  if (flag[i][j])
    return dp[i][j];
  if (abs(j - i) % 2 == n % 2)
    dp[i][j] = max(a[i] + memo(i + 1, j), a[j - 1] + memo(i, j - 1));
  else
    dp[i][j] = min(-a[i] + memo(i + 1, j), -a[j - 1] + memo(i, j - 1));
  flag[i][j] = true;
  return dp[i][j];
}

int main()
{
  cin >> n;
  REP(i, n)
  {
    cin >> a[i];
  }

  cout << memo(0, n) << endl;
}


Measured memory_bytes: 79616
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;

int main()
{
    int n;
    cin >> n;
    ll a[100005], b[100005];
    ll sa = 0, sb = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        sa += a[i];
    }
    for(int i = 0; i < n; i++){
        cin >> b[i];
        sb += b[i];
    }
    if(sa < sb){
        cout << -1 << endl;
        return 0;
    }
    ll d[100002];
    int ans = 0;
    ll s = 0;
    for(int i = 0; i < n; i++){
        if(a[i] < b[i]){
            ans++;
            s += b[i] - a[i];
            d[i] = 0;
        }
        else{
            d[i] = a[i] - b[i];
        }
    }
    sort(d, d + n, greater<ll>());
    for(int i = 0; i < n; i++){
        if(s <= 0) break;
        ans++;
        s -= d[i];
    }
    cout << ans << endl;
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define RREP(i, x, n) for (int i = x - 1; i >= (int)(n); i--)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, n, 0)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MAX 1e9 + 7

using namespace std;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }

int main(void)
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if ((a + b) == (c + d))
    {
        cout << "Balanced" << endl;
    }
    else if ((a + b) > (c + d))
    {
        cout << "Left" << endl;
    }
    else
    {
        cout << "Right" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
n, m = map(int,input().split())

#偶数タス偶数または奇数タス奇数
import math
def combinations_count(a, b):
    return math.factorial(a) // (math.factorial(a - b) * math.factorial(b))

if n >= 2:
    ans1 = combinations_count(n, 2)
else:
    ans1 = 0

if m >= 2: 
    ans2 = combinations_count(m, 2)
else:
    ans2 = 0
    
print(ans1 + ans2)


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

using namespace std;
long long sum=0;
long long n,st=1,V[1000001];

int main()
{
    cin>>n;
    n*=3;
    for(int i=1;i<=n;i++) cin>>V[i];
    sort(V+1,V+1+n);
    for(int i=n-1;i>=st;i-=2) sum+=V[i],st++;


    cout<<sum;
}


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

using namespace std;

#define INF (10000000000000000LL)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))

int main()
{
    int N,M;
    long long K;
    cin >> N >> M >> K;

    vector<long long> A;

    for(int i=0; i<N; ++i) {
        long long temp;
        cin >> temp;
        A.push_back(temp);
    }

    vector<long long> dp(N);
    long long mx=-1;
    long long mn=INF;
    for(int i=0; i<N; ++i) { // initialize
        mx=MAX(mx,A[i]);
        mn=MIN(mn,A[i]);
        if(i<M) dp[i]=K+(i+1)*(mx-mn);
        else dp[i]=INF;
    }

    int indx=1;
    while(indx<N) {
        mx=-1; mn=INF;
        long long temp=dp[indx];
        for(int k=1; k<=M && indx-k>=0 ; ++k) { // add one more box
            mx=MAX(mx,A[indx-k+1]);
            mn=MIN(mn,A[indx-k+1]);
            temp=MIN(temp,dp[indx-k]+K+k*(mx-mn));
        }
        if(dp[indx]==temp) ++indx;
        else dp[indx]=temp;
    }

    cout << dp[N-1] << endl;

    return 0;
}

Measured memory_bytes: 3328
#include<stdio.h>
int main(){
  int b,f,r,v,n,i,j,k;
  int count[4][3][10]={0};

   scanf("%d",&n);
   for(i=0;i<n;i++) {
    scanf("%d%d%d%d",&b,&f,&r,&v);
    count[b-1][f-1][r-1]+=v;
   }

   for(i=0;i<4;i++){
     for(j=0;j<3;j++){
       for(k=0;k<10;k++){
	 printf(" %d",count[i][j][k]);
       }
       printf("\n");
     }
     if(i<3) printf("####################\n");
   }
  return 0;
}

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

signed main(){
  int x, y; cin >> x >> y;
  for(int a = 0; a <= 100; a++){
    for(int b = 0; b <= 100; b++){
      if(2 * a + 4 * b == y && a + b == x){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}

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


signed main() {
    ll X;
    cin >> X;

    ll a = 100;
    ll cnt = 0;

    while (1) {
        cnt++;
        a = a * 1.01;
        if (X <= a) break;

    }

    cout << cnt << endl;

}


Measured memory_bytes: 3628
#include <stdio.h>
#include <string.h>

int main(void)
{
	int i;
	char str[20];
	
	scanf("%s", str);
	
	for (i = strlen(str) - 1; 0 <= i; i--){
		printf("%c", str[i]);
	}
	printf("\n");
	
	return (0);
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
#define two(a) (1<<(a))
#define LINF (1ll<<61)
#define EPS (1e-14)
#define Lshift(a,b) (a<<b)
#define Rshift(a,b) (a>>b)
#define rep(a,b) for(a=0 ; a<b ; a++)
#define xrep(a,b,c) for(a=b ; a<c ; a++)
#define INF (1<<29)
#define swap(a,b) ( (a^=b) , (b^=a) , (a^=b) )
#define GET(x) (mark[x>>5]>>(x&31)&1)
#define SET(x) (mark[x>>5]|=1<<(x&31))
#define maxL (10000000>>5)+1
#define mod 1000000007
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>
#define pb push_back
typedef long long ll;
using namespace std;

int main() {
    ll n;
    cin >> n;
    vector<ll> in(n);
    ll i;
    rep(i, n) cin >> in[i];
    ll money(1000), stock(0);
    rep(i, n-1) {
        if (in[i] > in[i+1]) {
            money += stock * in[i];
            stock = 0;
        } else if (in[i] < in[i+1]) {
            stock += money / in[i];
            money %= in[i];
        }
    }
    money += stock * in[n-1];
    cout << money << endl;
}


Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    long long ans = LLONG_MAX;
    int N,K;
    cin >> N >> K;
    vector< pair<long long,long long> > P;
    
    for ( int i = 0; i < N; i++ ) {
        long long x,y;
        cin >> x >> y;
        P.push_back( make_pair(x,y) );
    }
    
    for ( int i = 0; i < N; i++ ) {
    for ( int j = 0; j < i; j++ ) {
        
        int l = min( P[i].first, P[j].first);
        int r = max( P[i].first, P[j].first );
        
        vector<long long> x;
        for ( int k = 0; k < N; k++ ) {
            if ( l <= P[k].first && P[k].first <= r ){
                x.push_back( P[k].second );
            }
        }
        
        sort( x.begin(), x.end() );
        
        long long a = LLONG_MAX;
        for ( int k = 0; k + K - 1 < x.size(); k++ ) {
            a = min( a, x[k+K-1] - x[k] );
        }
        // cout << a << endl;
        if ( a == LLONG_MAX ) { continue; }
        
        ans = min( ans, a*(r-l) );
        
    }
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

int main() {
    int A,B,M;
    cin >> A >> B >> M;
    vector<int> a(A);
    vector<int> b(B);
    for(int i = 0;i < A;i++) {
        cin >> a.at(i);
    }
    for(int i = 0;i < B;i++) {
        cin >> b.at(i);
    }
    int ret = Inf;
    for(int i = 0;i < M;i++) {
        int aa,bb,cc;
        cin >> aa >> bb >> cc;
        ret = min(ret,a.at(aa - 1) + b.at(bb - 1) - cc);
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    ret = min(ret,a.at(0) + b.at(0));
    cout << ret << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <numeric>
#include <cmath>

using namespace std;

long long ggd(long long a, long long b)
{
	long long tmp;
	if (a < b) {
		tmp = a;
		a = b;
		b = tmp;
	}

	long long r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}

long long lcm(long long a, long long b)
{
	return a * b / ggd(a, b);
}

void solve()
{
	long long A, B;
	cin >> A >> B;

	cout << lcm(A, B) << endl;
}

int main()
{
	solve();

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<string> S(N);
  for(int i=0; i<N; i++){
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    S[i]=s;
  }
  long long ans=0;
  unordered_map<string, int> scores;
  for(int i=0; i<N; i++){
    if(scores[S[i]]==0){
      scores[S[i]]=1;
    }
    else{
      int temp=scores[S[i]];
      ans+=temp;
      scores[S[i]]=++temp;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 11428
package main

import (
	"fmt"
)

func main() {
	var a, b int
	fmt.Scan(&a, &b)
	fmt.Println(calcSubCurtain(a, b))
}

func calcSubCurtain(a, b int) int {
	sub := a - 2*b
	if sub < 0 {
		return 0
	}
	return sub
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
 
int main(){
  #define int int64_t
  int N,P;
  //cin>>N>>P;
  string S;
  cin>>S;
  N = S.size();
  P = 2019;
  int X=0;
  if(P==2 or P==5){
    for(int i=0;i<N;i++){
      if((int(S.at(i))-48)%P==0){
        X+=(i+1);
      }
    }
    cout<<X<<"\n";
    return 0;
  }
  unordered_map<int,int> MOD;
  int R=0;
  int Z=1;
  MOD[0]+=1;
  for(int i=0;i<N;i++){
    R=(R+(Z*(int(S.at(N-i-1))-48)))%P;
    X+=MOD[R];
    MOD[R]+=1;
    Z=(Z*10)%P;
  }
  cout<<X<<"\n";
}

Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define     PI                       acos(-1)
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-9);
using namespace std;
int dcmp(long double a,long double b){   return fabsl(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
int getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1;}
int setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
void GO(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
int countNumBit1(int mask) {int ret=0; while (mask) 	{mask &= (mask-1);++ret;	}return ret;}
const int N=1000000+9,mod=1e9+7;
int vis[N],LF[N],visid=1;
vector< pair<int,int> > v;
void solve(int n){

   for(int i=0;i<=n;i++) LF[i]=i;
   for(int i=2;i*i<=n;i++){
    if(vis[i]) continue;
    for(int j=i*2;j<=n;j+=i){
        vis[j]=1;
        LF[j]=min(LF[j],i);
    }
   }
}
void get_F(int n){

   visid++;
   while(n>1){
     if(vis[LF[n]]==visid){
        v.back().second++;
     }
     else{
        vis[LF[n]]=visid;
        v.pb(mp(LF[n],1));
     }
     n/=LF[n];
   }
}
int main(){
    GO();

    int T;
  //  cin>>T;
    T=1;
    while(T--){

        int n;
        cin>>n;
        solve(1000000);
        clr(vis,0);
        ll ans=0;
        for(int i=1;i<=n-1;i++){
            int rem= n-i;
            if(rem==0) continue;
            if(rem==1){
                ans++;
                continue;
            }
            v.clear();
            get_F(rem);
            ll tans=1;
            for(int j=0;j<sz(v);j++){
                tans*= (v[j].second+1);
            }

            ans+=tans;
        }
        cout<<ans<<"\n";
    }
}



















































































































































































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

int main() {
  int n;
  
  while(cin >> n, n) {
    int data[20]={}, all = 0;
    for(int i=0; i<n; i++) {
      cin >> data[i];
      all += data[i];
    }
    
    int ans = 1<<23;
    for(int i=0; i<(1<<n); i++) {
      int a = 0;
      for(int j=0; j<n; j++) {
	if((i>>j) & 1) {
	  a += data[j];
	  ans = min(ans, abs(a-(all-a)));
	}
      }
    }
    cout << ans << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1160
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// x ** n % mods を求める
fn mod_pow(x: i64, n: i64, mods: i64) -> i64 {
    if n == 0 {
        return 1;
    }
    let mut res = mod_pow(x * x % mods, n / 2, mods);
    if n % 2 == 1 {
        res = res * x % mods;
    }
    return res;
}

// (1/n) % mods を求める
fn mod_inv(n: i64, mods: i64) -> i64 {
    return mod_pow(n, mods-2, mods);
}

// nCk % mods を求める
fn mod_comb(n: i64, k: i64, mods: i64) -> i64 {
    let sum1 = (n-k+1..n+1).fold(1, |ac, x| ac * x % mods);
    let sum2 = (1..k+1).fold(1, |ac, x| ac * x % mods);
    return sum1 * mod_inv(sum2, mods) % mods;
}

// nCk の組み合わせを列挙する
fn combination(n: usize, k: usize) -> Vec<Vec<usize>> {
    let mut ans = Vec::new();
    if k == 1 {
        for i in 1..n+1 {
            let mut tmp = Vec::new();
            tmp.push(i);
            ans.push(tmp);
        }
    }
    else {
        for iter in combination(n-1, k-1) {
            let max = iter.iter().max().unwrap();
            for j in *max+1..n+1 {
                let mut tmp = iter.clone();
                tmp.push(j);
                ans.push(tmp);
            }
        }
    }
    ans
}


fn main() {
    input!{
        a: i64,
        b: i64,
        c: i64,
        k: i64,
    }
    let mut max: i64 = 0;
    if k < a {
        max = k;
    } else if k < a+b {
        max = a;
    } else {
        max = a - (k - a - b);
    }
    println!("{}", max);
}


Measured memory_bytes: 2108
//
// Created by yjq on 2019/11/7.
//

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define ull unsigned long long
#define __ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

string s;

stack<char> S;

int main() {
    __;
    cin >> s;
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == 'S')S.push(s[i]);
        if (s[i] == 'T') {
            if (S.empty())S.push(s[i]);
            else {
                if (S.top() == 'S')S.pop();
                else S.push(s[i]);
            }
        }
    }
    cout << S.size() << endl;
    return 0;
}

Measured memory_bytes: 720