akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
   #define PP pair<int,pair<int,int>>
const int MAX = 510000;
const int MOD =  1000000007;


     signed main(){
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    if(k>a[n-1]){
      cout<<"IMPOSSIBLE"<<endl;
      return 0;
    }
    for(int i=1;i<n;i++){
      while(a[i-1]!=0){
        a[i]%=a[i-1];
        swap(a[i],a[i-1]);
      }
    }
    if(k%a[n-1]){
      cout<<"IMPOSSIBLE"<<endl;
    }else cout<<"POSSIBLE"<<endl;
                  
}


        


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    private static Scanner sc;
    public static void main(String[] args) {
        Main instance = new Main();
        sc = instance.new Scanner();
        instance.solve();
    }

    private void solve() {
        try {
            long minValue = Long.MAX_VALUE;
            long N = sc.nextLong();
            for (int i = 0; i < 5; i++) {
                long hoge = sc.nextLong();
                minValue = (minValue > hoge) ? hoge: minValue;
            }
            System.out.println((long)Math.ceil(N/ (double) minValue)+(long)4);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private class Scanner {
        String[] s;
        int i;
        BufferedReader br;
        String regex = " ";

        public Scanner() {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        @Override
        protected void finalize() throws Throwable {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        }

        private void destruction() throws IOException {
            if (br != null) br.close();
        }

        public String next() throws IOException {
            if (i < s.length) return s[i++];
            String st = br.readLine();
            while (st == "") st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public Long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }

        public Double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }
    }
}

Measured memory_bytes: 22740
# import itertools
# import math
# import sys
# sys.setrecursionlimit(500*500)
import numpy as np
# import heapq
# from collections import deque

# N = int(input())
# S = input()
# n, *a = map(int, open(0))
N, K = map(int, input().split())
# A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# tree = [[] for _ in range(N + 1)]
# B_C = [list(map(int,input().split())) for _ in range(M)]
# S = input()

# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)


# def dfs(tree, s):
#     for l in tree[s]:
#         if depth[l[0]] == -1:
#             depth[l[0]] = depth[s] + l[1]
#             dfs(tree, l[0])
# dfs(tree, 1)

# def factorization(n):
#     arr = []
#     temp = n
#     for i in range(2, int(-(-n**0.5//1))+1):
#         if temp%i==0:
#             cnt=0
#             while temp%i==0:
#                 cnt+=1
#                 temp //= i
#             arr.append([i, cnt])
#     if temp!=1:
#         arr.append([temp, 1])
#     if arr==[]:
#         arr.append([n, 1])
#     return arr

A = [i for i in range(N + 1)]
A = np.array(A)
cum_A = np.cumsum(A)

cnt = 0
for i in range(K, N + 1):
    cnt += (cum_A[N] - cum_A[N - i]) - cum_A[i - 1] + 1
print((cnt + 1) % (10**9 + 7))

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, I, k=0;
    string s;
    cin >> n >> s;
    vector <int> V;
    for (int i = 0; i < n; i++)
    {
        if (s[i] == 'R')
        {
            V.push_back(i);
        }
    }
    V.push_back(-1);
    sort(V.rbegin(),V.rend());
    I = 0;
    for (int i = 0; i < n; i++)
    {
        if (s[i] == 'W')
        {
            if (i < V[I])
            {
                I++;
                k++;
            }
        }
    }
    cout << k;
    return 0;
}


Measured memory_bytes: 4404
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,d[100005];
  cin>>n;
  for(int i=0; i<n; i++){
    cin>>d[i];
  }
  sort(d,d+n,greater<int>());

  cout<<(d[n/2-1]-d[n/2])<<'\n';
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>

using namespace std;

typedef long long ll;

#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define INF 1000000000

