akhauriyash/Code-Regression huggingface dataset:
//INCLUDE
//------------------------------------------
#include <iostream>
#include <functional>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <string>
#include <cstring>
#include <vector>
//DEFINE
//------------------------------------------
#define ll long long
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
using namespace std;
//-------------------------------------------
int main(void){
  ll N,M;cin>>N>>M;
  ll s[M],c[M];
  REP(i,M)cin>>s[i]>>c[i];
  ll num[N];REP(i,N)num[i]=-1;
  bool E=false;
  REP(i,M){
    int p=s[i]-1;
    int q=c[i];
    if(num[p]==-1)num[p]=q;
    else if(num[p]==q)continue;
    else {
      E=true;
      break;
    }
    //REP(i,N)cout<<num[i];cout<<endl;
  }
  if(E)cout<<-1;
  else if(N!=1&&num[0]==0)cout<<-1;
  else if(N==1&&M==0)cout<<0;
  else {
    REP(i,N)cout<<(num[i]==-1? i==0?1: 0:num[i]);
    cout<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
P = list(map(int, input().split()))

P = [(1+p)/2 for p in P]

S = [P[0]]
for i in range(1,N):
    S.append(P[i]+S[i-1])

S.insert(0,0)

b = max([S[i]-S[i-K] for i in range(K, N+1)])

print(b)

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

using ll = long long;
constexpr ll MOD = 1e9+7;

ll dp[301][90001][2];

ll modpow(ll x, ll n) {
    ll res = 1;
    while(n > 0) {
        if(n & 1) {
            res = (res * x) % MOD;
        }
        x = (x * x) % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    int d;
    cin >> d;
    vector<ll> l(d);
    for(int i=0; i<d; ++i) {
        cin >> l[i];
    }
    ll s;
    cin >> s;
    //vector<vector<vector<ll>>> dp(d+1, vector<vector<ll>>(90001, vector<ll>(2)));
    dp[0][0][0] = 1;
    for(int i=0; i<d; ++i) {
        for(int j=0; j<=s; ++j) {
            for(int k=0; k<2; ++k) {
                if(dp[i][j][k] == 0) {
                    continue;
                }
                (dp[i+1][j][k] += dp[i][j][k]) %= MOD;
                if(j + l[i] <= s) {
                    (dp[i+1][j+l[i]][k^1] += dp[i][j][k]) %= MOD;
                }
            }
        }
    }
    ll res = 0;
    for(int i=0; i<s; ++i) {
        (res += dp[d][i][0] * modpow(s-i, d)) %= MOD;
        (res -= dp[d][i][1] * modpow(s-i, d)) %= MOD;
        res = (res + MOD) % MOD;
    }
    cout << res << endl;
}


Measured memory_bytes: 184744
# coding: utf-8
# submission # - User: herp_sy
# https://atcoder.jp/contests/
#
# lang: Python3 (3.4.3)

import math
import statistics
import numpy as np
import queue

n = int(input())
a = list(int(i) for i in input().split())

cnt, subcnt = 0, 0
for i in a:
	if i % 2 == 0:
		subcnt += 1
		if i % 3 == 0 or i % 5 == 0:
			cnt += 1

if subcnt == cnt:
	print('APPROVED')
else:
	print('DENIED')


Measured memory_bytes: 22852
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x) cout<<#x<<" = "<<(x)<<endl;
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int a[3]; REP(i,3) cin >> a[i];
  sort(a,a+3,greater<int>());
  COUT(a[0]*10+a[1]+a[2]);
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

void swap(double *x,double *y){
	double t;
	t=*x;*x=*y;*y=t;
}

int main()
{
	double x1,y1,x2,y2,x3,y3,x4,y4;
	int n,i;
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);
		if((y1-y2)/(x1-x2)==(y3-y4)/(x3-x4)) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

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

int main() {
    string A, B, C;
    cin >> A >> B >> C;
    if (A[A.length() - 1] == B[0] && B[B.length() - 1] == C[0]){
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
while True:
    h,w = map(int,input().split())
    if h == 0 and w == 0:
        break
    for i in range(h):
        if i == 0 or i == h - 1:
            print("#" * w)
        else:
            print("#" + "." * (w-2) + "#")
    print("")


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

int main()
{
    int K, S;
    cin >> K >> S;

    int count = 0;
    for(int x = 0; x <= K; x++)
    {
        for(int y = 0; y <= K; y++)
        {
            int z = S - (x+y);
            if(0 <= z && z <= K) count++;
        }
    }

    cout << count << endl;

    return 0;
}


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

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

const lli e5 = 1 << 20;
const lli mod = 1000000007;
const lli e3 = 1 << 13;
const lli INF = 1ll << 62;

lli h,w,a,b;

int main(){
  cin >> h >> w;
  cin >> a >> b;
  cout << (h-a)*(w-b) << endl;
}


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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

namespace ae86
{
	const int bufl = 1<<15;

	char buf[bufl],*s=buf,*t=buf;

	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}

	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

const double eps = 1e-11;

inline int dcmp(double x){if(-eps<x && x<eps)return 0;return x>0?1:-1;}

struct points
{
	double x,y;
	points(double _x=0,double _y=0){x=_x,y=_y;}

	inline friend points operator + (points a,points b){return points(a.x+b.x,a.y+b.y);}
	inline friend points operator - (points a,points b){return points(a.x-b.x,a.y-b.y);}
	inline friend points operator * (points a,double b){return points(a.x*b,a.y*b);}
	inline friend points operator / (points a,double b){return points(a.x/b,a.y/b);}

	inline friend int operator == (points a,points b){return dcmp(a.x-b.x)==0 && dcmp(a.y-b.y)==0;}

	void takein(){x=ty(),y=ty();}
	void print(char ends='\n'){printf("%.12lf %.12lf",x,y),putchar(ends);}
};

inline double dox(points a,points b){return a.x*b.x+a.y*b.y;}
inline double cox(points a,points b){return a.x*b.y-a.y*b.x;}
inline double length(points a){return sqrt(dox(a,a));}
inline double distan(points a,points b){return length(a-b);}

inline points pervec(points a){if(dcmp(length(a))<=0)return points(0,0);return a/length(a);}

inline int isponl(points p,points a,points b)
{
	return dcmp(cox(p-a,p-b))==0 && distan(a,p)<=distan(a,b) && distan(b,p)<=distan(a,b);
}

void finder()
{
	points al,ar,bl,br;
	al.takein(),ar.takein(),bl.takein(),br.takein();

	double amix=min(al.x,ar.x),amxx=max(al.x,ar.x),amiy=min(al.y,ar.y),amxy=max(al.y,ar.y);
	double bmix=min(bl.x,br.x),bmxx=max(bl.x,br.x),bmiy=min(bl.y,br.y),bmxy=max(bl.y,br.y);
	
	if(amxx<bmix || bmxx<amix || amxy<bmiy || bmxy<amiy){puts("0");return;}
	if(isponl(al,bl,br) || isponl(ar,bl,br) || isponl(bl,al,ar) || isponl(br,al,ar)){puts("1");return;}

	if(dcmp(cox(al-bl,br-bl))!=dcmp(cox(ar-bl,br-bl))
		&& dcmp(cox(bl-al,ar-al))!=dcmp(cox(br-al,ar-al)))puts("1");
	else puts("0");
}

int main()
{
	int q=ty();
	while(q--)finder();
	
	return 0;
}



Measured memory_bytes: 3116
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define PN cout << endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (n-1); i >= (int)(m); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - (a)) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - (a)) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

/*
ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
*/

/*
vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}
*/

/*
ll ncr[100][100];
ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

ll npr[100][100]={};
ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

ll nHr(int n,int r){ret nCr(n+r-1,r);}
*/

///////////////////////////////////////////////////////////////////////////



int main(){
    int k[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

    int n;
    cin >> n;
    P(k[n-1]);
    return  0;
}


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

using namespace std;

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> graph(h);
  for (auto &v : graph)
    cin >> v;

  vector<vector<bool>> visited(h, vector<bool>(w, false));
  vector<vector<int>> costs(h, vector<int>(w, 1e9));

  queue<pair<int, int>> que;
  que.push(make_pair(0, 0));
  visited[0][0] = true;
  costs[0][0] = 1;

  while (not que.empty()) {
    auto tmp = que.front();
    que.pop();
    int x = tmp.first;
    int y = tmp.second;

    vector<int> dxs = {-1, 1, 0, 0};
    vector<int> dys = {0, 0, -1, 1};

    for (int i = 0; i < 4; ++i) {
      int x2 = x + dxs[i];
      int y2 = y + dys[i];
      if (x2 < 0 || h <= x2 || y2 < 0 || w <= y2 || graph[x2][y2] == '#' || visited[x2][y2] == true)
        continue;
      visited[x2][y2] = true;
      que.push(make_pair(x2, y2));
      costs[x2][y2] = costs[x][y] + 1;
    }
  }

  int bcnt = 0;
  for (auto &row : graph)
    for (auto &v : row)
      bcnt += v == '#';

  if (costs[h-1][w-1] == 1e9)
    cout << -1 << endl;
  else
    cout << h * w - bcnt - costs[h-1][w-1] << endl;
}


Measured memory_bytes: 3552
#include <iostream>
#include <vector>
#include <algorithm>

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

P x[100000];
int n, m;

int main(){
    cin >> n;
    cin >> m;
    for (int i = 0; i < m; ++i) {
        cin >> x[i].second >> x[i].first;
    }
    sort(x, x + m);

    int last = 0; int ans = 0;
    for (int i = 0; i < m; ++i) {
        if (last <= x[i].second) {
            ans++;
            last = x[i].first;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 1024
def main():
    buf = input()
    buflist = buf.split()
    N = int(buflist[0])
    A = int(buflist[1])-1
    B = int(buflist[2])-1
    C = int(buflist[3])-1
    D = int(buflist[4])-1
    buf = input()
    S = buf
    if D < C:
        space = 0
        for i in range(B-1, min(D+2, N)):
            if S[i] == '.':
                space += 1
                if space >= 3:
                    break
            else:
                space = 0
        if space < 3:
            print('No') # unswappable
            return
    rock_count = 0
    for i in range(A, max(C, D)+1):
        if S[i] == '#':
            rock_count += 1
            if rock_count >= 2:
                break
        else:
            rock_count = 0
    if rock_count >= 2:
        print('No')
    else:
        print('Yes')

if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  ll N;
  cin >> N;

  for (ll h = 1; h <= 3500; h++) {
    for (ll n = 1; n <= 3500; n++) {
      if (4*h*n - N*h - N*n <= 0) continue;
      ll w = N*h*n / (4*h*n - N*h - N*n);
      if ((4*h*n - N*h - N*n)*w == N*h*n) {
        cout << h << " " << n << " " << w << endl;
        return 0;
      }
    }
  }

  return 0;
}

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

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

int main(){
cin.sync_with_stdio(false);
cin.tie(0);
    LL p, n, z, t, ans=0;
    cin>> p>> z>> n>> t;
    if(p>= t){ans += t;}
    else{
        ans += p;
        if(t>(p+z)){ans -= (t-p-z);}
    }
    cout<< ans << endl;
}




Measured memory_bytes: 3696
import java.util.*;

// UVa 11504

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		
		long x = in.nextLong();
		long a = x / 11 * 2;
		long rem = x % 11;
		
		if (rem != 0 && rem <= 6) {
			a += 1;
		} else if (rem != 0) {
			a += 2;
		}
		
		System.out.println(a);
	}
}

Measured memory_bytes: 20820
#include <algorithm>
#include <iostream>

using namespace std;

string ss[] = {
	"pon",
	"pon",
	"hon",
	"bon",
	"hon",
	"hon",
	"pon",
	"hon",
	"pon",
	"hon"
};

int main() {
	int n; cin >> n;
	cout << ss[n % 10] << '\n';
	return 0;
}


Measured memory_bytes: 3560
import sys
input = sys.stdin.readline
def solve():
  n,m = (int(i) for i in input().split())
  query = []
  for i in range(m):
    s,c = (int(i) for i in input().split())
    query.append((s,c))
  ans = -1
  if n == 1:
    i = 0
    isanswer = True
    number = str(i)
    for s,c in query:
      if number[s-1] != str(c):
        isanswer = False
    if isanswer:
      print(i)
      exit()
  
  for i in range(10**(n-1),10**(n)):
    #search 100 to 999
    isanswer = True
    number = str(i)
    for s,c in query:
      if number[s-1] != str(c):
        isanswer = False
    if isanswer:
      print(i)
      exit()
  print(ans)
solve()

Measured memory_bytes: 3064
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();

    if (a == 1 && b == 2 || a == 2 && b == 1) {
      System.out.println(3);
    } else if (a == 2 && b == 3 || a == 3 && b == 2) {
      System.out.println(1);
    } else if (a == 3 && b == 1 || a == 1 && b == 3) {
      System.out.println(2);
    }
  }

}


