akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<ctype.h>
#include<cstdio>
#include<algorithm>
using namespace std;
inline int read(){
	int x=0,f=0;char ch=getchar();
	while(!isdigit(ch))f|=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+(ch^48),ch=getchar();
	return f?-x:x;
}
int a[100007],ans;
int main(){
    int n=read(),er=1;
    if(n==1){
    	cout<<"1\n";
    	return 0;
	} 
	for(int i=1;i<=n;++i)a[i]=read();
	while(er<=n){
		while(er<=n && a[er]==a[er+1])er++;
    	if(er<=n && a[er]<a[er+1]){
			while(er<n && a[er]<=a[er+1])er++;
			er++,ans++;
		}
		while(er<=n && a[er]==a[er+1])er++;
		if(er<=n && a[er]>a[er+1]){
			while(er<n && a[er]>=a[er+1])er++;
			er++,ans++;
		}
	}
	if(er==n)ans++;
	cout<<ans<<"\n";
    return 0;
}

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

string s;
int n;
int dice[6]={1,2,3,4,5,6};
int ans=1;



void News(int a,int b){
    int temp=0;
    temp=dice[0];
    dice[0]=dice[b];
    dice[b]=dice[5];
    dice[5]=dice[a];
    dice[a]=temp;
    ans+=dice[0];
}

void rl(int a,int b){
    int temp=0;
    temp=dice[1];
    dice[1]=dice[b];
    dice[b]=dice[4];
    dice[4]=dice[a];
    dice[a]=temp;
    ans+=dice[0];
}

void command(string ss){
    if(ss=="North")News(4,1);
    else if(ss=="East")News(2,3);
    else if(ss=="West")News(3,2);
    else if(ss=="South")News(1,4);
    else if(ss=="Right")rl(3,2);
    else if(ss=="Left")rl(2,3);
}

int main(){
    while(cin>>n){
        if(n==0)return 0;
        for(int i=0;i<n;i++){
            cin>>s;
            command(s);
        }
        cout<<ans<<endl;
        for(int i=0;i<=5;i++){
            dice[i]=i+1;
        }
        ans=1;
    }
}
/*
 1 5 5 6 6 2 2 1 North
 1 3 3 6 6 4 4 1 East
 1 4 4 6 6 3 3 1 West
 1 2 2 6 6 5 5 1 South
 2 4 4 5 5 3 3 2 Right
 2 3 3 5 5 4 4 2 Left
 */
 



Measured memory_bytes: 3184
// problem 3 : count it
#include <bits/stdc++.h>
using namespace std;

// Driver function
int main(){
    unsigned long int h, temp, count, i=1;
    cin >> h;

    // temp = (h-1)*2 + 1;

    count = 1;
    temp = ceil(h/2);

    while(h > 1){
        count += pow(2, i);
        h /= 2;
        i++;
    }

    cout << count;

    return 0;
}


Measured memory_bytes: 256
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UnboxedTuples #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE MultiWayIf #-}

import Control.Monad
import Control.Monad.ST
import Control.Monad.State
import Control.Applicative
import Data.List
import Data.Array
import Data.Array.IO
import Data.Maybe
import Data.Bits
import Data.Ord
import Data.Ratio
import Data.Int
import Data.Char
import qualified Data.ByteString.Char8 as BS
import qualified Data.Set as Set
import Data.Tuple
import Data.Function
import Text.Printf
import Debug.Trace
import Numeric

modifyArray arr i f = readArray arr i >>= \x -> writeArray arr i (f x)

listToTuple2 [a,b] = (a,b)
listToTuple3 [a,b,c] = (a,b,c)
listToTuple4 [a,b,c,d] = (a,b,c,d)
listToTuple5 [a,b,c,d,e] = (a,b,c,d,e)

getWords = getLine >>= return . words

readIntBS = fst . fromJust . BS.readInt

for = flip map

main :: IO ()
main = do
  (n,i) <- listToTuple2 . map read . words <$> getLine :: IO (Int,Int)
  print $ n - i + 1
  


Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
int a[200010];

int main() {
    int n, t;
    scanf("%d %d", &n, &t);
    for(int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
    }
    long long last = t;
    long long ans = t;
    for(int i = 2; i <= n; i++) {
        if(a[i] <= last) {
            ans += a[i] + t - last;
        } else {
            ans += t;
        }
        last = a[i] + t;
    }
    printf("%lld\n", ans);
}


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

const int MAX = 100005;
const int nil = -1;

struct Node{int parent, left, right; };

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u, int d){
    if(u == nil) return;
    D[u] = d;
    setDepth(T[u].left, d+1);
    setDepth(T[u].right, d+1);
}

int setHeight(int u){
    int h1 = 0, h2 = 0;
    if(T[u].left != nil){
        h1 = setHeight(T[u].left) + 1;
    }
    if(T[u].right != nil){
        h2 = setHeight(T[u].right) +1;
    }
    return H[u] = (h1 > h2? h1:h2);
}

// 節点uの兄弟を返す
int getSibling(int u){
    if(T[u].parent == nil) return nil;
    if(T[T[u].parent].left != u && T[T[u].parent].left != nil) return T[T[u].parent].left;
    if(T[T[u].parent].right != u && T[T[u].parent].right != nil) return T[T[u].parent].right;
    return nil;
}

void print(int u){
    printf("node %d: ", u);
    printf("parent = %d, ", T[u].parent);
    printf("sibling = %d, ", getSibling(u));
    int deg = 0;
    if(T[u].left != nil) ++deg;
    if(T[u].right != nil) ++deg;
    printf("degree = %d, ", deg);
    printf("depth = %d, ", D[u]);
    printf("height = %d, ", H[u]);

    if(T[u].parent == nil) printf("root\n");
    else if(T[u].left == nil && T[u].right == nil) printf("leaf\n");
    else printf("internal node\n");
}

