akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
    public static void main(String [] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int [] a = new int[n + 1];
        for (int i = 1; i <= n; ++i) {
            a[i] = scanner.nextInt();
        }
        int deletedNum = 0;
        for (int i = 1; i <= n; ++i) {
            if (a[i] != i - deletedNum) {
                ++deletedNum;
            }
        }
        if (deletedNum == n) {
            deletedNum = -1;
        }
        System.out.println(deletedNum);
    }
}


Measured memory_bytes: 80388
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;



int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int x, y;
    cin >> x >> y;

    cout << (x + y / 2) << '\n';

    return 0;
}

Measured memory_bytes: 256
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 1
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"

S = v()

a = len(S)

if a % 2 == 0:
    ra = a//2
else:
    ra = a//2

for i in range(ra):
    if S[i] != S[-(i+1)]:
        cnt += 1

print(cnt)

Measured memory_bytes: 10204
main(){
	double a,b,c,d,e,f,g,h;
	for(scanf("%lf",&a);~scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f,&g,&h);)
		puts(fabs((c-a)*(h-f)-(d-b)*(g-e))>1e-10?"NO":"YES");
	exit(0);
}

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

int main(){
    float x,n;
    string u;
    cin >> n;

    float sum = 0;

    for(int i = 0;i < n;i ++){
        cin >> x >> u;
        if(u == "JPY"){
            sum += x;
        }else{
            sum += x * 380000;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

const int N = 2019, A = 10;
int tr[N][A];
ll dp[2][N];

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

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < A; j++) {
            tr[i][j] = (i * 10 + j) % N;
        }
    }

    string s;
    cin >> s;

    ll ans = 0;

    for (int i = 0; i < s.size(); i++) {
        memset(dp[(i & 1) ^ 1], 0, sizeof(dp[0]));

        int d = s[i] - '0';
        dp[i & 1][0]++;
        
        for (int j = 0; j < N; j++) {
            dp[(i & 1) ^ 1][tr[j][d]] += dp[i & 1][j];
        }

        ans += dp[(i & 1) ^ 1][0];
    }

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 3844
#include <iostream>
#include <string>//
#include <vector>//
#include <map>
#include <cstdlib>
#include <numeric>
#include <algorithm>//ソート等に使用
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <thread>///////////////////
#include <queue>//幅優先等のキュー
#include <stack>
#include <bitset>

#define rep(i,m,n) for(int i=(m);i<(n);i++)
#define mer(i,m,n) for(int i=(m);i>(n);--i)

#define MOD 1000000007
//#define MOD 998244353
//#define MAX 

using namespace std;

using ll = long long int;
using ld = long double;
using std::swap;

vector<int> v;
vector<int> w;
vector<long long int> vll;
vector<long long int> wll;
//vector<vector<int>> vec(50, vector<int>(4, 0));
vector<vector<int>> vv;
vector<vector<int>> ww;

//vector<char> vc;
vector<string> vs;




int main() {
	int N;
	cin >> N;
	v.resize(4,0);
	rep(i, 0, N) {
		string S;
		cin >> S;
		if (S == "AC")++v[0];
		else if (S == "WA")++v[1];
		else if (S == "TLE")++v[2];
		else ++v[3];
	}
	cout << "AC x " << v[0] << '\n';
	cout << "WA x " << v[1] << '\n';
	cout << "TLE x " << v[2] << '\n';
	cout << "RE x " << v[3] << '\n';


	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll x,ans,go;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> x;
	go = 1;
	while(x) {
		ans += go;
		go *= 2;
		x /= 2;
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int a,b,c,d,e,k;
	scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &k);
	if(e-a<=k) printf("Yay!");
 	else printf(":(");
  
  	return 0;
}

Measured memory_bytes: 128
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

S = input()

A = set(S)

for x in ascii_lowercase:
	if not x in A:
		print(S+x)
		break
else:
	B = [S[-1]]
	for i in range(len(S)-2, -1, -1):
		if bisect(B, S[i]) == len(B):
			insort(B, S[i])
		else:
			print(S[:i]+B[bisect(B, S[i])])
			break
	else:
		print(-1) 



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

int main() {
  int d;
  cin >> d;
  if(d == 22){
    cout << "Christmas Eve Eve Eve" << endl;
  }else if(d == 23){
    cout << "Christmas Eve Eve" << endl;
  }
  else if (d == 24){
    cout << "Christmas Eve" << endl;
  }
  else{
    cout << "Christmas" << endl;
  }
}

Measured memory_bytes: 3568
#include <iostream>

using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	int i;
	int t = 1;
	for(i = 2; i < 1000; i++) {
		t += i;
		if(b - a == i) break;
	}
	cout << t - b << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void)
{
	char str[2049], temp[2049];
	int i, j, flag;
	
	scanf("%[^\n]", str);
	getchar();
	
	i = flag = 0;
	
	while (str[i] != '\0'){
		j = 0;
		while (str[i] != ' ' && str[i] != ',' && str[i] != '.'){
			temp[j] = str[i];
			j++;
			i++;
		}
		
		temp[j] = '\0';
		
		if (3 <= strlen(temp) && strlen(temp) <= 6){
			if (flag != 0) printf(" ");
			printf("%s", temp);
			flag = 1;
		}
		
		i++;
	}
	printf("\n");
	return (0);
}

