akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
  int N;
  int ans = 100000;
  cin >> N;
  REP(i, N) {
    int  A, C;
    cin >> A;
    C = 0;
    if ((A % 2) != 0) {
      cout << 0 << endl;
      return 0;
    }
    while ((A%2) == 0) {
      C++;
      A /= 2;
    }
    ans = min(ans, C);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char N[4]; cin >> N;
  bool overlap = false;
  
  for(int i = 0;i < 4;i++){
    if(N[i] ==N[i + 1]) overlap = true;
  }
  if(overlap) cout << "Bad" << endl;
  else cout << "Good" << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <functional>
#include <iostream>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

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

using vll = vector<ll>;

void solve();

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

  solve();

  return 0;
}

#define ini(...)   \
  int __VA_ARGS__; \
  in(__VA_ARGS__)

#define inl(...)  \
  ll __VA_ARGS__; \
  in(__VA_ARGS__)

#define ins(...)      \
  string __VA_ARGS__; \
  in(__VA_ARGS__);

void in() {}
template <typename T, class... U>
void in(T& t, U&... u) {
  cin >> t;
  in(u...);
}

void out() {
  cout << endl;
}
template <typename T, class... U>
void out(const T& t, const U&... u) {
  cout << t;
  if (sizeof...(u))
    cout << " ";
  out(u...);
}

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

void solve();
#ifndef ONLINE_JUDGE
#include "./lib.hpp"
#endif

void solve() {
  inl(N, W);

  vll v[4];
  inl(base_weight);
  v[0].resize(1);
  cin >> v[0][0];

  rep(i, N - 1) {
    inl(w, v1);
    v[w - base_weight].push_back(v1);
  }

  vll acc_sum[4];
  rep(i, 4) {
    sort(v[i].begin(), v[i].end(), greater<ll>());
    acc_sum[i].resize(v[i].size() + 1);
    acc_sum[i][0] = 0;
    rep(j, v[i].size()) acc_sum[i][j + 1] = acc_sum[i][j] + v[i][j];
  }

  ll ret = 0;
  rep(i, v[3].size() + 1) {
    rep(j, v[2].size() + 1) {
      rep(k, v[1].size() + 1) {
        ll rest = W - (i * (base_weight + 3) + j * (base_weight + 2) +
                       k * (base_weight + 1));
        if (rest < 0)
          break;
        ll num = min(rest / base_weight, (ll)(v[0].size()));

        ll value =
            acc_sum[3][i] + acc_sum[2][j] + acc_sum[1][k] + acc_sum[0][num];
        if (ret < value)
          ret = value;
      }
    }
  }

  out(ret);
}


Measured memory_bytes: 3668
#include <stdio.h>

int main()
{
    int i, j;
    for(i = 1; i <= 9; i++)
    {
        for(j = 1; j <= 9; j++)
        {
             printf("%dx%d=%d\n", i, j, i * j);
        }
    }

    return 0;
}


Measured memory_bytes: 2008
def counter(x):
        if x == 0:
                return 0
        return counter(x >> 1) + (x & 1)

N = int(input())
A = []
x = [0] * N 
for i in range(N):
        A.append(int(input()))
        x[i] = [list(map(int, input().split())) for j in range(A[i])]

ans = 0 
for bits in range(1, 1 << N): 
        flag = 1 
        for i in range(N):
                if not bits & (1 << i): 
                        continue
                for j in range(A[i]):
                        if (bits >> (x[i][j][0] - 1) & 1) ^ x[i][j][1]:
                                flag = 0 
        if flag:
                ans = max(ans, counter(bits))
print(ans)

Measured memory_bytes: 50672
#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  if (a >= 13) {
    cout << b << endl;
  } else if (a >= 6) {
    cout << b / 2 << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}

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

/*
L(0) := P
L(n) := B L(n-1) P L(n-1) B
*/

ll f(int n){
    return n==0 ? 1 : f(n-1)*2+3;
}

ll g(int n){
    return n==0 ? 1 : g(n-1)*2+1;
}

ll calc(int n, ll x){
    if(x<=0) return 0;
    if(n==0){
        // assert(x==1);
        return 1;
    }
    ll fn = f(n);
    if(x > fn/2) return g(n-1) + 1 + calc(n-1, x - (fn/2+1));
    else return calc(n-1, x-1);
}

int main(void){
    int n;
    ll x;
    cin >> n >> x;
    cout << calc(n, x) << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)


n = int(input())
s = input().rstrip()
MOD = 10**9+7

cnt = 0
point = 1
for i, x in enumerate(s):
    if (x == 'B' and i % 2 == 0) or (x == 'W' and i % 2 != 0):
        cnt += 1
    else:
        point *= cnt
        cnt -= 1
        point %= MOD


if cnt != 0:
    print(0)
else:
    # factorial
    for x in range(1, n+1):
        point *= x
        point %= MOD

    print(point)

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

using namespace std;
typedef long long lint;

#define RPT(i, b, e) for (int i = (b); i <= (e); i++)
#define RPT0(i, n) RPT(i, 0, n - 1)
#define RPT1(i, n) RPT(i, 1, n)
#define EACH(it, v) for (const auto& it : v)
#define ALL(v) v.begin(), v.end()