int main(){
    cin >> n;
    for(int i=0; i<n; ++i) T[i].parent = nil;

    int id, l, r;
    for(int i=0; i<n; ++i){
        cin >> id >> l >> r;
        T[id].left = l;
        T[id].right = r;
        if(l != nil) T[l].parent = id;
        if(r != nil) T[r].parent = id;
    }

    int root;
    for(int i=0; i<n; ++i) if(T[i].parent == nil) root = i;

    setDepth(root, 0);
    setHeight(root);

    for(int i=0; i<n; ++i) print(i);
    return 0;
}


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

int main() {
  int A , B , C , K ;
  int i = 0;
  cin >> A >> B >> C >> K;
  
  while(i<K){
  if(A>=B){
    if(A>=C){
        A=A*2;
      }
  }
  if(B>=A){
    if(B>=C){
      B = B*2;
      }
  }
  if(C>=A){
    if(C>=B){
      C = C*2;
    }
  }
   i++;
  }
  
  cout << A+B+C << endl;
  // ここにプログラムを追記
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){

    int n,x,t,a;

    scanf("%d %d %d",&n,&x,&t);


    if(n%x==0){
        a = n/x;
    }else{
        a = n/x +1;
    }
    printf("%d\n",a*t);

    return 0;
}

Measured memory_bytes: 1704
R,G,B,N = map(int,input().split())
ans = 0
for r in range(N//R + 1) :
    for g in range((N-r)//G + 1) :
        calc = r*R + g*G
        if N < calc :
            break
        if (N-calc) % B == 0 :
            ans += 1
print(ans)


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

using namespace std;

int main() {
    int N; cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];

    vector<int> ans(N, 0);
    int sum = accumulate(a.begin(), a.end(), 0);

    ans[0] = sum;
    for (int i = 1; i < N-1; i+=2) {
        ans[0] -= 2*a[i];
    }

    for (int i = 1; i < N; i++) {
        ans[i] = 2*a[i-1] - ans[i-1];
    }

    for (int i = 0; i < N; i++) cout << ans[i] << endl;
    

    
}


Measured memory_bytes: 2048
N=int(input())
x,y=map(list,zip(*[list(map(int,input().split())) for i in range(N)]))
x=sorted(zip(x,range(N)))
y=sorted(zip(y,range(N)))
from heapq import heappop,heappush
qx,qy=[(10**9+1,0,0)],[(10**9+1,0,0)]
for i in range(N-1):
    heappush(qx,(x[i+1][0]-x[i][0],x[i][1],x[i+1][1]))
    heappush(qy,(y[i+1][0]-y[i][0],y[i][1],y[i+1][1]))
r=0
class UnionFind:
    def __init__(self,N):
        self.Parent=[-1]*N
    def unite(self,m,n):
        rm=self.root(m)
        rn=self.root(n)
        if rm==rn:
            return False
        else:
            if self.size(rm)<self.size(rn):
                rm,rn=rn,rm
            self.Parent[rm]+=self.Parent[rn]
            self.Parent[rn]=rm
            return True
    def root(self,n):
        if self.Parent[n]<0:
            return n
        else:
            self.Parent[n]=self.root(self.Parent[n])
            return self.Parent[n]
    def size(self,n):
        return -self.Parent[self.root(n)]
u=UnionFind(N)
while u.size(0)<N:
    d,i,j=heappop(qx) if qx[0]<qy[0] else heappop(qy)
    if u.unite(i,j):
        r+=d
print(r)

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


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


Measured memory_bytes: 3664
#include "bits/stdc++.h"
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
	int A, B, m;
	cin >> A >> B >> m;
	vector<int> a(A), b(B), c(m);
	int amin = 1001001001, bmin = 1001001001;
	rep(i, A){
		cin >> a[i];
		amin = min(amin, a[i]);
	}
	rep(i, B){
		cin >> b[i];
		bmin = min(bmin, b[i]);
	}
	vector<pair<int, int>> xy(m);
	rep(i, m) {
		int x, y;
		cin >> x >> y >> c[i];
		x--; y--;
		xy[i] = make_pair(x, y);
	}
	int ans = amin + bmin;
	rep(i, m) {
		int x = xy[i].first;
		int y = xy[i].second;
		ans = min(ans, a[x] + b[y] - c[i]);
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
set<ll>v;
void gen(ll x){
    if(x>1e10)return ;
    if(x>0)v.insert(x);
    ll r = x%10;
    if(r!=9)gen(x*10ll+r+1);
    gen(x*10ll+r);
    if(r!=0)gen(x*10ll+r-1);
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	for(int i=1;i<=9;i++)gen(i);
	int k;
	cin>>k;
	for(auto x:v){
        if(k==1){
            cout<<x<<endl;
            break;
        }
        k--;
	}

	return 0;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, l, r) for (int i = l; i <= (int)(r); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define all(v) v.begin(), v.end()
#define MOD (int) (1e9+7)
#define INF (int) 1e9
#define LLINF (ll) 1e18

ll mpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a;
        a = a * a;
        n >>= 1;
    }
    return res;
}

int main(){
    ll n;
    cin >> n;
    n--;

    int d = 1;
    rep(i, 15){
        if(n >= mpow(26, i+1)){
            n -= mpow(26, i+1);
            d++;
        }else{
            break;
        }
    }

    int ans[d];
    rep(i, d){
        ans[i] = n%26;
        n /= 26;
    }

    rep(i, d){
        cout << (char)('a'+ans[d-1-i]);
    }
    cout << endl;
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 3640
n=int(input())
s=[]
c0=0
c1=0
c2=0
c3=0
for i in range(n):
    s=input()
#    s.append(str(input()))
    if s=="AC":
        c0+=1
    if s=="WA":
        c1+=1
    if s=="TLE":
        c2+=1
    if s=="RE":
        c3+=1
print("AC x",c0)
print("WA x",c1)
print("TLE x",c2)
print("RE x",c3)


Measured memory_bytes: 9196
s = input()
count = 0
for i in range(len(s)):
  if i % 2 != 0 and (s[i] == 'L' or s[i] == 'U' or s[i] == 'D'):
    count += 1
  elif i % 2 == 0 and (s[i] == 'R' or s[i] == 'U' or s[i] == 'D'):
    count += 1
if count == len(s):
  print('Yes')
else:
  print('No')

Measured memory_bytes: 9056
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<functional>
#include<vector>

using namespace std;
#define endl '\n'
#define pb push_back
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1e9 + 7)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define REP(i,n) for(int i = 0;i < (n);i++)
#define FOR(i,a,b) for(int i = (a);i <= (b);i++)
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) > "Yes" : "No" ) << endl


typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vector<int>> vii;

template <class T = int> T in() { T x; cin >> x; return (x); }
template <class T = int> void out(T x) { cout << (x) << endl; }

int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

void solve() {

	int n = in(), tmp, cnt = 0;

	for(int i = 1; i <=n; i+=2) {
		tmp = 0;
		FOR(j, 1, i) {
			if (i % j == 0) {
				tmp++;
			}
		}
		if (tmp == 8) cnt++;
	}

	out(cnt);

	return;
}

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	solve();

	return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int A[1000000];
int cnt=0;
void insertSort(int A[],int n,int g){
    int j,v;
    for(int i=g;i<n;i++){
        v=A[i];
        j=i-g;
        while(j>=0 && A[j]>v){
            A[j+g]=A[j];
            j-=g;
            cnt++;
        }
        A[j+g]=v;
    }
}
void shell(int A[],int n){
    cnt=0;
    int h=1;
    vector<int> G;
    while(h<=n){
        G.push_back(h);
        h=3*h+1;
    }
    for(int i=G.size()-1;i>=0;i--){
        insertSort(A,n,G[i]);
    }
    cout<<G.size()<<endl;
    for(int i=G.size()-1;i>=0;i--){
        cout<<G[i];
        if(i) cout<<' ';
    }
    cout<<endl<<cnt<<endl;
}
int main(){
    int n,k;
    cin>>n;
    for(int i=0;i<n;i++){
        //cin>>k;
        //A.push_back(k);
        cin>>A[i];
    }
    shell(A,n);
    //insertSort(A,n,1);
    for(int i=0;i<n;i++){
        cout<<A[i]<<endl;
    }
    return 0;
}



Measured memory_bytes: 6964
# coding: utf-8
# Your code here!
N,K,Q = map(int,input().split())

A = []
for i in range(Q):
    A.append(int(input()))

array = [0] * (N + 10)
for i in range(Q):
    array[A[i]] += 1

for i in range(1, N + 1):
    if K - (Q - array[i]) <= 0:
        print("No")
    else:
        print("Yes")

Measured memory_bytes: 56536
import java.util.*;
 
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
      
      	int card = sc.nextInt();
      	int nam = sc.nextInt();
      	int max = -1;int min = 999999;
      
      for(int i = 0; i < nam ;i++){
      	 max = Math.max(max,sc.nextInt());
         min = Math.min(min,sc.nextInt());
      }
      	int cnt = 0;
      	for(int i = max;i <=min;i++){
        cnt++;
        }

		System.out.print(cnt);
      	


    }
}

Measured memory_bytes: 64464
n,k= map(int, input().split())
if n == k :
    print("Yes")
else:
    print("No")

# p = list(map(int,input().split()))

# count = 0
# val = sum(p[0:k])
# val_lis = [val]
# mx_val = val
# index = 0
# mx_index = 0
# for i,j in enumerate(p[k:]):
#     val = val - p[index] + j
#     val_lis.append(val)
#     index +=1
#     if val > mx_val:
#         mx_index = index
#         mx_val = val 
    
# ans = 0
# for i in range(k):
#     ans += ((p[mx_index + i]+1.0)*(p[mx_index+i]))/ (p[mx_index+i] *2.0)
# print(ans)  




# h = sorted(h,reverse = True)
# print(sum(h[k:]))

# s,t= map(str, input().split())
# a,b= map(int, input().split())
# u = input()
# print("x"*len(u))

# if(u == s):
#     print(a-1,b)
# else:
#     print(a,b-1)


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

#define rep(i,n) for(int i=0;i< (n);++i)
#define REP(i,n) for(int i=1;i<=(n);++i)
#define ALL(a) (a).begin(),(a).end()
using LLI = long long int;
LLI GCD(LLI a,LLI b){ if(a<b) return GCD(b,a); else if(a%b==0) return b; else return GCD(b,a%b); }
LLI LCM(LLI a,LLI b){ return (a/GCD(a,b))*b; }
using VI  = std::vector<LLI>;
using PI  = std::pair<LLI,LLI>;
using VVI = std::vector<VI>;
using VPI = std::vector<PI>;

int main() {
    std::ios::sync_with_stdio(false);
    LLI N,M,R;
    std::cin >> N >> M >> R;

    VI r(R);
    rep(i,R) {
        std::cin >> r[i] ;
        --r[i];
    }

    LLI dist[205][205] = {};
    rep(i,N)
        rep(j,N)
            if( i != j )
                dist[i][j] = 200 * 100000 + 1; // infinity
            else
                dist[i][j] = 0; // self

    rep(i,M) {
        LLI A,B,C;
        std::cin >> A >> B >> C;
        --A; --B;
        dist[A][B] = dist[B][A] = C;
    }

    rep(k,N)
        rep(i,N)
            rep(j,N)
                dist[i][j] = std::min(dist[i][j],dist[i][k]+dist[k][j]);

    std::sort(ALL(r));
    LLI ans = 200 * 100000 * 8 + 1;
    do {
        LLI sum = 0;
        rep(i,R-1)
            sum += dist[r[i]][r[i+1]];
        ans = std::min(ans,sum);
    } while (std::next_permutation(ALL(r)));
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
#define PUTS(x) std::cout << (x) << endl;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define F first
#define S second
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())
#define MOD 1000000007

#define INF 1e12



