akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += 72 - dig >> 3;
	return tmp;
}
const int dm = 1 << 20;
char dn[dm], * di = dn;
inline void putint(int X) {
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}

int to[400004], ne[400004], he[100001];
int kotae[100001], Q[100001];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int N = getint(), M = getint();
	int k = 1;
	rep(i, M) {
		int a = getint(), b = getint();
		to[k] = b;
		ne[k] = he[a];
		he[a] = k++;
		to[k] = a;
		ne[k] = he[b];
		he[b] = k++;
	}

	int q = 0;
	Q[q++] = 1;
	kotae[1] = 1;
	rep(i, N) {
		int u = Q[i];
		for (int v = he[u]; v; v = ne[v]) {
			int To = to[v];
			if (!kotae[To]) {
				kotae[To] = u;
				Q[q++] = To;
			}
		}
	}
	printf("Yes\n");

	for (int i = 2; i <= N; i++) putint(kotae[i]);
	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}

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

int main(){
  int x, y;
  cin >> x >> y;
  for(int c = 0; c <= x; c++){
    int t = x - c;
    int asi = c*2 + t*4;
    if(asi == y){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3628
H, W, D = map(int, input().split())
A = tuple(tuple(map(int, input().split())) for _ in range(H))

pos = [0] * (H * W + 1)

for i in range(H):
    for j in range(W):
        pos[A[i][j]] = (i, j)

def L1(p1, p2):
    return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])

costs = []

for i in range(H * W + 1):
    costs.append(0 if i <= D else costs[i - D] + L1(pos[i - D], pos[i]))

Q = int(input())
for _ in range(Q):
    L, R = map(int, input().split())
    print(costs[R] - costs[L])


Measured memory_bytes: 18060
n, m = map(int,input().split())
s = list(input())

s.reverse()
ng = False
c = 0
ans = []
while ng == False and c < n:
    for i in range(m, 0, -1):
        if c+i < n+1 and s[c+i] == '0':
            c += i
            ans.append(str(i))
            break
        elif i == 1:
            ng = True
if ng:
    print(-1)
else:
    ans.reverse()
    print(' '.join(ans))


Measured memory_bytes: 16988
package main

import (
  "fmt"
  "os"
  "bufio"
  "strconv"
)

func main() {
  sc := bufio.NewScanner(os.Stdin)
  sc.Split(bufio.ScanWords)

  sc.Scan()
  r, _ := strconv.Atoi(sc.Text())

  sc.Scan()
  d, _ := strconv.Atoi(sc.Text())

  sc.Scan()
  x, _ := strconv.Atoi(sc.Text())

  for i := 0; i < 10; i++ {
    x = r * x - d
    fmt.Println(x)
  }
}



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

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

int main(){
	int n;
	cin>>n;
	vector<vector<int> > Adj(n, vector<int>(n, 0));
	REP(i,n){
		int u,k;
		cin>>u>>k;
		REP(j,k){
			int l;
			cin>>l;
			//u==j+1??§??????
			Adj[u-1][l-1]=1;
		}
	}
	REP(i,n){
		REP(j,n-1){
			cout<<Adj[i][j]<<" ";
		}
		cout<<Adj[i][n-1]<<endl;
	}
	return 0;
}

Measured memory_bytes: 3200
H, W, K = map(int, input().split())
arr = []
tot_cnt = 0
for _ in range(H):
    curr = list(input())
    arr.append(curr)
    tot_cnt += curr.count('#')

tot_moves = 0
for h_combo in range(2**H):
    h_combo = list(bin(h_combo)[2:])
    h_combo = ['0'] * (H - len(h_combo)) + h_combo
    
    for w_combo in range(2**W):
        w_combo = list(bin(w_combo)[2:])
        w_combo = ['0'] * (W - len(w_combo)) + w_combo

        curr_cnt = 0
        for i in range(H):
            if h_combo[i] == '1':
                curr_cnt += arr[i].count('#')
        
        for i in range(W):
            if w_combo[i] == '1':
                for j in range(H):
                    if h_combo[j] != '1':
                        curr_cnt += 1 if arr[j][i] == '#' else 0
        
        if tot_cnt - curr_cnt == K:
            tot_moves += 1

print(tot_moves)


Measured memory_bytes: 9040
import sys

input = sys.stdin.readline
P = 10 ** 9 + 7


def solve(L, N):
    dp = [[0, 0] for _ in range(N + 1)]
    dp[0][0] = 1
    for i in range(N):
        n = L[i]
        for j in range(2):
            max_d = 1 if j == 1 else n
            for d in range(max_d + 1):
                next_j = int(j or d < n)
                dp[i + 1][next_j] += (d + 1) * dp[i][j]

        dp[i + 1][0] %= P
        dp[i + 1][1] %= P

    return (dp[N][0] + dp[N][1]) % P


def main():
    L = list(map(int, input().rstrip()))

    N = len(L)
    ans = solve(L, N)

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 24780
from itertools import product
 
n = int(input())
 
tfs = set()
for i in range(3,10):
    tfs |= set(product(['3', '5', '7'], repeat=i))

cnt = 0
for l in tfs:
    if ('3' in l) and ('5' in l) and ('7' in l):
        num = int(''.join(l))
        if num <= n:
            cnt += 1
print(cnt)

Measured memory_bytes: 16452
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const [W, a, b] = input[0].map(Number);

  if ((b >= a && b <= a + W) || (b + W >= a && b + W <= a + W)) {
    return 0;
  }

  return Math.min(
    Math.abs(a - b),
    Math.abs(a - (b + W)),
    Math.abs(a + W - b),
    Math.abs(a + W - (b + W))
  );
};

