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

fun main(args: Array<String>) {

    val (n, m) = readLine()!!.split(" ").map(String::toInt)

    val aList = readLine()!!.split(" ").map(String::toInt)

    println(abc141d(n, m, aList))
}

fun abc141d(n: Int, m: Int, aList: List<Int>): Any? {

    class Rev : Comparator<Int> {
        override fun compare(o1: Int?, o2: Int?): Int {
            return o2!! - o1!!
        }
    }
//    val comp = Comparator<Int>() { i1: Int, i2: Int ->
//        return@Comparator i2 - i1
//    }

    val tmpQueue = java.util.PriorityQueue<Int>(aList.size, Rev())

    for (a in aList) {
        tmpQueue.offer(a)
    }

    repeat(m) {
        val tmp = tmpQueue.poll()!! / 2
        tmpQueue += tmp
    }

//    repeat(m) {
//
//        var tmpMax = 0
//        var tmpindex = -1
//        for ((index,a) in aMutaList.withIndex()) {
//            if (a > tmpMax) {
//                tmpMax = a
//                tmpindex =  index
//            }
//        }
//
//        if (tmpindex > -1) {
//            val hanbun = tmpMax / 2
//            aMutaList[tmpindex] = hanbun
//        }
//    }


    var sum = 0L
    for (e in tmpQueue) {
        sum += e
    }
    return sum
}



Measured memory_bytes: 71932
'''
☆長さnの数列Aの中央値がxであるとは
１．x以上の要素が (n + 1)// 2 個以上
２．そのようなxの中で最小
ということ。
'''

class BIT:
    def __init__(self, n):
        self.bit = [0] * (n+1)

    def sum(self, i):
        '''
        :param i: 
        :return: bit[i]までの和
        '''
        s = 0
        while i > 0:
            s += self.bit[i]
            i -= i & -i
        return s

    def add(self, i, x):
        '''
        :param i:
        :param x:
        :return: bit[i]にxを加える
        '''

        while i < len(self.bit):
            self.bit[i] += x
            i += i & -i

'''
def median(L):
    n = len(L)
    L.sort()
    return L[n // 2]
'''

N = int(input())
a = list(map(int, input().split()))

def ans_bigger(X):
    '''
    答えがX以上かどうかを判定
    つまり、区間[l. r]のうち中央値がX以上であるものが ((N+1) * N /2 + 1 ) //2 個以上かを判定
    [l, r]の中央値がX以上 =
    '''
    a_X = [1 if a[i] >= X else -1 for i in range(N)]#1, -1に変換
    cum = [N]
    for i in range(N):
        cum.append(cum[i] + a_X[i]) #累積和を取るが、BITを使うため全部0以上に（初項N）
    b = BIT(2 * N + 1)
    ans = 0
    for j in range(N + 1):
        ans += b.sum(cum[j])
        b.add(cum[j], 1)
    if ans >= ((N+1) * N /2 + 1 ) //2:
        return True
    else:
        return False

l = min(a)
r = max(a) + 1
#区間[l, r)を2分探索
while r > l + 1:
    if ans_bigger((l + r) // 2):
        l = (l + r) // 2
    else:
        r = (l + r) // 2
print(l)

Measured memory_bytes: 121000
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  string s;
  cin>>s;
  map<char,pair<int,int>> A;
  for(char c='a';c<='z';c++)
    A[c]=make_pair(0,-1);
  for(int i=0;i<(int)s.size();i++){
    A[s[i]].first=max(A[s[i]].first,i-A[s[i]].second-1);
    A[s[i]].second=i;
  }
  int i=1000;
  for(pair<int,pair<int,int>> p:A)
    i=min(max(p.second.first,(int)s.size()-p.second.second-1),i);
  cout<<i<<endl;
}

Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <functional>
#include <set>
#include <ctime>

using namespace std;
typedef long long ll;

int __gcd(int x, int y)
{
    if (y == 0) return x;
    return __gcd(y, x % y);
}


int main(){
    set<string> str;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        string ch;
        cin >> ch;
        str.insert(ch);
    }
    int cnt = 0;
    auto itr = str.begin();
    while (itr != str.end()) {
        cnt++;
        itr++;
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 15696
n = int(input())
D = [int(input()) for i in range(n)]
S = {}

s = ans = 0
S[0] = -1
for i in range(n):
    s += D[i]
    if s in S:
        ans = max(i - S[s], ans)
    else:
        S[s] = i
print(ans)

Measured memory_bytes: 45964
#include <iostream>
using namespace std;
 
int main() {
 
  while(1) {
    int x,y,s;
    cin >> x >> y >>s;
    if(x == 0 && y == 0&&s==0) break;
 
    int maxab = 0;
    int maxy = 0;
    for(int i=1;i<s;i++){
      int a = i*(100.0+x)/100;
      for(int j=1;j<s;j++){
    int b = j*(100.0+x)/100;
    if(a+b==s && maxab <= a+b) {
      maxab = a+b;
      int ya = i*(100.0+y)/100;
      int yb = j*(100.0+y)/100;
      if(ya+yb > maxy) maxy = ya+yb;//,cout << i << " "<<j<<endl;
    }
      }
    }
    cout << maxy<<endl;
     
  }
       
  return 0;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
long long int dp[100000][100];
long long int func(int w,int i,int arr[][2],int n)
{

     if(w<0)
    {
        return -1*arr[i-1][1];
    }

    if(i>n-1)
    {
        return 0;
    }
if(dp[w][i]!=0)
    {
        return dp[w][i];
    }

    return dp[w][i]=max(arr[i][1]+func(w-arr[i][0],i+1,arr,n),func(w,i+1,arr,n));

}

int main()
{
    for(int i=0;i<100000;i++)
    {
        for(int j=0;j<100;j++)
        {
            dp[i][j]=0;
        }
    }
    int n,w;
    cin>>n;
    cin>>w;
    int arr[n][2];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<2;j++)
        {
            scanf("%d",&arr[i][j]);
        }
    }
   cout<<func(w,0,arr,n);
    //cout<<dp[0];
    return 0;
}