Measured memory_bytes: 21460
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()
int n,m;
vector<vector<int>> g;
int dp[100100];

int dfs(int now){
    if(dp[now]!=-1)return dp[now];
    
    int res = 0;
    for(int x: g[now]){
        res = max(res, dfs(x)+1);
    }
    return dp[now]=res;
}

int main()
{
    cin>>n>>m;
    g.resize(n);
    rep(i,1,m){
        int x,y;cin>>x>>y;
        --x,--y;
        g[x].push_back(y);
    }
    rep(i,0,100010)dp[i]=-1;
    int res = 0;
    rep(i,0,n-1)res=max(res,dfs(i));
    cout<<res<<endl;
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using vi=vector<int>;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    ll ar=0,sn=0;
    sn=a[0];
    for(int i=1;i<n;++i) ar+=a[i];
    ll ans=abs(sn-ar);
    for(int i=1;i<n-1;++i){
        sn+=a[i];
        ar-=a[i];
        ans=min(ans,abs(sn-ar));
    }
    cout << ans << "\n";
    return 0;
}   

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

template <class T> T Sq(const T &t) { return t * t; }

const int mod = 1e9 + 7;

signed main() {
  int n, k;
  std::cin >> n >> k;
  int x, ans = 0;
  REP(i, n) {
    x = read();
    ans += min(2 * x, 2 * abs(x - k));
  }
  print(ans);
}


Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
  let mut s = String::new();
  std::io::stdin().read_line(&mut s).ok();
  s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
  read::<String>().split_whitespace()
    .map(|e| e.parse().ok().unwrap()).collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
  (0..n).map(|_| read_vec()).collect()
}

