akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int n,ans[10100];
int main()
{
	cin>>n;
	int x=1e2;
	for(int a=1;a<=x;a++)
		for(int b=1;b<=x;b++)
			for(int c=1;c<=x;c++)
			{
				int f=a*a+b*b+c*c+a*b+a*c+b*c;
				if(1<=f&&f<=x*x)
					ans[f]++;
			}
	for(int i=1;i<=n;i++)
		cout<<ans[i]<<endl;
	return 0;
}

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

// DAME:
/*
    累積和 + dfs
*/

vector<int> to[200005];
vector<int> ans;

// p は親の番号
void dfs(int v, int p=-1){
    for(int u: to[v]){
        // 双方向への移動防止
        if(u==p) continue;
        // 累積和
        ans[u] += ans[v];
        dfs(u, v);
    }
}

int main(){
    int n, q;
    cin >> n >> q;
    for(int i=0; i<n-1; i++){
        int a, b;
        cin >> a >> b;
        --a, --b;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    ans.resize(n); // TIPS: resizeすると0うめされる
    for(int i=0; i<q; i++){
        int p, x;
        cin >> p >> x;
        --p;
        ans[p] += x;
    }

    dfs(0);
    for(int i=0; i<n; i++){
        cout << ans[i] << ' ';
    }

    return 0;
}

Measured memory_bytes: 23424
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define vi vector<int>
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m-1);i>=(int)(n);i--)
#define rev(i, n) revi(i, n, 0)
#define each(i, n) for(auto&& i: n)
#define pb push_back
#define mp make_pair
#define sz(v) ((int)(v).size()) 
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin() , (v).rend()
#define dump(x) cerr << #x << "=" << x <<endl
#define gcd __gcd
int lcm(int a, int b){return a / gcd(a, b) * b;}
const int INF = 1e18;
const int MOD = 1e9 + 7;
const double EPS = 1e-15;
const double PI = acos(-1);

void solve()
{
	/*--------------------------*/

	char C; cin >> C;
	const string alphabet = "abcdefghijklmnopqrstuvwxyz";
	bool f = false;
	each(a, alphabet) {
		if (f) {
			cout << a << endl;
			break;
		}
		if (C == a) f = true;
	}

	/*--------------------------*/
}

signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	solve();
}

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

// output
#define SPBR(w, n) std::cout << (w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define RFOR(i, a, n) for (int i = (n)-1; i >= (a); --i)
#define REP(i, n) for (int i = 0; i < int(n); ++i)
#define RREP(i, n) for (int i = int(n) - 1; i >= 0; --i)
#define IN(a, x, b) (a <= x && x < b)
#define OUT(a, x, b) (x < a || b <= x)
template <class T> inline T chmax(T &a, const T b) {
  return a = (a < b) ? b : a;
}
template <class T> inline T chmin(T &a, const T b) {
  return a = (a > b) ? b : a;
}

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;

using namespace std;

signed main() {
  int H, N;
  cin >> H >> N;

  vector<pair<int, int>> A(N);
  REP(i, N) cin >> A[i].first >> A[i].second;

  vector<int> vec(30010, INF);
  vec[0] = 0;
  REP(i, 30010){
    if(i >= H){
      if(vec[i] != INF){
        break;
      }
    }
    if(vec[i] == INF) continue;
    REP(j, N){
      chmin(vec[i+A[j].first], vec[i]+A[j].second);
    }
  }

  RREP(i, 30010){
    if(i == 0) break;
    vec[i-1] = min(vec[i-1], vec[i]);
  }

  cout << vec[H] << endl;

  return 0;
}

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

