akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

   typedef long long ll;
   typedef pair<ll, ll> Pii;
   typedef vector<ll> Vi;
   typedef vector<Vi> VVi;

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define RSORT(x) sort((x).rbegin(), (x).rend())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
   template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

   ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
   ll pow(ll a, ll b){if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a;}
   ll pow(ll a, ll b, ll m){if (b == 0) return 1; else if (a == 0) return 0; else if (b % 2 == 0) return (pow((a * a) % m, b / 2, m) % m); else return (pow((a * a) % m, b / 2, m) * a) % m;}
   ll residue(ll a, ll m){return ((a % m) + m) % m;};

   ll dx[4]={1,0,-1,0};
   ll dy[4]={0,1,0,-1};
const ll MAX_N = 30, MAX_M = 30;
ll cnt[MAX_M + 1] = {};
int main(){
   ll N, M; cin >> N >> M;
   REP(i, N){
      ll k; cin >> k;
      REP(j, k){
         ll a; cin >> a; cnt[a]++;
      }
   }
   ll ans = 0;
   REP(i, M) ans += (cnt[i + 1] == N);
   cout << ans << endl;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, a, n) for (int i = a; i < n; i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eps 1e-15

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef tuple<int, int, int> ti3;

int main()
{
    /* S/2円を払えるか？ */
    int n;
    scanf("%d", &n);

    if (n == 1) {
        printf("Hello World\n");
        return 0;
    }
    int a, b;
    scanf("%d %d", &a, &b);
    printf("%d\n", a + b);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
int main() {
	int n,a, b;
 
	std::cin >>n>> a >> b;
 
	if (n*a >=b) {
		std::cout <<b<< std::endl;
	}
	else {
		std::cout <<n*a << std::endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c;
    int num;
    
    cin >> a >> b >> c;
    
    if(a > b)
    {
        num = b;
        b = a;
        a = num;
    }
    
    if(b > c)
    {
        num = c;
        c = b;
        b = num;
    }
    if(a > b)
    {
        num = b;
        b = a;
        a = num;
    }
    
    cout << a << " " << b << " " << c << endl;
    
    return 0;
    
}



Measured memory_bytes: 3092
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int main()
{
    int n;
    char s;
    while(scanf("%d",&n)!=EOF){
        int p=0,w=0,g=0,y=0;
        getchar();
        for(int i=0;i<n;i++){
            scanf("%c",&s);
            getchar();
            if(s=='P') p=1;
            else if(s=='W') w=1;
            else if(s=='G') g=1;
            else if(s=='Y') y=1;
        }
        if(p==1&&w==1&&g==1&&y==1){
            printf("Four\n");
        }
        else {
            printf("Three\n");
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <complex>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 60;

int main() {
  //
  ll d;
  cin >> d;
  if (d == 25)
    cout << "Christmas" << endl;
  else if (d == 24)
    cout << "Christmas Eve" << endl;
  else if (d == 23)
    cout << "Christmas Eve Eve" << endl;
  else
    cout << "Christmas Eve Eve Eve" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
#define ll long long

int d = 365;
vector<vector<int>> s(d+1, vector<int>(26+1, 0));
vector<int> c(26+1);
vector<int> t(d);

ll calc(ll v, int d, int j, vector<ll> last) {
    ll tmp = v;
    ll p = 0;
    last[j] = d;
    for(int i = 0; i < 26; i++) {
        tmp -= c[i]*(d-last[i]);
        p -= c[i]*(d-last[i]);
    }
    //return tmp-v;
    p += s[d-1][j];
    return p;
    //return tmp;
}

void init() {
    cin >> d;
    for(int i = 0; i < 26; i++) cin >> c[i];
    for(int i = 0; i < d; i++) {
        for(int j = 0; j < 26; j++) {
            cin >> s[i][j];
        }
    }
    return;
}

int main() {
    init();
    /////////////////
    vector<int> t(d, 1);
    //vector<ll> ans(d, 0);
    vector<ll> last1(26+1, 0), last2(26+1, 0);
    vector<ll> last(26+1, 0);
    ll v = 0;
    ll tmp1 = 0, tmp2 = -1;
    ll ans = 0;
    for(int i = 0; i < d; i++) {
        //v += s[i][t[i]-1];
        //last[t[i]-1] = i+1;
        for(int j = 0; j < 26; j++) {
            //ans[i] -= c[j]*((i+1)-last[j]);
            //t[i] = j+1;
            last1[j] = i+1; // d
            tmp1 = calc(v+s[i][j], (i+1), (j), last);
            if(tmp2 < tmp1) {
                tmp2 = tmp1;
                last1 = last2;
                last2[j] = i+1;
                t[i] = j+1;
                last[j] = i+1;
            }
            // v -= c[j]*((i+1)-last[j]);
        }
        last1 = last2;
        v += (tmp2-v);
        ans += tmp2;
        tmp1 = 0, tmp2 = 0;
        //cout << "v: " << v << endl;
    }
    
    for(int i = 0; i < d; i++) {
        //cout << "i: " << i << " " << t[i] << endl;
        cout << t[i] << endl;
    }
    //cout << ans << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl

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

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

    // input
    int N, K;
    cin >> N >> K;

    map<int, int> mp;
    FOR(i, 0, N){
        int a;
        cin >> a;
        mp[a]++;
    }

    if(mp.size() <= K){
        p(0);
        return 0;
    }
    
    int cutNum = mp.size() - K;
    vector<int> V;
    for(auto p : mp){
        int count = p.second;
        V.push_back(count);
    }    
    sort(ALL(V));

    ll answer = 0;
    FOR(i, 0, cutNum){
        answer += V[i];
    }

    p(answer);

    return 0;
}

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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll A[200005];
//! 点iから右/左に進んで点iに戻ってくる時の最小値
ll LE[200005];
ll RE[200005];

//! 点iから右/左に進んで戻ってこない時の最小値
ll LO[200005];
ll RO[200005];

int main()
{
    ll N;
    cin >> N;
    REP(i, N)
    {
        cin >> A[i];
    }
    {
        ll sum = 0;
        LE[0] = 0;
        FOR(i, N + 1, 1)
        {
            sum += A[i - 1];
            ll t = A[i - 1] % 2;
            if (A[i - 1] == 0)
                t = 2;
            LE[i] = std::min(LE[i - 1] + t, sum);
        }
    }

    {
        ll sum = 0;
        RE[N] = 0;
        for (int i = N - 1; i >= 0; --i)
        {
            sum += A[i];
            ll t = A[i] % 2;
            if (A[i] == 0)
                t = 2;
            RE[i] = std::min(RE[i + 1] + t, sum);
        }
    }
    LO[0] = 0;
    FOR(i, N + 1, 1)
    {
        ll t = 1 - (A[i - 1] % 2);
        LO[i] = std::min(LO[i - 1] + t, LE[i - 1] + t);
    }
    RO[N] = 0;
    for (int i = N - 1; i >= 0; --i)
    {
        ll t = 1 - (A[i] % 2);
        RO[i] = std::min(RO[i + 1] + t, RE[i + 1] + t);
    }

    ll min = INF;
    REP(i, N + 1)
    {
        //cout << i << ":" << LE[i] << ":" << LO[i] << ":" << RE[i] << ":" << RO[i] << endl;
        //! 右に行ってから左に行く
        ll m0 = RE[i] + std::min(LE[i], LO[i]);
        min = std::min(min, m0);
        //! 左に行ってから右に行く
        ll m1 = LE[i] + std::min(RE[i], RO[i]);
        min = std::min(min, m1);
    }
    cout << min << endl;
    return 0;
}

Measured memory_bytes: 8064
str = gets.chomp
n = gets.to_i
 
for i in 1..n
  order = gets.chomp.split
  a = order[1].to_i
  b = order[2].to_i
 
 if order[0] == "print"
  puts str[a..b]
 elsif order[0] == "reverse"
  str[a..b] = str[a..b].reverse
 elsif order[0] == "replace"
  str[a..b] = order[3]
  end
end


Measured memory_bytes: 6916
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
       
        // 配列
        int a = 0;
        for(int i=0;i<m;i++){
            a += sc.nextInt();
        }
        
        if(a > n){
            System.out.println("-1");
        } else {
            System.out.println(n - a);
        }
    }
}


Measured memory_bytes: 46180
#include<stdio.h>

int main(){

  char s[5];
  int i;

  for(i=0;i<=4;i++){
    scanf("%s",&s[i]);}

  if(s[2]==s[3]&&s[4]==s[5]){
    printf("Yes");
  }
  else{
    printf("No");
  }
}


Measured memory_bytes: 128
n=int(input())
B=list(map(int,input().split()))
A=[]
a=0
for i in range(n):
  if i==0:
    a=B[i]
  elif i<n-1:
    a=min(B[i-1],B[i])
  else:
    a=B[-1]
  A.append(a)
print(sum(A))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i, n) for (int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"
#define fcout cout << fixed << setprecision(18)

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926535
/*
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
*/
#define ll long long int         // 10^18
#define INF 1000000001           // 1e9+1
#define LINF 1000000000000000001 // 1e18+1

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

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

    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    
    ll a,b,c,mn;cin>>a>>b>>c;
    if(a%2==1 && b%2==1 && c%2==1){
        mn = min(a*b, min(b*c, c*a));
    }else{
        mn = 0;
    }
    P(mn);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <cassert>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>

#define rep(i, l, r) for (ll i = (l); i <= (r); i++)
#define irep(i, r, l) for (ll i = (r); i >= (l); i--)
#define vec(t) vector<int>

using namespace std;
using ll = long long;
using veci = vec(int);
using vecll = vec(ll);

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

    veci A(6);
    rep(i, 0, 5) cin >> A[i];

    if (A[4] - A[0] > A[5])
        cout << ":(\n";
    else

        cout << "Yay!\n";
}

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

int main()
{
	int64_t n, k;
	cin >> n >> k;

	if (n == 0 || k == 1)
	{
		cout << 0 << endl;

		return 0;
	}

	cout << min(n % k, k - n % k) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
#define rep(i,n) for (ll i = 0; i < (ll)(n); ++i)
#define rrep(i,j,n) for(ll i = (ll)(j); i < (ll)(n); i++)
#define mrep(i,n) for (ll i = (ll)(n-1); i >= 0; i--)
#define be(v) (v).begin(), (v).end()
#define dcout cout << fixed << setprecision(20) 
ll INF = 1LL << 60;
ll mod = 1e9 + 7;

int main() {
	int a,b,c,d; cin >> a >> b >> c >> d;
	if(abs(a-c)<=d) {
		cout << "Yes" << endl;
		return 0;
	}
	else if(abs(a-b)<=d&&abs(b-c)<=d) {
		cout << "Yes" << endl;
		return 0;
	}
	else cout << "No" << endl;
}

Measured memory_bytes: 3584
N, W = map(int, input().split())

v = [0] * (N)
w = [0] * (N)

for i in range(N):
    v[i], w[i] = map(int, input().split())

dp = [-1] * (W + 1)
dp[0] = 0

for i in range(N):
    for j in range(W + 1):
        if dp[j] >= 0 and j + w[i] <= W:
            dp[j + w[i]] = max(dp[j + w[i]], dp[j] + v[i])

ans = 0

for i in range(W + 1):
    ans = max(ans, dp[i])

print(ans)



Measured memory_bytes: 5916
s = gets.chomp
t = gets.chomp
n = t.size
ans = 1001
(s.size - n + 1).times do |i|
  ss = s[i, n]
  d = 0
  n.times do |j|
    d += 1 if ss[j] != t[j]
  end
  ans = d if d < ans
end
puts ans


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n+1);
    rep(i,n+1) cin >> a[i];
    vector<int> b(n);
    rep(i,n) cin >> b[i];

    ll ans = 0;
    rep(i,n) {
        int left = min(a[i], b[i]);
        ans += left;
        a[i] -= left;
        b[i] -= left;

        int right = min(a[i+1], b[i]);
        ans += right;
        a[i+1] -= right;
    }
    cout << ans << endl;
    return 0;
}

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

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

    int evidence[N][N] = {};
    rep(i, N) rep(j, N) evidence[i][j] = -1;

    rep(i, N) {
        int ai, xi, yi;
        cin >> ai;
        rep(j, ai) {
            cin >> xi >> yi;
            evidence[i][xi-1] = yi;
        }
    }

    int MAX_REP = 1, ans = 0;
    rep(i, N) MAX_REP *= 2;
    rep(i, MAX_REP) {
        int honest[N] ={};
        rep(j, N) if (i & (1<<j)) honest[j] = 1; 
        bool exist_ok = true;
        rep(a, N) {
            if (honest[a]) {
                rep(x, N) {
                    if ((evidence[a][x] == 1) 
                         && (evidence[a][x] != honest[x])) exist_ok = false;
                    if ((evidence[a][x] == 0)
                         && (evidence[a][x] != honest[x])) exist_ok = false;
                }
            }
        }

        if (exist_ok) {
            // ans = max(ans, accumulate(honest, honest+N, 0));
            int tmp = 0;
            rep(i, N) tmp += honest[i];
            ans = max(ans, tmp);
        }
    }

    cout << ans << endl;

    return 0;
}



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

using namespace std;

#define mod 1000000007
#define ll long long int
#define mk make_pair
#define pb push_back
#define xx first
#define yy second
#define ar array

double pi=3.141592653589793238;
const int M = 1e9+7;
const int Nmax=5005;
const int MM = 1e7+1;
const int N=200010;

int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int T=1;
//cin>>T;
while(T--){
ll n;
cin>>n;
ll arr[n+1];
for(int i=0;i<n;i++)cin>>arr[i];
ll ans=1000;
for(int i=0;i<n-1;i++){
    ll s=0;
    if(arr[i]<arr[i+1])s=ans/arr[i];
    ans+=((arr[i+1]-arr[i])*s);
}
cout<<ans<<endl;
}
return 0;
}


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


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

  string s;
  cin >> s;
  rep(i,s.size()){
    if(s[i]=='?')cout << 'D';
    else cout << s[i];
  }
  cout << endl;
  
  return 0;
    

}