int main() {

	int n, k, one, ans = 0;
	cin >> n >> k;
	n--;
	k--;
	if (n%k == 0)cout << n / k << endl;
	else cout << n / k + 1 << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

//#define debug(x) ;
#define debug(x) cerr << #x << " = " << x << "\n";

ostream& operator<<(ostream& cerr, vector<ll> aux) {
  cerr << "[";
  for (auto e : aux) cerr << e << ' ';
  cerr << "]";
  return cerr;
}

const int maxT = 200011;
const int maxN = 600011;

struct node {
  int data;
  node* son[3];

  node() {
    data = 0;
    memset(son, 0, sizeof(son));
  }
};

int n, t;
int id[3], sol[maxN], cnt;
char s[maxT];
node* head;

void build(node* act, int lvl, int curr, int step) {
  if (lvl == n) {
    act->data = curr;
    return;
  }

  act->son[0] = new node();
  act->son[1] = new node();
  act->son[2] = new node();

  build(act->son[0], lvl + 1, curr, step * 3);
  build(act->son[1], lvl + 1, curr + step, step * 3);
  build(act->son[2], lvl + 1, curr + 2 * step, step * 3);
}

void salsa() {
  swap(id[1], id[2]);
}

void rumba(node* act, int lvl) {
 if (lvl == n) return;

 node* aux = act->son[id[2]];
 act->son[id[2]] = act->son[id[1]];
 act->son[id[1]] = act->son[id[0]];

 act->son[id[0]] = aux;
 rumba(act->son[id[0]], lvl + 1);
}

void print(node* act, int lvl, int curr, int step) {
  if (lvl == n) {
    sol[act->data] = curr;
    cnt++;
    return;
  }

  print(act->son[id[0]], lvl + 1, curr, step * 3);
  print(act->son[id[1]], lvl + 1, curr + step, step * 3);
  print(act->son[id[2]], lvl + 1, curr + 2 * step, step * 3);
}

int main()
{
  //freopen("test.in", "r", stdin);

  scanf("%d\n%s", &n, s);
  t = strlen(s);

  head = new node();
  build(head, 0, 0, 1);

  for (int i = 0; i < 3; i++) 
    id[i] = i;
   
  for (int i = 0; i < t; i++) {
    if (s[i] == 'S')
      salsa();
    else
      rumba(head, 0);
  }

  print(head, 0, 0, 1);
  for (int i = 0; i < cnt; i++)
    printf("%d ", sol[i]);

  return 0;
}


Measured memory_bytes: 43696
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<set>

using namespace std;
using ll = long long;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double PI = acos(-1.0);

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

int main() {
    int A, B, C; cin >> A >> B >> C;

    cout << min(B / A, C) << endl;
    return 0;
}


Measured memory_bytes: 256
# 配るDP

n = int(input())


max_n = 110000
dp = [n] * max_n

# 初期化
dp[0] = 0

for i in range(n):
    pow6, pow9 = 1, 1
    while i + pow6 <= n:
        dp[i + pow6] = min(dp[i + pow6], dp[i] + 1)
        pow6 *= 6
    while i + pow9 <= n:
        dp[i + pow9] = min(dp[i + pow9], dp[i] + 1)
        pow9 *= 9
print(dp[n])


Measured memory_bytes: 3828
S = input()

f = int(S[:2])
b = int(S[-2:])

if 0 < b and b < 13:
    yymm = True
else:
    yymm = False
    
if 0 < f and f < 13:
    mmyy = True
else:
    mmyy = False
    
if yymm and mmyy:
    ans = "AMBIGUOUS"
elif yymm:
    ans = "YYMM"
elif mmyy:
    ans = "MMYY"
else:
    ans = "NA"
    
        
print(ans)

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


int main() {
  int Q;
  cin >> Q;
  vector<int> L(Q), R(Q);
  for (int i = 0; i < Q; ++i) {
    cin >> L.at(i) >> R.at(i);
  }
  
  int max_R = *max_element(R.begin(), R.end());
  vector<int> dp(max_R + 1, 0);
  vector<bool> P(max_R + 1, false);
  dp.at(0) = 1, dp.at(1) = 1, dp.at(2) = 1;
  P.at(1) = true, P.at(2) = true;
  for (int i = 3; i <= max_R; ++i) {
    if (i % 2 == 0) {
      dp.at(i) = dp.at(i - 1);
      continue;
    }
    bool flg = true;
    for (int j = 3; j <= sqrt(i); j += 2) {
      if (i % j == 0) {
        flg = false;
        break;
      }
    }
    if (flg) {
      P.at(i) = true;
      if (P.at((i + 1) / 2)) {
        dp.at(i) = dp.at(i - 1) + 1;
      } else {
        dp.at(i) = dp.at(i - 1);
      }
    } else {
      dp.at(i) = dp.at(i - 1);
    }
  }
  
  for (int i = 0; i < Q; ++i) {
    int li = L.at(i) - 1, ri = R.at(i), result = dp.at(ri) - dp.at(li);
    cout << result << endl;
  }
}

Measured memory_bytes: 1792
#pragma region 宣言部分
#include <iostream>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
typedef long long ll;
#define REP(i,n) for(int i = 0;i < (n);i++)
#define rep(i,m,n) for(int i = (m);i < (n);i++)
#define P pair<int,int>
#define pb push_back
#define mk make_pair
using namespace std;
#define Vec(a) vector <int> a
const int INF = 1 << 20;
const int MOD = 1e9+7;

#pragma endregion



int main(){
    int n;
    cin >> n;
    string str[n];
    int a = 0,b = 0,c = 0,d = 0;
    REP(i,n){
        cin >> str[i];
        if(str[i] == "AC")
            a++;
        else if(str[i] == "WA")
            b++;
        else if(str[i] == "TLE")
            c++;
        else{
            d++;
        }
    }
    cout << "AC x " << a << endl;
    cout << "WA x " << b << endl;
    cout << "TLE x " << c << endl;
    cout << "RE x " << d << endl;
    return 0;
}


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

int main() {
long n;
cin >>n;
long kouho_one= 0;
long kouho_two= 0;
long dif=10000000;
for(long i=ceil(sqrt(n));i>1;i--)
    {if(n%i==0)
        {if(abs(sqrt(n)-i)<dif){
            dif=abs(sqrt(n)-i);
            kouho_one=i;
            kouho_two=n/i;}

        
}

    }
long ans = kouho_one+kouho_two-2;
if(kouho_one==0)cout << n-1 <<endl;
else cout << ans <<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
long long a[500001];
int main()
{
	long long n,k,sum=0;
	cin>>n>>k;
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
	sort(a+1,a+n+1);
	for(int i=n-k;i>=1;i--) sum+=a[i];
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 1792
/*
 		Resilience is the greatest of all virtues.
 		Code by rajiv
 */
 #include <iostream>
 #include <cstring>
 #include <vector>
 #include <map>
 #include <set>
 #include <stack>
 #include <queue>
 #include <deque>
 #include <sstream>
 #include <iomanip>
 #include <cassert>
 #include <sys/time.h>
 #include <algorithm>
 #include <bitset>
 #include <cmath>
 #include <functional>
 #include <cmath>
 #include <climits>

 using namespace std ;

 #define xx first
 #define yy second
 #define ll long long
 #define ld long double
 #define el (char)0x0A
 #define sp " "
 #define pb push_back
 #define mp make_pair
 #define all(x) (x).begin(),(x).end()
 #define clr(x) memset((x),0,sizeof(x))
 #define uint unsigned int
 #define abs(x) ((x<=0)?(-x):(x))
 #define CASET  int t;cin>>t;while(t--)
 #define FORN(i,x,y) for(int i=x;i<y;i++)
 #define MAXN 100005
 #define INF 10000000010
 #define MOD 1000000007
 #define last_set_bit(x) log2((x)&(-x))
 #define add(x,y) (x)=((x)+(y))%MOD
 #define PI 3.141592653589793

 typedef pair<int,int> PII ; typedef vector<int> VI ; typedef vector<vector<int> > VVI ; typedef vector<bool> VB ; typedef vector<string> VS ;
 typedef map<int,int> MII ; typedef map<int,VI > MIV ; typedef set<int> SI ; typedef set<PII > SPII ; typedef vector<PII > VPII ; typedef vector<VPII > VVPII ;
 const int N = 100050 ;


 vector<pair<int,ll >> v[N] ;

 ll D[N] ;
 int n , m  ;
 int dfs(int s, ll dist){
     if (D[s] != (LLONG_MAX)){
         return (D[s] == dist)?1:0 ;
     }
     D[s] = dist ;
     int ret = 1 ;
     for(auto it : v[s]){
         int x = dfs(it.xx,dist+it.yy) ;
         ret = min(ret,x) ;
     }
     return ret ;



 }
 int main(){
 	ios_base::sync_with_stdio(false) ;
 	cin.tie(nullptr) ;
    cin >> n >> m ;
    ll l , r , d ;
    for(int i = 0 ; i < m ; i++){
        cin >> l >> r >> d ;

        v[l].pb(mp(r,d)) ;
        v[r].pb(mp(l,-d));
    }

    for(int i = 0 ; i < N ; i++){
        D[i] = LLONG_MAX ;
    }
    bool ans = true ;
    for(int i = 1 ; i <= n ; i++){
        if (D[i]==(LLONG_MAX) && dfs(i,0)==0){
            ans = false ;
            break ;
        }
    }
    cout << (ans?"Yes":"No") << el ;
 }


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

int n, q;
string s;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> q >> s;
	vector<int> v(n);
	for(int i=0; i<n; ++i)
		if(s.substr(i, 2) == "AC")
			v[i+1] = 1;
	for(int i=1; i<n; ++i)
		v[i] += v[i-1];
	while(q--){
		int l, r;
		cin >> l >> r;
		cout << v[r-1] - v[l-1] << "\n";
	}
}

Measured memory_bytes: 1488
n = int(input())
p = list(map(int, input().split()))

cnt = 0
for i in range(n-2):
    if ((p[i]<p[i+1])and(p[i+1]<p[i+2])) or ((p[i]>p[i+1])and(p[i+1]>p[i+2])):
        cnt += 1
print(cnt)

Measured memory_bytes: 3064
#include <stdio.h>

int main()
{
  int i, j, k, n;
  double v, t;
  scanf("%d", &n);
  double a[n], b[n+1], c[n+1][n+1], ww[n+1];
  for (i=0; i<n; i++)    fscanf(stdin, "%lf", a+i);
  fscanf(stdin, "%lf", b);
  c[0][0] = b[0];
  ww[0] = a[0]+b[0];
  for (i=1; i<=n; i++) {
    fscanf(stdin, "%lf", b+i);
    c[i][i] = b[i];    
    c[i-1][i] = a[i-1]+(b[i-1]+b[i])*2;
    ww[i] = ww[i-1]+a[i]+b[i];
  }

  for (k=1; k<n; k++) {
    for (i=0; i<n-k; i++) {
      v = c[i][i] + c[i+1][i+k+1];
      for (j=i; j<i+k; j++) {
        t = c[i][j+1] + c[j+2][i+1+k];
        if (v>t) v=t;
      }
      c[i][i+k+1] = v + ww[i+k] - ww[i-1] + b[i+k+1];
    }
  }
  printf("%lf\n", c[0][n]);

  return 0;
}


Measured memory_bytes: 3724
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <string>
using namespace std; typedef long long ll; const int INF=100; typedef pair<int,int> P;
const int ld=10;

int main() {
  int n; cin>>n;
  int a[n]; for(int i=0;i<n;i++) cin>>a[i];
  int mx=0,mn=n;
  for(int i=0;i<n;i++) mx=max(mx,a[i]), mn=min(mn,a[i]);

  if (mx-mn >= 2) {
    cout<<"No"<<endl; return 0;
  } else if (mx-mn == 0) {
    if (a[0]==n-1 || n/2 >= a[0]) {
      cout<<"Yes"<<endl; return 0;
    } else {
      cout<<"No"<<endl; return 0;
    }
  } else if (mx-mn == 1) {
    int mxx=0;
    for(int i=0;i<n;i++) {
      if (a[i]==mx) mxx++;
    }
    if (mxx == 1) {
      cout<<"No"<<endl; return 0;
    }
    if ((n-mxx) <= mn && mx <= (n-mxx) + (mxx/2)) {
      cout<<"Yes"<<endl; return 0;
    } else {
      cout<<"No"<<endl; return 0;
    }
  }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <unordered_map>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A,B,C;
    cin >> A >> B >> C;
    if(A % 2 == 0 || B % 2 == 0 || C % 2 == 0){
        print(0);
        return 0;
    }
    print(min(A*B, min(B*C, C*A)));

    

}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const int MOD = 1000000007;

int main() {
  int n, dis;
  cin >> n;
  dis = 200 * (n / 15);
  cout << 800 * n - dis << endl;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }
int main()
{
    int N; cin >> N;
    map<int, int> M;
    for (int i = 0; i < N; i++) {
        int a; cin >> a;
        M[a]++;
    }
    if (N % 3) {
        if (M.size() == 1 && M.begin()->first == 0) {
            yes();
        }
    } else {
        if (M.size() == 1 && M.begin()->first == 0) {
            yes();
        }
        if (M.size() == 3) {
            auto it = M.begin();
            int a = it->first, na = it->second;
            ++it;
            int b = it->first, nb = it->second;
            ++it;
            int c = it->first, nc = it->second;
            if ((a ^ b) == c && na == nb && nb == nc) yes();
        }
        if (M.size() == 2 && M[0] == N/3) {
            yes();
        }
    }
    no();
    return 0;
}


Measured memory_bytes: 3840
#include<algorithm>
#include<climits>
#include<cmath>
#include<deque>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

int f(const string &s, unordered_map<char, int> &mp){
    stack<int> st;
    rrep(i, s.size()){
        if(s[i] == '[' || s[i] == ']'){
            continue;
        }
        if('a' <= s[i] && s[i] <= 'd'){
            st.push(mp[s[i]]);
        }else if(s[i] == '+'){
            int a = st.top();
            st.pop();
            int b = st.top();
            st.pop();
            st.push(a | b);
        }else if(s[i] == '*'){
            int a = st.top();
            st.pop();
            int b = st.top();
            st.pop();
            st.push(a & b);
        }else{
            int a = st.top();
            st.pop();
            int b = st.top();
            st.pop();
            st.push(a ^ b);
        }
    }

    return st.top();
}

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

    string s, p;
    while(cin >> s >> p){
        unordered_map<char, int> mp;
        rep(i, 4){
            mp['a' + i] = p[i] - '0';
        }

        int myHash = f(s, mp);

        int cnt = 0;
        rep(a, 10){
            mp['a'] = a;
            rep(b, 10){
                mp['b'] = b;
                rep(c, 10){
                    mp['c'] = c;
                    rep(d, 10){
                        mp['d'] = d;
                        if(f(s, mp) == myHash){
                            ++cnt;
                        }
                    }
                }
            }
        }

        cout << myHash << " " << cnt << endl;
    }

    return 0;
}


Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
int n,w;
long a[101][2];
long dp[101][100001];

long solve(int n, int w)
{   //cout<<n<<" "<<w<<endl;
    if(w<0) return (-a[n+1][1]-1);
    if(n==1){
    if(a[1][0]<=w) { dp[1][w] = a[1][1];} else dp[1][w]= 0;//-a[n+1][1]-1; 
    return dp[1][w];} //basecase
    if(dp[n][w]) return dp[n][w];
    else 
        {
            dp[n][w] = max(solve(n-1,w), solve(n-1,w-a[n][0])+a[n][1]);
            return dp[n][w];
        }
}
 
 
int main() {
	// your code goes here
    cin>>n>>w;
    for(int i=1;i<=n;++i)
        cin>>a[i][0]>>a[i][1];
     cout<<solve(n,w);
    /*for(int i=1;i<=n;++i){
        for(int j=1;j<=w;++j){
            cout<<dp[i][j]<<" ";
        }
        cout<<endl;
    }*/
   
    
}

Measured memory_bytes: 77312
# coding: utf-8
# Your code here!
S=input()

ans = "WA"

#for i in S:
#    print(i.isupper())
#print(S[2:-1])

if S[0] == "A":
#    print("1ok")
    d=0
    for j in S[2:-1]:
        if j == "C":
            d+=1
    if d == 1:
#        print("2ok")
        c=0
        for i in S:
            if i.isupper() == True:
                c+=1
        if c == 2:
            ans = "AC"
#            print("3ok")
        
print(ans)

Measured memory_bytes: 3060
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
#from collections import defaultdict
#d = defaultdict(int)
#import fractions
#import math
#import collections
#from collections import deque
#from bisect import bisect_left
#from bisect import insort_left
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
#import itertools
#import heapq
#import numpy as np
#INF = float("inf")
def primes(n):#nまでの素数を列挙0は入れちゃダメ
    is_prime = [True]*(n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2,int(n**(0.5)+1)):
        if not is_prime[i]:
            continue
        for j in range(i*2,n+1,i):
            is_prime[j] = False
    return is_prime
prime = primes(10**5)
li = [0]*(10**5)
for i in range(3,10**5,2):
    n = int((i-1)/2)
    if prime[i] and prime[int((i+1)/2)]:
        li[n] = li[n-1]+1
    else:
        li[n] = li[n-1]
Q = int(input())
for _ in range(Q):
    l,r = map(int,input().split())
    ln = int((l-1)/2)
    rn = int((r-1)/2)
    if ln == 0:
        print(li[rn])
    else:
        print(li[rn]-li[ln-1])

Measured memory_bytes: 5432
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    cin>>n>>k;
    vector<int> d(k);
    for(int i=0;i<k;i++)cin>>d[i];
    map<int,bool> m;
    for(int i=0;i<k;i++)m[d[i]]=true;
    for(;;n++){
        int x=n;
        bool b=true;
        while(x){
            int y=x%10;
            if(m[y])b=false;
            x/=10;
        }
        if(b){
            cout<<n<<endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
#define INF 0x3f3f3f3f
#define mod 1000000009
#define e  2.718281828459045
#define eps 1.0e18
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define memset(x,y) memset(x,y,sizeof(x))
#define lson i << 1,l,m
#define rson i << 1 | 1,m + 1,r
#define ll long long
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	map <string,int> mp;
	int n;
	cin>>n;
	int maxn=0;
	while(n--){
		string s;
		cin>>s;
		mp[s]++;
		maxn=max(maxn,mp[s]);
	}
	map<string,int>::iterator it;
		it = mp.begin();
		while(it != mp.end())
		{
			if(it->second ==  maxn){
				cout<<it->first<<endl;
			}
			it++;
		}
	return 0;
}


Measured memory_bytes: 23808
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  vector<int> a(5);
  while(cin>>a[0]){
    char d;
    string ans;
    rep(i,4)cin>>d>>a[i+1];
    sort(all(a));
    int co=1;
    rep(i,4)if(a[i]!=a[i+1])co++;
    if(a[0]==a[3]||a[1]==a[4])ans="four card";
    else if((a[0]==a[2])&&(a[3]==a[4])||(a[2]==a[4])&&(a[0]==a[1]))ans="full house";
    else if((a[0]==a[2])||(a[1]==a[3])||(a[2]==a[4]))ans="three card";
    else if(co==3)ans="two pair";
    else if(co==4)ans="one pair";
    else if((a[4]-a[0]==4)||(a[1]-a[0]==9)||(a[4]-a[3]==9))ans="straight";
    else ans="null";
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,count=0; cin >> N;
  vector<int> p(N);
  for(int i=0; i<N; i++) cin >> p[i];
  for(int i=0; i<N; i++) {
    if(p[i] != i+1) count++;
  }
  if(count<=2) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 3632
a=[list(map(int,input().split())) for _ in range(3)]
n=int(input())
b=list(int(input()) for _ in range(n))

for i in range(3):
    for j in range(3):
        for k in range(n):
            if a[i][j]==b[k]:
                a[i][j]=0
                
for i in range(3):
    if a[i][0]+a[i][1]+a[i][2]==0 or a[0][i]+a[1][i]+a[2][i]==0:
        print('Yes')
        exit()
if a[0][0]+a[1][1]+a[2][2]==0 or a[0][2]+a[1][1]+a[2][0]==0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<functional>
#include<math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pf(n) printf("%lld\n",n)
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1001001001;
const double PI = acos(-1);


int main() {
	ll a;
	string b;
	cin >> a >> b;

	ll ans = a * (b[0] - '0');
	ll k = (b[2] - '0') * 10 + (b[3] - '0');
	ans += (a*k) / 100;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<61;
const ll mod=1e9+7;

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

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

ll calc(ll t,ll u){
    ll r=t;
    ll ans=1;
    for(int i=0;i<=30;i++){
        if((u>>i)&1) {
            ans*=r;
            ans%=mod;
        }
        r=r*r%mod;
    }
    return ans;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll i,j;
    ll n,k;
    cin>>n>>k;
    ll ans=0;
    VI v(k+1,0);
    for(i=k;i>=1;i--){
        v[i]=calc(k/i,n);
        for(j=2;i*j<=k;j++){
            v[i]+=mod-v[i*j];
            if(v[i]>=mod) v[i]-=mod;
        }
        ans+=i*v[i];
        ans%=mod;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3992
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const long long INF = 1LL << 60;

int main(){
    int N;
    long long A, B;
    cin >> N >> A >> B;
    vector<int> pos(N);
    for(int i=0;i<N;i++){
        int p; cin >> p;
        pos[p-1] = 2*i+1;
    }
    vector<long long> dp(2*N+1, INF);
    for(int i=0;i<pos[0];i+=2) dp[i] = B;
    dp[pos[0]] = 0;
    for(int i=pos[0]+1;i<=2*N;i+=2) dp[i] = A;
    for(int i=1;i<N;i++){
        long long best = INF;
        for(int j=0;j<=2*N;j++){
            best = min(best, dp[j]);
            if(j%2 == 0){
                auto c = (j < pos[i] ? B : A);
                dp[j] = best + c;
            } else if(j == pos[i]){
                dp[j] = best;
            } else {
                dp[j] = INF;
            }
        }
    }
    cout << *min_element(dp.begin(), dp.end()) << endl;
}

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

int main() {
    int N, Y;
    cin >> N >> Y;

    for (int i = 0; i <= N; i++) {
        for (int j = 0; j <= N - i; j++) {
            if (Y == 10000 * i + 5000 * j + 1000 * (N - i - j)) {
                cout << i << ' ' << j << ' ' << N - i - j << endl;
                return 0;
            }
        }
    }

    cout << "-1 -1 -1" << endl;
    return 0;
}

Measured memory_bytes: 3584
#include <stdio.h>
int main () {
	int i, j, flag, A[100], N, x, c = 0;

	scanf ( "%d", &N);
	for ( i = 0; i < N; i++ ) {
		scanf ( "%d", &A[i]);
	}
	
	flag = 1;
	while ( flag ) {
	flag = 0;
		for ( j = N-1; j >= 1; j-- ) {
			if ( A[j] < A[j-1] ) {
				x = A[j];
				A[j] = A[j-1];
				A[j-1] = x;
				flag = 1;
				c++;
			}
		}
	}
	for ( i = 0; i < N-1; i++){
		printf ( "%d ",A[i]);
	}
	printf ( "%d\n%d\n", A[N-1], c);

	return 0;
}


Measured memory_bytes: 2136
N, M, C = map(int, input().split())
B = [int(s) for s in input().split()]

cnt = 0
for _ in range(N):
    A = [int(s) for s in input().split()]

    r = 0
    for i in range(M):
        r += A[i] * B[i]
    r += C

    if r > 0:
        cnt += 1

print(cnt)


Measured memory_bytes: 38512
# コピペ
# https://harutech.hateblo.jp/entry/2019/02/10/202515
# FPSゲーマーが惰性で競プロをするブログ    2019-02-10 

import numpy as np

n, k = map(int, input().split())
h = np.array([0] + list(map(int, input().split()))) # index調整
dp = np.zeros(n+1,dtype=np.int)

for i in range(2,n+1):
    start = max(1,i-k)
    dp[i] = min(dp[start:i]+np.abs(h[i]-h[start:i])) # ここがリストなら連結になります
print(dp[n])

Measured memory_bytes: 22916
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#define ll long long
using namespace std;
bool visit[1005];
int st,stack[10050];
vector<int>side[1005];
int n,m,cnt,ans=1e9+1000,data[1005];
void dfs(int now){
//	cout<<now<<endl;
	stack[++cnt]=now;visit[now]=1;
	for(int i=0;i<side[now].size();i++){
		if(cnt>=ans){cnt--;return;}
		int v=side[now][i];
		if(v==st&&cnt<ans){
				ans=cnt;
				for(int j=cnt;j>=1;j--){data[j]=stack[j];if(stack[j]==v)break;}
				cnt--;
				return;
		}
		if(visit[v])continue;
		dfs(v);
	}
	cnt--;
}
int main(){
	ios::sync_with_stdio(0);
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		int u,v;cin>>u>>v;
		side[u].push_back(v);
	}
	for(int i=1;i<=n;i++){
		cnt=0;memset(visit,0,sizeof(visit));
		st=i;dfs(i);
	}
	if(ans<1e9){
		cout<<ans<<endl;
		for(int i=1;i<=ans;i++)cout<<data[i]<<endl;
		return 0;	
	}
	cout<<"-1";
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <map>
#include <iomanip>

using namespace std;

void solve(){
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    for(int i=0; i<m; i++) cin >> a[i];
    long long sum = accumulate(a.begin(), a.end(), 0);
    if(sum > n)
        cout << -1 << endl;
    else
        cout << n - sum << endl;
}

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(16);
    
    solve();

    return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define int long long

int sumofdigits(int x) {
  int sum = 0;
  while (x > 0) {
    sum += x % 10;
    x /= 10;
  }
  return sum;
}

signed main() {
  int w, h, n;
  std::cin >> w >> h >> n;
  std::vector<int> z(w*h, 1);
  
  int xi, yi, ai;
  for (int i = 0; i < n; i++) {
    std::cin >> xi >> yi >> ai;
    switch (ai) {
        case 1:
          for (int x = 0; x < xi; x++) {
            for (int y = 0; y < h; y++) {
              z.at(x + w * y) = 0;
            } 
          }
          break;
        case 2:
          for (int x = xi; x < w; x++) {
            for (int y = 0; y < h; y++) {
              z.at(x + w * y) = 0;
            } 
          }
          break;
        case 3:
          for (int y = 0; y < yi; y++) {
            for (int x = 0; x < w; x++) {
              z.at(x + w * y) = 0;
            } 
          }
          break;
        case 4:
          for (int y = yi; y < h; y++) {
            for (int x = 0; x < w; x++) {
              z.at(x + w * y) = 0;
            } 
          }
          break;
    }
  }
  
  int sum = 0;
  for (int i = 0; i < w*h; i++) {
    sum += z.at(i);
  }
  std::cout << sum << '\n';
  
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000, boost::int128_type>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }
template<class T> inline bool isSosuu(const T& n) { if (n == T(1)) { return false; } for (T i = 2; i*i <= n; ++i) { if (n % i == 0) { return false; } } return true; }
template<class T> vector<vector<T>> split (const vector<T>& S, T delim) { vector<vector<T>> ret{}; vector<T> buff{}; for (auto c : S) { if (c == delim) { if (!buff.empty()) ret.push_back(buff); buff.clear(); } else { buff.push_back(c); } } if (!buff.empty()) ret.push_back(buff); return ret; }
template<class T> inline void printYesNo(const T& t) { cout << (t ? "Yes" : "No") << CRLF; }
template<class T = int64_t> T modpow(T N, T P, T M) { T ret{1}; N %= M; while (P) { if (P & 0x01) { ret *= N; ret %= M; } P >>= 1; N *= N; N %= M; } return ret; }

/** code for assert debug begin */
int gErr = 0;
#define ASSERT(p) if(!(p)){ gErr = 1; }else{ ; }
/** code for assert debug end */

struct Tmp
{
public:
  int N;
  Tmp(int N)
  : N(N)
  {}
};

void solve(void)
{
  vector<int> group(13);
  group[1] = group[3] = group[5] = group[7] = group[8] = group[10] = group[12] = 1;
  group[4] = group[6] = group[9] = group[11] = 2;
  group[2] = 3;
  int x, y; cin >> x >> y;
  auto ans = group[x] == group[y];
  cout << (ans ? "Yes" : "No") << CRLF;
  return;
}

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

  solve();

  return 0;
}


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

int main(){
	string s,t;
	cin>>s>>t;
	int hit=0;
	for(int i=0; i<s.length(); i++)
	{
		if(s[i]!=t[i])
		{
			hit++;
		}
	}
	cout<<hit<<endl;
}

Measured memory_bytes: 3916
import sys
import math

input = sys.stdin.readline

n, d = map(int, input().split())
x = [list(map(int, input().split())) for i in range(n)]
ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        t = 0
        for l in range(d):
            y = x[i][l]
            z = x[j][l]
            t += (y - z) ** 2
        if math.sqrt(t).is_integer():
            ans += 1
print(ans)


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

int main() {
	int64_t a, b; cin >> a >> b;
	if(a == b) {
		cout << 1 << '\n';
		return 0;
	}
	int64_t x;
	for(int64_t i = 60; i >= 0; --i) {
		if(b >> i & 1) {
			if(not (a >> i & 1)) {
				int64_t msk = (1ll << (i + 1)) - 1;
				a &= msk;
				b &= msk;
				x = (1ll << i);
				break;
			}
		}
	}
	int64_t y = 0;
	for(int64_t msk = (x >> 1ll); msk > 0; msk >>= 1ll) {
		if(b & msk) {
			y = msk;
			break;
		}
	}
	y = (y == 0 ? 1 : y << 1ll);
	int64_t ans = x - a;
	if(x + y < x + a) {
		ans += y;
		ans += (x << 1ll) - (x + a);
	} else {
		ans += (x << 1ll) - x;
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
f = int(input())
x = a + b + c + d + e + f
y = 100000
for i in (a,b,c,d):
    if y > i : y = i
z = 0
if e < f : z = e
else : z = f
print (x - y - z)


Measured memory_bytes: 5592
#include <stdio.h>
#include <iostream>
using namespace std;
struct node{
    node* nxt;
    node* last;
    int val;
    node(node *a,node* b,int n){
        val=n;
        nxt=a;
        last=b;
    }
    node(int n){
        nxt=last=nullptr;
        val=n;
    }
};
int main(){
    int n,inp;
    string s;
    bool first=true;
    node *begin=new node(-1),*end=new node(-1),*temp=nullptr;
    begin->nxt=end;
    end->last=begin;
    scanf("%d",&n);
    while(n--){
        cin>>s;
        if(s[0]=='i'){
            scanf("%d",&inp);
            temp=begin->nxt;
            begin->nxt=new node(inp);
            begin->nxt->nxt=temp;
            temp->last=begin->nxt;
            begin->nxt->last=begin;
        }
        else if(s.size()<9){
            scanf("%d",&inp);
            temp=begin->nxt;
            while(temp!=end){
                if(temp->val==inp){
                    temp=temp->nxt;
                    temp->last=temp->last->last;
                    delete temp->last->nxt;
                    temp->last->nxt=temp;
                    break;
                }
                else temp=temp->nxt;
            }
        }
        else if(s[6]=='F'){
            begin->nxt=begin->nxt->nxt;
            delete begin->nxt->last;
            begin->nxt->last=begin;
        }
        else{
            end->last=end->last->last;
            delete end->last->nxt;
            end->last->nxt=end;
        }
    }
    temp=begin->nxt;
    while(temp!=end){
        if(first)first=false;
        else printf(" ");
        printf("%d",temp->val);
        temp=temp->nxt;
    }
    printf("\n");
}


Measured memory_bytes: 34468
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

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)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

const int MAX = 1e5 + 10;
int N;
PLL ab[MAX];
bool used[MAX];

int main(void) {
    cin >> N;
    REP(i, N) {
        cin >> ab[i].first >> ab[i].second;
    }
    priority_queue<pair<LL, pair<PLL, int>>> taka, ao;
    REP(i, N) {
        taka.push(MP(ab[i].first + ab[i].second, MP(ab[i], i)));
        ao.push(MP(ab[i].first + ab[i].second, MP(ab[i], i)));
    }
    LL taka_sum = 0, ao_sum = 0;
    REP(i, N) {
        auto &now = (i % 2 == 0 ? taka : ao);
        while (!now.empty()) {
            auto el = now.top();
            now.pop();
            if (used[el.second.second]) continue;
            used[el.second.second] = true;
            DEBUG(el.second.second)
            if (i % 2 == 0) {
                taka_sum += el.second.first.first;
            } else {
                ao_sum += el.second.first.second;
            }
            break;
        }
    }
    DEBUG(taka_sum)
    DEBUG(ao_sum)
    cout << taka_sum - ao_sum << endl;
}


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

int main() {
	ll n, k, s;
	cin >> n >> k >> s;
	for (int i = 0; i < k; i++) {
		if (i == 0)cout << s;
		else cout << " " << s;
	}
	for (int i = 0; i < n - k; i++) {
		if (s == 1000000000)cout << " " << 99999999;
		else cout << " " << 1000000000;
	}
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 998244353

using namespace std;
using ll = long long;
using ldb = long double;

int main() {
    string S; cin >> S;
    string abc = "ABC";
    if (S == abc) cout << "ARC" << endl;
    else cout << "ABC" << endl;
}


Measured memory_bytes: 3620
var readable = process.stdin;
readable.resume();
readable.setEncoding( 'utf-8' );
readable.on( 'data', function( chunk ) {
   var data = chunk.split( ' ' );
   var a = parseInt( data[0] );
   var b = parseInt( data[1] );
   
  console.log( a*b + ' ' + (a+b)*2 );
} )

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

using namespace std;

queue<int> q;

int main()
{
  int n,i,rem=0;
  long long ans=0;

  scanf("%d",&n);
  for(int c=0;c<n;c++)
  {
    scanf("%d",&i);
    while(!q.empty()&&(rem&i))
    {
      rem^=q.front();
      q.pop();
    }
    q.push(i);
    rem^=i;
    ans+=q.size();
  }
  printf("%lld\n",ans);
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define foi(i,k,n) for(int i = (int)k; i < (int)n; ++i)
using namespace std;
typedef long long ll;
const int MAXN = 5 + 100;
const int MAXK = 5 + 100000;
const int MOD = 7 + 1000000000;
int N, K;
int arr[MAXN], dp[MAXN][MAXK];

void add(int& p, const int& q) { /// p = (p + q) % MOD
    assert(p >= 0 && p < MOD);
    assert(q >= 0 && q < MOD);
    p += q;
    if(p >= MOD) p -= MOD;
}

void sub(int& p, const int& q) { /// p = (p - q + MOD) % MOD
    assert(p >= 0 && p < MOD);
    assert(q >= 0 && q < MOD);
    p -= q;
    if(p < 0) p += MOD;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    cin >> N >> K;
    foi(i,0,N) {
        cin >> arr[i];
    }
    for(int i = 0; i <= K; ++i) {
        dp[N][i] = 1;
    }
    for(int i = N - 1; i >= 0; --i) {
        for(int j = 0; j <= K; ++j) {
            dp[i][j] = dp[1 + i][j];
            if(j > min(j,arr[i])) {
                sub(dp[i][j], dp[1 + i][j - min(j, arr[i]) - 1]);
            }
            if(j) {
                add(dp[i][j], dp[i][j - 1]);
            }
        }
    }
    if(K > 0) {
        sub(dp[0][K], dp[0][K - 1]);
    }
    cout << dp[0][K] << '\n';
    return 0;
}


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

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

    int n;
    cin >> n;
    string s, t;
    cin >> s;
    ll ans = 1, mod = 1e9 + 7;
    rep(i, 0, n) t += "BW";
    vector<int> l(2 * n), r(2 * n), d(2 * n);
    rep(i, 0, 2 * n) {
        if (i) {
            l[i] = l[i - 1];
            r[i] = r[i - 1];
        }
        if (t[i] == s[i])
            l[i]++;
        else
            r[i]++;
        d[i] = (t[i] != s[i]);
        if (l[i] < r[i]) {
            cout << 0 << endl;
            return 0;
        }
    }
    if (l[2 * n - 1] != r[2 * n - 1]) {
        cout << 0 << endl;
        return 0;
    }
    ll c = 0;
    rep(i, 0, 2 * n) if (d[i]) {
        ans = ans * (l[i] - c) % mod;
        c++;
    }
    for (ll i = 1; i <= n; i++) {
        ans = ans * i % mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3220
package main

import (
	"fmt"
	"strings"
)

type Player struct {
	i     int
	cards []string
	name  string
}

func (p *Player) Finished() bool {
	if p.i >= len(p.cards) {
		return true
	}
	return false
}

func main() {
	var sa, sb, sc string
	fmt.Scanf("%s", &sa)
	fmt.Scanf("%s", &sb)
	fmt.Scanf("%s", &sc)

	a := Player{name: "A", cards: strings.Split(sa, "")}
	b := Player{name: "B", cards: strings.Split(sb, "")}
	c := Player{name: "C", cards: strings.Split(sc, "")}

	var card string
	var order Player
	for {
		if card != "" {
			if card == "a" {
				order = a
			} else if card == "b" {
				order = b
			} else {
				order = c
			}

			if order.Finished() {
				fmt.Println(order.name)
				break
			}
		}

		if card == "" {
			card = a.cards[0]
			a.i = a.i + 1
		} else if card == "a" {
			card = a.cards[a.i]
			a.i = a.i + 1
		} else if card == "b" {
			card = b.cards[b.i]
			b.i = b.i + 1
		} else {
			card = c.cards[c.i]
			c.i = c.i + 1
		}
	}
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(void){
    
  int m,f,b,a;
  cin>>m>>f>>b;
  
  a=b-m;
  if(a<=0){
      cout<<"0"<<endl;
  }
  else if(a>0&&a<=f){
      cout<<a<<endl;
  }
  else{
      cout<<"NA"<<endl;
  }
  
  
  
}


Measured memory_bytes: 3096