Measured memory_bytes: 0
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    auto xab = readints;
    int x = xab[0], a = xab[1], b = xab[2];

    if (b - a <= 0) writeln("delicious");
    else if (b - a <= x) writeln("safe");
    else writeln("dangerous");
}


Measured memory_bytes: 256
use proconio::{
   fastout, input,
   marker::{Bytes, Chars, Isize1, Usize1},
};

use std::collections::HashSet;

fn main() {
   input! {
      n:usize,
      mut a:[usize;n]
   }
   let mut s = HashSet::new();
   a.sort();
   let mut table = [true; 1000001];

   let mut ans = 0_usize;
   for i in a {
      if table[i] {
         if s.contains(&i) {
            ans -= 1;
            table[i] = false;
         } else {
            ans += 1;
            s.insert(i);
            let mut buf = i + i;
            while buf < table.len() {
               table[buf] = false;
               buf += i;
            }
         }
      }
   }
   println!("{}", ans);
}


Measured memory_bytes: 10380
#%%
n, a = map(int, input().split())
x = list(map(int, input().split()))
x.insert(0, 0)

dp = [[[0] * max((max(x)*n+1), a*n+1) for _ in range(n+1)] for _ in range(n+1)]
dp[0][0][0] = 1
#print(dp)

for i in range(1, n+1):
    for j in range(0, n+1):
        for k in range(0, max(x)*n+1):
            if i == 0:
                pass
            else:
                if j == 0:
                    dp[i][j][k] = dp[i-1][j][k]
                else:
                    if k < x[i]:
                        dp[i][j][k] = dp[i-1][j][k]
                    else:
                        dp[i][j][k] = dp[i-1][j][k] + dp[i-1][j-1][k-x[i]] 
                        #print(x[i])

ans = 0
i = n
for j in range(n+1):
    ans += dp[i][j][j*a]
ans -= 1
print(ans)


#for i in range(n+1):
#    print(dp[i])


Measured memory_bytes: 93788
#include "bits/stdc++.h"
using namespace std;
int N;
vector<int>to[200005];
vector<int> ans;
void dfs(int v, int p = -1) {
	for (int e : to[v]) {
		if (p == e) {
			continue;
		}
		ans[e] += ans[v];
		dfs(e, v);
	}
}

int main() {
	int N, Q;
	cin >> N >> Q;
	for (int n = 0; n < N - 1; ++n) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		to[a].push_back(b);
		to[b].push_back(a);
	}	
	ans.resize(N);
	for (int n = 0; n < Q; ++n) {
		int p, q;
		cin >> p >> q;
		p--;
		ans[p] += q;
	}	
	dfs(0);
	for (int n = 0; n < N ; ++n) {
		cout << ans[n] << endl;
	}
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> iP;

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = 99999999;
const int MAX_N = int(1e5) + 5;
const double EPS = 1e-8;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)

int main() {
    int n,a;
    cin >> n >> a;
    cout << n*n-a << endl;
    return 0;
}


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

from collections import deque

deq = deque(a_list)
res = []
while len(deq) > 2:
    min_num = deq.popleft()
    max_num = deq.pop()
    if min_num < 0 and max_num > 0:
        ne = deq.pop()
        if ne >= 0:
            res.append((min_num, ne))
            min_num -= ne
            deq.appendleft(min_num)
            deq.append(max_num)
        else:
            res.append((max_num, ne))
            max_num -= ne
            deq.append(max_num)
            deq.appendleft(min_num)
    else:
        if max_num <= 0:
            res.append((max_num, min_num))
            max_num = max_num - min_num
            deq.append(max_num)
        else:
            res.append((min_num, max_num))
            min_num = min_num - max_num
            deq.appendleft(min_num)

tmp1 = deq[0]
tmp2 = deq[1]
res.append((max(tmp1, tmp2), min(tmp2, tmp1)))
ans = max(tmp1, tmp2) - min(tmp2, tmp1)
print(ans)
for x,y in res:
    print(x, y)


Measured memory_bytes: 20328
import java.util.*

fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val D = readLine()!!.split(" ").map { it.toInt() }

    val d = IntArray(13) { 0 }
    d[0] = 1

    D.forEach {
        d[it]++
    }

    var res = 0

    val st = TreeSet<Int>()
    val solo = TreeSet<Int>()

    for (s in 0 until (1 shl 13)) {
        var list = ArrayList<Int>()
        list.addAll(Array(d[0]) {0})
        list.addAll(Array(d[12]) {12})

        for (i in 1..11) {
            if (d[i] == 0) continue

            if (d[i] > 1) {
                list.add(i)
                list.addAll(Array(d[i] - 1) { 24 - i })
            } else if ((s shr i) and 1 == 1) {
                list.add(i)
            } else {
                list.add(24 - i)
            }
        }
        var h = 24
        for (i in list.indices) for (j in (i + 1) until list.size) {
            val d = Math.abs(list[i] - list[j])
            h = Math.min(h, Math.min(d, 24 - d))
        }
        res = Math.max(res, h)
    }

    println(res)
}


