akhauriyash/Code-Regression huggingface dataset:
// Problem : C - Forbidden List
// Contest : AtCoder - AtCoder Beginner Contest 170
// URL : https://atcoder.jp/contests/abc170/tasks/abc170_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

int main()
{
	int x,n,ans,min=100;
	cin>>x>>n;
	vector<int>v;
	vector<int>::iterator it;
	for(int i=0;i<n;i++)
	{
		int a;
		cin>>a;
		v.push_back(a);
	}
	if(x==1)
	ans=0;
	if(n==0)
	ans=x;
	else
	{
		int max=*max_element(v.begin(), v.end());
		for(int i=0;i<=max+1;i++)
	    {
	    	it=find(v.begin(),v.end(),i);
	    	if(it==v.end()&&min>abs(x-i))
	    	{
	    		min=abs(x-i);
	    		ans=i;
	    	}	    		    			
	    }
	}
	cout<<ans;	
	return 0;
}


Measured memory_bytes: 3604
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<utility>
#include<algorithm>
using namespace std;
#define ll int64_t
#define REP(i, n) for (int i=0; i<n; i++)

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

    ll H, W, N;
    cin >> H >> W >> N;
    vector<ll> a(N);
    REP(i, N) cin >> a[i];

    vector<pair<ll, ll>> path(H*W);
    REP(i, H*W){
        path[i].first = i/W;
        if (path[i].first % 2 == 0){
            path[i].second = i % W;
        } else {
            path[i].second = W-1-i%W;
        }
    }

    vector<vector<ll>> ans(H, vector<ll>(W));
    ll now = 0;
    REP(i, N){
        REP(j, a[i]){
            ans[path[now+j].first][path[now+j].second] = i+1;
        }
        now += a[i];
    }

    REP(i, H){
        REP(j, W){
            cout << ans[i][j] << ' ';
        }
        cout << "\n";
    }

}

Measured memory_bytes: 640
masu = gets.chomp.chars
ret = masu.size.times.map { 0 }
cand = [0, 1]
chose = 0
masu.size.times do |i|
  idx = i
  type = masu[idx]
  even = true

  if i != 0 && masu[i - 1] == masu[i]
    ret[cand[1 - chose]] += 1
    chose = 1 - chose
    next
  end

  loop do
    pre_idx = idx
    pre_type = type
    if type == 'R'
      idx += 1
    else
      idx -= 1
    end
    even = !even
    type = masu[idx]

    if type != pre_type
      cand = [idx, pre_idx]
      if even
        chose = 0
        ret[idx] += 1
      else
        chose = 1
        ret[pre_idx] += 1
      end
      break
    end
  end
end
puts ret.join(' ')

Measured memory_bytes: 10676
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;
int main(int argc, char const *argv[]) {
  ll n;std::cin >> n;
  string a, b, c;
  std::cin >> a >> b >> c;
  vector<set<ll>> t(n);
  re(i, n){
    t[i].insert(a[i]);
    t[i].insert(b[i]);
    t[i].insert(c[i]);
  }
  ll ans = 0;
  re(i, n){
    if(t[i].size()==2) ans++;
    else if(t[i].size()==3) ans +=2;
  }
  std::cout << ans << '\n';
}


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

using namespace std;

int main()
{
    int n, k;
    long long prime = (long long) 1000000007;
    cin >> n >> k;
    vector<vector<int>> adj_list (n);
    for (int i = 0; i < n - 1; i++) {
        int a, b; cin >> a >> b;
        adj_list[a - 1].push_back(b - 1);
        adj_list[b - 1].push_back(a - 1);
    }

    // let zero be the root
    queue<int> q;
    long long sol = k;
    vector<bool> visited (n, false);
    visited[0] = true;

    for (int i = 1; i <= adj_list[0].size(); i++) {
        sol *= (k - i);
        sol %= prime;
        if ((k - i) <= 0) {
            cout << "0" << endl;
            return 0;
        }
        int node = adj_list[0][i - 1];
        visited[node] = true;
        q.push(node);
    }

    while(!q.empty()) {
        int count = 0;
        int node = q.front();
        q.pop();
        for (int j = 0; j < adj_list[node].size(); j++) {
            int next_node = adj_list[node][j];
            if (visited[next_node]) continue;
            sol *= (k - count - 2);
            if (k - count - 2 <= 0) {
                cout << "0\n";
                return 0;
            }
            sol %= prime;
            visited[next_node] = true;
            q.push(next_node);
            count ++;
        }
    }
    cout << sol << endl;
}