void resolve()
{
    int N, W;
    cin >> N >> W;
    vector<int> w(N), v(N);
    RPT0(i, N) cin >> w[i] >> v[i];

    // dp[i][j]
    // i番目までの品物を、重さj以下になるように選んだ時の最大価値
    lint** dp;
    dp = (lint**)malloc(sizeof(lint) * N);
    RPT0(i, N) dp[i] = (lint*)malloc(sizeof(lint) * (W + 1));

    RPT(j, 0, min(w[0] - 1, W)) dp[0][j] = 0;
    RPT(j, w[0], W) dp[0][j] = v[0];

    RPT(i, 1, N - 1) RPT(j, 0, W)
    {
        dp[i][j] = (j < w[i]) ? dp[i - 1][j]
                              : max(dp[i - 1][j - w[i]] + v[i], dp[i - 1][j]);
    }
    cout << dp[N - 1][W] << endl;

    RPT0(i, N) free(dp[i]);
    free(dp);
}

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


Measured memory_bytes: 78720
/*
https://drken1215.hatenablog.com/entry/2019/02/24/230900
*/

#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
void chmin(long long &a, long long b) { if (a > b) a = b; }
const long long INF = 1LL<<58;

// vector v において、x の前方と後方の index を求める
template<class T> int former(const vector<T> &v, T x) {
    return upper_bound(v.begin(), v.end(), x) - v.begin() - 1;
}
template<class T> int latter(const vector<T> &v, T x) {
    return lower_bound(v.begin(), v.end(), x) - v.begin();
}