Measured memory_bytes: 3752
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX = 510000;
const int MOD =  998244353;

  
     signed main(){
     long double n,m,d;
      cin>>n>>m>>d;
     if(d!=0)cout << std::fixed << std::setprecision(15)<<2*(n-d)*(m-1)/(n*n)<<endl;
     else cout << std::fixed << std::setprecision(15)<<(n-d)*(m-1)/(n*n)<<endl;

      }

        

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

int main() {
  int a,b,c,d,e;
  cin>>a;
  b=a/1000;
  c=(a%1000)/100;
  d=(a%100)/10;
  e=a%10;
  if (b == c && c == d){
    cout<<"Yes"<<endl;
  }
 else if(c == d && d == e){
      cout<<"Yes"<<endl;
    }
  else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <queue>
#include<map>
#include<algorithm>
#include<set>
#include<iomanip>
#include<string>
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1; i<=n;i++)
#define rrep(i,n) for(int i = n-1;i >=0;i--)
#define ALL(a) a.begin(),a.end()
#define PI  acos(-1)
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
typedef long long int ll;
typedef long double ld;
const int MOD = 1e9 + 7;
int dx[4] = { 0,0,1,-1 }, dy[4] = { 1,-1,0,0 }, sum = 0;
int main() {
    int n,cnt = 0,r=0,w=0; string s; cin >> n >> s;
    rep(i, n) {
        if (s[i] == 'R')r++;
        else w++;
    }string t;
    rep(i, r) t += 'R';
    rep(i, w)t += 'W';
    rep(i, n) {
        if (s[i] == t[i]) continue;
        cnt++;
    }cout << cnt / 2 << endl;
}