Measured memory_bytes: 43924
#include <vector>
#include <iostream>
#include <stack>
#include <string>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <queue>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef pair<ll, ll> P;

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

vector<vector<int>> g;
vector<ll> c;
vector<ll> sum;

void dfs(int v, ll s) {
	if (sum[v] >= 0) {
		return;
	}
	sum[v] = s + c[v];
	for (auto e : g[v]) {
		dfs(e, sum[v]);
	}
}

vector<vector<int>> ps;
priority_queue<int, vector<int>, std::less<int>> q;

int main(void)
{
	int n, m;
	cin >> n >> m;
	ps.resize((int)2e5+5);
	rep(i, n) {
		int a, b;
		cin >> a >> b;
		ps[a].push_back(b);
	}
	ll sum = 0;
	for (int i = 1; i <= m; i++) {
		for (auto e : ps[i]) {
			q.push(e);
		}
		if (!q.empty()) {
			sum += q.top(); q.pop();
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 7936
// 2011/09/19 Tazoe

#include <iostream>
using namespace std;

int main()
{
	int t1, t2, t3, t4;
	cin >> t1 >> t2 >> t3 >> t4;

	int total = t1+t2+t3+t4;

	cout << total/60 << endl;
	cout << total%60 << endl;

	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>

int main(){
    std::string s;
    int ans = 0;

    std::cin >> s;

    for(int i = 0; i < s.size() - 1; i++){
        if(s.at(i) != s.at(i + 1)){
            ans++;
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 512
import numpy as np


n, m, k = map(int, input().split())
A = [0] + list(map(int, input().split()))
B = list(map(int, input().split()))

cumA = np.cumsum(A)
cumB = np.cumsum(B)

cumA = cumA[cumA <= k]
cumB = cumB[cumB <= k]

candidates = np.arange(len(cumA)) + np.searchsorted(cumB, k-cumA, side="right")
print(candidates.max())


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

int main() {
  int r, g, b;
  cin >> r >> g >> b;
  int ans = r * 100 + g * 10 + b;
  if(ans % 4 == 0){
    cout << "YES" <<endl;
  }
  else{
    cout << "NO" <<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    int n,y;
    cin>>n>>y;
    int a[3];
    memset(a,0,sizeof(a));
    int n1=n;
    int y1=y;
    a[2]=y1/10000;
    y1-=a[2]*10000;
    a[1]=y1/5000;
    y1-=a[1]*5000;
    a[0]=y1/1000;
    y1-=a[0]*1000;
    int sum=a[0]+a[1]+a[2];
    if(sum==n)
    {
        cout<<a[2]<<" "<<a[1]<<" "<<a[0];
        return 0;
    }
    else
    {
        if(n>y/1000)
        {
            cout<<"-1 -1 -1";
            return 0;
        }
        else
        {
            while(n-sum>=9 && a[2]>0)
            {
                a[2]--;
                a[0]+=10;
                sum+=9;
                if(sum==n)
                {
                    cout<<a[2]<<" "<<a[1]<<" "<<a[0];
                    return 0;
                }
            }
            while(n-sum>=4 && a[1]>0)
            {
                a[1]--;
                a[0]+=5;
                sum+=4;
                if(sum==n)
                {
                    cout<<a[2]<<" "<<a[1]<<" "<<a[0];
                    return 0;
                }
            }
            while(n-sum>=1 && a[2]>0)
            {
                a[2]--;
                a[1]+=2;
                sum+=1;
                if(sum==n)
                {
                    cout<<a[2]<<" "<<a[1]<<" "<<a[0];
                    return 0;
                }
            }
            cout<<"-1 -1 -1";
            return 0;
        }
    }
}


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

using namespace std;

const int MAX = 100000000;

int minEnergy(int h, const vector<int>& A, const vector<int>& B, vector<int>& memo) {
    if (h <= 0) {
        return 0;
    }
    if (memo[h] > 0) {
        return memo[h];
    }

    int ret = MAX;
    for (int i = 0; i < A.size(); ++i) {
        int e_i = minEnergy(h - A[i], A, B, memo) + B[i];
        ret = min(ret, e_i);
    }
    memo[h] = ret;
    return ret;
}

void Main() {
    int H, N;
    cin >> H >> N;
    vector<int> A(N, 0), B(N, 0);
    for (int i = 0; i < N; ++i) {
        cin >> A[i] >> B[i];
    }

    vector<int> memo(H + 1, -1);
    int ans = minEnergy(H, A, B, memo);
    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 4472
using System;

namespace atcoder1
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int X, A;
            X = int.Parse(input[0]);
            A = int.Parse(input[1]);

            if (X < A)
            {
                Console.WriteLine(0);
            }
            else
            {
                Console.WriteLine(10);
            }
        }
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<cstdio>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int INF = 1e9 + 7;
//約数列挙
vector<ll>calc_divisor(ll n) {
	vector<ll>res;
	for (ll i = 1LL; i*i <= n; ++i) {
		if (n%i == 0) {
			res.push_back(i);
			ll j = n / i;
			if (j != i)res.push_back(j);
		}
	}
	sort(res.begin(), res.end());
	return res;
}
int main() {
	ll N, M;
	cin >> N >> M;
	vector<ll>div = calc_divisor(M);

	//Mの約数dであって、d*N<=Mとなる最大のdを求める
	ll res = 1;
	for (ll i = 0; i < div.size(); ++i) {
		if (div[i]*N <= M) {
			res = max(res, div[i]);
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
count = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]

n = int(input())


b_list=[]
f_list=[]
r_list=[]
v_list=[]
while n > 0:
  b, f, r, v = map(int, input().split())
  b_list.append(b)
  f_list.append(f)
  r_list.append(r)
  v_list.append(v)
  n = n-1

for (blist,flist,rlist,vlist) in zip(b_list,f_list,r_list,v_list):
  count[blist-1][flist-1][rlist-1] = count[blist-1][flist-1][rlist-1] + vlist

for i in range(0, 4):
  for j in range(0, 3):
    for k in range(0, 10):
      print("",count[i][j][k],end="")
    print()
  if i != 3:
    print("####################")


Measured memory_bytes: 5648
#include <cstdio>
int main(){
	int n;
	scanf("%d", &n);
	int a[n], s = 0;
	for (int i = 0; i < n; i++){
		scanf("%d", &a[i]);
		if (i == 0) continue;
		s ^= (a[0] ^ a[i]);
	}
	for (int i = 0; i < n; i++) printf("%d ", a[i] ^ s);
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int R;
  cin >> R;
  if(R < 1200)
    cout << "ABC" << endl;
  else if(R < 2800)
    cout << "ARC" << endl;
  else
    cout << "AGC" << endl;
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	const maxWord = (1 << 30)
	buf := []byte{}
	sc.Buffer(buf, maxWord)
	sc.Split(bufio.ScanWords)
}

func input() string {
	sc.Scan()
	return sc.Text()
}

func gcd(x, y int) int {
	if x < y {
		x, y = y, x
	}
	for y > 0 {
		r := x % y
		x = y
		y = r
	}
	return x
}

func gcdList(x []int) int {
	ret := x[0]
	for i := 1; i < len(x); i++ {
		ret = gcd(ret, x[i])
	}
	return ret
}

func solve(n, k int, a []int) bool {
	sort.Ints(a)
	if a[len(a)-1] < k {
		return false
	}

	upNear := a[0]
	for _, v := range a {
		upNear = v
		if v == k {
			return true
		} else if v > k {
			break
		}
	}
	diff := upNear - k
	if diff%gcdList(a) == 0 {
		return true
	}
	return false
}

func main() {
	n, _ := strconv.Atoi(input())
	k, _ := strconv.Atoi(input())
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i], _ = strconv.Atoi(input())
	}
	if solve(n, k, a) {
		fmt.Println("POSSIBLE")
	} else {
		fmt.Println("IMPOSSIBLE")
	}
}


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

using namespace std;

int main(){
    int n;
    string s, t, st;
    cin >> n >> s >> t;
    for(int i=0; i<n; i++){
        st += s[i];
        st += t[i];
    }

    cout << st << endl;
    return 0;
}


Measured memory_bytes: 256
H,W=map(int,input().split())
N=int(input())
l=list(map(int,input().split()))
l2=[]
lt=[]
a=1
for x in l:
  for i in range(x):
    if len(lt)>=W:
      if len(l2)%2==1:
        lt.reverse()
        l2.append(lt)
      else:
        l2.append(lt)
      lt=[][:]
      lt.append(a)
    else:
      lt.append(a)
  a+=1
if len(lt)>0:
  if len(l2)%2==1:
    lt.reverse()
    l2.append(lt)
  else:
    l2.append(lt)
for x in l2:
  print(' '.join([str(a) for a in x]))

Measured memory_bytes: 3572
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val N = nextInt()
    val S = next()
    var a = 0
    var aa = 0
    for (i in S.indices) {
        if (S[i] == '(') {
            aa++
        } else if (aa > 0) {
            aa--
        } else {
            a++
        }
    }
    var b = 0
    var bb = 0
    for (i in S.length - 1 downTo 0) {
        if (S[i] == ')') {
            bb++
        } else if (bb > 0) {
            bb--
        } else {
            b++
        }
    }
    println("(".repeat(a) + S + ")".repeat(b))
}

Measured memory_bytes: 31872
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)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (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")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        q: usize,
        es: [(usize1, usize1); n - 1],
        qs: [(usize1, usize); q]
    }
    let mut t = vec![vec![]; n];
    for &(a, b) in &es {
        t[a].push(b);
        t[b].push(a);
    }
    let mut c = vec![0; n];
    for &(v, x) in &qs {
        c[v] += x;
    }
    dfs(0, 0, &t, &mut c);
    print!("{}", c[0]);
    for i in 1..n {
        print!(" {}", c[i]);
    }
    println!("");
}

fn dfs(r: usize, p: usize, t: &Vec<Vec<usize>>, c: &mut Vec<usize>) {
    for &v in &t[r] {
        if v == p {
            continue;
        }
        c[v] += c[r];
        dfs(v, r, t, c);
    }
}


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

int main() {
	long long n,m,i,j,k,ans,cur,res;
	cin >> n;
	vector<long long> a(n);
	
	for(i=0; i<n; i++){
		cin >> a[i];
		if(a[i]==0){
			cout << 0 << endl; return 0;
		}
	}
	
	cur=a[0];
	for(i=1; i<n; i++){
		res=a[i];
		if(cur*res>1000000000000000000 || double(cur)*double(res)+0.1>1e18){
			cout << -1 << endl; return 0;
		}else{
			cur*=res;
		}
	}
	cout << cur << endl;
	return 0;
}


Measured memory_bytes: 4000
#include<cstdio>
#include<iostream>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<deque>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<limits>
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
using namespace std;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define rep(I,N) up(I,0,N-1)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
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;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                                      ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<"\n";}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<"\n";}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<"\n";}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<"\n";}
inline void                                              out(ld p){printf("%.12Lf\n",p);}
template<class T>inline void outml(T p){for_each(all(p),out<decltype(p[0])>);}//ml=multi line
template<class T>inline void outol(T V){auto n=V.size();rep(i,n)cout<<V[i]<<" \n"[i==n-1];}//ol=one line
inline void solve(void){
  string s;
  in(s);
  out(s=="ABC"?"ARC":"ABC");
}
int main(void){
  BEGIN;
  solve();
  END;
}


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

using namespace std;

int main()
{
    int n , m , k;
    cin >> n >> m >> k;
    int p = k;
    while(k--){
        if(n & 1){
            n--;
            m += n/2;
            n -= n/2;
        }
        else{
                m += n/2;
                n -= n/2;
        }
        p--;
        if(p<=0)break;
        if(m & 1 and k>=0){
            m--;
            n += (m/2);
            m -= m/2;
        }
        else{
                n += (m/2);
                m -= m/2;
        }
        p--;
        if(p<=0)break;
    }
    cout << n << " " << m << endl;
    return 0;
}


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

#ifdef local
template <class T> void _E(T x) { cerr << x; } void _E(double x) { cerr << fixed << setprecision(6) << x; } void _E(string s) { cerr << "\"" << s << "\""; } template <class A, class B> void _E(pair<A, B> x) { cerr << '('; _E(x.first); cerr << ", "; _E(x.second); cerr << ")"; } template <class T> void _E(vector<T> x) { cerr << "["; for (auto it = x.begin(); it != x.end(); ++it) { if (it != x.begin()) cerr << ", "; _E(*it); } cerr << "]"; }
void ERR() {} template <class A, class... B> void ERR(A x, B... y) { _E(x); cerr << (sizeof...(y) ? ", " : " "); ERR(y...); }
#define debug(x...) do { cerr << "{ "#x" } -> { "; ERR(x); cerr << "}" << endl; } while(false)
#else
#define debug(...) 114514.1919810
#endif

using ll = long long;


int main(int argc, char *argv[]) {
  cin.sync_with_stdio(false), cin.tie(nullptr);

  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  for (int i = 0, j = n - 1; i < j; ) {
    if (s[i] == s[j] && s[i] == 'R') {
      ++i;
    } else if (s[i] == s[j] && s[i] == 'W') {
      --j;
    } else if (s[i] == 'W') {
      ++ans, ++i, --j;
    } else {
      ++i, --j;
    }
  }
  cout << ans << "\n";
}



Measured memory_bytes: 3760
#include<iostream>
#include<string>
using namespace std;
int main(){
  int N,K;
  cin>>N>>K;
  string S;
  cin>>S;
  if(S[K-1]=='A'){
    S[K-1]='a';
  }
  else if(S[K-1]=='B'){
    S[K-1]='b';
  }
  else if(S[K-1]=='C'){
    S[K-1]='c';
  }
  cout<<S<<endl;
  return 0;
}

Measured memory_bytes: 256
import sys
in1 = sys.stdin.readlines()

#in1 = ['-2 -2 1 1']

sx, sy, tx, ty = map(int, in1[0].split())

lx = tx - sx
ly = ty - sy

print('U'*ly+'R'*lx+'D'*ly+'L'*lx+'L'+'U'*(ly+1)+'R'*(lx+1)+'DR'+'D'*(ly+1)+'L'*(lx+1)+'U')


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

#define LOCAL 0

#define lli long long int
#define llu unsigned long long int
#define ld long double
#define all(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define si(n) scanf("%d",&n)
#define slli(n) scanf("%lld",&n);
#define ss(n) scanf("%s",n);

const long double EPS = 1e-10;
const lli MOD = 1000000007ll;
const lli mod1 = 1000000009ll;
const lli mod2 = 1100000009ll;
int INF = (int)1e9;
lli INFINF = (lli)1e18;
int debug = 0;
long double PI = acos(-1.0);

using namespace std;

lli bit_count(lli _x){lli _ret=0;while(_x){if(_x%2==1)_ret++;_x/=2;}return _ret;}
lli bit(lli _mask,lli _i){return (_mask&(1<<_i))==0?0:1;}
lli powermod(lli _a,lli _b,lli _m=MOD){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a)%_m;_b/=2;_a=(_a*_a)%_m;}return _r;}
lli add(lli a,lli b,lli m=MOD){lli x=a+b;while(x>=m)x-=m;while(x<0)x+=m;return x;}
lli sub(lli a,lli b,lli m=MOD){lli x=a-b;while(x<0)x+=m;while(x>=m)x-=m;return x;}
lli mul(lli a,lli b,lli m=MOD){lli x=a*1ll*b;x%=m;if(x<0)x+=m;return x;}

