akhauriyash/Code-Regression huggingface dataset:
#define dbg(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
#define dpri(x) dbg(#x ": %d\n", x)
#define dprs(x) dbg(#x ": %s\n", x)
#include <stdio.h>
#include <string.h>
typedef long long ll;
const int MYINF = 1e9+7;
typedef int bool;
const bool true = 1;
const bool false = 0;

#define MAX_H 32000000
#define parent(i) ((i)/2)
#define left(i) ((i)*2)
#define right(i) ((i)*2+1)

int H;
int heap[MAX_H];
#define len heap[0]

void swap(int i, int j) {
	int t;
	t = heap[i];
	heap[i] = heap[j];
	heap[j] = t;
}

void shiftup(int i) {
	int p = parent(i);
	if (i == 1 || heap[p] > heap[i]) return;
	swap(p, i);
	shiftup(p);
}

void insert(int x) {
	heap[++len] = x;
	shiftup(len);
}

void shiftdown(int i) {
	int l = left(i), r = right(i), c = -1000;
	if (len < i) return;
	if (len < l) return;
	if (r <= len) {
		if (heap[l] > heap[i] && heap[r] > heap[i]) {
			if (heap[l] > heap[r]) c = l;
			else c = r;
		} else if (heap[l] > heap[i]) {
			c = l;
		} else if (heap[r] > heap[i]) {
			c = r;
		} else {
			return;
		}
	} else if (l <= len) {
		if (heap[l] > heap[i]) c = l;
		else return;
	}
	swap(c, i);
	shiftdown(c);
}

int extract(void) {
	int res;
	res = heap[1];
	heap[1] = heap[len--];
	shiftdown(1);
	return res;
}

int main(int argc, char **argv)
{
	int x;
	char cmd[256];

	while (1) {
		scanf("%s", cmd);
		if (!strcmp(cmd, "end")) break;
		if (!strcmp(cmd, "insert")) {
			scanf("%d", &x);
			insert(x);
		} else if (!strcmp(cmd, "extract")) {
			printf("%d\n", extract());
		}
	}

	return 0;
}

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

int main(void) {
    long n, a, b;
    cin >> n >> a >> b;

    vector<long> v(n);
    for(auto &e: v) cin >> e;

    sort(v.begin(), v.end(), greater<>());

    long t = 0;
    for(long i=0; i<a; i++)
        t += v[i];
    // t/a

    long m = v[a-1], cm = 0, cmt = 0;
    for(long i=0; i<n; i++)
        if(v[i] == m) {
            if(i<a) cmt++;
            cm++;
        }

    auto comb = [&](long a, long b) {
        long r = 1;
        for(long i=0; i<b; i++)
            r *= a-i, r /= i+1;
        return (long)r;
    };

    cout << setprecision(16) << 1.0*t/a << endl;
    if(cmt == a) {
        // sum [a<=i<=b] (cm C i)
        long r = 0;
        for(long i=a; i<=b; i++)
            r += comb(cm, i);
        cout << r << endl;
    } else {
        // cm C cmt
        cout << comb(cm, cmt) << endl;
    }
}


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

int calcMaxPrice(int tax_before, int tax_after, int price);
int calcTax(int tax, int price);

int main(void)
{
    int tax_before, tax_after, price;

    int max_price;

    while (cin >> tax_before >> tax_after >> price && tax_before > 0) {
        max_price = calcMaxPrice(tax_before, tax_after, price);
        cout << max_price << endl;
    }
    
    return 0;
}

int calcMaxPrice(int tax_before, int tax_after, int price)
{
    int max_price = 0;
    for (int one_price = 1; one_price < price; one_price++) {
        for (int other_price = 1; other_price < price; other_price++) {
            if(calcTax(tax_before, one_price)+ calcTax(tax_before, other_price) == price) {
                int price_after = calcTax(tax_after,one_price) + calcTax(tax_after, other_price);
                if (price_after > max_price) {
                    max_price = price_after;
                }
            }
        }
    }

    return max_price;
}

int calcTax(int tax, int price)
{
    return price * (100 + tax) / 100;
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String s = sc.next(), t = sc.next();
        int a = sc.nextInt(), b = sc.nextInt();
        String u = sc.next();

        if (u.equals(s)) {
            a--;
        } else {
            b--;
        }
        System.out.println(a + " " + b);
        sc.close();
    }
}

Measured memory_bytes: 21588
#include<bits/stdc++.h>
#define LiangJiaJun main
using namespace std;
int a[104],n,k;
int dp[100004][2];
bool vis[100004][2];
int dfs(int p,int x){
    if(vis[x][p])return dp[x][p];
    dp[x][p]=0;
    vis[x][p]=1;
    for(int i=1;i<=n;i++){
        if(x>=a[i]){
            dp[x][p]|=(!dfs(1-p,x-a[i]));
        }
    }
    return dp[x][p];
}
int w33ha(){
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    if(dfs(1,k))return puts("First"),0;
    else return puts("Second"),0;
    return 0;
}
int LiangJiaJun(){
    while(scanf("%d%d",&n,&k)!=EOF)w33ha();
    return 0;
}


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

# AtCoder Grand Contest
# Problem A