Measured memory_bytes: 3920
import sys
import string
import functools


def count_alphabet(counter, letter):
    if letter.lower() in counter:
        counter[letter.lower()] += 1

    return counter


if __name__ == "__main__":
    sentence = sys.stdin.read()

    alphabet_counter = {}

    for c in string.ascii_lowercase:
        alphabet_counter[c] = 0

    alphabet_counter = functools.reduce(
        count_alphabet,
        sentence,
        alphabet_counter
    )

    for letter, num_contains in alphabet_counter.items():
        print('{c} : {n}'.format(c=letter, n=num_contains))



Measured memory_bytes: 6676
#!/usr/bin/python3

import array
from fractions import Fraction
import functools
import itertools
import math
import os
import sys


def main():
    H, W = read_ints()
    S = [inp() for _ in range(H)]
    print(solve(H, W, S))


def solve(H, W, S):
    o_table = [[0] * W for _ in range(H)]
    for y in range(H):
        c = 0
        for x in range(W - 1, -1, -1):
            if S[y][x] == 'O':
                c += 1
            o_table[y][x] = c

    i_table = [[0] * W for _ in range(H)]
    for x in range(W):
        c = 0
        for y in range(H - 1, -1, -1):
            if S[y][x] == 'I':
                c += 1
            i_table[y][x] = c

    ans = 0
    for y in range(H):
        for x in range(W):
            if S[y][x] == 'J':
                ans += o_table[y][x] * i_table[y][x]

    return ans