Measured memory_bytes: 6520
#include <bits/stdc++.h>
using namespace std;
#define im 2147483647
#define lm 9223372036854775807
#define ll long long
#define ii pair<int, int>
#define debug(index, num) cerr << "Case #" << index << ": " << num << endl
#define be(x) x.begin(), x.end()
#define rbe(x) x.rbegin(), x.rend()
#define pb push_back
const ll MOD = 1000000007;
int main() {
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(NULL); 
    ll n;
    cin >> n;
    vector<vector<int>> dp(n+1, vector<int> (3, 0));
    vector<int> a(n+1), b(n+1), c(n+1);
    for(int i = 1; i <= n; i++) cin >> a[i] >> b[i] >> c[i];
    for(int i = 1; i <= n; i++) {
        dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a[i];
        dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b[i];
        dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c[i];
    }
    cout << max({dp[n][0], dp[n][1], dp[n][2]});
}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define __builtin_popcount __builtin_popcountll

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 (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
    os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const map<S, T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int T, n, m;

int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    while(cin >> n >> m){
        vi h(n);
        vi dp(n + 1, MOD);
        dp[0] = 0;
        REP(i, n) {
            cin >> h[i];
            for(int j = max(0, i - m); j < i; j++) {
                chmin(dp[i], dp[j] + abs(h[i] - h[j]));
            }
        }
        cout << dp[n - 1] << endl;
    }
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
typedef long long int ll;

using namespace std;
int main(){
	ll n,on=0,tw=0,ma=100000000000;
	cin >> n;
	vector<ll> a(n);
	for(ll i=0;i<n;i++){
		cin >> a[i];
		tw += a[i];
	}
	for(ll i=0;i<n-1;i++){
		on += a[i];
		tw -= a[i];
		ma = min(ma,abs(on - tw));
	}
		
	cout << ma << endl;

}

Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int h = Integer.parseInt(sa[0]);
		int w = Integer.parseInt(sa[1]);
		int k = Integer.parseInt(sa[2]);
		int[][] s = new int[h][w];
		for (int i = 0; i < h; i++) {
			char[] ca = br.readLine().toCharArray();
			for (int j = 0; j < w; j++) {
				s[i][j] = ca[j] - '0';
			}
		}
		br.close();

		int ans = Integer.MAX_VALUE;
		int h1 = h - 1;
		int end = 1 << h1;
		label:
		for (int i = 0; i < end; i++) {
			int[][] a = new int[h][w];
			int j2 = 0;
			for (int j = 0; j < h; j++) {
				for (int j3 = 0; j3 < w; j3++) {
					a[j2][j3] += s[j][j3];
				}
				if ((i >> j & 1) == 1) {
					j2++;
				}
			}

			int cnt = Integer.bitCount(i);
			int[] sum = new int[h];
			int miss = -1;
			for (int j3 = 0; j3 < w; j3++) {
				boolean flg = false;
				for (int j = 0; j < h; j++) {
					sum[j] += a[j][j3];
					if (sum[j] > k) {
						cnt++;
						flg = true;
						break;
					}
				}
				if (flg) {
					if (j3 == miss) {
						continue label;
					}
					miss = j3;
					Arrays.fill(sum, 0);
					j3--;
				}
			}
			ans = Math.min(ans, cnt);
		}
		System.out.println(ans);
	}
}


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

int main()
{
	int a,b;
	cin>>a>>b;
	cout<<a/b<<" "<<a%b<<" ";
	cout<<setiosflags(ios::fixed)<<setprecision(5)<<(double)(a)/b;
	return 0;
}


Measured memory_bytes: 3268
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    string s;
    cin >> s;
    if(s.at(2) == s.at(3) && s.at(4) == s.at(5)) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

typedef long long ll;

int prime[10055], cnt;
map<ll, int> squ, cntm;
map<ll, bool> cted;

bool b[100055], m3;
ll op[100050], yp[100050];

void read(ll &rem){
	rem = 0; char c = getchar();
	while(c<'0'||c>'9') c = getchar();
	while(c>='0' && c<='9') rem = rem*10+c-48, c = getchar();
}

void Init(){
	for(int i = 2; i <= 100050; i++){
		if(!b[i]){
			prime[++cnt] = i;
			b[i] = 1;
			squ[1ll*i*i] = i;
		}
		for(int j = 1; j <= cnt && 1ll * i * prime[j] <= 100050ll; j++){
			b[i * prime[j]] = 1;
			if(i%prime[j] == 0) break;
		}
	}
}

ll pow3(int x){return 1ll * x * x * x;}

int main(){
	int ans = 0, n;
	Init();
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) {
		ll p;
		bool flag = 0;
		read(p);
		yp[i] = op[i] = 1;
		for(int j = 1; pow3(prime[j]) <= p && j <= cnt; j++){
			int tot = 0;
			while(p%prime[j] == 0) p/=prime[j], tot++;
			tot%=3;
			if(tot == 1) yp[i] *= 1ll * prime[j], op[i] *= 1ll * prime[j] * prime[j], flag = 1;
			else if(tot == 2) yp[i] *= 1ll * prime[j] * prime[j], op[i] *= 1ll * prime[j], flag = 1;
		}
		
		if(p>1){
			if(squ[p]) yp[i] *= 1ll * p, op[i] *= 1ll * squ[p];
			else yp[i] *= 1ll * p, op[i] *= 1ll * p * p;
			flag = 1;
		}
		
		if(flag) cntm[yp[i]]++;
		else {
			m3 = 1;
			yp[i] = -1;
		}
	}
	for(int i = 1; i <= n; i++) if(yp[i]!=1 && !cted[yp[i]]){
		cted[op[i]] = 1, cted[yp[i]] = 1;
		ans += max(cntm[yp[i]], cntm[op[i]]);
	}
	printf("%d", ans+m3);
}

