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

long long H, W;
long long d[10][10];
long long A[10];

int main(){
	cin >> H >> W;
	for(long long i = 0; i < 10; i++){
		for(long long j = 0; j < 10; j++){
			cin >> d[i][j];
		}
	}
	for(long long i = 0; i < H; i++){
		for(long long j = 0; j < W; j++){
			long long tmp;
			cin >> tmp;
			if(tmp != -1){
				A[tmp]++;
			}
		}
	}

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

	long long ans = 0;
	for(long long i = 0; i < 10; i++){
		ans += A[i] * d[i][1];
	}
	cout << ans << endl;
}

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

#define int long long
using ll = long long;
using ld = long double;
using intpair = pair<int, int>;
using intmap = map<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
const int MOD = 1e9 + 7;
inline int mod(ll a, int m = MOD) { return (a % m + m) % m; }
inline bool bit(ll b, ll i) { return b & (1 << i); }
inline ll ceiv(ll a, ll b) { return (a + b - 1) / b; }
// struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;

#define debug(x) cerr << #x << ": " << x << '\n'
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()

signed main(){
    string S; cin >> S;
    if(S == "RRR"){
        cout << 3 << endl;
        return 0;
    }
    if(S == "RRS"){
        cout << 2 << endl;
        return 0;
    }
    if(S == "SRR"){
        cout << 2 << endl;
        return 0;
    }
    if(S == "SSS"){
        cout << 0 << endl;
        return 0;
    }
    cout << 1 << endl;
}

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

long long N, M;
vector<long long> tree[100005];

int main(){
	cin >> N >> M;
	for(long long i = 0; i < M; i++){
		long long a, b;
		cin >> a >> b;
		a--;b--;
		tree[a].push_back(b);
		tree[b].push_back(a);
	}

	set<long long>visit;
	deque<long long>dq;
	visit.insert(0);
	visit.insert(tree[0][0]);

	dq.push_back(0);
	dq.push_back(tree[0][0]);

	while(true){
		//head check
		long long head = dq.front();
		bool ok = true;
		bool ok2 = true;
		for(long long i = 0; i < tree[head].size(); i++){
			if(visit.count(tree[head][i]) == 0){
				ok = false;
			}
		}

		//tail check
		head = dq.back();
		for(long long i = 0; i < tree[head].size(); i++){
			if(visit.count(tree[head][i]) == 0){
				ok2 = false;
			}
		}
		if(ok && ok2){
			break;
		}

		//extend head
		head = dq.front();
		ok = false;
		for(long long i = 0; i < tree[head].size(); i++){
			if(visit.count(tree[head][i]) == 0){
				dq.push_front(tree[head][i]);
				visit.insert(tree[head][i]);
				ok = true;
				break;
			}
		}
		if(ok){
			continue;
		}

		//extend tail
		head = dq.back();
		ok = false;
		for(long long i = 0; i < tree[head].size(); i++){
			if(visit.count(tree[head][i]) == 0){
				dq.push_back(tree[head][i]);
				visit.insert(tree[head][i]);
				ok = true;
				break;
			}
		}
		if(ok){
			continue;
		}
	}

	cout << dq.size() << endl;
	while(dq.size() > 0){
		cout << dq.front() + 1;
		if(dq.size() != 1){
			cout << " ";
		}
		dq.pop_front();
	}
	cout << endl;
}



Measured memory_bytes: 11776
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=998244353;
int main(){
    string s;
    cin>>s;
    vector<ll>a(s.size()+1);
    vector<ll>b(s.size()+1);
    rep(i,s.size()){
        if(s[i]=='<')a[i+1]=a[i]+1;
    }
    reverse(all(s));
    rep(i,s.size()){
        if(s[i]=='>')b[i+1]=b[i]+1;
    }
    reverse(all(b));
    ll sum=0;
    rep(i,s.size()+1){
        sum+=max(a[i],b[i]);
        //cout<<max(a[i],b[i])<<' ';
    }
    cout<<endl;
    cout<<sum<<endl;
}

Measured memory_bytes: 8708
a=[*?a..?z]
s=gets.chomp
if s.size < 26
  puts s + (a - s.chars.to_a)[0]
else
  i = 25
  loop do
    break if i == 0
    break if s[i-1] < s[i]
    i -= 1
  end
  if i == 0
    puts -1
  else
    s[i-1,200] = s[i-1].succ
    s[i-1,200] = s[i-1].succ until s.chars.to_a.uniq.size == s.size
    puts s
  end
end


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
int main(){
    cin.tie(NULL);
    ios::sync_with_stdio(false);
    // freopen("tc.txt", "r" ,stdin);
    int t = 1;
    // cin >> t;
    while(t--){
        int s, w;
        cin >> s >> w;
        if (w >= s) cout << "unsafe" << endl;
        else cout << "safe" << endl;
    }
    return 0;
}


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

using namespace std;