int main() {
    int A, B, Q; cin >> A >> B >> Q;
    vector<long long> s(A), t(B);
    for (int i = 0; i < A; ++i) cin >> s[i];
    for (int i = 0; i < B; ++i) cin >> t[i];
    s.push_back(INF); s.push_back(-INF); sort(s.begin(), s.end());
    t.push_back(INF); t.push_back(-INF); sort(t.begin(), t.end());
    
    for (int _ = 0; _ < Q; ++_) {
        long long x; cin >> x;
        long long res = INF;
        
        // 最初に s (前方に行くか後方に行くか場合分け)
        for (int i = 0; i < 2; ++i) {
            long long first = (i ? s[former(s, x)] : s[latter(s, x)]);
            // 次に t (現在地の前後を見る)
            for (int j = 0; j < 2; ++j) {
                long long second = (j ? t[former(t, first)] : t[latter(t, first)]);
                chmin(res, abs(x - first) + abs(first - second));
            }
        }
        // 最初に t (前方に行くか後方に行くか場合分け)
        for (int i = 0; i < 2; ++i) {
            long long first = (i ? t[former(t, x)] : t[latter(t, x)]);
            // 次に t (現在地の前後を見る)
            for (int j = 0; j < 2; ++j) {
                long long second = (j ? s[former(s, first)] : s[latter(s, first)]);
                chmin(res, abs(x - first) + abs(first - second));
            }
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 3956
#include <iostream>
#include <string>
#include <stack>
#include <math.h>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <vector>

using namespace std;





int main()
{
	int a[7];
	int n;
	int sum;
	string ind[10000];
	while (cin >> n,n) {
		for (int i = 0; i < n; i++) {
			cin >> ind[i];
		}
		for (int i = 1; i < 7; i++) {
			a[i] = i;
		}
		sum = 1;
		for (int i = 0; i < n; i++) {
			if (ind[i] == "North") {
				swap(a[1], a[2]);
				swap(a[2], a[6]);
				swap(a[6], a[5]);
			}
			else if (ind[i] == "East") {
				swap(a[1], a[4]);
				swap(a[4], a[6]);
				swap(a[6], a[3]);
			}
			else if (ind[i] == "West") {
				swap(a[1], a[3]);
				swap(a[3], a[6]);
				swap(a[6], a[4]);
			}
			else if (ind[i] == "South") {
				swap(a[1], a[2]);
				swap(a[1], a[5]);
				swap(a[5], a[6]);
			}
			else if (ind[i] == "Right") {
				swap(a[3], a[2]);
				swap(a[3], a[5]);
				swap(a[5], a[4]);
			}
			else if (ind[i] == "Left") {
				swap(a[2], a[3]);
				swap(a[2], a[4]);
				swap(a[4], a[5]);
			}
			sum += a[1];
		}

		cout << sum << endl;
	}




}

Measured memory_bytes: 1524
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace MultiplicationC
{
    class Program
    {
        static void Main()
        {

            decimal A = 0m;
            decimal B = 0m;
            decimal answer = 0;

            string[] input = Console.ReadLine().Split(' ');



            try
            {
                checked
                {
                    A = decimal.Parse(input[0]);
                    B = decimal.Parse(input[1]);
                    if (B > 10)
                    {
                        Console.WriteLine("error");
                        return;
                    }

                    answer = (decimal)Math.Truncate((A * B));
                }
            }
            catch(OverflowException ex)
            {
                Console.WriteLine("error");
                return;
            }
            catch (FormatException ex)
            {
                Console.WriteLine("error");
                return;
            }


            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 27592
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#define llint long long

using namespace std;

int h, w;
char p[105][105];
int id[105][105];
vector<int> G[2][10005];
const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
const int dx2[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy2[] = {0, -1, -1, -1, 0, 1, 1, 1};

int V;
string hash[2][10005];
int depth[2][10005];

void dfs(int x, int y, int nid)
{
	id[x][y] = nid;
	for(int i = 0; i < 4; i++){
		int nx = x + dx[i], ny = y + dy[i];
		if(nx < 0 || nx > w || ny < 0 || ny > h) continue;
		if(p[x][y] != p[nx][ny]) continue;
		if(id[nx][ny]) continue;
		dfs(nx, ny, nid);
	}
}
void dfs2(int x, int y, int nid)
{
	id[x][y] = nid;
	for(int i = 0; i < 8; i++){
		int nx = x + dx2[i], ny = y + dy2[i];
		if(nx < 0 || nx > w || ny < 0 || ny > h) continue;
		if(p[x][y] != p[nx][ny]) continue;
		if(id[nx][ny]) continue;
		dfs2(nx, ny, nid);
	}
}

string calc(int g, int v, int prev, int dep)
{
	depth[g][v] = dep;
	vector<string> vec;
	for(int i = 0; i < G[g][v].size(); i++){
		if(G[g][v][i] == prev) continue;
		vec.push_back(calc(g, G[g][v][i], v, dep+1));
	}
	sort(vec.begin(), vec.end());
	string ret = "("; //)
	for(int i = 0; i < vec.size(); i++) ret += vec[i];
	ret += ")";
	return hash[g][v] = ret;
}

int main(void)
{
	while(1){
		
		for(int g = 0; g < 2; g++){
			cin >> h >> w;
			if(h == 0 && w == 0) return 0;
			h++, w++;
			
			for(int y = 0; y <= h; y++){
				for(int x = 0; x <= w; x++){
					p[x][y] = '.';
				}
			}
			for(int y = 1; y < h; y++){
				for(int x = 1; x < w; x++){
					cin >> p[x][y];
				}
			}
			
			for(int x = 0; x <= w; x++){
				for(int y = 0; y <= h; y++){
					id[x][y] = 0;
				}
			}
			int nid = 1;
			for(int x = 0; x <= w; x++){
				for(int y = 0; y <= h; y++){
					if(!id[x][y]){
						if(p[x][y] == '.') dfs(x, y, nid++);
						else dfs2(x, y, nid++);
					}
				}
			}
			V = nid - 1;
			
			for(int i = 1; i <= V; i++) G[g][i].clear();
			for(int x = 0; x <= w; x++){
				for(int y = 0; y <= h; y++){
					for(int i = 0; i < 4; i++){
						int nx = x + dx[i], ny = y + dy[i];
						if(nx < 0 || nx > w || ny < 0 || ny > h) continue;
						if(id[nx][ny] != id[x][y]){
							G[g][id[x][y]].push_back(id[nx][ny]);
							G[g][id[nx][ny]].push_back(id[x][y]);
						}
					}
				}
			}
			for(int i = 1; i <= V; i++){
				sort(G[g][i].begin(), G[g][i].end());
				G[g][i].erase(unique(G[g][i].begin(), G[g][i].end()), G[g][i].end());
			}
			
			/*for(int i = 1; i <= V; i++){
				cout << "* ";
				for(int j = 0; j < G[g][i].size(); j++) cout << G[g][i][j] << " "; cout << endl;
			}
			cout << endl;*/
		}
		
		calc(0, 1, -1, 0);
		calc(1, 1, -1, 0);
		for(int i = 1; i <= V; i++){
			if(depth[1][i] % 2 == 0 && hash[0][1] == hash[1][i]){
				cout << "yes" << endl;
				goto end;
			}
		}
		for(int i = 1; i <= V; i++){
			if(depth[0][i] % 2 == 0 && hash[1][1] == hash[0][i]){
				cout << "yes" << endl;
				goto end;
			}
		}
		cout << "no" << endl;
		end:;
	}
	
	return 0;
}


Measured memory_bytes: 5200
import os

def main():
	n = int(input())
	s = input()
	flag = True
	if n%2 != 0:
		flag = False
	else:
		n = n//2
		if s[n:] != s[:n]:
			flag = False
	if flag:
		print("Yes")
	else:
		print("No")

if __name__ == "__main__":
	main()


Measured memory_bytes: 2940
#define _USE_MATH_DEFINES
#include  <iostream>
#include  <algorithm>
#include  <climits>
#include  <vector>
#include  <string>
#include  <cstring>
#include  <stack>
#include  <queue>
#include  <cmath>
#include  <iomanip>
#include  <set>
#include  <map>
#include  <new>
#include <cstdint>
#include <cctype>
using namespace std;
#define rep(i,n)  for(int i = 0; i < n; i++)
#define lrep(i,n,m)  for(int i = n; i < m; i++)

using ll = long long;
using Vii = vector<vector<int> >;
using Gjudge = vector<vector<bool>>;
using Vi = vector<int>;
using Vl = vector<ll>;
using Vll = vector<vector<ll> >;
using Vs = vector<string>;
using Vb = vector<bool>;
using the = pair<int, int>;
using lthe = pair<ll, ll>;

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

const int Mod = static_cast<int>(1e9 + 7);
const int INF = INT_MAX;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,1,0,-1 };

int main() {
	int a, b;
	cin >> a >> b;
	cout << a * b << endl;
}


Measured memory_bytes: 3676
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
using namespace std;

#define ABS(a) (((a) >= 0) ? (a) : -(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, a, b) for (int i = a; i > b; --i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define int long long

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

const int kMaxN = 200000;

int N;
int a[kMaxN], b[kMaxN];
int ans = 0;

// int Pow(int a, int n) {
//   int r = 1;
//   REP(i, n) { r *= a; }
//   return r;
// }

signed main() {
  cin >> N;
  REP(i, N) { cin >> a[i]; }
  REP(i, N) { cin >> b[i]; }

  REP(k, 29) {
    // cout << k << endl;
    int a2[kMaxN], b2[kMaxN];
    REP(i, N) { a2[i] = a[i] % (2<<k); }
    REP(i, N) { b2[i] = b[i] % (2<<k); }
    sort(b2, b2+N);

    int cntk1 = 0;
    REP(i, N) {
      auto be = lower_bound(b2, b2+N, MAX(0, (1<<k)-a2[i]));
      auto en = lower_bound(b2, b2+N, MAX(0, (2<<k)-a2[i]));
      // cout << en << " " << be << " " << en-be << endl;
      cntk1 += en-be;
      be = lower_bound(b2, b2+N, (3<<k)-a2[i]);
      en = lower_bound(b2, b2+N, (4<<k)-a2[i]);
      cntk1 += en-be;
    }

    if (cntk1%2 == 1) { ans += (1<<k); }
    // cout << k << " " << cntk1 << " " << ans << endl;
  }

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


Measured memory_bytes: 6528
#include<stdio.h>
//revenge of QUEEEEEEEEEE
int main(){
  char str[100001] = {};
  char stack[100001] = {};
  int stackcnt = 0;
  int n = 0;
  int i = 0;
  scanf(" %s",str);
  for(i=0;;i++){
    if(str[i] == '\0'){
      break;
    }else{
      n++;
    }
  }
  //printf("%d/",n);
  for(i=0;i<n;i++){
    if(stackcnt == 0 || str[i] == stack[stackcnt-1]){
      stack[stackcnt] = str[i];
      stackcnt++;
    }else{
      stackcnt--;
    }
  }
  printf("%d",n-stackcnt);
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
using namespace std;


int main() {
    string S, T;
    cin >> S >> T;
    for (int i = 0; i < S.size(); i++) {
        string s = S.substr(i) + S.substr(0, i);
        if (s == T) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

while True:
    M,F,R = map(int,input().split())
    if M == -1 and F == -1 and R == -1:
        break
    if M == -1 or F == -1:
        print("F")
    elif M+F >= 80:
        print("A")
    elif M+F >= 65:
        print("B")
    elif M+F >= 50:
        print("C")
    elif M+F >= 30:
        if R >= 50:
            print("C")
        else:
            print("D")
    else:
        print("F")




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

int main() {
  int w, h, x, y;
  cin >> w >> h >> x >> y;
  long long ans = w;
  ans *= h;
  ans >>= 1;
  cout << ans;
  if (w % 2 == 1 and h % 2 == 1) {
    cout << ".5 0";
  } else {
    cout << " " << ((x * 2 == w and y * 2 == h) ? 1 : 0);
  }
  cout << endl;
}


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

int main() {
  ll N,K,a,count=0;

  cin >> N >> K;

  vector<ll> d(K);
  vector<ll> okashi;
  vector<ll> person(N,0);

  for(ll i=0;i<K;i++){
    cin >> d[i];
    for(ll j=0;j<d[i];j++){
      cin >> a;
      okashi.push_back(a);
    }
  }

  for(ll i=0;i<okashi.size();i++){
    person[okashi[i]-1]++;
  }

  for(ll i=0;i<person.size();i++){
    if(person[i] == 0){
      count++;
    }
  }

  cout << count << endl;
}


Measured memory_bytes: 3636
n=gets.chomp.to_i
as=gets.split.map(&:to_i)

bs=Array.new(n, 0)
as.each{|a| bs[a]+=1}
tot=1
(n/2).times{tot=(tot*2)%(1_000_000_000+7)}
if n%2==1 and bs[0]!=1
  puts 0
else
  bs[0]=0
  ok=bs.reduce(true){|r, b| r and (b%2==0)}
  puts (ok ? tot : 0)
end

Measured memory_bytes: 8836
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

typedef long long ll;

ll n, k;
ll a[505];
ll b[505];
ll sum, ans;

void f(ll p)
{
    ll t = 0;
    ll t2 = 0;
    for(ll i = 0; i < n; i++)
    {
        t += a[i] % p;
        b[i] = a[i] % p;
    }
    sort(b, b + n);
    for(ll i = 0; i < n - t / p; i++)
    {
        t2 += b[i];
    }
    if(t2 <= k) ans = max(ans, p);
}

int main()
{
    cin>>n>>k;
    for(ll i = 0; i < n; i++)
    {
        cin>>a[i];
        sum += a[i];
    }
    for(ll i = 1; i * i <= sum; i++)
    {
        if(sum % i == 0) f(i), f(sum / i);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)


const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * g / b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}




const long double PI = 3.14159265359;
const int MAX_N = 100010;


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int h, a; cin >> h >> a;
	cout << (h + a - 1) / a << endl;
	return 0;
}

Measured memory_bytes: 256
roll_dict = dict(E = (3, 1, 0, 5, 4, 2), W = (2, 1, 5, 0, 4, 3), S = (4, 0, 2, 3, 5, 1), N = (1, 5, 2, 3, 0, 4))

dice1 = list(map(int, input().split()))
dice2 = list(map(int, input().split()))

dices = []
dices.append(dice1)
judge = False

for i in "EWSN":
  dice = dices[0]
  new_dice = []
  for j in range(6):
    new_dice.append(dice[ roll_dict[i][j] ])
  dices.append(new_dice)

dice = dices[1]
new_dice = []
for i in range(6):
  new_dice.append(dice[ roll_dict["E"][i] ])
dices.append(new_dice)

for i in range(6):
  if dices[i][0] == dice2[0] and dices[i][5] == dice2[5]:
    str_dice1 = "".join(map(str, dices[i]))
    str_dice2 = "".join(map(str, dice2))

    side1 = str_dice1[1:3]+str_dice1[4]+str_dice1[3]
    side1 += side1
    side2 = str_dice2[1:3]+str_dice2[4]+str_dice2[3]

    judge = side2 in side1

if judge == True:
  print("Yes")
elif judge == False:
  print("No")



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

int main(){
  string S;
  int N;
  cin>>N>>S;
  for(int i=0; i<S.size(); i++){
    if(S.at(i)+N>90){
      S.at(i)=char(S.at(i)+N-90+64);
    }
    else{
      S.at(i)=char(S.at(i)+N);
    }
  }
  cout<<S<<endl;
}

Measured memory_bytes: 3636
# -*- coding: utf-8 -*-
def main():
    A = [list(map(int,input().split())) for i in range(3)]
    N = int(input())
    B = [int(input()) for i in range(N)]
    #print(A,N,B)
    for j in B:
        for k in range(3):
            for l in range(3):
                if j == A[k][l]:
                    A[k][l] = -1
    A1 = A[0]
    A2 = A[1]
    A3 = A[2]
    if A1.count(-1)==3 or A2.count(-1)==3 or A3.count(-1)==3:
        print('Yes')
        return
    for m in range(3):
        if A1[m] ==-1 and A2[m] == -1 and A3[m] == -1:
            print('Yes')
            return
    if A1[0]==-1 and A2[1]==-1 and A3[2]==-1:
        print('Yes')
        return
    if A1[2]==-1 and A2[1]==-1 and A3[0]==-1:
        print('Yes')
        return
    print('No')


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
import java.util.*;

public class Main {
	public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int N = keyboard.nextInt();
		long a1 = keyboard.nextLong();
		long sum = 0;
		
		for(int n=1; n<N; n++) {
			long a = keyboard.nextLong();
			if(a<a1) {
				sum += a1-a;
			}else {
				a1 = a;
			}
		}
		
		System.out.print(sum);
		keyboard.close();
	}
}

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

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

int main() {
    int n;cin>>n;
    int a[n];
    rep(i,n)cin>>a[i];
    sort(a,a+n);
    cout<<a[n-1]-a[0]<<endl;
	return 0;
}

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

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

    int cnt = 0;

    for (int i = A; i <= B; i++)
    {
        if ((i % 10 == (i / 10000) && (i / 10) % 10 == (i / 1000) % 10))
            cnt++;
    }
    cout << cnt << endl;
}


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

int A, B;

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

    int ans = 0;
    for (int i = A; i <= B; i++) {
        string target = to_string(i);
        if (target[0] == target[4] && target[1] == target[3]) ans++; 
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const long long INF = 1e18;
# define len(x) ((int)(x).size())
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define foreps(i, m, n) for(int i = m;i < n;i++)
# define ALL(x) (x).begin(), (x).end()
# define rall(x) (x).rbegin(), (x).rend()
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() {
    ll N; cin >> N;
    map<ll, ll> mp;
    
    rep(i, N) {
        ll x; cin >> x;
        mp[x]++;
    }

    ll ans = 0;
    for (auto itr = mp.begin(); itr != mp.end(); itr++) {
        if (itr->second % 2 != 0) {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 9820
#include <bits/stdc++.h>
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 ALL(n) begin(n),end(n)
#define MOD 1000000007
 
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
void print(int x){printf("%d\n", x);}
void print(ll x){printf("%lld\n", x);}
void printvec(vector<int> a){
rep(i, a.size()-1){
printf("%d ", a[i]);
}
printf("%d\n", a[a.size()-1]);
}
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 n;
    cin >> n;

    vector<vector<int>> G(n);
    vector<int> deg(n, 0);
    int a, b;
    rep(i, n){
        scanf("%d %d", &a, &b);
        --a; --b;
        deg[a]++; deg[b]++;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    vector<bool> ispushed(n, false);
    queue<int> que;

    rep(i, n) if(deg[i]==1) que.push(i);
    while(!que.empty()){
        int e = que.front(); que.pop();
        ispushed[e] = true;
        for(auto to: G[e]){
            deg[to]--;

            if(deg[to]==1) que.push(to);
        }
    }

    int q;
    cin >> q;
    int u, v;
    rep(i, q){
        scanf("%d %d", &u, &v);
        if(!ispushed[u-1] && !ispushed[v-1]) printf("2\n");
        else printf("1\n");
    }
    return 0;
}


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

using namespace std;
typedef long long ll;
#define int ll

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

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
const int MAX_N = 100010;

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

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

    int N, X;
    cin >> N >> X;
    vector<int> pos(N);
    REP(i, N) {
        cin >> pos[i];
        pos[i] = abs(X - pos[i]);
    }
    int ans = pos[0];
    REP(i, N) {
        ans = gcd(ans, pos[i]);
    }
    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod = 1e9+7;

int main(){
    int n;
    cin >> n;
    vector<vector<bool>> shop(n);
    vector<vector<int>> mon(n);
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 10; j++){
            int tmp;
            cin >> tmp;
            shop[i].push_back(tmp);
        }
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 11; j++){
            int p;
            cin >> p;
            mon[i].push_back(p);
        }
    }

    ll sum = -mod;

    for(int bit=1; bit<(1<<10); bit++){
        vector<bool> much(10,false);
        ll can = 0;
        for(int i=0; i<10; i++){
            if(bit&(1<<i)) much[i] = true;
        }
        for(int i = 0; i < n; i++){
            int cnt = 0;
            for(int j = 0; j < 10; j++){
                if(shop[i][j] && much[j]) cnt++;
            }
            can += mon[i][cnt];
        }

        if(sum < can) sum = can; 
    }

    cout << sum << endl;
}

Measured memory_bytes: 256
if __name__ == '__main__':
    nums = [[[0 for r in range(10)] for f in range(3)] for b in range(4)]
    n = int(input())
    for i in range(n):
        b, f, r, v = [int(i) for i in input().split()]
        nums[b-1][f-1][r-1] += v
    for b in range(4):
        for f in range(3):
            print(' ' + ' '.join([str(i) for i in nums[b][f]]))
        if b == 3: break
        print('#'*20)

Measured memory_bytes: 6724
#include<bits/stdc++.h>
#define prArr(Arr,n) for(int _=0;_<n;_++)   cout<<(Arr)[_]<<" ";
using namespace std;
const int INF=(int)1e9+10;
const int MOD=998244353;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    vector<double> v(n);
    for(int i=0;i<n;i++)
        cin>>v[i];
    sort(v.begin(),v.end());
    long double ans=(v[0]+v[1])/2.0;
    for(int i=2;i<n;i++)
        ans=(ans+v[i])/2.0;
    cout<<fixed<<setprecision(10)<<ans;
    return 0;
}



Measured memory_bytes: 256
use std::collections::HashSet;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        a: [usize; n],
    }
    let mut done = HashSet::new();
    let mut next = 0;
    let mut ans = 0;
    while next != 1{
        if done.contains(&next){
            println!("{}", -1);
            return;
        }
        done.insert(next);
        next = a[next] - 1;
        ans += 1;
    }
    println!("{}", ans)
}



Measured memory_bytes: 8444
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using P = pair<int, int>;

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n, c; cin >> n >> c;
  VVI d(c, VI(c));
  for (int i = 0; i < c; i++) {
    for (int j = 0; j < c; j++) {
      cin >> d[i][j];
    }
  }
  VVI grid(n, VI(n));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> grid[i][j];
      grid[i][j]--;
    }
  }
  vector<P> a0, a1, a2;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if ((i + j) % 3 == 0) {
        a0.push_back(P(i, j));
      } else if ((i + j) % 3 == 1) {
        a1.push_back(P(i, j));
      } else {
        a2.push_back(P(i, j));
      }
    }
  }
  VVI iwa(3, VI(c));
  for (int i = 0; i < c; i++) {
    for (auto&& a : a0) {
      iwa[0][i] += d[grid[a.first][a.second]][i];
    }
    for (auto&& a : a1) {
      iwa[1][i] += d[grid[a.first][a.second]][i];
    }
    for (auto&& a : a2) {
      iwa[2][i] += d[grid[a.first][a.second]][i];
    }
  }
  int res = 2e9;
  for (int i = 0; i < c; i++) {
    for (int j = 0; j < c; j++) {
      if (j == i) continue;
      for (int k = 0; k < c; k++) {
        if (k == i or k == j) continue;
        res = min(res, iwa[0][i] + iwa[1][j] + iwa[2][k]);
      }
    }
  }
  cout << res << '\n';
  return 0;
}