fn main() {
  let (n, k, q) = {
    let tmp: Vec<usize> = read_vec();
    (tmp[0], tmp[1], tmp[2])
  };
  let mut a: Vec<usize> = Vec::new();
  for i in 0..q { a.push(read()) }

  if k > q {
    for _ in 0..n {
      println!("Yes");
    }
    return;
  } else {
    let mut answerer_vector: Vec<isize> = Vec::new();
    for i in 0..n { answerer_vector.push((q-k) as isize * -1)}
    for i in 0..q {
      let tmp = a[i] - 1;
      answerer_vector[tmp] += 1;
    }
    for i in 0..n {
      if answerer_vector[i] > 0 { println!("Yes"); }
      else { println!("No"); }
    }
  }
}

Measured memory_bytes: 6780
/** 
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

/*
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
*/

#include <bits/stdc++.h>
using namespace std;

/* see https://github.com/pllk/cphb/
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,
    tree_order_statistics_node_update> indexed_set;
 **/

typedef long long ll;
#define endl "\n"
#define fori(n) for(ll i=0; i<(n); i++)

#define cins(s) string s; cin>>s;
#define cini(i) int i; cin>>i;
#define cinll(l) ll l; cin>>l;
#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }
#define cinall(a, n) vll a(n); fori(n) { cin>>a[i]; }