Measured memory_bytes: 33664
#include<bits/stdc++.h>
using namespace std;
int main() {
	const double pi = 2 * acos(0);
	cout << fixed << setprecision(10);
	int a, b, x; cin >> a >> b >> x;
	if(x <= 0.5 * a * a * b) {
		cout << atan(a * b * b * 0.5 / x) * 180 / pi << endl;
	} else {
		cout << atan(2.0 * (a * a * b - x) / (a * a * a)) * 180 / pi << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define INF LLONG_MAX
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll n; cin >> n;
    //vector<ll> a(n);
    ll count = 0;
    REP(i, n) {
        ll num; cin >> num;
        while (num % 2 == 0) {
            num /= 2;
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<pair<int, int>> pos;
vector<int> dp;
const int M = 998244353;


int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    cin >> n  >> k;
    pos.resize(k);
    for(auto &i: pos)
        cin >> i.first >> i.second;
    sort(pos.begin(), pos.end());
    dp.resize(n+2);
    dp[n] = 1;
    for (int i=n-1; i>=1; i--){
        for (auto &j: pos){
            if (i+j.first>n) break;
            int l = i+j.first, h = min(n, i+j.second);
            dp[i] = (dp[i]+(dp[l]-dp[h+1]))%M;
            while (dp[i]<0)
                dp[i] +=M;
        }
        if (i==1) break;
        dp[i] = (dp[i]+dp[i+1])%M;
    }
    cout << dp[1] << "\n";
}

Measured memory_bytes: 3960
import Control.Monad

main = do
  [h, w] <- fmap (map read . words) getLine :: IO [Int]
  if [h, w] == [0, 0] then
    return ()
  else do
    mapM_ putStrLn [[ if x == 1 || y == 1 || x == w || y == h then
                        '#' else '.' | x <- [1..w]] | y <- [1..h]]
    putStrLn ""
    main

Measured memory_bytes: 4004
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
int a[207];
int main(){
	int n,sum = 0;
	scanf("%d",&n);
	for(int i = 1; i <= 2*n; i++) scanf("%d",&a[i]);
	sort(a+1,a+1+2*n);
	for(int i = 1; i <= 2*n; i+=2) sum += a[i];
	printf("%d\n",sum);
	return 0;
}

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

#define reps(i,a,b) for(int i=a; i<b; i++)
#define rep(i,n) reps(i,0,n)
#define all(x) (x).begin(),(x).end()
#define INF (1e9)

int main(){
  int n;
  cin >> n;
  int a[26];
  rep(i,26){
    a[i] = INF;
  }
  int tmp[26]={};
  rep(i,n){
    string s;
    cin >> s;
    rep(j,26){
      tmp[j] = 0;
    }
    rep(j,s.size()){
      tmp[s[j]-'a'+0]++;
    }
    rep(j,26){
      a[j] = min(a[j],tmp[j]);
    }
  }
  
  string alp = "abcdefghijklmnopqrstuvwxyz";
  
  rep(i,26){
    rep(j,a[i]){
      cout << alp[i];
    }
  }
  cout << endl;
}

Measured memory_bytes: 256
#include<cstring>
#include<iostream>
#include<algorithm>
#include<string>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
using namespace std;

int main() {
    int n;
    string s;    
    cin >> n >> s;
    int cnt = 0;
    rep(i, n-2) {
        char check[3];
        check[0] = s[i];
        check[1] = s[i + 1];
        check[2] = s[i + 2];
        char z[3] = {'A', 'B', 'C'};
        if (strstr(check, z)) {
            ++cnt;
        } 
    }
    cout << cnt << endl;
    
    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>
 
using namespace std;
using namespace __gnu_pbds;
 
#define endl '\n'
 
typedef long long ll;
typedef pair<ll, ll> pii;
typedef tree<int, null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
template<typename T>
static T randint(T lo, T hi){
	return uniform_int_distribution<T>(lo, hi)(rng);
}



int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 
	// freopen("settling.in", "r", stdin);
	// freopen("settling.out", "w", stdout);

	ll a, b, c;
	cin >> a >> b >> c;

	ll cnt = a / b + (a % b != 0);
	cout << cnt * c << endl;
		
	return 0;
}


Measured memory_bytes: 3596
import heapq
N = int(input())
h = list(map(int, input().split()))

INF = 10**10
dp = [INF] * N

dp[0] = 0
que = [(0, 0)]

while que:
    cost, i = heapq.heappop(que)
    if cost <= dp[i]:
        for j in [i + 1, i + 2]:
            if j < N:
                if dp[j] > dp[i] + abs(h[j] - h[i]):
                    dp[j] = dp[i] + abs(h[j] - h[i])
                    heapq.heappush(que, (dp[j], j))
print(dp[-1])

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

//const int INF = 1001001001;
//const ll INF18 = 1000000000000000000;
const ll INF15 = 1000000000000000;

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

	int ans = 0;
	rep(i,n.size()) {
		int digit = n[i] - '0';
		ans += digit % 9;
		ans %= 9;
	}
	if (ans == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
	//cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MOD 1000000007

ll rep_sqr(ll base, ll k){
    if(k == 0){
        return 1;
    }else if(k % 2 == 0){
        ll p = rep_sqr(base, k / 2);
        return (p * p) % MOD;
    }else{
        return (rep_sqr(base, k - 1) * base) % MOD;
    }
}

ll inv(ll a){
    return rep_sqr(a, MOD-2);
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll facts[1000001];
    facts[0] = 1;
    facts[1] = 1;

    ll x, y;
    cin >> x >> y;

    ll r = 0, u = 0;
    while(x > 0 || y > 0){
        if(x > y){
            r ++;
            x -= 2;
            y -= 1;
        }else{
            u ++;
            y -= 2;
            x -= 1;
        }
    }

    for(ll i=2; i <= u+r; i++){
        facts[i] = (facts[i-1] * i) % MOD;
    }

    ll ans = 0;
    if(x == 0 && y == 0){
        ans = (((facts[r + u] * inv(facts[r])) % MOD) * inv(facts[u])) % MOD;
        cout << ans << endl;
    }else{
        cout << ans << endl;
    }
}


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

int main(){
	string S;
	cin >> S;
	if(S.at(5) == '0'){
		if(S.at(6) == '1' || S.at(6) == '2' || S.at(6) == '3' || S.at(6) == '4'){
			cout << "Heisei" << endl;
			return 0;
		}
	}
	cout << "TBD" << endl;
	return 0;
}


Measured memory_bytes: 256
import math
n=int(input())

def koch(n,a,b):
    if n==0:
        return
    th=math.pi*60.0/180.0
    s,t,u=[0,0],[0,0],[0,0]
    s[0]=(2.0*a[0]+1.0*b[0])/3.0
    s[1]=(2.0*a[1]+1.0*b[1])/3.0
    t[0]=(1.0*a[0]+2.0*b[0])/3.0
    t[1]=(1.0*a[1]+2.0*b[1])/3.0
    u[0]=(t[0]-s[0])*math.cos(th)-(t[1]-s[1])*math.sin(th)+s[0]
    u[1]=(t[0]-s[0])*math.sin(th)+(t[1]-s[1])*math.cos(th)+s[1]

    koch(n-1,a,s)
    print(s[0],s[1])
    koch(n-1,s,u)
    print(u[0],u[1])
    koch(n-1,u,t)
    print(t[0],t[1])
    koch(n-1,t,b)


a=[0,0]
b=[100,0]

print(a[0],a[1])
koch(n,a,b)
print(b[0],b[1])



Measured memory_bytes: 5788
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
int d,t,s;
signed main(){
	cin>>d>>t>>s;
	ll val=(ll)t*s;
	if(val>=d){
		cout<<"Yes"<<endl;return 0;
	}
	cout<<"No"<<endl;
	return 0;
}

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

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    int a[n], b[n], c[m], d[m];
    for (int i=0;i<n;i++) {
        cin >> a[i];
        cin >> b[i];
    }
    for (int i=0;i<m;i++) {
        cin >> c[i];
        cin >> d[i];
    }
    
    
    for(int i=0;i<n;i++) {
        int dist = abs(a[i] - c[0])  + abs(b[i] - d[0]);
        int min = dist;
        int minj = 0;
        for (int j=0;j<m;j++) {
            dist = abs(a[i] - c[j]) + abs(b[i] - d[j]);
            if(min > dist) {
                min = dist;
                minj = j;
            }
        }
        cout << minj+1 << endl;
    }
}


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

using namespace std;


int a[100001];
pair<int, int> cb[100001];

int main()
{
	int n, m;
	long long ans = 0;
	cin >> n >> m;

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

	sort(a, a + n);

	for (int i = 0; i < m; i++)
	{
		int b, c;
		cin >> b >> c;

		cb[i] = { c, b };
	}

	sort(cb, cb + m, greater<pair<int,int>>());

	int cur = 0, card = 0;
	while (cur < n) {
		if (cb[card].second == 0) ++card;
		if (card >= m) break;
		if (a[cur] < cb[card].first) {
			ans += cb[card].first - a[cur];
			--cb[card].second;
			++cur;
		}
		else break;
	}
	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 1408
#include <stdio.h>

int main(void){
		char s[5];
		int i, num = 0;

		scanf("%s", s);

		for(i=0; i<4; i++){
			if(s[i] == '+')
				num++;
			else if(s[i] == '-')
				num--;
		}

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

		return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int bfs(int start,vector<int> e[],int n){
    queue<int> que;
    que.push(start);
    int v[n];
    fill_n(v,n,-1);
    v[start]=1;
    while(!que.empty()){
        int now = que.front();
        que.pop();
        for(int i = 0;i<e[now].size();i++){
            int to = e[now][i];
            if(v[to]==-1){
                v[to] = v[now]+1;
                que.push(to);
            }
        }
    }
    rep(i,n) rep(j,e[i].size()){
        if(abs(v[e[i][j]]-v[i])!=1) return 0;
    }
    sort(v,v+n,greater<int>());
    return v[0];
}
int main(){
    int n;
    cin >> n;
    vector<int> e[n];
    int k;
    string s;
    //cout << "meu" << endl;
    for(int i = 0;i<n;i++){
        cin >> s;
        for(int j = 0;j<n;j++){
            if(s[j]=='1') e[i].push_back(j);
        }
    }
    //cout << "meu" << endl;
    int ans = 0;
    rep(i,n) ans = max(ans,bfs(i,e,n));
    if(ans==0) cout << -1 << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz size()
#define ll long long
#define all(_v) _v.begin(), _v.end()
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pvllvll pair <vector <ll>, vector <ll> >
#define ld long double
#define veci vector <int>
#define vecll vector <ll>


const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const double PI = 3.1415926535897932384626433832795;
const double eps = 1e-9;
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;

void solve() {
    int n;
    cin >> n;
    for(int i = 0; i < n; ++i) cout << "ACL";
}


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int T = 1;
    ///cin >> T;
    while(T--) solve(), cout << '\n';
    return 0;
}


Measured memory_bytes: 3612
///supercalifragilisticexpialidocious.
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <cctype>
#include <ctime>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <utility>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <list>
#include <bitset>
#include <complex>
using namespace std;
#define f first
#define s second
#define PB pop_back 
#define pb push_back
#define mp make_pair
#define int long long
#define y1 y_golabi
#define sz(s) (int)s.size()
#define seper(n) setprecision(n)
#define all(v) v.begin(),v.end()
#define mem(a,b) memset(a,b,sizeof a)
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
typedef long long ll; 
typedef map<int , int> mii;
typedef pair<int , int> pii; 
typedef map<string , int> msi;
typedef pair<int , string> pis; 
typedef pair<int , pair<int , int> > piii;
int k , a , b , c;
int32_t main()
{
	cin >> a >> b >> c >> k;
	if(k & 1)
		if(b - a > 1e18)
			cout << "Unfair" << endl;
		else
			cout << b - a << endl;
	else
		if(a - b > 1e18)
			cout << "Unfair" << endl;
		else
			cout << a - b << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>
#include <map>
#include <sstream>
#include <unordered_map>
#include <set>

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
static ull tenq = 1000000000;
static ull mod = tenq + 7;

using namespace std;

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

  ll x;
  cin >> x;
  ll minv = x;
  ll res = -2 * tenq;
  for (ll i = 1; i < N; i++)
  {
    cin >> x;
    res = max(res, x - minv);
    minv = min(minv, x);
  }

  cout << res << endl;

  return 0;
}



Measured memory_bytes: 3104
#include<iostream>
using namespace std;
int a,b,c,n,sum;
double x;
int main(){
  while(cin>>a>>b>>n){
    a=a%b;
    sum=0;
    for(int i=0;i<n;i++){
      a*=10;
      sum+=a/b;
      a=a%b;
    }
    cout<<sum<<endl;
  }
  return 0;
}

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



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main(void){

	int N; cin >> N;
	vector<int> a(N);
	REP(i,N) cin >> a[i];

	int ans = 0;
	REP(i,N) ans += a[i] - 1;

	cout << ans << endl;


	return 0;

}


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

#define FOR(i,a,b) for (int i=(a); i<(b); ++i)
inline int in() { int x; cin >> x; return x; }

void solve() {
  int a = in(), b = in();
  FOR(i,1,b+1) {
    if ((i*a) % b == 0) {
      cout << i*a << endl;
      break;
    }
  }
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pi  pair<int,int>
#define  pb  push_back
#define  F   first
#define  S   second
const int N=2e5+3;
string s,p;
//vector<int>v;
//map<int,int>mp;

int main()
{
    ft
    ll t,i,j,n,m,l,r,ans=0;
    cin>>s>>m;
    if(m==1)
    {
        n=s.size();
        ans+=(9*(n-1));
        int f=0;
        for(i=0; i<n; i++)
        {
            if(s[i]!='0')
            {
                f++;
            }
        }
        ans+=(s[0]-48);
    }
    else if(m==2)
    {
        n=s.size();
        m=n-2;
        ans+=81*((m*(m+1))/2);
        p="";
        for(i=0; i<n; i++)
        {
            p+="0";
        }
        for(i=1; i<10; i++)
        {
            p[0]=(char)(i+48);
            for(j=1; j<10; j++)
            {
                for(int k=1; k<n; k++)
                {
                    p[k]=(char)(j+48);
                    if(p<=s)
                    {
                        ans++;
                    }
                    p[k]='0';
                }
            }
        }
    }
    else
    {
        n=s.size();
        m=n-3;
        l=0,r=1;
        while(m>0)
        {
            l+=(m*r);
            m--,r++;
        }
        ans+=729*l;
        p="";
        for(i=0; i<n; i++)
        {
            p+="0";
        }
        for(i=1; i<10; i++)
        {
            p[0]=(char)(i+48);
            for(j=1; j<10; j++)
            {
                for(int k=1; k<n-1; k++)
                {
                    p[k]=(char)(j+48);
                    for(r=1; r<10; r++)
                    {
                        for(l=k+1; l<n; l++)
                        {
                            p[l]=(char)(r+48);
                            if(p<=s)
                            {
                                ans++;
                            }
                            p[l]='0';
                        }
                    }
                    p[k]='0';
                }
            }
        }
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <set>
#include <vector>
#include <iomanip>
#define pb push_back
#define mp make_pair
using namespace std;
const int N = 5e6;
const int INF = 1e9;

int main() {
int n;
  scanf("%d", &n);
  if (n % 10 == 9 || n / 10 == 9) {
  	cout << "Yes";
  } else {
  	cout << "No";
  }
  return 0;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,q,t,x,s;
    scanf("%d %d",&n,&q);
    priority_queue<int>v[n];
    for(int i=0;i<q;i++)
    {
        cin>>s;
        if(s==0)
        {
            cin>>t;
            cin>>x;
            v[t].push(x);
        }
        else if(s==1)
        {
            cin>>t;
            if(v[t].size()!=0){
            cout<<v[t].top()<<endl;}
        }
        else if(s==2)
        {
            cin>>t;
            if(v[t].size()!=0){
            v[t].pop();}
        }
    }
    return 0;
}




Measured memory_bytes: 4156
#include<bits/stdc++.h> 
using namespace std; 
#define ll long long
#define pii pair<int,int>
#define ff first
#define ss second
#define vi vector<int>
#define fo(n) for(int i = 0;i < int(n);i++)
#define foo(a,b) for(int i = int(a);i <= int(b);i++)
#define mk make_pair
#define pb push_back
#define MAXN (int)1e5
#define mod 1000000007
#define all(x) x.begin(),x.end()
#define fastio ios_base:: sync_with_stdio(false)
#define inf (int)1e9

vi h(MAXN);
int dp[MAXN];

int sol(int i){
	if(i == 0) return 0;

	if(dp[i] != -1) return dp[i];

	int sj = inf;
	int lj = inf;

	if(i-1 >= 0){
		sj = abs(h[i]-h[i-1]) + sol(i-1);
	}

	if(i-2 >= 0){
		lj = abs(h[i]-h[i-2]) + sol(i-2);
	}

	dp[i] = min(lj,sj);
	return dp[i];
}

int main(){
	
	fastio;
	int n;
	cin >> n;

	fo(n) cin >> h[i];

	memset(dp,-1,sizeof(dp));
	int ans = sol(n-1);

	cout << ans << endl;

	return 0;
 }	

Measured memory_bytes: 5760
N, M = map(int,input().split())
AB = [list(map(int,input().split())) for i in range(N)]

AB.sort(key=lambda x: x[0])

ans = 0

for x in AB:
    if M <= x[1]:
        ans += x[0]*M
        break
    else:
        ans += x[0]*x[1]
        M -= x[1]

print(ans)

Measured memory_bytes: 29020
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e16+7;
int mod = 998244353;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int N,X,T;
    cin >> N >> X >> T;
    cout << (N+X-1)/X*T << endl;
}


Measured memory_bytes: 3592
#include <stdio.h>
#include <math.h>

int main(void) {
	int a, b;
	scanf("%d %d", &a, &b);
	if (a > b) {
		printf("a > b\n");
	} else if (a < b) {
		printf("a < b\n");
	} else {
		printf("a == b\n");
	}
	return 0;
}

Measured memory_bytes: 580
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int X = sc.nextInt();
		int res = 0;
		for (int a=0; a<=A; a++) {
			for (int b=0; b<=B; b++) {
				for (int c=0; c<=C; c++) {
					int total = a*500 + b*100 + c*50;
					if ( total == X ) res++;
				}
			}
		}
		System.out.println(res);
	}
}


Measured memory_bytes: 23124
#include<cstdio>
#include<iostream>
using namespace std;
const int MAXN=200001;
int n;
long long int ans=0,temp=2147483647;
long long int A[MAXN],B[MAXN];
bool flag=false;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%d%d",&A[i],&B[i]);
		if(A[i]!=B[i]) flag=true;
		if(A[i]>B[i]) temp=min(temp,B[i]);
		ans+=B[i];
	}
	ans-=temp;
	if(flag) printf("%lld",ans);
	else printf("0");
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <stdlib.h>
#define gett(y, m, d) (y * 31 * 12 + m * 31 + d)
int main(){
  int y,m,d,t;
  std::string in;
  int i=0, j = 0;
  std::cin >> in;
  i = in.find('/');
  y = atoi(in.substr(0,i).c_str());
  j = i + 1;
  i = in.find('/', j);
  m = atoi(in.substr(j,i-j).c_str());
  d = atoi(in.substr(i + 1,-1).c_str());
  t = gett(y,m,d);
  if (t <= gett(2019,4,30))
    std::cout << "Heisei";
  else
    std::cout << "TBD";
  return 0;
}

Measured memory_bytes: 256
// tested by Hightail - https://github.com/dj3500/hightail
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;

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

    int n,k;
    cin>>n>>k;
    int h[n],dp[n];
    for(int i=0;i<n;i++){
        cin>>h[i];
        dp[i]=INT_MAX;
    }
    dp[0]=0;
    for(int i=1;i<n;i++){
        for(int j=max(i-k,0);j<i;j++){
            dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]));
        }
    }
    cout<<dp[n-1];
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <iostream>
using namespace std;

int main(void)
{
    char S[5];
    scanf("%s",S);
    if((S[0]==S[1]&&S[1]!=S[2]&&S[2]==S[3])||
       (S[0]==S[2]&&S[1]==S[3]&&S[2]!=S[3])||
       (S[0]==S[3]&&S[1]!=S[3]&&S[2]==S[1]))cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}



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


def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-(n ** 0.5) // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    # if arr==[]:  # n=1のとき、[1,1]を返す
    #     arr.append([n, 1])

    return arr


# factorization(24)
## [[2, 3], [3, 1]]
##  24 = 2^3 * 3^1

gcdall = A[0]
for i in range(1, N):
    gcdall = gcd(gcdall, A[i])

# print(gcdall)
if gcdall > 1:
    print("not coprime")
    exit()

MAX = 10 ** 6 + 1
num = [False] * MAX
A = sorted(A)[::-1]
primeset = set()
for a in A:
    if a == 1:
        continue
    if num[a]:
        print("setwise coprime")
        exit()
    fact = factorization(a)
    for p, nn in fact:
        if p == 1:
            continue
        if p in primeset:
            continue
        primeset.add(p)
        for j in range(p, MAX, p):
            num[j] = True

print("pairwise coprime")


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

void solve(string S){
	// string s1 = S;
	// while(true) {
	// 	string s2 = "";
	// 	for (int i = 0; i<s1.length(); i++) {
	// 		if (i == s1.length()-1) s2 += s1[i];
	// 		else if (s1[i] != s1[i+1]) {
	// 			i++;
	// 		} else {
	// 			s2 += s1[i];
	// 		}
	// 	}
	// 	if (s1 == s2) break;
	// 	s1 = s2;
	// }
	int a = 0, b = 0;
	for (int i = 0; i < S.length(); i++) {
		if (S[i] == '0') a++; else b++;
	}
	cout << S.length()-abs(a-b) << "\n";
}

int main(){
	string S;
	cin >> S;
	solve(S);
	return 0;
}


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

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

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

    int N; cin >> N;
    ll data[N]; F0R(i, N) cin >> data[i];

    ll dp[N][2];
    F0R(i, N) {
        dp[i][0] = -1 * 1e16;
        dp[i][1] = -1 * 1e16;
    }
    dp[1][0] = data[0];
    dp[1][1] = -1 * data[0];
    FOR(i, 2, N) {
        int cur = data[i-1];
        dp[i][0] = cur + dp[i-1][0];
        dp[i][1] = dp[i-1][0] - cur;
        cur = -1 * cur;
        dp[i][0] = max(dp[i][0], dp[i-1][1] + cur);
        dp[i][1] = max(dp[i][1], dp[i-1][1] - cur);

    }

    ll ans = dp[N-1][0] + data[N-1];
    ans = max(ans, dp[N-1][1] - data[N-1]);
    cout << ans << endl;

    return 0;
}

