akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

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

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

#define VIN(v) for(auto&elem_: (v) )cin>>elem_
#define VOUT(v, sep) for(_loop_int idx=0; idx<(_loop_int)v.size(); idx++) {cout<<v[idx]; if(idx<(_loop_int)v.size()-1) cout<<sep;} cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(debugidx,v.size())cout<<" "<<v[debugidx];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(debugidx,n)cout<<" "<<v[debugidx];cout<<endl

const ll MOD = 1000000007ll;
const int IINF = numeric_limits<int>::max()/2-1;
const ll LINF = numeric_limits<ll>::max()/2-1;

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



int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    string s,t,u;
    int a,b;
    cin>>s>>t;
    cin>>a>>b;
    cin>>u;

    if(s==u){
        a--;
    }else if(t==u){
        b--;
    }
    cout << a <<" "<< b << endl;
    return 0;
}

Measured memory_bytes: 3648
//
//  main.cpp
//  B - fLIP
//
//  Created by wenhan on 2017/9/23.
//  Copyright © 2017年 wenhan. All rights reserved.
//

#include <iostream>
#include <cstdio>
using namespace std;
int main() {
    int a,b,c;
    cin>>a>>b>>c;
    int i;
    for(i=1;i<=a;i++)
        if(c-b*i==0||(a-2*i!=0&&(c-b*i)%(a-2*i)==0&&(c-b*i)/(a-2*i)>0&&(c-b*i)/(a-2*i)<=b))
            break;
    if(i>a)
        printf("No\n");
    else
        printf("Yes\n");
    // insert code here...
    //std::cout << "Hello, World!\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <array>
#include <queue>
#include <string>

using namespace std;
using ll = long long int;
using vec = vector<int>;

#define rep(n) for(int i = 0; i < (n); ++i)
#define Sort(a)    sort(a.begin(), a.end())
#define gSort(a)   sort(a.begin(), a.end(), greater<int>())
const int INF = 2147483647;
const ll  MOD = 1000000007;

int main() {
    string S; cin >> S;

    array<int, 4> direction = {0}; // NSEW

    array<int, 4> ns = {1,1,0,0};
    array<int, 4> we = {0,0,1,1};
    array<int, 4> nsew = {1,1,1,1};
    array<int, 4> not_nsew = {0,0,0,0};

    for(auto i : S) {
        if(i == 'N') direction[0] = 1;
        if(i == 'S') direction[1] = 1;
        if(i == 'E') direction[2] = 1;
        if(i == 'W') direction[3] = 1;
    }
    
    if((direction == ns) || (direction == we) || (direction == nsew) || (direction == not_nsew)) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 256
#ifndef _WIN32
#include<iostream>
#endif // !_WIN32

#include<algorithm>
#include<vector>
#include<string>
#include<iomanip>
#include<map>
using namespace std;
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
int main() {
	int n,p;
	while (cin >> n>>p, n+p) {
		int q = p;
		vector<int> a(n);
		for (int i=0;;(i+=1)%=n) {
			if (p == 0) {
				p = a[i]; a[i] = 0;
			}
			else {
				a[i] ++;
				p--;
				if (a[i] == q) { cout << i << endl; break; }
			}
		}
	}

}

Measured memory_bytes: 2988
#include <stdio.h>
int main(void) 
{
    int a,b,d,r;
    double f;
    
    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&d);
    scanf("%d",&r);
    scanf("%lf",&f);
    
    d=a/b;
    r=a%b;
    f=1.0*a/b;
    
    printf("%d %d %.5f\n",d,r,f);
    
    return 0;    
}



Measured memory_bytes: 2104
N = int(input())
A = list(map(int, input().split()))
A.sort()
MAX = 10**6+1
cnt = [0]*MAX

for x in A:
  if cnt[x] != 0:
  	cnt[x] = 2
  else:
    for i in range(x, MAX, x):
      cnt[i] += 1
  
ans = 0
for x in A:
  # 2回以上通った数字 (cnt[x]>1) は，その数字より小さい約数が存在する (割り切れる他の数が存在する)。
  if cnt[x] == 1:  
    ans += 1
    
print(ans)

Measured memory_bytes: 32168
A = input()
B = input()

def compare(A,B):
    if A == B:
        return 'EQUAL'
    if len(A) > len(B):
        return 'GREATER'
    if len(B) > len(A):
        return 'LESS'
    for i in range(len(A)):
        a = int(A[i])
        b = int(B[i])
        if a > b:
            return 'GREATER'
        if b > a:
            return 'LESS'

print(compare(A,B))

Measured memory_bytes: 3060
# https://atcoder.jp/contests/abc155/tasks/abc155_e
# DPで解き直してみる
# アイデアとしては以下
# F(n)をn円使ったときに使う紙幣の最小と定義
# 例えばF(36)→8,(サンプルの通り)、F(4)→4、F(6)→5
# F(23456)を考える
# F(23456)=min(F(2345)+6, F(2346)+4) となる
# ∵6をそのまま払うなら、桁上りは必要ないので2345を払う最小F(2345)を足せば良い。
# お釣り狙いならばとりあえず、10 - 6のお釣りの分をカウント。そして上位桁で多く払う分2346の最小F(2346)を足せば良い。

# ナイーブな実装

'''
def F(n: int):
    if n < 5:
        # 終了条件
        return n
    a, b = divmod(n, 10)
    ret = min(F(a) + b, F(a + 1) + (10 - b))
    # print(n, ret)
    return ret


print(F(int(input())))
'''
# しかしこれには不適切な実装が含まれている
# 1、再帰の深さが最大100000になる。再帰メモ化でもハッシュの衝突が起きたりして遅くなる可能性がある
# 2、int型を前提にした実装なので、10^100000の大きさの数字を扱おうとするとかなり遅くなる。
# よって上記の再帰関数をdpの形で書き直し、且つ文字列で扱える処理に変更する必要がある。


N = input()
# Nの先頭に0がついているとみたてて
dp0 = 0  # 桁上がりしない
dp1 = 1  # 桁上りするときに必要な紙幣の枚数

for n in N:
    n = int(n)
    dp0_new = min(dp0 + n, dp1 + (10 - n))
    n = n + 1
    dp1_new = min(dp0 + n, dp1 + (10 - n))
    dp0, dp1 = dp0_new, dp1_new

print(dp0)

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

int main() {
  int A, B, count;
  cin >> A >> B;
  count = 0;
  
  for (int i = A; i <= B; i++) {      
    if (i / 10000 == i % 10 && (i / 1000) % 10 == (i / 10) % 10)
      count++;
  }

  cout << count << endl;
}

Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr = input.trim().split("\n");
while (true) {
   var tdl = arr[0];
   if (tdl == "0 0 0") break;
   var [t,d,l]=tdl.split(" ").map(Number);
   var cnt=0;
   var time=0;
   for(var i=0;i<t;i++){
      if(time!=0)cnt++;
      if(time>0)time--;
      var x=arr[i+1]-0;
      if(x>=l)time=d;
   }
   console.log(cnt);
   arr=arr.slice(t+1);
}


Measured memory_bytes: 194208
#include<cstdio>
typedef long long LL;
const int N=1e5+8;
int A[N],op[N],n,nxt[N],nx;
LL ans,now,suf[N];char s[4];
int main(){
	scanf("%d%d",&n,A+1),ans=A[1];
	for(int i=2;i<=n;++i)scanf("%s%d",s,A+i),ans+=A[i]*((op[i]=*s=='-')?-1:1);
	for(int i=n;i;--i){
		suf[i]=suf[i+1]+A[i];
		if(op[i])nxt[i]=nx,nx=i;
	}
	now=A[1];
	for(int i=2;i<=n;++i){
		if(op[i]&&nxt[i]){
			LL nw=now-suf[i]+2*suf[nxt[i]];
			if(nw>ans)ans=nw;
		}
		now+=A[i]*(op[i]?-1:1);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2176
#include<stdio.h>

int main(void)
{

    int a,b,c;
    int count = 0;
    int i;

    scanf("%d %d %d",&a,&b,&c);

    for(i = a;i <= b;i++)
      if(c % i == 0)
        count++;

    printf("%d\n",count);

    return 0;
}


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

int main (void){
  char a;


  cin >> a;
  for(int i = 65; i <= 90;i++){
    if(a == i){
      cout << 'A' << endl;
      return 0;
    }
  }
  cout << 'a' << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <stdlib.h>

enum { R, U, L, D };

int map[5][5][4] = { 0 };
int x = 0, y = 0, dir = R;

void scan();
void print();
void calc();
int calcDir();

int main() {
  scan();
  //print();
  calc();
  return 0;
}

int calcDir() {
  int i;
  if (map[y][x][dir] && !map[y][x][(dir + 5) % 4]) return dir;
  if (map[y][x][(dir + 3) % 4]
      && !map[y][x][dir]
      && !map[y][x][(dir + 5) % 4]) return (dir + 3) % 4;
  if (map[y][x][(dir + 5) % 4]) return (dir + 5) % 4;
  return (dir + 6) % 4;
  /*
  for (i = 0; i < 4; i++) {
    //printf("%d, %d, %d\n", x, y, (dir+5-i)%4);
    if (map[y][x][(dir + 4 - i) % 4]) {
      if (map[y][x][(dir + 6 - i) % 4]) continue;
      return (dir + 4 - i) % 4;
    }
  }
  return -1;
  */
}

void calc() {
  char c;
  do {
    dir = calcDir();
    switch (dir) {
      case R:
	c = 'R';
	x++;
	break;
      case U:
	c = 'U';
	y--;
	break;
      case L:
	c = 'L';
	x--;
	break;
      case D:
	c = 'D';
	y++;
	break;
      default:
	puts("error");
	exit(1);
	break;
    }
    putchar(c);
  } while (x != 0 || y != 0);
  puts("");
}

void scanEven(int n) {
  int i = 0;
  for (i = 0; i < 4; i++) {
    int w = (getchar() == '1') ? 1 : 0;
    map[n][i][R] = w;
    map[n][i+1][L] = w;
  }
  getchar();
}

void scanOd(int n) {
  int i = 0;
  for (i = 0; i < 5; i++) {
    int w = (getchar() == '1') ? 1 : 0;
    map[n][i][D] = w;
    map[n+1][i][U] = w;
  }
  getchar();
}

void scan() {
  int i = 0;
  for (i = 0; i < 4; i++) {
       scanEven(i);
       scanOd(i);
  }
  scanEven(i);
}

void print() {
  int i, j, k;
  for (i = 0; i < 5; i++) {
    for (j = 0; j < 5; j++) {
      for (k = 0; k < 4; k++) {
	printf("%c%d", k?',':'{', map[i][j][k]);
      }
      printf("} ");
    }
    puts("");
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

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

using namespace std;
using namespace __gnu_pbds; // gp_hash_table<int, int> table;

template <typename T> void smin(T &a, const T &b) { a = (a < b ? a : b); }
template <typename T> void smax(T &a, const T &b) { a = (a > b ? a : b); }

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;

const int N = 1010;

vector <int> g[N];
int used[N];


vector <int> st;
bool dfs1(int u, vector <int> &ans)
{
  st.push_back(u);
  used[u] = 1;
  for (int v : g[u])
  {
    if (used[v] == 1)
    {
      while (st.back() != v)
      {
        ans.push_back(st.back());
        st.pop_back();
      }
      ans.push_back(st.back());
      return 1;
    }
    if (!used[v] && dfs1(v, ans))
      return 1;
  }
  used[u] = 2;
  st.pop_back();
  return 0;
}

signed main()
{
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector <pair <int, int>> es;
  for (int i = 0; i < m; i++)
  {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    es.push_back({u, v});
  }

  vector <int> ans;

  for (int i = 1; i <= n; i++)
    if (dfs1(i, ans))
      break;
  reverse(all(ans));

  if (ans.empty())
    return cout << -1, 0;

  for (auto e : es)
  {
    int pos1 = -1, pos2 = -1;
    for (int i = 0; i < ans.size(); i++)
    {
      if (ans[i] == e.first)
        pos1 = i;
      else if (ans[i] == e.second)
        pos2 = i;
    }
    if (pos1 == -1 || pos2 == -1)
      continue;
    vector <int> tmp;
    if (pos1 < pos2)
    {
      for (int i = pos2; i != pos1; i = (i + 1) % ans.size())
        tmp.push_back(ans[i]);
      tmp.push_back(ans[pos1]);
    }
    else
    {
      for (int i = pos2; i <= pos1; i++)
        tmp.push_back(ans[i]);
    }
    ans = tmp;
  }

  cout << ans.size() << "\n";
  for (int i : ans)
    cout << i << "\n";

  return 0;
}

Measured memory_bytes: 384
import itertools
import math
x = int(input())

remain = x % 100
quotient = math.floor(x/100)

items = [100, 101, 102, 103, 104, 105]
n = 6

for moneys in itertools.combinations_with_replacement(items, quotient):
    if sum(moneys) == x:
        print(1)
        exit()
print(0)


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

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

	
	int b1, b2, b3;
	cin >> b1 >> b2 >> b3;

	if((b1 && b2 && !b3) || (!b1 && !b2 && b3)){
		cout << "Open" << endl;
	}
	else {
		cout << "Close" << endl;
	}

	return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin>>n;
    ll temp1=n/500;
    ll temp2=(n-500*temp1)/5;
    ll ans=1000*temp1+5*temp2;
    cout<<ans<<endl;
	
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
using namespace std;


int main(){
  int a, b, c;
  cin >> a >> b;
  cout << a / b << endl;
  cout << a % b << endl;
  cout << fixed << setprecision(10)<< (double)a / b << endl;
  return 0;
}

Measured memory_bytes: 1240
N, D = gets.chomp.split.map(&:to_i)
X = N.times.map{gets.chomp.split.map(&:to_i)}

p X.combination(2).count{|a, b|
    d = (0...D).inject(0){|sum, i| sum += (a[i] - b[i]) ** 2} ** 0.5
    d == d.round
}

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

using ll=int64_t;

ll keta(ll x) {
  ll ret_val=0;
  while (0<x) {
    x/=10;
    ret_val++;
  }
  return ret_val;
}

int main(){
  ll N; cin >>N;
  ll ans=keta(N);
  for (ll A=1;A*A<=N;A++) {
    if (!(N%A)) {
      ll B=N/A;
      ll check=max(keta(A),keta(B));
      if (check<ans) ans=check;
    }
  }
  cout <<ans <<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
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 int inf = 1001001001;
const ll linf = 1001001001001001001;

vector<vi> tree;
vi x;
vi inv_x;

void dfs(int n = 0) {
    vector<vi> dp(tree[n].size()+1,vi(x[n]+1,inf));
    dp[0][0] = 0;
    rep(i,tree[n].size()) {
//        rep(j,5) cout << dp[1][j] << " ";
//        cout << endl;
        dfs(tree[n][i]);
        int now = x[tree[n][i]];
//        cout << now << endl;
        rep(j,x[n]+1) {
            if(j >= now) {
                chmin(dp[i+1][j],dp[i][j-now]+inv_x[tree[n][i]]);
//                cout << i << " " << j << " " << dp[i+1][j] << " " <<  dp[i][j-now]+inv_x[tree[n][i]] << endl;
            }
        }
        now = inv_x[tree[n][i]];
//        cout << now << endl;
        rep(j,x[n]+1) {
            if(j >= now) {
                chmin(dp[i+1][j],dp[i][j-now]+x[tree[n][i]]);
//                cout << "#" << i << " " << j << " " << dp[i+1][j] << " " <<  dp[i][j-now]+inv_x[tree[n][i]] << endl;
            }
        }
//        rep(j,5) cout << dp[1][j] << " ";
//        cout << endl;
    }
//    if(n == 0) {
//        rep(i,tree[n].size()+1) {
//            rep(j,x[n]+1) cout << dp[i][j] << " ";
//            cout << endl;
//        }
//    }
    rep(i,x[n]+1) {
        chmin(inv_x[n],dp[tree[n].size()][i]);
    }
    if(inv_x[n] == inf) {
        cout << "IMPOSSIBLE" << endl;
//        cout << n << endl;
        exit(0);
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    tree.resize(n);
    rep(i,n-1) {
        int p;
        cin >> p;
        p--;
        tree[p].pb(i+1);
    }
    x.resize(n);
    rep(i,n) cin >> x[i];
    inv_x.resize(n);
    rep(i,n) inv_x[i] = inf;
    dfs();
    cout << "POSSIBLE" << endl;
}


Measured memory_bytes: 13296
#include <bits/stdc++.h> //万能头文件！！
using namespace std;
int main()
{
    double w,h,x,y;
    cin>>w>>h>>x>>y;
    cout<<fixed<<setprecision(6)<<w*h/2<<" ";
    if (x==w/2.0&&y==h/2.0) cout<<1;
    else cout<<0;
    return 0;//别忘了！千万别功亏一篑呀~
}

Measured memory_bytes: 256
l, r = map(int, input().split())

mod = 2018

if r - l >= 2019:
    print(0)
else:
    for i in range(l, r):
        for j in range(i+1, r+1):
            tmp = i * j % 2019
            if tmp < mod:
                mod = tmp
    print(mod)

Measured memory_bytes: 3060
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main (void) {

    const unsigned int thisYear = 1000;

    const unsigned int bigm = 20;
    const unsigned int smallm = 19;
    const unsigned int size_y = 10;

    unsigned int n;
    unsigned int sum;
    int y, m, d;

    cin >> n;

    while(n-- > 0) {
        cin >> y >> m >> d;

        sum = 0;
        unsigned int left_d = (m % 2 != 0 || y % 3 == 0) ? (bigm - d) : (smallm - d);
        unsigned int left_m = (size_y - m);

        if (y % 3 == 0) {
            sum += left_d + left_m * bigm;
        } else {
            unsigned int odd_m;
            unsigned int even_m;

            odd_m = floor(left_m / 2.0);
            even_m = (left_m % 2 == 0) ? floor(left_m / 2.0) : ceil(left_m / 2.0);
            sum += left_d + even_m * 19 + odd_m * 20;
        }

        for (int i = y+1; i < thisYear; i++)
            sum += (i % 3 == 0) ? 20 * 10 : 20 * 5 + 19 * 5;

        sum += 1;

        cout << sum << endl;
    }

    return 0;
}

Measured memory_bytes: 1168
#include<iostream>
#include<bits/stdc++.h>
#define MOD 1000000007
#define ll long long int
using namespace std;
int countSetBits(ll n) 
{ 
unsigned int count = 0; 
while (n) 
{ 
    count += n & 1; 
    n >>= 1; 
} 
return count; 
} 
int main(){
    int n;
    cin>>n;
    vector<vector<int>> vec(n,vector<int>(n));
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
                cin>>vec[i][j];
        }
    }
    vector<ll> dp(pow(2,n),0);
    dp[0] = 1;
    for(ll mask=0;mask<pow(2,n);mask++){
       // bitset<n> b1(mask);
        int k = countSetBits(mask);
        for(int i=0;i<n;i++){
            //cout<<(mask&(1<<i))<<" "<<vec[k][i]<<" ";
            if(((mask&(1<<i))==0)&&(vec[k][i])){
                //cout<<"*";
                dp[mask|(1<<i)] = (dp[mask|(1<<i)] + dp[mask] )%MOD; 
            }
        }
    }
    cout<<dp[pow(2,n)-1];
}



Measured memory_bytes: 16640
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;cin>>N;
  int K;cin>>K;
  int ans = 0;
  repeat(i,N){
    int x;cin>>x;
    ans += 2*min(x,K-x);
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

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

int main(int argc, char const *argv[]) {
	int d, goal;
	std::cin >> d >> goal;
	std::vector<int> p(d) , c(d);
	int x = 1;
	for (size_t i = 0; i < d; i++) {
		std::cin >> p[i] >> c[i];
		x *= (i+1);
	}

	std::vector<std::vector<int>> v;
	std::vector<int> s(d);
	iota(s.begin() , s.end() , 0);
	do {
		v.push_back(s);
	} while(next_permutation(s.begin(), s.end()));

	int ans = INT_MAX / 2;
	for (size_t i = 0; i < v.size(); i++) {
		int kari = 0;
		int zan = goal;
		for (size_t j = 0; j < v[i].size(); j++) {
			if (zan <= 0) {
				break;
			}
			if (zan <= (v[i][j]+1) * 100 * p[v[i][j]]) {
				kari = kari + (zan / ((v[i][j]+1) * 100)) + !!(zan % ((v[i][j]+1) * 100));
				break;
			}
			kari += p[v[i][j]];
			zan = zan - (v[i][j]+1) * 100 * p[v[i][j]] - c[v[i][j]];
		}
		ans = min(ans, kari);
	}

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


Measured memory_bytes: 257180
n, c = map(int, input().split())
program = [list(map(int, input().split())) for _ in range(n)]

table = [[0 for _ in range(c)] for _ in range(10 ** 5)]

for p in program:
	for i in range(p[0] - 1, p[1]):
		table[i][p[2]-1] = 1

ans = 1

for i in range(10 ** 5):
	s = sum(table[i])
	if ans < s:
		ans = s

print(ans)

Measured memory_bytes: 104152
# coding=utf-8

# write code...
import math

a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
List1=[a,b,c,d,e]
List2=[(a-1)%10,(b-1)%10,(c-1)%10,(d-1)%10,(e-1)%10]

# List.index()で()内の値を探す。↓の場合最小値を含むリストのインデックスを探索
index=List2.index(min(List2))

# math.ceil切り上げ。全部切り上げて、一番待ち時間が長いものだけを引いて
ans = math.ceil(a/10)+math.ceil(b/10)+math.ceil(c/10)+math.ceil(d/10)+math.ceil(e/10)-math.ceil(List1[index]/10)+List1[index]/10
ans = int(ans*10)

print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,d;
	cin>>n>>d;
	int ans = 0;
	while (n--){
		double x,y;
		cin>>x>>y;
		double sq_x = x*x;
		double sq_y = y*y;
		double res = sqrt(sq_x + sq_y);
		if (res <= d){
			++ans;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3752
#include<stdio.h>
int main(void){
int a,b,c,d;
scanf("%d",&a);

b = a / 3600 ;
c = ( a % 3600)/60 ;
d = (a % 3600) % 60;

printf("%d:%d:%d\n",b,c,d);

return 0 ;
}



Measured memory_bytes: 2076
#include <bits/stdc++.h>                                             
using namespace std;                                                 
                                                                     
int main(void){                                                      
  int x, y, s;                                                       
  while(cin >> x >> y >> s, x | y | s){                              
    int ans = 0;                                                     
    for(int i=1; i < s; i++){                                        
      for(int j=i; j < s; j++){                                      
        if(int(i * (100+x)/100) + int(j * (100+x)/100) == s)         
          ans = max(ans, int(i * (100+y)/100 + j * (100+y)/100));    
        if(int(i * (100+x)/100) + int(j * (100+x)/100) > s)          
          break;                                                     
      }                                                              
    }                                                                
    cout << ans << endl;                                             
  }                                                                  
  return 0;                                                          
}                                                                    

Measured memory_bytes: 1160
#include<cstdio>
#define ll long long
using namespace std;
int n,k,a[200005],b[200005];
int check(int mid){
	ll t=0;
	for(int i=1;i<=n;i++){
		int x=a[i];
		t+=(x-1)/mid;
	}
	return t<=k;
}
int main(){
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	int l=1,r=1e9;
	while (l<r){
		int mid=(l+r)>>1;
		if (check(mid)) r=mid;
		else l=mid+1;
	}
	printf("%d\n",l);
	return 0;
}

Measured memory_bytes: 3996
#include<stdio.h>
#include<string.h>
int main(void)
{
	int i,j,k=0,n,m[30];
	char s[30],t[30]={'a','b','c','d','e','f','g','h','i','j','k','l','m',
					  'n','o','p','q','r','s','t','u','v','w','x','y','z'};
	scanf("%s",s);
	n=strlen(s);
	for(i=0;i<26;i++) m[i]=0;
	for(i=0;i<n;i++){
		for(j=0;j<26;j++){
			if(s[i]==t[j]) m[j]++;
		}
	}
	for(i=0;i<26;i++){
		if(m[i]>=2) k=1; 
	}
	if(k==1) printf("no\n");
	else  printf("yes\n");
	return 0;
}
	

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

int main(){
  string s;
  cin >> s;
  for(int i = 0; i < s.length(); i+=2){
    cout << s[i];
  }
  cout << endl;
}


Measured memory_bytes: 512
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
    int m[1000];
int main(){
    int a;
    int n;
    cin>>a>>n;
    for (int i=1;i<=a;i++)
        cin>>m[i];
    for (int i=1;i<=a;i++)
        n-=m[i];
    sort(m,m+a+1);
    a+=n/m[1];
    cout<<a<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using u32 = uint32_t;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define REP(i,n) for(auto i = 0 * (n), i##_len = (n); i < i##_len; ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,n) for(ll i=s, i##_len=(ll)(n); i<i##_len; ++i)
#define TEN(x) ((ll)1e##x)
const ll mod = TEN(9) + 7;

int main() {
#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);
	string s; cin >> s;
	ll cnt = 0;
	FOR(i, 1, s.size()) if (s[i] != s[i - 1]) cnt++;
	cout << cnt << endl;

	return 0;
}

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

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> Vector;
typedef vector<vector<ll> > DVector;

#define fi          first
#define se          second
#define pb          push_back
#define INF         INT_MAX/3
#define bcnt        __builtin_popcount
#define all(x)      (x).begin(),(x).end()
#define dbg(x)      cout<<#x"="<<x<<endl
#define ub(x,y)     upper_bound(all(x),y)-x.begin()
#define lb(x,y)     lower_bound(all(x),y)-x.begin()
#define uni(x)      x.erase(unique(all(x)),x.end())
#define rep(i,n)    repl(i,0,n-1)
#define repl(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);i++)
#define mmax(x,y)   (x>y?x:y)
#define mmin(x,y)   (x<y?x:y)
#define maxch(x,y)  x=mmax(x,y)
#define minch(x,y)  x=mmin(x,y)
#define exist(x,y)  (find(all(x),y)!=x.end())
#define each(itr,v) for(auto itr:v)
#define usort(x)    sort(all(x))
#define dsort(x)    sort(all(x),greater<int>())
#define mkp(x,y)    make_pair(x,y)

void print_vector(Vector a){
 cout << a[0];
 repl(i, 1, a.size()-1) cout << ' ' << a[i];
 cout << endl;
}

void selectionSort(Vector a){
  int count=0;
  rep(i,a.size()){
    int minj = i;
    repl(j, i, a.size()-1)if(a[j] < a[minj])minj = j;
    swap(a[i],a[minj]);
    if(i!=minj)count++;
  }
  print_vector(a);
  cout << count << endl;
}

int main(){
  cin.sync_with_stdio(false);
  int n;
  cin >> n;
  Vector a(n);
  rep(i,n)cin >> a[i];
  selectionSort(a);
}

Measured memory_bytes: 3156
#include<iostream>
#include<vector>
#include<set>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<map>
#include<queue>
#include<iomanip>
#include<numeric>
#define INF 1e9
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using namespace std;
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; }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  return s;
}

template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
  s << vv[i] << endl;
  }
  return s;
}


int calc(ll v){
    int ret = 0;
    while(1){
      if(v % 2 != 0){
        break;
      }
      v = v/2;
      ret++;
    }
    return ret;
}
int N;
signed main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  cin >> N;
  int ret = 0;
  rep(i,N){
    ll v;
    cin >> v;
    ret += calc(v);
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
//all possible//
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long a,b;
	cin>>a>>b;
	if(a==0 && b==0)
	{
	    cout<<"Impossible";
	    return 0;
	}
	if((a+b)%3==0 || a%3==0 || b%3==0)
	cout<<"Possible";
	else
	cout<<"Impossible";
	
	

}


Measured memory_bytes: 256
H, W, A, B = map(int, input().split())
mod = 10**9+7

F = [1]*200010
p = 1
for i in range(1, len(F)):
  F[i] = p = p*i%mod

def comb(n, k):
  return F[n]*pow(F[n-k], mod-2, mod)*pow(F[k], mod-2, mod)%mod

ans = 0
for h in range(H-A):
  x = comb(B-1+h, h) # 右にB-1回、下にh回移動する方法の数
  y = comb(W+H-B-h-2, H-h-1) # 右にW-B-1回、下にH-h-1回移動する方法の数
  ans += x*y
  ans %= mod
print(ans)

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

int main() {
  int n, k, q;
  cin >> n >> k >> q;
  vector<int> ans_count(n, 0);
  for (int i = 0; i < q; i++) {
    int a;
    cin >> a;
    a--;
    ans_count[a]++;
  }
  for (int i=0;i<n;i++){
    if (k-(q-ans_count[i])<=0){
      cout << "No" << endl;
    } else {
      cout << "Yes" << endl;
    }
  }
}


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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
const ll INF = 1001001001;
const int mod = 1000000007;

int main() {
    ll w, h, x, y;
    cin >> w >> h >> x >> y;

    double ans = (double) w * h / 2;

    if (x * 2 == w && y * 2 == h) {
        cout << ans << ' ' << 1 << endl;
    } else {
        cout << ans << ' ' << 0 << endl;

    }

}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  double xa1,ya1,xa2,ya2,xb1,yb1,xb2,yb2;
  while(scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&xa1,&ya1,&xa2,&ya2,&xb1,&yb1,&xb2,&yb2)!=EOF){
    if(  (yb1<=ya2)&&(ya1<=yb2)&&(xb1<=xa2)&&(xa1<=xb2) )
      puts("YES");
    else
      puts("NO");
  }
  return 0;
}

Measured memory_bytes: 612
import sys
from bisect import bisect_left,bisect_right,insort
#input = sys.stdin.readline

def main():
    s=list(input())
    a,b=0,0
    x,y=0,0
    for i in range(len(s)):
        if i%2==0:
            a+=int(s[i])
            x+=1
        else:
            b+=int(s[i])
            y+=1
    print(min(x-a+b,y-b+a))
           

if __name__ == '__main__':
    main()

Measured memory_bytes: 3956
#include<bits/stdc++.h>  
#include <cstdio>  
#include <iostream>  
#include <cstring>  
#include <map>  
#include <set>  
#include <bitset>  
#include <cctype>  
#include <cstdlib>  
#include <queue>  
#include <cmath>  
#include <stack>  
#include <ctime>  
#include <string>  
#include <vector>  
#include <sstream>  
#include <functional>  
#include <algorithm>  
using namespace std;  
  
#define mem(a,n) memset(a,n,sizeof(a))  
#define memc(a,b) memcpy(a,b,sizeof(b))  
#define rep(i,a,n) for(int i=a;i<n;i++) ///[a,n)  
#define dec(i,n,a) for(int i=n;i>=a;i--)///[n,a]  
#define pb push_back  
#define fi first  
#define se second  
#define IO ios::sync_with_stdio(false)  
#define fre freopen("in.txt","r",stdin)  
#define lson l,m,rt<<1  
#define rson m+1,r,rt<<1|1  
typedef long long ll;  
typedef unsigned long long ull;  
const double PI = acos(-1.0);  
const double e = 2.718281828459045;  
const double eps = 1e-8;  
const int INF = 0x3f3f3f3f;  
const int MOD = 258280327;  
const int N = 1e3 + 5;  
const ll maxn = 5e4;  
const int dir[4][2] = { -1,0,1,0,0,-1,0,1 };  
int n, m;  
bool vis[N];  
int match[N];  
bool a[N][N];  
int dfs(int x)  
{  
    for (int y = 1; y <= n; y++)  
    {  
        if (!vis[y] && a[x][y])  
        {  
            vis[y] = 1;  
            if (match[y] < 0 || dfs(match[y]))  
            {  
                match[y] = x;  
                return true;  
            }  
        }  
    }  
    return false;  
}  
  
    int solve()  
    {  
        int ans = 0;  
        memset(match, -1, sizeof(match));  
        for (int i = 1; i <= n; i++)  
        {  
            mem(vis, 0);  
            if (dfs(i))ans++;  
        }  
        return ans;  
    }  
  
int main()  
{  
    IO;  
  
    cin >> n;  
    int t1[n + 1];  
    int t2[n + 1];  
    int t3[n+1];  
    int t4[n+1];  
    for (int i = 1; i <= n; i++)  
    {  
        cin >> t1[i];  
        cin >> t2[i];  
    }  
    for (int i = 1; i <= n; i++)  
    {  
        cin >> t3[i];  
        cin >> t4[i];  
    }  
  
        memset(a, 0, sizeof(a));  
        for (int i = 1; i <= n; i++)  
            for(int j=1;j<=n;j++)  
        {  
            if(t1[i]<t3[j]&&t2[i]<t4[j])  
                {  
                    a[i][j] = 1;  
            }  
        }  
  
  
    cout << solve() << endl;  
    return 0;  
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define N 55
using namespace std;
int n;
int p[N];
int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&p[i]);
	if(is_sorted(p+1,p+1+n)) {
		printf("YES\n");
		exit(0);
	}
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++) {
			swap(p[i],p[j]);
			if(is_sorted(p+1,p+1+n)) {
				printf("YES\n");
				exit(0);
			}
			swap(p[i],p[j]);
		}
	printf("NO\n");
	return 0;
}

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

int main(){

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

    int ans = 10000;
    for(int i = 0; i < n; i++){

        int cnt = 0;
        while(a[i] % 2 == 0){
            cnt++;
            a[i] /= 2;
        }

        ans = min(ans, cnt);
    }

    cout << ans << endl;

    return 0;
}

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

#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#include <math.h>

int main() {

    long long int a;
    cin >> a;
    long double b;
    cin >> b;

    long long int bb = ( b + 0.001 ) * 100;

    cout << a * bb / 100 << endl;

    return 0;

}


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

int main(){
    int n, x, coo, count;
    cin >> n >> x;
    coo = 0;
    count = 1;

    for(int i = 0; i < n; i++){
        int l;
        cin >> l;
        coo += l;
        if(coo <= x){
            count += 1;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 888
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }
const int MAX = 1100000;
const int MOD = 998244353;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(ll n, ll k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll myPow(ll x, ll n, ll m) {
    if (n == 0)
        return 1;
    if (n % 2 == 0)
        return myPow(x * x % m, n / 2, m);
    else
        return x * myPow(x, n - 1, m) % m;
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    vll D(N);
    rep(i, N) cin >> D[i];
    if (D[0] != 0) {
        cout << 0 << endl;
        return 0;
    }
    ll m = 998244353;

    ll maxD = *max_element(D.begin(), D.end());
    unordered_map<int, int> cnt;
    REP(i, 1, N) {
        cnt[D[i]]++;
    }
    if (cnt[0] > 0) {
        cout << 0 << endl;
        return 0;
    }

    ll ans = 1;

    REP(i,1, maxD) {
        ans *= myPow(cnt[i], cnt[i + 1], m);
        ans %= m;
    }

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

Measured memory_bytes: 5156
# AtCoder Beginner Contest 042
# A - 和風いろはちゃんイージー / Iroha and Haiku (ABC Edition)
l = input().split()
count_5 = 0
count_7 = 0
for i in range(3):
    if int(l[i]) == 5:
        count_5 = count_5 + 1
    elif int(l[i]) == 7:
        count_7 = count_7 + 1
if count_5 == 2 and count_7 == 1:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 2940
"use strict";
// inputに入力データ全体が入る
const main = (input) => {
  const arr = ["ABC"];
  arr.push(input);
  return arr.join("");
};

// ※この行以降は編集しない (標準入力から一度に読み込みMainを呼び出します)
console.log(main(require("fs").readFileSync("/dev/stdin", "utf8")));


Measured memory_bytes: 29544
#include<stdio.h>

int main()
{
	long N,K;
	long sum = 0;
	scanf("%ld %ld", &N, &K);

	for (int i = K; i <= N + 1; i++) {
			sum += (N - i + 1) * i + 1;
			sum %= 1000000007;
	}

	printf("%ld", sum);
	return 0;
}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
inline long long getnum()
{
		long long now=0;long long fh=1;char ch=getchar();
		while(ch<'0' || ch>'9'){if(ch=='-')fh=-1;ch=getchar();}
		while(ch>='0' && ch<='9'){now=(now<<3)+(now<<1)+ch-'0';ch=getchar();}
		return now*fh;
}
int r[100003],mx[100003],mn[100003],ans,n,q,k,x,ans0[100003],ansx[100003],f,t;
int ai,ti;
int qz[100003];
int find(int t)//correct
{
	int bl=0;
	int br=k+1;
	int mid;
	while (br-bl>1)
	{
		mid=(bl+br)>>1;
		if (r[mid]>t)	br=mid;else bl=mid;

	}
	return bl;
}
int main()
{
	x=getnum();
	k=getnum();
	for (int i=1;i<=k;i++)
	{
		r[i]=getnum();
	}
	q=getnum();
	f=-1;
	ansx[0]=x;
	mx[0]=x;
	for (int i=1;i<=k;i++)
	{
		ans0[i]=ans0[i-1]+f*(r[i]-r[i-1]);
		ans0[i]=max(ans0[i],0);
		ans0[i]=min(ans0[i],x);

		ansx[i]=ansx[i-1]+f*(r[i]-r[i-1]);
		ansx[i]=max(ansx[i],0);
		ansx[i]=min(ansx[i],x);

		qz[i]=qz[i-1]+f*(r[i]-r[i-1]);

		f=-f;
	}
	f=-1;
	for (int i=1;i<=k;i++)
	{
		t+=f*(r[i]-r[i-1]);
		mn[i]=max(mn[i-1],-t);
		mx[i]=min(mx[i-1],x-t);
		f=-f;
		//printf("%d  %d %d\n",t,mn[i],mx[i]);
	}
	while(q--)
	{
	  ti=getnum();
	  ai=getnum();
	  int la=find(ti);
	  int ans;
	  if (mn[la]<=ai&&mx[la]>=ai)
	  	ans=ai+qz[la]+((la%2)*2-1)*(ti-r[la]);//la%2==1:+  ==0:-
	  else
	  	if (mn[la]>ai)
	  		ans=ans0[la]+((la%2)*2-1)*(ti-r[la]);
	  	else
	  		ans=ansx[la]+((la%2)*2-1)*(ti-r[la]);
	  ans=max(ans,0);
		ans=min(ans,x);
	  printf("%d\n", ans);
	}

}


Measured memory_bytes: 3584
#include<stdio.h>

int main(){
    int a,b,c;
    scanf("%d %d",&a,&b);
    int h1=a+b,h2=a-b,h3=a*b;

    if (h1>=h2 && h1>h3) printf("%d\n",h1);
    else if(h2>=h1 && h2>h3) printf("%d\n",h2);
    else printf("%d\n",h3);

    return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <algorithm>
#include <cctype>
#include <cmath>
using namespace std;
typedef long long int64;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
int64 a, b, c, d, e;
int64 ans;
int main()
{
    a = read(), ans = read(), c = read(), d = read(), e = read();
    if(!a||!d||!e) ans += a/2*2+d/2*2+e/2*2;
    else ans += a+d+e-(a%2 != d%2||a%2 != e%2);
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX = 200000;

int main(){
  int n;
  int R[MAX];

  cin >> n;
  for (int i = 0; i < n; i++) cin >> R[i];

  int maxv = -2000000000;
  int minv = R[0];

  for (int i = 1; i < n; i++){
    maxv = max(maxv, R[i] - minv);
    minv = min(minv, R[i]);
  }

  cout << maxv << endl;

  return 0;

}

Measured memory_bytes: 3848
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 arr[] = new int[n+1];
        for(int i=1;i<=n;i++){
            arr[i] = sc.nextInt();
        }

        int dp[] = new int[n+1];
        dp[1] = 0;
        
        for(int i=2;i<=n;i++){
            int ans = Integer.MAX_VALUE;
            int t = k;
            for(int j=i-1;j>=1 && t--> 0;j--){
                ans = Math.min(ans, Math.abs(arr[j]-arr[i]) + dp[j]);
            }
            dp[i] = ans;
        }

        System.out.println(dp[n]);

    }
}

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

//using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
//typedef unsigned long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
typedef pair<int, int> P;
//typedef pair<ll, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 100;
//const ll INF = (1ll << 31) - 1;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;
#define ret() return 0;

bool contain(set<char> &s, char a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;

double check(int i, int k) {
    double j = 1;
    while (i < k) {
        i *= 2;
        j /= 2;
    }
    return j;
}

int main() {
    int n, k;
    cin >> n >> k;

    double ans = 0;
    for (int i = 1; i <= n; i++) {
        double j = check(i, k);
        ans += (j / n);
    }
    printf("%.20f\n", ans);

}



Measured memory_bytes: 256
use std::io::BufRead;

fn main() {
    loop {
        let handle = std::io::stdin();
        let num: f64 = handle.lock()
            .lines().take(1).next().unwrap().unwrap().parse().unwrap();
        if num == 0.0 { break; }
        let info = handle.lock()
            .lines().take(1).next().unwrap().unwrap();
        let sum: f64 = info.split_whitespace()
            .map(|a| a.parse::<f64>().unwrap()).sum();
        let standard_deviation: f64 = (info.split_whitespace()
           .map(|a| (sum / num - a.parse::<f64>().unwrap()).powi(2))
           .sum::<f64>() / num).sqrt();
        println!("{:.*}", 5, standard_deviation);
    }
}


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

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String word = reader.readLine();
        int count = 0;
        while (true) {

            String sentence = reader.readLine();
            String[] words = sentence.split(" ");
            if (words[0].equals("END_OF_TEXT")) {
                break;
            } else {
                for (int i = 0; i < words.length; i++) {
                    if (word.equalsIgnoreCase(words[i])) {
                        count++;
                    }
                }
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 24244
#include <iostream>
#include <string>
#include <set>

using namespace std;

string s;
set<string> ts;
int k;

int main() {
    cin >> s >> k;

    for(int i = 1; i <= k; i++) {
        for(int j = 0; j < s.size() + 1 - i; j++) {
            ts.insert(s.substr(j, i));
        }
    }

    for(int i = 0; i < k - 1; i++) ts.erase(ts.begin());
    cout << *ts.begin() << endl;

    return 0;
}


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

using namespace std;

#define X first
#define Y second
#define ll long long
#define inf (ll)1e18
#define all(x) x.begin(), x.end()

const int MX = 200020;
const int N = 1000060;
const int mood = ((int)1e9 + 7);

int main(){
/*
    Hossam ^_^
     ___     ___
    (^_^)   (^_^)
   /( | )\ /( | )\
     | |     | |
*/
    cin.tie(0);
    cin.sync_with_stdio(0);

    #ifdef Cyborg101
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    int n;
    cin >> n;

    int a[2][n];
    for(int i = 0; i < 2; ++i){
    	for(int j = 0; j < n; ++j){
    		cin >> a[i][j];
    	}
    }


    int bst[2][n];
    memset(bst, 0xff, sizeof bst);

    bst[0][0] = a[0][0];

    queue<pair<int, int>> q;
    q.push({0, 0});

    auto valid = [&](int x, int y){
    	return x >= 0 && x < 2 && y >= 0 && y < n;
    };
    
    while(!q.empty()){
    	auto t = q.front();
    	q.pop();

    	int i = t.X;
    	int j = t.Y;

    	if(valid(i, j + 1) && bst[i][j] + a[i][j + 1] > bst[i][j + 1]){
    		bst[i][j + 1] = bst[i][j] + a[i][j + 1];
    		q.push({i, j + 1});
    	}

    	if(valid(i + 1, j) && bst[i][j] + a[i + 1][j] > bst[i + 1][j]){
    		bst[i + 1][j] = bst[i][j] + a[i + 1][j];
    		q.push({i + 1, j});
    	}

    }

    cout << bst[1][n - 1] << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define ALLOC(size,type) ((type*)calloc((size),sizeof(type)))

void calc (i32 max, i32 n, i32 *a, i32 *ans) {
  if (n == 1) {
    ans[0] = max;
    return;
  }
  i32 m = n / 2;
  i32 x = max;
  for (i32 i = 0; i < m; ++i) {
    x = MAX (x, a[i]);
  }
  calc (x, n - m, a + m, ans + m);
  x = max;
  for (i32 i = m; i < n; ++i) {
    x = MAX (x, a[i]);
  }
  calc (x, m, a, ans);
}

void run (void) {
  i32 n;
  scanf ("%" SCNi32, &n);
  i32 *a = ALLOC (n, i32);
  for (i32 i = 0; i < n; ++i) {
    scanf ("%" SCNi32, a + i);
  }
  i32 *ans = ALLOC (n, i32);
  calc (0, n, a, ans);
  for (i32 i = 0; i < n; ++i) {
    printf ("%" PRIi32 "\n", ans[i]);
  }
}

int main (void) {
  run();
  return 0;
}


Measured memory_bytes: 3072
Num = input().split(' ')
num1 = int(Num[0])
num2 = int(Num[1])

if num1 > num2:
    print('a', end=' ')
    print('>', end = ' ')
    print('b') 
elif num1 < num2:
    print('a', end=' ')
    print('<', end = ' ')
    print('b') 
elif num1 == num2:
    print('a', end=' ')
    print('==', end = ' ')
    print('b') 


Measured memory_bytes: 5592