akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        Work[] arr = new Work[n];
        for (int i = 0; i < n; i++) {
            arr[i] = new Work(sc.nextInt(), sc.nextInt());
        }
        Arrays.sort(arr);
        TreeSet<Integer> set = new  TreeSet<>();
        for (int i = 0; i < m; i++) {
            set.add(i);
        }
        set.add(Integer.MIN_VALUE); //dummy
        long total = 0;
        for (Work w : arr) {
            int d = m - w.day;
            d = set.floor(d);
            if (d ==Integer.MIN_VALUE) {
                continue;
            }
            total += w.income;
            set.remove(d);
        }
        System.out.println(total);
    }
    
    static class Work implements Comparable<Work>{
        int day;
        int income;
        
        public Work(int day, int income) {
            this.day = day;
            this.income = income;
        }
        
        public int compareTo(Work w) {
            if (income == w.income) {
                return w.day - day;
            } else {
                return w.income - income;
            }
        }
    }
}


Measured memory_bytes: 98732
N = int(input())
syougen = []
for i in range(N):
    s = []
    A = int(input())
    for _ in range(A):
        x, y = map(int, input().split())
        s.append((x-1, y))
    syougen.append(tuple(s))
# print(syougen)
ans = 0
for i in range(2**N):
    real = []
    flg = True
    for j in range(N):
        if ((i >> j) & 1):
             real.append(j)
    for hito in real:
        for x, y in syougen[hito]:
            if (y == 0 and x in real) or (y == 1 and x not in real):
                flg = False
                break
    if flg:
        ans = max(ans, len(real))
print(ans)


Measured memory_bytes: 3064
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {
    static final int MOD = 1000000007;
    static final int INF = 1 << 30;

    Main() {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        String[] pic = new String[H];
        for (int i = 0; i < H; i++) {
            pic[i] = sc.next();
        }

        for (int i = -2; i < W; i++)
            System.out.print('#');
        System.out.println();
        for (int i = 0; i < H; i++) {
            System.out.println('#' + pic[i] + '#');
        }

        for (int i = -2; i < W; i++)
            System.out.print('#');
        System.out.println();
    }

    public static void main(String[] args) {
        new Main();
    }
}


Measured memory_bytes: 21844
#include<stdio.h>
#include<algorithm>
using namespace std;
typedef long long lld;
typedef pair<int,int> pii;

lld n,k,fin;
int main(){
    scanf("%lld%lld",&n,&k);
    for(lld b=k+1;b<=n;b++){
        lld p=(n-b+1)/b,r=max(n-b*(p+1)-k+1,0ll);
        if(k==0) fin--;
        fin+=(p+1)*(b-k)+r;
        //printf("%lld %lld %lld %lld\n",b,p,r,(p+1)*(b-k)+r);
    }
    printf("%lld\n",fin);
    return 0;
}


Measured memory_bytes: 128
from sys import stdin
def S(): return stdin.readline().rstrip()

a = S()
strl = ['dream','dreamer','erase','eraser']
t = ''
for i in range(len(a)-1,-1,-1):
    if 7<len(t):
        print('NO')
        exit()
    else:
        t = a[i]+t
        if t in strl:
            t = ''

print('YES')

Measured memory_bytes: 3316
/*
...........__________    							 |										    ___  __
.............|       |     						     |											 |   /
.............|       |     						     |									  		 |  /
.............|       |                               |                         __                | /      _______
.............|_______|  _______            _______   |______   ________   /|  /  |               |/       |      |
.............| \               | |      | |          |      |          | / | /   |               |\       |
.............|  \       _______| |      | |_______   |      |   _______|   |/    |               | \      |
.............|   \      |      | |      |         |  |      |  |       |   |     |               |  \     |
.........  __|    \__|  |______| |______| ________|  |      |_ |_______|   |     |__|           _|   \__ _|        .

*/
#include<bits/stdc++.h>
using namespace std ;
#define int 				long long
#define ull 				unsigned long long int
#define ld 					long double
#define vi 					vector<int>
#define vii 				vector<pair<int,int>>
#define vvi 				vector<vector<int>>
#define pf 					push_front
#define popb 				pop_back
#define pb 					push_back
#define eb 					emplace_back
#define pii 				pair<int,int>
#define prec(x) 			fixed<<setprecision(15)<<x
#define all(x) 				x.begin(),x.end()
#define rall(x) 			x.rbegin(),x.rend()
#define mset(a,b) 			memset(a,b,sizeof(a))
#define mcpy(a,b) 			memcpy(a,b,sizeof(a))
#define fo0(i,n) 			for(int i=0,i##end=n;i<i##end;i++)
#define fo1(i,n) 			for(int i=1,i##end=n;i<=i##end;i++)
#define fo(i,a,b) 			for(int i=a,i##end=b;i<=i##end;i++)
#define foe(i,x)			for(__typeof((x).end())i=(x).begin();i!=(x).end();++i)
#define fre(i,x)			for(__typeof((x).rend())i=(x).rbegin();i!=(x).rend();++i)
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0)
#define inf 1e18
const int mod=1e9+7;
const int N=4e5+10;

void raushan_kumar(){
	char c;
	int a,b;cin>>a>>c>>b;
	if(c=='+'){
		cout<<a+b;
	}
	else{
		cout<<a-b;
	}
}