//typedef __int128 lll;
typedef pair<int, int> pii;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<string> vs;
typedef vector<ll> vll;

int main() {
cin.tie(nullptr);
std::ios::sync_with_stdio(false);
    cini(n);
    int ans=0;
    if(n>=100000)
        n=99999;
    if(n>=9999)
        ans+=(n-9999);
    n=min(n, 999);
    if(n>99)
        ans+=(n-99);
    n=min(n, 9);
    ans+=n;
    cout<<ans<<endl;
}



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

//宣言
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

//数値
#define MOD 1000000007
#define INF (1<<20)
const double EPS = 1e-10;
const double PI = acos(-1.0);

//操作
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define REP(i,n) FOR(i,0,n)
#define REPB(i,n) for(int i=n;i>=0;--i)
#define SORT(A) sort(A,A+sizeof(A)/sizeof(A[0]))
#define VSORT(A) sort(A.begin(),A.end())
#define EXIST(s,e) (s.find(e)!=s.end())
#define PB push_back
#define MP make_pair
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);

//DEBUG
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main() {
	int a, b;
	cin >> a >> b;
	char s[12] = { "" };
	cin >> s;
	int f = 1;
	REP(i, a + b + 1) {
		if (i == a) {
			if (s[i] != '-') f = 0;
		}
		else {
			if (s[i]<'0' || s[i]>'9') f = 0;
		}
	}
	if (f) cout << "Yes" << endl;
	else cout << "No" << endl;

}

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

int main() {
  int n, t;
  std::cin >> n >> t;

  int cost = 10000;
  for (int i = 0; i < n; i++) {
    int c, ti;
    std::cin >> c >> ti;
    if (ti <= t) {
      cost = std::min(cost, c);
    }
  }
  if (cost != 10000) {
    std::cout << cost << std::endl;
  } else {
    std::cout << "TLE" << std::endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
        int[][] a=new int[3][3];
      int hantei=0;
		Scanner sc = new Scanner(System.in);
      for(int i=0;i<3;i++){
        for(int k=0;k<3;k++){
		int tugi = sc.nextInt();
          a[i][k]=tugi;
        }
      }
      int N=sc.nextInt();
      boolean[][] kekka=new boolean[3][3];
      for(int i=0;i<3;i++){
        for(int k=0;k<3;k++){
		kekka[i][k]=false;
        }
      }
      for(int t=0;t<N;t++){
        int now=sc.nextInt();
        for(int i=0;i<3;i++){
        for(int k=0;k<3;k++){
          if(a[i][k]==now){
            kekka[i][k]=true;
          }
        }
      }
        if(kekka[0][0]==true&&kekka[0][1]==true&&kekka[0][2]==true){
          hantei=1;
          break;
        }
        if(kekka[1][0]==true&&kekka[1][1]==true&&kekka[1][2]==true){
          hantei=1;
          break;
        }
        if(kekka[2][0]==true&&kekka[2][1]==true&&kekka[2][2]==true){
          hantei=1;
          break;
        }
        if(kekka[0][0]==true&&kekka[1][0]==true&&kekka[2][0]==true){
          hantei=1;
          break;
        }
        if(kekka[0][1]==true&&kekka[1][1]==true&&kekka[2][1]==true){
          hantei=1;
          break;
        }
        if(kekka[0][2]==true&&kekka[1][2]==true&&kekka[2][2]==true){
          hantei=1;
          break;
        }
        if(kekka[0][0]==true&&kekka[1][1]==true&&kekka[2][2]==true){
          hantei=1;
          break;
        }
        if(kekka[0][2]==true&&kekka[1][1]==true&&kekka[2][0]==true){
          hantei=1;
          break;
        }
      }
      if(hantei==1){
        System.out.println("Yes");
      }else{
        System.out.println("No");
      }
	}
}


Measured memory_bytes: 23124
a, b, k = map(int, input().split())

for i in range(k):
	if i%2==0:
		if a%2==1:
			a-=1
		a = a/2
		b = b+a
	if i%2==1:
		if b%2==1:
			b-=1
		b = b/2
		a = b+a

print("{} {}".format(int(a), int(b)))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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=1000000007;
const int INF=1001001001;

vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}

struct edge{
  int to;
  int64_t cost;
};
vector<vector<edge>>g;
vector<int64_t>ans;
void dfs(int now,int back,int64_t dist){
  ans[now]=dist;
  for(auto e:g[now]){
    if(e.to==back){continue;}
    dfs(e.to,now,dist+e.cost);
  }
}

int main() {
  int N;
  cin>>N;
  g.resize(N);
  ans.resize(N);
  for(int i=0;i<N-1;i++){
    int a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    g[a].push_back((edge){b,c});
    g[b].push_back((edge){a,c});
  }
  
  int Q,K;
  cin>>Q>>K;
  K--;
  dfs(K,-1,0);
  for(int i=0;i<Q;i++){
    int x,y;
    cin>>x>>y;
    x--;y--;
    cout<<ans[x]+ans[y]<<endl;
  }
  return 0;  
}

Measured memory_bytes: 15604
#include <iostream>
#include <vector>
#define neparan & 1
using namespace std;

const int mod = 998244353;

int add(int a, int b) {
	a += b;
	if(a >= mod) a -= mod;
	if(a < 0) a += mod;
	return a;
}

int mul(int a, int b) {
	return ((long long)a * b) % mod;
}