long long n, cnt;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n;
	if (n % 2) cout << 0 << endl;
	else {
		n /= 10;
		cnt += n;
		while (n) {
			n /= 5;
			cnt += n;
		}
		cout << cnt << endl;
	}	
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var ha, ma, hb, mb, k int
	fmt.Scan(&ha, &ma, &hb, &mb, &k)

	a := 60*ha + ma
	b := 60*hb + mb

	ansM := (b - k) - a

	fmt.Println(ansM)
}


Measured memory_bytes: 1756
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

int p[11];
int c[11];

int main() {
	int d, g;
	cin >> d >> g;
	for (int i = 0; i < d; i++)
		cin >> p[i] >> c[i];
	int ans = 1e9;
	for (int i = 0; i < (1 << d); i++) {
		int tmp = 0;
		long sum = 0;
		for (int j = 0; j < d; j++) {
			if (i & (1 << j)) {
				tmp += p[j];
				sum += 100 * (j + 1) * p[j] + c[j];
			}
		}
		for (int j = d - 1; j >= 0 && sum < g; j--) {
			if (!(i & (1 << j))) {
				for (int l = 1; l <= p[j] && sum < g; l++) {
					tmp++;
					sum += 100 * (j + 1);
				}
			}
		}
		ans = min(ans, tmp);
	}
	cout << ans << endl;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

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

	vector<bool> a(200, false);
	a[0] = true;
	rep(i,101){
		if(a[i]){
			a[i + 4] = a[i + 7] = true;
		}
	}

	cout << (a[n] ? "Yes" : "No") << endl;
}


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


int main() {
  int K;
  cin>>K;
  string S;
  cin>>S;
  if(S.size()<=K)cout<<S<<endl;
  else {
    for(int i=0;i<K;i++)
      cout<<S[i];
    cout<<"..."<<endl;
       }
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
#include <iostream>
#include <numeric>
#include <math.h>
#define ll  long long
#define ull unsigned long
#define mpa make_pair
#define pb push_back
#define ff first
#define pii pair<ll,ll>
#define dd double
#define trace(x) cerr << #x << " : " << x << endl
#define ss second
#define boost ios_base::sync_with_stdio(0)
#define forp(i,a,b) for(ll i=a;i<=b;i++)
#define rep(i,n)    for(ll i=0;i<n;++i)
#define ren(i,n)    for(ll i=n-1;i>=0;i--)
#define forn(i,a,b) for(ll i=a;i>=b;i--)
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end();
#define sc(x) scanf("%lld",&x)
#define clr(x,val) memset(x,val,sizeof(x))
#define pr(x) printf("%lld\n",x) 
#define gc getchar
#define pdd pair<dd,dd>
#define prec(x) cout<<fixed<<setprecision(x)
using namespace std;
ll a[2000005];
int main(){
	
    ll n,k;
    vector<char> sol;

    cin>>n;
    string s;
    while(n > 0){
    	n--;
    	s+=char('a'+n%26);
    	n/=26;
	}
	for(ll i=s.size()-1;i>=0;i--) cout<<s[i];
	
}
    


	
	
    



Measured memory_bytes: 3632
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int[] pri = new int[260000];
		for(int i=2;i<=250000;i++){
			pri[i] = i;
		}
		for(int i=2;i<=300000;i++){
			for(int j=i+i;j<=250000;j+=i){
					pri[j]=0;
			}
		}

		while(true){
			int n = sc.nextInt();
			if(n==0)break;
			int sum=0;
			for(int i=n+1;i<=n+n;i++){
				if(pri[i]>0)sum++;
			}
			System.out.println(sum);
		}
	}
	
}

Measured memory_bytes: 23248
S = input()
T = input()

N, M = len(S), len(T)

if N < M:
    print('UNRESTORABLE')