Measured memory_bytes: 78336
#include<iostream>
#include<algorithm>
#include<map>
#include<queue>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)
#define RREP(i, a, n) for(int i=n-1; i>=a; i--)
#define INF 1000000000
#define MP(a, b) make_pair(a, b)
#define F first
#define S second

int dy[8] = { -1, -1, 0, 1, 1, 1, 0, -1 };
int dx[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
int main() {
	int w, h;
	while (cin >> w >> h, w || h) {
		bool field[52][52];
		int num[52][52];
		REP(i, 0, h + 2) REP(j, 0, w + 2) {
			if (i == 0 || j == 0 || i == h + 1 || j == w + 1) field[i][j] = 0;
		}
		REP(i, 1, h + 1) REP(j, 1, w + 1) cin >> field[i][j];
		REP(i, 0, h + 2) REP(j, 0, w + 2) num[i][j] = 0;
		
		int cnt = 1;
		REP(i, 1, h + 1) {
			REP(j, 1, w + 1) {
				if (!field[i][j] || num[i][j] != 0) continue;

				num[i][j] = cnt;

				queue<pair<int, int>> q;
				q.push(MP(i, j));
				while (!q.empty()) {
					int y = q.front().F;
					int x = q.front().S;
					q.pop();

					REP(k, 0, 8) {
						int ny = y + dy[k];
						int nx = x + dx[k];
						if (field[ny][nx] && num[ny][nx] == 0) {
							num[ny][nx] = cnt;
							q.push(MP(ny, nx));
						}
					}
				}

				cnt++;
			}
		}

		int ans = 0;
		REP(i, 0, h + 2) REP(j, 0, w + 2) {
			ans = max(ans, num[i][j]);
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3024
n = int(input())

list_1 = []
for i in range(n):
    array = list(map(int, input().split()))
    list_1.append(array)

list_2 = []
for i in range(n):
    array = list(map(int, input().split()))
    list_2.append(array)


num = 2**10
max_ans = -100000000000
for i in range(1, num):
    a = format(i, 'b').zfill(10)
    common_list = [0] * n
    ans = 0
    for j in range(n):
        count = 0
        for k in range(10):
            if list_1[j][k] == int(a[k]) and int(a[k]) == 1:
                count += 1
        ans += list_2[j][count]
    if ans > max_ans:
        max_ans = ans

print(max_ans)


Measured memory_bytes: 3064
/*
 * FileName:     C_fix
 * CreatedDate:  2020-04-04 21:28:10 +0900
 * LastModified: 2020-04-04 21:37:16 +0900
 */

#include <stdio.h>
#include <stdlib.h>
long int min(long int s, long int t){
    if(s<t){return s;}
    else{ return t; }
}
int main(void){
    long int n,k;
    scanf("%ld %ld",&n,&k);
    long int tmp=n/k;
    printf("%ld\n", min(n-tmp*k,-n+(tmp+1)*k));
    return 0;
}


Measured memory_bytes: 128
#グラフの連結成分を調べる
def Graph(ab):
    G = [[] for i in range(n)]
    for a, b, c in ab:
        G[a - 1].append([b, c])
        G[b - 1].append([a, c])
    return G

from collections import deque
def bfs(k):
    q = deque()
    q.append((k, - 1, 0))
    dis = [0] * n 
    while q:
        V, P, cnt = q.popleft()
        for nv, d in G[V - 1]:
            if nv == P:continue
            dis[nv - 1] = cnt + d
            q.append((nv, V, cnt + d))
    
    return dis 

n = int(input())
abc = [list(map(int,input().split())) for _ in range(n - 1)]
G = Graph(abc)
q, k = map(int,input().split())
dis = bfs(k)

for _ in range(q):
    x, y = map(int,input().split())
    print(dis[x - 1] + dis[y - 1])

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

int main(){
  int n;
  cin >> n;
  vector<int> p(n);
  for(int i=0;i<n;i++) cin >> p.at(i);
  int ans=0;
  
  for(int i=1;i<n-1;i++){
    if(p.at(i)>p.at(i-1)){
      if(p.at(i)<p.at(i+1)) ans++;
    }
    else{
      if(p.at(i)>p.at(i+1))ans++;
    }
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
//树状数组
#include<iostream>
#include<cmath>
#define maxn 200005 
using namespace std;
int n;
long long c[maxn]={0};
long long lowbit(long long x)
{
	return x&(-x);
}//lowbit函数

void update(long long i,long long x)
{
	while(i<=n)//一定要注意区间求和的范围
	{
		c[i]+=x;
		i+=lowbit(i);
	}
}//i点增量为x

long long sum(long long x)
{
	long long res=0;
	while(x>0)
	{
		res+=c[x];
		x-=lowbit(x);
	}
	return res;
}//区间求和[1,x]

long long Get(long long x1,long long x2)
{
	return sum(x2)-sum(x1-1);
}
int main()
{
	long long MIN=0xffffffff;
	long long temp;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>temp;
		update(i,temp);
	}
	for(int i=1;i<n;i++)
	{
		long long x,y;
		x=sum(i);
		y=sum(n)-sum(i);
		if(abs(x-y)<MIN)
		MIN=abs(x-y);
	}
	cout<<MIN<<endl;
	return 0;
}

Measured memory_bytes: 1792
def main():
    nums = list(map(int, input().split()))
    nums.sort(reverse=True)

    cnt = 0
    if (nums[1] - nums[2]) % 2 == 0:
        cnt += (nums[1] - nums[2]) // 2
        cnt += nums[0] - nums[1]

    else:
        cnt += 1
        cnt += (nums[1] - nums[2] + 1) // 2
        cnt += nums[0] - nums[1]

    print(cnt)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
import random

def is_prime3(q, k=50):
    q = abs(q)
    # 計算するまでもなく判定できるものははじく
    if q == 2: return True
    if q < 2 or q & 1 == 0: return False

    # n-1=2^s*dとし（但しaは整数、dは奇数)、dを求める
    d = (q - 1) >> 1
    while d & 1 == 0:
        d >>= 1

    # 判定をk回繰り返す
    for i in range(k):
        a = random.randint(1, q - 1)
        t = d
        y = pow(a, t, q)
        # [0,s-1]の範囲すべてをチェック
        while t != q - 1 and y != 1 and y != q - 1:
            y = pow(y, 2, q)
            t <<= 1
        if y != q - 1 and t & 1 == 0:
            return False
    return True

if __name__ == '__main__':
    a = int(input())
    while(not is_prime3(a)):
        a = a+1
    print(a)

Measured memory_bytes: 4208
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
inline void read(rel &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  x=f?x:-x;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;

ll f(ll b,ll n){return n<b?n:f(b,n/b)+n%b;}

int main(){
ll n,s;read(n),read(s);
if (n==s) return write(n+1),0;
for (ll i=2;i<=sqrt(n)+1;++i) if (f(i,n)==s) return write(i),0;
if (n-s>1) for (ll i=sqrt(n);i;--i){
  ll b=(n-s)/i+1;
  if (f(b,n)==s) return write(b),0;
  }
puts("-1");
}

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

int main() 
{
	int n;
	scanf("%d", &n);
	long long s = 0;
	for (int i = 1; i <= n; ++i) s += (long long)(i + n / i * i) * (n / i) / 2;
	printf("%lld\n", s);
	return 0;
}


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


int main(){
	int a, b, c;
	cin >> a >> b >> c;
	int maxi = max({a,b,c});
	cout << (a+b+c - maxi) << endl;
}


Measured memory_bytes: 256
#6re
h,w = map(int,input().split())
s = []
s.append(list("." for i in range(w+2)))
for i in range(h):
    s.append(list("."+input()+"."))
s.append(list("." for i in range(w+2)))
ans = [[0 for j in range(w) ] for i in range(h) ]
    
for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j] != "#":
            for m in range(i-1,i+2):
                for n in range(j-1,j+2):
                    if s[m][n] == "#":
                        ans[i-1][j-1] += 1
        else:
            ans[i-1][j-1] = "#"
                
for i in range(h):
    for j in range(w):
        ans[i][j] = str(ans[i][j])
        
for i in range(h):
    print("".join(ans[i]))

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N;
  cin >> N;
  vint X(N);
  rep(i, N) cin >> X[i];
  vint A = X;
  sort(all(A));
  rep(i, N) {
    int p = lower_bound(all(A), X[i])-A.begin();
    if(p < N/2) cout << A[N/2] << endl;
    else cout << A[N/2-1] << endl;
  }

  return 0;
}


Measured memory_bytes: 5376
import java.util.*;
/*
Main class for AOJ where there is no input.
*/
public class Main{
   public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      
      String str;
      String[] arr;
      int[] a = new int[2];
      
      while(true){
         str = sc.nextLine();
         arr = str.split(" ");
                  
         a[0] = Integer.parseInt(arr[0]);
         a[1] = Integer.parseInt(arr[1]);
         
         Arrays.sort(a);
         if(a[1] == 0){
            break;
         }else{
            System.out.println(a[0] + " " + a[1]);
         }
      }    
      
   }//main method 
}//class

Measured memory_bytes: 35488
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long N,K;
    cin>>N>>K;
    long long count=0;
    vector<int>wtf(N);
    for(long long i=0; i<N; i++){
    cin>>wtf.at(i); 
    count+=wtf.at(i);
    }
    sort(wtf.begin(),wtf.end());
    if(N<=K){
    count=0;
    }
    else if(K!=0){
   for(int i=0; i<K; i++){
    count-=wtf.at(N-i-1);
   }
    }
   cout<<count<<endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
#define db long double
#define fi first
#define se second
#define  pb push_back
#define  pob pop_back
#define W while
#define fn(i,x) for(int i=0;i<x;i++)
#define fs(i,s,x) for(int i=s;i<x;i++)
#define fr(i,x) for(int i=x;i>=0;i--)
#define fit(it,s) for(auto it=s.begin();it!=s.end();it++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mod 1000000007
#define MAX 1005
using namespace std;
int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);

    // freopen("in.txt","r",stdin);
    // freopen("out.txt","w",stdout);
    
    ll n,k;
    cin >> n >> k;
    string g;
    cin >> g;
    g[k-1] = tolower(g[k-1]);
    cout << g;

    return 0;

}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	private final static byte MASK_RIGHT = 0x0F; //右4bit数値化用マスク
	private final static int STRIP_LENGTH = 10; //短冊1行の長さ
	private static int[] punchTape = new int[100]; //10*10の方眼紙を短冊にしてくっつけた紙テープ

	public static void main(String[] args) throws Exception {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 512);
		String sLine;
		while ((sLine = reader.readLine()) != null) {
			droppingInk(sLine.charAt(0) & MASK_RIGHT, sLine.charAt(2) & MASK_RIGHT, sLine.charAt(4) & MASK_RIGHT);
		}
		calcResult();
	}

	/**
	 *都合の良い滴下
	 */
	private static void droppingInk(int x, int y, int size) {
		sinking(x, y - 1);
		sinking(x - 1, y);
		sinking(x, y);
		sinking(x + 1, y);
		sinking(x, y + 1);
		if (size == 1) {
			return;
		}

		sinking(x - 1, y - 1);
		sinking(x + 1, y - 1);
		sinking(x - 1, y + 1);
		sinking(x + 1, y + 1);
		if (size == 2) {
			return;
		}

		sinking(x, y - 2);
		sinking(x - 2, y);
		sinking(x + 2, y);
		sinking(x, y + 2);
	}

	/**
	 * 床は汚さないようにする
	 */
	private static void sinking(int x, int y) {
		if (x >= 0 && x < 10 && y >= 0 && y < 10) {
			punchTape[x * STRIP_LENGTH + y]++;
		}
	}

	/**
	 *紙の染みを数え、損害を報告する
	 */
	private static void calcResult() {
		int white = 0;//綺麗な部分
		int max = 0;//一番ひどい汚れ
		for (int cell : punchTape) {
			if (cell == 0) {
				white++;
			} else if (cell > max) {
				max = cell;
			}
		}
		System.out.println(white);
		System.out.println(max);
	}
}

