akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <cctype>
#include <bits/stdc++.h>
#include <queue>

using namespace std;
// for loop
#define F(i, L, R) for(long i = L; i < R; i++)
#define FE(i, L, R) for(long i = L; i <= R; i++)
// for (reversed)
#define FR(i, L, R) for(long i = L; i > R; i--)
#define FRE(i, L, R) for(long i = L; i >= R; i--)

// data types
#define Int long
#define ul unsigned long
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned shoft

// vectors
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> ii;
#define ALL(c) (c).begin(),(c).end()
#define last(vec) vec.size()-1
#define lastEle(vec) vec[last(vec)]
#define pb push_back
#define InputV(a, n) F(i,0,n){long l; cin >> l; a.pb(l);}

// debug
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;
#define printA(a, L, R) FE(i, L, R) cout << a[i] << (i==R?'\n':' ')
#define printAF(a, L) printA(a, 0, L-1)
#define printV(a) printA(a, 0, a.size()-1)

// utils
#define char2int(c) (c-'0')
#define bit(x, i) (x&(1<<i))
#define space ' '
#define PI 3.14159265358979323


#define TST 0

int main() {
#if TST==1
    ifstream in ("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    int n,k;
    cin >> n >> k;
    vi p(n);
    for(int i = 0;i < n;i++){
        cin >> p[i];
    }
    sort(p.begin(), p.end());
    long sum = 0;
    for(int i =0;i < k;i++){
        sum += p[i];
    }
    cout << sum << endl;

#if TST==1

#endif
}



Measured memory_bytes: 3552
#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];
  }
}

template <typename T>
T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}

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

  ll a, b;
  cin >> a >> b;
  auto g = gcd(a, b);
  cout << a * b / g << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a, b, n;
	int i;
	int total;


	while (scanf("%d %d", &a, &b) != EOF){
		n = a + b;
		total = 1;
		while (1){

			if (n < 10)break;

			else {
				n = n / 10;
				total++;
			}
		}
		printf("%d\n", total);

	}



	return (0);
}

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

int main() {
    /* 入力受け取り */
    int n, Q;
    cin >> n >> Q;
    vector<long long> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];

    /* Q 回分のクエリを処理 */
    for (int j = 0; j < Q; ++j) {
        long long x; cin >> x; // 各クエリ x

        /* 合計値 */
        long long res = 0;

        /* 区間の左端 left で場合分け */
        int right = 0;     // 毎回 right を使い回すようにする
        long long sum = 0; // sum も使い回す
        for (int left = 0; left < n; ++left) {
            /* sum に a[right] を加えても大丈夫なら right を動かす */
            while (right < n && sum + a[right] <= x) {
                sum += a[right];
                ++right;
            }

            /* break した状態で right は条件を満たす最大 */
            res += (right - left);

            /* left をインクリメントする準備 */
            if (right == left) ++right; // right が left に重なったら right も動かす
            else sum -= a[left]; // left のみがインクリメントされるので sum から a[left] を引く
        }

        cout << res << endl;
    }
}


Measured memory_bytes: 3620
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict
N,P=map(int, sys.stdin.readline().split())
S=sys.stdin.readline().strip()

if P in (2,5):
    ans=0
    for i,x in enumerate(S):
        if int(x)%P==0:
            ans+=i+1
    print ans
else:
    S=S[::-1]   #文字列Sの右側から累積和を取りたいので、左から数えられるように文字列を反転させる
    L=[0]
    for i,x in enumerate(S):
        x=int(x)
        L.append( (L[-1]+x*pow(10,i,P))%P ) #元の文字列Sの右側から累積和を取った配列を作成
    ans=0
    D=defaultdict(lambda: 0)
    for i in range(N,-1,-1):
        x=L[i]
        ans+=D[x]
        D[x]+=1
    print ans


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

int main(){
 string S,T; cin>>S>>T;
 int ans = 1000000;
 rep(i,S.size()-T.size()+1){
  string s = S.substr(i,T.size());
  int tmp = 0;
  rep(j,T.size()) if(s[j]!=T[j]) tmp++;
  ans = min(ans,tmp);
 }
 cout<<ans<<endl;
 return 0;
}

Measured memory_bytes: 3596
#include <stdio.h>

int main(void){
	int y, m, d;
	
	while(scanf(" %d %d %d", &y, &m ,&d) != EOF){
		char *ans;
		int year;
		int flag=0;
		
	
		if(y<1868 || (y==1868 && m<9) || (y==1868 && m==9 && d<=7) ) { 
			ans = "pre-meiji";
			flag=1;
		}
		else if(y<1912 || (y==1912 && m<7) || (y==1912 && m==7 && d<=29) ) {
			ans = "meiji";
			year = y - 1868 + 1;
		}
		else if(y<1926 || (y==1926 && m<12) || (y==1926 && m==12 && d<=24) ) {
			ans = "taisho";
			year = y - 1912 + 1;
		}
		else if(y<1989 || (y==1989 && m<1) || (y==1989 && m==1 && d<=7) ) {
			ans = "showa";
			year = y - 1926 + 1;
		}
		else {
			ans = "heisei";
			year = y - 1989 + 1;
		}
	
		if(flag==1) printf("%s\n", ans);
		else printf("%s %d %d %d\n", ans, year, m, d);
	}


	return 0;
}

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