else:
    for i in range(max(0,N-M), -1, -1):
        # 今着目しているSの部分
        # 後ろから探査
        now = S[i:i+M]

        # nowにTを入れられるかチェック
        for j in range(M):
            if now[j] == '?' or now[j] == T[j]:
                continue
            else:
                break
        else:
            # 入れられるならその部分をTに置換
            S = S[0:i] + T + S[i+M:N]
            # 残った?をaに置換
            S = S.replace('?', 'a')
            print(S)
            break
    else:
        # どこにもTを入れられなかったら
        print('UNRESTORABLE')


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a[3];
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	int x=a[0]%2,y=a[1]%2,z=a[2]%2;
	if((x&&y&&z)||!(x||y||z))
	{
		cout<<(2*a[2]-a[0]-a[1])/2<<'\n';
	}
	else
	{
		if(x==y)
		{
			a[0]++;
			a[1]++;
			
		}
		else if(x==z)
		{
			a[0]++;
			a[2]++;
		}
		else 
		{
			a[1]++;
			a[2]++;
		}
		cout<<(abs(a[2]-a[1])+abs(a[2]-a[0]))/2+1<<'\n';
	}
}

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

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int n = Integer.parseInt(br.readLine());
		
		for(int i = 0; i < n ; i++){
			String[] tmpArray = br.readLine().split(" ");
			
			int x1 = getIntFromMCXI(tmpArray[0]);
			int x2 = getIntFromMCXI(tmpArray[1]);
			//System.out.println(x1 + " " + x2);
			
			int result = x1 + x2;
			
			System.out.println(getMCXIfromInt(result));
		}
	}

	private static String getMCXIfromInt(int result) {
		// TODO ?????????????????????????????????????????????
		StringBuffer str = new StringBuffer();
		
		if(result >= 1000 && result < 2000){
			str.append("m");
		}
		else if(result >= 2000){
			str.append(result/1000 + "m");
		}
		
		if(result%1000 >= 100 && result%1000 < 200){
			str.append("c");
		}
		else if(result%1000 >= 200){
			str.append((result%1000)/100 + "c");
		}

		if(result%100 >= 10 && result%100 < 20){
			str.append("x");
		}
		else if(result%100 >= 20){
			str.append((result%100)/10 + "x");
		}
		
		if(result%10 >= 1 && result%10 < 2){
			str.append("i");
		}
		else if(result%10 >= 2){
			str.append((result%10) + "i");
		}
		
		return str.toString();
	}

	private static int getIntFromMCXI(String string) {
		// TODO ?????????????????????????????????????????????
		int result = 0;
		int indexM = string.indexOf('m');
		
		if(indexM == 0){
			result += 1000;
		}
		else if(indexM != -1){
			result += 1000*Integer.parseInt(string.substring(indexM - 1, indexM));
		}
		
		int indexC = string.indexOf('c');
		
		if(indexC == 0 || indexC >= 1 && Character.isAlphabetic(string.charAt(indexC - 1))){
			result += 100;
		}
		else if(indexC != -1){
			result += 100*Integer.parseInt(string.substring(indexC - 1, indexC));
		}

		int indexX = string.indexOf('x');
		
		if(indexX == 0 || indexX >= 1 && Character.isAlphabetic(string.charAt(indexX - 1))){
			result += 10;
		}
		else if(indexX != -1){
			result += 10*Integer.parseInt(string.substring(indexX - 1, indexX));
		}
		
		int indexI = string.indexOf('i');
		
		if(indexI == 0 || indexI >= 1 && Character.isAlphabetic(string.charAt(indexI - 1))){
			result += 1;
		}
		else if(indexI != -1){
			result += Integer.parseInt(string.substring(indexI - 1, indexI));
		}
		return result;
	}

}

Measured memory_bytes: 29304
let s = read_line ();;

let rec f i min_diff =
    let min_diff = min min_diff (abs ((int_of_string (String.sub s i 3)) - 753)) in
    if (String.length s) = (i + 3) then
        min_diff
    else
        f (i+1) min_diff
;;

print_endline (string_of_int (f 0 999999))


Measured memory_bytes: 384
#include<iostream>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int main() {
  int A[32] = {
1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
  }, K;
  std::cin >> K;
  fin(A[K-1]);
  return 0;
}


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

int main() {
  long long N, T;
  cin >> N >> T;
  vector<long long> t(N);
  for (int i=0; i<N; i++) cin >> t.at(i);
  long long X = 0LL;
  for (int i=1; i<N; i++) {
    if (t.at(i)-t.at(i-1)<T) X += t.at(i)-t.at(i-1);
    else X += T;
  }
  X += T;
  cout << X << endl;
  return 0;
}

Measured memory_bytes: 1792
X = int(input())
if X<600:
    print(8)
    exit()
if X<800:
    print(7)
    exit()
if X<1000:
    print(6)
    exit()
if X<1200:
    print(5)
    exit()
if X<1400:
    print(4)
    exit()
if X<1600:
    print(3)
    exit()
if X<1800:
    print(2)
    exit()
if X<2000:
    print(1)
    exit()


Measured memory_bytes: 9128
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int W = scan.nextInt();
		int H = scan.nextInt();
		int x = scan.nextInt();
		int y = scan.nextInt();
		int r = scan.nextInt();
		
		if (W >= x + r && H >= y + r && x + r > 0 && y + r > 0){
				System.out.println("Yes");
		}else{
			System.out.println("No");
		}
		scan.close();
	}
}


Measured memory_bytes: 26368
num_task = int(input())

maps = [map(int, input().split(' ')) for _ in range(0, num_task)]
tasks = [(b, a) for a, b in maps]
tasks.sort()


current_time = 0

for deadline, time_needed in tasks:
    end_time = current_time + time_needed

    if end_time > deadline:
        print("No")
        break

    current_time = end_time

else:
    print("Yes")


Measured memory_bytes: 107364
import math
from collections import deque
from collections import defaultdict
import itertools as it