// read the question correctly (ll vs int)
// template by bqi343

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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

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

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

  ll N, M;
  cin >> N >> M;
  vector<ll> A(N);
  for(int i = 0; i < N; i++) cin >> A[i];  

  sort(A.begin(), A.end());

  // M個以上となる最小値を求める

  ll left = -1;
  ll right = 2 * A[N-1] + 1;

  ll tmp_cnt = 0;
  while(right - left > 1){
    
    ll mid = left + (right - left) / 2;

    ll cnt = 0;
    // mid以上が、何個あるか数える

    for(int i = 0; i < N; i++){
      auto itr = lower_bound(A.begin(), A.end(), mid - A[i]);
      cnt += distance(itr, A.end());
    }

    if(cnt < M){
      right = mid;
      tmp_cnt = cnt;
    }else{
      left = mid;
    }
  }

  // cout << right << endl;

  // right以上のやつを足し合わせる
  vector<ll> sumA(N);
  sumA[0] = A[0];
  for(int i = 0; i < N-1; i++){
    sumA[i+1] = sumA[i] + A[i+1];
  }

  ll ans = 0;
  for(int i = 0; i < N; i++){
    auto itr = lower_bound(A.begin(), A.end(), right - A[i]);
    int num = distance(itr, A.end());
    if(num > 0){
      ll sumAm = 0;
      if(N-num-1 >= 0){
        sumAm = sumA[N-num-1];
      }else{
        sumAm = 0;
      }
      ans += num * A[i] + (sumA[N-1] - sumAm);
    }
  }
  
  ans += (M-tmp_cnt) * left;

  cout << ans << endl;



  return 0;
}


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

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

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

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

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

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

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

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