using namespace std;
using ll = long long;
constexpr int mod = 1e9+7;
constexpr int md = mod;
int main(){
    int n,m;
    cin>>n>>m;
    vector<vector<int>> g(n+m);
    vector<ll> in(n+1);
    for(int i=0;i<n+m-1;++i){
        ll from,to;
        cin>>from>>to;
        g[from].push_back(to);
        in[to]++;
    }
    int root;
    for(int i=1;i<=n;++i){
        if(in[i] == 0){
            root = i;
        }
    }
    vector<int> par(n+1);
    par[root] = 0;
    queue<int> q;
    q.push(root);
    while(!q.empty()){
        auto u = q.front();q.pop();
        for(auto v : g[u]){
            in[v]--;
            if(in[v] == 0){
                par[v] = u;
                q.push(v);
            }
        }
    }
    for(int i=1;i<=n;++i){
        cout << par[i] << endl;
    }
    return 0;
}



Measured memory_bytes: 7424
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#include <numeric>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[8]={ 0, 1, 0,-1, 1, 1,-1,-1}; // x軸方向への変位
ll dy[8]={ 1, 0,-1, 0, 1,-1, 1,-1}; // y軸方向への変位

int main(void){
    ll n, m;
    cin >> n >> m;
    ll check;
    ll MAX = 0;
    for(ll i = 0; i < n; i++){
        ll a;
        cin >> a;
        if(i==0) check = a;
        else check = __gcd(check, a);
        MAX = max(MAX, a);
    }
    if(check==m)
        cout << "POSSIBLE" << endl;
    else if(check==1 && MAX >= m)
        cout << "POSSIBLE" << endl;
    else {
        if(m%check==0 && m <= MAX)
            cout << "POSSIBLE" << endl;
        else
            cout << "IMPOSSIBLE" << endl;
    }
    return 0;
}


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

using namespace std;
struct UnionFind {
	vector<int> par;

	UnionFind(int N) : par(N) {
		for(int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) {
		if(par[x] == x) return x;
			//ここで併合処理も行なっている
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) {
		int rx = root(x);
		int ry = root(y);
		if(rx == ry) return;
		par[rx] = ry;
	}

	bool same(int x, int y) {
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}

};


int main() {
	int N;
	cin >> N;
	int M;
	cin >> M;
	UnionFind b(M);
	vector<bool> L(M, false);
	for(int i = 0; i < N; i++) {
		int ki;
		cin >> ki;
		int pre_l = -1;
		for(int j = 0; j < ki; j++) {
			int l;
			cin >> l;
			l--;
			L[l] = true;
			if(pre_l == -1) {
				pre_l = l;
				continue;
			}
			b.unite(pre_l, l);
		}
	}
	int f = -1;
	for(int i = 0; i < M; i++) {
		if(L[i] == false) continue;
		if(f == -1){
			f = i;
			continue;
		}
		if(b.same(f, i) == false) {
			cout << "NO" << endl;
			return 0;
		}
	}
		cout << "YES" << endl;
}


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

int main(){
    ll k;
    int n;
    cin >> n >> k;
    vector<int>a(n);
    rep(i,n){
        cin >> a.at(i);
    }

    vector<int> s;
    vector<int> ord(n+1,-1);
    int c = 1,l= 0;
    {
        int v = 1;
        while(ord[v] == -1){
            ord[v] = s.size();
            s.push_back(v);
            v = a[v-1];
        }
        c = s.size() - ord[v];
        l = ord[v];
        //c:周期,l:周期の前の数
    }

    if(k < l)cout << s[k] << endl;
    else{
        k -= l;
        k %= c;
        cout << s[l+k] << endl;
    }
    return 0;
}

Measured memory_bytes: 5888
a,b,c,d=map(int,input().split())
mod=998244353
dp=[(d+2)*[0]for _ in range(c+2)]
dp[a][b]=1
for i in range(a,c+1):
    for j in range(b,d+1):
        dp[i][j]%=mod
        dp[i+1][j]+=dp[i][j]*j
        dp[i][j+1]+=dp[i][j]*i
        dp[i+1][j+1]-=dp[i][j]*i*j
print(dp[c][d])


Measured memory_bytes: 136860
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n);
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