if __name__ == '__main__':
    number = int(input())
    l = sorted(list(map(int, input().split())), reverse=True)
    count = 0

    for i in range(number):
        count += min(l[2 * i], l[2 * i + 1])

    print(count)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main() {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t k;
    cin >> k;
    int64_t res = 0;
    for(int64_t i=1; i<k+1; i++){
        for(int64_t j=1; j<k+1; j++){
            for(int64_t n=1; n<k+1; n++){
                res += __gcd(i,__gcd(j,n));
            }
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[100];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

		for (int i = 0; i < n; i++) {
			System.out.print(a[n - i - 1]);
			if (i != n - 1)
				System.out.print(" ");
		}
		System.out.println("");
	}

}



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

public class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    int A = scanner.nextInt();
    int B = scanner.nextInt();
    int C = scanner.nextInt();
    int[] num = {A, B, C};
    int count = 0;

    Arrays.sort(num); //num[0]が最小で、num[1]が真ん中、num[2]が最大
    if((num[2] - num[0]) % 2 == 0 && (num[2] - num[1]) % 2 == 0){
      count = num[2] - (num[0]+num[1])/2;
    }
    if((num[2] - num[0]) % 2 == 1 && (num[2] - num[1]) % 2 == 1){
      count = num[2] - (num[0]+num[1])/2;
    }
    if((num[2] - num[0]) % 2 == 0 && (num[2] - num[1]) % 2 == 1){
      count = 1 + (2 * num[2] - num[0] - num[1] + 1)/2;
    }
    if((num[2] - num[0]) % 2 == 1 && (num[2] - num[1]) % 2 == 0){
      count = 1 + (2 * num[2] - num[0] - num[1] + 1)/2;
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 23124
n = int(input())
a = [int(input()) for i in range(n)]
check = [0 for i in range(n)]
now = 1
ans = 0
while check[now-1] == 0:
    if now == 2:
        print(ans)
        break
    check[now-1] = 1
    now = a[now-1]
    ans += 1
else:
    print(-1)

Measured memory_bytes: 7852
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
const int N=100000;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u];i;i=sq[i].nxt)
#define fir first
#define sec second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define maxd 998244353
#define eps 1e-8
int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

int main()
{
	int n=read();
	ll a=1,b=1;
	rep(i,1,n)
	{
		int na=read(),nb=read();
		ll ma=(a-1)/na+1,mb=(b-1)/nb+1;
		ll mul=max(ma,mb);
		a=mul*na;b=mul*nb;
	}
	printf("%lld",a+b);
	return 0;
}

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

using namespace std;

int N, M;
int A[100000];
vector<int> B[100000];

int special(int x)
{
    int y=B[x].size();
    return y/2;
}

int paircount(int x)
{
    map<int, int> m;
    for(int i=0; i<(int)B[x].size(); i++)
        m[B[x][i]]++;
    int ret=0;
    for(auto& it: m)
        ret+=it.second/2;
    return ret;
}