int po(int a, int b) {
	if(b == 0) return 1;
	if(b == 1) return a;
	if(b neparan) return mul(po(a, b - 1), a);
	int x = po(a, b / 2);
	return mul(x, x);
}

int dj(int a, int b) {
	return mul(a, po(b, mod - 2));
}

int fa[500000];

int ovrh(int n, int k) {
	return dj(fa[n], mul(fa[k], fa[n - k]));
}

int main() {
	
	fa[0] = 1;
	for(int i = 1; i < 500000; i++) {
		fa[i] = mul(fa[i - 1], i);
	}
	
	long long n, a, b, k;
	cin >> n >> a >> b >> k;
	
	int re = 0;
	
	for(int ca = 0; ca <= n; ca++) {
		long long umn = a * ca;
		if(umn <= k) {
			long long mcb = k-umn;
			if(mcb % b == 0) {//add(mul(ca, a), mul(cb, b)) == k) {
				long long cb = mcb / b;
				if (cb > n) continue;
				re = add(re, mul(ovrh(n, ca), ovrh(n, cb)));
			}
			//cout << k << ' ' << umn << '\n';
		}
	}
	
	cout << re;
	
	return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <numeric>
#include <iomanip>
#include <climits>
#include <cstring>
#include <cmath>

using namespace std;

#define int long long
#define rep(i, n) for (int i=0;i<(int)(n);++i)
#define rep1(i, n) for (int i=1;i<=(int)(n);++i)
#define rrep(i, n) for (int i=(int)(n)-1;i>=0;--i)
#define rrep1(i, n) for (int i=(int)(n);i>=1;--i)
#define range(i, l, r) for (int i=l;i<(int)(r);++i)
#define rrange(i, l, r) for (int i=(int)(r)-1;i>=l;--i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi=vector<int>;
using pii=pair<int, int>;
using vpii=vector<pii>;
using ll=long long;

constexpr int TEN(int n){return n==0?1:10*TEN(n-1);}
template<typename T>bool chmin(T&a,T b){return a>b?(a=b,1):0;}
template<typename T>bool chmax(T&a,T b){return a<b?(a=b,1):0;}
int read(){int a;scanf("%lld",&a);return a;}

const long double pi = acos(-1);
constexpr int inf = 3*TEN(18) + 10;

struct SegTree { // 区間min,max
	int n;
	vector<int> Max;
	vector<int> Min;
	void init(int n_) {
		n = 1;
		while (n < n_) n *= 2;
		Max.resize(2 * n);
		Min.resize(2 * n);
		for (int i = 0; i < 2 * n - 1; ++i) {
			Max[i] = -inf;
			Min[i] = inf;
		}
	}
	void update(int idx, int val) {
		idx += n - 1;
		Min[idx] = val;
		Max[idx] = val;
		while (idx > 0) {
			idx = (idx - 1) / 2;
			Min[idx] = min(Min[idx * 2 + 1], Min[idx * 2 + 2]);
			Max[idx] = max(Max[idx * 2 + 1], Max[idx * 2 + 2]);
		}
	}
	int get_min(int a, int b, int k = 0, int l = 0, int r = -1) { // [a, b)のmin
		if (r == -1) r = n;
		if (r <= a || b <= l) return inf;
		if (a <= l && r <= b) return Min[k];
		int vl = get_min(a, b, k * 2 + 1, l, (l + r) / 2);
		int vr = get_min(a, b, k * 2 + 2, (l + r) / 2, r);
		return min(vl, vr);
	}
	int get_max(int a, int b, int k = 0, int l = 0, int r = -1) { // [a, b)のmax
		if (r == -1) r = n;
		if (r <= a || b <= l) return -inf;
		if (a <= l && r <= b) return Max[k];
		int vl = get_max(a, b, k * 2 + 1, l, (l + r) / 2);
		int vr = get_max(a, b, k * 2 + 2, (l + r) / 2, r);
		return max(vl, vr);
	}
};

int N;
int a[200010], idx[200010];
SegTree st;

signed main()
{
	cin >> N;
	st.init(N + 1);

	rep(i, N) {
		cin >> a[i];
		--a[i];
		idx[a[i]] = i;
	}

	int ans = 0;

	range(i, 0, N) {
		int l = st.get_max(0, idx[i]) + 1;
		int r = st.get_min(idx[i], N) - 1;

		if (l < 0) l = 0;
		if (r > N) r = N - 1;

		int lenl = idx[i] - l + 1;
		int lenr = r - idx[i] + 1;

		ans += (i + 1) * lenl * lenr;

		st.update(idx[i], idx[i]);
	}

	cout << ans << endl;
}



Measured memory_bytes: 11520
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define ss(x) (int) x.size()
#define pb push_back
#define ll long long
#define cat(x) cerr << #x << " = " << x << endl
#define FOR(i, n) for(int i = 0; i < n; ++i)

using namespace std;	

int n;

vector <string> v[4] = {
	{
		"ccba",
		"aaba",
		"cbcc",
		"cbaa"
	}
	,
	{
		"ac.aa",
		"acbb.",
		"caa.b",
		"c.c.b",
		"aacaa"
	}
	, 
	{
		"a.ac..",
		"a.ac..",
		".abbaa",
		".a.abb",
		"ccba..",
		"aab.aa"
	}
	,
	{
		"caabb..",
		"cb..aa.",
		"ab....b",
		"a..c..b",
		"..bc.aa",
		"b.baa..",
		"baa..aa"
	}
};

char s[1111][1111];
			
int main() {
	scanf("%d", &n);
	if(n == 2) 
		return printf("-1\n"), 0;
	if(n == 3) {
		printf(".aa\n");
		printf("a..\n");
		printf("a..\n");
		return 0;
	}
	int r = n % 4;
	int w = n - (r + 4);
	
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= n; ++j)
			s[i][j] = '.';
	int k = 1;
	for(int i = 0; i < ss(v[r]); ++i) 
		for(int j = 0; j < ss(v[r][i]); ++j)
			s[i + k][j + k] = v[r][i][j];
	k += (r + 4);
			
	for(int i = 0; i < w / 4; ++i) {
		for(int i = 0; i < 4; ++i)
			for(int j = 0; j < 4; ++j)
				s[i + k][j + k] = v[0][i][j];
		k += 4;
	}
	
	for(int i = 1; i <= n; ++i) {
		for(int j = 1; j <= n; ++j)
			printf("%c", s[i][j]);
		printf("\n");
	}
	
	
	return 0;
}