int main()
{
    int a, b, k;
    cin>>a>>b>>k;
    RFOR(i,min(a,b)+1,1) {
        if (a % i == 0 && b % i == 0) {
            k--;
            if (!k) {
                cout<<i<<endl;
                break;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin >> a  >> b;
  for(int i=0;i<=1000000000;i++){
    if(abs(i-a)==abs(i-b)){
      cout << i << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}

Measured memory_bytes: 3600
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define vint(a,n) vint a(n); rep(i, n) cin >> a[i];
#define vll(a,n) vll a(n); rep(i, n) cin >> a[i];
#define ALL(n) begin(n),end(n)
#define RALL(n) rbegin(n),rend(n)
#define MOD (1000000007)
#define INF (2e9)
#define INFL (2e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
using vint=vector<int>;
using vll=vector<ll>;
using vbool=vector<bool>;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
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; }

int main()
{
    int x; cin >> x;
    if(x==1) pr(0);
    else pr(1);
    return 0;}

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

using namespace std;

int main() {
	string s;
	cin >> s;
	
	bool flag1 = 1;
	bool flag2 = 1;
	
	for (int i = 0; i < s.size(); i += 2) if (s[i] == 'L') flag1 = 0;
	for (int i = 1; i < s.size(); i += 2) if (s[i] == 'R') flag2 = 0;
	
	if (flag1 && flag2) printf("Yes\n");
	else printf("No\n");
}


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

using namespace std;

int a[100100],dp[100100];

int main () {
    ios::sync_with_stdio(false); cin.tie(0);
    int n; cin>>n;
    for(int i=1;i<=n;i++) {cin>>a[i]; dp[i]=INT_MAX;} dp[1]=0;
    for(int i=1;i<=n;i++) {
        if(i+1<=n) dp[i+1]=min(dp[i+1],dp[i]+abs(a[i+1]-a[i]));
        if(i+2<=n) dp[i+2]=min(dp[i+2],dp[i]+abs(a[i+2]-a[i]));
    }
    cout<<dp[n]<<endl;
}


Measured memory_bytes: 1024
def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)

a=int(input())
n = num2alpha(a)
print(n.lower())

Measured memory_bytes: 9180
import java.util.*;

public class Main {
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
		
		int N1 = sc.nextInt();
        int N2 = sc.nextInt();
        int N3 = sc.nextInt();
        int N4 = sc.nextInt();
        ArrayList<Integer> a = new ArrayList<Integer>();
        a.add(1);
        a.add(7);
        a.add(9);
        a.add(4);
        
        if(a.indexOf(N1) != -1){
        	a.remove(a.indexOf(N1));
            if(a.indexOf(N2) != -1){
        		a.remove(a.indexOf(N2));
                if(a.indexOf(N3) != -1){
        			a.remove(a.indexOf(N3));
                    if(a.indexOf(N4) != -1){
        				System.out.println("YES");
                    }else{System.out.println("NO");}
                }else{System.out.println("NO");}
            }else{System.out.println("NO");}
        }else{
        	System.out.println("NO");        
        }
     } 
}  
        
        


Measured memory_bytes: 22996
import java.util.*;
public class Main {
    public static void main(String... args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt(); // 4
        int b = sc.nextInt(); // 12
        int k = sc.nextInt(); // 3
        
        if (b - a + 1 >= k * 2) {
            for (int index = a ; index < a + k ; index++) {
                System.out.println(index);
            }
            for (int index = k ; index > 0 ; index--) {
                System.out.println(b - index + 1);
            }
        } else {
            for (int index = a ; index < b + 1; index++) {
                System.out.println(index);
            }
        }
    }
}

Measured memory_bytes: 23764
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	long long a, b = 2, c = 1, d = 0, e;
	cin >> a;
	for (int h = 1; h <= a; h++) {
		d = b;
		b = c;
		c = d + c;
	}
	cout << b << "\n";
	cin >> e;
}

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

using namespace std;

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

const long long INF = 1LL << 60;

// 入力
int N;
int K;
long long h[100010];

// DP テーブル
long long dp[100010];

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

    // 初期化 (最小化問題なので INF に初期化)
    for (int i = 0; i < 100010; ++i) dp[i] = INF;

    // 初期条件
    dp[0] = 0;

    // ループ
    for (int i = 1; i < N; ++i) {
      for(int j = max(0,i-K); j<i;j++){
        chmin(dp[i],dp[j]+abs(h[j]-h[i]));
      }
    }

    // 答え
    cout << dp[N-1] << endl;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int ans = 0;
        while (N > 0) {
            ans++;
            N /= K;
        }
        System.out.println(ans);
    }
}



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

int main()
{
	int N, M;
	cin >> N >> M;
	vector<pair<int,int>> input(N);

	for(int i = 0; i < N; ++i) {
		cin >> input[i].first >> input[i].second;
	}

	vector<pair<int,int>> input2(M);
	for(int loop = 0; loop < M; ++loop) {
		cin >> input2[loop].first >> input2[loop].second;
	}

	for(int loop = 0; loop < N; ++loop) {
		int mi = 1e9;
		int result = 0;
		for(int loop2 = 0; loop2 < M; ++loop2) {
			int t = abs(input2[loop2].first - input[loop].first) + abs(input2[loop2].second - input[loop].second);
			if (mi > t) {
				mi = t;
				result = loop2 + 1;
			}
		}
		cout << result << endl;
	}

	return 0;
}


Measured memory_bytes: 3560
using System;
using static System.Console;
public class Hello{
    public static void Main(){
        string[] a = ReadLine().Split(' ');
        int x = int.Parse(a[0]);
        int y = int.Parse(a[1]);
        int z = int.Parse(a[2]);
        if((y*10+z)%4==0){
            WriteLine("YES");
        }else{
            WriteLine("NO");
        }
    }
}


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

march = {'M':0,'A':0,'R':0,'C':0,'H':0}

for i in range(n):
    si = input()
    if si[0] in march.keys():
        march[si[0]] += 1
#print(march)

sum = 0
sum += (march['M'] * march['A'] * march['R'])
sum += (march['M'] * march['A'] * march['C'])
sum += (march['M'] * march['A'] * march['H'])
sum += (march['A'] * march['R'] * march['C'])
sum += (march['A'] * march['R'] * march['H'])
sum += (march['R'] * march['M'] * march['C'])
sum += (march['R'] * march['M'] * march['H'])
sum += (march['R'] * march['C'] * march['H'])
sum += (march['C'] * march['M'] * march['H'])
sum += (march['C'] * march['A'] * march['H'])
print(sum)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;







int main() {
	int n;
	while (cin >> n&&n > 0) {
		vector<vi> v(n + 1, vi(n + 1, 0));
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				cin >> v[i][j];
				v[i][n] += v[i][j];
				v[n][j] += v[i][j];
			}
			v[n][n] += v[i][n];
		}
		for (int i = 0; i <= n; i++) {
			for (int j = 0; j <= n; j++) {
				printf("%5d", v[i][j]);
			}
			cout << endl;
		}
	}
}

Measured memory_bytes: 1244
local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, '*'..string.sub(k, i, i)) end local r = io.read local u = table.unpack or unpack return function() return r(u(a)) end end})
read.N = function(N) local t={} for i=1,N do t[i]=read.n() end return t end
string.totable = function(s) local t={} local u=string.sub for i=1,#s do t[i] = u(s, i, i) end return t end
string.split = function(s) local t={} for w in string.gmatch(s, "[^%s]+") do table.insert(t, w) end return (table.unpack or unpack)(t) end
----

local function factorial(n)
    local a = 1
    for i=1, n do
        a = a * i
    end
    return a
end