#自作関数群
def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()
def factorization(n):
  res = []
  if n%2==0:
    res.append(2)
  for i in range(3,math.floor(n//2)+1,2):
    if n%i==0:
      c = 0
      for j in res:
        if i%j==0:
          c=1
      if c==0:
        res.append(i)
  if len(res)==0:
    res = [n]
  return res
def fact2(n):
  p = factorization(n)
  res = []
  for i in p:
    c=0
    z=n
    while 1:
      if z%i==0:
        c+=1
        z/=i
      else:
        break
    res.append([i,c])
  return res
def fact(n):#階乗
  ans = 1
  m=n
  for _i in range(n-1):
    ans*=m
    m-=1
  return ans
def comb(n,r):#コンビネーション
  if n<r:
    return 0
  l = min(r,n-r)
  m=n
  u=1
  for _i in range(l):
    u*=m
    m-=1
  return u//fact(l)
def combmod(n,r,mod):
  return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
  r=copyQueue(q)
  ans=[0]*r.qsize()
  for i in range(r.qsize()-1,-1,-1):
    ans[i] = r.get()
  print(ans)
class UnionFind():
  def __init__(self, n):
    self.n = n
    self.parents = [-1]*n

  def find(self, x): # root
    if self.parents[x]<0:
      return x
    else:
      self.parents[x] = self.find(self.parents[x])
      return self.parents[x]

  def union(self,x,y):
    x = self.find(x)
    y = self.find(y)

    if x==y:
      return

    if self.parents[x]>self.parents[y]:
      x,y = y,x

    self.parents[x]+=self.parents[y]
    self.parents[y]=x

  def size(self,x):
    return -1*self.parents[self.find(x)]

  def same(self,x,y):
    return self.find(x)==self.find(y)

  def members(self,x): # much time
    root = self.find(x)
    return [i for i in range(self.n) if self.find(i)==root]

  def roots(self):
    return [i for i,x in enumerate(self.parents) if x<0]

  def group_count(self):
    return len(self.roots())

  def all_group_members(self):
    return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
  x = 1
  zero = "0"*n
  ans = []
  ans.append([0]*n)
  for i in range(2**n-1):
    ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
    x+=1
  return ans;
def arrsSum(a1,a2):
  for i in range(len(a1)):
    a1[i]+=a2[i]
  return a1
def maxValue(a,b,v):
  v2 = v
  for i in range(v2,-1,-1):
    for j in range(v2//a+1): #j:aの個数
      k = i-a*j
      if k%b==0:
        return i
  return -1
def copyQueue(q):
  nq = queue.Queue()
  n = q.qsize()
  for i in range(n):
    x = q.get()
    q.put(x)
    nq.put(x)
  return nq
def get_sieve_of_eratosthenes(n):
  data = [2]
  #data = [0,0,0]
  for i in range(3,n+1,2):
    data.append(i)
    data.append(0)
  for i in range(len(data)):
    interval = data[i]
    if interval!=0:
      for j in range(i+interval,n-1,interval):
        data[j] = 0
  ans = [x for x in data if x!=0]
  #ans = data[:]
  return ans


a,b = readInts()

#print(a+b)
print(a*b)

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

typedef struct{
  int dt;
  int idx;
}data;

long half (long x){
  if(x == 1){
    return 0;
  }else{
    return x/2;
  }
}

int main() {
  long h;
  cin >> h;
  
  long a = 0;
  long b = 1;
  long num,hp;
  while(1){
    if(h/2 != 0){
      h/=2;
      b *= 2;
      a+=b;
    }else{
      break;
    }

  }
  a++;
  cout << a << endl;
}


Measured memory_bytes: 256
taro = 0
hanako = 0
n = int(input())
for _ in range(n):
    moji1, moji2 = input().split()
    if moji1 == moji2:
        taro += 1
        hanako += 1
    else:
        for m1, m2 in zip(moji1, moji2):
            p1, p2 = map(ord, (m1, m2))
            if p1 != p2:
                break
        else:
            p1 = len(moji1)
            p2 = len(moji2)
        if p1 > p2:
            taro += 3
        else:
            hanako += 3
print(f'{taro} {hanako}')


Measured memory_bytes: 5612
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

namespace A_AISING2020
{
    class MainClass
    {

        static int[] s;

        public static void Main(string[] args)
        {
            s = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);

            var ans = 0;
            for (int i = s[0]; i <= s[1]; i++)
            {
                if (i % s[2] == 0) ans++;
            }
            WriteLine(ans);
        }


        public static int LowerBound<T>(T[] a, T v)
        {
            return LowerBound(a, v, Comparer<T>.Default);
        }

        public static int LowerBound<T>(T[] a, T v, Comparer<T> cmp)
        {
            var l = 0;
            var r = a.Length - 1;
            while (l <= r)
            {
                var mid = l + (r - l) / 2;
                var res = cmp.Compare(a[mid], v);
                if (res == -1) l = mid + 1;
                else r = mid - 1;
            }
            return l;
        }
        public static int UpperBound<T>(T[] a, T v)
        {
            return UpperBound(a, v, Comparer<T>.Default);
        }

        public static int UpperBound<T>(T[] a, T v, Comparer<T> cmp)
        {
            var l = 0;
            var r = a.Length - 1;
            while (l <= r)
            {
                var mid = l + (r - l) / 2;
                var res = cmp.Compare(a[mid], v);
                if (res <= 0) l = mid + 1;
                else r = mid - 1;
            }
            return l;
        }
    }
}


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

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

ll N, M, R;

int main() {
    cin >> N >> M >> R;
    vector<ll> r(R);
    rep(i, R) {
        ll tmp;
        cin >> tmp;
        tmp--;
        r[i] = tmp;
    }

    vector<vector<ll>> dist(N, vector<ll>(N, INF));
    rep(i, M) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        dist[a][b] = min(dist[a][b], c);
        dist[b][a] = min(dist[b][a], c);
    }
    // dist[i][i] = 0 は INF のままいく
    rep(i, N) dist[i][i] = 0;

    rep(k, N)rep(i, N)rep(j, N) dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);

    ll ans = INF;
    sort(r.begin(), r.end());
    do {
        ll tmp = 0;
        for (int i = 0; i <= r.size() - 2; i++) {
            tmp += dist[r[i]][r[i + 1]];
            // printf("%d ", r[i]);
        }
        ans = min(ans, tmp);
        // printf("\n");
    } while (next_permutation(r.begin(), r.end()));
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
#define int long long
typedef long long ll;
using namespace std;

const int S = 2222;
int dp[S];
int s;

int solve() {
    cin >> s;
    dp[0] = 1;
    rep(i, 3, s) {
        rep(d, 3, i) {
            dp[i] = (dp[i] + dp[i - d]) % MOD;
        }
    }
    cout << dp[s] << endl;
    return 0;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
    while(t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3656
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <functional>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define REP(i,n) for(int i=0,_n=(n);(i)<(int)_n;++i)
#define RANGE(i,a,b) for(int i=(int)a,_b=(int)(b);(i)<_b;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define PRINT1(table, D0) REP(d0, D0) cout<<table[d0]<<" "; cout<<"\n";
#define PRINT2(table, D0, D1) REP(d0, D0) { REP(d1, D1) cout<<table[d0][d1]<<" "; cout<<"\n"; }
#define PRINT3(table, D0, D1, D2) REP(d0, D0) { REP(d1, D1) { REP(d2, D2) cout<<table[d0][d1][d2]<<" "; cout<<"\n"; } cout<<"\n"; }
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M,Q,l,r,p,q;
	while(cin>>N>>M>>Q) {
//		DD("----");
		VVI w(N);
		REP(i, M) {
			cin>>l>>r;
			w[l-1].PB(r-1);
		}
		REP(i, N) sort(ALL(w[i]));
		REP(i, Q) {
			cin>>p>>q;
			ll ans = 0;
//			DD("q");DD(i);
			REP(j, N) {
				if(p-1<=j) {
					ll v = distance(w[j].begin(), upper_bound(ALL(w[j]), q-1));
//					DD(j);
//					DD(v);
					ans += v;
				}
			}
			cout<<ans<<endl;
		}
	}
	
	return 0;
}


Measured memory_bytes: 3456
N,M=map(int, input().split())
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
A=make_divisors(M)
for i in range(len(A)):
  if A[i]>=N:
    print(A[-1-i])
    exit()

Measured memory_bytes: 9224
k = int(input())

a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
     1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(a[k-1])


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

int main(){
  int n,k=0;
  vector<int> A,B,C;

  cin >> n;
  A.resize(n);
  B.resize(n);
  for(int i=0;i<n;i++){
    cin >> A[i];
    k > A[i] ? : k = A[i];
  }
  C.resize(k+1);

  for(int i=0;i<n;i++){
    C[A[i]]++;
  }
  for(int i=1;i<k+1;i++){
    C[i] += C[i-1];
  }
  for(int i=n-1;i>=0;i--){
    B[C[A[i]] - 1] = A[i];
    C[A[i]]--;
  }

  cout << B[0];
  for(int i=1;i<n;i++){
    cout << " " << B[i];
  }
  cout << endl;
}


Measured memory_bytes: 18316
n,a,b = map(int,input().split())
if a>b:
    print(0)
else:
    if n==1:
        if a==b:
            print(1)
        else:
            print(0)
    else:
        mn = (n-1)*a+b
        mx = a+(n-1)*b
        print(mx-mn+1)
    

Measured memory_bytes: 38256
#import pysnooper
#import os,re,sys,operator,math,heapq,string
from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from copy import deepcopy

setrecursionlimit(10**6)
input=stdin.readline

a,b=map(int,input().split())
print(str(a*b))


Measured memory_bytes: 7140
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * Created by Meepo on 4/1/2017.
 */
public class Main {
    BufferedReader br;
    StringTokenizer st;
    PrintWriter out;

    public String nextToken() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    public void solveA() throws IOException {
        int n = nextInt();
        int[] a = new int[3 * n];
        for (int i = 0; i < 3 * n; i++) {
            a[i] = nextInt();
        }
        Arrays.sort(a);
        long ans = 0;
        for (int i = 0; i < n; i++) {
            ans += a[3 * n - 2 * i - 2];
        }
        out.println(ans);
    }

    public void solveB() throws IOException {
        int n = nextInt();
        int m = nextInt();
        ArrayList<Integer>[] e = new ArrayList[n];
        for (int i = 0; i < e.length; i++) {
            e[i] = new ArrayList<>();
        }
        for (int i = 0; i < m; i++) {
            int a = nextInt() - 1;
            int b = nextInt() - 1;
            e[a].add(b);
            e[b].add(a);
        }

        int[][] color = new int[n][11];

        for (int i = 0; i < n; i++) {
            Arrays.fill(color[i], -1);
        }

        int q = nextInt();
        int[] c = new int[q];
        for (int i = 0; i < q; i++) {
            int v = nextInt() - 1;
            int d = nextInt();
            c[i] = nextInt();
            color[v][d] = i;
        }

        boolean change = true;
        while (change) {
            change = false;
            for (int v = 0; v < e.length; v++) {
                for (int d = 1; d < color[v].length; d++) {
                    if (color[v][d] == -1) {
                        continue;
                    }
                    for (int u : e[v]) {
                        if (color[u][d - 1] < color[v][d]) {
                            color[u][d - 1] = color[v][d];
                            change = true;
                        }
                    }
                }
            }
        }

        for (int i = 0; i < n; i++) {
            int ans = -1;
            for (int j = 0; j < color[i].length; j++) {
                ans = Math.max(ans, color[i][j]);
            }
            out.println(ans == -1 ? 0 : c[ans]);
        }
    }

    public void run() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);

            solveB();

            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 119440
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<char> S;


int main(){
    int n;
    cin>>n;
    vector<int> a(n,0);
    rep(i,n) cin>>a[i];
    reverse(a.begin(),a.end());
    for(int i=0;i<n-1;i++){
        if(a[i]<a[i+1]){
            if(a[i+1]-a[i]>1) {
                cout<<"No"<<endl;
                return 0;
            }
            else a[i+1]--;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
int main()
{
int a,b,c,work;

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

if(a>b){
   work=a;
   a=b;
   b=work;
  }if(b>c){
   work=b;
   b=c;
   c=work;
}if(a>b){
   work=a;
   a=b;
   b=work;
}
  printf("%d %d %d\n",a,b,c);
  return 0;
}


Measured memory_bytes: 596
//g++ -std=gnu++14 a.cpp

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>
#include <stdio.h>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;
ll MODP = 998244353;


int main(){
  string s;
  cin >> s;
  vector<string> today = {"MON","TUE","WED","THU","FRI","SAT","SUN"};
  rep(i,7){
    if(today[i] == s){
      int ans = 6 - i;
      if(ans == 0)ans = 7;
      cout << ans << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 3548
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
using namespace std;

#define rep(i, s) for (int i = 0; i < s; ++i)
#define all(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int> a(n)
#define PQ(a) priority_queue<int> a
#define PQmin(a) priority_queue<int, : vector<int>, greater<int>> a
#define PAIR pair<int, int>
/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

int main()
{
    string s;
    cin >> s;
    cout << s[0] << s.size() - 2 << s[s.size() - 1] << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

void yes(){
    cout << "Yes" << endl;
}

void no (){
    cout << "No" << endl;
}

ll cel (ll a, ll b){
    if (a % b == 0) return a / b;
    else return a / b + 1;
}

ll gcds(ll a, ll b){
    ll c = a % b;
    while (c != 0){
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}


struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    //コンストラクタ
    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};


int main() {
    int n, m; cin >> n >> m;
    UnionFind tree(n);
    rep(i,m){
        int a, b; cin >> a >> b;
        tree.unite(a,b);
    }
    vector<int> ar(n,0);
    rep(i,n){
        ar[tree.root(i)]++;
    }
    int ans = 0;
    rep(i,n) ans = max(ans,ar[i]);
    cout << ans << endl;
}


Measured memory_bytes: 11076
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,k;
    int c[105];
    scanf("%d%d%d",&a,&b,&k);
    int d=min(a,b);
    int cnt=0;
    for(int i=1;i<=d;i++){
        if(a%i==0&&b%i==0){
            cnt++;
            c[cnt]=i;
        }
    }
    sort(c+1,c+1+cnt);
    int tmp=0;
    for(int i=cnt;i>0;i--){
        tmp++;
        if(tmp==k){
            printf("%d\n",c[i]);
        }
    }
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
   int a, b, c, i, g, d[100];

   scanf("%d %d %d", &a, &b, &c);
   g=0;
   for(i=a;i>=1;i--){
        if((a%i==0)&&(b%i==0)){
                d[g]=i;
                g=g+1;
 
        }
   }

   printf("%d\n",d[c-1]);
   return 0;
}



Measured memory_bytes: 128
#include <iostream>
#include <vector>

using namespace std;
using ll = long long;
using vi = vector<int>;
template<class T>using vv = vector<vector<T>>;

#define in(v) v; cin >> v;

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define repi(i,a,b) for(int i=(a),_i=(b);i<_i;++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

int N;
vv<int> A;
ll dp[1<<16][16];
const ll INF = 1e15;
ll dfs(int used, int i) {
  if (i == N) return 0;
  if (dp[used][i] != INF) return dp[used][i];
  if (used & (1 << i)) return dfs(used, i+1);

  ll ans = 0;
  int notUsed = ((1 << N)-1) ^ used;
  for (int bit = notUsed; bit > 0; bit = (bit-1)&notUsed) {
    ll tmp = 0;
    bool ok = true;
    rep(j, N) {
      if (j == i && !(bit & (1 << i))) {
        ok = false; break;
      }
      if (bit & (1 << j))
        rep(k, j+1, N) {
          if (bit & (1 << k))
            tmp += A[j][k];
        }
    }
    if (ok)
      ans = max(ans, tmp + dfs(used | bit, i+1));
  }

  return dp[used][i] = ans;
}
int main() {
  in(N);
  A.resize(N, vector<int>(N, 0));

  rep(i, 1<<16) rep(j, 16) dp[i][j] = INF;
  rep(i, N) rep(j, N) {
    cin >> A[i][j];
  }
  cout << dfs(0, 0) << endl;

  return 0;
}


Measured memory_bytes: 8448
N, M, D = map(int, input().split())

# 美しい組：1-1+D, 2-2+D, ..., N-D-N

if D == 0:
    prob = 1 / N
else:
    prob = (N - D) / (N**2) * 2

ans = prob * (M - 1)
print(ans)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,b;
    cin>>n;
    if(n%2==0){
        b=n/2;
        cout<<b<<endl;
    }
    else
    {
        b=n/2;
        cout<<b+1<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#include<iomanip>
#define BUG puts("no bug")
#define sci(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define ll long long
#define ull unsigned long long
#define REP(a,b,c) for(ll a=b;a<=c;a++)
#define PER(a,b,c) for(ll a=b;a>=c;a--)
#define lb(a) (a&(-a))
#define pp (p<<1)
#define ppp (p<<1|1)
#define pi pair<ll,ll>
#define pii pair<pair<ll,ll>,ll>
using namespace std;
const ll MAXN=1e6+5;
ll n,m,t;
ll v[MAXN];
char s[MAXN];
int main(){
    ll a,b;
    cin>>a>>b>>n;
    if(n>=b)cout<<a*(b-1)/b;
    else cout<<a*(n)/b;
}

Measured memory_bytes: 3192
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define rep(i,l,n) for(int (i)=(l);(i)<(n);(i)++)
#define min(a,b) (a)<(b)?(a):(b)
#define max(a,b) (a)>(b)?(a):(b)

int main(){
	int N,M; scanf("%d %d",&N,&M);
	printf("%d",N*(N-1)/2+M*(M-1)/2);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int  a[15];
  for(int n=0;n<10;n++){
    cin >>a[n];
  }
  sort(a,a+10);
  for(int n=9;n>=7;n--){
    cout <<a[n]<<'\n';
  }
  return (0);
}



Measured memory_bytes: 3168
//#pragma GCC target("avx2,avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
//using mint = modint1000000007;
#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//using i128 = __int128_t;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
constexpr char ln = '\n';
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) {if (a < b) {a = b; return true;} return false;}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) {if (a > b) {a = b; return true;} return false;}
inline int topbit(int x) {return x == 0 ? -1 : 31-__builtin_clz(x);}
inline int topbit(long long x) {return x == 0 ? -1 : 63-__builtin_clzll(x);}
inline int botbit(int x) {return x == 0 ? 32 : __builtin_ctz(x);}
inline int botbit(long long x) {return x == 0 ? 64 : __builtin_ctzll(x);}
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
inline int kthbit(long long x, int k) {return (x>>k)&1;}
inline void print() {cout << "\n";}
template<class T>
inline void print(const vector<T> &v) {
    for (auto itr = v.begin(); itr != v.end(); ++itr) cout << *itr << " ";
    print();
}
template<class T, class... Args>
inline void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
#ifdef MINATO_LOCAL
#define dump(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
inline void debug() {cerr << endl;}
template<class T>
inline void debug(const vector<T> &v) {
    for (auto itr = v.begin(); itr != v.end(); ++itr) cerr << *itr << " ";
    debug();
}
template<class T, class... Args>
inline void debug(const T &x, const Args &... args) {
    cerr << x << " ";
    debug(args...);
}
#else
#define dump(x) void(0)
inline void debug() {}
template<class T> inline void debug(const vector<T> &v) {}
template<class T, class... Args> inline void debug(const T &x, const Args &... args) {}
#endif
struct Fast_ios {Fast_ios() {cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);};} fast_ios;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    int N,M; cin >> N >> M;
    vector<mint> A(N),B(M);
    rep(i,N) {
        int a; cin >> a;
        A[i] = a;
    }
    rep(i,M) {
        int a; cin >> a;
        B[i] = a;
    }

    auto C = convolution(A,B);
    rep(i,N+M-1) {
        cout << C[i].val() << " ";
    }
    cout << ln;
}


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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))

using namespace std;
using ll = long long;
using pii = pair<int, int>;

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'000'000'001;
constexpr ll LLINF = 4'000'000'000'000'000'001;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    string s;
    cin >> s;
    int n = s.size();
    char b = s[0];
    int cnt = 1;
    vector<int> a;
    for(int i = 1; i < n; ++i){
        if(b == s[i]) ++cnt;
        else {
            a.push_back(cnt);
            b = s[i];
            cnt = 1;
        }
    }
    a.push_back(cnt);
    vector<int> ans(n);
    int sum = 0;
    for(int i = 0; i < a.size(); i += 2){
        sum += a[i];
        ans[sum-1] = CEIL(a[i], 2) + a[i+1] / 2;
        ans[sum] = a[i] / 2 + CEIL(a[i+1], 2);
        sum += a[i+1];
    }
    cout << ans[0];
    for(int i = 1; i < n; ++i){
        cout << " " << ans[i];
    }
    cout << "\n";
    return 0;
}

Measured memory_bytes: 1480
import java.util.*;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    
    if(8>=a && 8>=b){
      System.out.println("Yay!");
    }
    else{
      System.out.println(":(");
    }
  }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
int myctoi(char C) {return C - 48;}
char myitoc(int N) {return '0' + N;}

signed main()
{
  int N;
  cin >> N;
  vector<int> A;
  int sumA = 0;
  for (int i = 0; i < N; i++)
  {
    int a;
    cin >> a;
    A.push_back(a);
    sumA += a;
  }
  A.push_back(A.at(0));
  
  vector<int> ans(N, 0);
  for (int i = 0; i < N; i += 2)
  {
    ans.at(0) += A.at(i);
  }
  ans.at(0) -= sumA / 2;
  ans.at(0) *= 2;
  
  for (int i = 1; i < N; i++)
  {
    ans.at(i) = (A.at(i - 1) - ans.at(i - 1) / 2) * 2;
  }

  for (int i = 0; i < N; i++)
  {
    cout << ans.at(i);
    if (i == N - 1) cout << endl;
    else cout << " ";
  }
}

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

using namespace std;

int main(){
	string str1,str2;
	cin>>str1>>str2;
	int len1 = str1.length(),len2 = str2.length();
	char *password = new char[len1+len2];
	int j = 0;
	for(int i=0;i<len1+len2;i+=2)
		password[i] = str1[j++];
	j = 0;
	for(int i=1;i<len1+len2;i+=2)
		password[i] = str2[j++];
	for(int i=0;i<len1+len2;i++)
		cout<<password[i];
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
 
int main(){
  int a, b;
  cin >> a >> b;
  if(a > b){
    if(a - 1 == b){
      cout << a + b;
    }
    else if(a - 1 > b){
      cout << 2 * a - 1;
    }
  }
  else if(b > a){
    if(b - 1 == a){
      cout << a + b;
    }
    else if(b - 1 > a){
      cout << 2 * b - 1;
  }
  }
  else {
    cout << a + b;
  }
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,N) for(int i = 0; i < N; i++)
#define int long long
#define pb push_back
#define LLINF 1LL << 60
typedef pair<int,int> Pi;
#define F first
#define S second
 
signed main()
{
  int N;
  int A[200005];
  int wsum = 0;
  cin >> N;
  Rep(i,N) {
    cin >> A[i]; wsum += A[i];
  }
  Rep(i,N) A[i + N] = A[i];
   
  int l = 0, r = 1e14;
  while (l + 1 < r) {
    int m = (l + r + 1) / 2;
     
    bool flag = false;
    int j = 0, k = 0, jsum = 0, ksum = 0;
    Rep (i,N) {
      for (; j < i + N && jsum < m; j++) jsum += A[j], ksum -= A[j];
      for (; k < i + N && ksum < m; k++) ksum += A[k];
      if (jsum >= m && ksum >= m && wsum - jsum - ksum >= m) flag = true;
      jsum -= A[i];
    }
    
    if (flag)  l = m;
    else r = m;
  }
  cout << l << endl;
  return 0;
}

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

vector<int> ans;
vector<P> to[100005];

void dfs(int i, int j=-1){
    for(P u : to[i]){
        if(u.first == j) continue;
        if(u.second % 2 == 0){
            ans[u.first] = ans[i];
        }else{
            ans[u.first] = -ans[i];
        }
        dfs(u.first, i);
    }
}


int main()
{
    // input
    int n;
    cin >> n;
    rep(i,n-1){
        int u,v,w;
        cin >> u >> v >> w;
        u--;v--;
        to[u].emplace_back(make_pair(v,w));
        to[v].emplace_back(make_pair(u,w));
    }

    // solve
    ans.resize(n);
    ans[0] = 1;
    dfs(0);

    // ouput
    rep(i,n){
        if(ans[i]==-1) cout << '0' << endl;
        else if(ans[i]==1) cout << '1' << endl;
    }

    return 0;
}

Measured memory_bytes: 8320