fn main() {
    input! {
        n: i64,
        a: i64,
        b: i64,
    }
    println!("{}", std::cmp::min(n * a, b));
}

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

using namespace std;

typedef long long ll;

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

    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
    }

    vector<int> gridrow(W, 0);
    vector<vector<int> > grid(H, gridrow);

    int cur = 0;
    for(int i=0;i<N;i++){
        for(int t=0;t<A[i];t++){
            int r = cur/W;
            int c = cur%W;
            if(r%2==1) c = (W-1)-c;
            grid[r][c] = i+1;
            cur++;
        }
    }

    for(int y=0;y<H;y++){
        for(int x=0;x<W;x++){
            cout << grid[y][x] << " ";
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 384
#pragma region header
#include <bits/stdc++.h>
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 rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr int inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
bool isprime(int n) { //素数判定
    if(n==1)return false;
    if(n==2)return true;
    for(int i = 2;i<=sqrt(n);i++) {
        if(n%i==0) return false;
    }
    return true;
}
/* ----------------------end----------------------- */
#pragma endregion

signed main() {
    int n;cin >> n;
    vi a(n),b(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    int sa=0;//変えるべき量
    vi v;//多い所
    int count=0;
    rep(i, n) {
        if(a[i]<b[i]) sa+=b[i]-a[i],count++;
        else if(a[i]>b[i]) v.pb(a[i]-b[i]);
    }
    if(count==0) {
        cout << "0\n";
        return 0;
    }
    resort(v);
    rep(i, v.size()) {
        sa-=v[i];
        if(sa<=0) {
            cout << i+1+count << endl;
            return 0;
        }
    }
    cout << "-1\n";
    return 0;
}

Measured memory_bytes: 5464
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,dis[N],inq[N];
void spfa() {
	queue<int> Q;
	for (int i=1;i<=9;++i) dis[i]=i,Q.push(i);
	while (!Q.empty()) {
		int u=Q.front(); Q.pop(); inq[u]=0;
		for (int i=0;i<10;++i) {
			int v=(u*10+i)%n;
			if (dis[v]>dis[u]+i) {
				dis[v]=dis[u]+i;
				if (!inq[v]) {
					inq[v]=1;
					Q.push(v);
				}
			}
		}
	}
}
int main() {
	memset(dis,63,sizeof dis);
	scanf("%d",&n);
	spfa();
	printf("%d\n",dis[0]);
}

Measured memory_bytes: 1408
// C.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	cin >> n;

	vector<long long> a(n);
	vector<long long> b(n);

	for (int i = 0; i < n; i++) {
		cin >> a[i];
		b[i] = a[i] - (i+1);
		//cout << b[i] << endl;
	}

	sort(b.begin(), b.end());

	long long x = b[n / 2];

	long long sum = 0;
	//cout << x << endl;
	for (int i = 0; i < n; i++) {
		sum += abs(b[i] - x);
	
	}
	cout << sum << endl;


}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


Measured memory_bytes: 6400
#include<stdio.h>
#include<string.h>
int main() {

	char s[1001], t[1001];
	int count = 0, i, j, ans = 0;

	scanf("%s%s", s, t);

	for (i = 0; i <= strlen(s) - strlen(t); i++) {
		for (j = 0; j < strlen(t); j++) {
			if (s[i + j] == t[j]) {
				count++;
			}
		}
		if (ans < count) {
			ans = count;
		}
		count = 0;
	}

	printf("%d", strlen(t) - ans);

	return 0;
}

Measured memory_bytes: 2160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2005;
int dp[N][2];
int a[N],n;
int dfs(int pos,int f)
{
    if(dp[pos][f]!=-1)return dp[pos][f];
    int &ans=dp[pos][f];
    if(pos==n)return ans=abs(a[n-1]-a[n]);
    ans=abs(a[pos-1]-a[n]);
    for(int i=pos+1; i<=n; i++)
    {
        if(!f)ans=max(ans,dfs(i,1));
        else ans=min(ans,dfs(i,0));
    }
    return ans;
}
int main()
{
    int z;
    cin>>n>>z>>a[0];
    for(int i=1; i<=n; i++)
        cin>>a[i];
    memset(dp,-1,sizeof(dp));
    cout<<dfs(1,0);
    return 0;
}


Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;

namespace SolutionCS
{
    class Program
    {
        class CountedHashSet
        {
            public class Counter
            {
                public Counter()
                {
                    count = 1;
                }

                public int count { get; set; }
            }


            public Dictionary<int, Counter> keySet;

            public CountedHashSet()
            {
                keySet = new Dictionary<int, Counter>();
            }

            public void Add(int key)
            {
                Counter c;

                if (keySet.TryGetValue(key, out c))
                {
                    c.count++;
                }
                else
                {
                    keySet.Add(key, new Counter());
                }
            }

            public int GetKeyCount(int key)
            {
                Counter c;

                if (keySet.TryGetValue(key, out c))
                {
                    return c.count;
                }

                return 0;
            }
        }

        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            CountedHashSet hs = new CountedHashSet();

            for (int i = 0; i < N; i++)
            {
                int v = int.Parse(Console.ReadLine());
                hs.Add(v);
            }

            int ans = 0;
            foreach (KeyValuePair<int, CountedHashSet.Counter> e in hs.keySet)
            {
                if ( (e.Value.count % 2) != 0)
                {
                    ans++;
                }
            }


            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 26972
#include<algorithm>
#include<cstdio>
#include<vector>
#define ll long long
using namespace std;
vector<pair<ll, ll>> vt;
vector<pair<ll, ll>>vt1;
int main()
{
	ll n;
	scanf("%lld", &n);
	ll sum = 0;
	ll gap = 1234567890;
	for (int i = 0; i < n; i++)
	{
		ll q, w;
		scanf("%lld %lld", &q, &w);
		sum += q;
		if (q < w)
			vt.push_back({ q,w });
		else {
			if (q > w)
				gap = min(gap, w);
			vt1.push_back({ w,q });
		}
	}
	if (vt1.size() == n)
	{
		puts("0");
		return 0;
	}
	sum -= gap;
	printf("%lld\n", sum);
}


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

int main(){
    double sum=0;
    int N;
    cin >> N;
    int i;
    int a[N];
    for(i=0;i<N;i++)cin >>a[i];
    for(i=0;i<N;i++)sum += 1.0/(double)(1.0*a[i]);
      cout << fixed << setprecision(16);
      cout << 1.0/sum << endl;
}

Measured memory_bytes: 256