local function perm(seq)
    local up = table.unpack or unpack
    local t = {up(seq)}
    return coroutine.wrap(function()
        local function rec(i)
            if i > #t then
                --coroutine.yield({up(t)})
                coroutine.yield(t)
                return
            end
            rec(i+1)
            for j=i+1,#t do
                t[i], t[j] = t[j], t[i]
                rec(i+1)
                t[i], t[j] = t[j], t[i]
            end
        end
        rec(1)
    end)
end

-- C
local N = read.n()
local X, Y = {}, {}
for i=1,N do
    X[i], Y[i] = read.nn()
end

local route_num = factorial(N)

local sum = 0
local set = {}
for i=1,N do set[i] = i end
for route in perm(set) do
    for n=1,N-1 do
        local i, j = route[n], route[n+1]
        local d = math.sqrt((X[i]-X[j])^2 + (Y[i]-Y[j])^2)
        sum = sum + d
    end
end

print(sum / route_num)


Measured memory_bytes: 256
using System;
class Program{
	private int dx, dy;
	private int dis(int x1, int y1, int x2, int y2){
		if (x1 > x2)
			dx = x1 - x2;
		else
			dx = x2 - x1;
		if (y1 > y2)
			dy = y1 - y2;
		else
			dy = y2 - y1;
		return dx + dy;
	}
	private int iseven(int x, int y){
		return (x - y) % 2 == 0 ? 1 : 0;
	}
	public static void Main(){
		Program prog = new Program();
		int N = int.Parse(Console.ReadLine());
		int[] t = new int[N+1];
		int[] x = new int[N+1];
		int[] y = new int[N+1];
		t[0] = 0;
		x[0] = 0;
		y[0] = 0;
		string[] str;
		for (int p = 0 ;p < N ;p++ ){
			str = Console.ReadLine().Split(' ');
			t[p+1] = int.Parse(str[0]);
			x[p+1] = int.Parse(str[1]);
			y[p+1] = int.Parse(str[2]);
		}
		int f = 1;
		int d;
		for (int q = 0 ;q < N ;q++ ){
			d = prog.dis(x[q],y[q],x[q+1],y[q+1]);
			if (prog.iseven(d,t[q+1]-t[q]) == 0){
				f = 0;
				break;
			}else if (d - t[q+1] + t[q] > 0){
				f = 0;
				break;
			}
		}
		if (f == 1)
			Console.WriteLine("Yes");
		else
			Console.WriteLine("No");
	}
}

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

int main(void){
    int n;
    scanf("%d",&n);
    set<int> s;
    int t;
    for (size_t i = 0; i < n; i++)
    {
        scanf("%d",&t);
        s.insert(t);
    }
    printf("%d",s.size());
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl
const ll INF=1e9+7;
const ll N = 104;
ll n,f[N][11],p[N][11],ans=-INF;
ll joi[11];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	FOR(i,0,n){
		FOR(j,0,10){
			cin>>f[i][j];
		}
	}
	FOR(i,0,n){
		FOR(j,0,11){
			cin>>p[i][j];
		}
	}
	FOR(i,1,1024){
		ll k=i,w=0;
		FOR(j,0,10){
			joi[j]=k%2;
			k/=2;
		}
		FOR(j,0,n){
			ll c=0;
			FOR(m,0,10){
				if(f[j][m]==1&&joi[m]==1)c++;
			}
			w+=p[j][c];
		}
		if(ans<=w)ans=w;
	}
	pri(ans);
	return 0;
}


Measured memory_bytes: 256
#! /usr/bin/env python3

import sys
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

k = int(readline())

ans = -1
acc = 7 % k
for n in range(1, k + 10):
    if acc == 0:
        ans = n
        break
    acc = (10 * acc + 7) % k

print(ans)


Measured memory_bytes: 9244
#include<bits/stdc++.h>
long long i,a,N,s,A=INT_MAX,l,r,S[100002];int main(){scanf("%ld%ld",&N,&s);for(;i<N;i++){scanf("%ld",&a);S[i+1]+=S[i]+a;}for(;;){if(S[r]-S[l]>=s){A=std::min(A,r-l);l++;}else r++;if(r>N){if(A==INT_MAX)A=0;printf("%ld\n",A);return 0;}}}

Measured memory_bytes: 3988
#include <bits/stdc++.h> 
using namespace std; 
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    int l;
    cin>>l;

    double d = l*l*l/27.0;

    cout<<fixed<<setprecision(12);
    cout<<d<<"\n";
	return 0; 
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    ll W, H, N;
    cin >> W >> H >> N;
    ll lm[5] = {0, 0, W, 0, H};
    rep(i, 0, N){
        ll x, y, a;
        cin >> x >> y >> a;
        if(a == 1){
            lm[a] = max(lm[a], x);
        }else if(a == 2){
            lm[a] = min(lm[a], x);
        }else if(a == 3){
            lm[a] = max(lm[a], y);
        }else{
            lm[a] = min(lm[a], y);
        }
    }
    if(lm[1] > lm[2] || lm[3] > lm[4]){
        cout << 0 << endl;
    }else{
        ll ans = H * W;
        ans -= lm[1] * H + (W - lm[2]) * H;
        ans -= lm[3] * W + (H - lm[4]) * W;
        ans += lm[1] * lm[3] + lm[1] * (H - lm[4]);
        ans += (W - lm[2]) * lm[3] + (W - lm[2]) * (H - lm[4]);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
int v[200005],vv[200005];
int main() {
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&v[i]);
        vv[i]=v[i];
    }
    sort(v+1, v+1+n);
    int t1=v[n/2],t2=v[n/2+1];
    for(int i=1;i<=n;i++){
        if(vv[i]>t1)
            printf("%d\n",t1);
        else if(vv[i]<t2)
            printf("%d\n",t2);
        else
            printf("%d\n",t1);
    }
    // insert code here...
    //std::cout << "Hello, World!\n";
    return 0;
}