console.log(main(read()));


Measured memory_bytes: 29600
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		
		System.out.printf("%d %d %.5f",(a/b),(a%b), a/(b*1.0) );
		
		scanner.close();
	}

}

Measured memory_bytes: 26484
#include<iostream>
int main(){
int r;
std::cin >> r;
 
if( r < 1200 ) std::cout << "ABC" << std::endl;
 
else if( r <  2800 ) std::cout << "ARC" <<std::endl;
 
 
else  std::cout << "AGC" << std::endl;
 
 
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
    ll n;
    cin>>n;
    vector<vector<ll> > cnt(n,vector<ll>(n,0) );
    vector<vector<ll> > a(n,vector<ll>(n-1,0));
    for(int i=0;i<n;i++)for(int j=0;j<n-1;j++){
	ll tmp ;
	cin>>tmp;
	tmp--;
	a[i][j] = tmp;
    }
    int tmp;
    queue<ll> q;
    for(ll i=0;i<n;i++)q.push(i);
    ll res = 0;
    ll rest = n*(n-1);
    vector<queue<ll> > qq(n);
    for(int i=0;i<n;i++)for(int j=0;j<n-1;j++)qq[i].push( a[i][j] );
    while( rest > 0 && !q.empty() ){
	res++;
	//cout<<res<<endl;
	queue<ll> tq;
	while( !q.empty() ){
	    ll now = q.front();
	    q.pop();
	    if(qq[now].empty() )continue;
	    ll k = qq[now].front();
	  //  cout<<':'<<now<<' '<<k<<endl;
	    qq[now].pop();
	    cnt[now][k] ++ ;
	    cnt[k][now] ++ ;
	    if(cnt[now][k] == 2){
	//	cout<<' '<<res<<' '<<now<<' '<<k<<endl;
		tq.push(now);
		tq.push(k);
		rest-=2;
	    }
	}
	if(tq.empty()) break;
	q = tq;	
	//cout<<rest<<"Ok"<<endl;
    }
    if( rest != 0){
	cout<<-1<<endl;
    }else{
	cout<<res<<endl;
    }

    return 0;
}


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

using namespace std;

typedef long long ll;

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

	int a[5];
	rep(i, 5) cin >> a[i];

	int k;
	cin >> k;

	for(int i = 0; i < 5; i++){
		for(int j = i+1; j <5; j++){
			if(abs(a[i] - a[j]) > k){
				cout << ":(" << endl;
				return 0;
			}
		}
	}

	cout << "Yay!" << endl;

}


Measured memory_bytes: 256
//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define double long double 
#define fi first
#define se second
#define pii pair<int, int>

signed main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> v;
  for (int i = 0; i < n; i++) {
    int sum = 0;
    for (int j = i; j < n; j++) {
      sum += a[j]; 
      v.push_back(sum);
    }
  }
  sort(v.rbegin(), v.rend());
  int ans = 0;
  for (int b = 61; b >= 0; b--) {
    if ((v[0] & (int)pow(2, b)) == 0) {
      continue;
    }
    if ((v[k - 1] & (int)pow(2, b)) == 0) {
      int nt = (int) pow(2, 62) - 1 - (int) pow(2, b);
      for (int i = 0; i < sz(v); i++) {
        v[i] &= nt;
      }
      sort(v.rbegin(), v.rend());
    } else {
      ans += (int) pow(2, b);
    }
  }
  cout << ans << "\n";
}



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

