akhauriyash/Code-Regression huggingface dataset:
import math
import string
import collections
from collections import Counter


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())
h = readints()
cnt = 0
ans = 0
for i in range(n-1):
    if h[i] >= h[i+1]:
        cnt += 1
    else:
        ans = max(cnt, ans)
        cnt = 0
print(max(ans, cnt))


Measured memory_bytes: 64112
/* ex6_2 melo */
#include <stdio.h>
#include<string.h> //文字列関数
#define SIZE 101 //文字列の大きさを定義
int main(void){
    char sente[SIZE];//文字列を用意
    int length;//整数の箱を用意
    fgets(sente,SIZE,stdin);//入力を文字列に代入（改行を含む）
    length=(int)strlen(sente);//改行を含む文字列の長さを代入
    if (sente[length-1]=='\n') {//改行を削除
        sente[length-1]='\0';//NULLに変換
    }
    printf("%c%d%c\n",sente[0],(int)strlen(sente)-2,sente[(int)strlen(sente)-1]);//１文字目,文字列の長さ-2,最後の文字を出力
    return 0;//正常終了
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i, n) for (int i = 0; i < n; i++)
int main() {
	ll N;
	std::vector<ll> A;
	int flag = 0;
	A.reserve(1001);
	cin>>N;
	REP(i,N){
		cin>>A[i];
	}
	REP(i,N){
		if(A[i]%2 ==0){
			if(A[i]%3 == 0 || A[i]%5 == 0){
			}
			else{
				cout << "DENIED"<<endl;
				return 0;
			}
		}
	}
	cout << "APPROVED"<<endl;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define yes(n) cout << ((n) ? "yes" : "no") << endl

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

const int INF = 1001001001;
const vector<int> di = {-1,  0, 1, 0};
const vector<int> dj = { 0, -1, 0, 1};

void chmin(int &a, int b) { if (a > b) a = b; }

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll LCM(ll a, ll b) {
    ll g = GCD(a, b);
    return a / g * b;
}


int main() {
    int n; 
    string s;
    cin >> n >> s;

    int res = 1;
    rep(i, n - 1) {
        if (s[i] == s[i+1]) continue;
        res++;
    }
    cout << res << endl;
}

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

int main()
{
	int S, T, D;
	cin >> S >> T >> D;
	ll X = T - S;
	vector<ll> w(D);
	for (int i = 0; i < D; i++) {
		cin >> w[i];
	}
	ll sum = accumulate(w.begin(), w.end(), 0LL);
	ll res = LLONG_MAX;
	ll tmp = 0;
	for (int i = 0; i < D; i++) {
		tmp += w[i];
		if (tmp <= X) {
			res = min(res, i + 1LL);
		}
		else if (sum < 0) {
			res = min(res, (tmp - X + (-sum) - 1) / (-sum) * D + i + 1);
		}
	}
	cout << (res == LLONG_MAX ? -1 : res) << endl;
	return 0;
}



Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define INF 999999999
#define rep(i, n) for(int i = 0;i < n;i++)
#define pb(n) push_back(n)
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl;
#define Vecpr vector<pair<lli,lli>>
int main() {
  lli A,B=0,C=0,D=0,F=INF;
  cin >> A >> B;
  vector<lli>P(A);
  rep(i,A)cin >> P[i];
  Sort(P);
  Rev(P);
  rep(i,B)C+=P[i];
  Out(C);
}

Measured memory_bytes: 256
N=int(input())
A=[input().split() for _ in range(2)]
ans=0

for M in range(N):
    sum=0
    for j in range(M+1):
        sum += int(A[0][j])
    for k in range(M,N):
        sum += int(A[1][k])
    if sum>ans:
        ans=sum

print(ans)


Measured memory_bytes: 2940
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func solve(n, m, k int) {
	for i := 0; i <= n; i++ {
		for j := 0; j <= m; j++ {
			x := (m-j)*i + (n-i)*j
			// out(i, j, x)
			if x == k {
				out("Yes")
				return
			}
		}
	}
	out("No")
}

func main() {
	sc.Split(bufio.ScanWords)
	N, M, K := getInt(), getInt(), getInt()

	solve(N, M, K)
}


Measured memory_bytes: 640
# input
N, M = map(int, input().split())
H = list(map(int, input().split()))
L = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    L[a-1].append(H[b-1])
    L[b-1].append(H[a-1])

# process
ans = 0
for i, l in enumerate(L):
    if [x for x in l if x >= H[i]] == []:
        ans += 1

# output
print(ans)


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

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String num = br.readLine();
		String[] set = num.split(" ");

		int a = Integer.parseInt(set[0]);
		int b = Integer.parseInt(set[1]);
		int c = Integer.parseInt(set[2]);

		int cnt = 0;

		for(int i = a; i<=b; i++) {
			if(c%i == 0) {
				cnt++;
			}
		}
		System.out.println(cnt);
	}

}

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

bool is_h(int num) {
  int i = num;
  int sum = 0;
  while(i > 0){
    sum += i % 10;
    i /= 10;
  }
  
  return num % sum == 0;
}