lli N,x;
lli a[100010];

int main()
{
if(LOCAL){
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    debug = 1;
}
    srand (time(NULL));

    slli(N);
    slli(x);
    for(int i=1;i<=N;i++)
        slli(a[i]);
    lli ans = 0;
    for(int i=1;i<=N;i++)
        if(a[i] > x){
            ans += a[i] - x;
            a[i] = x;
        }
    for(int i=2;i<=N;i++){
        if(a[i]+a[i-1]>x){
            ans += a[i]+a[i-1]-x;
            a[i] = x - a[i-1];
        }
    }
    cout<<ans;

    return 0;
}


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

typedef long long ll;

int main()
{
    int N;
    cin >> N;
    vector<pair<int, int>> jobs(0);
    for(int i = 0; i < N; i++)
    {
        int a, b;
        cin >> a >> b;
        jobs.push_back(make_pair(b, a));
    }
    sort(jobs.begin(), jobs.end());
    ll time = 0;
    for(int i = 0; i < N; i++)
    {
        pair<int, int> job = jobs.at(i);
        if(job.first < job.second + time){
            cout << "No" << endl;
            return 0;
        }
        time += job.second;
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 2420
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include<stack>
#include<sstream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<list>
#include<numeric>
#include <utility>
typedef long long ll;

#define pi 3.14159265358979323846
#define VI vector<int>
#define VLL vector<long long>
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
const ll MOD = 1e9 + 7;
const ll unllMOD = 1e18;
using namespace std;
template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}

template<typename T>
T binarysearch(vector<T> A, T key) {
	ll left = 0;ll right = 4;ll mid;
	while (left < right) {
		mid = (left + right) / 2;
		if (key == A[mid]) return 1;
		if (key > A[mid]) left = mid + 1;
		else if (key < A[mid]) right = mid;
	}
	return 0;
}

template<typename T>
T finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}
ll frac(ll n)//階乗
{
	if (n == 0) {
		return 1;
	}
	return (n * frac(n - 1)) % MOD;
}