Measured memory_bytes: 3712
#include<cstdio>
#include<algorithm>
#include<utility>
using namespace std;
#define ran 200020
#define i64 long long int
int n;
pair<int,int> a[ran],b[ran];
int main(){
	scanf("%d",&n);
	for(int i=0; i<n; i++)
		scanf("%d",&a[i].second);
	for(int i=0; i<n; i++)
		scanf("%d",&b[i].second);
	int ret = 0;
	for(int bit = 0; bit <= 28; bit ++){
		int ca0 = 0, ca1 = 0;
		for(int i=0; i<n; i++){
			a[i].first = a[i].second & ((1 << bit)-1);
			b[i].first = b[i].second & ((1 << bit)-1);
			if(a[i].second & (1<<bit))
				ca1 ++;
			else
				ca0 ++;
		}
		sort(a,a+n);
		sort(b,b+n);
		int p=n-1,s,e;
		i64 stat = 0;
		int cc1=0, cc0=0;
		for(s=0; s<n; s=e){
			int cb1=0, cb0=0;
			for(e=s; e<n && b[e].first == b[s].first; e++){
				if(b[e].second & (1<<bit))
					cb1 ++;
				else
					cb0 ++;
			}
			while(p >= 0 && (a[p].first + b[s].first) >= (1<<bit)){
				if(a[p].second & (1<<bit))
					cc1 ++;
				else
					cc0 ++;
				p--;
			}
			stat += (i64)cb0 * cc0;
			stat += (i64)cb0 * (ca1 - cc1);
			stat += (i64)cb1 * (ca0 - cc0);
			stat += (i64)cb1 * cc1;
		}
		if(stat%2)
			ret += 1<<bit;
	}
	printf("%d\n",ret);
	return 0;
}

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

typedef long long ll;
typedef pair<int, int> ii;

const int N = 1e5 + 5;
int n, a, b;
vector<ii> e[N];
int res[N];
int ans;

void dfs(int par, int u, int c) {
  int i = 1;
  for (auto p : e[u]) {
    int v = p.first, resno = p.second;
    if (v == par) continue;
    if (c == i) ++i;
    res[resno] = i;
    ans = max(ans, i);
    dfs(u, v, i++);
  }
}

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

  cin >> n;
  for (int i = 0; i < n - 1; ++i) {
    cin >> a >> b;
    e[a].push_back(ii(b, i));
    e[b].push_back(ii(a, i));
  }

  dfs(0, 1, 0);
  cout << ans << endl;
  for (int i = 0; i < n - 1; ++i) {
    cout << res[i] << endl;
  }

  return 0;
}


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

int main(){
	int b[3];
	scanf("%d%d%d",b,b+1,b+2);
	if(b[0]==1&&b[1]==1) printf("Open\n");
	else if(b[2]) printf("Open\n");
	else printf("Close\n");
}