int main() {
  int a;
  cin >> a;
  cout << (is_h(a) ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 256
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define gcd __gcd
#define lcm(n, m) n * m / gcd(n, m)
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define ea(i, n) for(auto&& i: n)
#define so(n) sort(n.begin(), n.end())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// rtsq ルート, int 2*10^9, __gcd

int main() {
  int N, a = 0;
  ci(N);
  ve<int> V(N), C(N);
  rep(i, N){
    ci(V.at(i));
  }
  rep(i, N){
    ci(C.at(i));
  }
  rep(i, N){
    if(V.at(i) > C.at(i)){
      a += V.at(i) - C.at(i);
    }
  }
  co(a);
}

Measured memory_bytes: 256
from collections import Counter
n = int(input())
V = list(map(int, input().split()))

Odd, Evn = [], []
for i in range(n):
    Evn.append(V[i]) if i%2 == 0 else Odd.append(V[i])
Evn = sorted( dict(Counter(Evn)).items(), key = lambda x:x[1], reverse=True)
Odd = sorted( dict(Counter(Odd)).items(), key = lambda x:x[1], reverse=True)

cnt = -1
for evn in Evn[0:2]:
    for odd in Odd[0:2]:
        if evn[0] != odd[0]:
            cnt = max(cnt, evn[1]+odd[1])
print(n-cnt) if cnt > 0 else print(n//2)

Measured memory_bytes: 71148
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

vector<int> dp(100000, -1);
vector<vector<int>> g(100000);

int dfs(int cur)
{
    if (dp[cur] >= 0)
        return dp[cur];
    if (g[cur].size() == 0)
        return dp[cur] = 0;
    for (const auto &v : g[cur])
    {
        dp[cur] = max(dp[cur], dfs(v) + 1);
    }
    return dp[cur];
}

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

    int N, M;
    cin >> N >> M;
    for (int i = 0; i < M; i++)
    {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        g[x].push_back(y);
    }
    int res = -1;
    for (int i = 0; i < N; i++)
    {
        res = max(res, dfs(i));
    }
    cout << res << endl;
}


Measured memory_bytes: 8192
ans =0
A,B,N = list(map(int,input().split()))
# for x in range(B):
#     ans = max(ans ,int(A* x/ B)-A* int(x/B))

# ans = int()
# search_range = min()
if N >= B:
    x = B-1
else:
    x = N

print(int(A*x/B))



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

int main(void) {
	char c;
	int count[26] = {0}, i;
	while (1) {
		if (scanf("%c", &c) == EOF)
			break;
		if ('a' <= c && c <= 'z')
			count[c-'a']++;
		else if ('A' <= c && c <= 'Z')
			count[c-'A']++;
	}
	for (i = 0; i < 26; i++) {
		cout << (char)(i + 'a') << " : " << count[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 1000000007
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

struct IOSetup{
    IOSetup(){
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(12);
    }
} iosetup;
 
template<typename T1,typename T2>
ostream &operator<<(ostream &os,const pair<T1,T2>&p){
    os<<p.first<<" "<<p.second;
    return os;
}
 
template<typename T>
ostream &operator<<(ostream &os,const vector<T>&v){
    for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==(int)v.size()?"":" ");
    return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is,pair<T1,T2>&p){
    is>>p.first>>p.second;
    return is;
}

template<typename T>
istream &operator>>(istream &is,vector<T>&v){
    for(T &x:v)is>>x;
    return is;
}

using T=tuple<ll,ll,ll>;

signed main(){
    ll n,k;cin>>n>>k;
    if(2*k-n-1>0){
        cout<<-1<<endl;
        return 0;
    }

    vector<T> v;
    for(ll a=k+2*n-1,b=n;a>=n+k;a--){
        v.push_back(T(a+b,a,b));
        if(b==k)b=n+k-1;
        else b--;
    }

    sort(ALL(v));
    vector<T> res;
    ll c=k+2*n;
    rep(i,n){
        auto [_,a,b]=v[i];
        res.push_back(T(a,b,c));
        c++;
    }
    for(auto [x,y,z]:res) cout<<x<<" "<<y<<" "<<z<<endl;
    return 0;
}


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

#define int long long 
#define dou double 
#define endl "\n"

const int MOD=1e9+7;

void solve()
{
	int n,k,x;
	cin >> n;
	int arr[n+1];
	int sum=0;
	vector<int>count(100001,0);
	for(int i=0;i<n;i++)
		cin >> arr[i];
	int xor1=0;
	for(int i=0;i<n;i++)
		xor1=xor1^arr[i];
	for(int i=0;i<n;i++){
		int k= xor1^arr[i];
		cout << k << ' ';
	}
	cout << '\n';

}

main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	solve();
	return 0;
}


Measured memory_bytes: 5576
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int h, w;

    cin >> h >> w;
    char a[h][w];
    for(int i=0; i<h; i++)
      for(int j=0; j<w; j++) cin >> a[i][j];
    for(int i=0; i<w+2; i++) cout << '#';
    cout << endl;
    for(int i=0; i<h; i++){
      cout << '#';
      for(int j=0; j<w; j++){
        cout << a[i][j];
      }
      cout << '#' << endl;
    }
    for(int i=0; i<w+2; i++) cout << '#';
    cout << endl;
}

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

using namespace std;

double dp[21][200001];

int main()
{
	int N;
	int A[21];
	
	A[0] = 1;
	
	scanf("%d", &N);
	
	fill(dp[0], dp[0] + 200001, 200000);
	for (int i = 1; i <= N; i++){
		scanf("%d", A + i);
		fill(dp[i], dp[i] + 200001, 200000);
	}
	
	dp[0][1] = 0;
	
	for (int i = 0; i < N; i++){
		for (int j = 1; j <= 200000; j++){
			for (int k = j; k <= 200000; k += j){
				dp[i + 1][k] = min(dp[i + 1][k], max(dp[i][j], abs(k - A[i + 1]) * 1.0 / A[i + 1]));
			}
		}
	}
	
	printf("%.10lf\n", *min_element(dp[N], dp[N] + 200000));
	
	return (0);
}

Measured memory_bytes: 34028
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cstring>

using namespace std;

int main()
{
    int n;

    cin >> n;

    if (n%2) {
        printf("%.10lf\n", (double)(n/2+1)/n);
    }
    else {
        printf("%.10lf\n", ((double)n/2)/n);
    }
}


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

using namespace std;

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

    int n;
    cin >> n;
    vector<int> a(n);
    for (auto &&x : a)
    {
        cin >> x;
        x--;
    }
    vector<int> b(n);
    for (auto &&x : b)
        cin >> x;
    vector<int> c(n - 1);
    for (auto &&x : c)
        cin >> x;

    int manzoku_id = 0, manzoku_chain = 0;
    for (auto &&x : b)
    {
        manzoku_id += x;
    }
    for (int i = 1; i < n; i++)
    {
        if(a[i]-1 == a[i-1])
        {
            manzoku_chain += c[a[i-1]];
        }
    }

    cout << manzoku_chain + manzoku_id << endl;

}


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

const vector<int> dy({0, 0, 1, -1});
const vector<int> dx({1, -1, 0, 0});

int H, W;
int sy, sx, ey, ex;
vector<string> s;

void input() {
  cin >> H >> W;
  cin >> sy >> sx >> ey >> ex;
  --sy, --sx, --ey, --ex;
  s.resize(H);
  rep(i, H) { cin >> s[i]; }
}

void solve() {

  const int INF = 1e9;

  vector<vector<int>> dist(H, vector<int>(W, INF));
  dist[sy][sx] = 0;

  deque<P> q;
  q.emplace_front(sy, sx);

  while (!q.empty()) {
    int y = q.front().first;
    int x = q.front().second;
    q.pop_front();
    int d = dist[y][x];

    rep(i, 4) {
      int ny = y + dy[i];
      int nx = x + dx[i];
      if (ny < 0 or nx < 0 or ny >= H or nx >= W)
        continue;
      if (s[ny][nx] == '#')
        continue;
      if (dist[ny][nx] <= d)
        continue;
      dist[ny][nx] = d;
      q.emplace_front(ny, nx);
    }

    for (int i = -2; i <= 2; ++i) {
      for (int j = -2; j <= 2; ++j) {
        int ny = y + i;
        int nx = x + j;
        if (ny < 0 or nx < 0 or ny >= H or nx >= W)
          continue;
        if (s[ny][nx] == '#')
          continue;
        if (dist[ny][nx] <= d + 1)
          continue;
        dist[ny][nx] = d + 1;
        q.emplace_back(ny, nx);
      }
    }
  }
  int ans = dist[ey][ex];
  cout << ((ans == INF) ? -1 : ans) << endl;
}

int main() {
  input();
  solve();
  getchar();
  return 0;
}

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

#define INF 1e9
using namespace std;
typedef long long ll;

int main() {

    int n, m; cin >> n >> m;

    int c[55] = {0};

    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        --a; --b;

        c[a]++;
        c[b]++;
    }

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

Measured memory_bytes: 256
# 下記ページを参考に実装してる
# https://qiita.com/ofutonfuton/items/550c984f08e39a189ca6#d%E5%95%8F%E9%A1%8C
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
n, m = map(int, input().split())
p = list(map(int, input().split()))

tree = UnionFind(n)

for i in range(m):
  x, y = map(int, input().split())
  x -= 1
  y -= 1
  tree.union(x, y)
#print(tree)
ans = 0
for i in range(n):
  if tree.same(i, p[i]-1):
    ans += 1
print(ans)

Measured memory_bytes: 84656
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jaynil
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BDigits solver = new BDigits();
        solver.solve(1, in, out);
        out.close();
    }

    static class BDigits {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int t = in.nextInt();
            int k = in.nextInt();
            String x = Integer.toString(t, k);
            out.println(x.length());
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

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

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

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

    }
}