int main() {
  ll n, k, ans;
  cin >> n >> k;
  vector<ll> a(n);
  rep (i, n) {
    cin >> a[i];
  }
  ll inA = 0;
  for (int i = 0; i < n ;i++) {
    for (int j = i + 1; j < n; j++){
      if (a[i] > a[j]) inA++;
    }
  }
  ans = 0;
  rep (i, k / 100000) {
    ans  += 100000 * inA;
    ans %= 1000000007;
  }
  ans += (k % 100000) * inA;
  ans %= 1000000007;
  ll inK = 0;
  for (int i = 0; i < n ;i++) {
    for (int j = 0; j < n; j++){
      if (a[i] > a[j]) inK++;
    }
  }
  ll loop = k * (k - 1) / 2;
  loop %= 1000000007;
  rep (i, loop / 100000) {
    ans += 100000 * inK;
    ans %= 1000000007;
  }
  ans += inK * (loop % 100000);
  ans %= 1000000007;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
S = input()
key = 'keyence'
ok = False
for i in range(8):
    # print(S[i-8:i])
    if i == 7:
        j = S[:7]
    else:
        j = S[:i] + S[i-7:]
    if key == j:
        ok = True

if ok:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    string s;
    cin >> s;
    int ans = INF;
    string check = "01";
    
    rep(i, 2) {
        int sum = 0;
        rep(i, s.length()) {
            if (s[i] == check[i % 2]) sum++;
        }
        ans = min(ans, sum);
        check = "10";
    }

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

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
ll mod = 1000000007;

int main() {
    ll n;
    cin >> n;
    ll ans = 0;
    repd(i, 1, n + 1) {
        ll num = n / i;
        ans += i * num * (num + 1) / 2;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define f first
#define s second
#define maxsize 1000005
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    float n;
    cin>>n;
    float p = 3.14159265359;
    printf("%.20f",2*p*n);
}


Measured memory_bytes: 3808
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

using namespace std;

int main()
{ int d,t,s;
   cin>>d>>t>>s;
   
   if(s*t>=d)
   cout<<"Yes";
   else 
   cout<<"No";

    return 0;
}


Measured memory_bytes: 3600
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    long M = 1_000_000_007;
    char[] K = scanner.next().toCharArray();
    int D = scanner.nextInt();

    long[][][] dp = new long[K.length + 1][D][2];
    dp[0][0][0] = 1;
    for (int i = 0; i < K.length; i++) {
      for (int j = 0; j < D; j++) {
        for (int k = 0; k < 10; k++) {
          dp[i + 1][(j + k) % D][1] += dp[i][j][1];
          if (dp[i + 1][(j + k) % D][1] > M) dp[i + 1][(j + k) % D][1] -= M;
        }
        int d = K[i] - '0';
        for (int k = 0; k < d; k++) {
          dp[i + 1][(j + k) % D][1] += dp[i][j][0];
          if (dp[i + 1][(j + k) % D][1] > M) dp[i + 1][(j + k) % D][1] -= M;
        }
        dp[i + 1][(j + d) % D][0] += dp[i][j][0];
        if (dp[i + 1][(j + d) % D][0] > M) dp[i + 1][(j + d) % D][0] -= M;
      }
    }
    System.out.println((dp[K.length][0][0] + dp[K.length][0][1] - 1) % M);
  }
}


Measured memory_bytes: 87496
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String S, T;

        S = in.nextLine();
        T = in.nextLine();

        int correct = 0;
        for (int i = 0; i < T.length(); i++) {
            if (S.charAt(i) == T.charAt(i)) correct++;
        }

        System.out.println(correct);
    }
}

Measured memory_bytes: 21588
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)
typedef long long ll;
static const ll MOD = 1e9 + 7;
static const ll INF = (ll)1 << 62;

//////////////////////////////////////////////////////
//Union Find /////////////////////////////////////////
//////////////////////////////////////////////////////
static const ll MAX_M = 100001;
static const ll MAX_N = 100001;
int par[MAX_N];
int rak[MAX_N];

void init(int n) {
	rep(i, 0, n) {
		par[i] = i;
		rak[i] = 0;
	}
}

int find(int x) {
	if (par[x] == x)return x;
	else return par[x] = find(par[x]);
}

void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y)return;

	if (rak[x] < rak[y]) par[x] = y;
	else {
		par[x] = y;
		if (rak[x] == rak[y]) rak[x]++;
	}
}

bool same(int x, int y) {
	return find(x) == find(y);
}

struct edge { int u, v, cost; };
bool comp(const edge& e1, const edge& e2) {
	return e1.cost < e2.cost;
}

int V, E;
edge es[MAX_M];

int krascal() {
	sort(es, es + E, comp);
	init(V);
	int res = 0;

	rep(i, 0, E) {
		edge e = es[i];
		if (!same(e.u, e.v)) {
			unite(e.u, e.v);
			res += e.cost;
		}
	}
	return res;
}

int main() {
	ll n, m; cin >> n >> m;
	V = n, E = m;
	rep(i, 0, m) {
		ll s, t, w; cin >> s >> t >> w;
		edge *e = new edge();
		e->u = s;
		e->v = t;
		e->cost = w;
		es[i] = *e;
	}

	cout << krascal() << endl;

	return 0;
}


Measured memory_bytes: 7484
n = gets.to_i
xs = [0] * n
(n*(n-1)/2).times do
  a, b, c, d = gets.split.map(&:to_i)
  case c <=> d
  when 1
    xs[a-1] += 3
  when 0
    xs[a-1] += 1
    xs[b-1] += 1
  when -1
    xs[b-1] += 3
  end
end

hash = {}
xs.each_with_index do |x, i|
  hash[x] ||= []
  hash[x] << i
end

ys = [0] * n
rank = 1
hash.keys.sort.reverse.each do |x|
  hash[x].each do |i|
    ys[i] = rank
  end
  rank += hash[x].size
end

n.times do |i|
  puts ys[i]
end


Measured memory_bytes: 7104
#include <iostream>
#include <vector>

using namespace std;

int main(){
	int N, max_h = 0, count = 0;
	vector<int> H;

	cin >> N;
	for(int i = 0; i < N; ++i){
		int Hi;
		cin >> Hi;
		H.push_back(Hi);
	}

	max_h = H[0];
	for(int i = 0; i < N; ++i){
		if(max_h <= H[i]){
			count++;
		}

		if(max_h < H[i]) max_h = H[i];
	}

	cout << count << endl;

	return 0;
}


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