Measured memory_bytes: 2304
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }

void solve(void)
{
  int N, K; cin >> N >> K;
  vector<int> H(N);
  for(auto& h : H) cin >> h;
  boost::sort(H, std::greater<int>());
  ll ans = 0;
  for (int i = K; i < N; ++i) {
    ans += H[i];
  }
  cout << ans << CRLF;
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {

  char X,Y;

  cin >> X >> Y ;

  int x=(int)(X-'A'),y=(int)(Y-'A'); 

  if(x>y) cout << '>' << endl;

  else if(x<y) cout << '<' << endl;

  else cout << '=' << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<functional>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<utility>
#include<vector>

#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REPR(i,n)   FORR(i,n,0)

using namespace std;

int main() {
	int H, W, N, a[10000] = { 0 }, c[100][100];

	cin >> H >> W >> N;
	cin >> a[0];
	int x;
	FOR(i, 1, N) {
		cin >> x;
		a[i] = x + a[i - 1];
	}

	int key = 1, cnt = 0;
	REP(i, H) {
		REP(j, W) {
			cnt++;
			if (cnt > a[key - 1]) {
				key++;
			}
			if (i % 2 == 0) {
				c[i][j] = key;
			}
			else {
				c[i][W - j - 1] = key;
			}

		}
	}

	REP(i, H) {
		REP(j, W) {
			cout << c[i][j];
			if (j != W - 1) {
				cout << " ";
			}
		}
		cout << endl;
	}

	

	return 0;
}

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

using namespace std;

int main(){
    double N,avl=0;
    cin >> N;
    vector<double> x(N),y(N);
    for(int i=0;i<N;i++){
        cin >> x[i] >> y[i];
    }

    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            avl += pow((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]),0.5);
        }
    }

    cout << setprecision(12) << avl*2/N << endl;
}

Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#define printjudge(cond) {if(cond) printf("Yes\n"); else printf("No\n");}
#define printans(ans) {printf("%d\n",(ans));}
#define intscan(x) {scanf("%d", &x);}
#define Ntimes(N) for(int i=0; i<N; i++)
#define min(x,y) (((x)<(y)) ? (x) : (y))
#define max(x,y) (((x)>(y)) ? (x) : (y))
typedef int* intarray;
typedef char* string;

int main(){
    int N;
    double x, ans = 0.0;
    char u[4];
    intscan(N);
    Ntimes(N){
        scanf("%lf %s", &x, u);
        if(u[0]=='J') ans += (int)x;
        else ans += 380000.0 * x;
    }
    printf("%f\n", ans);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
bool p(string a){
	int k=a.size();
	for(int i=0;i<k/2;i++)
		if(a[i]!=a[k-1-i])
			return false;
	return true;
}
int main(){
	string x;
	cin>>x;
	int a=x.size();
	if(p(x)&&p(x.substr(0,(a-1)/2))&&p(x.substr((a+3)/2-1,a)))
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <vector>

#define ll long long

int main()
{
    ll A, B, N;
    std::cin >> A >> B >> N;

    // xはB以下になると思われる(0になるから)
    ll max = 0;
    ll x = N-4;

    if(N >= B) {
        max = (A * (B-1)) / B;
        //std::cout << max << std::endl;
    }
    else {
        max = A * N / B - A * (N / B);
    }
    std::cout << max << std::endl;
}

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

bool solve() {
    ll K, A, B;
    cin >> K >> A >> B;
    if ( A / K != B / K ) return true;
    if ( A % K == 0 || B % K == 0 ) return true;
    return false;
}

int main() {
    string ans = solve() ? "OK" : "NG";
    cout << ans << "\n";
    return 0;
}

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

int main() {
  int N, M, C;
  scanf("%d%d%d", &N, &M, &C);

  vector<int> B(M, 0);
  for (int i = 0; i < M; i++) {
    scanf("%d", &B.at(i));
  }

  vector<vector<int>> A(N, vector<int>(M, 0));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      scanf("%d", &A.at(i).at(j));
    }
  }

  int ans = 0;
  for (int i = 0; i < N; i++) {
    int sum = 0;
    for (int j = 0; j < M; j++) {
      sum += A.at(i).at(j) * B.at(j);
    }
    sum += C;
    if (sum > 0) ans++;
  }

  printf("%d", ans);
  return 0;
}