int main () {
  
  int N;
  cin >> N;
  
  priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
  
  for (int i = 0; i < N; i++) {
    
    int A, B;
    cin >> A >> B;
    pq.push({B, A});
    
  }
  
  int time = 0;
  
  for (int i = 0; i < N; i++) {
    
    pair<int, int> p = pq.top();
    pq.pop();
    int B = p.first;
    int A = p.second;
    time += A;
    
    if (time > B) {
      cout << "No" << endl;
      return 0;
    }
    
  }
  
  cout << "Yes" << endl;
  return 0;
  
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ll N;
    cin >> N;
    vector<ll> vec(N);
    rep(i,N){
        cin >> vec[i];
    }
    sort(all(vec));
    bool possible = true;
    if (N % 2 == 0){
        rep(i,N){
            if (i % 2 == 0){
                if (vec[i] != i + 1) possible = false;
            }
            else{
                if (vec[i] != i) possible = false;
            }
        }
    }
    else{
        rep(i,N){
            if (i % 2 == 0){
                if (vec[i] != i) possible = false;
            }
            else{
                if (vec[i] != i + 1) possible = false;
            }
        }
    }
    if (!possible) cout << 0 << endl;
    else{
        ll ans = 1;
        ll num = N / 2;
        rep(i,num){
            ans = (ans * 2) % 1000000007;
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
ll n,m,t,ans,a[55],b[55],f[55],d[55],s[55];
vector<int> e[55];
void dfs(int x,int y){
	f[x]=y,d[x]=d[y]+1;
	for(int i=0;i<e[x].size();i++)
		if(e[x][i]!=y)dfs(e[x][i],x);
}
void gg(int x,int y){
	if(d[x]<d[y])swap(x,y);
	while(d[x]>d[y])
		s[x]=0,x=f[x];
	while(x!=y){
		s[x]=s[y]=0;
		x=f[x],y=f[y];
	}
}
int main(){
	n=read();
	for(int i=1;i<n;i++){
		int x=read(),y=read();
		e[x].push_back(y);
		e[y].push_back(x);
	}
	dfs(1,0),m=read();
	for(int i=0;i<m;i++)
		a[i]=read(),b[i]=read();
	for(int i=0;i<1<<m;i++){
		for(int j=2;j<=n;j++)
			s[j]=1;
		for(int j=0;j<m;j++)
			if(i&(1<<j))gg(a[j],b[j]);
		t=0;
		for(int j=2;j<=n;j++)
			t+=s[j];
		ans+=(1ll<<t)*(__builtin_popcount(i)&1?-1:1);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3572
// AOJ 3065 How old are you
// 2019.9.30 bal4u

#include <stdio.h>

typedef long long ll;

int main()
{
	int N, q, x;
	ll A, B;

	A = 0, B = 1;
	scanf("%d", &N);
	while (N--) {
		scanf("%d%d", &q, &x);
		if (q == 1) A *= x, B *= x;
		else if (q == 2) A += x;
		else A -= x;
	}
	printf("%lld %lld\n", -A, B);
	return 0;
}


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

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

#define rep(i, n) for (int i = 1; i <= (n); ++i)
#define rag(con) std::begin(con), std::end(con)

constexpr int MAX = 1e5 + 1e4 * 5 + 10;

std::vector<int> g[MAX];

double pre[MAX];
double parv;

bool used[MAX];

double ans[MAX];

void dfs0(int v)
{

    used[v] = 1;

    int cnt = 0;
    for (auto c : g[v])
    {
        if (!used[c])
        {
            dfs0(c);
            pre[v] += pre[c];
            ++cnt;
        }
    }

    if (v == 1)
    {
        pre[v] /= (double)g[v].size();
        pre[v] += 1.0;
    }
    else if (cnt != 0)
    {
        pre[v] /= (double)(g[v].size() - 1);
        pre[v] += 1.0;
    }
}

void dfs(int v)
{
    used[v] = 1;

    if (pre[v] == 0.0)
        ans[v] = parv + 1.0;
    else if (v == 1)
        ans[v] = pre[v];
    else
        ans[v] = ((pre[v] - 1.0) * (double)(g[v].size() - 1) + parv) / (double)g[v].size() + 1.0;

    //std::cerr << v << ' ' << parv << ' ' << ans[v] << std::endl;

    double pparv = parv;

    for (auto c : g[v])
    {
        if (!used[c])
        {
            if (v == 1)
            {
                if (g[v].size() != 1)
                    parv = ((pre[v] - 1.0) * (double)g[v].size() - pre[c]) / (double)(g[v].size() - 1) + 1.0;
            }
            else
                parv = pre[v] + (parv - pre[c]) / (double)(g[v].size() - 1);

            dfs(c);

            parv = pparv;
        }
    }
}

int main()
{
    int n;

    std::cin >> n;

    rep(i, n - 1)
    {
        int u, v;
        std::cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    dfs0(1);

    /*rep(i, n)
            std::cerr
        << pre[i] << ' ';
    std::cerr << std::endl;*/

    std::memset(used, 0, sizeof(used));

    dfs(1);

    rep(i, n)
            std::cout
        << std::fixed << ans[i] << std::setprecision(8) << std::endl;

    return 0;
}

Measured memory_bytes: 20324
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

ans = 0

for i in range(n):
    if a[i] < b[i]:
        ans += a[i]
        if a[i+1] < b[i]-a[i]:
            ans += a[i+1]
            a[i+1] = 0
        else:
            ans += b[i]-a[i]
            a[i+1] -= b[i]-a[i]
    else:
        ans += b[i]

print(ans)

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

int N, K;
vector<int> v;

void input() {
  cin >> N >> K;
  v.resize(N);
  for (auto &e : v) { cin >> e; }
  sort(v.begin(), v.end());
}

void solve() {
  long long ans = 0;
  rep(i, 0, K) ans += v[i];
  cout << ans << endl;
}

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

Measured memory_bytes: 3632
//QQ
//
//??\?????????????????¨?¨???§????????????????????????????????????????????°???????????????????????????????????????¨?????????£?????????????°?????????? x ????????¨?????????????????????
//
//1x1 = 1
//1x2 = 2
//.
//.
//9x8 = 72
//9x9 = 81
//
//Input
//
//?????????????????\????????????????????????
//Output
//
//1x1 = 1
//1x2 = 2
//.
//.
//9x8 = 72
//9x9 = 81

#include <stdio.h>

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

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

#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, n) for (ll i = 1; i <= n; i++)

using namespace std;

using ll = long long;
using p  = pair<ll, ll>;
constexpr ll INF = 1LL << 62;

int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll H, W;
    cin >> H >> W;
    vector<vector<bool> > S(H + 2, vector<bool>(W + 2, false));
    reps(i, H) {
        string str;
        cin >> str;
        reps(j, W) {
            S[i][j] = str[j - 1] == '#';
        }
    }
    
    ll dh[4] = {-1, 0, 1, 0};
    ll dw[4] = { 0,-1, 0, 1};

    
    reps(i, H) {
        reps(j, W) {
            if (!S[i][j]) {
                continue;
            }
            bool ok = false;
            rep(k, 4) {
                ok |= S[i + dh[k]][j + dw[k]];
            }
            if (!ok) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    
    cout << "Yes" << endl;
    
    return 0;
}


Measured memory_bytes: 256
n = int(input())
c    = 0
plus = 0
x, y, z = 0, 0, 0 
for _ in range(n):
    s = input()
    for i in range(0, len(s)-1):
        if s[i:i+2] == 'AB': c+=1
    
    if s[0] == 'B' and s[-1]=='A': y+=1
    elif s[0]=='B': z+=1   
    elif s[-1]=='A':x+=1

if  y == 0:
    plus = min(x, z)
else:
    plus = y-1
    plus += 1 if x > 0 else 0
    plus += 1 if z > 0 else 0
    
    lr    = min(x-1,z-1) 
    plus += lr if lr > 0 else 0 
    
print(plus+c)   

Measured memory_bytes: 3064
a = list(map(int, input().split()))
a.sort()
d1 = a[2] - a[0]
d2 = a[2] - a[1]
if abs(d1-d2) % 2 == 0:
  print(abs(d1-d2)//2 + min(d1,d2))
else:
  print((abs(d1-d2)+1)//2 + 1 + min(d1,d2))

Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <memory.h>
#include <set>
#include <cmath>
#define fio ios::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
ll _pow(ll a, ll b) {
	ll ans = 1;
	for (ll i = 0; b >> i; i++) {
		if ((b >> i) & 1) ans *= a;
		a *= a;
	}
	return ans;
}
int main(void) {
	int a, b, c; char tmp;
	scanf("%d", &a); getchar();
	scanf("%d", &b); getchar();
	scanf("%d", &c);
	ll ans = a * 10000 + b * 100 + c;
	if (ans <= 20190430) {
		printf("Heisei\n");
	}
	else {
		printf("TBD\n");
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		int[] d = new int[N];
		for(int i = 0; i < N; i++) {
			d[i] = stdIn.nextInt();
		}
		Arrays.sort(d);
		
		int count = 0;
		for(int i = 0; i < N; i++) {
			if(i >= 1 && d[i] != d[i-1]) {
				count++;
			}
			else if(i == 0) {
				count++;
			}
		}
		
		System.out.println(count);

	}

}

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

using namespace std;

int main()
{
    int n;
    cin>>n;
    int str1[n],str2[n];
    for(int i=0;i<n;i++)
    {
        cin>>str1[i];
        str2[i]=str1[i];
    }
    sort(str1,str1+n);
    int a=str1[(n-2)/2],b=str1[(n)/2];
    for(int i=0;i<n;i++)
    {
        if(str2[i]<=a)cout<<b<<endl;
        else if(str2[i]>=b)cout<<a<<endl;
    }
    return 0;
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;

int main() {
	int N,M, Q;
	cin >> N >> M >> Q;
	
	map<int, int> order;
	vector<int> input;
	set<int> used;
	vector<int> pos(M+1, 0);
	
	pos[0] = N;
	
	vector<int> nums;
	for(int i=0; i<Q; i++) {
		int p;
		cin >> p;
		input.push_back(p);
	}
	reverse(input.begin(), input.end());
	for(int i=0; i<input.size(); i++) {
		int p = input[i];
		int cnt = used.size();
		used.insert(p);
		if((int)used.size() != cnt) {
			order[p] = cnt+1;
			nums.push_back(p);
		}
		int cur = order[p];
		if(pos[cur-1] > 0) {
			pos[cur-1]--;
			pos[cur]++;
		}
	}
	/*
	for(int i=0; i<3; i++) {
		cout <<" " << i << " " << pos[i] << endl;
	}
	for(int i=0; i<nums.size(); i++)
		cout << nums[i] << endl;
	*/
	int last = nums.size()-1;
	bool ok = true;
	for(int val = nums.back(); val>=1; val--) {
		
		if(order[val] == 0) ok = false;
		if(last>0 && val == nums[last-1]) {
			last--;
		}
	}
	if(!ok) {
		last = nums.size();
	}
	
	bool judge = true;
	for(int i=0; i<last; i++)
		if(pos[i] > 0)
			judge = false;
	if(judge) cout << "Yes" << endl;
	else cout << "No" << endl;	
	return 0;
}


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

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

A, B, C = map(int, read().split())

if A == B == C:
    if A % 2 == 0:
        print(-1)
    else:
        print(0)
else:
    cnt = 0
    while True:
        if (A % 2 + B % 2 + C % 2) >= 1:
            break
        cnt += 1
        A, B, C = (B + C) // 2, (A + C) // 2, (A + B) // 2

    print(cnt)


Measured memory_bytes: 12504
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll pow(ll a){
	ll sum=1;
	for(ll i=1;i<=a;i++) sum*=2;
	return sum;
}
int main(){
	ll a,b;cin>>a>>b;
	for(int i=1;i<=70;i++){
		ll t=pow(i-1);
		if(t*a>b){
			cout<<i-1<<endl;
			return 0;
		} 
	}
	return 0;
}

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

int main() {
    int k;
    vector<int> a(3), b(3);
    bool f = false;
    cin >> a[0] >> a[1] >> a[2] >> k;
    rep(trit, pow(3, k)) {
        int tmp = trit;
        b = a;
        rep(i, k) {
            b[tmp % 3] *= 2;
            tmp /= 3;
        }
        if (b[0] < b[1] && b[1] < b[2]) {
            f = true;
            break;
        }
    }
    cout << ((f) ? "Yes" : "No") << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL << 60;
ll dp[100010];

int main(){

  int n;cin>>n;
  int k;cin>>k;
  int h[n+10];rep(i,0,n)cin>>h[i];

  rep(i,0,n)dp[i]=INF;
  dp[0]=0;
  rep(i,0,n){
    for(int next=i+1;next<=min((ll)n-1,i+k);next++){
      chmin(dp[next],dp[i]+abs(h[next]-h[i]));
    }
  }

  out(dp[n-1]);

  return 0;
}


Measured memory_bytes: 1408
#include<stdio.h>
int main(){
	int a,b;
	scanf("%d %d",&a,&b);
	if(a<b){
	printf("a < b\n",a,b);}
	else if(a>b){
	printf("a > b\n",a,b);}
	else{
	printf("a == b\n",a,b);}
	 return 0;
}

Measured memory_bytes: 580
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args){

		solve_abc157_a();
	}
  
  	public static void solve_abc157_a(){

		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		if(N % 2 == 1) N += 1;
		
		int ans = N / 2;
		
		System.out.println(ans);
		
		sc.close();
	}
}


Measured memory_bytes: 22996
n = int(input())
aa = []
bb = []

for _ in range(n):
  a,b = map(int,input().split())
  aa.append(a)
  bb.append(b)

aa= sorted(aa)[(n-1)//2:]
bb= sorted(bb,reverse=True)[(n-1)//2:]
if n%2==1:
  print(abs(bb[0]-aa[0])+1)
else:
  print((bb[0]+bb[1])-(aa[0]+aa[1])+1)



Measured memory_bytes: 27092
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
t = n-1
ans = 0
for i in range(n):
    lim = 2
    if i == 0:
        lim = 1
    for j in range(lim):
       if t > 0:
           ans += a[i] 
           t -= 1

print(ans)

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

using namespace std;

const int INF = 1001001001;

typedef tuple<int, int, int, int> State;

struct Comp {
	bool operator()(const State &l, const State &r)
	{
		if (get<0>(l) != get<0>(r)) return (get<0>(l) > get<0>(r));
		return (true);
	}
};

int mini[201][201][6];
int mp[201][201];

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


int main()
{
	int sx, sy, gx, gy;
	int n;
	int lx, ly;

	scanf("%d %d %d %d", &sx, &sy, &gx, &gy);
	scanf("%d", &n);

	for (int i = 0; i < n; i++){
		int x, y;
		scanf("%d %d", &x, &y);
		mp[y + 100][x + 100] = 1;
	}

	scanf("%d %d", &lx, &ly);

	for (int i = -ly; i <= ly; i++){
		for (int j = -lx; j <= lx; j++){
			for (int k = 0; k < 6; k++){
				mini[i + 100][j + 100][k] = INF;
			}
		}
	}

	priority_queue<State, vector<State>, Comp> pq;
	pq.push(State(0, 0, sy, sx));
	mini[sy + 100][sx + 100][0] = 0;

	while (pq.size()){
		State now = pq.top(); pq.pop();

		if (get<2>(now) == gy && get<3>(now) == gx){
			printf("%d\n", get<0>(now));
			return (0);
		}

		int prefer = abs(get<1>(now) * get<2>(now) * get<3>(now)) % 6;

		for (int i = 0; i < 7; i++){
			State nxt = now;
			get<0>(nxt) += (prefer != i);
			get<1>(nxt) = (get<1>(now) + 1) % 6;
			get<2>(nxt) += dy[(get<3>(now) + 100) % 2][i];
			get<3>(nxt) += dx[(get<3>(now) + 100) % 2][i];

			if (-ly <= get<2>(nxt) && get<2>(nxt) <= ly &&
				-lx <= get<3>(nxt) && get<3>(nxt) <= lx &&
				!mp[get<2>(nxt) + 100][get<3>(nxt) + 100] &&
				mini[get<2>(nxt) + 100][get<3>(nxt) + 100][get<1>(nxt)] > get<0>(nxt)){
				mini[get<2>(nxt) + 100][get<3>(nxt) + 100][get<1>(nxt)] = get<0>(nxt);
				pq.push(nxt);
			}
		}
	}

	printf("-1\n");

	return (0);
}

Measured memory_bytes: 2404
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#include <unistd.h>
#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
#define vecin(a) rep(i,a.size())cin >> a[i]
#define vecout(a) rep(i,a.size())cout << a[i] << " ";cout << "\n"
#define vecvec(a) vector<vector<(a)>>
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll inf = 2147483647;
const ll INF = 1LL << 60;
const ld pi = 3.14159265358;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
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> inline bool change(T a,T b){if(a > b){swap(a,b);return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
const ll cmax = 1000000;
ll fac[cmax], finv[cmax], inv[cmax];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < cmax; 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 nCk(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;
}
//nのm乗をMODで割ったあまりO(logN)
ll modpow(ll n,ll m,ll MOD){
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}

//printf("%.10f\n", N);
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/

//    cout << fixed << setprecision(15);

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N,K;
    cin >> N >> K;
    vector<ll> vec(N),ato(N);vecin(vec);
    ll m = min(100LL,K);
    for(ll i = 0;i < m;i++){
        rep(i,N){
            ll left = i - vec[i],right = i + vec[i] + 1;
            if(left < 0)left = 0;
            ato[left]++;
            if(right < N)
            ato[right]--;
        }
        //vecout(ato);
        rep(i,N - 1){
            ato[i + 1] += ato[i];
        }
        vec = ato;
        rep(i,N)ato[i] = 0;
        //vecout(vec);
    }
    vecout(vec);
}

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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

const ll MOD = 924844033;
const int MN = 2010;

int N, K;
ll fac[MN];
ll dp[2][MN][MN];
ll sub[MN][MN];

int main() {
	cin >> N >> K;
	fac[0] = 1;

	rep(i, MN - 1) {
		fac[i+1] = fac[i] * (i+1) % MOD;
	}

	sub[0][0] = 1;

	int now = 0;

	for (int m = 0; m < K * 2 && m < N; ++m) { //mod 2K
		
		vector<pii> vec;

		for (int p = m; p < N; p += K * 2) {
			int l = (p >= K), r = (p + K < N);
			vec.eb(l, r);
		}

		int n = vec.size();
		for (int i = 0; i <= n; ++i) {
			for (int j = 0; j <= n; ++j) {
				dp[0][i][j] = dp[1][i][j] = 0;
			}
		}

		dp[0][0][0] = 1;

		rep(i, n) {
			rep(j, n) {
				rep(k, 2) {
					if (!dp[k][i][j]) continue;
					dp[0][i+1][j] = (dp[0][i+1][j] + dp[k][i][j]) % MOD;

					if (vec[i].fi && !k) {
						dp[0][i+1][j+1] = (dp[0][i+1][j+1] + dp[k][i][j]) % MOD;
					}
					if (vec[i].se) {
						dp[1][i+1][j+1] = (dp[1][i+1][j+1] + dp[k][i][j]) % MOD;
					}
				}
			}
		}

		for (int c = 0; c <= N; ++c) {
			for (int j = 0; j <= n; ++j) {
				rep(k, 2) {
					sub[now+1][c+j] = (sub[now+1][c+j] + sub[now][c] * dp[k][n][j]) % MOD; 
				}
			}
		}
		++now;
	}

	ll ret = 0;

	for (int i = 0; i <= N; ++i) {
		ll t = sub[now][i];
		if (i & 1) {
			t = MOD - t;
		}
		ret = (ret + t * fac[N-i]) % MOD;
	}
	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 37120
N = int(input())
food = list(map(int, input().split(" ")))
one = list(map(int, input().split(" ")))
sec = list(map(int, input().split(" ")))
cnt = 0
for i in range(N-1):
  cnt += one[food[i]-1]
  if food[i+1] == food[i]+1:
    cnt += sec[food[i]-1]
cnt += one[food[N-1]-1]
print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
struct node{
    int id;
    int val;
    bool operator < (const node& a) const{
        return val<a.val;
    }
}a[100*100+100];
int str[105][105];
int main(){
    int n,m;
    cin>>n>>m;
    int k;
    cin>>k;
    int h=0;
    for(int i=1;i<=k;i++){
        int g;
        scanf("%d",&g);
        a[h].id=i;
        a[h].val=g;
        h++;
    }
    sort(a,a+h);

    h=0;
    for(int i=1;i<=n;i++){
        if(i%2){
            for(int j=1;j<=m;j++){
                str[i][j]=a[h].id;
                a[h].val--;
                if(a[h].val==0){
                    h++;
                }
            }
        } else {
            for(int j=m;j>=1;j--){
                str[i][j]=a[h].id;
                a[h].val--;
                if(a[h].val==0){
                    h++;
                }
            }
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            printf("%d ",str[i][j]);
        }
        puts("");
    }
    return 0;
}


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

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

using namespace std;

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

  int result=1;
  rep(i,n){
    if(result<=k){
      result*=2;
    }else{
      result+=k;
    }
  }

  cout<<result;
  return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]

num = [-1] * n
for s, c in sc:
    if num[s - 1] != -1 and num[s - 1] != c:
        print(-1)
        exit()
    if n > 1 and s == 1 and c == 0:
        print(-1)
        exit()
    num[s - 1] = c

if n > 1 and num[0] == -1:
    num[0] = 1

for i in range(n):
    if num[i] == -1:
        num[i] = 0

print("".join(str(x) for x in num))


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

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    if (a < b && a < c) {
        cout << a << " ";
        if (b < c) {
            cout << b << " ";
            cout << c;
        } else {
            cout << c << " ";
            cout << b;
        }
    } else {
        if (b < c) {
            cout << b << " ";
            if (a < c) {
                cout << a << " ";
                cout << c;
            } else {
                cout << c << " ";
                cout << a; 
            }
        } else {
            cout << c << " ";
            if (a < b) {
                cout << a << " ";
                cout << b;
            } else {
                cout << b << " ";
                cout << a;
            }
        }
    }

    cout << endl;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;




int main(void) {
  ll N, M;
  cin >> N >> M;
  ll s[11], c[11];
  ll i, j;
  ll d[11];
  
  memset(d, -1, sizeof(d));
  for(i=0; i<M; i++) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  
  for(i=0; i<M; i++) {
    if(d[s[i]]!=-1 && d[s[i]]!=c[i]) {
      pt(-1);
      return 0;
    }
    
    d[s[i]]=c[i];
    
  }
  
  if(N==1) {
    pt(max(d[0], 0LL));
    
  }else if(N==2) {
    if(d[0]==0) {
      pt(-1);
    }else {
      pt(max(d[0], 1LL)<<max(d[1], 0LL));
    }
    
  }else if(N==3) {
    if(d[0]==0) {
      pt(-1);
    }else {
      pt(max(d[0], 1LL)<<max(d[1], 0LL)<<max(d[2], 0LL));
    }
  }
  
}




Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 6)

def dfs(v,prev = -1):
    for u in graph[v]:
        if u == prev:
            continue
        point[u] += point[v]
        dfs(u,v)

N, Q = list(map(int,input().split()))
graph = [[] for _ in range(N)]
point = [0]*N

for i in range(N-1):
    a,b = list(map(int,input().split()))
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

for i in range(Q):
    p,x = list(map(int,input().split()))
    p -= 1
    point[p] += x

dfs(0)
print(*point)


Measured memory_bytes: 282704
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <random>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
#include <cstdint>
using namespace std;
using LL = long long;

int main() {
	int N;
	cin >> N;
	vector<LL>A(N + 1);
	for (int i = 0; i <= N; i++) {
		cin >> A[i];
	}
	if (N == 0) {
		if (A[0] == 1)cout << 1 << endl;
		else cout << -1 << endl;
		return 0;
	}
	if (A[0] != 0) {
		cout << -1 << endl;
		return 0;
	}
	vector<LL>L;
	L.push_back(1);
	for (int i = 1; i <= N; i++) {
		L.push_back(L.back() * 2 - A[i]);
		L.back() = min(L.back(), LL(LLONG_MAX / 2.1));
		if (i < N && L.back() <= 0) {
			cout << -1 << endl;
			return 0;
		}
	}
	if (L.back() < 0) {
		cout << -1 << endl;
		return 0;
	}
	LL ans = 0;
	LL now = 0;
	for (int i = N; i >= 1; i--) {
		now += A[i];
		ans += now;
		now = min(now, L[i - 1]);
	}
	ans += 1;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 5104
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する

ll gcd(ll a,ll b){
    if(a < b) swap(a,b);
    if(a % b == 0) return b;
    return gcd(b, a % b);

}

ll lcm(ll a,ll b){
    return a / gcd(a,b) * b;
}

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

    int N,K;
    cin >> N >> K;
    ll max_v = 0;
    ll g = 0;
    vector<ll> v(N);

    rep(i,0,N){
        cin >> v[i];
        max_v = max(v[i],max_v);
        if(i == 0){
            g = v[0];
        }else{
            g = gcd(g,v[i]);
        }
    }
    if(K <= max_v && (max_v - K) % g == 0){
        cout << "POSSIBLE" << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }


    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
char s[10];
int S[10000],ans;
int main(){
	scanf("%s",s+1);
	for(int i=1;i<=4;++i){
		S[s[i]]++;
		if(S[s[i]]==2)ans++;
	}
	puts(ans==2? "Yes":"No");
}

Measured memory_bytes: 764
# https://atcoder.jp/contests/agc038/submissions/7671675
# を参考にした、というよりもはやそのもの

mod = 998244353
max_A = 10**6
N = int(input())
A = list(map(int, input().split()))

# nまでの自然数が素数かどうかを表すリストを返す、エラストテネスの篩 O(nloglogn)
def make_prime_checker(n):
    is_prime = [False, True, False, False, False, True] * (n//6+1)
    del is_prime[n+1:]
    is_prime[1:4] = False, True, True
    for i in range(5, int(n**0.5)+1):
        if is_prime[i]:
            is_prime[i*i::i] = [False] * (n//i-i+1)
    return is_prime

# max_A 以下の素数のリスト
primes = [p for p, is_prime in enumerate(make_prime_checker(max_A)) if is_prime]

g = [0] * (max_A+1)
for a in A:
    g[a] += a
for p in primes:
    # 倍数集合の高速ゼータ変換みたいなやつ  O((max_A)loglog(max_A))
    # 大きい素数から再帰的に計算することで、約数列挙の手間を省く。賢すぎでは
    for k in range(max_A//p, 0, -1):
        g[k] = (g[k] + g[k*p]) % mod

# この時点で g[d] = Σ_{d|a} a  (A の要素のうち d の倍数であるものの総和)

g = [v * v % mod for v in g]

# この時点で
# g[d] = (Σ_{d|a} a)(Σ_{d|b} b)
#      = Σ_{(d|a)∧(d|b)} ab
#      = Σ_{d | gcd(a,b)} ab
# ただし重複込み

for p in primes:
    # 倍数集合の高速メビウス変換みたいなやつ  O((max_A)loglog(max_A))
    for k, g_kp in enumerate(g[p::p], 1):  # 高速化（ゼータ変換の方は途中で g が変化するので高速化できない）
        g[k] = (g[k] - g_kp) % mod  # 包除原理ヤバい
# 包除原理についてはg[d] = (dの倍数の個数)で考えて見ると何をしているのか分かりやすい
# 包除原理を適用可能な関数をモジュラ関数という
# 参考：http://www.misojiro.t.u-tokyo.ac.jp/~murota/lect-kisosuri/modularfunc081022.pdf

# この時点で g[d] = Σ_{gcd(a,b)=d} ab

def make_modinv_list(n, mod=10**9+7):
    # 0 から n までの mod 逆元のリストを返す、有限体より逆元が存在 O(n)
    # 参考：http://wakabame.hatenablog.com/entry/2019/04/08/023634
    modinv = [0, 1]
    for a in range(2, n+1):
        modinv.append(- (mod//a) * modinv[mod%a] % mod) # 1/a = -q * 1/r
    return modinv

modinv_list = make_modinv_list(max_A, mod)
ans = sum((gg % mod * minv % mod for gg, minv in zip(g, modinv_list)))
ans %= mod

# この時点で
# ans = Σ_d ( Σ_{gcd(a,b)=d} ab/d )
#     = Σ_d ( Σ_{gcd(a,b)=d} lcm(a,b) )
#     = Σ_a Σ_b lcm(a,b)

ans -= sum(A) # a = bのケースを抜く
ans *= modinv_list[2] # *1/2に相当
ans %= mod

# この時点で ans = Σ_{i<j} lcm(a,b)

print(ans)


Measured memory_bytes: 149652
# priority queueで楽勝だった
import heapq

n, m = map(int, input().split())
a = list(map(lambda x: int(x) * -1, input().split()))
heapq.heapify(a)

for _ in range(m):
    x = -(-a[0] // 2)
    heapq.heapreplace(a, x)
    #print(a)
print(sum(a) * -1)


Measured memory_bytes: 70936
#include <bits/stdc++.h>
#define LL long long
using namespace std;
int a[10005];
int main()
{
    int n,i,j,k,all;
    scanf("%d",&n);
    while(n!=0)
    {
        all=k=0;
        for(i=1;i<=n;i++)
        {
            a[i]=0;
            scanf("%d",&a[i]);
            all+=a[i];
        }
        all=all/n;
        for(i=1;i<=n;i++)
        {
            if(a[i]<=all)
                k++;
        }
        printf("%d\n",k);
        scanf("%d",&n);
    }
    return 0;
}



Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int ar[n];
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>ar[i];
    }
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    int cnt=0;
    for(int i=0;i<n;i++)
    {
        if(ar[i]>a[i])
        {
            cnt+=ar[i]-a[i];
        }

    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
n,M,K=map(int,input().split())

mod=998244353


fac = [1] * (n + 1)
inv = [1] * (n + 1)

for j in range(1, n + 1):
    fac[j] = fac[j-1] * j % mod


inv[n] = pow(fac[n], mod-2, mod)
for j in range(n-1, -1, -1):
    inv[j] = inv[j+1] * (j+1) % mod


def comb(n, r):
    if r > n or n < 0 or r < 0:
        return 0
    return fac[n] * inv[n - r] * inv[r] % mod

ans=0
temp=(M*(M-1)**(n-K-1))%mod#1乗
for k in range(K+1)[::-1]:
    ans=(ans+temp*comb(n-1,k))%mod
    temp=(temp*(M-1))%mod

print(ans)


Measured memory_bytes: 26528
k,n = map(int,input().split())
L = list(map(int,input().split()))
li = []
for i in range(n-1):
    li.append(L[i+1]-L[i])
li.append(k-L[n-1]+L[0])
#print(L,li)

min1 =10**10
#min1 = k-L[n-1]+L[0]
for i in range(n):
   min1 = min(min1,(k-li[i]))
   #print(min1)
print(min1)

Measured memory_bytes: 26436
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<queue>
using namespace std;


int main()
{
    int n,m,i,k,l,j;
    scanf("%d %d",&n,&m);
    if(n<=0&&m>=0)
        printf("Zero\n");
    else if(n>0)
        printf("Positive\n");
    else
    {
        k=m-n;
        if(k%2==0)
            printf("Negative\n");
        else
            printf("Positive\n");
    }
    return 0;
}


Measured memory_bytes: 128
function Main(input) {
	tmp = input.split("\n");
	
	var n = parseInt(tmp[0]);
	var s = tmp[1];
	var k = parseInt(tmp[2]);
	var r = "";
	
	var t = s.charAt(k-1);
	for (var i = 0 ; i < n ; i++){
		if(s.charAt(i)!=t){
			r+="*";
		}else{
			r+=s.charAt(i);
		}
	}
	
	console.log(r);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main(){
    int N,X;
    cin >> N;
    X=N/1.08;
    int ans;
   for(int i=1;i<X+2;i++){
       ans=1.08*i;
       if(ans==N){
           cout << i;
           return 0;
       }
   }
   cout << ":(";
    return 0;
}

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

#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)

#define INF (int)1e9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef map<int, int> mii;



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

    ll a,b;
    cin>>a>>b;
    cout<<a*b;
    return 0;
}


Measured memory_bytes: 3572
#include "bits/stdc++.h"
using namespace std;

int main() {
	int H, W, N;
	cin >> H >> W >> N;
	vector<int>A(N); 
	vector<vector<int>> data(H, vector<int>(W));
	for (int i = 0;i<N;++i) {
		cin >> A[i];
	}	
	int count = 0;
	for (int i = 0; i < N; ++i) {
		for (int j = 0;j<A[i];++j) {
			int x = count / W;
			int y = count %W;
			if (1 == x%2) {
				y = W - 1 - y;
			}
			data[x][y]= i + 1;
			count++;
		}
	}
	for (int i = 0;i<H;++i) {
		for (int j = 0;j<W;++j) {
			if (0 != j) {
				cout <<" ";
			}
			cout << data[i][j];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}
#define REP(i, n) for (long long i = 0; i < (n); i++)

vector<bool> visited(105);
vector<vector<int>> edge(105);
bool dfs(int cur, int par) {
    // if a cycle doesn't exist, return true
    visited[cur] = true;
    bool ic = false;
    if (edge[cur].size() == 0) {
        return true;
    } else {
        for (int i = 0; i < edge[cur].size(); i++) {
            if (edge[cur][i] == par) {
                continue;
            }
            if (visited[edge[cur][i]]) {
                ic = true;
                break;
            } else {
                visited[edge[cur][i]] = true;
            }
            if (!dfs(edge[cur][i], cur)) {
                ic = true;
            }
        }
        if (ic) {
            return false;
        } else {
            return true;
        }
    }
}
int ctoi(char c) {
    if (c >= '0' && c <= '9') {
        return c - '0';
    }
    return 0;
}
long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t % 2019;
    } else {
        return modpow(m, n - 1) * m % 2019;
    }
}
signed main() {
    long long n, m;
    cin >> n >> m;
    vector<vector<int>> graph(n + 1);
    REP(i, m) {
        int a, b;
        cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    map<int, int> cnt;
    REP(i, graph[1].size()) { cnt[graph[1][i]]++; }
    REP(i, graph[n].size()) {
        if (cnt[graph[n][i]] > 0) {
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 21360
import java.util.Scanner;
class Main {
  public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
int [] [] cards=new int [4][13];
for(int q=0;q<4;q++) {
	for(int w=0;w<13;w++) {
		cards[q][w]=1;
	}
}
int a=sc.nextInt();
for(int i=-0;i<a;i++) {
	String egara=sc.next();
	int lank=sc.nextInt();
	if(egara.equals("S")) {
		cards[0][lank-1]=0;
	}
	else if(egara.equals("H")) {
		cards[1][lank-1]=0;
	}
	else if(egara.equals("C")) {
		cards[2][lank-1]=0;
	}
	else if(egara.equals("D")) {
		cards[3][lank-1]=0;
	}
}
for(int e=0;e<4;e++) {
	for(int r=0;r<13;r++) {
		if(cards[e][r]==1) {
			if(e==0) {
				System.out.println("S "+(r+1));
			}
			else if(e==1) {
				System.out.println("H "+(r+1));
			}
			else if(e==2) {
				System.out.println("C "+(r+1));
			}
			else if(e==3) {
				System.out.println("D "+(r+1));
			}
		}
	}
}
sc.close();
  }
}






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

#define rep(i,n) for(int i = 0;i < n;++i)
#define rep2(i,n,m) for(int i = n;i < m;++i)
#define all(v) v.begin(),v.end()

using namespace std;
using ll = long long;


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

    ll n,m;
    double l;
    cin >> n >> m;
    vector<int> a(m);
    rep(i,m){
        cin >> a.at(i);
    }
    rep(i,m){
        n -= a.at(i);
    }

    if(n < 0){
        cout << "-1" << endl;
    }else{
        cout << n << endl;
    }

}

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

long long nos[200010];
long long dp[200010][4];
long long cuml[200010];
// 0 -> Ignore, 1 -> Odd, 2 -> Event
long long cost(int x, int t){
	if(t == 0) return x;
	else if(t == 1){
		if(x == 0) return 1;
		else return 1 - (x%2);
	}else{
		if(x == 0) return 2;
		else return x%2;
	}
}
int main(){
	int N; cin>>N;
	for(int i=1;i<=N;i++) cin>>nos[i];
	cuml[N] = nos[N];
	for(int i=N-1;i>=0;i--) cuml[i] = nos[i] + cuml[i+1];
	long long mcost = 1LL<<60;
	for(int i=1;i<=N;i++){
		dp[i][0] = dp[i-1][0] + cost(nos[i],0);
		dp[i][1] = min(dp[i][0], dp[i-1][1] + cost(nos[i],2)); // Even end meets start end
		dp[i][2] = min(dp[i][1], dp[i-1][2] + cost(nos[i],1)); // Odd end meets even end
		dp[i][3] = min(dp[i][2], dp[i-1][3] + cost(nos[i],2));
		mcost = min(mcost, dp[i][3] + cuml[i+1]);
	}
	cout<<mcost<<endl;
	return 0;
}

Measured memory_bytes: 9728
#include <bits/stdc++.h>
//#define DEBUG
#define REP( i , nn ) for(int i = 0 ; i < (int) nn; i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
template <class T>
void print_vect(std::vector<T> v){
    for(int i = 0 ; i < v .size(); i++) cout << v[i] << " ";
    cout << endl;
}

void solve(){
    int n;
    cin >> n;
    vi p(n);
    REP(i,n) cin >> p[i];
    int current_min = p[0];
    ll count = 0;
    for(int i = 0 ; i < n ; i++){
        if( p[i] <= current_min){
            count++;
            current_min = p[i];
        }
    }
    cout << count << "\n";
} 

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/

    #ifdef DEBUG
    int TEST_CASES = 2;
    while(TEST_CASES--){
    #endif // DEBBUG

    solve();

    #ifdef DEBUG
    }
    #endif // DEBUG
    
    return 0;
}

//Thanks to CSES problemset
// I am trained with this kind of problem

Measured memory_bytes: 3956
// 
// 
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define is_in(i, s) (s.find(i) != s.end())
#define all(x) (x).begin(),(x).end()
#define outl(x) cout<<x<<endl
#define outsp(x) cout<<x<<" "
typedef long long ll;
typedef pair<int,int> P;


#define MAX_N 1000000005


int main() {
	int a,b,c,k;
	cin >> a >> b >> c >> k;
	if(a+b>=k){
		outl(min(a,k));
	}else{
		outl(a-(k-a-b));
	}
    return 0;
}



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

class Main {
	public static void main(String args[]) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] splitLine = new String[2];
		int[] blood = {0,0,0,0};
		while(true){
			line = br.readLine();
			if(line == null || line.isEmpty()){
				break;
			}
			splitLine = line.split(",");
			if(splitLine[1].equals("A")){
				blood[0] ++;
			}else if(splitLine[1].equals("B")){
				blood[1] ++;
			}else if(splitLine[1].equals("AB")){
				blood[2] ++;
			}else if(splitLine[1].equals("O")){
				blood[3] ++;
			}
		}
		
		for(int i=0;i<4;i++){
			System.out.println(blood[i]);
		}
	}
}

Measured memory_bytes: 15048
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
typedef long long ll;
ll mod_pow(ll, ll, ll);
ll mod_fact(ll, ll);
ll mod_inv(ll, ll);
//
int main(){
    int n;
    cin >> n;
    set<string> st;
    for(int i = 0; i < n; i++){
        string s;
        cin >> s;
        st.insert(s);
    }
    cout << st.size();
}


Measured memory_bytes: 19180
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll n, ans = 0; cin >> n;
    set<pair<ll, ll>> red;
    set<pair<ll, ll>> blue;
    rep(i, n){
        ll a, b;
        cin >> a >> b;
        red.insert(make_pair(-a, -b));
    }
    rep(i, n){
        ll c, d;
        cin >> c >> d;
        blue.insert(make_pair(c, d));
    }

    for(auto &bp: blue){
        ll c = bp.first, d = bp.second;
        auto it = red.upper_bound({-c, 0});
        auto p = red.end();

        for(; it != red.end(); it++){
            ll a = (*it).first;
            ll b = (*it).second;
            if(p == red.end()){ if(b > (-d)) p = it; }
            else if((*p).second > b && b > (-d)) p = it;
        }
        if(p != red.end()){ ans++; red.erase(p); }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3668