Measured memory_bytes: 3700
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    s[--k]+=32;
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define PI acos(-1.0)
#define pb push_back
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=1e5+5;
const int MOD=1e9+7;
template <class T>
bool sf(T &ret){ //Faster Input

    char c; int sgn; T bit=0.1;
    if(c=getchar(),c==EOF) return 0;
    while(c!='-'&&c!='.'&&(c<'0'||c>'9')) c=getchar();
    sgn=(c=='-')?-1:1;
    ret=(c=='-')?0:(c-'0');
    while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0');
    if(c==' '||c=='\n'){ ret*=sgn; return 1; }
    while(c=getchar(),c>='0'&&c<='9') ret+=(c-'0')*bit,bit/=10;
    ret*=sgn;
    return 1;
}

ll a[4];
int main(void){

    for(int i=1;i<=3;i++)   sf(a[i]);
    ll ans=1e18+8;
    do{
        ll res=abs(a[2]-a[3])+abs(a[2]-a[1]);
        ans=min(ans,res);
    }while(next_permutation(a+1,a+1+3));
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
int indg[100005];
queue<int> pos;
int cost[100005];
vector<int> adj[100005];
int topo()
{
	int ret=0;
	while(!pos.empty())
	{
		int u=pos.front();
		pos.pop();
		cost[u]++;
		ret=max(cost[u], ret);
		for(int z=0;z<adj[u].size();z++)
		{
			int v=adj[u][z];
			indg[v]--;
			if(indg[v]==0) pos.push(v);
			cost[v]=max(cost[u], cost[v]);
		}
	}
	return ret;
}
int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	for(int a=0;a<m;a++)
	{
		int l,r;
		scanf("%d%d", &l, &r);
		adj[l].pb(r);
		indg[r]++;
	}
	for(int a=1;a<=n;a++)
	{
		if(indg[a]==0) pos.push(a);
	}
	printf("%d\n", topo()-1);
	return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

const int INF = 1000000000000000;

int calc(int num) {
	int ret = 0;
	while (num) {
		ret += num % 10;
		num /= 10;
	}
	return ret;
}

signed main() {
	int K;
	cin >> K;

	set<int> ret;

	REP(i, 1, 9) ret.insert(i);
	
	int ninelen = 1;
	while (true) {
		REP(base, 1, 200) {
			int num = base;
			rep(i, ninelen) {
				num *= 10;
				num += 9;
				if (num >= INF) break;
			}
			if (num >= INF) break;
			int num2 = base + 1;
			rep(i, ninelen) {
				num2 *= 10;
				num2 += 9;
			}
			double val1 = (double)num / calc(num);
			double val2 = (double)(num2) / calc(num2);
			if (val1 <= val2) {
				ret.insert(num);
			}
		}
		ninelen++;
		if (ninelen == 15) break;
	}

	itrep(it, ret) {
		cout << *it << endl;
		K--;
		if (K == 0) break;
	}

    return 0;
}


Measured memory_bytes: 256
x,y = map(int,input().split())
a = [1,3,5,7,8,10,12]
b = [4,6,9,11]
c = [2]
if a.count(x) == 1 and a.count(y) == 1:
    print("Yes")
elif b.count(x) == 1 and b.count(y) == 1:
    print("Yes")
elif x == 2 and y == 2:
    print("Yes")

else:
    print("No")
    


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

int main(){
  int X,Y;
  cin>>X;
  X=X+3;
  X=X%7;
  switch(X){
    case 0: cout << "mon" << endl;  break;
        case 1: cout << "tue" << endl;  break;
        case 2: cout << "wed" << endl;  break;
        case 3: cout << "thu" << endl;  break;
        case 4: cout << "fri" << endl;  break;
        case 5: cout << "sat" << endl;  break;
        case 6: cout << "sun" << endl;  break;
    }
  }



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

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

  vector<vector<int>> D(N, vector<int>(N, -1));

  rep(i, N) {
    int A; cin >> A;
    rep(k, A) {
      int X, Y; cin >> X >> Y;
      X--;
      D[i][X] = Y;
    }
  }
  int ans = 0;

  for (int bit = 0; bit < (1<<N); bit++) {
    int cnt = 0;
    bool check = true;
    rep(b, N) {
      if (bit & (1 << b)) {
        cnt++;
        rep(i, N) {
          if (D[b][i] == 1) {
            if ((bit & (1 << i)) == 0) check = false;
          }
          if (D[b][i] == 0) {
            if ((bit & (1 << i)) != 0) check = false;
          }
        }
      }
    }
    if (check) ans = max(ans, cnt);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

/**
 * Created by enpingkuang on 2020/9/19 7:52 下午
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String n = scanner.next();
        if(n.endsWith("s")){
            System.out.println(n+"es");
        }else{
            System.out.println(n+"s");
        }
    }
}


Measured memory_bytes: 39032
n,k=map(int,input().split())
ans=0
li=[k]
tmp=k
from math import ceil
for i in range(k):
    tmp/=2
    li.append(ceil(tmp))
    if tmp<1:
        break
# if n>=k:
#     ans+=(n-k+1)
#     n=k-1
now=n
for i,v in enumerate(li):
    if now>=v:
        ans+=(now-v+1)/(2**i)
        now=v-1
print(ans/n)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
using namespace std;
typedef long long ll;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
int W, H, N;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> W >> H >> N;
    vector<int> x(N), y(N);
    for(int i = 0; i < N; i++) cin >> x[i] >> y[i];
    int ans = 0;
    int py = y[0], px = x[0];
    for(int i = 1; i < N; i++)
    {
        if(px == x[i] || py == y[i]) ans += abs(px - x[i]) + abs(py - y[i]);
        else if((py - y[i]) / (double)(px - x[i]) > 0)
        {
            pair<int, int> p = {px, py}, q = {x[i], y[i]};
            if(p > q) swap(p, q);
            int d;
            if(q.second - p.second > q.first - p.first) d = q.first - p.first;
            else d = q.second - p.second;
            q.first -= d;
            q.second -= d;
            ans += d + max(q.first - p.first, q.second - p.second);
        }
        else ans += abs(px - x[i]) + abs(py - y[i]);
        px = x[i];
        py = y[i];
    }
    cout << ans << endl;
    return 0;
}




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

int main()
{
	int n;
	long power = 1;

	cin >> n;

	for (int i = 1; i <= n; ++i)
	{
		power *= i;
		power %= 1000000007;
	}

	cout << power << endl;

	return 0;
}

Measured memory_bytes: 256
import itertools

def main():
    N,M,X = list(map(int, input().split(' ')))
    
    inputs = []
    for _ in range(N):
        inputs.append(list(map(int, input().split(' '))))
        
    Ci = [s[0] for s in inputs]
    Aij = [s[1:] for s in inputs]
    
    # print(Ci, Aij)
    
    indexs = [i for i in range(N)]
    
    com = []
    for n in range(1,N+1):
        com.extend(list(itertools.combinations(
        indexs, n)))
    
    
    minimum = 100000000
    isOK = False
    for inds in com:
        # A,B,C=0,0,0
        # skills = [m for m in range(M)]
        skills = [0 for m in range(M)]
        MONE = 0
        for ind in inds: # (0,1)
            power = Aij[ind]
            skills = [power[i] + skills[i] for i in range(M)]
            MONE += Ci[ind]
        
        skills = [n >= X for n in skills]
        # print(skills, inds, MONE)
        if False not in skills:
            isOK = True
            minimum = min(minimum, MONE)
    
    if isOK is True:
        print(minimum)
    else:
        print('-1')
    
    
            
    

main()

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

using namespace std;

using Elem = pair<int, bool>;

int N, K;

vector<vector<Elem>> W;
vector<bool> ans_ary;

void calc_next(int tgt, int parent, bool odd);

int main()
{
	
	cin >> N;
	W = vector<vector<Elem>>(N+1,vector<Elem>());

	ans_ary = vector<bool>(N + 1,false);
	
	for (int i = 1; i < N; i++) {
		int u, v, w;
		cin >> u;
		cin >> v;
		cin >> w;
		
		bool odd = w % 2;
		W.at(u).push_back(make_pair(v, odd));
		W.at(v).push_back(make_pair(u, odd));
	}

	calc_next(1,0,false);

	for (int i = 1; i <= N; i++) {
		cout << ans_ary.at(i) << endl;
	}

	return 0;
}

void calc_next(int tgt,int parent,bool odd)
{
	ans_ary.at(tgt) = odd;

	for (Elem e : W.at(tgt)) {
		if (e.first != parent) {
			calc_next(e.first, tgt, odd ^ e.second);
		}
	}
}

Measured memory_bytes: 7808
import java.util.*;

/**
 * Created by Santa on 2016/10/16.
 */
public class Main {

    static int N;
    static long A;
    static long B;
    static long C;
    static long[] map;





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

        A = scanner.nextInt();


        if(A > 999){
            System.out.println("ABD");
        }else{
            System.out.println("ABC");
        }


    }



}



Measured memory_bytes: 23252
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>

typedef long long LL;
using namespace std;

const LL N=5e6;
LL a,b;
inline LL gcd(LL x,LL y)
{
	return !y?x:gcd(y,x%y);
}

int main()
{
	scanf("%lld %lld",&a,&b);
	LL p=gcd(a,b);
	LL k=2,ans=0;
	LL o=sqrt(p);
	while(k<=o)
	{
		if(!(p%k))
		{
			ans++;
			while(!(p%k)) p/=k;
			o=sqrt(p);
		}
		k++;
	}
	if(p>1) ans++;
	printf("%lld",ans+1);
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        PriorityQueue<Double> pq = new PriorityQueue<>();
        for(int i = 0; i < n; i++)
        	pq.offer(sc.nextDouble());


        while(pq.size() > 1) {
        	double a = pq.poll();
        	double b = pq.poll();
        	pq.offer((a + b) / 2.0);
        }
        System.out.println(pq.peek());
    }
}