typedef pair<int, int> Pii;

void readline(int N, vector<int> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atoi(s.c_str());
    }
    getline(cin, s, '\n');
    a[N - 1] = atoi(s.c_str());
}
void readline(int N, vector<double> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atof(s.c_str());
    }
    getline(cin, s, '\n');
    a[N - 1] = atof(s.c_str());
}

signed main(){

    int X;
    cin >> X;
    vector<int> p(1);
    p[0] = 1;

    FOR(i, 2, 100){
        int tmp = i * i;
        while(tmp <= X){
            p.push_back(tmp);
            tmp *= i;
        }
    }

    sort(p.begin(), p.end());

    cout << p[p.size() - 1];

    return 0;
}

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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    bool ans = false;
    for (int i = 1;i < b;i++){
        if (a*i % b == c){
            ans = true;
        }
    }
    if (ans){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define All(a) a.begin(),a.end()
#define INF 1000000007
const int MOD = 1000000007;
//accumulate(vec.begin(), vec.end(), 0)

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

int main(){
  ll h,w;
  cin >> h >> w;
  if(h==1 || w==1) cout<< 1 <<endl;
  else cout<< (w*h+1)/2 <<endl;
}


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

using namespace std;

#define ll long long
#define mk make_pair

void PLAY()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    cout << fixed << setprecision(10);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

/*ll v[1000000];
ll len[1000000];
ll cnt = 0;
vector<vector<ll>> x;
ll dfs(ll n)
{
    //cout<<n<<" a"<<endl;
    vis[n] = 1;
    for (int i = 0; i < x[n].size(); i++)
    {
        ll lol = x[n][i];
        if (!vis[lol])
        {
            dfs(lol);
            cnt++;
        }
    }
    return cnt;
}
void seth(ll a, ll b)
{
    if (vis[a] == 2)
        return;
    vis[a] = 2;
    len[a] = b;
    for (int i = 0; i < x[a].size(); i++)
    {
        ll lol = x[a][i];
        if (vis[lol] != 2)
        {
            seth(lol, b);
        }
    }
    }*/

bool cmp(pair<ll, ll> &a, pair<ll, ll> &b)
{
    if (a.second != b.second)
    {
        return a.second < b.second;
    }
    return a.first < b.first;
}

const ll N = 1e5;
const ll mod = 1e18 + 9;

ll poww(ll b, ll p)
{
    if (p == 0)
        return 1;
    if (p % 2)
        return (poww(b, p - 1) * b) % mod;
    return (poww((b * b) % mod, p / 2)) % mod;
}

ll fact[N], infact[N];
ll ncr(ll n, ll r)
{
    return (((fact[n] * infact[r]) % mod) * infact[n - r]) % mod;
}

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

    ll n;
    cin>>n;
    ll ans=1;
    n/=2;

    while(n>0)
    {
        n/=2;
        ans++;
    }

    ll sum=0;
    for(int i=1;i<ans;i++)
    {
        sum+=poww(2,i);
    }
    cout<<sum+1<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
    int prime[55555]={0};
    prime[0]=1;prime[1]=1;
    for(int p=2;p<55555;p++)
    {
        if(prime[p]==0)
        {
            for(int q=p*2;q<55555;q+=p)
            {
                prime[q]=1;
            }
        }
    }
    int p5[55555]={0};
    int ck=0;
    for(int r=0;r<55555;r++)
    {
        if(prime[r]==0 && r%5==1)
        {
            p5[ck]=r;
            ck++;
        }
        if(ck>56)break;
    }
    int n;
    scanf("%d",&n);
    for(int s=0;s<n;s++)
    {
        printf("%d ",p5[s]);
    }
}


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

int main(){

  int N, K, X, Y, sum=0;
  cin >> N >> K >> X >> Y;

  for (int i=1; i<=N; i++){

    if (i>K){
      sum += Y;
    }
    else {
      sum += X;
    }
  }

  cout << sum << endl;
}


Measured memory_bytes: 256
n = gets.to_i
a = gets.strip.split.map(&:to_i).sort.reverse

al = 0
bo = 0

a.each_with_index do |v, i|
  if i %2 == 0
    al = al + v
  else
    bo = bo + v
  end
end

if al - bo > 0
  puts al - bo
else
  puts bo - al
end


Measured memory_bytes: 1788
#ifndef LOCAL
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#else
#include <iostream>
#include <iomanip> 
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}
#define fix(a) fixed << setprecision(a)
#define forn(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 all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'


void solve(){
  ll a, b, c;
  cin >> a >> b >> c;
  ll ans = 1e18;
  setmin(ans, a % 2ll * b * c);
  setmin(ans, b % 2ll * a * c);
  setmin(ans, c % 2ll * a * b);
  cout << ans;
}

int main() {
  ios::sync_with_stdio(false);
  // cin.tie(0); cout.tie(0);
  int t = 1;
  // cin >> t;
  forn(i, t){
    solve();
  }
}