template<typename T>
T keta(T a) {
	ll kazu = 1;
	while (1) {
		if (a / 10 != 0) { a /= 10;kazu++; }
		else break;
	}
	return kazu;
}//桁数


template<typename T>
T nCr(ll n, T r) {
	ll ans = 1;
	for (int i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (int i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
/*char r[4];
int yaju[4];
char op[3];
int sum = 0;
scanf("%s", r);
for (int i = 0;i < 4;i++) {
	yaju[i] = r[i] - '0';
}
*///map < string, ll> s;

/*i++ずつずらす
a[0] a[1] a[2]//a[1] a[2] a[3]
a[0] a[2] a[4]//a[1] a[3] a[5]
/*if (N % 2 != 0)a = N / 2;
else a = N / 2 - 1;
for (int i = 1;i <= a;i++) {
	for (int j = 0;j < N - (i * 2);j++) {
		if (S[j] != S[j + i] && S[j + i * 2] != S[j] && S[j + i] != S[j + i * 2]) sum--;
		if (sum == 0)break;
	}
}*/

//mapの使い方
/*map<int, int> mp;
for (int i = 0; i < N; i++)
	mp[a[i]]++;

int ans = 0;
for (auto p : mp) {
	int x = p.first;
	int n = p.second;
	if (n < x) ans += n;
	else ans += n - x;
}*/
//cout << std::fixed << std::setprecision(12) <<<< endl;

int main() {
	ll X;
	cin>>X;
	ll money=100;
	for(ll i=1;;i++){
		money=money/100+money;
		if(money>=X){cout<<i<<endl;break;}
	}
}

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

using namespace std;
typedef long long ll;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define each(i,mp) for(auto& i:mp)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
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; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;
const ll m=1LL<<32;

int main(){

  ll n;cin>>n;
  string s;cin>>s;
  vector<ll>sum(n+1,0);
  rep(i,0,n){
    sum[i+1]=sum[i]+(s[i]=='#');
  }

  ll mi=INF;
  rep(i,0,n+1){
    mi=min(mi,sum[i]+((n-i)-(sum[n]-sum[i])));
    // mi=min(mi,sum[i]+((n-i)-(sum[n]-sum[i])));
  }
  out(mi);


  return 0;
}


Measured memory_bytes: 2180
n,k,s = map(int,input().split())

if s == 10**9:
    ans = [1]*n
    for i in range(k):
        ans [i] = s
else:
    ans = [s+1]*n
    for i in range(k):
        ans[i] = s

for i in ans:
    print(i,end = " ")


Measured memory_bytes: 9964
#include<iostream>

using namespace std;

int main(){
int n;
  cin>>n;
  const int m=n;
  int a[m];
  for(int i=0;i<m;i++){
  cin>>a[i];
    if((a[i]/2)*2==a[i]){

    if((a[i]/3)*3!=a[i]&&(a[i]/5)*5!=a[i]){
    cout<<"DENIED";
      return 0;
    }

    }

  }

     cout<<"APPROVED";
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<cmath>
#include<cstring>
using namespace std;
#define maxn 100100
#define inf (llg)1e18
#define llg long long 
#define yyj(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
llg n,m,ans=inf,a[maxn],qz[maxn];

inline int getint()
{
       int w=0,q=0; char c=getchar();
       while((c<'0' || c>'9') && c!='-') c=getchar(); if(c=='-') q=1,c=getchar(); 
       while (c>='0' && c<='9') w=w*10+c-'0', c=getchar(); return q ? -w : w;
}

void work(llg sum)
{
	qz[1]=a[1];
	for (llg i=2;i<=n;i++)
	{
		qz[i]=qz[i-1]+a[i];
		if (qz[i-1]>0 && qz[i]>=0)
		{
			sum+=abs(-1-qz[i]); qz[i]=-1;
		}
		if (qz[i-1]<0 && qz[i]<=0)
		{
			sum+=abs(1-qz[i]); qz[i]=1;
		}
	}
	ans=min(ans,sum);
}

int main()
{
//	yyj("A");
	cin>>n;
	for (llg i=1;i<=n;i++) a[i]=getint();
	if (a[1]==0)
	{
		a[1]=1;
		work(1);
		a[1]=-1;
		work(1);
	}
	else
	{
		work(0);
		if (a[1]>0) 
		{
			llg v=a[1];
			a[1]=-1;
			work(v+1);
		}
		else
		{
			llg v=a[1];
			a[1]=1;
			work(1-v);
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;

int N;
ll h[5010],p[5010],dp[5010][5010] = {},inf = 1e18;
vector<P> v;

int main(){
    cin >> N;
    for(int i=1;i<=N;i++){
        cin >> h[i] >> p[i];
        v.push_back(P(h[i]+p[i],i));
    }
    v.push_back(P(0,0));
    sort(v.begin(),v.end());
    for(int i=0;i<=N;i++){
        for(int j=0;j<=N;j++){
            dp[i][j] = inf;
        }
    }
    dp[0][0] = 0;
    for(int i=1;i<=N;i++){
        int id = v[i].second;
        for(int j=0;j<=i;j++){
            if(j<i && dp[i-1][j]<=h[id]){
                dp[i][j+1] = min(dp[i][j+1],dp[i-1][j]+p[id]);
            }
            dp[i][j] = min(dp[i][j],dp[i-1][j]);
        }
    }
    int ans = 0;
    for(int i=0;i<=N;i++) if(dp[N][i]!=inf) ans = i;
    cout << ans << endl;
}

Measured memory_bytes: 196352
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os, const map<T,U>& mp){ os << "{"; for(auto& p : mp){ os << p << ","; } os << "}"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int,int>;
using vi = std::vector<int>;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    ll n,m,l; cin >> n >> m >> l;
    vector<vector<ll>> g(n,vector<ll>(n,INF));
    rep(i,m){
        int a,b; ll c;
        cin >> a >> b >> c;
        a--; b--;
        g[a][b] = c;
        g[b][a] = c;
    }

    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                g[i][j] = min(g[i][j],g[i][k]+g[k][j]);
            }
        }
    }

    vector<vi> g2(n,vi(n,INF));
    rep(i,n){
        rep(j,n){
            g2[i][j] = g[i][j];
            if(g2[i][j] > l){
                g2[i][j] = INF;
            }else{
                g2[i][j] = 1;
            }
        }
    }

    rep(k,n){
        rep(i,n){
            rep(j,n){
                g2[i][j] = min(g2[i][j], g2[i][k]+g2[k][j]);
            }
        }
    }

    int q; cin >> q;
    rep(i,q){
        int s,t; cin >> s >> t;
        s--; t--;
        if(g2[s][t] == INF){
            cout << -1 << endl;
        }else{
            cout << g2[s][t]-1 << endl;
        }
    }
}


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

using namespace std;

#define S scanf
#define P printf
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)





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






int main()
{
    FAST();

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    int i,n,ans=0;
    char s[102];
    cin >> s+1;
    n=strlen(s)-1;
    for(i=1;i<=n/2;i++)
    {
        if(s[i] != s[n-i+1])++ans;
    }
    cout << ans;
    return 0;
}


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


int main(void){
    string s;
    cin>>s;
    bool ok = false;
    rep(i,s.size()-1){
        if(s[i]=='A' && s[i+1]=='C') ok = true;
    }
    cout<<(ok ? "Yes" : "No")<<endl;
    return 0;
}


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

using namespace std;

//print 
int main()
{
    int x, y;
    
    while (true)
    {
        cin >> x >> y;
        if (x == 0 && y == 0) break; 
        if (x > y) swap(x, y);         
        cout << x << ' ' << y << endl;
      
    }
}


Measured memory_bytes: 3004
import itertools

while True:
    z = []
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        break
    for i in itertools.combinations(range(1, a + 1), 3):
        if i[0] + i[1] + i[2] == b:
            z.append(i)
    print(len(z))
    z = []



Measured memory_bytes: 5732
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
    int n,m,A[10],dp[200000],B[11]={0,2,5,5,4,5,6,3,7,6};
    cin>>n>>m;
    rep(i,m) cin>>A[i];
    rep(i,n+1) dp[i]=-1;
    dp[0]=0;
    rep(i,n)rep(j,m) if(dp[i]!=-1) dp[i+B[A[j]]]=max(dp[i]+1,dp[i+B[A[j]]]);
    vector<int> C;
    int b=n;
    while(b>0){
        int a=0,c=0;
        rep(i,m) if(dp[b-B[A[i]]]>=a&&b-B[A[i]]>=0){
            if(dp[b-B[A[i]]]>a) c=A[i];
            else c=max(c,A[i]);
            a=dp[b-B[A[i]]];
        }
        b-=B[c];
        C.push_back(c);
    }
    sort(C.begin(),C.end(),greater<int>());
    for(auto i:C) cout<<i;
}

Measured memory_bytes: 384
#include <time.h>

#include <stdlib.h>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <numeric>

using namespace std;
class UnionFind{
	int32_t *par;
	int32_t *rank;
private:
	int32_t root(int32_t num){
		if(par[num]==num){
			return num;
		}else{
			return par[num]=root(par[num]);
		}
	}
public:
	UnionFind(const int32_t size){
		par = new int32_t[size];
		rank=new int32_t[size];
		for(int32_t i=0;i<size;i++){
			par[i]=i;
			rank[i]=0;
		}
	}
	bool same(int32_t a,int32_t b){
		return root(a)==root(b);
	}
	void unite(int32_t a,int32_t b){
		if(root(a)==root(b)){
			return;
		}
		a=root(a);
		b=root(b);
		if(rank[a]<rank[b]){
			par[a]=b;
		}else if(rank[a]==rank[b]){
			par[a]=b;
			rank[b]++;
		}else{
			par[b]=a;
		}

	}
	virtual ~UnionFind(){
		delete[] par;
		delete[] rank;
	}
};
struct edge{
	int32_t v1;
	int32_t v2;
	int32_t cost;
};
bool operator<(const edge& a,const edge& b){
	return a.cost<b.cost;
}
int main() {
	int32_t n;
	cin>>n;
	vector<edge> e;
	e.reserve(n);
	int32_t **cost_matrix=new int32_t*[n];
	for(int32_t i1=0;i1<n;i1++){
		cost_matrix[i1]=new int32_t[n];
		for(int32_t i2=0;i2<n;i2++){
			int32_t temp;
			cin>>temp;
			cost_matrix[i1][i2]=temp;
			if(i1<i2){
				e.push_back(edge{i1,i2,temp});
			}
		}
	}
	sort(e.begin(),e.end());
	UnionFind l(n);
	int64_t cost=0;
	bool possible=true;
	for(auto i=e.begin();i!=e.end();i++){
		if(l.same(i->v1,i->v2)){
			bool under=false;
			bool equal=false;
			for(int32_t i2=0;i2<n;i2++){
				if(i2==i->v1||i2==i->v2){
					continue;
				}
				if(cost_matrix[i->v1][i2]+cost_matrix[i2][i->v2]<i->cost){
					under=true;
				}else if(cost_matrix[i->v1][i2]+cost_matrix[i2][i->v2]==i->cost){
					equal=true;
				}

			}
			if(under){
				possible=false;
				goto END;
			}else if(!equal){
				cost+=i->cost;
			}
		}else{
			l.unite(i->v1,i->v2);
			cost+=i->cost;
		}
	}
	END:
	if(possible){
		cout<<cost<<endl;
	}else{
		cout<<-1<<endl;
	}

}


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

int main()
{
ll t1 , t2 ;
cin >> t1 >> t2 ;
ll a1 , a2 ;
cin >> a1 >> a2 ;
ll b1 , b2 ;
cin >> b1 >> b2 ;
if(a1<b1){
  swap(a1,b1);
  swap(a2,b2);
}
if(a1*t1+a2*t2>b1*t1+b2*t2){
  cout << 0 << endl;
  return 0;
}
if(a1*t1+a2*t2==b1*t1+b2*t2){
  cout << "infinity" << endl;
  return 0;
}
ll cal=a1*t1-b1*t1;
ll cal2=b1*t1+b2*t2-a1*t1-a2*t2;
ll k=cal/cal2;
ans=1+k*2;
if(cal%cal2==0)ans--;
cout << ans << endl;
return 0;
}

Measured memory_bytes: 256