###############################################################################
# AUXILIARY FUNCTIONS

DEBUG = 'DEBUG' in os.environ


def inp():
    return sys.stdin.readline().rstrip()


def read_int():
    return int(inp())


def read_ints():
    return [int(e) for e in inp().split()]


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


if __name__ == '__main__':
    main()



Measured memory_bytes: 366772
#include <iostream>
#include <algorithm>
#include <map>

using namespace std;

const int N = 1000;

int n;
pair<int, int> data[N];

int calc(int emp){
  bool dp[N][N+1];
  fill(dp[0], dp[N], false);
  dp[0][0] = true;
  for(int i=0;i<n-1;i++){
    for(int j=0;j<=emp;j++){
      dp[i+1][j] |= dp[i][j];
      if(j+data[i].second <= emp) dp[i+1][j+data[i].second] |= dp[i][j];
    }
  }
  int tmp = 0;
  for(int i=0;i<=emp;i++) if(dp[n-1][i]) tmp = i;
  int res = data[n-1].first * 2;
  for(int i=0;i<n;i++) res += data[i].second;
  return res - tmp;
}

main(){
  while(cin >> n && n){
    for(int i=0;i<n;i++){
      int a, b;
      cin >> a >> b;
      data[i] = make_pair(a, b);
    }
    sort(data, data+n);
    int sum = 0;
    for(int i=0;i<n-1;i++) sum += data[i].first;
    int ans = 0;
    if(sum >= data[n-1].first){
      for(int i=0;i<n;i++) ans += data[i].first + data[i].second;
    }else ans = calc(data[n-1].first - sum);
    cout << ans << endl;
  }
}

Measured memory_bytes: 2148
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    double a, b, x;
    cin >> a >> b >> x;
    const double PI=3.1415926535897932;
    if(x >= a * a * b / 2)
    {
        double z = 2 * (b - (x/(a*a)));
        double aa =  PI / atan(z/a) ;
              printf("%lf", 180.000000000 / aa);
    }
    else
    {
        double y = 2 * x / (a*b);
        double aa = PI / atan(b/y);
        printf("%lf", 180.000000000 / aa);
    }
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        long n=Long.parseLong(sc.next());
        long num[]=new long[5];
        
        for(int i=0;i<5;i++)num[i]=Long.parseLong(sc.next());
        long min=num[0];
        for(int i=0;i<4;i++)min=Math.min(min,num[i+1]);
        long count=0;
        if(n%min==0)count=n/min+4;
        else count=n/min+5;
        System.out.println(count);
    }
}


Measured memory_bytes: 21844
#include <stdio.h>
int main(){
  int a,b,c;
  scanf("%d %d %d", &a, &b, &c);
  if(a >= b){
    if(a < c){
      printf("%d %d %d\n",b,a,c);
    }
    else if(b > c){
      printf("%d %d %d\n",c,b,a);
    }
    else if(a > c && b < c){
      printf("%d %d %d\n",b,c,a);
    }
    else if(a == b){
      if(a > c){
	printf("%d %d %d\n",c,a,b);
      }
      else if(a < c){
	printf("%d %d %d\n",a,b,c);
      }
    }
    else if(b == c){
      if(a > b){
	printf("%d %d %d\n",b,c,a);
      }
      else if(a < b){
	printf("%d %d %d\n",a,b,c);
      }
    }
  }
    else if(a == c){
      if(a < b){
	printf("%d %d %d\n",a,c,b);
      }
      else if(a > b){
	printf("%d %d %d\n",b,a,c);
      }
    }
    else if(a < b){
      if(b < c){
	printf("%d %d %d\n",a,b,c);
      }
      else if(a > c){
	printf("%d %d %d\n",c,a,b);
      }
      else if(b > c && a < c){
	printf("%d %d %d\n",a,c,b);
      }  
    } 
    else{
      printf("%d %d %d\n",a,b,c);
    }
  
  return 0;
}




Measured memory_bytes: 2044
import collections
n = int(raw_input())
p,q = map(int,raw_input().split(' ')), map(int,raw_input().split(' '))
res = []

def perms(i, elems,res):

	if i == len(elems):
		res.append(tuple(elems)) 
		return 
	for j in range(i, len(elems)):
		elems[j], elems[i] = elems[i], elems[j]
		perms(i+1, elems, res)
		elems[j], elems[i] = elems[i], elems[j]

perms(0, range(1, n+1), res)
tp,tq = tuple(p),tuple(q)
res.sort()
for i in range(len(res)):
	if res[i] == tp: ii = i
	if res[i] == tq: jj = i

print abs(jj - ii)

Measured memory_bytes: 45596
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <iomanip>
typedef long long ll;
const int mod=1e9+7;
#define lol(i,n) for(int i=0;i<n;i++)
#define tot(i,n) for(int i=1;i<=n;i++)
using namespace std;
string s;
int main () {
    cin >> s ;
    int a,b,k;
    a=b=0;
  k=s.length();
   for(int i=0;i<k;i++){
        if(s[i]=='0')a++;
        if(s[i]=='1')b++;
    }
    cout << min(a,b)*2<< endl;
}

Measured memory_bytes: 512
//平方数に注意
#include <iostream>
#include <map>
#define int long long
using namespace std;

int mod = 1000000007;
int n, k;
map<int, int> num;

int power(int a, int n) {
	if (n == 0) return 1;
	if (n % 2 == 0) return power((a * a) % mod, n / 2) % mod;
	return (a * power(a, n - 1)) % mod;
}