/* 

k (k-1) (k-1)

*/

Measured memory_bytes: 3644
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m,k;
    cin>>n>>m>>k;
    vector<ll> a(n),b(m);
    rep(i,n)cin>>a[i];
    rep(i,m)cin>>b[i];
    vector<ll> sum(m+1,0);
    rep(i,m){
        sum[i+1]=sum[i]+b[i];
    }
    //debug(sum);
    ll ans=upper_bound(ALL(sum),k)-sum.begin();
    ans--;
    ll s=0;
    rep(i,n){
        s+=a[i];
        ll kk=k-s;
        if(kk>=0){
            ll temp = upper_bound(ALL(sum), kk) - sum.begin();
            temp--;
            chmax(ans,i+1+temp);
        }
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 7852
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
int N;
int dfs(int K,bitset<8> B,vii A){
  bool flag=1;
  int R=0;
  rep(i,0,A[K].size()){
    if(!B.test(A[K][i])){
      bitset<8> C=B;
      C.set(A[K][i]);
      R+=dfs(A[K][i],C,A);
      flag=0;
    }
  }
  if(flag){
    if(B.count()==N)
      return 1;
    return 0;
  }
  return R;
}
signed main(){
  int M; cin>>N>>M;
  vii A(N);
  rep(i,0,M){
    int X,Y; cin>>X>>Y;
    A[X-1].push_back(Y-1);
    A[Y-1].push_back(X-1);
  }
  bitset<8> B;
  B.set(0);
  cout<<dfs(0,B,A)<<endl;
  }



Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <iostream>
using namespace std;

int h[100005];

int main() {
	int n, k;
	while (cin >> n >> k) {
		for (int i = 0; i < n; ++i) {
			cin >> h[i];
		}
		sort(h, h + n);
		int Min = h[k - 1]  - h[0];
		for (int i = k; i < n; ++i) {
			int diff = h[i] - h[i - k + 1];
			if (diff < Min) {
				Min = diff;
			}
		}
		cout << Min << endl;
	}
	return 0;
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vector<long long> a(N);
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
    }
    long long XOR = 0;
    for (int i = 0; i < N; i += 2) {
        XOR ^= (a[i] ^ a[i + 1]);
    }
    for (int i = 0; i < (N - 1); ++i) {
        cout << (XOR ^ a[i]) << ' ';
    }
    cout << (XOR ^ a[N - 1]) << '\n';
    return 0;
}

Measured memory_bytes: 4780
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,k;
int main(){
	cin>>n>>k;
	ll ans = 0;
	for(int r=k+1;r<=n;r++){
		for(ll d=0;;d++){
		    if(d*r+k > n) break;
		    //d*r+k ~ d*r+r-1
		    ans += min(d*r+r-1,1LL*n)-max(d*r+k,1LL)+1;
		}
	}
	cout<<ans<<endl;
}


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

using namespace std;
using ll = long long;

#define int ll
const ll MOD = 1e9 + 7;

vector<int> G[101010];
ll memo[101010][2];
int visited[101010];

ll dp(int v, int c,int p){
    if(~memo[v][c])return memo[v][c];
    ll sum = 1;
    if(c){
        for(auto adj : G[v])if(adj != p)sum *= dp(adj, 0, v), sum%= MOD;
    }
    else for(auto adj : G[v])if(adj != p)sum *= (dp(adj, 1, v) + dp(adj, 0, v)), sum %= MOD;
    return memo[v][c] = sum;
}

void solve(){
    int N;
    cin >> N;
    for (int j = 0; j < 101010; ++j) {
        for (int i = 0; i < 2; ++i) {
            memo[j][i] = -1;
        }
    }
    for (int i = 0; i < N-1; ++i) {
        int x,y;
        cin >> x >> y;
        G[x].push_back(y);
        G[y].push_back(x);
    }

    G[0].push_back(1);
//    int sum1 = dp(1,0);
//    for (int l = 0; l < 101010; ++l) {
//        visited[l] = 0;
//    }
//    for (int j = 0; j < 101010; ++j) {
//        for (int i = 0; i < 2; ++i) {
//            memo[i][j] = -1;
//        }
//    }
    cout << dp(0,0,0) << endl;



}

#undef int
int main() {

#ifdef debug
    freopen("../in","r",stdin);
    freopen("../out","w",stdout);
#endif

    solve();
    return 0;
}

Measured memory_bytes: 14336
import java.util.*;
public class Main 
{
    public static void main(String[] args) 
    {
        Scanner scan=new Scanner(System.in);
        int array[]=new int[3];
        array[0]=scan.nextInt();
        array[1]=scan.nextInt();
        array[2]=scan.nextInt();
        Arrays.sort(array);
        System.out.println(array[0]+" "+array[1]+" "+array[2]);
    }
}


Measured memory_bytes: 26232
#include<cstdio>
#include<algorithm>

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

using namespace std;

const int INF=1<<29;

inline int popcount(int x){
	x=((x>>1)&0x55555555)+(x&0x55555555);
	x=((x>>2)&0x33333333)+(x&0x33333333);
	x=((x>>4)+x)&0x0f0f0f0f;
	x+=(x>>8);
	x+=(x>>16);
	return x&0x3f;
}