int main() {
    Int n;
    cin >> n;
    Int m = INF;
    Int M = -INF;
    Int m2 = INF;
    Int M2 = -INF;
    rep(i, n) {
        Int x, y;
        cin >> x >> y;
        m = min(m, x + y);
        M = max(M, x + y);
        m2 = min(m2, x - y);
        M2 = max(M2, x - y);
    }
    PUTS(max(M - m, M2 - m2));
}

Measured memory_bytes: 3616
#include<iostream>
using namespace std;
int main()
{
    // 整数の入力
    int x1=0, x2=2, x3=3, x4=4, x5=5;
    cin >> x1 >> x2 >> x3 >> x4 >> x5;
  	// 解答の代入
  	int ans;
  	if (x1 == 0) {ans = 1;}
  	if (x2 == 0) {ans = 2;}
  	if (x3 == 0) {ans = 3;}
  	if (x4 == 0) {ans = 4;}
  	if (x5 == 0) {ans = 5;}
    // 出力
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3520
#include <algorithm>
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>
#include <climits>
#include <utility>
#include <deque>
#include <list>
#include <stdexcept>
using namespace std;

int main()
{
	cout << fixed << setprecision(6);
	int r;
	cin >> r;
	cout << 3 * r * r << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
	char a[200];
	int s[200];
	int i,n,j=0;
	scanf("%s",a);
	n=strlen(a);
	for(i=0;i<200;i++)
	{
		s[i]=-1;
	}
	for(i=0;i<n;i++)
	{
		if(a[i]=='0'||a[i]=='1')
		{
			s[j]=a[i]-'0';
			j++;
		}
		else if(a[i]=='B'&&j>0)
		{
			j--;
			s[j]=-1;
		}
	}
	for(i=0;i<j;i++)
	{
		printf("%d",s[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 128
// 1_6_D
#include <iostream>
using namespace std;

int main(){
  int n, m, i, j;
  cin >> n >> m;
  int matrix[n][m] = {}, vector[m] = {}, product[n] = {};

  for(i = 0; i < n; i++){
    for(j = 0; j < m; j++){
      cin >> matrix[i][j];
    }
  }
  for(i = 0; i < m; i++){
    cin >> vector[i];
  }

  for(i = 0; i < n; i++){
    for(j = 0; j < m; j++){
      product[i] += matrix[i][j] * vector[j];
    }
  }

  for(i = 0; i < n; i++){
    cout << product[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 3128
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000
#define int long long

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    int A[200010], F[200010];
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> F[i];
    sort(A, A + N, greater<int>());
    sort(F, F + N);
    int ok = INF2;
    int ng = -1;
    while(abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;
        int need = 0;
        rep(i, N) {
            int lack = max(0LL, A[i] * F[i] - mid);
            need += (lack + F[i] - 1)/F[i];
        }
        if (need <= K) ok = mid;
        else ng = mid;
        //cout << mid << " " << need << endl;
    }
    cout << ok << endl;

    return 0;
}
// 4 2 1
// 1 2 3

Measured memory_bytes: 3328
#include <cstdio>
#include <utility>
#include <queue>
#include <vector>
using namespace std;

int main(){
	typedef pair<int,int> pii;
	
	priority_queue< pii, vector<pii>, greater<pii> > qu;
	int tr[100002];
	int i, N, L, t = 0;
	
	scanf("%d%d", &N, &L );
	for( i = 1; i <= N; i++ )	scanf("%d", tr + i );
	
	tr[0] = tr[N+1] = 0;
	for( i = 1; i <= N; i++ )
		if( tr[i] > tr[i-1] && tr[i] > tr[i+1] ){
			qu.push( pii( L - tr[i], i ) );
			tr[i] = L;
		}

	while( !qu.empty() ){
		pii p = qu.top();
		qu.pop();
		
		t = p.first;
		int s = p.second;
		tr[s] = 0;
		if( tr[s-1] != 0 && tr[s-1] != L  && tr[s-1] > tr[s-2] ){
			qu.push( pii( t + L - tr[s-1], s-1 ) );
			tr[s-1] = L;
		}
		if( tr[s+1] != 0 && tr[s+1] != L  && tr[s+1] > tr[s+2] ){
			qu.push( pii( t + L - tr[s+1], s+1 ) );
			tr[s+1] = L;
		}
	}
	printf("%d\n", t );
}

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

struct Node{
    int key;
    Node *right, *parent, *left;
};

Node *root;
Node *NIL;

void insert(int k){
    Node *y = NIL;
    Node *x = root; // 走査用
    Node *z;

    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while(x != NIL){
        y = x;
        if(x->key > z->key){
            x = x->left;
        }else{
            x = x->right;
        }
    }

    z->parent = y;
    if(y == NIL){
        root = z;
    }else if(y->key > z->key){
        y->left = z;
    }else{
        y->right = z;
    }
}

void inorder(Node *u){
    if(u == NIL)    return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}

void preorder(Node *u){
    if(u == NIL)    return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}

Node* find(Node *u, int x){
    while(u != NIL && u->key != x){
        if(u->key < x){
            u = u->right;
        }else{
            u = u->left;
        }
    }
    return u;
}

int main(){
    int n, i, x;
    string com;
    scanf("%d", &n);
    
    for(i = 0; i < n; i++){
        cin >> com;
        if(com == "insert"){
            scanf("%d", &x);
            insert(x);
        }else if(com == "print"){
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }else if(com == "find"){
            scanf("%d", &x);
            if(find(root, x) != NIL) printf("yes\n");
            else               printf("no\n");
        }
    }

    return 0;
}


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


int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a.at(i);
  
  vector<ll> x(n);
  rep(i, n){
    if((i+1)%2 == 1) x.at(0) += a.at(i);
    else x.at(0) -= a.at(i);
  }
  for(int i = 1; i < n; i++){
    x.at(i) = 2*a.at(i-1) -x.at(i-1);
  }
  
  rep(i, n) cout << x.at(i) << endl;
}

Measured memory_bytes: 2944
#include <iostream>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int cur_sock = 1;
  int 
  ans = 0;
  while(cur_sock < m) {
  	cur_sock += (n - 1);
  	ans++;
  }
  return cout << ans, 0;
}
  

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP0(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define RREP0(i,n) for(int i=n-1; i>=0; --i)
#define RREP1(i,n) for(int i=n; i>=1; --i)
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define FILL(c, v) fill((c).begin(),(c).end(), v)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define CLR(a) memset((a), 0 ,sizeof(a))

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long LL;
typedef unsigned long long ULL;

const int INTINF = 1e9;
const LL LLINF = 1e18;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int N;

int dfs(int rem_digit, string ptn, int s3, int s5, int s7)
{
    if (rem_digit==0)
    {
        if (s3 * s5 * s7 > 0 and toInt(ptn) <= N) return 1;
        else return 0;
    }
    int p1 = dfs(rem_digit - 1, ptn + "3", s3 + 1, s5, s7);
    int p2 = dfs(rem_digit - 1, ptn + "5", s3, s5 + 1, s7);
    int p3 = dfs(rem_digit - 1, ptn + "7", s3, s5, s7 + 1); 
    return p1 + p2 + p3;
}

void solve()
{
    cin >> N;

    int digit = 1; int tmp = N;
    while(tmp/10>0) { digit++; tmp /= 10; }

    int ans = 0;
    FOR(i, 3, digit+1)
    { // 3桁から N の桁数まで
        ans += dfs(i, "", 0, 0, 0);
    }

    cout << ans << endl;

}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;

int main()
{
  int n;
  cin>>n;
  vecint h(n);
  REP(i,n) cin>>h[i];
  reverse(ALL(h));
  bool ok = true;
  REP(i,n-1) {
    if (h[i+1] > h[i] + 1) ok = false;
    if (h[i+1] == h[i] + 1) --h[i+1];
  }
  if (ok) {
    cout<<"Yes"<<endl;
  } else {
    cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 640
#define REP(i, t, n)  for (int i = t; i < n; i++)
#define ALL(n)        (n).begin(),(n).end()
#include <limits.h>
#include <stdio.h>
#include <cmath>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <deque>
#include <functional>
#include <algorithm>
#include <cstring>
#include <unordered_map>
#include <numeric>

using namespace std;

typedef bool               BOOL;
typedef short              WORD;
typedef unsigned short     U_WORD;
typedef long               DWORD;
typedef unsigned long      U_DWORD;
typedef long long          QWORD;
typedef unsigned long long U_QWORD;


//ABC084-D 2017-like Number
#define MAX_NUM (100000)

vector<DWORD> vdwPrime;
bool abIsPrime[MAX_NUM + 1] = {};
DWORD adwCumSum[MAX_NUM + 1] = {}; 

bool isPrime(QWORD n)
{
	if (n == 0) {
		return false;
	} else if (n == 1) {
		return false;
	} else if (n == 2) {
		return true;
	}

	for (QWORD i = 2; i * i <= n; i++) {
		if (n % i == 0) return false;
	}
	return true;
}


void makeSieveTable(QWORD n) //エラトステネスの篩の表を作成
{
	QWORD primeNum = 0;
	REP(i, 0, n + 1) abIsPrime[i] = true;
	abIsPrime[0] = abIsPrime[1] = false;

	REP(i, 2, n + 1) {
		if (abIsPrime[i]) {
			primeNum++;
			vdwPrime.push_back(i);

			for (int multiNum = i * 2; multiNum <= n; multiNum += i) {
				abIsPrime[multiNum] = false;
			}
		}
	}
}

void procLikeNum()
{
	auto itr = vdwPrime.begin();

	for (auto itr = vdwPrime.begin(); itr != vdwPrime.end(); ++itr) {
		QWORD n = (*itr + 1) / 2;
		if (!isPrime(n)) {
			abIsPrime[*itr] = false;
		}
	}
}

void calcCumSum(QWORD n)
{

	DWORD nowNum = 0;

	REP(i, 0, MAX_NUM + 1) {
		if (abIsPrime[i]) {
			nowNum ++;
		}
		adwCumSum[i] = nowNum;
	}

}

void solve_main()
{
	QWORD N = MAX_NUM;
	makeSieveTable(N);

	procLikeNum();
	calcCumSum(N);

	DWORD Q;
	cin >> Q;

	REP(i, 0, Q) {
		DWORD l, r;
		cin >> l >> r;
		cout << adwCumSum[r] - adwCumSum[l - 1] << endl;
		
	}
}

int main()		
{
#ifdef FOR_IDE
	ifstream in("input.txt");
	cin.rdbuf(in.rdbuf());
#endif

	solve_main();
	return 0;
}

Measured memory_bytes: 1664
#include<iostream>
#include<vector>
#include<queue>
#include<cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<set>
#define INF 2147483647
#define lli long long int

using namespace std;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
int main() {
	lli x; cin >> x;
	lli amari = x % 11;
	lli syo = x / 11;
	if (amari <= 6 and amari != 0){
		cout << syo *2+ 1 << endl;
	}else if(amari == 0){
		cout << syo * 2 << endl;
	}else{
		cout << syo *2+ 2 << endl;
	}
	return 0;
}





Measured memory_bytes: 256
h, w = map(int, input().split())
a = [input() for _ in range(h)]
ans = ['#'*(w+2)]
# print(ans)
for i in range(h):
    ans.append('#' + a[i] + '#')

ans.append('#'*(w+2))
for i in range(h+2):
    print(ans[i])


Measured memory_bytes: 9088
a,b = map(int,input().split())

if a > b: #一応a<=bの制約はあるので実際はいらない
    a,b = b,a

"""
制約10**12は、2**40に収まるので、外側のループを2**40にする
>>> 10**12 < 2**40
True

また、aからbまでを愚直に足していくわけには行かず、ここに法則を見出す必要がある。
a,bに対して、
ans = 0~bまでのXOR ^ 0~(a-1)までのXOR (^は演算子でXOR)

ということができる。
あとは、各桁ごとの0~Xに対するXORを求める関数を作れば良い。

法則：
0~Xまでの各桁の2進数表記には周期がある。
2**0桁：0 1 0 1 0 1 0 1 (周期2)
2**1桁：0 0 1 1 0 0 1 1 (周期4)
2**2桁：0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 (周期8)
2**3桁：0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 (周期16)...
2**k桁目の周期 loop = 2*(i+k)
よって、この周期性を式に起こした上で、その桁における1の出現回数の偶奇が0~Xのその桁におけるXORの和
"""

def search_cycle(k): #引数；何桁目か
    loop = 1<<(k+1) #周期が2**nに従っているのは明らかなので、ビットシフトを用いる
    return loop

def func(x): #0~X-1のXORを求める
    if x==0: return 0
    ans = 0
    for i in range(40): #制約上、10**9<2**40である
        loop = search_cycle(i)
        count = (x//loop) * (loop//2) #(loopした回数)*(1が出てきた回数) (端数は次に計算)
        amari = max(0,x%loop - (loop//2)) #割り切れなかった部分について、000...111..なので
        #000...のところを引いてやって、111...のところの合計をcountに足してやる(負の数を除去)
        count += amari
    
        #いよいよ偶奇が求まったので、全てのXORが1だった場合はans += i**2をする。
        if count %2 == 1:
            ans += 1<<i
    
    return ans

print(func(b+1) ^ func(a)) #A~BのXOR = 0~BのXOR ^ 0~(A-1)のXOR

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

int main()
{
  int H, W; cin >> H >> W;
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      string str; cin >> str;
      if (str == "snuke") {
        cout << (char)('A'+j) << i + 1 << endl;
        return 0;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <cstring>
#include <map>
#include <climits>
#include <bitset>

#define ll long long
const ll MOD = 1e9 + 7;
const ll INF = 1 << 29;


int main()
{
    int N, Q;
    std::cin >> N >> Q;

    std::string S;
    std::cin >> S;

    std::vector<int> sum(N+1, 0);
    for (auto i=0; i<N; ++i)
    {
        sum[i+1] = sum[i];
        if (S[i] == 'C' && S[i-1] == 'A')
            sum[i+1]++;
    }

    for (auto i=0; i<Q; ++i)
    {
        int from, to;
        std::cin >> from >> to;
        std::cout << sum[to] - sum[from] << std::endl;
    }
}


Measured memory_bytes: 3804
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

class Main{

	public static void main(String[] args) throws IOException{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();

		while(true){

			String[] token = br.readLine().split(" ");
			int h = Integer.parseInt(token[0]);
			int w = Integer.parseInt(token[1]);

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

			for(int i = 0; i < h; i++){
				for(int j = 0; j < w; j++){
					if(i == 0 || i == h - 1 || j == 0 || j == w - 1){
						sb.append("#");
					}else{
						sb.append(".");
					}
				}
				sb.append("\n");
			}
			sb.append("\n");

		}

		System.out.print(sb);

	}
}

Measured memory_bytes: 25444
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

s,t = input().split()
a,b = get_nums_l()
u = input()

if u == s:
    print(a-1, b)
else:
    print(a, b-1)

Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define int long long
#define REP(i,a,n) for(int i=a;i<(n);i++)
#define REP_sz(i,s) for(int i=0;i<s.size();i++)
#define RE return
#define FILL(a,b) memset(a,b,sizeof(a))
#define SO(a) sort(all(a))
#define pb push_back
#define sz(a) a.size()
#define V vector
#define ld long double
#define viit(a) vector<int>::iterator a
#define msit1(a) map<string,int>::iterator a
#define miit(a) map<int,int>::iterator a
#define msit2(a) map<int,string>::iterator a
#define IT iterator
#define FOR(i,a,n) for(int i=a;i<=(n);i++)
#define B(s) s.back()
#define all(a) a.begin(),a.end()
#define ER1(a) a.erase(a.begin())
#define ER0(a) a.erase(a.end())
#define pii pair<int,int>
#define pause system("PAUSE")
#define cls system("CLS")
using namespace std;
bool isMonth(int month)
{
	return month>=1&&month<=12;
}
signed main()
{
	ios::sync_with_stdio(0);
    cin.tie(0);
	string s;
	cin>>s;
	int mon1=(s[0]-'0')*10+(s[1]-'0');
	int mon2=(s[2]-'0')*10+(s[3]-'0');
	if(isMonth(mon1)&&!isMonth(mon2))cout<<"MMYY\n";
	else if(!isMonth(mon1)&&isMonth(mon2))cout<<"YYMM\n";
	else if(isMonth(mon1)&&isMonth(mon2))cout<<"AMBIGUOUS\n";
	else if(!isMonth(mon1)&&!isMonth(mon2))cout<<"NA\n";
    return 0;
}


Measured memory_bytes: 3624
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

typedef long long ll;

using namespace std;

int solve(int n,int k){
    bool card[100001]={0};
    int in,ren=0,renw=0,ans=0;
    
    for(int i=0;i<k;i++){
        scanf("%d",&in);
        card[in]=true;
    }
    
    for(int i=1;i<=n;i++){
        if(card[i]){
            ren++;
            renw++;
        }else if(card[0]){
            if(ren){
                renw=ren+1;
                ren=0;
            }else{
                renw=0;
            }
        }else{
            renw=0;
        }
        
        ans=max(ans,renw);
    }
    
    printf("%d\n",ans);
    
    return 0;
}

int main(){
    int n,k;
    
    while(1){
        scanf("%d%d",&n,&k);
        if(n+k==0)
            break;
        solve(n,k);
    }
    
    return 0;
}

Measured memory_bytes: 1292
x,n = map(int, input().split())
if n==0:
  print(x)
else:
  p = list(map(int, input().split()))
  p.append(0)
  while True:
    if p[n]%2==1:
      s = x-((p[n]+1)/2)
      #print(s,"こ")
    else:
      s = x+(p[n]/2)
      #print(s,"ここ")
    if s not in p:
      print(int(s))
      break
    else:
      p[n]+=1
  

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

using namespace std;

#define INF 999999999

struct team{
	int id, ac, pe;
	
	bool operator<(const team& a) const{
		if(ac != a.ac) return ac > a.ac;
		if(pe != a.pe) return pe < a.pe;
		if(id != a.id) return id < a.id;
	}
};

int main(){
	int i, j, t, p, r, tid, pid, time, wa[51][11];
	string ma;
	vector<team> set(51);
	while(1){
		cin >> t >> p >> r;
		if(!t) break;
		for(i=0;i<=t;i++){
			set[i].id = i;
			set[i].pe = 0;
			set[i].ac = 0;
			for(j=0;j<=p;j++) wa[i][j] = 0;
		}
		for(i=0;i<r;i++){
			cin >> tid >> pid >> time >> ma;
			if(ma == "WRONG") wa[tid][pid]++;
			else{
				set[tid].ac++;
				set[tid].pe += wa[tid][pid]*1200 + time;
			}
		}
		sort(set.begin()+1, set.begin()+t+1);
		for(i=1;i<=t;i++){
			cout << set[i].id << " " << set[i].ac << " " << set[i].pe << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N, K, R, S, P; cin >> N >> K >> R >> S >> P;
  string T; cin >> T;
  vector<char> A(K);
  long long ans = 0;
  
  for(int i = 0; i < N; i++){
    if(i<K){
      A.at(i) = T.at(i);
      if(T.at(i) == 'r') ans += P;
      if(T.at(i) == 's') ans += R;
      if(T.at(i) == 'p') ans += S;
    }
    else if(A.at(i%K) == T.at(i)) A.at(i%K) = 'n';
    else{
      A.at(i%K) = T.at(i);
      if(T.at(i) == 'r') ans += P;
      if(T.at(i) == 's') ans += R;
      if(T.at(i) == 'p') ans += S;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
int main()
{    
	int a,b;
	cin>>a>>b;
	string c;
	for(int i=1;i<=a+b+1;i++) cin>>c[i];
	int flag=0;
	for(int i=1;i<=a+b+1;i++)
	{
		if((c[i]<'0'||c[i]>'9')&&i!=a+1)
			flag=1;
	}
	if(flag==0&&c[a+1]=='-')
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
n,k = map(int, input().split())

ans = 0
mod = 10**9+7

for i in range(k,n+2):
    # print((n*(n+1)/2 - (n-i)*(n-i+1)/2 - (i-1)*i/2 +1))
    ans += int((n*(n+1)/2 - (n-i)*(n-i+1)/2 - (i-1)*i/2 +1))

if ans >= mod:
    print(ans%mod)
else:
    print(ans)

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

int main() {
  int N, K;
  
  cin >> N >> K;
  
  vector<int> vec(N);
  
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  std::sort(vec.begin(),vec.end());//昇順ソート
  int out = 0;
  for (int i = 0; i < K; i++) {
    out+=vec[i];
  }
  
  std::cout << out << std::endl;
  
}


Measured memory_bytes: 3636
def check(h,w):
    if (h+w)%2 == 0:return'#'
    return'.'
while True:
    H,W = map(int,input().split())
    for h in range(H):
        for w in range(W):
             print(check(h,w),end="")
        print()
    if H ==0 and W==0:
        break
    else:
        print()
    
    
    


Measured memory_bytes: 7004
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <utility>
using namespace std;
int xd[]={1,0,0,-1};
int yd[]={0,1,-1,0};
int main()
{
	int W,H;
	while(cin>>W>>H,W!=0){
		vector<string> board(H);
		queue<pair<int,int> > q;
		for(int i=0;i<H;i++)
			cin>>board[i];
		for(int i=0;i<H;i++){
			string::iterator
			p=find(board[i].begin(),board[i].end(),'@');
			if(p!=board[i].end()){
				q.push(pair<int,int>(i,p-board[i].begin()));
				break;
			}
		}
		int count=0;
		while(!q.empty()){
			pair<int,int> v=q.front();
			q.pop();
			if(board[v.first][v.second]=='#')continue;
			board[v.first][v.second]='#';
			count++;
			for(int i=0;i<4;i++){
				int newx=xd[i]+v.first;
				int newy=yd[i]+v.second;
				if(0<=newx&&newx<H&&0<=newy&&newy<W
						&&board[newx][newy]=='.')
					q.push(pair<int,int>(newx,newy));

			}
		}
		cout<<count<<endl;
	}
	return 0;
}

Measured memory_bytes: 1236
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int32_t, int32_t>;

bool CanMove(const Pair &p1, const Pair &p2) {
  return ((p1.first + p1.second) == (p2.first + p2.second) || (p1.first - p1.second) == (p2.first - p2.second));
}

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

  int64_t H, W;
  cin >> H >> W;
  if (H == 1 || W == 1) {
    cout << 1 << endl;
  } else {
    cout << (((W + 1) / 2LL) * ((H + 1LL) / 2LL) + (W / 2LL) * (H / 2LL)) << endl;
  }
  return 0;
}


Measured memory_bytes: 256
N=gets.to_i
s=gets.chomp.chars.map{|c|c=='o' ? 'S' : 'W'}

['SS','SW','WW','WS'].each do |c|
  ret = c.dup
  i = 2
  while i < N
    ret << ((s[i-1]==ret[-1])==(ret[-2]=='S') ? 'S' : 'W')
    i += 1
  end
  if ((s[-1]==ret[-1]) == (ret[-2]==ret[0])) &&
    (s[0]==ret[0]) == (ret[-1]==ret[1])
    puts ret
    exit 0
  end
end

puts -1


Measured memory_bytes: 16764
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;

const int size = 100001;

int dp[size];
int stone[size];

int frog(int n){
    if(n <= 0)
        return 0;
    if(dp[n] != -1)
        return dp[n];
  	if(n - 2 >= 0)
    	return dp[n] = min(frog(n - 1) + abs(stone[n] - stone[n - 1]), frog(n - 2) + abs(stone[n] - stone[n - 2]));
	else if(n - 1 >= 0)
      	return dp[n] = frog(n - 1) + abs(stone[n] - stone[n -1]);
}

int main(){
    int n;
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> stone[i];
    for(int i = 0; i < n; i++)
        dp[i] = -1;
    cout << frog(n - 1) << endl;

}

Measured memory_bytes: 2560
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


int main()
{
	int n;
	string s;

	cin >> n >> s;

	int res = 1;
	string prev = s.substr(0, 1);
	for (int i = 1; i < n; i++)
	{
		if (prev != s.substr(i, 1))
		{
			res++;
		}

		prev = s.substr(i, 1);
	}

	println(res);
}


Measured memory_bytes: 512
#include<stdio.h>

int road[20][20] = {}, count = 0;

int sroad(int x, int y){
	if( road[x][y] == 2 ) count++;
	if( road[x+1][y] != 0 ) sroad(x+1,y);
	if( road[x][y+1] != 0 ) sroad(x,y+1);
	return count;
}
int main(void){
	
	int a, b, n, i, j;
	
	while(1){
		scanf("%d %d", &a, &b);
		if(a == 0 && b == 0) break;
		
		for(i = 0; i < 20; i++){
			for(j = 0; j < 20;j++){
				road[i][j] = 0;
			}
		}
		
		scanf("%d",&n);
		
		for( i = 1; i < a+1; i++ ){
			for( j = 1; j < b+1; j++ ){
				road[i][j] = 1;
			}
		}
		
		road[a][b] = 2;
		
		for( i = 0; i < n; i++ ){
			scanf("%d %d", &a, &b);
			road[a][b] = 0;
		}
		
		count = 0;
		printf("%d\n", sroad(1,1));
	}
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <memory.h>
#include <cassert>

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;


int main() {
	char c;
	map<int, int> ps;
	set<int> x;
	for (int a, b; cin >> a >> c >> b, (a | b) != 0; ) {
		ps[a] = b;
		x.insert(b);
	}
	for (int n; cin >> n; ) {
		int p = ps[n];
		int res = 0;
		for (__typeof(x.rbegin()) i = x.rbegin(); i != x.rend(); i++) {
			res++;
			if (*i == p) break;
		}
		cout << res << endl;
	}
	
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  std::vector<double> vec(n);
  rep(i,n) cin >> vec.at(i);
  double total = 0.0;
  int i = 0;
  while (vec.size() != 1) {
    sort(vec.begin(), vec.end());
    total = (vec.at(i) + vec.at(i+1)) / 2.0;
    reverse(vec.begin(), vec.end());
    vec.pop_back();
    vec.pop_back();
    vec.push_back(total);
  }
  cout << vec.at(0) << endl;
}


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

int n,x,y,ans;

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d %d",&x,&y);
		ans+=y-x+1;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
/**
* Think twice, code once.
* 1.integer overflow(maybe even long long overflow : (a+b >= c) -> (a >= c-b)
* 2.runtime error
* 3.boundary condition
* ---------------------------------------------------------------------------------------
* Author : zzy
* Date : 2020-03-12-20.13.34 Thursday
*/
#include <bits/stdc++.h>

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, r, l) for (int i = (r); i >= (l); i--)
#define ms(x, y) memset(x, y, sizeof(x))
#define SZ(x) ((int)(x).size())

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) {
    return a > b ? (a = b, true) : false;
}
template<class T> bool uax(T &a, T b) {
    return a < b ? (a = b, true) : false;
}

const i64 maxn = 2*(i64)1e5 + 1000;
const i64 mod = 998244353;
i64 n, rmost[maxn], dp[maxn], a[maxn], tVal[maxn<<4];
struct node {
    i64 l, d;
} rev[maxn];

int query(int node, int l, int r, int ql, int qr) {
    if (ql > qr) return 0;
    if (l >= ql && r <= qr) return tVal[node];
    int mid = (l+r) >> 1;
    int res = 1;
    if (ql <= mid) res = max(res, query(node<<1, l, mid, ql, qr));
    if (mid < qr) res = max(res, query(node<<1|1, mid+1, r, ql, qr));
    return res;
}
int pushUp(int node) {
    tVal[node] = max(tVal[node<<1], tVal[node<<1|1]);
}
void update(int node, int l, int r, int pos, int val) {
    if (l == r) {
        tVal[node] = val;
        return;
    }
    int mid = (l+r) >> 1;
    if (pos <= mid) update(node<<1, l, mid, pos, val);
    else update(node<<1|1, mid+1, r, pos, val);
    pushUp(node);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "r", stdin);
#endif

    ms(rmost, 0);
    cin >> n;
    for1(i, n) {
        cin >> rev[i].l >> rev[i].d;
    }
    sort(rev+1, rev+1+n, [&](node n1, node n2) {
        return n1.l<n2.l;
    });
    for1(i, n) a[i] = rev[i].l;
    for (int i = n; i >= 1; --i) {
        int idx = lower_bound(a+1+i, a+1+n, a[i]+rev[i].d)-a-1;
        if (idx == i) rmost[i] = i;
        else rmost[i] = query(1, 1, n, i+1, idx);
        update(1, 1, n, i, rmost[i]);
    }
    ms(dp, 0);
    dp[n+1] = 1;
    for (int i = n; i >= 1; --i) {
        dp[i] = (dp[i+1]+dp[rmost[i]+1])%mod;
        //cerr << i << ' ' << dp[i] << ' ' << rmost[i] << endl;
    }
    cout << dp[1] << endl;

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n; string s;
	cin >>n >>s;
	VI lf(n+1), rg(n+1);
	rep(i, n) lf[i+1] = lf[i] + (s[i]=='E');
	repr(i, n-1, 0) rg[i] = rg[i+1] + (s[i]=='W');
	int ans = 1<<30;
	rep(i, n){
		int w = rg[i+1] + lf[i];
//		dbg(i, w, n-1-w);
		ans = min(ans, n-1-w);
	}
	cout <<ans <<"\n";
	return 0;
}


Measured memory_bytes: 2964