Measured memory_bytes: 22740
#include<stdio.h>
 int main(void)
 {
     char S[3];
     int i,m=0;

     scanf("%s",S);

     for(i=0;i<3;i++){
       if(S[i]=='o') m++;
     }

     printf("%d\n",700+(100*m));

     return 0;
 }



Measured memory_bytes: 128
/*Lucky_Glass*/
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

#define cs const int &
const int N=43,MOD=1e9+7;
inline int Add(cs a,cs b){return a+b>=MOD? a+b-MOD:a+b;}
inline int Sub(cs a,cs b){return a-b<0? a-b+MOD:a-b;}
inline int Mul(cs a,cs b){return 1ll*a*b%MOD;}
inline int Pow(int a,int b){int r=1;while(b){if(b&1)r=Mul(r,a);a=Mul(a,a),b>>=1;}return r;}

int n,x,y,z,li;
int f[N][1<<17];

#define test(S,x) ((S)>>(x)&1)
void Print(int x){for(int i=0;i<li;i++) printf("%d",x>>i&1);}
int main(){
	scanf("%d%d%d%d",&n,&x,&y,&z);
	li=x+y+z;
	f[0][0]=1;
	int all=(1<<li)-1;
	for(int i=1;i<=n;i++)
		for(int S=0;S<(1<<li);S++){
			if(!f[i-1][S]) continue;
			for(int k=1;k<=10;k++){
				int T=(S<<k|(1<<(k-1)))&all;
				if(test(T,x-1) && test(T,x+y-1) && test(T,x+y+z-1)) continue;
				f[i][T]=Add(f[i][T],f[i-1][S]);
			}
		}
	int ans=Pow(10,n);
	for(int S=0;S<(1<<li);S++)
		ans=Sub(ans,f[n][S]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 20376
data=[list(map(int,input().split())) for _ in range(4)]
n=0
while n<4:
    a=data[n][0]
    b=data[n][1]
    if a==1:
        print(6000*b)
        n+=1
    if a==2:
        print(4000*b)
        n+=1
    if a==3:
        print(3000*b)
        n+=1
    if a==4:
        print(2000*b)
        n+=1


Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
void print(const std::vector<int>& v)
{
  std::for_each(v.begin(), v.end(), [](int x) {
    std::cout << x << " ";
  });
  std::cout << std::endl;
}
signed main()
{
int x=0,y=0,z=0,w=0;
std::cin >> x;
std::vector<int> v(x);
rep(i,x){
  v[i]=i+1;
}
std::vector<int> vv(x);
std::vector<int> vvv(x);
rep(i,x){
  std::cin >> vv[i];
}
rep(i,x){
  std::cin >> vvv[i];
}
  do{
    y++;
    if(v==vv){
      z=y;
    }
    if(v==vvv){
      w=y;
    }
  }while(next_permutation(all(v)));

std::cout << abs(z-w) << '\n';
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int f(int a) {
	a = a / 2;
	int c = 0;
	if (a % 2 == 0) c = f(a);
	c = c + 1;
	return c;
}
int main() {
	int a;
	vector<int> vec;
	cin >> a;
	int b=0;
	for (int i = 0; i < a; ++i) {
		int n = 0;
		cin >> n;
		if (n % 2 == 0) {
			vec.push_back(n);
			b += 1;
		}
	}
	int c = 0;
	for (int i = 0; i < b; ++i) {
		c = c + f(vec[i]);
	}
	cout << c << endl;
	return 0;
}

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

using namespace std;

int main(){
    string S;
    cin >> S;
    int n = S.length();
    for (int bits = 0; bits < 1 << (n - 1); bits++){
        int sum = S[0] - '0';
        for (int i = 0; i < n - 1; i++){
            if (bits & (1 << i))
                sum += S[i + 1] - '0';
            else
                sum -= S[i + 1] - '0';
        }
        if (sum == 7){
            cout << S[0];
            for (int i = 0; i < n - 1; i++){
                cout << (bits & (1 << i) ? '+' : '-') << S[i + 1];
            }
            cout << "=7" << endl;
            return 0;
        }
    }
}

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

int n, k;
vector<int> h;

int solve();

int main() {
  cin >> n >> k;
  for(int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    h.push_back(x);
  }
  sort(h.begin(), h.end());
  cout << solve() << endl;
  return 0;
}

int solve() {
  int ans = 2000000000;
  for(int i = 0; i + k - 1 < n; ++i)
    ans = min(ans, h[i + k - 1] - h[i]);
  return ans;
}

Measured memory_bytes: 892
n = gets.to_i
a = gets.chomp.split(" ").map(&:to_i)
sum = a[0].abs
for i in 1..n-1
  sum += (a[i]-a[i-1]).abs
end
sum += a[-1].abs
a.unshift(0).push(0)
for i in 1..n
  puts sum-(a[i]-a[i-1]).abs-(a[i+1]-a[i]).abs+(a[i+1]-a[i-1]).abs
end

Measured memory_bytes: 12548
///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=200005;
vector<int>adj[M];
 main()

{
    fast
    int n,m;
    cin>>n>>m;
    f(i,1,m)
    {
       int u,v;
       cin>>u>>v;
       adj[u].pb(v);
       adj[v].pb(u);
    }
    for(auto x:adj[1])
    {
        if(x!=n)
        {
            for(auto y:adj[x])
            {
                if(y==n)
                {
                    cout<<"POSSIBLE"<<endl;
                    return 0;
                }
            }
        }
    }
    cout<<"IMPOSSIBLE"<<endl;
    return 0;

}





































Measured memory_bytes: 15724
N=int(input())

G=[[] for i in range(N+1)]

for i in range(N-1):
    a,b=map(int,input().split())
    G[a].append(b)
    G[b].append(a)
C=list(map(int,input().split()))
C.sort(reverse=True)
S=sum(C[1:])

num=[0 for i in range(N+1)]
un_used=[True for i in range(N+1)]

q=[]
q.append(1)
un_used[1]=False

while q:
    node = q.pop(0)
    num[node] = C.pop(0)
    
    for i in range(len(G[node])):
        if un_used[G[node][i]]:
            un_used[G[node][i]]=False
            q.append(G[node][i])

print(S)
print(" ".join(map(str,num[1:])))

Measured memory_bytes: 6008
H, W = list(map(int,input().split()))
A = [list(map(int, input().split())) for i in range(10) ]

for k in range(10):
  for j in range(10):
    for i in range(10):
      A[i][j] = min(A[i][j],A[i][k]+A[k][j])

wall = [list(map(int, input().split())) for i in range(H) ]
ans = 0

for h in range(H):
  for w in range(W):
    if wall[h][w] < 0:
      continue
    ans += A[wall[h][w]][1]

print(ans)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;
    cin >> N;
    bool ans = false;
    
    rep(i, 10) {
        rep(ii, 10) {
            if ((i * ii) == N) {
                ans = true;
            }
        }
    }
    
    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,a,x,y;
    cin>>n;
    std::multimap<int, pair<int,int>> map;
    for (int i=0;i<n;i++) {
        cin>>a;
        for (int j=0;j<a;j++) {
            cin>>x>>y;
            map.emplace(i+1,make_pair(x,y));
        }
    }
    int count=0,ans=0;
    for (int bit=0;bit<(1<<n);bit++) {
        count=0;
        std::deque<int> honest(n+1,0);
        int flag=0;
        for (int i=0;i<n;i++) {
            if (bit&(1<<i)) {
                honest[i+1]=1;
            }
        }
        for (int k=0;k<=n+1;k++) {
            if (honest[k]==1) {
                auto p=map.equal_range(k);
                for (auto itr=p.first;itr!=p.second;itr++) {
                    int X=itr->second.first;
                    int Y=itr->second.second;
                    if (Y==1) {
                        if (honest[X]!=1) {
                            flag=1;
                            break;
                        }
                    } else if (Y==0) {
                        if (honest[X]==1) {
                            flag=1;
                            break;
                        }
                    }
                }
                if (flag==1) {
                    break;
                }
            }
        }
        if (flag==0) {
            for (int l=0;l<=n+1;l++) {
                if (honest[l]==1) {
                    count++;
                }
            }
            ans=max(ans,count);
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  string s[8];
  r(i,8)cin>>s[i];
  cout<<90<<endl;
  r(i,8){r(j,8)cout<<s[7-j][i];cout<<endl;}
  cout<<180<<endl;
  r(i,8){r(j,8)cout<<s[7-i][7-j];cout<<endl;}
  cout<<270<<endl;
  r(i,8){r(j,8)cout<<s[j][7-i];cout<<endl;}
}

Measured memory_bytes: 3192
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    map<int, int> cnt;
    int a;
    rep(i,n){
        cin >> a;
        cnt[a+1]++;
        cnt[a]++;
        cnt[a-1]++;
    }
    int ans = 0;
    for(auto p : cnt){
        chmax(ans, p.second);
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4736
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <set>
using namespace std;

int N, cnt;

int main() {
	cin >> N;

	for (int i = 1; i <= N; i += 2) {
		int tmp = 0;
	
		for (int j = 1; j * j <= i; ++j) {
			if (i%j == 0) {
				tmp += 2;
			}
			if (j * j == N) tmp--;
		}
		if (tmp == 8) {
			cnt++;
		}
	}
	cout << cnt;
}

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

int BubbleSort(int A[],int N){
	bool flag=1;
	int i;
	int j;
	int sw=0;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = N - 1; j >= i+1; j--) {
			if (A[j - 1] > A[j]) {
				swap(A[j - 1], A[j]);
				flag = 1;
				sw++;
			}
		}
	}
	return sw;
}

int main() {
	int N;
	int A[100];
	int sw;
	cin >> N;
	for (int i = 0; i < N; i++) { cin >> A[i]; }
	
	sw = BubbleSort(A, N);

	for (int i = 0; i < N; i++) {
		if (i) { cout << " "; }
		cout << A[i];
	}
		cout << endl;
		cout << sw << endl;
	}

Measured memory_bytes: 3092
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " " 
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(lli i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    cout << std::fixed << std::setprecision(10);
    lli a, b,c;
    cin>>a>>b>>c;
    Yes(a==b&&b==c);

}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORe(i, k, n) for(int i = (k); i <= (n); i++)
#define FORr(i, k, n) for(int i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(int i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;

const int INF = 1001001001;

vector<ll> bg(51), p(51);

ll f(ll n, ll x){
  if(n == 0) return p[0];
  if(x == 1) return 0;
  if(1 < x && x <= bg[n-1]+1) return f(n-1, x-1);
  if(x == bg[n-1]+2) return p[n-1]+1;
  if(bg[n-1]+2 < x && x <= 2*bg[n-1]+2) return p[n-1]+1 + f(n-1, x-bg[n-1]-2);
  if(x == bg[n]) return p[n];
}

int main(void){
  ll n, x;
  cin >> n >> x;

  bg[0] = 1;
  p[0] = 1;
  REP(i, n){
    bg[i+1] = 2*bg[i]+3;
    p[i+1] = 2*p[i]+1;
  }
  cout << f(n, x) << endl;
  return 0;
}

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

int main(void){
    int n;
    cin>>n;
    int a[n], b[n];
    for(int i=0; i<n; i++){
        cin>>a[i];
        b[i]=a[i];
    }
    sort(b,b+n);
    bool Wmax=false;
    if(b[n-1]==b[n-2]){
        Wmax=true;
    }
    
    if(Wmax==true){
        for(int i=0; i<n; i++){
            cout<<b[n-1]<<endl;
        }
    }else{
        for(int i=0; i<n; i++){
            if(a[i]==b[n-1]){
                cout<<b[n-2]<<endl;
            }else{
                cout<<b[n-1]<<endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 5168
n, times = map(int, input().split())
a = list(map(int, input().split()))

for i in range(n):
    a[i] -= 1
    
log_size = times.bit_length() + 2
double = [[-1] * n for i in range(log_size)]

# ダブリングで2^0回(= 1回)たどって到達する値を求める
for i in range(n):
    double[0][i] = a[i]

# ダブリングで2^k回たどって到達する値を求める
for k in range(1, log_size):
    for i in range(n):
        double[k][i] = double[k - 1][double[k - 1][i]]

ans = 0
for i in range(70)[::-1]:
    if times & (1 << i):
        ans = double[i][ans]
print(ans + 1)


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

int main() {
  int n,m; cin >> n >> m;
  vector<int> H(n);
  vector<int> G(n,1);
  rep(i,n) cin >> H[i];
  vector<vector<int>> M(n, vector<int>());
  rep(i,m) {
    int a,b; cin >> a >> b;
    a--; b--;
    M[a].push_back(b);
    M[b].push_back(a);
  }

  rep(j,n) {
    for (auto k : M[j]) {
      if (H[k] >= H[j]) {
        G[j] = 0;
        break;
      }
    }
  }
  int ans = 0;
  rep(i,n) ans += G[i];
  cout << ans << endl;
}

Measured memory_bytes: 9016
#include<stdio.h>

int main(){
    int N,L,i,abs_min;
    int result=0;
    int sign=-1;
    scanf("%d %d",&N,&L);
    for(i=0;i<N;i++){
        if(i==0){
            abs_min=abs(L+i);
            if(L+i<0){
                sign=1;
            }else{
                sign=-1;
            }
        }else if(abs(L+i)<abs_min){
            abs_min=abs(L+i);
            if(L+i<0){
                sign=1;
            }else{
                sign=-1;
            }
        }
        result+=L+i;
    }
    printf("%d\n",result+sign*abs_min);
    return 0;
}

Measured memory_bytes: 128
N, M = gets.chomp.split.map(&:to_i)
A = Array.new(N, 0)  # 0 means no trap, 1 means existence of trap
M.times do
  i = gets.chomp.to_i
  i -= 1  # 0-indexed
  A[i] = 1
end

MOD = 1000000007

# p N, M
# p a

def solve
  dp = Array.new(N, 0)  # 0 initialized
  dp[0] = 1 if A[0] == 0
  dp[1] = 1 + dp[0] if A[1] == 0
  if (N <= 2) 
    p dp[N-1]
    return
  end

  0.upto(N-3).each do |i|
    if A[i+2] == 0
      dp[i+2] = dp[i+1] + dp[i]
      dp[i+2] %= MOD
    end
  end
  
  p dp[N-1]
end

solve

Measured memory_bytes: 3708
N = int(input())
T = list(map(int, input().split()))
M = int(input())
P = []
X = []
for _ in range(M):
    p, x = map(int, input().split())
    P.append(p)
    X.append(x)

for i in range(0,M):
    T_tmp = T[:]
    T_tmp[P[i]-1] = X[i]
    print(sum(T_tmp))


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

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

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

ll solve(const vector<ll>& x, const vector<ll>& v, ll C) {
  int N = x.size();
  vector<ll> cumv(N + 1, 0), gain(N);
  REP(i, N) cumv[i + 1] = cumv[i] + v[i];
  gain[0] = cumv[1] - x[0];
  for(int i = 1; i < N; ++i) {
    gain[i] = cumv[i + 1] - x[i];
  }
  vector<int> opt(N, 0);
  for(int i = 1; i < N; ++i) {
    opt[i] = (gain[i] > gain[opt[i - 1]]) ? i : opt[i - 1];
  }

  ll ret = max(0LL, gain[opt[N - 1]]);
  for(int i = 1; i < N; ++i) {
    ll tmp = cumv[N] - cumv[i] - 2 * (C - x[i]) + gain[opt[i - 1]];
    ret = max(ret, tmp);
  }
  return ret;
}

int main(){
  ll N, C;
  cin >> N >> C;
  vector<ll> x(N), v(N);
  REP(i,N) cin >> x[i] >> v[i];

  ll ret = solve(x, v, C);
  reverse(ALL(x));
  REP(i, N) x[i] = C - x[i];
  reverse(ALL(v));
  ret = max(ret, solve(x, v, C));
  cout << ret << endl;
  return 0;
}



Measured memory_bytes: 3800
# ABC 082
def db(x): 
    global debug
    if debug: print(x)
debug = False
s = input()
sl = [c for c in s]
t = input()
tl = [c for c in t]
sl.sort()
tl.sort()
tl.reverse()
db((sl,tl))
for i in range(min(len(s),len(t))):
    if sl[i]<tl[i]:
        print('Yes')
        break
    elif  sl[i]>tl[i]:
        print('No')
        break
else:
    if len(s)<len(t):
        print('Yes')
    else: print('No')


Measured memory_bytes: 3064
from math import gcd
from functools import reduce
from itertools import product

def resolve():
  K, M = map(int, input().split(" "))
  A = [int(x) for x in input().split(" ")]
  print(K-sum(A) if K-sum(A) >= 0 else -1)

if __name__ == "__main__":
    resolve()

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

int a0 = 0, a1 = 0, a2 = 0, a = 0;

int main(){
    for(int i = 0; i < 10; i++){
        cin >> a;
        if(a0 <= a){
            a2 = a1;
            a1 = a0;
            a0 = a;
        }else if(a1 <= a){
            a2 = a1;
            a1 = a;
        }else if(a2 <= a){
            a2 = a;
        }
    }
    cout << a0 << endl << a1 << endl << a2 << endl;
    return 0;
}

Measured memory_bytes: 1160
s = int(input())

def func(n):
    if n%2==0:
        return n/2
    else:
        return 3*n+1
    
A = [s]
m = 1
while 1:
    m+=1
    if func(A[-1]) in A:
        print(m)
        break
    else:
        A.append(func(A[-1]))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main(){
  int N ;
  cin >> N;
  vector<pair<int,int>> p(N);
  for(int i = 0; i<N; i++){
    int a;
    cin >> a;
    p.at(i) = make_pair(a,i+1);
  }
  sort(p.begin(),p.end());
  for(int i = 0; i< N-1 ; i++){
    cout << p.at(i).second << " ";
  }
  cout << p.at(N-1).second << endl;
  
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define mt make_tuple
#define mp make_pair
#define pu push_back
#define INF 1000000001
#define MOD 1000000007
#define EPS 1e-6
#define ll long long int
#define ld long double
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define pr(v) { for(int i=0;i<v.size();i++) { v[i]==INF? cout<<"INF " : cout<<v[i]<<" "; } cout<<endl;}
#define t1(x)                cerr<<#x<<" : "<<x<<endl
#define t2(x, y)             cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl
#define t3(x, y, z)          cerr<<#x<<" : " <<x<<" "<<#y<<" : "<<y<<" "<<#z<<" : "<<z<<endl
#define t4(a,b,c,d)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<endl
#define t5(a,b,c,d,e)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<" "<<#e<<" : "<<e<<endl
#define t6(a,b,c,d,e,f)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<" "<<#e<<" : "<<e<<" "<<#f<<" : "<<f<<endl
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define t(...) GET_MACRO(__VA_ARGS__,t6,t5, t4, t3, t2, t1)(__VA_ARGS__)
#define _ cerr<<"here"<<endl;
#define __ {ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}

using namespace std;
template<class A, class B> ostream& operator<<(ostream& out, const pair<A, B> &a){ return out<<"("<<a.first<<", "<<a.second<<")";}
template <int> ostream& operator<<(ostream& os, const vector<int>& v) { os << "["; for (int i = 0; i < v.size(); ++i) { if(v[i]!=INF) os << v[i]; else os << "INF";if (i != v.size() - 1) os << ", "; } os << "]\n"; return os; } 
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { os << "["; for (int i = 0; i < v.size(); ++i) { os << v[i]; ;if (i != v.size() - 1) os << ", "; } os << "]\n"; return os; } 


int main()
{
  __;
  ll a,b;
  cin >> a >> b;
  if(a == 1 || b == 1) cout << 1 << endl;
  else cout << (a*b+1)/2 << endl;
  return 0;
}


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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 61)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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; }

i64 ceil(i64 a, i64 b) { return (a+b-1)/b; }
mt19937 rnd(time(NULL));

int d, c[30], s[404][30];
int ans[400];
clock_t start;

int score(int a[400], int l, int r){
	int cnt = 0;
	int last[26] = {};
	fill(last,last+26,l-1);
	
	for(int i = l; i < r; i++){
		cnt += s[i][a[i]];
		last[a[i]] = i;
		for(int j = 0; j < 26; j++){
			cnt -= c[j]*(i-last[j]);
		}
	}
	return cnt;
}

void solve(){
	start = clock();
	
	cin >> d;
	for(int i = 0; i < 26; i++) cin >> c[i];
	for(int i = 0; i < d; i++){
		for(int j = 0; j < 26; j++) cin >> s[i][j];
	}
	
	int ma = 0;
	for(int i = 0; i < d; i++){
		// int v = i%26;
		// ans[i] = v;
		ans[i] = rnd()%26;
	}
	ma = score(ans,0,d);
	
	int cc[30] = {};
	for(int i = 0; i < 26; i++){
		cc[i+1] = c[i] + cc[i];
	}
	
	int value[30] = {};
	int lp = 0;
	while(clock()-start < 1.9*CLOCKS_PER_SEC){
		int res[400] = {};
		int last[26] = {};
		fill(last,last+26,-1);
		for(int i = 0; i < d; i++){
			res[i] = ans[i];
			int r = rnd()%200;
			if(r == 0){
				for(int j = 0; j < 26; j++){
					value[j+1] = value[j];
					value[j+1] += (c[i]*(i-last[j])*(i-last[j]-1)/2) * 0.1;
					value[j+1] += s[i][j];
				}
				r = rnd()%value[26];
				r = lower_bound(value,value+26, r)-value-1;
				res[i] = r;
			}
			last[res[i]] = i;
		}
		
		if(chmax(ma,score(res,0,d))){
			for(int i = 0; i < d; i++){
				ans[i] = res[i];
			}
		}
		//cout << score(res,0,d) << endl;
		lp++;
	}
	//cout << lp << endl;
	//cout << ma << endl;
	
	for(int i = 0; i < d; i++){
		cout << ans[i]+1 << endl;
	}
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 3724
#
# File    : A.rb
# Author  : Kazune Takahashi
# Created : 2018-7-21 20:51:33
# Powered by Visual Studio Code
#

a = gets.chomp.split(" ").map{|i| i.to_i}.sort

puts (a[1] - a[0]).abs + (a[2] - a[1]).abs




Measured memory_bytes: 1788
#include <stdio.h>
#include <algorithm>
typedef long long ll;
using namespace std;

int main(void) {
  ll i, j, k, n, ans = 0, now = 0;
  scanf("%lld", &n);
  ll a[n];
  for(i = 0; i < n; ++i) scanf("%lld", &a[i]);
  sort(a, a + n);
  if(n & 1) {
    for(i = 0; i < n / 2 - 1; ++i) ans -= a[i] * 2;
    for(; i < n / 2 + 1; ++i) ans -= a[i];
    for(; i < n; ++i) ans += 2 * a[i];
    for(i = 0; i < n / 2; ++i) now -= a[i] * 2;
    for(; i < n / 2 + 2; ++i) now += a[i];
    for(; i < n; ++i) now += 2 * a[i];
  } else {
    for(i = 0; i < n / 2 - 1; ++i) ans -= a[i] * 2;
    for(; i < n / 2; ++i) ans -= a[i];
    for(; i < n / 2 + 1; ++i) ans += a[i];
    for(; i < n; ++i) ans += 2 * a[i];
  }
  printf("%lld", ans > now ? ans : now);
  return 0;
}

Measured memory_bytes: 896
while True:
    m, f, r = map(int, input().split())
    if m == -1 and f == -1 and r == -1:
        break
    elif m == -1 or f == -1:
        grade = "F"
    elif (m + f) >= 80:
        grade = "A"
    elif (m + f) >= 65:
        grade = "B"
    elif (m + f) >= 50:
        grade = "C"
    elif (m + f) >= 30:
        if r >= 50:
            grade = "C"
        else:
            grade = "D"
    else:
        grade = "F"
    print(grade)


Measured memory_bytes: 5596
N = gets.to_i

def f(n)
  res = 0
  while n > 0
    res += n % 10
    n /= 10
  end
  res
end

ans = 1.0/0
(1...N).each{|i|
  a = f(i)
  b = f(N-i)
  ans = a + b if a + b < ans
}
p ans


Measured memory_bytes: 1788
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    public static bool f = false, t = true;
    static void Main(string[] args)
    {
        string a = Console.ReadLine();
        int ans = 0;
        for(int i = 0; i < a.Length; i++)
        {
            ans += a[i] == '1' ? 1 : 0;
        }Console.WriteLine(ans);
    }

    public static long gcd(long a, long b)
    {
        while (true)
        {
            if (a == 0) { return b; }
            if (b == 0) { return a; }
            if (a > b) { a -= b; }
            else { b -= a; }
        }
    }
    public static long lcm(long a, long b)
    {
        return a / gcd(a, b) * b;
    }
    public static bool IsPrime(long n)
    {
        if (n < 2) return false;
        if (n == 2) return true;

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

}
public static class Read
{
    public static void outl(string n = "") { Console.WriteLine(n); return; }
    public static long Long()
    {
        return long.Parse(Console.ReadLine());
    }
    public static long[] longs()
    {
        return Console.ReadLine().Split().Select(long.Parse).ToArray();
    }
    public static int Int()
    {
        return int.Parse(Console.ReadLine());
    }
    public static int[] ints()
    {
        return Console.ReadLine().Split().Select(int.Parse).ToArray();
    }
    public static string Str() { return Console.ReadLine(); }
    public static string[] Strs() { return Console.ReadLine().Split(); }
}

Measured memory_bytes: 13140
N,K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

li = {}
for i in A:
    if(not i in li):
        li[i]=1
    else:
        li[i]+=1

if(len(li)-K<0):
    print(0)
else:
    ans = 0
    for i in sorted(li.items(),key = lambda x: x[1])[:len(li)-K]:
        ans += i[1]
    print(ans)



Measured memory_bytes: 39044
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>

//#include<bits/stdc++.h>

using namespace std;


int main() {
	int x=0;
	string h;
	cin >> h;
	int a = 0, b = h.size();
	for (int i = 0; i < h.size(); i++) {
		if (h[i] == 'A'&&b > i)b = i;
		if (h[i] == 'Z'&&a < i)a = i;

	}
	cout << a - b + 1 << endl;
	return 0;
	
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n, k;std::cin >> n >> k;
  ll ans = 1;
  re(i, n) ans = min(ans*2, ans+k);
  std::cout << ans << '\n';
}


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


int main()
{
	int a,b,count=0,num=1;
	cin>>a>>b;
	if(b==1)
		cout<<'0';
	else
	{
		while(num<b)
		{
			num+=a-1;
			count++;
		}
		cout<<count;
	}
}

Measured memory_bytes: 256