int main(){
	for(int m,n;scanf("%d%d",&m,&n),m;){
		int light[30]={};
		rep(i,m) rep(j,16) {
			int a; scanf("%d",&a);
			light[i]|=a<<j;
		}

		int hand[30]={};
		rep(i,n) rep(j,16) {
			int a; scanf("%d",&a);
			hand[i]|=a<<j;
		}

		static int dp[31][1<<16];
		rep(i,m+1) rep(S,1<<16) dp[i][S]=-INF;
		dp[0][0]=0;
		rep(i,m) rep(S,1<<16) {
			rep(j,n){
				int S2=(S|light[i])&~hand[j];
				dp[i+1][S2]=max(dp[i+1][S2],dp[i][S]+popcount((S|light[i])&hand[j]));
			}
		}

		int ans=0;
		rep(S,1<<16) ans=max(ans,dp[m][S]);
		printf("%d\n",ans);
	}

	return 0;
}

Measured memory_bytes: 8964
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

    int m;
    cin >> m;
    ll sum = 0;
    ll digit = 0;
    for(int i = 0; i < m; ++i){
        int d;
        ll c;
        cin >> d >> c;
        sum += c * d;
        digit += c;
    }
    
    ll ans = digit - 1 + (sum - 1) / 9;
    cout << ans << endl;
}

Measured memory_bytes: 256
// ------------------------------------
// Date:2018/ 2/22
// Problem:ABC 042 IrohaLovesStrings b.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()

int main()
{
  int N,L;
  cin >> N >> L;
  vector<string> S(N);
  REP(i,N) {
    cin >> S[i];
  }
  sort(ALL(S));
  REP(i,N) cout << S[i];
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

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

    public static void solve(){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int l = sc.nextInt();
        int ans = 20000;
        int counter = 0;

        for(int i=1;i<=n;i++){
        	counter += l + i - 1;
        }

        for(int i=1;i<=n;i++){
        	int count = 0;
        	for(int j=1;j<=n;j++){
        		if(i == j){
        			continue;
        		}
        		count += l + j - 1;
        	}
        	
        	if(Math.abs(Math.abs(counter) - Math.abs(ans)) > Math.abs(Math.abs(counter) - Math.abs(count))){
        		ans = count;
        	}
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 22612
a,b,c,k=map(int,input().split())
count=0
count+=a
if k-a>0:
    k-=a
else:
    print(k)
    exit()
if k-b>0:
    k-=b
else:
    print(count)
    exit()
if k-c>0:
    count-=c
else:
    count-=k
    print(count)
    exit()

Measured memory_bytes: 9188
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<iomanip>
#include<queue>
typedef long long LL;

using namespace std;



int main(void) {
	int n;
	cin >> n;
	vector<int>a(n);
	for (int i = 0; i < n; i++)cin >> a[i];
	int color = 0;
	bool c1 = true, c2 = true, c3 = true, c4 = true, c5 = true, c6 = true, c7 = true, c8 = true;
	int wild = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] >= 1 && a[i] < 400 && c1) {
			color++;
			c1 = false;
		}
		if (a[i] >= 400 && a[i] < 800 && c2) {
			color++;
			c2 = false;
		}
		if (a[i] >= 800 && a[i] < 1200 && c3) {
			color++;
			c3 = false;
		}
		if (a[i] >= 1200 && a[i] < 1600 && c4) {
			color++;
			c4 = false;
		}
		if (a[i] >= 1600 && a[i] < 2000 && c5) {
			color++;
			c5 = false;
		}
		if (a[i] >= 2000 && a[i] < 2400 && c6) {
			color++;
			c6 = false;
		}
		if (a[i] >= 2400 && a[i] < 2800 && c7) {
			color++;
			c7 = false;
		}
		if (a[i] >= 2800 && a[i] < 3200 && c8) {
			color++;
			c8 = false;
		}
		if (a[i] >= 3200) {
			wild++;
		}
	}
	if (color == 0) {
		cout << 1 << " " << wild;
	}
	else {
		cout << color << " " << color + wild;
	}
	return 0;
}

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

long int pow(int x){
	return x*x;
}

int main(){
	float ans;
	int N;
	cin >> N;
	
	float dist = 0;
	
	vector < pair<int, int> > pos(N);
	
	for(int i = 0; i < N; i++){
		cin >> pos[i].first >> pos[i].second;
	}
	
	for(int i = 0; i < N - 1; i++){
		for(int j = i + 1; j < N; j++){
			dist += sqrt(pow(pos[i].first - pos[j].first) + pow(pos[i].second - pos[j].second));
		}
	}
	
	ans = dist*2/N;
	
	cout << fixed << setprecision(7) << ans << endl;
	
	return 0;
}
			


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