Measured memory_bytes: 16852
#include<stdio.h>
    int main()
{
    int b[100]={0}, c[100]={0}, a[100][100]={0}, m, n, i, j;
    scanf("%d %d", &n, &m);
    for(i = 0; i < n; i++){
        for(j = 0; j < m; j++){
            scanf("%d", &a[i][j]);
        }
    }
      
    for(i = 0; i < m; i++){
        scanf("%d", &b[i]);
    }
      
    for(i = 0; i < n; i++){
        for(j = 0; j < m; j++){
            c[i] += a[i][j] * b[j];
        }
    }   
      
    for(i = 0; i < n; i++){
        printf("%d\n", c[i]);
    }
    return 0;
}

Measured memory_bytes: 648
#include<stdio.h>

int main(void){
  char buff[1000];
  char x,y;
  int nx,ny;

  fgets(buff,1000,stdin);
  sscanf(buff,"%c %c",&x,&y);


  if(x=='A'){
    nx=10;
  }else if(x=='B'){
    nx=11;
  }else if(x=='C'){
    nx=12;
  }else if(x=='D'){
    nx=13;
  }else if(x=='E'){
    nx=14;
  }else if(x=='F'){
    nx=15;
  }

  if(y=='A'){
    ny=10;
  }else if(y=='B'){
    ny=11;
  }else if(y=='C'){
    ny=12;
  }else if(y=='D'){
    ny=13;
  }else if(y=='E'){
    ny=14;
  }else if(y=='F'){
    ny=15;
  }


  if(nx>ny){
    printf(">");
  }else if(nx<ny){
    printf("<");
  }else if(nx==ny){
    printf("=");
  }

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
using P = pair<int, int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef vector<ll> vi;
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
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; }