int main()
{
    scanf("%d%d", &N, &M);
    for(int i=0; i<N; i++)
    {
        scanf("%d", A+i);
        B[A[i]%M].push_back(A[i]);
    }
    int ans=special(0);
    if(M%2==0)
        ans+=special(M/2);
    for(int i=1; i<M-i; i++)
    {
        int x=i;
        int y=M-i;
        sort(B[x].begin(), B[x].end());
        sort(B[y].begin(), B[y].end());
        if(B[x].size()<B[y].size())
            B[x].swap(B[y]);
        int px=paircount(x);
        int py=paircount(y);
        int sx=B[x].size();
        int sy=B[y].size();
        while(sx>sy && px--)
            ans++, sx-=2;
        ans+=min(sx, sy);
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 6144
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main()
{
	int N;
	double v[1000];
	double v2[1000];

	int count = 0;

	scanf("%d", &N);

	for (int i = 0; i < N; i++)
	{
		scanf("%lf", &v[i]);
	}

	for (int i = 1; i <= 1000; i++)
	{
		for (int j = 0; j < N; j++)
		{
			if (i == v[j])
			{
				v2[count] = v[j];
				count++;
				//break;
			}
		}
	}

	for (int i = 0; i < N-1; i++)
	{
		v2[i + 1] = (v2[i] + v2[i + 1]) / 2;
	}

	//for(int i = 0;  i < N; i++)
		printf("%f ", v2[N-1]);

}


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

int main(){
	int N; cin >> N;
	ll A[N];
	ll l = 0, r = 0;
	for(int i=0; i<N; i++){
		cin >> A[i];
		r += A[i];
	}
	ll d = r;
	ll ans = d;
	for(int i=0; i<N-1; i++){
		l += A[i];
		r -= A[i];
		if(ans > abs(l-r)) ans = abs(l-r);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
/*
int compare_int(const void *a, const void *b)
{
    return *(int *)a - *(int *)b;
}
*/
int main()
{

    int n = 0;
    //    int n[101];
    int data[100002]; //名前
    int nannko[1000002];
    for (int i = 0; i < 1000001; i++)
    {
        nannko[i] = 0;//初期化
    }

    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &data[i]); //データ
        nannko[data[i]]++;
    }
    int q;


    scanf("%d", &q);
   
   /* qsort(data,n, sizeof(int), compare_int);
   */
    long long count=0;
    int a,move;
    long long disa=0;
    for (int i = 0; i < 100001; i++)
    {
        count=count+ (long long)nannko[i] * i;
    }
    for (int j = 0; j < q; j++)
    {
        scanf("%d %d", &a ,&move);
        disa = (long long)nannko[a] * (move - a);
        nannko[move] = nannko[move]+nannko[a];
        nannko[a] = 0;
        
        count = count+disa;
        printf("%lld\n",count);
    }
}

Measured memory_bytes: 6420
N = gets.to_i
A = gets.split.map(&:to_i)
B = gets.split.map(&:to_i)
C = gets.split.map(&:to_i)
satis = 0
bef = 0

for i in A do
  if i.to_i >= 2 && (i.to_i - 1) == bef then
    satis = B[i - 1].to_i + C[i - 2].to_i + satis
  else
    satis = B[i -1].to_i + satis
  end
  bef = i.to_i
end
print satis

Measured memory_bytes: 1788
#include <stdio.h>

int main(void)
{
    int h, w, i, j;

    while (1) {
        scanf("%d %d", &h, &w);

        if (h == 0 && w == 0)
            break;

        for (i = 1; i <= h; i++) {
            for (j = 1; j <= w; j++) {
                if (i % 2 != 0 && j % 2 != 0 || i % 2 == 0 && j % 2 == 0)
                    printf("#");
                else
                    printf(".");
                if (j == w)
                    printf("\n");
            }
        }

        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
using std::cout;
using std::endl;
using std::cin;

int main(){
	long n, k; cin >> n >> k;
	
	if(!k){
		cout << n * n << endl;
		return 0;
	}
	
	long ans = 0;
	for(long i = k + 1; i <= n; i++){
		long A = (n + 1) / i;
		long B = (n + 1) % i;
		
		ans += A * (i - k);
		if(B >= k) ans += B - k;
	}
	
	cout << ans << endl;
	return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  char C;
  cin>>C;
  cout<<char(C+1)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]){
    double a, b, c, d, e, f, x, y;
    
    while(scanf("%lf %lf %lf %lf %lf %lf", &a, &b, &c, &d, &e, &f) != EOF){
        x = (c * e - f * b) / ( a * e - d * b) + 0.0004;
        y = (c * d - a * f) / ( b * d - a * e) + 0.0004;
        printf("%.3lf %.3lf\n", x, y);
    }
    return 0;
}

Measured memory_bytes: 656
#include <cstdio>
int main() {
    int x, y, z, q, i;
    scanf("%d%d%d\n", &x, &y, &z);
    q = 0;
    for(i = x; i <= y; ++i) {
        if(z%i == 0) {
            q += 1;
        }
    }
    printf("%d\n", q);
    return 0;
}


Measured memory_bytes: 2720
n = gets.chomp.to_i
a_arr = gets.chomp.split(" ").map(&:to_i)

hash = {}
(1..n).each do |a|
  tmp_a = a + a
  while tmp_a <= n do
    hash[a] ||= []
    hash[a] << tmp_a
    tmp_a += a
  end
end

b_arr = []
hash2 = {}
while n > 0 do
  n /= 2
  a_arr[n..-1].each_with_index do |a, i|
    num = n + i + 1
    count = (hash[num] || []).map{|map_n| hash2[map_n].to_i }.inject(&:+).to_i
    if a == 1 then
      if count % 2 == 1 then
        hash2[num] = 0
      else
        hash2[num] = 1
        b_arr << num
      end
    else
      if count % 2 == 1 then
        hash2[num] = 1
        b_arr << num
      else
        hash2[num] = 0
      end
    end
  end
  a_arr = a_arr[0..(n-1)]
end

puts b_arr.length
if b_arr.length > 0 then
  puts b_arr.reverse.join(" ")
end


Measured memory_bytes: 88844
# -*- coding: utf-8 -*-
# AtCoder Beginner Contest 125
# B - Resale

N = int(input())
V = [int(v) for v in input().split(' ')]
C = [int(v) for v in input().split(' ')]

# zip() : 組み込み関数
# V,Cから一つずつ取り出して順にv,cに入れる

# まず利益がマイナスになるものを除外
prof = [v-c for v, c in zip(V,C) if v-c > 0]

# 全部買う
print(int(sum(prof)))

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

using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}

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

int a[2010];
bitset<4000010> dp;
signed main(void)
{
  int n;
  cin >> n;
  int su = 0;
  REP(i, n) cin >> a[i], su += a[i];

  dp.set(0);
  REP(i, n) dp |= (dp << a[i]);

  // dp[n] でビットが立っている sum/2 以上の最小
  FOR(i, su/2 + !!(su%2), su+1) {
    if(dp[i]) {
      cout << i << endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int a,b;
  cin >> a >>b;
  int c;
  if(a==0) c=1;
  else if(a==1) c=100;
  else c=10000;
  if(b<100) cout << c*b << endl;
  else cout << c*(b+1) << endl;
  
}

Measured memory_bytes: 256
#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(){
  int n;
  while(cin>>n,n){
    vector<int>in(n);
    int co=0;
    rep(i,n)cin>>in[i];
    rep(i,n){
      rep(j,n-i-1){
	if(in[j]>in[j+1]){
	  co++;
	  swap(in[j],in[j+1]);
	}
      }
    }
    cout<<co<<endl;
  }
}

Measured memory_bytes: 1196
#S=input()

#print(ans)


n=int(input())
lis=list(map(int,input().split()))
sa=sum(lis)
for i in range(n+1):
    sa=sa-2*lis[i]
    if sa<0:
        ans=min(abs(sa+2*lis[i]),abs(sa))
        break
print(ans)


Measured memory_bytes: 2940
#include <iostream>
#include <set>
#include <queue>

using namespace std;
using P = pair<int, int>;

const int MAX = 100;
const int NIL = -1;

int G[MAX][MAX];

int main() {

    int n;
    cin >> n;

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

    set<int> T;
    int sum = 0;

    T.insert(0);

    while (T.size() < n) {
        priority_queue<P, vector<P>, greater<>> pq;
        for (int u : T) {
            for (int i = 0; i < n; i++) {
                if (G[u][i] != NIL && T.find(i) == T.end()) {
                    pq.push(make_pair(G[u][i], i));
                }
            }
        }
        T.insert(pq.top().second);
        sum += pq.top().first;
    }

    cout << sum << endl;
}


Measured memory_bytes: 3128
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007

int main()
{
	int n;
	cin >> n;
	int a[200001];
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	if(a[0] > 0){
		cout << -1 << endl;
		return 0;
	}
	long long int ans = 0;
	for(int i = 1; i < n; i++){
		if(a[i - 1] > a[i]){
			ans += a[i];
		} else if(a[i - 1] == a[i]){
			ans += a[i];
		} else if(a[i - 1] + 1 == a[i]){
			ans++;
		} else{
			ans = -1;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010


int main(){
  int x, y, n, m, a;

  cin >> n >> m >> x >> y;

  for(int i=0;i<n;i++){ scanf("%d", &a); x = max(x, a);}
  for(int i=0;i<m;i++){ scanf("%d", &a); y = min(y, a);}

  puts(x < y ? "No War" : "War");
    
  return 0;
}



Measured memory_bytes: 256
s = input()
n = len(s)
sum = 0
for b in range(1 << (n-1)):
    t = 0
    for i in range(n-1):
        if b & (1 << i):
            sum += int(s[t:i+1])
            t = i+1
    sum += int(s[t:])
print(sum)

Measured memory_bytes: 66952
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <set>
#define SIZE 200005

using namespace std;
typedef long long int ll;

ll A[SIZE],B[SIZE];
ll sum,all;
int cnt;
multiset <ll> st;
multiset <ll>::iterator it;
int n,q;

void ins(int k)
{
	if(k==0||k==n-1)
	{
		all+=A[k];
	}
	else
	{
		all+=A[k];
		if(A[k]<B[k])
		{
			cnt++;
			sum+=B[k]-A[k];
		}
		st.insert(B[k]-A[k]);
	}
}
void rem(int k)
{
	if(k==0||k==n-1)
	{
		all-=A[k];
	}
	else
	{
		all-=A[k];
		if(A[k]<B[k])
		{
			cnt--;
			sum-=B[k]-A[k];
		}
		it=st.lower_bound(B[k]-A[k]);
		st.erase(it);
	}
}
ll get_ans()
{
	if(cnt%2==0) return all+sum;
	else
	{
		it=st.upper_bound(0);
		ll mx=-(*it);
		it--;
		mx=max(mx,(*it));
		return all+sum+mx;
	}
}
int main()
{
	scanf("%d %d",&n,&q);
	n*=2;
	for(int i=0;i<n;i++) scanf("%lld",&A[i]);
	for(int i=0;i<n;i++) scanf("%lld",&B[i]);
	for(int i=0;i<n;i++) ins(i);
	for(int i=0;i<q;i++)
	{
		int p;
		ll x,y;
		scanf("%d %lld %lld",&p,&x,&y);p--;
		rem(p);
		A[p]=x,B[p]=y;
		ins(p);
		printf("%lld\n",get_ans());
	}
	return 0;
}


Measured memory_bytes: 14208
import sys
s = input()

for i in range(len(s)):
    if i % 2 == 0:
        if s[i] not in ["R","U","D"]:
            print("No")
            sys.exit()
    else:
        if s[i] not in ["L","U","D"]:
            print("No")
            sys.exit()
print("Yes")

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

typedef vector<int> VI;

bool f(const VI &vx, int X) {
  unordered_set<int> pos;
  pos.insert(0);
  for (auto x : vx) {
    unordered_set<int> next_pos;
    for (auto y : pos) {
      next_pos.insert(y + x);
      next_pos.insert(y - x);
    }
    pos = next_pos;
  }
  // for (auto y : pos) {
  //  cout << y << " ";
  //}
  // cout << endl << endl;
  return pos.find(X) != pos.end();
}

int main() {

  string S;
  cin >> S;
  int N;
  N = S.size();

  int X, Y;
  cin >> X >> Y;

  VI vx, vy;

  int n = 0;
  bool horizontal = true;
  bool first = true;
  for (int i = 0; i < S.size(); i++) {
    char c = S[i];
    if (first) {
      if (c == 'F') {
        X--;
      } else {
        first = false;
        horizontal = false;
      }
    } else {
      if (c == 'F') {
        n++;
      } else {
        if (n > 0) {
          if (horizontal) {
            vx.push_back(n);
          } else {
            vy.push_back(n);
          }
          n = 0;
        }
        horizontal = !horizontal;
      }
    }
  }
  if (horizontal) {
    vx.push_back(n);
  } else {
    vy.push_back(n);
  }

  // for (auto x : vx) {
  //  cout << x << " ";
  //}
  // cout << endl;
  // for (auto x : vy) {
  //  cout << x << " ";
  //}
  // cout << endl << X << " " << Y << endl << endl;

  if (f(vx, X) && f(vy, Y)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 768
/**
 *      purpose : 「みんなのプロコン 2019」B
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cctype>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define fi first
#define se second

const int INF = 1e4;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int dis[4][4] = {};

    rep(i, 4){
        rep(j, 4) dis[i][j] = INF;
    }

    rep(i, 3){
        int a, b; cin >> a >> b;
        --a; --b;
        dis[a][b] = dis[b][a] = 1;
    }

    rep(k, 4){
        rep(i, 4){
            rep(j, 4) dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
        }
    }

    rep(i, 4){
        rep(j, 4) {
            if (dis[i][j] == 3) {
                print("YES"); return 0;
            }
        }
    }
    print("NO");
    
    
    return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
s=[False]*200001
g=[False]*200001
r='POSSIBLE'
for _ in range(m):
    a,b=map(int,input().split())
    if a==1:
        if g[b]:
            break
        s[b]=True
    elif b==n:
        if s[a]:
            break
        g[a]=True
else:
    r='IMPOSSIBLE'
print(r)

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

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    ll a,b,c,x,y;
    while(cin >> a >> b >> c >> x >> y)
    {
        ll ans = a*x + b*y;
        for(int t = 0; t <= x; t++)
        {
            ll cur = a*t + (2*c)*(x-t);
            ll oth = max(0LL, y - (x-t));
            cur += b*oth;
            ans = min(ans, cur); 
        }
        for(int t = 0; t <= y; t++)
        {
            ll cur = b*t + (2*c)*(y-t);
            ll oth = max(0LL, x - (y-t));
            cur += a*oth;
            ans = min(ans, cur); 
        }
        cout << ans << '\n';
    }
    return 0;
}

Measured memory_bytes: 256
/*
Problem Number: ABC177A
Problem Name: Don't be late
Notes: 
*/

#include <bits/stdc++.h>
#define endl "\n"

using namespace std;

int main(){
    cin.tie(0) -> sync_with_stdio(0);
    
    int D, T, S;
    cin >> D >> T >> S;

    cout << (D <= S * T ? "Yes" : "No") << endl;
    
    return 0;
}

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

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

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

int main(){
 	int n,k,a=1;
  	cin>>n>>k;
  	for(int i=0;i<n;i++){
     	if(a*2<a+k)
          a*=2;
      	else
          a+=k;
    }
  	cout<<a<<endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args){

    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();

    if ((B % A) == 0) {
      System.out.println(A + B);
    } else {
      System.out.println(B - A);
    }

  }
}

Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < (b); ++i)
#define rrep(i,a,b) for(int i = (b); i --> (a);)
#define trav(x,v) for(auto  &x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) (int)(v).size()
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> pll;

const int k = 13;
const int mxc = (1<<k)+1;
typedef bitset<mxc> bbs;

ll gcd(ll a, ll b){
	while(b){
		a %= b;
		swap(a,b);
	}
	return a;
}

ll inv(ll a, ll b){
	return a>1 ? b - inv(b%a,a)*b/a : 1LL;
}

pll crt(pll a, pll b){
	ll m, n, x, y;
	tie(m,x) = a;
	tie(n,y) = b;
	ll d = gcd(m,n);
	rep(q,0,n/d) if((x+m*q)%n == y)
		return pll(n/d*m, (x + m*q)%(n/d*m));
	return pll(-1,-1);
}

int zz(bbs &r, int per){
	int ans = 0;
	rep(i,0,per) if(r[i] < r[(i+per-1)%per]){
		int cur = 1;
		while(!r[(i+cur)%per]) ++cur;
		ans = max(ans, cur);
	}
	return ans;
}

int main(){
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);

	int n;
	cin >> n;
	vector<ll> xs(n), ys(n);

	rep(i,0,n) cin >> xs[i] >> ys[i];

	vi ls = {7,8,9,10,11,12,13};
	int m = sz(ls);
	vi rs(m);

	pll yy(1,0), xx(1,0);
	
	trav(q, ls){
		int rp = (1<<q)-1, cp = (1<<q)+1;
		vector<bbs> rs(rp);
		rep(i,0,rp) rep(j,0,i+2) if( ((i+1)&j) == j )
			rs[i].set(cp-j-1);
		bbs resy(0), resx(0);
		auto fun = [&](bbs &res, ll x, ll y){
			ll q = y / rp;
			if(q*rp > y) --q;
			y -= q*rp;
			x -= q;
			x %= cp;
			if(x < 0) x += cp;
			res ^= rs[y]>>x;
			res ^= rs[y]<<(cp-x);
		};
		rep(t,0,n){
			fun(resy, xs[t], ys[t]);
			fun(resx, ys[t], xs[t]);
		}
		yy = crt(yy, pll(rp, rp-zz(resy,cp)));
		xx = crt(xx, pll(rp, rp-zz(resx,cp)));
	}
	if(yy.second > 1e17) yy.second -= yy.first;
	if(xx.second > 1e17) xx.second -= xx.first;
	cout << xx.second << ' ' << yy.second << endl;
}


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


typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

#define pb push_back
#define mp make_pair
#define snd second
#define fst first
#define debug printf("--%d--\n",__LINE__)
#define ll long long int

int main(void){
	int N;
	cin >> N;
	
	int sum = 0, i = 0;
	for(i=1;i<=N;i++){
		sum += i;
		if (sum >= N) break;
	}
	int d = sum - N;
	for(int j=1;j<=i;j++){
		if (j!=d) cout << j << endl;
	}
	
	
	
	return 0;
}


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

int max(int a, int b) {
    if (a >= b) return a;
    else return b;
}

int exponential (int a, int x) {
    int b = a;
    for (int i=0; i<x-1; ++i) {
        b = b * a;
    }
    return b;
}

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

    // F(A, B)が最小 == AまたはBの最大値が最小 -> N=A*Bを満たす10^5以下の数の最大値のペアは最小となる
    int res = 0;
    
    int sqN = (int)sqrt(N);
    for (int i=1; i<=sqN; ++i) {
        if (N % i == 0) {
            res = max(res, i);  // N=A*B を満たすN^(1/2)以下の最大値を求める
            //cout << res << endl;
        }
    }
    
    int count = 0;
    long long b = N / res;
    for (long long i=1; i<=10; ++i) {
        long long e = exponential(10, i);
        long long mod = b % e;
        //cout << b << " " << e << endl;
        if (b > 0) ++count;
        b = b - mod;
    }

    cout << count << endl;
}

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

int main() {

  string S; cin >> S;

  rep(i,S.size()){
    cout<<'x';
  }

  cout<<endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define MOD 1000000007
template <typename Type>
istream &operator>>(istream &in, vector<Type> &vec) {
    ll n = vec.size();
    for (ll i = 0; i < n; i++)
        in >> vec[i];
    return in;
}
template <typename Type>
ostream &operator<<(ostream &out, vector<Type> &vec) {
    for (auto val : vec)
        out << val << " ";
    return out;
}
#define PI 3.14159265
void solve()
{
    ll a,b,c,d;
  	cin>>a>>b>>c>>d;
  	vector<ll>v(4);
  	v[0] = a*c;
  	v[1] = a*d;
  	v[2] = b*d;
  	v[3] = b*c;
  	cout<<*max_element(v.begin(),v.end());
}
int main()
{
    ll t=1;
    // cin>>t;
    while(t--)
    solve();
    return 0;
}


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

int main(){
    string s;
    cin >> s;
    
    int ans;
    for(int i = s.size(); i >= 0; i--){
        s.erase(i-1);
        if(s.size() % 2 == 1){
            continue;
        }
        string a,b;
        a = s.substr(0, s.size()/2);
        b = s.substr(s.size()/2, s.size()/2);
        if(a == b){
            ans = s.size();
            break;
        }
    } 
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <algorithm>
#include <functional>
#include <chrono>
#include <random>
#include <vector>
#include <string>
#include <cmath>
#include <bitset>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cassert>

#define sq(x) ((x) * (x))
#define err(x) cerr << "["#x"]  " << (x) << "\n";
#define errp(x) cerr << "["#x"]  {" << ((x).first) << ", " << ((x).second) << "}\n";
#define errv(x) {cerr << "["#x"]  [";for(const auto& ___ : (x)) cerr << ___ << ", "; cerr << "]\n";}
#define errvn(x, n) {cerr << "["#x"]  [";for(auto ___ = 0; ___ < (n); ++___) cerr << (x)[___] << ", "; cerr << "]\n";}
#define errf() cerr << "\n\n";

//#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast, unroll-loops", "omit-frame-pointer","inline")
#pragma GCC option("arch=native","tune=native","no-zero-upper")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native,avx2")

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getrnd(int l, int r) {
    return uniform_int_distribution<int>(l, r)(rng);
}

ll getrndll(ll l, ll r) {
    return uniform_int_distribution<ll>(l, r)(rng);
}

template <typename T1, typename T2>
inline bool relax(T1& a, const T2& b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

template <typename T1, typename T2>
inline bool strain(T1& a, const T2& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

// :::::::::::::::::::::::::::::::

const int MOD = 1e9 + 7; // 998244353;

int add(int a, int b) {
    a += b;
    if (a >= MOD) a -= MOD;
    if (a < 0) a += MOD;
    return a;
}

int mul(int a, int b) {
    return 1LL * a * b % MOD;
}

int binpow(int a, ll n) {
    if (n < 0)
        a = binpow(a, MOD - 2), n *= -1;
    
    int res = 1;
    while (n) {
        if (n & 1)
            res = mul(res, a);
        a = mul(a, a);
        n /= 2;
    }
    return res;
}

int inv(int x) {
    return binpow(x, MOD - 2);
}

const int N = 5e5 + 3;

int fact[N];

int C(int n, int k) {
    if (k > n) return 0;
    return mul(fact[n], inv(mul(fact[k], fact[n - k])));
}

void solve() {
    fact[0] = 1;
    for (int i = 1; i < N; ++i)
        fact[i] = mul(fact[i - 1], i);
    
    int n, m;
    cin >> n >> m;
    
    int ans = mul(C(m, n), fact[n]);
    ans = mul(ans, ans);
    
    for (int i = 1; i <= n; ++i) {
        int temp = mul(fact[i], mul(C(n, i), C(m, i)));
        int q = mul(C(m - i, n - i), fact[n - i]);
        q = mul(q, q);
        temp = mul(temp, q);
        if (i % 2)
            temp *= -1;
//        err(temp);
        ans = add(ans, temp);
    }
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);
    srand(time(0));
    
    int t = 1;
//    cin >> t;
    while (t--)
        solve();
    
    return 0;
}


Measured memory_bytes: 5564
#include<bits/stdc++.h>
int main(){
int a;scanf("%d",&a);
int L=a/100;
int R=a%100;
if(1<=L&&L<=12){
if(1<=R&&R<=12)printf("AMBIGUOUS\n");
else printf("MMYY\n");
}else{
if(1<=R&&R<=12)printf("YYMM\n");
else printf("NA\n");
}}

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

x = int(input())
#s = input()
#a = [int(i) for i in readline().split()]
#m = [[int(i) for i in readline().split()] for _ in range(n)]



if x >= 10000: print(1)
else:
    q = x//100
    r = x%100
    
    c = r//5
    if r%5: c += 1
    
    if q >= c:
        print(1)
    else:
        print(0)



Measured memory_bytes: 3060
def main():
    n = int(input())
    array = [int(x) for x in input().split()]
    mod = 10 ** 18
    ans = 1
    if 0 in array:
        print(0)
        return
    for x in array:
        ans *= x
        if ans > mod:
            print(-1)
            return
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 21480
N=int(input())
b=list(map(int,input().split()))

ans=[-1]*N
for i in reversed(range(N)):
  for j in reversed(range(1,i+2)):
    br=0
    if b[j-1]==j:
      ans[i]=j
      b.pop(j-1)
      br=1
      break
  if br==0:
    print(-1)
    exit()
      
for i in ans:
  print(i)

Measured memory_bytes: 3064
#include<stdio.h>
#define MAX 100000
int A[MAX];

int main(){
  int n,i,j,r,p,x,tmp;

  scanf("%d",&n);
  for(r=0;r<n;r++) scanf("%d",&A[r]);

  x=A[--r];
  i=-1;
  for(j=0;j<n-1;j++){
    if(A[j]<=x){
      tmp=A[++i];
      A[i]=A[j];
      A[j]=tmp;
    }
  }
  tmp=A[i+1];
  A[i+1]=A[r];
  A[r]=tmp;

  for(j=0;j<n;j++){
    if(j>0) printf(" ");
    if(j==i+1) printf("[%d]",A[j]);
    else printf("%d",A[j]);
  }
  printf("\n");
  return 0;
}



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

int main(){
  int N;
  cin >> N;
  vector<int> vec(N + 1);
  for (int i = 1; i < N + 1; i++){
    cin >> vec.at(i);
  }
  int index = 1, count = 0, tmp;
  while (index != 2){
    if (vec.at(index) == index){
      cout << -1;
      return 0;
    }
  tmp = vec.at(index);  
  vec.at(index) = index;
  index = tmp;
  count++;
  }
  cout << count;
  return 0;
}

Measured memory_bytes: 3804
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;
#define n_max 100000
#define N_max 100


int main()
{
    int N, M; 
	int max = -1000;

    cin >> N;
    
    map<string, int> A, B;

    for(int i = 0; i < N; i ++) {
        string tmp;
        cin >> tmp;
        A.insert(make_pair(tmp, 0));
        A.at(tmp)++;
    }

    cin >> M;

    for(int i = 0; i < M; i ++) {
        string tmp;
        cin >> tmp;
        B.insert(make_pair(tmp, 0));
        B.at(tmp)++;
    }

    //for(auto i : A) {
    for(auto i = A.begin(); i != A.end(); i++) {
        //cout << "key -> " << i->first << ", value -> " << i->second << endl; 
		int tmp = i->second;
		if(B.find(i->first) != B.end()) {
 			tmp -= B.at(i->first);
		}
		if(tmp > max) { max = tmp; }
    }

	if(max < 0) { 	
		cout << 0 << endl;
	} else {
		cout << max << endl;
	}
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  ll x,y;
  cin >> x >> y;
  ll k=y/x;
  ll cnt=0;
  while(k!=0){
    k /=2;
    cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <utility>
#include <vector>
#include <string>
using namespace std;

#define gcu getchar_unlocked
#define ii inline int in
#define is inline bool scan
ii(int c) {
	int n = 0;
	bool minus = false; if (c == '-') minus = true, c = gcu();
	do {n = 10 * n + (c - '0'), c = gcu();} while (c >= '0');
	//return n; }
	return minus ? -n : n; }
ii() {return in(gcu());}
is(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);}
is(char &c){c=gcu();gcu();return c!=EOF;}
is(string &s){int c; s = "";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#undef ii
#define pcu putchar_unlocked
template <typename T>
void out(T n) {
	static char buf[20];
	char *p = buf;
	if(n < 0) pcu('-'), n *= -1;
	if (!n) *p++ = '0';
	else while (n) *p++ = n % 10 + '0', n /= 10;
	while (p != buf) pcu(*--p); }
void out(const char *s){while(*s)pcu(*s++);}
void out(char c){pcu(c);}
void out(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail>
void out(head&& h, tail&&... t){out(h);out(move(t)...);}
#undef svo

typedef vector<string> v;

void slip(v &r) {
	int x = 0, y = 0;
	for (;;) {
		char c = r[y][x];
		r[y][x] = 'X';
		switch (c) {
		case '.': out(x, ' ', y, '\n'); return;
		case 'X': out("LOOP\n"); return;
		case '>': x += 1; break;
		case '<': x -= 1; break;
		case 'v': y += 1; break;
		case '^': y -= 1; break;
		}
	}
}

int main() {
	for (int H, W; H = in(), W = in(), H || W;) {
		v r(H);
		for (auto &s: r)
			scan(s);
		slip(r);
	}
}


Measured memory_bytes: 2524
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#include<time.h>
#include<stdlib.h>
#define pb push_back
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ull unsigned long long
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/__gcd((a),(b))
#define clr(x) x.clear()
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vi>
#define mp make_pair
#define hell 1000000007

using namespace std;

int main()
{
    IOS
    int a,p;
    cin>>a>>p;
    cout<<(a*3+p)/2<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

std::map<LL, LL> decomposit_prime(LL n)
{
	LL d = 2;
	std::map<LL, LL>res;
	while (d*d <= n)
	{
		if (n%d == 0)
		{
			++res[d];
			n /= d;
		}
		else ++d;
	}
	++res[n];
	return res;
}

int main()
{
	LL N, P;
	in >> N >> P;

	if (N == 1)
	{
		out << P << std::endl;
		return 0;
	}
	if (P == 1)
	{
		out << 1 << std::endl;
		return 0;
	}
	auto res = decomposit_prime(P);
	LL ans = 1;
	for (auto i : res)
	{
		if (i.second >= N)
		{
			rep(j, i.second / N) ans *= i.first;
		}
	}
	out << ans << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
#define rep(i,n) for(i = 0; i < (n); ++i)
#define rrep(i,n) for(i = 1; i <= (n); ++i)
#define drep(i,n) for(i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
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;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z main.cpp
//./a.exe

bool isPrime(int x){
    int i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}


int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
  int a,b,c,d,e,A,B,C,D,E,last,ans;
  cin >> a >> b >> c >> d >> e;
  A = a%10;
  B = b%10;
  C = c%10;
  D = d%10;
  E = e%10;
  if(A==0){
      A=A+10;
  }
  if(B==0){
      B=B+10;
  }
  if(C==0){
      C=C+10;
  }
  if(D==0){
      D=D+10;
  }
  if(E==0){
      E=E+10;
  }
  last = min({A,B,C,D,E});


  if(A==0){
      A=A-10;
  }
  if(B==0){
      B=B-10;
  }
  if(C==0){
      C=C-10;
  }
  if(D==0){
      D=D-10;
  }
  if(E==0){
      E=E-10;
  }
  ans = a+b+c+d+e+40-A-B-C-D-E+last;
  cout << ans << endl;




//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

const int INF = 1001001001;

int main(){
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i, n) cin >> s.at(i);
  vector<vector<int>> gr(n, vector<int>());
  vector<vector<int>> wf(n, vector<int>(n, 0));
  rep(i, n){
    rep(j, n){
      if(s.at(i).at(j) == '1'){
        gr.at(i).push_back(j);
        wf.at(i).at(j) = 1;
      }else{
        if(i != j) wf.at(i).at(j) = INF;
      }
    }
  }

  vector<int> chk(n, 0);
  chk.at(0) = 1;
  queue<int> q; q.push(0);
  while(!q.empty()){
    int now = q.front(); q.pop();
    for(int i : gr.at(now)){
      if(chk.at(i) == 0){
        chk.at(i) = -1*chk.at(now);
        q.push(i);
      }else{
        if(chk.at(i) == chk.at(now)){
          cout << -1 << endl;
          return 0;
        }
      }
    }
  }

  rep(k, n)rep(i, n)rep(j, n){
    wf.at(i).at(j) = min(wf.at(i).at(j), wf.at(i).at(k)+wf.at(k).at(j));
  }
  int ans = 0;
  rep(i, n)rep(j, n){
    ans = max(ans, wf.at(i).at(j));
  }
  cout << ans+1 << endl;
  return 0;
}

Measured memory_bytes: 4008
#include <stdio.h>
#include <limits.h>

static int maximum(int *x, int s)
{
    int max = INT_MIN;
    for (int i = 0; i < s; ++i) {
        if (x[i] > max) {
            max = x[i];
        }
    }
    return max;
}

static int minimum(int *x, int s)
{
    int min = INT_MAX;
    for (int i = 0; i < s; ++i) {
        if (x[i] < min) {
            min = x[i];
        }
    }
    return min;
}

static int cost(int *x, int c, int s)
{
    if (s <= 0) {
        return 0;
    }
    return (*x - c) * (*x - c) + cost(x + 1, c, s - 1);
}

int main(void)
{
    int n;
    scanf("%d", &n);
    int a[n];
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
    }

    int j = minimum(a, n);
    int k = maximum(a, n);
    int l = k - j + 1;
    int b[l];
    for (int i = 0, c = j; c <= k; ++c, ++i) {
        b[i] = cost(a, c, n);
    }
    printf("%d\n", minimum(b, l));

    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#define ll long long
const int MOD= 1e9 + 7;
const int INF = 1000000005;
using namespace std;

int check(ll x) {
	int ret = 0;
	while (x != 0) {
		x /= 10;
		ret++;
	}
	return ret;
}

int main()
{
	ll n;
	cin >> n;
	int a, b, ans = INF;
	for (ll i = 1; i <= sqrt(n); i++) {
		if (n == (n / i)*i) {
			a = check(i);
			b = check(n / i);
			ans = min(ans, max(a,b));
		}
	}
	cout << ans << endl;
	return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
using ll=long long;
#ifdef ONLINE_JUDGE
#define D(...)
#else
#define D(...)cerr<<__LINE__<<":"<<"["<<#__VA_ARGS__<<"]->",P(__VA_ARGS__)
#endif
void P(){cerr<<endl;} 
template<typename H,typename...T>void P(H h,T...t){cerr<<h<<" ";P(t...);}
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    int n,m,X,Y;
    cin>>n>>m>>X>>Y;
    int maxm=-200;
    for(int i=0,x;i<n;++i){
        cin>>x;
        maxm=max(maxm,x);
    }
    int minm=200;
    for(int i=0,x;i<m;++i){
        cin>>x;
        minm=min(minm,x);
    }
    if(minm>maxm&&Y>=minm&&minm>X){
        cout<<"No War";
    }
    else cout<<"War";
}

Measured memory_bytes: 3612
using System;
class Program
{
 	static void Main(string[] args)
 	{
 		// 整数の入力
 		int X = int.Parse(Console.ReadLine());
 		// スペース区切りの整数の入力
 		if (X == 7 || X == 5 || X == 3) {
  			Console.WriteLine("YES");
		}
  		else {
        	Console.WriteLine("NO");
        }
    }
}

Measured memory_bytes: 13140
II = lambda: int(input())
SI = lambda: input()
LI = lambda: list(map(int,input().split()))
MI = lambda: map(int,input().split())
n = II()
d = [[0,0,0] for i in range(n)]
for i in range(n):
	a,b,c = MI()
	if i == 0:
		d[0][0] = a
		d[0][1] = b
		d[0][2] = c
	else:
		d[i][0] = max(d[i-1][1],d[i-1][2])+a
		d[i][1] = max(d[i-1][0],d[i-1][2])+b
		d[i][2] = max(d[i-1][1],d[i-1][0])+c
print(max(d[-1]))

Measured memory_bytes: 86696
# -*- coding: utf-8 -*-
a, b, c, d = map(int, raw_input().split())

flag = False
if abs(a - c) <= d:
    flag = True
elif abs(a - b) <= d and abs(c - b) <= d:
    flag = True



if flag:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 2568
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {

  public static void main(String[] args) {
    solve(System.in, System.out);
  }

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */
    int n = sc.nextInt();
    int k = sc.nextInt();
    int[] a = new int[n];

    for (int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
    }

    SortedSet<Integer> set = new TreeSet<>();

    // find already k-length ordered segment
    Set<Integer> orderedIndexes = new HashSet<>();
    int l = 0;
    int r = 1;
    for (l = 0; l < n; l++) {
      if (l == r) r++;
      while (r < n && a[r - 1] < a[r]) r++;
      if (k == r - l) orderedIndexes.add(l);
    }

    for (int i = 0; i < k; i++) {
      set.add(a[i]);
    }

    int res = n - k + 1;

    for (int i = 0; i < n - k; i++) {
      int min = set.first();
      int max = set.last();
      set.remove(a[i]);
      set.add(a[i + k]);
      if (min == a[i] && max < a[i + k]) res--;
    }

    if (orderedIndexes.size() > 1) {
      res -= orderedIndexes.size() - 1;
    }

    os.println(res);

  }

}

Measured memory_bytes: 94396