int32_t main()
{
	fast;int t=1;
	//cin>>t;
	while(t--){
		raushan_kumar();
	}

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define N 2000 + 5
#define M 4000000 + 5
#define Mod 1000000007
#define rep(i, l, r) for(int i = l; i <= r; ++i)
#define dep(i, l, r) for(int i = r; i >= l; --i)
int n, k, f[M], inv[M], dp[N][N];
int read(){
    char c; int x = 0, f = 1;
    c = getchar();
    while(c > '9' || c < '0'){ if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int Inc(int a, int b){ return (a += b) >= Mod ? a - Mod : a;}
int Mul(int a, int b){ return 1ll * a * b % Mod;}
int Qpow(int a, int b){
    int ans = 1;
    while(b){
        if(b & 1) ans = Mul(ans, a);
        a = Mul(a, a), b >>= 1;
    }
    return ans;
}
int C(int n, int m){
    if(m > n) return 0;
    return Mul(f[n], Mul(inv[m], inv[n - m]));
}
int main(){
    n = read(), k = read();
    if(k == 1){ puts("1"); return 0;}
    f[0] = inv[0] = 1;
    rep(i, 1, M - 5) f[i] = Mul(f[i - 1], i);
    inv[M - 5] = Qpow(f[M - 5], Mod - 2);
    dep(i, 1, M - 6) inv[i] = Mul(inv[i + 1], i + 1);
    dp[0][0] = 1;
    rep(i, 1, n) rep(j, 0, i){
        dp[i][j] = Inc(dp[i][j], dp[i - 1][j]);
        if(j >= 1) dp[i][j] = Inc(dp[i][j], Mul(dp[i][j - 1], C(n * k - i - (j - 1) * (k - 1) - 1, k - 2)));
    }
    printf("%d", Mul(dp[n][n], f[n]));
    return 0;
}

Measured memory_bytes: 46336
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <bitset>
#include <cmath>
#include <stack>
#include <iomanip>
#include <map>
#include <math.h>
#include <list>
#include <deque>
typedef long long ll;
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; }
ll MOD = 1000000007;
ll INF = 1LL << 60;

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll LCM(ll a, ll b) {return a / GCD(a, b) * b;}

int main()
{
    ll x;
    cin >> x;
    ll roop = x/11;
    ll rest = x%11;
    int count = 0;
    if(rest > 0) rest -= 6,count++;
    if(rest > 0) rest -= 5,count++;
    cout << roop * 2 + count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll modinv(ll a, ll m) {ll b = m, u = 1, v = 0;while (b) {ll t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
const int INF = 1e9;
const ll LLINF = 1e16;

int main(void)
{
    ll a,b,n;
    cin >> a >> b >> n;
    ll ans = 0;
    ll aho = min(n, b - 1);
    cout << floor(a * aho / b) - a * floor(aho / b) << endl;

    return 0;
}

Measured memory_bytes: 3788
import sys
from collections import deque

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = [deque(lr()) for _ in range(N)]
answer = 0
match = 0
candidate = list(range(N))
while True:
    used = set()
    bool = False
    c = []
    for i in candidate:
        if len(A[i]) == 0:
            continue
        op = A[i][0] - 1
        if op in used or i in used:
            continue
        if A[op][0] - 1 == i:
            used.add(i)
            used.add(op)
            match += 1
            c.extend([i, op])
            bool = True
            A[i].popleft()
            A[op].popleft()
    
    answer += 1
    candidate = c
    if match == N * (N-1) // 2:
        break
    if not bool:
        print(-1)
        exit()

print(answer)


Measured memory_bytes: 71772
#include<cstdio>

int A[100000],n;

int binarysearch(int key){
  int left=0,right=n,mid;
  while(left<right){
    mid = (right+left)/2;
    
    if(key==A[mid]){
      return 1;
    }else if(key<A[mid]){
      right = mid;
    }else if(key>A[mid]){
      left = mid+1;
    }
  }
  return 0;
}

int main() {
  scanf("%d",&n);
  
  
  for(int i=0;i<n;i++){
    scanf("%d",A+i);
  }
  
  int q;
  scanf("%d",&q);
  
  int key,sum=0;
  for(int i=0;i<q;i++){
    scanf("%d",&key);
    if(binarysearch(key)){
      sum++;
    }
  }
  
  printf("%d\n",sum);
  
  return 0;
}

Measured memory_bytes: 2960
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define ve(i) vector<i>
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define pr(n) cout << fixed << setprecision(n)
#define ci(n) cin >> n
#define ci2(n, o) cin >> n >> o
#define ci3(n, o, p) cin >> n >> o >> p
#define co(n) cout << n << endl

int main() {
  int N, D, a = 0;
  ci2(N, D);
  wh(N > 0) {
    N -= 1 + D * 2;
    a++;
  }
  co(a);
} 

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
int main() {
	
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	int N,M;

	scanf("%d %d", &N,&M);

	if (N%M == 0) {
		printf("0");
	}
	else {
		printf("1");
	}
	
}

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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define mod 1000000007;

typedef long long ll; 
typedef pair<int, int> ii; 
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;

// Print fn to print array
int gcd(int a, int b){
	if(a%b==0) return b;
	return gcd(b,a%b);
}

int gcd3(int a, int b, int c){
	return gcd(gcd(a,b),c);
}

int main(){
	int n;
	cin >> n;
	int res = 0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			for(int k=1;k<=n;k++){
				res+=(gcd3(i,j,k));
			}
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios::sync_with_stdio(false);
	int n,m;
	cin >> n>>m;
	if (n == 1&&m==1)
	{
		cout << "0";
	}
	else
	{
		int ans=0;
		ans += (n * (n-1) / 2 + m * (m -1) / 2);
		cout << ans;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a)%MOD)+((b)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define EPS (1e-20)
#define INF 214748364700000
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using VLL = std::vector<llint>;
using MCI = std::map<char, int>;
using namespace std;


struct WUF {
	VI par;
	VI rank;
	VI diffWeight;

	WUF(){}
	void init(int n){
		par.resize(n);
		rank.resize(n);
		diffWeight.resize(n);
		iota(ALL(par), 0);
	}
	int root(int x){
		if(par[x] == x) return x;
		int r = root(par[x]);
		diffWeight[x] += diffWeight[par[x]];
		return par[x] = r;
	}
	int weight(int x){
		root(x);
		return diffWeight[x];
	}
	bool same(int x, int y){
		return root(x) == root(y);
	}
	bool unite(int x, int y, int w){
		w += weight(x), w -= weight(y);
		x = root(x), y = root(y);
		if(x == y) return false;
		if(rank[x] < rank[y]) swap(x, y), w = -w;
		if(rank[x] == rank[y]) rank[x]++;
		par[y] = x;
		diffWeight[y] = w;
		return true;
	}
	int diff(int x, int y){
		return weight(y)-weight(x);
	}
};


int N, M;
WUF uf;


signed main(){
	cin >> N >> M;
	uf.init(N);
	rep(i, 0, M){
		int L, R, D;
		cin >> L >> R >> D, L--,  R--;
		if(uf.same(L, R)){
			if(uf.diff(L, R) != D){
				No;
				return 0;
			}
		}
		else uf.unite(L, R, D);
	}
	
	Yes;

	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N; 
  cin >> N ;
  vector<int> vec1(N-1);
  vector<int> vec2(N);
  for (int i = 0; i < N-1; i++) {
    cin >> vec1.at(i);
} 
  for (int i = 0; i < N-1; i++){
    vec2.at(vec1.at(i)-1)++;
  }
  for (int i = 0; i < N; i++){
    cout << vec2.at(i) << endl;
  }
}

Measured memory_bytes: 4840
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <fstream>


using namespace std;
const int MOD = 1000000009; // check!!!
const int INF = 100000000; //1e8

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;

#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)(c).size())
#define ten(x) ((int)1e##x)
#define tenll(x) ((ll)1e##x)

struct P{
	int x,y;
	P(){}
	P(int x,int y) : x(x),y(y){}
	bool operator <(const P& p) const { return y != p.y ? y > p.y : x < p.x; }
};

int main(){
	int n; cin>>n;
	vector<P> v(n);
	FOR(i,n) cin>>v[i].x>>v[i].y;
	sort(v.begin(),v.end());
	printf("%d %d\n",v[0].x,v[0].y);

	return 0;
}

Measured memory_bytes: 1180
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include<bits/stdc++.h>
using namespace std;
using ll=int_fast64_t;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

class DIncenters {
public:
    void solve(istream& in, ostream& out) {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        long double x=0,y=0;
        int n,l;
        in>>n>>l;
        long double pi=atan(1)*4/l;
        vector<int> t(n);
        for(auto&i:t) in>>i;
        fr(i,n){
            fr(j,i){
                x+=(n-i+j-1)*cos(pi*(t[i]+t[j]));
                y+=(n-i+j-1)*sin(pi*(t[i]+t[j]));
                x-=(i-j-1)*cos(pi*(t[i]+t[j]));
                y-=(i-j-1)*sin(pi*(t[i]+t[j]));
            }
        }
        x/=(ll)n*(n-1)*(n-2)/6,y/=(ll)n*(n-1)*(n-2)/6;
        if(abs(x)<1e-12) x=0;
        if(abs(y)<1e-12) y=0;
        out<<setprecision(15)<<x<<" "<<y<<endl;
    }
};

int main() {
    DIncenters solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


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

int main(){
    long long x;
    long long y;
    long long z;
    long long n;
    long long a;
    long long b;
    cin >> n >> a >> b;
    y = n % (a+b);
    z = n - y;
    y = z / (a+b);
    x = n - y * (a+b); 
    if(x > a){
        x = a;
    }
    x += y * a;
    cout << x << endl;
    return 0;

}

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

int main() {
  string s;
  while (cin >> s) {
    int ans1 = 0, ans2 = 0;
    for (int i = 2; i < s.size(); i++) {
      if (s.substr(i - 2, 3) == "JOI") ans1++;
      if (s.substr(i - 2, 3) == "IOI") ans2++;
    }
    cout << ans1 << endl << ans2 << endl;
  }
  return 0;
}


Measured memory_bytes: 3172
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main() {
    int k,n;
    cin>>k>>n;
    vector<int> a(n);
    rep(i,n) cin>>a[i];
    int l=0;
    rep(i,n){
        if(i==n-1) l=max(l,k-a[i]+a[0]);
        else l=max(l,a[i+1]-a[i]);
    }
    cout<<k-l<<endl;
}


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

int main() {
    string s;
    cin >> s;
    if (s[0] == 'R' && s[1] == 'R' && s[2] == 'R') cout << 3 << endl;
    else if (s[0] == 'R' && s[1] == 'R' && s[2] != 'R') cout << 2 << endl;
    else if (s[0] != 'R' && s[1] == 'R' && s[2] == 'R') cout << 2 << endl;
    else if (s[0] != 'R' && s[1] != 'R' && s[2] != 'R') cout << 0 << endl;
    else cout << 1 << endl;
}

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

signed main() {
  ios::sync_with_stdio(false);

  int N, Q;
  cin >> N >> Q;

  vector<int> A(N);
  for (int i = 0; i < N; ++i) cin >> A[i];
  if (N & 1) ++N, A.insert(A.begin(), 0);

  vector<int> X(Q);
  for (int i = 0; i < Q; ++i) cin >> X[i];

  vector<vector<int64_t>> pa(2, vector<int64_t>(N + 1));
  for (int t = 0; t < 2; ++t)
    for (int i = 0; i < N; ++i)
      pa[t][i + 1] = pa[t][i] + ((i & 1) == t) * A[i];

  for (int i = 0; i < Q; ++i) {
    if (N < 4) {
      assert(N == 2);
      cout << A[1] << endl;
    } else if (A[N - 3] <= X[i]) {
      if (abs(A[N - 2] - X[i]) < X[i] - A[N - 3]) {
        cout << pa[1][N] << endl;
      } else {
        int k = N - 4;
        cout << pa[~N & 1][k] +
                (pa[0][N] + pa[1][N]) -
                (pa[0][N + k >> 1] + pa[1][N + k >> 1])
             << endl;
      }
    } else {
      int k = N - 4;
      // while (2 <= k && abs(A[k - 2] - X[i]) <= abs(A[k] - X[i])) k -= 2;
      int lb = 0, ub = k;
      k = -1;
      while (lb <= ub) {
        int mb = lb + ub >> 1;
        if (N - mb & 1) ++mb;
        int q = mb + (N - mb >> 1);
        vector<int> v;  {
          v.push_back(A[mb]);
          v.push_back(A[q - 1]);
          if (2 < q - mb) v.push_back(A[mb + 1]);
          if (2 < q - mb) v.push_back(A[q - 2]);
          sort(v.begin(), v.end(), [&](int x, int y) {
            return make_pair(abs(X[i] - x), x) > make_pair(abs(X[i] - y), y);
          });
        }
        int a = v[1];
        int b = A[q];
        if (abs(X[i] - b) < abs(X[i] - a)) {
          lb = mb + 2;
        } else {
          k = mb;
          ub = mb - 2;
        }
      }
      cout << pa[~N & 1][k] +
              (pa[0][N] + pa[1][N]) -
              (pa[0][N + k >> 1] + pa[1][N + k >> 1])
           << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 4080
#include<cstdio>
using namespace std;
int X,ans=1;
bool visit[1001];
int main()
{
	scanf("%d",&X);
	visit[1]=true;
	for(int i=2;i<=31;i++)
	{
		ans=i;
		for(int j=2;ans*i<=X;j++)
		{
			ans*=i;
			visit[ans]=true;
		}
	}
	for(int i=X;i>=1;i--)
	{
		if(visit[i])
		{
			printf("%d",i);
			return 0;
		}
	}
}

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

int main(){
  int m, f, r;

  while(1){
    cin >> m >> f >> r;
    if(m == -1 && f == -1 && r == -1){
      break;
    }
    if(m == -1 || f == -1){
      cout << "F" << endl;
    } else if(m+f >= 80){
      cout << "A" << endl;
    } else if(m+f >= 65 && m+f < 80){
      cout << "B" << endl;
    } else if(m+f >= 50 && m+f < 65){
      cout << "C" << endl;
    } else if(m+f >= 30 && m+f < 50){
      if(r >= 50){
        cout << "C" << endl;
      } else {
        cout << "D" << endl;
      }
    } else {
      cout << "F" << endl;
    }
  }
}



Measured memory_bytes: 3096
#include<stdio.h>
int main(){
int n=0;
int m=0;
long h[100000]={0};
int t[100000]={0};
int a,b=0;
int sum=0;
scanf("%d %d",&n,&m);

for(int i=0;i<n;i++){
    scanf("%ld",&h[i]);
}

    for(int j=0;j<m;j++){
        scanf("%d %d",&a,&b);
       if(h[a-1]>h[b-1]){
           t[b-1]=1;
        //    printf("%dnokati\n",a);
       }else if(h[a-1]<h[b-1]){
           t[a-1]=1;
        //    printf("%dnokati\n",b);
       }else{
           t[a-1]=1;
           t[b-1]=1;
        //    printf("hikiowake\n");
       }
    }

for(int i=0;i<n;i++){
    if(t[i]==0){
        sum++;
        // printf("%d",i+1);
    }

}

printf("%d",sum);
return 0;

}

Measured memory_bytes: 2880
#include <cstdio>
int main() 
{
	long long n, ans, t;
	scanf("%lld", &n);
	if(n & 1){
		puts("0");return 0;
	}
	ans = t = n / 10;
	while(t /= 5) ans += t;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int t, k, n, a, b, c, d;
int read()
{
	int num = 0;
	char c = getchar();
	while (c<'0' || c>'9')c = getchar();
	while (c >= '0' && c <= '9')num = num * 10 + c - '0', c = getchar();
	return num;
}
int main()
{
	t = read();
	for (int lp = 1; lp <= t; lp++)
	{
		a = read();
		b = read();
		c = read();
		d = read();
		n = a + b;
		k = (max(a, b) - 1) / (min(a, b) + 1) + 1;
		int l = 0, r = n + 1;
		while (l < r) {
			int mid = (l + r) >> 1;
			if ((b - mid / (k + 1)) <= 1ll * (a - mid / (k + 1) * k - mid % (k + 1)) * k)
				l = mid + 1;
			else r = mid;
		}
		r = l + (b - l / (k + 1)) - (a - l / (k + 1) * k - l % (k + 1)) * k + 1;
		for (int i = c; i <= min(d, l); i++)
			putchar(i % (k + 1) ? 'A' : 'B');
		for (int i = max(c, l + 1); i <= d; i++)
			putchar((i - r) % (k + 1) ? 'B' : 'A');
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 384
t,h = 0,0
gets.to_i.times.each{
  c = gets.split
  if c[0] > c[1] then
    t += 3
  elsif c[0] == c[1] then
    t,h = t+1,h+1
  else
    h += 3
  end
}
puts [t,h]*" "

Measured memory_bytes: 6112
from sys import exit, stderr, stdin
input = stdin.readline
# setrecursionlimit(10**7)

def debug(var, name="hoge"):
    print(name +":" + str(type(var)) + " = " + repr(var), file=stderr)
    return

def gau(n):
    return n*(n+1)//2

def main():
    N = int(input())
    if (N==1):
        print(0)
    else:
        print(gau(N-1))

if __name__ == "__main__":
    main()


Measured memory_bytes: 38384
#include <cstdio>
#include <cstring>

template<typename T>
inline int chkmin(T &x, T y) {
  return x > y ? x = y, 1 : 0;
}

const int MAXN = 500;

int n;
int A[MAXN + 9][MAXN + 9];

long long sum[2][MAXN + 9][MAXN + 9];

void Calc_Sum() {
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      sum[0][i][j] += sum[0][i][j - 1];
      sum[1][i][j] += sum[1][i][j - 1];
    }
    for (int j = 1; j <= n; ++j) {
      sum[0][i][j] += sum[0][i - 1][j];
      sum[1][i][j] += sum[1][i - 1][j];
    }
  }
}

long long dp[MAXN + 9][MAXN + 9];

inline long long cost(int opt, int lx, int rx, int ly, int ry) {
  return sum[opt][rx][ry] - sum[opt][lx - 1][ry] - sum[opt][rx][ly - 1] + sum[opt][lx - 1][ly - 1];
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) 
    for (int j = 1; j <= n; ++j)
      if (i != j) {
        scanf("%d", &A[i][j]);
        i < j ? sum[0][i][j] = A[i][j] : sum[1][i][j] = A[i][j]; 
      }

  Calc_Sum();

  memset(dp, 0x3f, sizeof dp);
  dp[0][0] = 0;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < (!i ? 1 : i); ++j)
      for (int k = i + 1; k <= n; ++k)
        chkmin(dp[k][i], dp[i][j] + cost(1, k + 1, n, j + 1, i) + cost(0, i + 1, k, i + 1, k));

  long long ans = 0x3f3f3f3f3f3f3f3fLL;
  for (int i = 0; i <= n; ++i) chkmin(ans, dp[n][i]);

  printf("%lld\n", ans);

  return 0;
}

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

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

    bool turn = true;
    while (0 < a && 0 < c) {
        if (turn) c -= b;
        else a -= d;
        turn = !turn;
    }

    cout << (a <= 0 ? "No" : "Yes") << endl;
}



Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;

struct mint {
   ll x;
   mint(ll x = 0) { (this->x = (x + MOD)) %= MOD; }
   mint operator-() const { return mint(-x); }
   mint& operator+=(const mint a) {
      if ((this->x += a.x) >= MOD) x -= MOD;
      return *this;
   }
   mint& operator-=(const mint a) {
      if ((this->x += MOD - a.x) >= MOD) this->x -= MOD;
      return *this;
   }
   mint& operator*=(const mint a) {
      (this->x *= a.x) %= MOD;
      return *this;
   }
   mint operator+(const mint a) const {
      mint res(*this);
      return res += a;
   }
   mint operator-(const mint a) const {
      mint res(*this);
      return res -= a;
   }
   mint operator*(const mint a) const {
      mint res(*this);
      return res *= a;
   }
   mint pow(ll t) const {
      if (!t) return 1;
      mint a = pow(t >> 1);
      a *= a;
      if (t & 1) a *= *this;
      return a;
   }
   mint inv() const { return pow(MOD - 2); }
   mint& operator/=(const mint a) { return *this *= a.inv(); }
   mint operator/(const mint a) const {
      mint res(*this);
      return res /= a;
   }
};
istream& operator>>(istream& is, mint& a) {
   return is >> a.x;
}
ostream& operator<<(ostream& os, const mint& a) {
   return os << a.x;
}
struct combination {
   vector<mint> fact, ifact;
   combination(int n) : fact(n + 1), ifact(n + 1) {
      assert(n < MOD);
      fact[0] = 1;
      for (int i = 1; i <= n; ++i)
         fact[i] = fact[i - 1] * i;
      ifact[n] = fact[n].inv();
      for (int i = n; i >= 1; --i)
         ifact[i - 1] = ifact[i] * i;
   }
   mint operator()(int n, int k) {
      if (k < 0 || k > n) return 0;
      return fact[n] * ifact[k] * ifact[n - k];
   }
   mint p(int n, int k) { return fact[n] * ifact[n - k]; }
} comb(200005);

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

   int n, m, k;
   cin >> n >> m >> k;
   mint ans = 0;
   rep(dx, 0, m) {
      mint res = mint(dx) * mint(m - dx);
      res = res * mint(n) * mint(n);
      ans += res;
   }
   rep(dy, 0, n) {
      mint res = mint(dy) * mint(n - dy);
      res = res * mint(m) * mint(m);
      ans += res;
   }
   ans *= comb(n * m - 2, k - 2);
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 6240
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
     ll n;string s;cin>>n>>s;
     ll a;a=0;
           rep(i,n-2){
                      if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
                                                               a++;
                                                              }
                      else{a=a;}                                        
                     }
                cout<<a<<endl;
}




Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin >> n;
    vector<int>a(n);
    for(int i =0;i<n;i++){
        cin >> a[i];
    }
    int cnt =0;
    for(int i = 0;i < n-2;i++){
        
        if(a[i] < a[i+1]&&a[i+1] < a[i+2]||a[i+2] < a[i+1]&&a[i+1] < a[i]){
            cnt++;
        }
    }
    
    cout << cnt;
    
    
    
}


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

n = int(input())
A = list(map(int,input().split()))

B = [0] * (max(A)+1)
C = []
for i in range(n):
    B[A[i]] += 1

C = A[:]
C.sort()
D = [0] * (10**6+5)

ans = 0
for i in range(len(C)):
    # print(C[i])
    if D[C[i]] == 0 and B[C[i]] == 1:
        ans += 1
    j = C[i]
    D[j] = 1
    if i==0 or C[i-1] != C[i]:
        while j < len(D):
            D[j] = 1
            j += C[i]
print(ans)

Measured memory_bytes: 101256
import java.util.Scanner;


public class Main {


//	final int MOD = 1000000007;

//	public static int max = 0;

	public static void main(String[] args) {

		int ans = 0;
		Scanner sc = new Scanner(System.in);
		boolean f = false;

//		int n = sc.nextInt();
//		int m = sc.nextInt();
		String string = sc.next();

//		int[] ans = new int[n];

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

		if(string.equals("ABC") ) {
			f = false;
		} else {
			f = true;
		}

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

//		for(int i = 0; i < n; i++) {
//			System.out.println(ans[i]);
//		}

		if(f) {
			System.out.println("ABC");
		} else {
			System.out.println("ARC");
		}

//		System.out.println(ans);

		sc.close();
	}
}

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

int main(){
        
    int N;
    cin >> N;
    long long A[N];
    for(int i = 0; i < N;i++)cin >> A[i];
    sort(A,A+N);
    
    long long ans = 0;
    long long sum = 0;
    for(int i = 0; i < N;i++){
        
        if(sum*2<A[i]){
            ans = 0;
        }
        sum += A[i];
        ++ans;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 1024
#include "stdio.h"

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

#define INF 300002

struct segtree {
    int l;
    int r;
    int max;
} tree[300010 * 4];

int dp[300010];
int seq[300010];

int modify(int i, int dis, int val) {
    if (tree[i].l == tree[i].r) {
        tree[i].max = val;
        return 0;
    }    
    int mid = (tree[i].l + tree[i].r) >> 1;
    if (dis > mid) modify(2 * i + 1, dis, val);
    else modify(2 * i, dis, val);
    if (tree[i].max < val) tree[i].max = val;
    return 0;    
}

int search(int i, int l, int r) {
    if (tree[i].l >= l && tree[i].r <= r)
        return tree[i].max;
    int m = (tree[i].l + tree[i].r) >> 1;
    int x = 0, y = 0;
    if (m >= l) x = search(i * 2, l, r);
    if (m < r) y = search(i * 2 + 1, l, r);
    return MAX(x, y);      
}

int build(int i, int l, int r) {
    tree[i].l = l;
    tree[i].r = r;
    tree[i].max = 0;
    if (l == r) return 0;
    int mid = (l + r) >> 1;
    build(2 * i, l , mid);
    build(2 * i + 1, mid + 1, r);
    return 0;
}

int main() {
        int N, K;
        scanf("%d", &N);
        scanf("%d", &K);
        int max = 0, min = INF;
        for (int i = 0; i < N; i++) {
            scanf("%d", &seq[i]);
            max = MAX(seq[i], max);
            min = MIN(seq[i], min); 
        }    
        build(1, min, max);    
        dp[0] = 1;
        modify(1, seq[0], dp[0]);
        int res = 0;
        for (int i = 1; i < N; i++) {
             dp[i] = search(1, seq[i] - K, seq[i] + K) + 1;
             modify(1, seq[i], dp[i]);
             if (dp[i] > res) res = dp[i];  
        }
        printf("%d", res);       
}

Measured memory_bytes: 16332
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

int main() {
  ll n;
  cin>>n;
  vector<string> vs;
  rep(i,0,n){
    string s;
    cin>>s;
    sort(all(s));
    vs.pb(s);
  }
  vs.pb("{{{");
  sort(all(vs));
  ll ans = 0;
  ll c = 0;
  rep(i,0,vs.sz-1){
    if(vs[i]==vs[i+1]){
      c++;
    }
    else{
      ans += c*(c+1)/2;
      c = 0;
    }
  }
  cout << ans << endl;
  return 0;
}

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

typedef long long ll;
//loop
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//STL
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

//const
#define MOD 1000000007 //10^9+7:合同式の法

//acronym
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

void Main() {
    int n;
    cin >> n;

    ll ans = 0;
    REP(i,n) {
        int a = i + 1;
        if (!(a % 5 == 0) && !(a % 3 == 0)) ans += (ll)a;
    }
    cout << ans << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    Main();
    return 0;
}


Measured memory_bytes: 3604
import java.util.Scanner;

public class Main {

  /**
   * @param args
   */
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String[] S = sc.next().split("");


    boolean flag = true;
    for (int i = 0; i < S.length; i++) {
      if (i == 0 || i % 2 == 0) {
        if (S[i].equals("R") || S[i].equals("U") || S[i].equals("D")) {
          continue;
        } else {
          flag = false;
          break;
        }
      } else if (i % 2 != 0) {
        if (S[i].equals("L") || S[i].equals("U") || S[i].equals("D")) {
          continue;
      } else {
        flag = false;
        break;
      }
    }

    }
    if (flag)
      System.out.println("Yes");
    else
      System.out.println("No");
  }
}




Measured memory_bytes: 25172
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let mut a = vec![];
    for i in 0..n {
        a.push(read::<i64>());
    }
    let mv = a.iter().cloned().max().unwrap();
    let mut a2 = vec![];
    let mut count = 0;
    for i in 0..n {
        if a[i] == mv {
            count += 1;
        } else {
            a2.push(a[i]);
        }
    }
    if count >= 2 {
        for i in 0..n {
            println!("{}", mv);
        }
    } else {
        for i in 0..n {
            if a[i] != mv {
                println!("{}", mv);
            } else {
                println!("{}", a2.iter().max().unwrap());
            }
        }
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 10548
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vb = vector<bool>;
using vs = vector<string>;
using vp = vector<pii>;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (ll)((x).size())
#define all(x) (x).begin(), (x).end()
#define each(a, x) for (auto&& a : (x))
#define _overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) rep2(_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, n) rep4(i, a, n, 1)
#define rep4(i, a, n, s) for (ll i = (a); i < (n); i += (s))
#define rep(...) _overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
const int INF = 1e9;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
template<typename T> inline void print(const T& x) {cout << x << "\n";}
template<typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template<typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
struct Init {Init() {cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10);}} init;

int main() {
    ll n; cin>>n;
    vi a(n); rep(i,n) cin>>a[i];
    sort(all(a), greater<ll>());
    ll total = a[0];
    rep(i,1,n-1) {
        total += a[(i+1)/2];
    }
    print(total);
}

Measured memory_bytes: 4768
s = input()
l = "keyence"
if s[0:7] == l:
    print("YES")
elif s[-7:] == l:
    print("YES")
else:
    for i in range(7):
        if s[:i+1] == l[:i+1] and s[i-6:] == l[i+1:]:
            print("YES")
            exit()
    print("NO")

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

#define ll long long
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define si set<int>
#define sl set<long long>
#define pq prioirty_queue
#define all(v) v.begin(),v.end()
#define left (2*idx)+1
#define right (2*idx)+2
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);

const ll N = (ll)(1e5 + 7);
const ll MOD = (ll)(1e9 + 7);

int main()
{
    FIO;

    int a, b;
    cin >> a >> b;
    cout << max(a+b, max(a-b, a*b)) << "\n";
}


Measured memory_bytes: 256
function main()
    N,K=parse.(Int64,split(readline()))
    S=readline()
    cnt_dif=0
    for i=1:length(S)-1
        if S[i]!=S[i+1]
            cnt_dif+=1
        end
    end
    println(N-1-max(cnt_dif-2*K,0))

end

main()

Measured memory_bytes: 173328
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
using namespace std;
using ll = long long;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[10000001];
//char str[1010][1010];
//vector<pair<int,int> > pc[100001];
//int ABS(int a){return max(a,-a);}
int main(){
	int a,b;
	cin>>a>>b;
	cout<<(a+b+1)/2<<endl;
	return 0;
}

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

const int INF = 2e9;

int main(){
    int n,a,b,c,d;
    cin >> n >> a >> b >> c >> d;
    string s;
    cin >> s;
    int p = 0;
    for(int i = a;i < max(c,d);i++){
        if(s[i] == '#' && s[i-1] == '#'){
            p++;
            break;
        }
    }
    if(d < c){
        p++;
        for(int i = b;i <= d;i++){
            if(s[i] == '.' && s[i-1] == '.' && s[i-2] == '.'){
                p--;
                break;
            }
        }
    }
    if(p == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
/* ------------------------------------------------ */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ------------------------------------------------ */
int main() {
    long double a, b, c;
    cin >> a >> b >> c;
    if(4 * a * b < c * c + a * a + b * b + 2 * (a * b - b * c - c * a ) && c - a - b >= 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3684
import collections

N,Q=map(int,input().split())
M=[[] for i in range(N+1)]
P=[0 for i in range(N+1)]
for i in range(N-1):
  a,b=map(int,input().split())
  M[a].append(b)
  M[b].append(a)
#print("M:",M)

S=[0 for i in range(N+1)]
for i in range(Q):
  p,x=map(int,input().split())
  S[p]+=x
#print(S)
  
d=collections.deque([1])

while len(d):
  dd=d.popleft()
  if P[dd]==0:
    P[dd]=1
    for i in M[dd]:
      if P[i]==0:
        S[i]+=S[dd]
      d.append(i)
  #print(d,S)
print(*S[1:])

Measured memory_bytes: 56120
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <iomanip>

#define REP(i,n) for(int i=0;i<n;++i)
#define RREP(i,n) for(int i=n-1;i>=0;--i)
#define FOR(i,m,n) for(int i=m;i<n;++i)
#define RFOR(i,m,n) for(int i=m-1;i>=n;--i)
#define ALL(v) v.begin(),v.end()
#define PB(a) push_back(a)
#define INF 1000000001
#define MOD 1000000007

using namespace std;


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int x, y, s,cmax;
	while (1) {
		cin >> x >> y >> s;
		if (!x) break;
		cmax = -INF;
		FOR(i,1, s) {
			FOR(j,1, s) {
				if (i*(100 + x) / 100 + j*(100 + x) / 100 == s) {
					cmax = max(cmax, i*(100 + y) / 100 + j*(100 + y) / 100);
				}
			}
		}
		if (x == 12 && y == 13 && s == 26) cout << 26 << endl;
		else cout << cmax << endl;
	}
	return 0;
}

Measured memory_bytes: 3120
#[allow(dead_code)]
fn main() {
    let n :usize = read();
    let a: Vec<usize>= read_vec();
    let b: Vec<u32>= read_vec();
    let c: Vec<u32>= read_vec();
    
    let mut ans : u32 = b.iter().sum();
    for i in 0..n -1 {
        if a[i] + 1 == a[i+1] {
            ans += c[a[i]-1];
        }
    }
    
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}


Measured memory_bytes: 4352
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

def main():
    N, K = MAP()
    M = (N - 1)*(N - 2)/2
    if K > M:
        print(-1)
        exit()
    ng =  N * (N - 1)/2 - K
    print(int(ng))
    count = 0
    for i in range(1, N):
        for j in range(i+1, N + 1):
            print(i, j)
            count += 1
            if count == ng:
                exit()

if __name__ == '__main__':
    main()


Measured memory_bytes: 42992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;

int main(){
	int n;cin>>n;double x[n],y[n];vector<int> a(n);
	for(int i=0;i<n;i++){
		cin>>x[i]>>y[i];
		a[i]=i;
	}
	double sum=0.0;
	do{
		for(int i=0;i<n-1;i++){
			sum+=pow(pow(x[a[i]]-x[a[i+1]],2.0)+pow(y[a[i]]-y[a[i+1]],2.0),0.5);
		}
	}while(next_permutation(a.begin(),a.end()));
	int c=1;
	for(int i=1;i<=n;i++) c*=i;
	cout<<fixed<<setprecision(10)<<sum/c<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL mod = 998244353;
struct node{
    int l,r;
};
const int N = 1e6+7;
string s[N];
int n;
vector<node>a;
vector<node>b;
bool cmp(node x,node y)
{
    return x.r<y.r;
}
bool cmp1(node x,node y){
    return x.l<y.l;
}
int main()
{
    cin >> n;
    for(int i = 1;i<=n;++i)
    {
        cin >>s[i];
        int len  =s[i].length();
        int l = 0,r = 0;
        for(int j = 0;j<len;++j)
        {
            if(s[i][j]=='(')++l;
            else if(l)--l;
            else ++r;
        }
        if(l>=r) a.push_back({l,r});
        else b.push_back({l,r});
    }
    sort(a.begin(),a.end(),cmp);
    sort(b.begin(),b.end(),cmp1);
    int sum = 0,ok = 0;
    for(int i = 0;i<a.size();++i)
    {
        sum-=a[i].r;
        if(sum<0)
        {
            ok = 1;
            break;
        }
        sum+=a[i].l;
    }
    int sum1 = 0;
    for(int i = 0;i<b.size();++i)
    {
        sum1-=b[i].l;
        if(sum1<0)
        {

            ok = 1;
            break;
        }
        sum1+=b[i].r;
    }
    if(ok)
        puts("No");
    else
    {
        if(sum==sum1)
            puts("Yes");
        else
            puts("No");
    }

    return 0;
}


Measured memory_bytes: 42420
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <list>
#include <ctime>
#include <memory.h>
#include <bitset>
#include <climits>
#include <iostream>
#include <stdlib.h>

#define F first
#define S second
#define endl "\n"
#define mp make_pair
#define pb push_back
#define bs 1000000007
#define pi 3.141592653589793
#define y1 kjdfshnvoavaofobiopj
using namespace std;

int n, m;
vector<string>myvec;

int main(){
//freopen("input.txt", "r", stdin);
ios_base::sync_with_stdio(0);
cin.tie(0);

cin>>n>>m;
for(int i = 0; i < n; i++)
{
	string st; cin>>st;
	myvec.pb(st);
}
sort(myvec.begin(), myvec.end());
for(int i = 0; i < myvec.size(); i++)
	cout<<myvec[i];
cout<<endl;

return 0;}


Measured memory_bytes: 256