int main(){
  vector<vector<char>> c(2, vector<char>(3));
  rep(i,2){
    rep(j,3){
      cin >> c[i][j];
    }
  }
  if(c[0][0]==c[1][2]&&c[0][1]==c[1][1]&&c[0][2]==c[1][0]){
    print("YES");
  }
  else{
    print("NO");
  }
}

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

using namespace std;
#define all(a)a.begin(),a.end()
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod = int(1e9)+7;
using V = vector<int>;
using P = pair<int,int>;

int main()
{
    ll n,m;cin >>n>>m;
    ll k=min(n,m/2);
    ll ans=0;
    ans+=k;
    m=(m-2*k<0)?0:m-2*k;
    //cout << ans << endl;
    ans+=m/4;
    cout << ans << endl;
    return 0;
}


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

typedef pair<double, int> Player;

int main(void){  
  vector<Player> group[3], losers;
  
  for (int i=0; i<3; i++){
    for (int j=0; j<8; j++){
      int id;
      double tm;
      cin >> id >> tm;
      group[i].push_back(make_pair(tm, id));
    }
    sort(group[i].begin(), group[i].end());
    for (int j=0; j<8; j++){
      Player p = group[i][j];
      if (j<2){
        printf("%d %2.2f\n", p.second, p.first);
      } else {
        losers.push_back(p);
      }
    }
  }
  sort(losers.begin(), losers.end());
  for (int i=0; i<2; i++){
    Player p = losers[i];
    printf("%d %2.2f\n", p.second, p.first);
  }
  return 0;
}