Measured memory_bytes: 256
K = int(input())
A,B = map(int,input().split())
K1 = 0
flag = 0
while K1 <= B:
    K1 = K1 + K 
    if A <= K1 <= B:
        print("OK")
        flag = 1
        break
if flag == 0:
    print("NG")


Measured memory_bytes: 9164
# 情報数理科学演習?
# 2014 冬

def heian_kyoWalking()
  gx, gy = gets.split.map(&:to_i) # 秘密の場所の座標
  n = gets.to_i                   # マタタビの区間の数
  matatabiPathes = []

  n.times do
    matatabiPathes << gets.split.map(&:to_i)
  end

  # 平安京の道: 1 ... 通行可能. 0 ... マタタビ.
  # 縦横別の配列を用意。添字は道の出発点の座標。
  heiankyoRow    = Array.new(16).map{ Array.new(15, 1) }
  heiankyoColumn = Array.new(15).map{ Array.new(16, 1) }

  # 平安京の交差点: 交差点までの経路の総数
  heiankyoCross = Array.new(16).map{ Array.new(16, 0) }

  # マタタビのおいてある道に0を代入
  matatabiPathes.each do |x| # x: x1 y1 x2 y2
    a, b, c, d = x
    minx = [a, c].min # 道の端点の座標のうち、
    miny = [b, d].min # 出発点 = 小さい方を用いる。
    if a == c # 縦の道
      heiankyoColumn[miny][minx] = 0
    else      # 横の道
      heiankyoRow[miny][minx] = 0
    end
  end

  # まず、外周の交差点の値を初期化する.外周の交差点への経路の総数は、マタタビがなければすべて1.
  # y = 0 の座標の交差点
  0.upto(14) do |i|
    # マタタビが見つかった場合、それ以降は中止
    heiankyoRow[0][i].zero? ? break : heiankyoCross[0][i+1] = 1
  end

  # x = 0 の座標の交差点
  0.upto(14) do |i|
    # マタタビが見つかった場合、それ以降は中止
    heiankyoColumn[i][0].zero? ? break : heiankyoCross[i+1][0] = 1
  end

  # 中の交差点
  1.upto(gy) do |y|
    1.upto(gx) do |x|
      if heiankyoRow[y][x-1].zero?
      # 交差点にはたどり着けない。
        if heiankyoColumn[y-1][x].zero?  
          heiankyoCross[y][x] = 0
      # 交差点には縦の道からのみ行ける
        else
          heiankyoCross[y][x] = heiankyoCross[y-1][x]
        end
      # 交差点には横の道からのみ行ける
      elsif heiankyoColumn[y-1][x].zero?
        heiankyoCross[y][x] = heiankyoCross[y][x-1]
      # 縦横両方の道から行ける
      else
        heiankyoCross[y][x] += heiankyoCross[y][x-1] + heiankyoCross[y-1][x]
      end
    end
  end

  puts (heiankyoCross[gy][gx].zero? ? "Miserable Hokusai!" : heiankyoCross[gy][gx].to_s)
end

if __FILE__ == $0
  gets.to_i.times{ heian_kyoWalking }
end

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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string L; cin >> L;
    ll dp[2][L.length()];
    dp[0][0] = 2;
    dp[1][0] = 1;
    for(int i = 1; i < L.length(); i++){
        if(L[i] == '0'){
            dp[0][i] = dp[0][i-1];
            dp[1][i] = (dp[1][i-1]*3) % mod;
        }
        else{
            dp[0][i] = (dp[0][i-1]*2) % mod;
            dp[1][i] = (dp[0][i-1] + dp[1][i-1]*3) % mod;
        }
    }
    cout << (dp[0][L.length()-1] + dp[1][L.length()-1]) % mod << endl;
    return 0;
}

Measured memory_bytes: 2000
<?php
list($kind,$dough)=explode(" ",trim(fgets(STDIN)));
$sweet=[];

for($i=0;$i<$kind;$i++){
    $sweet[]=trim(fgets(STDIN));
}

$count=0;

//計算1 少なくとも 1 つは全種類作る

$sum=array_sum($sweet);
$residue =$dough-$sum;
    
    if($residue>=0){
       $count+=$kind;
       //計算2 余ったら、最も少ない使用量のドーナツを作る
       $count+=intdiv($residue,min($sweet));
       echo $count;
    
    }else{
        echo 0;
    }


?>

Measured memory_bytes: 4604
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define FOR(a, c) for (int(a) = 0; (a) < (c); (a)++)
#define FORL(a, b, c) for (int(a) = (b); (a) <= (c); (a)++)
#define FORR(a, b, c) for (int(a) = (b); (a) >= (c); (a)--)
#define INF 1000000000000000003
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define F first
#define S second
#define pb push_back 
#define pob pop_back
#define mp make_pair

void solve(){
	int x,n;
	cin>>x>>n;
	// int arr[x]={0};
	map<int,int> m;
	FOR(i,n){
		int v;
		cin>>v;
		m[v]++;
	}
	// cout<<arr[4];
	int MINI = 1e9;
	int ans;
	for(int i=-300;i<=300;i++){
		if(!m[i]){
			if(MINI>abs(x-i)){
				MINI = abs(x-i);
				ans = i;
			}
	    }
    }
    cout<<ans;
}