Measured memory_bytes: 23380
# include<iostream>
using namespace std;
long long f(long long x)
{
	if(x==1)
	{
		return 1;
	}
	else
	{
		return 2*f(x/2)+1;
	}
}
int main ()
{
	long long  N;
	cin>>N;
	cout<<f(N)<<endl;
	
}

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

int main(){
    int N,count=0;
    cin >> N ;
    vector<int> p(N);
    vector<int> pt(N);
    for (int i=0;i<N;i++){
        cin >> p.at(i);
        pt.at(i)=p.at(i);
    }
    sort(p.begin(),p.end());
    for (int j=0;j<N;j++){
        if(p.at(j)!=pt.at(j)) count++;
    }
    if(count!=2 && count!=0) cout << "NO" << endl;
    else cout << "YES" << endl;

    return 0;
}


Measured memory_bytes: 256
#pragma region Macros
#include <bits/stdc++.h>
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll;
#pragma endregion

bool kaibun(string str)
{
	int len = sz(str);
	int i = 0;
	while (len / 2 > i)
	{
		if (str[i] != str[len - i - 1])
		{
			return false;
			break ;
		}
		i++;
	}
	return true;
}

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

	string s, ans = "Yes";
	cin >> s;

	if (!kaibun(s))
		ans = "No";

	string temp;
	temp = s.substr(0, sz(s) / 2);

	if (!kaibun(temp))
		ans = "No";

	temp = s.substr((sz(s) + 3) / 2 - 1, sz(s) / 2);

	if (!kaibun(temp))
		ans = "No";

	cout << ans << '\n';
	return 0;
}


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