Measured memory_bytes: 1168
#include <iostream>
using namespace std;
int main() {
  int N;cin>>N;
  while(N>0) {
    int v[5],b=0,f=0,d[]={0,0,0,1,0,3,2,0};
    for(;b<5;++b) {
      v[b]=N;f|=1<<--N;cin>>N;
    }
    for(b=0;b<5;++b) cout<<((v[b]==d[f])?1:(d[f]?2:3))<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
// Example program
#include <iostream>
#include <string>
using namespace std;
int main()
{
  int a,b,c;
  cin>>a>>b>>c;
  if(a+b==c||a+c==b||b+c==a){cout<<"Yes"<<endl;}
  else{cout<<"No"<<endl;}
  return 0;
}



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

int main(){
    int i;
    string s;
    cin >> s;
    for(i=0; i<3; i++){
        if(s[i] == '1'){
            cout << '9';
        }else{
            cout << '1';
        }
    }
    return 0;
}

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

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef unordered_map<int,int> umii;
typedef unordered_map<ll,ll> umll;

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define bs(v,val) binary_search(v.begin(),v.end(),val)
#define mod 1e9+7
#define ff first
#define ss second
#define fi(n) for(int i=0;i<n;i++)
#define fj(n) for(int j=0;j<n;j++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define m_p make_pair
#define endl '\n'

struct custom_hash {    // anti-hack for unordered_map. To declare: unordered_map<long long, int, custom_hash> safe_map;
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

ll power(ll x, ll y, ll p)
{  
    ll res = 1;
    x = x % p;  
    if (x == 0) return 0;
    while (y > 0){  
        if (y & 1)  res = (res*x) % p;  
        y = y>>1;
        x = (x*x) % p;  
    }  
    return res;  
}
ll modInverse(ll n, ll p)
{
    return power(n, p-2, p); 
}
// ********** CODE STARTS HERE ****************//

int count(vector<vector<char>>&c, int a, int b)
{
    vector<bool>row(c.size(),false);
    vector<bool>col(c[0].size(), false);
    int idx = 0;
    while(a!=0)
    {
        row[idx++] = a%2;
        a/=2;
    }
    idx = 0;
    while(b!=0)
    {
        col[idx++] = b%2;
        b/=2;
    }
    int cnt = 0;
    for(int i=0;i<c.size();i++)
    {
        if(row[i])continue;
        for(int j=0;j<c[0].size();j++)
        {
            if(col[j])continue;
            if(c[i][j]=='#')cnt++;
        }
    }
    return cnt;
}
void solve()
{
    int H,W,K;
    cin>>H>>W>>K;
    vector<vector<char>>c(H,vector<char>(W));
    fi(H)
        fj(W)
            cin>>c[i][j];
    int cnt = 0;
    for(int i=0;i< (1<<H); i++)
    {
        for(int j=0; j< (1<<W); j++)
        {
            // if(i!=0 || j!=0)
            // {
                if(count(c, i, j) == K)
                    cnt++;
            // }
        }
    }
    cout<<cnt<<'\n';
}

int main()
{
	fastio;
    // int T;
    // cin>>T;
    // while(T--)
        solve();
	return 0;
}

Measured memory_bytes: 3656
# -*- coding: utf-8 -*-

import sys
from heapq import heapify, heappush, heappop

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
A = LIST()

A1 = A[:N]
A2 = A[N:N*2]
A3 = [-a for a in A[N*2:]]
heapify(A1)
heapify(A3)

# 真ん中グループ(A2)をiまで左に取り込んだ時の左グループ(A1)の最大値
ansa = [0] * (N+1)
ansa[0] = sum(A1)
for i in range(N):
    heappush(A1, A2[i])    
    ansa[i+1] = ansa[i] + A2[i] - heappop(A1)

# 真ん中グループ(A2)を後ろからiまで右に取り込んだ時の右グループ(A1)の最小値
ansb = [0] * (N+1)
ansb[N] = -sum(A3)
for i in range(N-1, -1, -1):
    heappush(A3, -A2[i])
    ansb[i] = ansb[i+1] + A2[i] - (-heappop(A3))

# 各位置iから一番いい場所を得る
ans = -INF
for i in range(N+1):
    ans = max(ans, ansa[i]-ansb[i])
print(ans)


Measured memory_bytes: 39620
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		try(Scanner scan = new Scanner(System.in);){
			int N = Integer.parseInt(scan.next());
			int a = Integer.parseInt(scan.next());
			int b = Integer.parseInt(scan.next());
			int sum = 0;
			for(int i=0; i<=N; i++) {
				int tmpSum = 0;
				int num = i;
				while(num != 0) {
					tmpSum += num %10;
					num /= 10;
				}
				if(tmpSum >= a && tmpSum <= b) {
					sum += i;
				}
			}
          System.out.println(sum);
		}
	}
}

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

int main() {
	int N, P; cin >> N >> P;
	int odd=0, A;
	for(int i=0; i<N; ++i){
	    cin >> A;
	    if(A%2) ++odd;
	}
	long T;
	if(odd) T=pow(2, N-1);
	else if(P) T=0;
	else T=pow(2, N);
	cout << T << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

int dx[]={1, 0, -1, 0};
int dy[]={0, -1, 0, 1};

int main(){
    int n, w, h; cin>>n>>w>>h;
    vector<int> imosw(w+1, 0), imosh(h+1, 0);
    for(int i=0; i<n; i++){
        int x, y, d; cin>>x>>y>>d;
        int minx = max(0, x - d);
        int maxx = min(w - 1, x + d - 1);
        imosw[minx]++;
        imosw[maxx + 1]--;

        int miny = max(0, y - d);
        int maxy = min(h - 1, y + d - 1);
        imosh[miny]++;
        imosh[maxy + 1]--;
    }

    bool validw = true;
    for(int i=0; i<w; i++){
        if(imosw[i] <= 0) validw = false;
        imosw[i + 1] += imosw[i];
    }

    bool validh = true;
    for(int i=0; i<h; i++){
        if(imosh[i] <= 0) validh = false;
        imosh[i + 1] += imosh[i];
    }

    if(validw || validh){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
long long  n, k, ans, flag;
int main() {
	scanf("%lld%lld",&n, &k);
	long long MAX = n * 7 ;
	for(long long i = 8; i <= MAX ; i++) {
        if(i % 7 != 0 && i % 7 != 1 && (i * 9) % 11 == k ) {
            	 ans ++, flag = i;
                 break;
            }   
    }
	MAX -= flag + 7;
	ans = (MAX / 77) * 5;
	int yu = MAX % 77;
	flag %= 7;
	if(flag == 2) {
		if(yu >=  0 && yu < 11) ans += 0;
		if(yu >= 11 && yu < 22) ans += 1;
		if(yu >= 22 && yu < 33) ans += 2;
		if(yu >= 33 && yu < 44) ans += 2;
		if(yu >= 44 && yu < 55) ans += 3;
		if(yu >= 55 && yu < 66) ans += 3;
		if(yu >= 66 && yu < 77) ans += 4;
	}
	if(flag == 3) {
		if(yu >=  0 && yu < 11) ans += 0;
		if(yu >= 11 && yu < 22) ans += 0;
		if(yu >= 22 && yu < 33) ans += 1;
		if(yu >= 33 && yu < 44) ans += 1;
		if(yu >= 44 && yu < 55) ans += 2;
		if(yu >= 55 && yu < 66) ans += 3;
		if(yu >= 66 && yu < 77) ans += 4;
	}
	if(flag == 4) {
		if(yu >=  0 && yu < 11) ans += 0;
		if(yu >= 11 && yu < 22) ans += 0;
		if(yu >= 22 && yu < 33) ans += 1;
		if(yu >= 33 && yu < 44) ans += 2;
		if(yu >= 44 && yu < 55) ans += 3;
		if(yu >= 55 && yu < 66) ans += 4;
		if(yu >= 66 && yu < 77) ans += 4;
	}
	if(flag == 5) {
		if(yu >=  0 && yu < 11) ans += 0;
		if(yu >= 11 && yu < 22) ans += 1;
		if(yu >= 22 && yu < 33) ans += 2;
		if(yu >= 33 && yu < 44) ans += 3;
		if(yu >= 44 && yu < 55) ans += 3;
		if(yu >= 55 && yu < 66) ans += 4;
		if(yu >= 66 && yu < 77) ans += 4;
	}
	if(flag == 6) {
		if(yu >=  0 && yu < 11) ans += 0;
		if(yu >= 11 && yu < 22) ans += 1;
		if(yu >= 22 && yu < 33) ans += 1;
		if(yu >= 33 && yu < 44) ans += 2;
		if(yu >= 44 && yu < 55) ans += 2;
		if(yu >= 55 && yu < 66) ans += 3;
		if(yu >= 66 && yu < 77) ans += 4;
	}
	
	printf("%lld\n",ans + 1);
	return 0; 
}


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

int main() {
	string s;
	cin >> s;
	sort(s.begin(), s.end());
	if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner
import java.io.PrintWriter

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val pw = new PrintWriter(System.out)

    val n = sc.nextInt()
    var set: Set[Int] = Set()
    for (i <- 1 to 9) {
      for (j <- i to 9) {
        set += i * j
      }
    }
    if (set.contains(n)) {
      pw.println("Yes")
    } else {
      pw.println("No")
    }

    pw.flush()
  }
}

Measured memory_bytes: 27424
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

  public static void main(String[] args) {
    FastScanner sc = new FastScanner();

    int A = sc.nextInt();
    int B = sc.nextInt();

    int ans = (int) Math.ceil((double) B / (A - 1));

    if ((ans - 1) * (A - 1) + 1 >= B) {
      ans--;
    }
    System.out.println(ans);

  }
}

class FastScanner {
  private final InputStream in = System.in;
  private final byte[] buffer = new byte[1024];
  private int ptr = 0;
  private int buflen = 0;

  private boolean hasNextByte() {
    if (ptr < buflen) {
      return true;
    } else {
      ptr = 0;
      try {
        buflen = in.read(buffer);
      } catch (IOException e) {
        e.printStackTrace();
      }
      if (buflen <= 0) {
        return false;
      }
    }
    return true;
  }

  private int readByte() {
    if (hasNextByte()) {
      return buffer[ptr++];
    } else {
      return -1;
    }
  }

  private static boolean isPrintableChar(int c) {
    return 33 <= c && c <= 126;
  }

  private void skipUnprintable() {
    while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
      ptr++;
    }
  }

  public boolean hasNext() {
    skipUnprintable();
    return hasNextByte();
  }

  public String next() {
    if (!hasNext()) {
      throw new NoSuchElementException();
    }
    StringBuilder sb = new StringBuilder();
    int b = readByte();
    while (isPrintableChar(b)) {
      sb.appendCodePoint(b);
      b = readByte();
    }
    return sb.toString();
  }

  public int nextInt() {
    if (!hasNext()) {
      throw new NoSuchElementException();
    }
    int n = 0;
    boolean minus = false;
    int b = readByte();
    if (b == '-') {
      minus = true;
      b = readByte();
    }
    if (b < '0' || '9' < b) {
      throw new NumberFormatException();
    }
    while (true) {
      if ('0' <= b && b <= '9') {
        n *= 10;
        n += b - '0';
      } else if (b == -1 || !isPrintableChar(b)) {
        return minus ? -n : n;
      } else {
        throw new NumberFormatException();
      }
      b = readByte();
    }
  }

  public long nextLong() {
    if (!hasNext()) {
      throw new NoSuchElementException();
    }
    long n = 0;
    boolean minus = false;
    int b = readByte();
    if (b == '-') {
      minus = true;
      b = readByte();
    }
    if (b < '0' || '9' < b) {
      throw new NumberFormatException();
    }
    while (true) {
      if ('0' <= b && b <= '9') {
        n *= 10;
        n += b - '0';
      } else if (b == -1 || !isPrintableChar(b)) {
        return minus ? -n : n;
      } else {
        throw new NumberFormatException();
      }
      b = readByte();
    }
  }
}

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

int main(){
  int n,m;
  cin>>n>>m;
  vector<int> cnt(n,1),pos(n,0);//pos is bool
  pos[0]=1;
  rep(i,m){
    int x,y;
    cin>>x>>y;
    x--;y--;
    if(pos[x]==1){
      if(cnt[x]==1){
        pos[x]=0;
        pos[y]=1;
      }else{
        pos[y]=1;
      }
    }
    cnt[x]--;
    cnt[y]++;
  }
  
  int ans=0;
  rep(i,n){
    if(pos[i]==1)ans++;
  }  
  cout<<ans<<endl;
}

Measured memory_bytes: 4036
#include <algorithm>
#include <array>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <utility>
#include <vector>
#define FOR(i,a,b) for (int i=(a),for_##i##_max=(b);i<=(for_##i##_max);++i)
#define RFOR(i,a,b) for (int i=(a),rfor_##i##_min=(b);i>=(rfor_##i##_min);--i)
#define REP(i,n) for (int i=0,rep_##i##_len=(n);i<(rep_##i##_len);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)
constexpr int INF = 100100100;

template<typename T>
void chmin(T &x, T y) {
  x = std::min(x, y);
}

template<typename T>
void chmax(T &x, T y) {
  x = std::max(x, y);
}

using namespace std;

int main() {
  // cout << fixed << setprecision(10);
  int A, B, T;
  cin >> A >> B >> T;
  cout << (T / A) * B << endl;
  return 0;
}


Measured memory_bytes: 768
#include "bits/stdc++.h"
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;

using namespace std;

struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if (AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


const int NM = 100000;


void solve() {
    ll H,W;
    cin >> H >> W;
    ll out=0;

    if (H == 1 || W == 1) {
        cout << 1;
        return;
    }

    bool isOdd = false;
    if (H % 2 == 0) {
        isOdd = true;
    }

    if (isOdd) {
        out = W  * H / 2;
    }
    else {
        out = W * (H / 2) + ((W+1)/2);
    }

    cout << out;
}



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







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

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

  int n;
  cin >> n;
  vector<int> p(n);
  rep(i, 0, n) cin >> p[i];
  int min_val = p[0], ans = 0;
  rep(i, 0, n) {
    if (min_val >= p[i]) {
      ans++;
      min_val = p[i];
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 1024
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define vec vector
#define fi first
#define se second
#define eb emplace_back
#define ef emplace_front
#define pof pop_front()
#define pob pop_back()
#define Rep(i,n) for(li i=0,nn=(li)(n);i!=nn;++i)
#define Rep1(i,n) for(li i=1,nn=(li)(n)+1;i!=nn;++i)
#define Size(v) (li)(v.size())
#define SortA(v) sort(v.begin(),v.end())
#define SortD(v) sort(v.rbegin(),v.rend())
#define All(a) (a).begin(),(a).end()
#define Input(a) for(li ii=0,nn=(li)(a.size());ii!=nn;++ii){cin>>(a).at(ii);}
#define Input2(a,b) for(li ii=0,nn=(li)(a.size());ii!=nn;++ii){cin>>(a).at(ii)>>(b).at(ii);}
#define mp make_pair
using li = int64_t;
using intl = int64_t;
using vi = vec<li>;
using vb = vec<bool>;
using vvi = vec<vi>;
using qi = deque<li>;
using pi = pair<li,li>;
using vpi = vec<pi>;
using si = set<li>;
using vsi = vec<si>;
using mii = map<li,li>;
using vmii = vec<mii>;
vec<li> dx = {0, 1, 0, -1, 1, 1, -1, -1};
vec<li> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr li INF = 9223372036854775807;

void Yes(li b){
  if(b)cout<<"Yes";
  else cout<<"No";
}
void yes(li b){
  if(b)cout<<"yes";
  else cout<<"no";
}

int main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  cout.precision(16);

  li N=200000,K=41;
  cin >>N>>K;

  vector<int> A(N,0),B(N,0);
  
  if(K>41){
    Rep(i,N){
      cout<<N<<' ';
    }
    return 0;
  }

  Input(A);

  li l,r;
  Rep(j,K){
  Rep(i,N){
  	l=max(0L,i-A[i]);
  	r=min(N-1,i+A[i]);
  	B[l]++;
  	if(r+1<N){B[r+1]--;}
  }
  Rep1(i,N-1){
  	B[i]+=B[i-1];
  }
  Rep(i,N){
  	A[i]=B[i];
  	B[i]=0;
  }
}

for(auto&& a:A){
	cout<<a<<' ';
}

}

Measured memory_bytes: 4796
from collections import deque

n, m = map(int, input().split())
xyz = []
for _ in range(m):
    x, y, z = map(int, input().split())
    xyz.append((x, y, z))


uf = [-1]*(n+1)
def find(i):
    if uf[i] < 0:
        return i
    else:
        uf[i] = find(uf[i])
        return uf[i]

for x, y, z in xyz:
    px, py = find(x), find(y)
    
    if px != py:
        px, py = (px, py) if uf[py] < uf[px] else (px, py)
        uf[px] += uf[py]
        uf[py] = px

# print(uf)
ans = sum([1 for i in range(1, n+1) if uf[i] < 0])
print(ans)


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

int main(){
	int n; cin >> n;
	vector<int> a(n);
	int ans=0;
	for(int i=0;i<n;i++){
		cin >> a[i];
		while(a[i]%2==0){
			a[i]/=2;
			ans++;
		}
	}
	cout << ans << endl;
}


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

inline int in()
{
    int aa=0,ff=1;char cc=getchar();
    for(;!isdigit(cc);cc=getchar())if(cc=='-')ff=-1;
    for(;isdigit(cc);cc=getchar())aa=(aa<<3)+(aa<<1)+(cc&15);
    return aa*ff;
}

string s;
bool C=0,F=0;

int main()
{
    cin>>s;
    int l=s.length();
    for(int i=0;i<l;++i)
    {
        if(s[i]=='C')
        {
            for(int j=i+1;j<l;++j)
            {
                if(s[j]=='F')
                {
                    puts("Yes");
                    return 0;
                }
            }
        }
    }
    puts("No");
    
    return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    sum = 0
    for i in range(N):
        x,y = (_ for _ in input().split())
        if y == 'JPY':
            sum += float(x)
        elif y == 'BTC':
            sum += float(x) * 380000.0
    print(sum)

if __name__  == '__main__':
    main()


Measured memory_bytes: 2940
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define MOD 1000000007
using namespace std;

int main(void){
    string s;
    cin >> s;
    int n=s.length();
    int count=0;
    for(int i=0; i<s.length(); i++){
        count+=s[i]-'0';
    }
    cout << 2*min(count,n-count) << endl;
    return 0;
}

Measured memory_bytes: 512
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"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 lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	H, W := getInt(), getInt()
	a := make([][]byte, H)
	for i := 0; i < H; i++ {
		a[i] = []byte(getString())
		// out(a[i])
	}
	h := make([]bool, H)
	for i := 0; i < H; i++ {
		flg := true
		for j := 0; j < W; j++ {
			if a[i][j] == '#' {
				flg = false
				break
			}
		}
		h[i] = flg
	}

	w := make([]bool, W)
	for j := 0; j < W; j++ {
		flg := true
		for i := 0; i < H; i++ {
			if a[i][j] == '#' {
				flg = false
				break
			}
		}
		w[j] = flg
	}

	// out(w)
	for i := 0; i < H; i++ {
		if h[i] == true {
			continue
		}
		for j := 0; j < W; j++ {
			if w[j] == true {
				continue
			}
			fmt.Print(string(a[i][j]))
		}
		out()
	}
}


Measured memory_bytes: 896