int main(){

    //#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1; 
    // cin>>t;
    while(t--){
      solve();
    }
    return 0;
}

Measured memory_bytes: 3520
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};

vector<lint> edge[100050];
lint in[100050];

int main(void){
    lint N,M;
    cin >> N >> M;
    vector<lint> topo;
    stack<lint> V;
    rep(i,M){
        lint x,y;
        cin >> x >> y;
        x--,y--;
        edge[x].push_back(y);
        in[y]++;
    }
    rep(i,N) if(in[i]==0) V.push(i);
    while(!V.empty()){
        lint v=V.top();
        V.pop();
        topo.push_back(v);
        rep(i,edge[v].size()){
            in[edge[v][i]]--;
            if(in[edge[v][i]]==0) V.push(edge[v][i]);
        }
    }
    lint dp[N]={};
    rep(i,N){
        lint now=topo[i];
        rep(j,edge[now].size()) dp[edge[now][j]]=max(dp[edge[now][j]],dp[now]+1);
    }
    cout << *max_element(dp,dp+N) << endl;
}

Measured memory_bytes: 8180
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n,a[10005];
int gcd(int a,int b)
{
    if (b==0) return a;
    else return gcd(b,a%b);
}
int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for (int i=1;i<=n;i++)
        cin>>a[i];
    int ans=a[1]*a[2]/gcd(a[1],a[2]);
    for (int i=3;i<=n;i++)
    {
        int p=gcd(ans,a[i]);
        p=ans*a[i]/p;
        ans=p;
    }
    cout<<ans<<"\n";
    return 0;
}



Measured memory_bytes: 3152
n, k = map(int, input().split())
r, s, p = map(int, input().split())
r, s, p = p, r, s
point = {'p':p, 'r':r, 's':s}

t = input()
lose_flag = []
ans = 0
for i in range(len(t)):
    if i >= k and t[i] == t[i-k] and not lose_flag[i-k]:
        lose_flag.append(True)
        continue
    lose_flag.append(False)
    ans += point[t[i]]
    # print(point[t[i]])
print(ans)

Measured memory_bytes: 4212
fun main(args: Array<String>) {
    agc009a()
}

fun agc009a() {
    val n = readLine()!!.toInt()
    val aList = LongArray(n)
    val bList = LongArray(n)
    (1..n).map { readLine()!!.split(" ").map { it.toLong() } }.forEachIndexed { index, list ->
        aList[index] = list[0]
        bList[index] = list[1]
    }

    var push = 0L
    (n - 1 downTo 0).forEach { i ->
        push += (bList[i] - ((aList[i] + push) % bList[i])) % bList[i]
    }

    println(push)
}


Measured memory_bytes: 65360
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
    string str = "a";
    vector<string> v;
    while(str != "0"){
        cin >> str;
        // cout << str << endl;
        v.push_back(str);
    }
    vector<int> sums(v.size());
    for(int i = 0; i < v.size(); i++){
        int sum = 0;
        for(int j = 0; j < v[i].size(); j++) {
            int value = v[i][j] - '0';
            sum += value;
        }
        sums[i] = sum;
        // cout << v[i] << endl;
    }
    // for(int i = 0; i < sums.size(); i++) {
    //     if(sums[i] != 0){
    //         cout << sums[i] << endl;
    //     }
    // }
    for(auto x: sums) {
        if(x != 0){
            cout << x << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3216
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<iomanip>
#include<algorithm>
using namespace std;

int main() {
  int n,ans;cin >> n;
  for(int i=1;i<n+1;i++){
    ans += i;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(4100000)

import math

import logging

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)
from functools import lru_cache


def resolve():
    global N, grid

    # S = [x for x in sys.stdin.readline().split()][0]  # 文字列 一つ
    N = [int(x) for x in sys.stdin.readline().split()][0]  # int 一つ
    # N, D = [int(x) for x in sys.stdin.readline().split()]  # 複数int
    # grid = [list(sys.stdin.readline().split()[0]) for _ in range(N)]  # 文字列grid
    grid = [[int(x) for x in sys.stdin.readline().split()]
            for _ in range(N)]  # int grid

    logger.debug('{}'.format([]))

    grid = [(x + l, x - l) for x, l in grid]

    grid = sorted(grid)

    ans = 0
    t = - 10**10

    for right, left,  in grid:
        if t <= left:
            ans += 1
            t = right

    print(ans)

if __name__ == "__main__":
    resolve()

# AtCoder Unit Test で自動生成できる, 最後のunittest.main は消す
# python -m unittest template/template.py で実行できる
# pypy3 -m unittest template/template.py で実行できる

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """4
2 4
4 3
9 3
100 5"""
        output = """3"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """2
8 20
1 10"""
        output = """1"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """5
10 1
2 1
4 1
6 1
8 1"""
        output = """5"""
        self.assertIO(input, output)


Measured memory_bytes: 78424
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;

int main() {
  int n, m, dp[200010] = {1};
  bool broken[200010] = {};
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int t;
    cin >> t;
    broken[t] = true;
  }
  for (int i = 0; i <= n; i++) {
    if (!broken[i + 1]) (dp[i + 1] += dp[i]) %= MOD;
    if (!broken[i + 2]) (dp[i + 2] += dp[i]) %= MOD;
  }
  cout << dp[n] << endl;
}


Measured memory_bytes: 1280