int main(int argc, const char * argv[]) {
    // insert code here...
    int n,seconds, hours, minutes;
    cin >> n;
    hours = n / 3600;
    minutes = (n % 3600) / 60;
    seconds = n % 60;
    printf("%d:%d:%d\n", hours,minutes,seconds);
    return 0;
}


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

int main(){
#ifdef _DEBUG
	freopen("in" , "r", stdin );
	freopen("out", "w", stdout);
#endif
	ios::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	cout << n * (n + 1) / 2 << ' ';
}


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

using namespace std;

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

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)1e5 + 9;
int a[N];
int b[N];


int main(){
  fastIO;
  int n, m, q;
  cin >> n >> m >> q;
  int ans = (int)1e9;
  for(int i = 0 ; i < n; i ++ )
    cin >> a[i];
  for(int i = 0 ; i < m ; i ++ )
    cin >> b[i];
  int x, y, c;
  for(int i = 0 ; i < q; i ++ ){
    cin >> x >> y >> c;
    --x;
    --y;
    ans = min(ans, a[x] + b[y] - c);
  }
  sort(a, a + n);
  sort(b, b + m);
  ans = min(ans, a[0] + b[0]);
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

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

			int n = sc.nextInt();
			
			int[] cells = new int[n];

			for(int i = 0 ; i < n ; i++ ) {
				cells[i] = sc.nextInt();
			}
			
			int rightHeight = cells[n-1];
			for(int i = 1 ; i < n ; i++ ) {
				//right to left
				int current = cells[n-i-1];
				if ( current == rightHeight ||  current - 1 == rightHeight ) {
					//ok
				}
				else if ( current < rightHeight ) {
					rightHeight = current;
				}
				else {
					System.out.println("No");
					return;
				}
			}
			
			System.out.println("Yes");
		}
	}
}


Measured memory_bytes: 50244
def main():
    n = int(input())
    cnt = [0] * 10001

    for i in range(1,100):
        for j in range(1,100):
            for k in range(1,100):
                v = i*i + j*j + k*k + i*j + j*k + k*i
                if v<=10000:
                    cnt[v] += 1

    for i in range(1, n+1):
        print(cnt[i])

main()

Measured memory_bytes: 9312