#define rep(i,x,y) for(long long int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define show(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define show(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<62;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    ll x_size,y_size,z_size,a,b,c,n;
    cin >> x_size >> y_size >> z_size >> a >> b >> c >> n;

    vector<ll> cnt1(n);
    rep(i,0,n) cnt1[i]+=(x_size-a)/n;
    rep(x,a+n*((x_size-a)/n),x_size) ++cnt1[(x-a)%n];
    rep(i,0,n) cnt1[i]+=(a+1)/n;
    for(ll x=a-n*((a+1)/n); x>=0; --x) ++cnt1[(a-x)%n];
    --cnt1[0];

    vector<ll> cnt2(n);
    rep(i,0,n) cnt2[i]-=cnt1[i];
    rep(i,0,n) cnt2[i]+=x_size*((y_size-b)/n);
    {
        vector<ll> tmp1=cnt1;
        ll y1=b+n*((y_size-b)/n),z1=c;
        rep(y,y1,y_size){
            rep(i,0,n) cnt2[i]+=tmp1[i];
            vector<ll> tmp2(n);
            rep(i,0,n) tmp2[i]=tmp1[(i-1+n)%n];
            swap(tmp1,tmp2);
        }
    }
    rep(i,0,n) cnt2[i]+=x_size*((b+1)/n);
    {
        vector<ll> tmp1=cnt1;
        ll y1=b-n*((b+1)/n),z1=c;
        for(ll y=y1; y>=0; --y){
            rep(i,0,n) cnt2[i]+=tmp1[i];
            vector<ll> tmp2(n);
            rep(i,0,n) tmp2[i]=tmp1[(i-1+n)%n];
            swap(tmp1,tmp2);
        }
    }

    vector<ll> cnt3(n);
    rep(i,0,n) cnt3[i]-=cnt2[i];
    rep(i,0,n) cnt3[i]+=x_size*y_size*((z_size-c)/n);
    {
        vector<ll> tmp1=cnt2;
        rep(z,c+n*((z_size-c)/n),z_size){
            rep(i,0,n) cnt3[i]+=tmp1[i];
            vector<ll> tmp2(n);
            rep(i,0,n) tmp2[i]=tmp1[(i-1+n)%n];
            swap(tmp1,tmp2);
        }
    }
    rep(i,0,n) cnt3[i]+=x_size*y_size*((c+1)/n);
    {
        vector<ll> tmp1=cnt2;
        for(ll z=c-n*((c+1)/n); z>=0; --z){
            rep(i,0,n) cnt3[i]+=tmp1[i];
            vector<ll> tmp2(n);
            rep(i,0,n) tmp2[i]=tmp1[(i-1+n)%n];
            swap(tmp1,tmp2);
        }
    }

    rep(i,0,n) cout << cnt3[i] << (i==n-1?"\n":" ");
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}

Measured memory_bytes: 3248
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <cmath>
using namespace std;
const int N=100005;
int n,a,b;
int che[N];

bool mep(long long int x)
{
    long long int sum=0;
    for(int i=0; i<n; ++i)
    {
        long long t=(long long)che[i]-x*b;
        if(t>0)
        {
            sum+=(int)ceil((t*1.0)/(a-b));
            if(sum>x || sum<0)
                return false;
        }
    }
    return true;
}

int main()
{
    int ma=0;
    scanf("%d %d %d",&n,&a,&b);
    for(int i=0; i<n; ++i)
        scanf("%d",&che[i]),ma=max(ma,che[i]);
    long long l=0,r=ma;
    while(l<r)
    {
        long long mid=(l+r)/2;
        if(mep(mid)) r=mid;
        else l=mid+1;
    }
    printf("%d\n",r);
    return 0;
}


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

signed main() {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  
  //1周目
  for( int i = 0; i < tx-sx; i++ ) cout << 'R';
  for( int i = 0; i < ty-sy; i++ ) cout << 'U';
  for( int i = 0; i < tx-sx; i++ ) cout << 'L';
  for( int i = 0; i < ty-sy; i++ ) cout << 'D';
  
  //2周目
  cout << 'D';
  for( int i = 0; i < tx-sx+1; i++ ) cout << 'R';
  for( int i = 0; i < ty-sy+1; i++ ) cout << 'U';
  cout << "LU";
  for( int i = 0; i < tx-sx+1; i++ ) cout << 'L';
  for( int i = 0; i < ty-sy+1; i++ ) cout << 'D';
  cout << 'R';
  
  
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let (a,p) = scan!(usize, usize);
    println!("{}", (a *3 + p)/2);
}


Measured memory_bytes: 4352
x1, y1, x2, y2 = gets.chomp.split.map(&:to_i)
dx = x2 - x1
dy = y2 - y1
x3 = x2 - dy
y3 = y2 + dx
x4 = x3 - dx
y4 = y3 - dy
puts "#{x3} #{y3} #{x4} #{y4}"

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

using namespace std;

typedef long long ll;
typedef long double ld;

const int N=400+5;
int n;
ll v[N];
ll p[N];

ll ask(int l,int r)
{
    return p[r]-p[l-1];
}