void setNum(int d) {
	num[d] = power(k, (d + 1) / 2);
	for (int i = 1; i * i <= d; i++) {
		if (d % i != 0) continue;
		if (i != d) {
			if (num.find(i) == num.end()) setNum(i);
			num[d] = (num[d] + mod - num[i]) % mod;
		}
		if (i != d / i && d / i != d) {
			if (num.find(d / i) == num.end()) setNum(d / i);
			num[d] = (num[d] + mod - num[d / i]) % mod;
		}
	}
}

signed main() {
	int i;
	
	cin >> n >> k;
	
	for (i = 1; i * i <= n; i++) {
		if (n % i != 0) continue;
		setNum(i);
		setNum(n / i);
	}
	
	int ans = 0;
	for (map<int, int>::iterator it = num.begin(); it != num.end(); it++) {
		int d = (*it).first;
		int cnt = (*it).second;

		if (d % 2) {
			ans += d * cnt;
		}
		else {
			ans += (d / 2) * cnt;
		}
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		String t = scan.next();
		int s_length = s.length();
		int t_length = t.length();
		String[] s_list = new String[s_length];
		String[] t_list = new String[t_length];
		String message = "No";
		int i = 0;
		for(i = 0; i < s_length; i++) {
			s_list[i] = s.charAt(i) + "";
		}
		for(i = 0; i < t_length; i++) {
			t_list[i] = t.charAt(i) + "";
		}
		Arrays.sort(s_list);
		Arrays.sort(t_list);
		for(i = 0; i < s_length && i < t_length; i++) {
			if(s_list[i].compareTo(t_list[t_length - i - 1]) < 0) {
				message = "Yes";
				break;
			} else if(s_list[i].compareTo(t_list[t_length - i - 1]) > 0) {
				break;
			}
		}
		if(i == s_length || i == t_length) {
			if(s_length < t_length) {
				message = "Yes";
			}
		}
		System.out.println(message);
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;

int main(){
	int N, i;
	scanf("%d", &N);
	vector<double> X(N), Y(N);
	int Xsum = 0, Ysum = 0;
	for(i = 0; i < N; i++){
		scanf("%lf%lf", &X[i], &Y[i]);
		Xsum += X[i];
		Ysum += Y[i];
		X[i] *= N;
		Y[i] *= N;
	}
	if(N % 2 == 1){
		printf("NA\n");
		return 0;
	}
	for(i = 0; i < N / 2; i++){
		if((X[i] + X[i + N / 2]) != 2 * Xsum || (Y[i] + Y[i + N / 2]) != 2 * Ysum){
			printf("NA\n");
			return 0;
		}
	}
	printf("%.10lf %.10lf\n", (double)Xsum / N, (double)Ysum / N);
	return 0;
}


Measured memory_bytes: 3244
module Main where

import Data.Functor
import Data.List

main :: IO()
main = do
  { [w,h,x,y,r] <- getInts
  ; if x < r then putStrLn "No"
    else if y < r then  putStrLn "No"
      else if x + r > w then putStrLn "No"
        else if y + r > h then putStrLn "No"
          else putStrLn "Yes"
  }

getInts :: IO [Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO ()
putInts = putStrLn . unwords . map show

Measured memory_bytes: 3652
from fractions import gcd

A, B, C, D = map(int, input().split())
A -= 1
lcm = int(C*D / gcd(C, D))
nA = A - (A//C + A//D - A//lcm)  
nB = B - (B//C + B//D - B//lcm)
print(nB - nA)

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

int main(){
  
  int N;
  cin >> N;
  string S;
  cin >> S;
  int count=1;
  
  for(int i=0; i<N-1; i++){
  	if(S[i]!=S[i+1]) count++;
  }
  cout << count << endl;
}

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

int main() {
  int N, cnt=0;
  cin >> N;
  vector<int> P(N);
  rep(i, N) cin >> P.at(i);
  rep(i, N-2){
   if((P.at(i)<P.at(i+1) && P.at(i+1)<P.at(i+2)) || (P.at(i)>P.at(i+1) && P.at(i+1)>P.at(i+2))){
     cnt++;
   }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
N = int(input())
TA = [list(map(int, input().split())) for i in range(N)]


t_votes = TA[0][0]
a_votes = TA[0][1]
for n in range(1, N):
    t_ratio = TA[n][0]
    a_ratio = TA[n][1]
    # coeff = 1
    # while TA[n][0] * coeff < t_votes or TA[n][1] * coeff < a_votes:
    #     coeff += 1
    # ↓
    coeff = max((t_ratio + t_votes - 1) // t_ratio,
                (a_ratio + a_votes - 1) // a_ratio)

    t_votes = coeff * t_ratio
    a_votes = coeff * a_ratio

print(t_votes + a_votes)

Measured memory_bytes: 41200
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(a) (a).begin(), (a).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

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

  int n;
  string s;
  cin >> n >> s;

  int ans = 0;
  rep(i, n) {
    if (i >= n-2) continue;

    if (s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') ans++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import heapq 
n = int(input())
a = list(map(int, input().split()))
f_ans = [0]*(n+1)
b_ans = [0]*(n+1)

def f_sum():
  f = a[:n]
  heapq.heapify(f)
  foward_sum = sum(f)
  f_ans[0] = foward_sum
  for i in range(n, 2*n):
    heapq.heappush(f, a[i])
    foward_sum = foward_sum + a[i] - heapq.heappop(f)
    f_ans[i-n+1] = foward_sum

def b_sum():
  b = a[2*n:]
  backward_sum = sum(b)  
  b = [-1*i for i in b]
  heapq.heapify(b)
  b_ans[-1] = backward_sum
  for i in range(2*n-1, n-1, -1):
    heapq.heappush(b, -a[i])
    backward_sum = backward_sum + a[i] + heapq.heappop(b)
    b_ans[i-n] = backward_sum
    

f_sum()
b_sum()
ans = -float('inf')
for i in range(len(f_ans)):
  f = f_ans[i]
  b = b_ans[i]
  ans = max(ans, f-b)
print(ans)



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

int main(){
	int A,B,C,X,Y;
	int value;
	cin >> A >> B >> C >> X >> Y;
	if(A+B <= 2*C){
		value = A * X + B * Y;
	}
	else{
		int M = min(X,Y);
		int D = max(X,Y) - M;
		int E;
		if(X > Y) E = A;
		else E = B;
		value = 2 * M * C + min(2*C,E) * D;
	}
	cout << value << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
import math
def i():return int(sys.stdin.readline().replace("\n",""))
def i2():return map(int,sys.stdin.readline().replace("\n","").split())
def s():return str(sys.stdin.readline().replace("\n",""))
def l():return list(sys.stdin.readline().replace("\n",""))
def intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def lx():return list(map(lambda x:int(x)*-1,sys.stdin.readline().replace("\n","").split()))
def t():return tuple(map(int,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":pass

n = i()
s = s()
cnt = 0
l = s.split("ABC")
if len(l) == 1:
    print(0)
else:
    print(len(l)-1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <cstdlib> // abs(x-y)
#include <iomanip> // 出力の桁数指定
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)

using namespace std;

int main() {
  char n;
  cin >> n;
  //vector<int> p(n); 
  //rep (i, 0, n)  cin >> p.at(i);  

  cout << char(n+1) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;
#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 Sort(a) sort(a.begin(),a.end())
#define pb push_back
#define vl vector<ll>
#define vll vector<vector<ll>>
#define INF 999999999999

int main(){
  int N;
  map<string,int> P;
  map<string,int>::iterator i;
  cin>>N;

  rep(i,N){
    string S;
    cin>>S;
    P[S]++;
  }

  int max=0;
  for(i=P.begin();i!=P.end();i++){
    if(max<i->second) max=i->second;
  }
  for(i=P.begin();i!=P.end();i++){
    if(i->second==max) cout<<i->first<<endl;
  }
return 0;
}


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

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

  int n;
  cin >> n;
  vector<string> v(n);
  for (int i = 0; i < n; i++) cin >> v.at(i);
  map<string, int> counter;
  int max_num = 0;
  for (int i = 0; i < n; i++)
  {
    if(counter.count(v.at(i))) counter.at(v.at(i))++;
    else counter[v.at(i)] = 1;
    max_num = max(max_num, counter.at(v.at(i)));
  }
  for (auto elem : counter)
  {
    auto value = elem.second;
    if(max_num == value) cout << elem.first << endl;
  }
  return 0;
}

Measured memory_bytes: 25472
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

int memo[200005];
int m[200005][3]; //! m[i][j] = (1<<i) % (pc+j-1)

int solve(int x) 
{
    if (x == 0) return 0;
    int ret = memo[x];
    if (!ret) {
        int pc = __builtin_popcount(x);
        ret = 1 + solve(x % pc);
        memo[x] = ret;
    }
    return ret;
}

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

    int N;
    string X;
    cin >> N >> X;
    int pc = 0;
    rep(i, N) {
        if (X[i] == '1') ++pc;
    }

    vector<int> sum(3);
    rep(i, N) rep(j, 3) {
        if (pc+j-1 <= 0) continue;
        if (i == 0) {
            if (pc+j-1 == 1) {
                m[i][j] = 0;
            } else {
                m[i][j] = 1;
            }
        } else {
            m[i][j] = (m[i-1][j] * 2) % (pc+j-1);
        }
        if (X[N-i-1] == '1') {
            sum[j] = (sum[j] + m[i][j]) % (pc+j-1);
        }
    }

    // cout << "pc = " << pc << endl;
    // cout << "sum = "; dump(sum);
    // rep(i, N) cout << m[i][0] << ' '; cout << endl;
    // rep(i, N) cout << m[i][1] << ' '; cout << endl;
    // rep(i, N) cout << m[i][2] << ' '; cout << endl;

    rep(i, N) {
        int ans = 0;
        bool on = (X[i] == '1');
        // cout << "i = " << i << ", on = " << (on ? "T" : "F") << endl;
        if (pc != 1 || !on) {
            int base = pc + (on ? -1 : 1);
            int j = on ? 0 : 2;
            int s = sum[j];
            int r = s;
            if (on) {
                r = (r + base - m[N-i-1][j]) % base;
            } else {
                r = (r + m[N-i-1][j]) % base;
            }
            // cout << "base = " << base << ", j = " << j << ", s = " << s << ", r = " << r << endl;
            ans = 1 + solve(r);
        }
        cout << ans << '\n';
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 6500
fun main(args: Array<String>)
{
    val n = readInt()
    val ab = mutableMapOf<Long, MutableList<Long>>()

    repeat(n) {
        val (a, b) = readLine()!!.split(" ").map {it.toLong()}
        if (!ab.containsKey(b)){
            ab.put(b, mutableListOf<Long>())
        }
        ab[b]!!.add(a)
    }

    val sortedKey: List<Long> = ab.keys.toLongArray().sorted()

    var flag = true
  var sum = 0L
    for (key in sortedKey) {
        sum += ab[key]!!.reduce( {acc, it -> acc + it} )
        if (sum > key) {
            flag = false
            break
        }
    }

    println(if (flag) "Yes" else "No")
}

// Read an integer
// Usage: val a = readInt()
fun readInt() = readLine()!!.toInt()

// Read N integers separated by " "
// Usage: val (a, b, c) = readNInts()
fun readNInts() = readLine()!!.split(" ").map(String::toInt)

// Read a string
// Usage: val a = readString()
fun readString() = readLine()!!


Measured memory_bytes: 160052
#include <iostream>
#include <vector>
#include <cstdlib>
#include <limits.h>
using namespace std;

struct place{
	int id;
	int weight;
};

const int unseen = -INT_MAX;

int update(vector<place>& vi, int k, int w){
	vector<place>::iterator iter = vi.begin();
	while(iter != vi.end() && (*iter).id != k) iter++;
	if(iter == vi.end()){
		place p;
		p.id = k;
		p.weight = w;
		vi.push_back(p);
		return 1;
	}else{
		if((*iter).weight == w){
			return 0;
		}else{
			if(w < (*iter).weight){
				(*iter).weight = w;
				return 1;
			}else return 0;
		}
	}
}

void swap(vector<place>& vp, int i, int j){
	place p;
	p.id = vp[i].id; p.weight = vp[i].weight;
	vp[i].id = vp[j].id; vp[i].weight = vp[j].weight;
	vp[j].id = p.id; vp[j].weight = p.weight;
}

place remove(vector<place>& vp){
	int min = 0;
	for(int i = 0; i < vp.size(); i++){
		if(vp[i].weight < vp[min].weight)
			min = i;
	}
	swap(vp, min, vp.size() - 1);
	place p = vp[vp.size() - 1];
	vp.pop_back();
	return p;
}

int visit(int route[100][100], int k, int n){
	int weight = 0;
	int val [100];
	for(int i = 0; i < 100; i++) val[i] = unseen;
	vector<place> vp;
	update(vp, k, -unseen);
	while(!vp.empty()){
		place p = remove(vp);
		k = p.id;
		val[k] =-val[k];
		if(val[k] == -unseen) val[k] = 0;
		weight += val[k];
		for(int i = 0; i < n; i++){
			if(route[k][i] != 0)
				if(val[i] < 0)
					if(update(vp, i, route[k][i]))
					{
						val[i] = -route[k][i];
					}
		}
	}
	return weight;
}

int main(){
	const int nmax = 100;
	int n;
	int m;
	int route[nmax][nmax];
	int a, b;
	int dis;
	char c;
	while(cin >> n){
		for(int i = 0;i < nmax; i++){
			for(int j = 0; j < nmax; j++){
				route[i][j] = 0;
			}
		}
		if(n == 0) break;
		cin >> m;
		for(int i = 0; i < m; i++){
			cin >> a >> c >> b >> c >> dis;
			dis = dis / 100 - 1;
			route[a][b] = dis;
			route[b][a] = dis;
		}
		cout << visit(route, 0, n) << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using lli = long long;
using pii = pair<int, int>;

int main() {
    int N;
    cin >> N;
    vector<pii> AB(N);
    for (pii &ABi : AB) cin >> ABi.first >> ABi.second;

    sort(AB.begin(), AB.end(),
         [](const pii &p1, const pii &p2) { return p1.second < p2.second; });

    string ans    = "Yes\n";
    int curr_time = 0;
    for (const pii &abi : AB) {
        curr_time += abi.first;
        if (curr_time > abi.second) {
            ans = "No\n";
            break;
        }
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 4844
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }
void Taka() { cout << "Takahashi" << endl; }
void Aoki() { cout << "Aoki" << endl; }
void digit(int d) { cout << fixed << setprecision(d); }
void IOup() { cin.tie(0); ios::sync_with_stdio(false); }

int main() {
	int x, y, z;
	cin >> x >> y >> z;
	cout << (x - z) / (y + z) << endl;

	return 0;
}

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

#define ll long long
//ll a[2000010];

/*long long merge(ll arr[], ll l, ll m, ll r)
{
    ll i,j,k;
    ll x=m-l+1;
    ll y=r-m;
    ll left[x],right[y];
    for(i=0; i<x; i++)
        left[i] = arr[l + i];
    for(j=0; j<y; j++)
        right[j]=arr[m+1+j];

    i=0;j=0;k=l;
    ll coun=0;
    while(i<x&&j<y){
        if (left[i]<=right[j]){
            arr[k]=left[i];
            i++;
        }
        else{
            arr[k]=right[j];
            j++;
            coun+=x-i;
        }
        k++;
    }

    while(i<x){
        arr[k]=left[i];
        i++;k++;
    }

    while(j<y){
        arr[k]=right[j];
        j++;k++;
    }return coun;
}

long long mergeSort(ll arr[], ll l, ll r)
{
    ll coun=0;
    if(l<r){
        ll m=l+(r-l)/2;
        coun+=mergeSort(arr,l,m);
        coun+=mergeSort(arr,m+1,r);
        coun+=merge(arr,l,m,r);
    }return coun;
}*/
int main()
{
    ll a,b;
    cin>>a>>b;
    cout<<a+b/2<<endl;
}



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

#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
using namespace std;

int main() {
	ll h, w; cin >> h >> w;
	ll mi = min(h, w);
	ll ans = 0;
	if (mi == 1) {
		ans++;
	}
	else {
		ans += (double)(h*w) / 2 + 0.5;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define LLINF (1e18)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

ll dp[100010][4];
// dp[i+1][j]:=i文字目まで見た時に、"ABC"のうちj番目まで照合したものの個数

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();
    dp[0][0] = 1;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < 4; j++)
        {
            if (s[i] == '?')
            {
                dp[i + 1][j] += (dp[i][j] * 3 % MOD);
                dp[i + 1][j] %= MOD;
            }
            else
            {
                dp[i + 1][j] += dp[i][j];
                dp[i + 1][j] %= MOD;
            }
        }
        if (s[i] == 'A' || s[i] == '?')
        {
            dp[i + 1][1] += dp[i][0];
            dp[i + 1][1] %= MOD;
        }
        if (s[i] == 'B' || s[i] == '?')
        {
            dp[i + 1][2] += dp[i][1];
            dp[i + 1][2] %= MOD;
        }
        if (s[i] == 'C' || s[i] == '?')
        {
            dp[i + 1][3] += dp[i][2];
            dp[i + 1][3] %= MOD;
        }
    }
    cout << dp[n][3] << endl;
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

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

    //赤玉がある可能性がある:1/ない:0
    vector<int> r(n,0);
    r[0]=1;
    //箱iの玉の数
    vector<int> ct(n,1);

    rep(i,m)
    {
        int x,y;
        scanf(" %d %d", &x, &y);
        --x;
        --y;

        if(ct[x]==1)
        {
            if(r[x]==1)
            {
                //確実に赤玉が移動する
                r[x]=0;
                r[y]=1;
            }
            --ct[x];
            ++ct[y];
        }
        else
        {
            if(r[x]==1)
            {
                //赤玉が移動するかもしれない
                r[y]=1;
            }
            --ct[x];
            ++ct[y];
        }
    }

    int ans=0;
    rep(i,n) ans+=r[i];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
class segment_tree:
    def __init__(self, N, operator_M, e_M):
        self.op_M = operator_M
        self.e_M = e_M
        
        self.N0 = 1<<(N-1).bit_length()
        self.dat = [self.e_M]*(2*self.N0)
    
    # 長さNの配列 initial で初期化
    def build(self, initial):
        self.dat[self.N0:self.N0+len(initial)] = initial[:]
        for k in range(self.N0-1,0,-1):
            self.dat[k] = self.op_M(self.dat[2*k], self.dat[2*k+1])

    # a_k の値を x に更新
    def update(self,k,x):
        k += self.N0
        self.dat[k] = x
        k //= 2
        while k:
            self.dat[k] = self.op_M(self.dat[2*k], self.dat[2*k+1])
            k //= 2

    # 区間[L,R]をopでまとめる
    def query(self,L,R):
        L += self.N0; R += self.N0 + 1 
        sl = sr = self.e_M
        while L < R:
            if R & 1:
                R -= 1
                sr = self.op_M(self.dat[R],sr)
            if L & 1:
                sl = self.op_M(sl,self.dat[L])
                L += 1
            L >>= 1; R >>= 1
        return self.op_M(sl,sr)

    def get(self, k): #k番目の値を取得。query[k,k]と同じ
        return self.dat[k+self.N0]

# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

n, = map(int,readline().split())
*a, = map(int,readline().split())
*b, = map(int,readline().split())

ca = [0]*(n+1)
cb = [0]*(n+1)

for i in a: ca[i] += 1
for i in b: cb[i] += 1


from heapq import *

qc = [0]*(n+1)
for i,(x,y) in enumerate(zip(ca,cb)):
    if x+y > n:
        print("No")
        exit()
    elif i==0 or x+y==0:
        continue
    else:
        qc[i] = x+y


def op(a,b):
    if qc[a] <= qc[b]: return b
    else: return a

s = segment_tree(n+1,op,0)
s.build(list(range(n+1)))

sa = set(a)
sb = set(b)

def dela(j):
    ca[j] -= 1
    if ca[j]==0:
        sa.remove(j)
    
def delb(j):
    cb[j] -= 1
    if cb[j]==0:
        sb.remove(j)

ans = [None]*n
for i in range(n):
    j = s.dat[1]
    #print(i,sa,sb,v,j)
    #print(j,qc,s.dat)
    if ca[j]:
        dela(j)

        for k in sb:
            if k != j: break
        delb(k)
        ans[i] = (j,k)

    else:
        delb(j)
        
        for k in sa:
            if k != j: break
        dela(k)
        ans[i] = (k,j)
    
    qc[j] -= 1
    qc[k] -= 1
    s.update(j,j)
    s.update(k,k)

from operator import itemgetter
ans.sort(key=itemgetter(0))

print("Yes")
ans = [y for x,y in ans]
print(*ans)










    
    
    

Measured memory_bytes: 167276
#include<bits/stdc++.h>
using namespace std;
const int N=1e2+10;
int n,k,a[N],b[N];

int main()
{
	cin>>n>>k;
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	
	int ans=-0x3f3f3f3f;
	for (int i=0;i<=k;i++)
		for (int j=0;i+j<=k && i+j<=n;j++) {
			int now=0;
			for (int l=1;l<=i;l++) b[++now]=a[l];
			for (int r=n;r>=n-j+1;r--) b[++now]=a[r];
			sort(b+1,b+now+1);
			for (int t=1;t<=k-now;t++)
				if (b[t]<0) b[t]=0;
			int tmp=0;
			for (int t=1;t<=now;t++) tmp+=b[t];
			ans=max(ans,tmp);	 
		}
	cout<<ans<<endl;
	return 0;
}

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

int main(){
	
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;
	
	if ( x - r  >= 0 && x + r <= W && y - r >= 0 && y + r <= H ) cout << "Yes" <<endl;
	
	
	else cout << "No" <<endl;
	
	return 0;
	
}


Measured memory_bytes: 3112
class Main{
    public static void main(String[] a){
        for (int i = 1; i < 10; i++) {
	    	for(int j = 1; j < 10; j++) {
	    		
	    		int ans = i * j;
	    		System.out.println(i + "x" + j + "="+ ans);
	    	}
	    }
    }
}


Measured memory_bytes: 24052
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <limits>

using namespace std;

int main()
{
    
    int N, K;
    cin >> N >> K;
    
    vector<int> dp(N+1);
    dp[0] =1;
    for(int a = 1; a <= N;++a)
    {
        dp[a] = min(dp[a-1]*2, dp[a-1]+K);
    }
    cout << dp[N] << endl;
    
    return 0;
}

Measured memory_bytes: 256