Measured memory_bytes: 3132
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define lp(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define INFLL ((LL)4e18)
#define ALL(x) (x).begin(),(x).end()
#define BIT(x) (1 << (x))
using namespace std;

int main(){
	int N, C;
	cin>>N>>C;
	vector<vector<int> > D(C, vector<int>(C));
	REP(x, C){
		REP(y, C){
			cin>>D[x][y];
		}
	}
	vector<vector<int>> csum(C, vector<int>(3, 0));
	REP(i, N){
		REP(j, N){
			int d;
			cin>>d;
			--d;
			++csum[d][(i+j)%3];
		}
	}
	int ans = INF;
	REP(i, C){
		REP(j, C){
			if(i==j)continue;
			REP(k, C){
				if(i==k||j==k)continue;
				int sum = 0;
				REP(l, C){
					sum += D[l][i]*csum[l][0];
					sum += D[l][j]*csum[l][1];
					sum += D[l][k]*csum[l][2];
				}
				ans=min(ans, sum);
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, D, X;
  cin >> N >> D >> X;
  vector<int> A(N);
  for(int i = 0; i < N; i++){
    cin >> A.at(i);
  }
  vector<int> C(N);
  for(int i = 0; i < N; i++){
    for(int j = 0; j < 100; j++){
      if(j*A.at(i) + 1 <= D)C.at(i)++;
    }
  }
  int sum = 0;
  for(int i = 0; i < N; i++){
    sum += C.at(i);
  }
  cout << sum + X << endl;
}
  

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

int main() {
    string s;
    int y = 700;
    cin >> s;
    if (s[0] == 'o') y += 100;
    if (s[1] == 'o') y += 100;
    if (s[2] == 'o') y += 100;
    cout << y << endl;
}

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

int w,h;
int mp[50][50];
void dfs(int y,int x){

  mp[y][x] = 0;
  for(int i=-1;i<=1;i++)
    for(int j=-1;j<=1;j++){
      int ny = y + i;
      int nx = x + j;
      if(nx < 0 || ny < 0 || nx >= w || ny >= h) continue;
      if(mp[ny][nx] == 0) continue;
      dfs(ny,nx);
    }
}

signed main(){
  while(1){
    cin>>w>>h;
    if( w == 0 && h == 0) return 0;
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++) cin>>mp[i][j];

    int ans = 0;
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++){
        if(mp[i][j] == 0) continue;
        ans++;
        dfs(i, j);
      }

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



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

typedef long long ll;

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

const ll MOD = 1e9+7;

int main(void){
    ll n,m,ans = 0;
    cin >> n >> m;
    if(n-m == 0){
        ans = 2;
        rep(i,n){
            ans = ans * (i+1) % MOD;
        }
        rep(i,m){
            ans = ans * (i+1) % MOD;
        }
    }
    else if(abs(n-m) == 1){
        ans = 1;
        rep(i,n){
            ans = ans * (i+1) % MOD;
        }
        rep(i,m){
            ans = ans * (i+1) % MOD;
        }
    }
    
    cout << ans << endl;
}

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

using namespace std;

bool isprime(int x);

int main()
{
	int n, a[10000], ans = 0;
	int i, j;
	
	cin >> n;
	
	for (i = 0; i < n; i++){
		cin >> a[i];
		if (isprime(a[i]) == true) ans++;
	}
	
	cout << ans << "\n";
	
	return (0);
}

bool isprime(int x)
{
	int i = 3;
	
	if (x == 2) return (true);
	
	if (x < 2 || x % 2 == 0) return (false);
	
	while (x >= i * i){
		if (x % i == 0) return (false);
		i += 2;
	}
	
	return (true);
}


Measured memory_bytes: 3124
import math
import itertools
import sys
import collections

def solve(N,M,Q,ABCD):
    ans = 0
    A = [i for i in range(1,M+1)]
    for p in itertools.combinations_with_replacement(A,N):
        tmp = 0
        for a,b,c,d in ABCD:
            if(p[b-1] - p [a-1] == c):
                tmp+=d
        ans = max(ans,tmp)
    return ans



def main():
    N ,M,Q = map(int,input().split())
    ABCD = []
    for _ in range(Q):
        ABCD.append(list(map(int,input().split())))
    # solve()
    print(solve(N,M,Q,ABCD))
if __name__ == '__main__':
   main()

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

int main(){
  int64_t H;
  cin >> H;
  int64_t ans=0;
  int64_t n=1;
  while(H>0){
    ans+=n;
    H/=2;
    n*=2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define REP(i, n) for(int i=0;i<(n);++i)
#define REPA(i, n) for(int i=1;i<(n);++i)
#define lp(i, n) for(int i=-;i<(n);++i)
#define PII pair<int, int>
#define PLL pair<long long, long long>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define DEKAI ((int)1e9+7)
#define ALL(x) (x).begin(), (x).end()
#define BIT(x) (1<<(x))
#define foreach(i, n) for(auto &i:(n))
using namespace std;

int main(){
    int N, M;
    while(cin>>N>>M&&N){
        vector<vector<int> > road(N+1);
        vector<vector<char> > con(N+1, vector<char>(N+1, false));
        vector<int> line(N+1, -1);
        REP(i, M){
            int a, b;
            cin >> a >> b;
            road[a].push_back(b);
            road[b].push_back(a);
            con[a][b]=true;
            con[b][a]=true;
        }
        queue<PII> que;
        line[1]=0;
        que.push(PII(1, 0));
        while(!que.empty()){
            PII d = que.front();
            que.pop();
            foreach(i, road[d.first]){
                if(line[i]!=-1)continue;
                line[i]=d.second+1;
                que.push(PII(i, d.second+1));
            }
        }
        REPA(i, N+1)line[i]%=2;
        bool flag = true;
        int a = 0;
        vector<int> ans;
        REPA(i, N+1)
            if(line[i])++a;
        REPA(i, N+1){
            REPA(j, N+1){
                if(line[i]*line[j]&&con[i][j]){
                    flag=false;
                }
            }
        }
        if(flag&&a%2==0)ans.push_back(a);
        a=N-a;
        flag=true;
        REPA(i, N+1){
            REPA(j, N+1){
                if(line[i]+line[j]==0&&con[i][j]){
                    flag=false;
                }
            }
        }
        if(flag&&a%2==0)ans.push_back(a);
        sort(ALL(ans));
        if(ans.size()==2&&ans[0]==ans[1])ans.pop_back();
        cout << ans.size() << endl;
        foreach(i, ans)cout << i/2 << endl;
    }
    return 0;
}



Measured memory_bytes: 4264
S = list(input())
odd = ['R', 'U', 'D']
even = ['L', 'U', 'D']
S_even = S[::2]
S_odd = S[1::2]
ans = True
for i in range(len(S_even)):
    if not S_even[i] in odd:
        ans = False

for j in range(len(S_odd)):
    if not S_odd[j] in even:
        ans = False

if ans:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
#include<bitset>
#include<functional>

#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 2000000000
#define LLINF 9000000000000000000
#define PI 3.14159265358979

using namespace std;
typedef long long int ll;
typedef pair<long long int, long long int> P;



int main(void) {
	string s;
	int count[3] = {};

	cin >> s;
	FOR(i, 0, s.size() - 1) {
		count[s[i] - 'a']++;
	}

	sort(count, count + 3);
	if (count[0] + 2 <= count[2]) {
		cout << "NO" << endl;
	}
	else {
		cout << "YES" << endl;
	}


	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

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

    vi squares;
    F0R(i, 1000) {
        squares.pb(i*i);
    }

    int N; cin >> N; int D; cin >> D;
    int coord[N][D];

    F0R(i, N) {
        F0R(j, D) {
            cin >> coord[i][j];
        }
    }

    int ans = 0;

    F0R(i, N) {
        FOR(j, i+1, N) {
            int dist = 0;
            F0R(k, D) {
                dist += (coord[i][k] - coord[j][k]) * (coord[i][k] - coord[j][k]);
            }
            F0R(k, 1000) {
                if (squares[k] == dist) ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

// read the question correctly (ll vs int)
// template by bqi343

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

int main(){
  int h, w;
  cin >> h >> w;
  vector<vector<int>> vec(h, vector<int>(w, 0));
  int n;
  cin >> n;
  vector<int> str;
  for(int i=1; i<=n; i++){
    int num;
    cin >> num;
    for(int j=0; j<num; j++) str.push_back(i);
  }
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      if(i % 2 == 0){
        vec[i][j] = str[w*i+j];
      }else{
        vec[i][w-1-j] = str[w*i+j];
      }
    }
  }
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      cout << vec[i][j] << " ";
    }
    cout << endl;
  }
  return 0;
}
  

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const ll MAX = 2510;
using T = tuple<ll, ll, ll>;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, m, s;
  cin >> n >> m >> s;
  vector<vector<ll>> to(n), pay(n), co(n);
  rep(i, m) {
    ll u, v, a, b;
    cin >> u >> v >> a >> b;
    --u, --v;
    to[u].push_back(v);
    to[v].push_back(u);
    pay[u].push_back(a);
    pay[v].push_back(a);
    co[u].push_back(b);
    co[v].push_back(b);
  }
  vector<pair<ll, ll>> trade(n);
  rep(i, n) cin >> trade[i].first >> trade[i].second;
  vector<vector<ll>> node(n, vector<ll>(MAX+1, LINF));
  priority_queue<T, vector<T>, greater<T>> que;
  que.push(make_tuple(0, 0, min(s, MAX)));
  node[0][min(s, MAX)] = 0;
  while (!que.empty()) {
    ll cost, now, sil;
    tie(cost, now, sil) = que.top();
    que.pop();
    if (cost > node[now][sil])
      continue;
    if (chmin(node[now][min(sil+trade[now].first, MAX)], cost+trade[now].second))
      que.push(make_tuple(cost+trade[now].second, now, min(sil+trade[now].first, MAX)));
    rep(i, to[now].size()) {
      if (sil < pay[now][i])
        continue;
      if (chmin(node[to[now][i]][sil-pay[now][i]], cost+co[now][i]))
        que.push(make_tuple(cost+co[now][i], to[now][i], sil-pay[now][i]));
    }
  }
  for (int i = 1; i < n; i++) {
    ll res = LINF;
    for (auto e : node[i])
      chmin(res, e);
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 7324
s = gets.chomp
t = gets.chomp

reg = "^(.*)("
t.split('').each do |char|
  reg += "[#{char}|¥?]"
end
reg += ")(.*?)$"
regexp = Regexp.new(reg)
if m= s.match(regexp)
  puts "#{m[1]}#{t}#{m[3]}".gsub('?', 'a')
else
  puts "UNRESTORABLE"
end

Measured memory_bytes: 1788
import sys
def fastio():
    from io import StringIO
    from atexit import register
    global input
    sys.stdin = StringIO(sys.stdin.read())
    input = lambda : sys.stdin.readline().rstrip('\r\n')
    sys.stdout = StringIO()
    register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

INF = 10**20
MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))
# from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br

n, m = I()
print(n * (n - 1) // 2 + m * (m - 1) // 2)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define REP(n) for(int i = 0; i < n; i++)
#define all(p) p.begin(), p.end()
#define count_1(p) __builtin_popcountll(p)
#define count_0(p) __builtin_ctzll(p)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
template<class X=int>inline X min(X a,X b,X c){return min(min(a,b),c);}
template<class X=int>inline X min(X a,X b,X c,X d){return min(min(a,b,c),d);}
template<class X=int> inline X max(X a,X b,X c){return max(max(a,b),c);}
template<class X=int> inline X max(X a,X b,X c,X d){return max(max(a,b,c),d);}
template<class X=int> inline X mid(X s,X e){return (s+(e-s)/2);}
template<class X=int> inline X len(X s,X e){return (e-s+1);}
const int MOD = 1e9 + 7;
const int INF = 987654321;
const bool TESTCASES = 0;
const bool CODEJAM = 0;
struct modll{ll v=0;operator ll(){return v;}modll(){}modll(int n){v=n;}modll(ll n){v=n;};
modll operator+(ll b){ll ret=v+b;if(ret>=MOD)ret-=MOD;return {ret};}
modll operator+(int b){ll ret=v+b;if(ret>=MOD)ret-=MOD;return {ret};}
modll operator+(modll b){ll ret=v+b.v;if(ret>=MOD)ret-=MOD;return {ret};}
modll operator-(ll b){ll ret=v-b;if(ret<0)ret+=MOD;return {ret};}
modll operator-(int b){ll ret=v-b;if(ret<0)ret+=MOD;return {ret};}
modll operator-(modll b){ll ret=v-b.v;if(ret<0)ret+=MOD;return {ret};}
modll operator*(ll b){ll ret = (v*b)%MOD;return {ret};}
modll operator*(int b){ll ret = (v*b)%MOD;return {ret};}
modll operator*(modll b){ll ret = (v*b.v)%MOD;return {ret};}
modll &operator+=(modll b){v+=b.v;if(v>=MOD)v-=MOD;return*this;}
modll &operator-=(modll b){v-=b.v;if(v<0)v+=MOD;return*this;}
modll &operator*=(modll b){v=v*b.v%MOD;return*this;}
modll &operator++(int){v++;if(v>=MOD)v-=MOD;return*this;}
modll &operator--(int){v--;if(v<0)v+=MOD;return*this;}
modll inv(modll &x,int y){if(y==0)return {1};
modll p=inv(x,y/2);p=p*p;return(y%2==0)?p:(x*p);}
modll operator/(modll b){return {(v*inv(b,MOD-2))%MOD};}
modll operator/(int b){modll t=b;return{(v*inv(t,MOD-2))%MOD};}
modll operator/(ll b){modll t=b;return{(v*inv(t,MOD-2))%MOD};}
modll &operator/=(modll b){v*=inv(b,MOD-2);return*this;}
friend istream &operator>>(istream &in, modll &c){in>>c.v;return in;}};

void solve() {
	int n, k;
	cin >> n >> k;
	vector<modll> A(n);
	REP(n) cin >> A[i];
	vector<vector<modll>> dp(n + 1, vector<modll>(k + 1));
	dp[0][0] = 1;
	vector<modll> pre(k + 2, 1);
	pre[0] = 0;
	for(int i = 1; i <= n; i++) {
		for(int j = 0; j <= k; j++) {
			dp[i][j] = pre[j + 1] - pre[max(0LL, j - A[i - 1])];
		}
		for(int j = 0; j <= k; j++) {
			pre[j + 1] = pre[j] + dp[i][j];
		}
	}
	cout << dp[n][k] << "\n";
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	int T = 1;
	if(TESTCASES) cin >> T;
	for(int t = 1; t <= T; t++) {
		if(CODEJAM) cout << "Case #" << t << ": ";
		solve();
	}
	return 0;
}


Measured memory_bytes: 83036
/**
 * Created by iainws on 4/09/16.
 */

import java.io.InputStreamReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.InputStream;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReaderMain in = new InputReaderMain(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskMain solver = new TaskMain();
        solver.solve(1, in, out);
        out.close();
    }
}
class TaskMain {
    public void solve(int taskNumber, InputReaderMain in, PrintWriter out) {
        int N;
        N = in.nextInt();
        int [] arr = new int[2 * N];
        for(int i = 0; i < 2 * N; ++i){
            int a;
            a = in.nextInt();
            arr[i] = a;
        }
        Arrays.sort(arr);
        int sum = 0;
        for(int i = 0; i < 2 * N; i+=2){
            int a = arr[i];
            int b = arr[i + 1];
            int r = Math.min(a, b);
            sum += r;
        }
        System.out.println(sum);

    }
}

class InputReaderMain {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReaderMain(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

}

Measured memory_bytes: 7892
import sys
input = lambda : sys.stdin.readline().rstrip()

M = (10**9)+7
n = int(input())
As = map(int, input().split(" "))

cumsum = []
cur = 0
out = 0
for i in range(n-1):
    cur += As[i]
    out += cur*As[i+1] 
    out = out % M
print(out)

Measured memory_bytes: 91336
import java.util.Scanner;


public class Main {
	public static void main(String args[]){
		new Main().run();
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a[] = new int[n];
		for (int i = 0; i < n; i++) {
			String s = sc.next();
			a[i] = s.equals("A") ? 0 : 1;
		}
		boolean used[] = new boolean[n];
		boolean yes = true;
		for(int i = 0; i < n; ++i){
			if(a[i] == 0){
				boolean found = false;
				for(int j = i+1; j < n; ++j){
					if(used[j] || a[j] == 0) continue;
					used[j] = true;
					found = true;
					break;
				}
				if(!found) yes = false;
			} else {
				if(!used[i]) yes = false;
			}
			if(!yes) break;
		}
		System.out.println(yes ? "YES" : "NO");
		sc.close();
	}
}

Measured memory_bytes: 26236
#include <stdio.h>
int main(){

  int pasta[3],drink[2],blank,i;

  for(i = 0; i < 3; i++) scanf("%d",&pasta[i]);

  for(i = 2; i > 0; i--){

    if(pasta[i] < pasta[i-1]){

      blank=pasta[i];
      pasta[i]=pasta[i-1];
      pasta[i-1]=blank;

    }

  }

  scanf("%d %d",&drink[0],&drink[1]);

  if(drink[0] > drink[1]) drink[0]=drink[1];

  printf("%d\n",pasta[0]+drink[0]-50);

  return 0;

}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
#define ll                      long long
#define pb                      push_back
#define rep(i,a,b,c)            for(ll i=(a);i<=(b);i+=(c))
#define repb(i,a,b,c)           for(ll i=(a);i>=(b);i-=(c))
#define MOD                     1000000007
#define inf                     3e18
#define ld                      long double
#define mp                      make_pair
#define vpll                    vector<pair<ll,ll> >
#define vll                     vector<ll>
#define vld                     vector<ld>
#define vvll                    vector<vector<ll>>
#define vvld                    vector<vector<ld>>
#define pll                     pair<ll,ll>
#define vvpll                   vector<vector<pair<ll,ll>>>
#define pqll                    priority_queue<ll>
#define mll                     map<ll,ll>
#define mlc                     map<ll,char>
#define um                      unordered_map
#define umll                    um<ll,ll>
#define umlc                    um<ll,char>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define ln                      cout<<"\n";
#define endl                    "\n"
#define test                    ll T;cin>>T;while(T--)
#define isvowel(a)              (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define fastIO                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define show(w,size)            for(ll i=0;i<size;i++) cout<<w[i]<<" ";
#define prll(a)                 cout<<a<<"\n";
#define mset(dp,no)             memset(dp,no,sizeof(dp))
#define input(a,n)              rep(i,0,n-1,1) cin>>a[i];
#define countbit                __builtin_popcount                                           //Number of setbits in decimal notation
#define lb(v,cur)               lower_bound(all(v),cur)-v.begin()
#define ub(v,cur)               upper_bound(all(v),cur)-v.begin()
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
ll pows(ll b,ll e){if(e==0)return 1;else if(e%2==0){ll a=pow(b,e/2);return a*a;}else {ll a=pow(b,e/2);return b*a*a;}}
ll powm(ll x,ll y,ll m){x=x%m;ll res=1;while(y){if(y&1)res=res*x;res%=m;y=y>>1;x=x*x;x%=m;}return res;}
ll modInverse(ll a, ll m=MOD){if(m == 1)return 0;ll m0=m,y=0,x=1;while(a>1){ll q=a/m,t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0) x+=m0;return x;}
int main()
{
fastIO
ll n,m,i,j,k,x,y,z,e,f,p,q,g,l,r,w,h,count1=0,prod=1,a,b,c,d,index,x1,x2,diff,ans=0,sum=0,sum1=0,sum2=0,flag=0,flag1=0,flag2=0;
string s,s1,s2;
cin>>n>>m;
if(n==1||m==1)
{
  cout<<"1";
  return 0;
}
p=(n*m);
cout<<(p+1)/2;
}


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

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define D(x) cerr<<#x<<'='<<x<<'\n';
using namespace std;
typedef long long ll;
int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	int ans=0;
	while (n)
	{
		ans++;
		n/=k;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
#define INF 1000000007
#define LINF 1000000000000000007
 
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> P;


int a, b, c;

int main(){
	cin >> a >> b >> c;
	set<int> s;
	s.insert(a);
	s.insert(b);
	s.insert(c);
	
	cout << s.size() << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
#define ll long long
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int main(){
	fastio();
	int n;
	cin>>n;
	cout<<(n+1)/2;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  if(a<=c &&b<=c) printf("%d",a+b);
  else if(b<=a&&c<=a) printf("%d",b+c);
  else if(c<=b&&a<=b) printf("%d",a+c);
  else;
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
typedef long long ll;
const int INF = 1000000000;
const long INF64 = 1000000000000000ll;
const int MOD = 1000000007;


int main(){
	int n,m;
	char a[50][50],b[50][50];
	std::cin >> n>>m;
	rep(i,n)rep(j,n)std::cin >> a[i][j];
	rep(i,m)rep(j,m)std::cin >> b[i][j];
	bool han=false;
	rep(c,n-m+1)rep(d,n-m+1){
		bool hhan=1;
		for (int i = 0; i < m; i++) {
			/* code */
			for (int j = 0; j < m; j++) {
				/* code */
				if(a[c+i][d+j]!=b[i][j])hhan=0;
			}
		}
		if(hhan)han=1;
	}
	if(han)std::cout << "Yes" << std::endl;
	else std::cout << "No" << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int sll;
typedef  double ld;
#define A 1000000007ll
#define D 100000000000000ll
#define B 998244353ll
#define C 1000000000000000000ll
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oset tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define br break
#define PI acos(-1)
#define subt cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n" 
 
const ll MAXN=200005;
ve<ve<ll>> adj(MAXN);
bool vis[MAXN];
ve<ll> vec;
ll a[MAXN],ans[MAXN];

void dfs(ll v)
{
    vis[v]=true;
    auto z=lb(vec.begin(),vec.end(),a[v]);
    ll x=-1,y=-1;
    if(z==vec.end())
        vec.pb(a[v]);
    else
    {
        x=lb(vec.begin(),vec.end(),a[v])-vec.begin();
        y=vec[x];
        vec[x]=a[v];
    }
    ans[v]=vec.size();
    for(auto i=adj[v].begin();i!=adj[v].end();i++)
        if(!vis[*i])
            dfs(*i);
    if(x==-1)
        vec.pob();
    else
        vec[x]=y;
    return;
}

int main() 
{
    FAST;
    ll n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    ll x,y;
    for(int i=1;i<n;i++)
    {
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    dfs(1);
    for(int i=1;i<=n;i++)
        cout<<ans[i]<<"\n";
    subt;
    return 0;
}

Measured memory_bytes: 29300
import sys
sys.setrecursionlimit(10**5 + 9)
from collections import defaultdict
dp=defaultdict(lambda:0)
n=int(input())
ar,br,cr=[0]*n,[0]*n,[0]*n

for i in range(n):
	ar[i],br[i],cr[i]=map(int,input().split())
if n==1:
	print(max(ar[0],br[0],cr[0]))
	exit()
def points(i,pv):
	if dp[(i,pv)] != 0:
		return dp[(i,pv)]
	if pv==1:
		x,y=br[i],cr[i]
		a,b=2,3
	elif pv==2:
		x,y=ar[i],cr[i]
		a,b=1,3
	else:
		x,y=ar[i],br[i]
		a,b=1,2
	if i==n-1:
		return max(x,y)
	ax=points(i+1,a)+x
	by=points(i+1,b)+y
	ans=max(by,ax)
	dp[(i,pv)]=ans
	return ans
p=points(1,1)+ar[0]
q=points(1,2)+br[0]
r=points(1,3)+cr[0]
print(max(p,q,r))

	
		



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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

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

    if((B+C)-A > 0)cout << (B+C)-A << endl;
    else cout << 0 << endl;
}


Measured memory_bytes: 256