ll dp[N][N];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    for(int i=0;i<N;i++)
    {
        for(int j=0;j<N;j++)
        {
            dp[i][j]=(1LL<<60);
        }
    }
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>v[i];
        p[i]=p[i-1]+v[i];
    }
    for(int i=1;i<=n;i++)
    {
        dp[i][i]=0;
    }
    for(int ln=2;ln<=n;ln++)
    {
        for(int l=1;l+ln-1<=n;l++)
        {
            int r=l+ln-1;
            for(int p=l;p<r;p++)
            {
                dp[l][r]=min(dp[l][r],dp[l][p]+dp[p+1][r]);
            }
            dp[l][r]+=ask(l,r);
        }
    }
    cout<<dp[1][n]<<"\n";
    return 0;
}



Measured memory_bytes: 1536
n, A, B, C = map(int, input().split())
l = [int(input()) for _ in range(n)]
inf = 10 ** 18


def dfs(i, a, b, c):
    if i == n:
        if a < 1 or b < 1 or c < 1:
            return inf
        return abs(A - a) + abs(B - b) + abs(C - c)
    res = dfs(i + 1, a, b, c)
    res = min([res, dfs(i + 1, a + l[i], b, c) + (10 if a > 0 else 0)])
    res = min([res, dfs(i + 1, a, b + l[i], c) + (10 if b > 0 else 0)])
    res = min([res, dfs(i + 1, a, b, c + l[i]) + (10 if c > 0 else 0)])
    return res


print(dfs(0, 0, 0, 0))


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(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 repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int k, n;
    cin >> k >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    sort(all(a));
    vi d(n-1);
    rep(i, n-1) d[i] = a[i+1] - a[i];
    int md = (a[0] + k) - a[n-1];
    rep(i, n-1) md = max(md, d[i]);
    cout << k - md << endl;
    return 0;
}


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

int main() {
    int n,m,s=0;
    cin>>n>>m;
    int a[n];
    for(int i=0;i<n;i++)
    cin>>a[i];
    sort(a,a+n);
    for(int i=0;i<m;i++)
    s+=a[i];
    cout<<s;
	return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <cmath>
#include <ctime>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <set>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;

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

    while(N >= 10){
        N = N%10;
    }

    if(N == 2 || N == 4 || N == 5 || N == 7 || N == 9){
        cout << "hon" << endl;
    }
    else if(N == 0 || N == 1 || N == 6 || N == 8){
        cout << "pon" << endl;
    }
    else if(N == 3){
        cout << "bon" << endl;
    }

}

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


#define MAX 100005


int main() {
    vector<int> primes;
    int p[MAX];
    for (int i = 0; i < MAX; i++) p[i] = 1;
    for (long long i = 2; i < MAX; i++)
        if (p[i]) {
            primes.push_back(i);
            for (long long j = i*i; j < MAX; j+=i)
                p[j] = 0;
        }
    p[0] = p[1] = 0;
    int n; cin >> n;
    cout << *lower_bound(primes.begin(), primes.end(), n) << '\n';
}

Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#include <iomanip>
//cout << fixed << setprecision(20) << *** << endl;
#define rep(i,N) for(int i=0;i<(int)N;++i)
typedef long long ll;
using namespace std;
int main()
{
	ll ANS=0;
	string s;
	char ch='#';
	cin>>s;
	for(ll i=0;i<s.size();i++){
		if(s[i]==ch){
			if(i!=s.size()-1){
				i++;
				ANS++;
				ch='#';
			}
		}
		else{
			ANS++;
			ch=s[i];
		}
		//cout<<ANS<<":"<<i<<endl;
	}
	cout<<ANS<<endl;
}

Measured memory_bytes: 832
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
using namespace std;

int main() {
	cin.sync_with_stdio(false); cin.tie(nullptr);
	double l; cin >> l;
	l = l / 3.0;
	cout << fixed << setprecision(15) << l * l*l << endl;
	return 0;
}

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

int S_max=3001;
int64_t MOD=998244353;

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

  //g[L][S]はf[L][R][S]のRを走る和
  vector<vector<int64_t>> g(N+1,vector<int64_t>(S_max,0));
  for(int i=0;i<=N;++i) g[i][0]=1;


  //漸化式
  for(int i=N-1;i>=0;--i){
    for(int j=1;j<=S;++j){
      if(A[i]==j) g[i][j]=(N-i)+g[i+1][j];
      else if(A[i]<j) g[i][j]=g[i+1][j]+g[i+1][j-A[i]];
      else g[i][j]=g[i+1][j];
      g[i][j] %= MOD;
    }
  }

  int64_t ans=0;
  for(int i=0;i<N;++i){
    ans += g[i][S];
    ans %= MOD;
  }

  cout<<ans<<endl;

}


Measured memory_bytes: 72192
from collections import Counter

N = int(input())
S = [input()[:1] for _ in range(N)]
c = Counter(S)

first_name = 'MARCH'
c = [c[i] for i in first_name if c[i]]

ans = 0
if len(c) > 2:
    ans += c[0]*c[1]*c[2]

if len(c) > 3:
    for i in c[3:]:
        for j in range(3):
            tmp = c[:3]
            tmp[j] = i
            ans += tmp[0]*tmp[1]*tmp[2]
if len(c) > 4:
    tmp = c[3:]
    for j in range(3):
        ans += tmp[0]*tmp[1]*c[j]
print(ans)

Measured memory_bytes: 10220