akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p){os<<"("<<p.first<<","<< p.second<<")";return os;}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v){os<<"{";REP(i,(int)v.size()){if(i)os<<",";os<<v[i];}os<<"}";return os;}
template <typename T, size_t S> void printArray(const T (&array)[S]){for(auto val : array)std::cout << val << ", ";std::cout << "\n";}
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
const double PI=acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
template<class T>inline bool chmax(T& a, T b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T& a, T b){if(a > b){a = b; return 1;}return 0;}
const ll INF = 1LL<<60;
//const int dx[4] = {1, 0, -1, 0};
//const int dy[4] = {0, 1, 0, -1};
//const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve(){
    string s; cin >> s;
    bool flag = true;
    if(s[0] != 'A') flag = false;
    ll cnt = 0;
    for(int i=2; i<=s.size()-2; i++){
        if(s[i] == 'C') cnt++;
        if(s[i] == 'A' || s[i] == 'B' || ('D' <= s[i] && s[i] <= 'Z')) flag = false;
    }
    if(cnt != 1) flag = false;
    if('A' <= s[1] && s[1] <= 'Z') flag = false;
    if('A' <= s[s.size()-1] && s[s.size()-1] <= 'Z') flag = false;
    if(flag) cout << "AC" << endl;
    else cout << "WA" << endl;
}

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

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <functional>
#include <map>
#include <set>
#include <cmath>
#include <string>
#define SIZE 200005
#define INF 1000000005LL

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

int n;
ll K;

int C[25];
int T[25][50005];

int main()
{
	int m;
	scanf("%d %d",&n,&m);
	for(int i=1;i<=m;i++)scanf("%d",&C[i]);
	for(int i=0;i<=n;i++)T[0][i]=99999999;
	for(int i=0;i<=m;i++)T[i][0]=0;
	for(int i=1;i<=m;i++){
		for(int j=1;j<=n;j++){
			if(j-C[i]>=0){
				T[i][j] = min(T[i-1][j],T[i][j-C[i]]+1);
				//printf("%d*",T[i][j]);
			}else{
				T[i][j] = T[i-1][j];
				//printf("%d+",T[i][j]);
			}
		}
	}

	printf("%d\n",T[m][n]);
	return 0;
}



Measured memory_bytes: 6864
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <cmath>         // sqrt
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <bits/stdc++.h> // isupper, islower, isdigit, toupper, tolower
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, n) for (int i = (a); i < (n); i++)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> Pl;
typedef pair<int, int> P;
typedef tuple<ll, ll, string> Tlls;

// Greatest Common Divisor (最大公約数)
ll gcd(ll a, ll b)
{
  // Eucledean algorithm
  while (a)
  {
    if (a < b)
    {
      std::swap(a, b);
    }
    a %= b;
  }
  return b;
}

// Least Common Multiple 最小公倍数
ll lcm(ll a, ll b)
{
  return a / gcd(a, b) * b;
}

// key: value of prime factor素因数分解
// value: number of prime factor
map<ll, ll> prime_factorization(ll n)
{
  map<ll, ll> prime_factors;
  for (ll i = 2; i * i <= n; i++)
  {
    while (n % i == 0)
    {
      prime_factors[i]++;
      n /= i;
    }
  }
  if (n != 1)
    prime_factors[n] = 1;
  return prime_factors;
}

// 約数リスト約数の列挙
vector<ll> get_divisors(const ll n)
{
  vector<ll> divs;
  for (ll i = 1; i < (ll)sqrt((ld)n) + 1; i++)
  {
    if (n % i == 0)
    {
      divs.push_back(i);
      if (i != n / i)
      {
        divs.push_back(n / i);
      }
    }
  }

  // 必要に応じてソート
  // sort(divs.begin(), divs.end());

  return divs;
}

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()
{
  ll N, K;
  // int INF = 100000000;
  cin >> N >> K;
  const long long INF = 1LL << 60;

  // 入力
  // int N;
  // long long h[110000];

  // DP テーブル
  long long dp[110000];

  // for (int i = 0; i < N; ++i)
  //   cin >> h[i];

  // 初期化 (最小化問題なので INF に初期化)
  for (int i = 0; i < 110000; ++i)
    dp[i] = INF;
  vector<ll> h(N + K + 1);
  // vector<ll> dp(N + K + 1, INF);
  rep(i, N)
  {
    cin >> h.at(i);
  }
  dp[0] = 0;
  for (int i = 0; i < N; ++i)
  {
    for (int j = 1; j <= K; ++j)
    {
      chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
    }
  }
  // 答え
  cout << dp[N - 1] << endl;
  return 0;
}


Measured memory_bytes: 1920
/* بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ */
//codeforces
#include <bits/stdc++.h>
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define mp make_pair
#define pb push_back
#define sz(v) ((int)v.size())
#define all(v) v.begin(), v.end()
void parseArray(ll* A,ll n){ for ( ll K = 0; K < n; K++){ cin >> A[K]; } }
ll modInverse(ll a, ll b){ return 1<a ? b - modInverse(b%a, a)*b/a : 1; }
ll gcd(ll a, ll b){ return b?gcd(b, a % b):a; }
ll lcm(ll a, ll b){ return (a*b)/gcd(a, b); }
ld dist(ld x, ld y, ld a, ld b){ return sqrt((x-a)*(x-a) + (y-b)*(y-b)); }
void debug(ll* a, ll n) { for ( ll k = 0; k < n; k++ ){ cerr << a[k] << " ";} cout << "\n"; }
#define PI 3.14159265358979323846
#define FF first
#define SS second

int main(){
	FASTIO;
	ll n; cin >> n;
	string s; cin >> s;
	ll r = 0, w = 0;
	for ( int k = 0; k < n; k++ )
		if (s[k] == 'R') r++;
		else w++;
	ll ans = 0;
	if (w <= r) {
		for ( int k = 0; k < r; k++ ){
			if (s[k] == 'W')
				ans++;
		}
	}else {
		for ( int k = 0; k < w; k++ ){
			if (s[n - 1 - k] == 'R')
				ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3796
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vii = vector<ii>;
const int oo = 1e9+7;
const ll mod = 1e9+7;
vector<ll> nums;

void add(ll& a, const ll b) {
    a = (a + b) % mod;
}

void sub(ll& a, const ll b) {
    a = (a - b + mod) % mod;
}

//~ int mult(int a, int b) {
    //~ return (ll) a * b % mod;
//~ }

int main() {
    
    int n, k;
    scanf("%d%d",&n,&k);
    
    nums.resize(n);
    for(ll& i : nums) {
        scanf("%lld", &i);
    }
    
    // slow version O(N * K^2)
    
    vector<ll> dp(k+1, 0);
    dp[k] = 1;
    
    // dp[ind][k] - for child with index ind there are dp[ind][k] ways 
    // of having k candies available to take
    
    for(int ind = 0; ind < n-1; ++ind) {
        vector<ll> new_dp(k+1, 0);
        vector<ll> pre(k+1, 0);
        
        for(int avail = k; avail >= 0; --avail) {
            add(pre[avail], dp[avail]);
            if(avail-nums[ind] > 0) sub(pre[avail-nums[ind]-1], dp[avail]);
        }
        
        ll run = 0;
        for(int left = k; left >= 0; --left) {
            add(run, pre[left]);
            add(new_dp[left], run);
        }
        
        dp = new_dp;
    }
    
    ll ans = 0;
    for(int i = 0; i <= nums[n-1]; ++i) {
        add(ans, dp[i]);
    }
    
    printf("%lld\n", ans%mod);
    
    return 0;
}




Measured memory_bytes: 2644
import sys
bingo = [list(map(int, input().split())) for _ in range(3)]
input_num = int(input())
input_list = [int(input()) for _ in range(input_num)]
flag = False

for l in bingo:
	match_count = 0
	if [x for x in l if x in input_list]:
		match_count = len([x for x in l if x in input_list])
		if match_count == 3:
			print('Yes')
			sys.exit()


match_count = 0
for l in list(zip(*bingo)):
	match_count = 0
	if [x for x in l if x in input_list]:
		match_count = len([x for x in l if x in input_list])
		if match_count == 3:
			print('Yes')
			sys.exit()

match_count = 0
for n, l in zip([0,1,2], bingo):
	if l[n] in input_list:
		match_count += 1
	if match_count == 3:
		print('Yes')
		sys.exit()

match_count = 0
for n, l in zip([-1,-2,-3], bingo):
	if l[n] in input_list:
		match_count += 1
	if match_count == 3:
		print('Yes')
		sys.exit()

print('No')

Measured memory_bytes: 3064
from math import ceil
from fractions import gcd

N, M = map(int, input().split())
A = list(map(int, input().split()))

# 2で割ったものに置き換え
A = [a // 2 for a in A]


def lcm(x, y):
    return x*(y//gcd(x, y))


# 各要素について、2で割り切れる回数が等しいかチェック
count_div_2 = None
for a in A:
    cnt = 0
    while a % 2 == 0:
        a //= 2
        cnt += 1

    if count_div_2 is None:
        count_div_2 = cnt
    elif cnt != count_div_2:
        print(0)
        exit()

# LCM計算
while len(A) > 1:
    a, b = A.pop(), A.pop()
    my_lcm = lcm(a, b)

    # Mを超えたlcmは意味がない
    if my_lcm > M:
        print(0)
        exit()

    A.append(my_lcm)


print(ceil(M // A[0] / 2))


Measured memory_bytes: 90080
A = [[]]*3
for T in range(0,3):
    A[T] = [int(x) for x in input().split()]
A   = sum(A,[])
ATF = [False]*9

N = int(input())
for TT in range(0,N):
    B = int(input())
    if B in A:
        ATF[A.index(B)] = True

Flag = 0
if   (all(ATF[:3])) or (all(ATF[3:6])) or (all(ATF[6:])):
    Flag = 1
elif (all(ATF[::3])) or (all(ATF[1::3])) or (all(ATF[2::3])):
    Flag = 1
elif (all(ATF[::4])) or (all(ATF[2:7:2])):
    Flag = 1

if Flag:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 38384
#include <iostream>

using namespace std;

int main(){
    int N;
    int K;
    string S;
    cin >> N >> S >> K;

    string ans;
    for(int i = 0;i < N;i++){
        if(S[i] != S[K-1]) ans += "*";
        else ans += S[K-1];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<sstream>
#include<vector>
#include<cstdlib>
using namespace std;
typedef long long ll;
string S;
ll ans;
bool f[11] = {false};
vector<string> split(const string& input, char delimiter){
  istringstream stream(input);
  string field;
  vector<string>result;
  while(getline(stream,field,delimiter)){
    result.push_back(field);
  }
  return result;
}

void solve(int i, bool flag){
  vector<string>a;
  string s;
  f[i-1] = flag;
  if(i == S.length()){
  s = S;
  int l = 1;
  for(int k = 1; k < S.length(); k++){
    if(f[k]){
      s.insert(s.begin()+l,'+');l++;
    }
    l++;
  }
 
  a = split(s,'+');
  for(int j = 0; j < a.size(); j++){
    ll x = atoll(a[j].c_str());
    ans += x;
  }
    return;
  }
   solve(i+1,false);
   solve(i+1,true);
 
  
    return;
  }
 

int main(){
  cin>>S;
  solve(1,false);
  cout<<ans<<endl;
    
}
 

Measured memory_bytes: 256
from collections import Counter

input()
d = Counter(map(int, input().split()))
d = dict(sorted(d.items(), reverse=True))
ans = []
for i, j in d.items():
    if j >= 4:
        ans.append(i)
    if j >= 2:
        ans.append(i)
if len(ans) >= 2:
    print(ans[0] * ans[1])
else:
    print(0)

Measured memory_bytes: 34676
#include<bits/stdc++.h>
#define ll long long 
#define P pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int cnt;
void out(vector<int> a,int n){
    rep(j,n){
        cout << a[j];
        if(j!=n-1) cout << " ";
    }
    cout << endl;
}

vector<int> insertionSort(vector<int> a,int n,int g){
    for(int i=g;i<n;i++){
        int v = a[i];
        int j = i-g;
        while(j>=0 && a[j]>v){
            a[j+g] = a[j];
            j -= g;
            cnt++;
        }
        a[j+g] = v;
    }
    return a;
}
void shellSort(vector<int> a,int n){
    cnt = 0;
    int r = 1;
    vector<int> G;
    while(r<=n){
        G.push_back(r);
        r *= 2;
    }
    int m = G.size();
    reverse(G.begin(),G.end());
    cout << m << endl;
    out(G,m);
    rep(i,m){
        a = insertionSort(a,n,G[i]);
    }
    cout << cnt << endl;
    rep(i,n) cout << a[i] << endl;
}

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    shellSort(a,n);
    return 0;
}


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

int main(){
    char I[3]="aaa";
    int N,M,s;
    char c;
    scanf("%d",&N);
    scanf("%d",&M);
    for (int i=0; i<M; i++) {
        scanf("%d %c",&s,&c);
        if(I[s-1]!='a'){
            if (c!=I[s-1]) {
                printf("-1\n");
                return 0;
            }
        }
        else{
            I[s-1]=c;
        }
    }
    if (N==1) {
        if (M==0) {
            printf("0\n");
            return 0;
        }
        else{
            printf("%c\n",I[0]);
            return 0;
        }
    }
    else{
        for (int i=0; i<N; i++) {
            if (i==0) {
                if(I[i]=='0'){
                    printf("-1\n");
                    return 0;
                }
                else if(I[i]=='a'){
                    printf("1");
                }
                else{
                    printf("%c",I[i]);
                }
            }
            else{
                if(I[i]=='a'){
                    printf("0");
                }
                else{
                    printf("%c",I[i]);
                }
            }
        }
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=45,M=(1ll<<17)+10,mod=1e9+7;
ll dp[N][M];
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n,x,y,z;cin>>n>>x>>y>>z;
    ll req_mask = (1ll<<(z-1)) + (1ll<<(y+z-1)) + (1ll<<(x+y+z-1));
    ll mx_mask = (1ll<<(x+y+z));
    dp[0][0]=1;
    for(ll i=0;i<n;i++){
        for(ll mask=0;mask<=mx_mask;mask++){
            if(dp[i][mask]==0)continue;
            for(ll p=1;p<=10;p++){
                if(mask==mx_mask){
                    dp[i+1][mask]+=dp[i][mask];
                    dp[i+1][mask]%=mod;
                    continue;
                }
                ll nmask= ( (mask<<p)| (1ll<<(p-1)) ) & (mx_mask-1);
                if((nmask&req_mask)==req_mask)nmask=mx_mask;
                dp[i+1][nmask]+=dp[i][mask];
                dp[i+1][nmask]%=mod;
            }
        }
    }
    cout<<dp[n][mx_mask];
}


Measured memory_bytes: 41216
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    ll A, B, V, W, T;
    cin >> A >> V >> B >> W >> T;
    if(abs(B-A) > T*(V-W)) cout << "NO" << endl;
    else cout << "YES" << endl;
}

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

#define REP(i,n) for(int (i) = 0;(i) < (n);(i)++)
using namespace std;

class node{
public:
	int id;
	int parent,child1,child2,sibling;
	int degree,depth,height;
	node():id(-1),parent(-1),child1(-1),child2(-1),sibling(-1),degree(0),depth(0),height(0){};
	
	friend ostream& operator<<(ostream& os,const node& N){
		cout << "node " 		<< N.id ;
		cout << ": parent = "	<< N.parent;
		cout << ", sibling = " 	<< N.sibling;
		cout << ", degree = " 	<< N.degree;
		cout << ", depth = " 	<< N.depth;
		cout << ", height = "	<< N.height;
		cout << ", ";
		if(N.parent==-1) cout << "root";
		else if(N.child1==-1 && N.child2==-1) cout << "leaf";
		else cout << "internal node";
		cout << endl;
	}
};

void Pre(int n,vector<node> N){
	int c1=N[n].child1,c2=N[n].child2;
	cout << " " << n;
	if(c1 != -1) Pre(c1,N);
	if(c2 != -1) Pre(c2,N);
}

void Ino(int n,vector<node> N){
	int c1=N[n].child1,c2=N[n].child2;
	if(c1 != -1) Ino(c1,N);
	cout << " " << n;
	if(c2 != -1) Ino(c2,N);
}

void Pos(int n,vector<node> N){
	int c1=N[n].child1,c2=N[n].child2;
	if(c1 != -1) Pos(c1,N);
	if(c2 != -1) Pos(c2,N);
	cout << " " << n;
}

int main(){
	int n,m;
	cin >> n;
	vector<node> N(n);
	REP(i,n){
		N[i].id=i;
	}
	REP(i,n){
		int id,c1,c2;
		cin >> id >> c1 >> c2;
		N[id].child1 = c1;
		N[id].child2 = c2;
		N[id].degree = ((c1!=-1)?1:0)+((c2!=-1)?1:0);
		if(c1 != -1) N[c1].sibling = c2,N[c1].parent = id;
		if(c2 != -1) N[c2].sibling = c1,N[c2].parent = id;
	}
	int i;
	while(N[i].parent!=-1)i++;
	cout << "Preorder" << endl;Pre(i,N);
	cout << endl << "Inorder" << endl;Ino(i,N);
	cout << endl << "Postorder" << endl;Pos(i,N);
	cout << endl;
	return 0;
}

Measured memory_bytes: 3048
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<string,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
ll INF=1LL<<60;
ll MOD=1000000007;

int main(){
    ll N;
    cin >> N;
    Map M;
    for(ll i=0;i<N;i++){
        string s;
        cin>>s;
        M[s]++;
    ;}
    cout<<M.size()<<endl;

    return 0;
}


Measured memory_bytes: 19228
-- | Main entry point to the application.
module Main where
 
import Control.Applicative
import Control.Monad
import Data.List
import Debug.Trace
import Text.Printf
import Data.Array

-- | The main entry point.
main :: IO ()
main = do
    ns <- concatMap (fmap (read :: String -> Int) . words) . lines <$> getContents
    -- let ns = [5,3,1,3,4,3]
    let topthree = take 3 $ reverse $ sort ns
    forM_ [0..2] $ \i -> do
      putStrLn $ show $ topthree !! i

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long
#define vi vector <int>
#define pii pair <int, int>
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i,n) for (int i = 0; i < (int) (n); ++ i)
#define foreach(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); ++ it)

inline int read() {
	int x = 0, f = 1, c = getchar();
	for (;!isdigit(c);c = getchar()) if (c == '-') f ^= 1;
	for (; isdigit(c);c = getchar()) x = x * 10 + c - '0';
	return f ? x : -x;
}

#define N 305
int n, m, L;
vi g[N], cost[N];
ll dis[N][N];
ll dp[N][N];
int que[N], lb, rb;

int main() {
	n = read(), m = read(), L = read();
	memset(dis, 0x3f, sizeof(dis));
	rep(i, m) {
		int u = read() - 1, v = read() - 1, w = read();
		g[u].pb(v); cost[u].pb(w);
		g[v].pb(u); cost[v].pb(w);
		dis[u][v] = dis[v][u] = w;
	}
	rep(k, n) rep(i, n) rep(j, n) dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
	memset(dp, -1, sizeof(dp));
	rep(t, n) {
		lb = rb = 0;
		rep(s, n) if (dis[s][t] <= L) {
			dp[s][t] = 0; que[rb ++] = s;
		}
		while (lb < rb) {
			int u = que[lb ++];
			rep(s, n) if (dis[s][u] <= L) {
				if (!~dp[s][t]) {
					dp[s][t] = dp[u][t] + 1;
					que[rb ++] = s;
				}
			}
		}
	}
	for (int q = read(); q --; ) {
		int s = read() - 1, t = read() - 1;
		printf("%lld\n", dp[s][t]);
	}
	return 0;
}

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

int main() {
  int N,M,i,j;
  cin >> N >> M;
  vector<int> city(N);
  int k;
  for(i=0;i<M*2;i++){
    cin >>k;
    for(j=0;j<N;j++){
      if(k-1==j){
        city[j]++;
        break;
      }
    }
  }
  for(i=0;i<N;i++){
    cout << city[i] << endl ;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int x[n],y[n];
  for(int i=0;i<n;i++){
  	cin>>x[i];
  }
  for(int j=0;j<n;j++){
  	cin>>y[j];
  }
  int ans=0;
  for(int i=0;i<n;i++){
  	if(x[i]-y[i]>0){
  		ans+=x[i]-y[i];
  	}
  }
  cout<<ans<<endl;
}


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

int main() {
	// your code goes here
	string m,n;
	while(cin >> m >> n && m!="0"){
		int h=0,b=0;
		int nums[10][2]={};
		for(int i=0;i<4;i++)
			if(m[i]==n[i])
				h++;
			else{
				nums[m[i]-'0'][0]++;
				nums[n[i]-'0'][1]++;
			}
		for(int i=0;i<9;i++){
			if(min(nums[i][0],nums[i][1])>0)
			b+=min(nums[i][0],nums[i][1]);
		}
		cout << h << " " << b << endl;
	}
	return 0;
}

Measured memory_bytes: 1184
import java.util.*;
 
public class Main{
  public static void main(String[]args){
    Scanner sc =  new Scanner(System.in);
    int A = Integer.parseInt(sc.next());
    int B = Integer.parseInt(sc.next());
    if(A%2 != B%2){
      System.out.println("IMPOSSIBLE");
      return;
    }
    
    System.out.println((A+B)/2);
  }
}

Measured memory_bytes: 22996
// -*- coding:utf-8-unix -*-

use proconio::input;

// ABC086C - Traveling
// https://atcoder.jp/contests/abs/fasks/arc089_a

fn main() {
    input! {
        x: usize,
        y: usize,
        z: usize,
        k: usize,
        mut a: [usize; x],  // Vec<(i32, i32, i32)>
        mut b: [usize; y],
        mut c: [usize; z],
    }

    // oishii junnni sort
    a.sort_unstable_by(|a0,a1| a1.cmp(a0));
    b.sort_unstable_by(|b0,b1| b1.cmp(b0));
    c.sort_unstable_by(|c0,c1| c1.cmp(c0));
    
    // a, b dake kangaeru
    // kouho wo atsumeru
    let mut aplusb :Vec<usize> = Vec::new();
    for i in 0..k.min(x) {
        for j in 0..k.min(y) {
            aplusb.push(a[i]+b[j]);
        }
    }
    // sort
    aplusb.sort_unstable_by(|x0,x1| x1.cmp(x0));
    let aplusb = aplusb;

    // a, b, c wo kangaeru
    // kouho wo atsumeru
    let mut aplusbplusc :Vec<usize> = Vec::new();
    for l in 0..k.min(x*y) {
        for m in 0..k.min(z) {
            aplusbplusc.push(aplusb[l]+c[m]);
        }
    }
    // sort
    aplusbplusc.sort_unstable_by(|x0,x1| x1.cmp(x0));

    // output
    for n in 0..k {
        println!("{}", aplusbplusc[n]);
    }
}


Measured memory_bytes: 33332
n = int(input())
l = sorted([int(x) for x in input().split()])
coeff_l = [n-1] + [n-x for x in range(1,n)]
coeff_l = [1*0.5**n for n in coeff_l]
result = sum([a*b for a,b in zip(l,coeff_l)])
print(result)

Measured memory_bytes: 3060
using System;

namespace abc070c
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            long[] t = new long[n];
            for (int i = 0; i < n; i++)
            {
                t[i] = long.Parse(Console.ReadLine());
            }

            long current = 0;
            for (int i = 0; i < n; i++)
            {
                if (current == 0)
                {
                    current = t[i];
                    continue;
                }

                current = Lcm(current, t[i]);
                //Console.WriteLine(current);
            }
            Console.WriteLine(current);
        }

        static long Gcd(long a, long b)
        {
            if (b == 0)
                return a;

            return Gcd(b, a % b);
        }

        static long Lcm(long a, long b)
        {
            return a / Gcd(a, b) * b;
        }
    }
}

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;




int main() {
  int a,b,k;
  cin >> a >> b >>k;
  
 for(int i=a;i<min(a+k,b+1);i++){
    cout << i <<endl;
  }
  
  for(int i=max(b-k+1,a+k);i<=b;i++){
    cout << i << endl;
  }
  
}
       
    
  


Measured memory_bytes: 256
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif

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

    int N; cin >> N;
    vl A(N); REP(i, N) cin >> A[i];

    ll ans = 0;
    ll sum = 0;
    int r = 0;
    REP(l, N) {
        while(r < N && (sum & A[r]) == 0) {
            sum += A[r];
            r++;
        }
        ans += (r - 1) - l + 1;

        sum -= A[l];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
import java.util.*;
import java.io.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int N = Integer.parseInt(sc.next());
        List<Integer> list = new ArrayList<Integer>(N);
        for (int i = 0; i < N; i++) {
            list.add(new Integer(sc.next()));
        }
        sc.close();
        Collections.sort(list);

        double max = list.get(0);
        for (int i = 1; i < N; i++) {
            double temp = max;
            max = (temp + list.get(i)) / 2.0;
        }

        out.printf("%.10f\n", max);
        out.flush();
    }
}


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

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

    pair<long long, int> p[100010];
    for(int i = 0;i < n;i++){
        cin >> p[i].first >> p[i].second;
    }

    sort(p, p+n);

    long long ans = 0;
    int i = 0;
    while(m > 0){
        if(p[i].second == 0){
            i++;
        }
        m--;
        ans += p[i].first;
        p[i].second--;
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for(int i = 0;i < (n);i++)
#define rep(i,m,n) for(int i = (m);i < (n);i++)
#define P pair<int,int>
#define pb push_back
#define mk make_pair
using namespace std;
const int INF = 1e9;



#define MAX_V 10000

struct edge {
    int to;
    int cost;
};


int V;
vector<edge> G[MAX_V];
int d[MAX_V];


void dijkstra(int s) {
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d+V, INF);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;

        for (int i=0; i<G[v].size(); ++i) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}



int main(){
  int E,r;
  cin >> V >> E;
  REP(i,E){
    int f,t,c;
    cin >> f >> t >> c;
    f--;
    t--;
    edge e = {t,c};
    G[f].pb(e);
    e.to = f;
    G[t].pb(e);
  }
  ll dis[V][V];
  REP(i,V){
    dijkstra(i);
    REP(j,V){
      dis[i][j] = d[j];
    }
  }
  
  ll sum = 0;
 
  REP(i,V){
    REP(j,G[i].size()){
      bool u = false;
      REP(k,V){
	if(dis[k][i] + G[i][j].cost == dis[k][G[i][j].to]){
	  u = true;
	}
      }
      if(!u)
	sum++;
      
    }
  }
  
  cout << sum/2 << endl;
  return 0;
}


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

#define sz(a) int((a).size())
#define all(c) c.begin(), c.end()
#define ll long long
#define pb push_back
#define zoom                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define pl pair<ll, ll>
#define MOD 1000000007
#define endl "\n"
#define ff first
#define ss second
#define trace1(x) cerr << #x << ": " << x << endl
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z) cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl
#define trace4(a, b, c, d) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl
#define trace5(a, b, c, d, e) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl
#define trace(v)                                   \
    for (auto it = v.begin(); it != v.end(); it++) \
        cerr << *it << " ";                        \
    cerr << endl;
#define tr(container, it) \
    for (typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<vi> vvi;

void solve()
{
    int n=5;

    for(int i=1;i<=n;i++){
        int temp;
        cin>>temp;

        if(temp==0){
            cout<<i<<endl;
            return;
        }
    } 
}

int main()
{
    zoom;
    ll t=1;
    //cin >> t;

    while (t--)
    {
        solve();
    }
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define INF 1e18
#define P pair<int,int>
vector<P> g[100001];
int d[100001];
void dfs(int now){
    for(int i=0;i<g[now].size();i++){
        if(d[g[now][i].first]>d[now]+g[now][i].second){
            d[g[now][i].first]=d[now]+g[now][i].second;
            dfs(g[now][i].first);
        }
    }
}
signed main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        d[i]=INF;
    }
    for(int i=0;i<n-1;i++){
        int a,b,c;
        cin>>a>>b>>c;
        g[a].push_back(P(b,c));
        g[b].push_back(P(a,c));
    }
    int q,k;
    cin>>q>>k;
    d[k]=0;
    dfs(k);
    for(int i=0;i<q;i++){
        int a,b;
        cin>>a>>b;
        cout<<d[a]+d[b]<<endl;
    }
    return 0;
}

Measured memory_bytes: 14336
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN=3e5+5,INF=1e9+7;
ll nums[MAXN];
int b[60];

int main()
{
    int N;
    cin>>N;
    for(int i=0;i<N;i++) {
        cin>>nums[i];
        for(int j=0;j<60;j++)
            if(nums[i]>>j&1) b[j]++;
    }
    ll ans=0;
//    for(int i=0;i<N-1;i++){ //n^2 TLE
//        ll sum=0;
//        for(int j=i+1;j<N;j++)
//            sum +=(nums[i]^nums[j])%INF;
//        //cout<<sum<<endl;
//        ans +=sum%INF;
//    }
    for(int i=0;i<N;i++){ //O(n) AC
        for(int j=0;j<60;j++)
            if(nums[i]>>j&1) b[j]--;
        for(int j=0;j<60;j++)
            if(nums[i]>>j&1)
                ans=(ans+(1ll<<j)%INF*(N-1-i-b[j])%INF)%INF;
            else
                ans=(ans+(1ll<<j)%INF*b[j]%INF)%INF;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 2560
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define fo(x,a,b) for(register int x=a;x<=b;x++)
#define dfo(x,a,b) for(register int x=a;x>b;x--)
#define p  1000000007
#define intt long long
using namespace std;
intt n,y;
intt fun(intt x,intt k)
{
	if (k==0) return 1;
	if (k==1) return x;
	if (k%2==0) return(fun(x,k/2)*fun(x,k/2)%p);else return(x*fun(x,k-1)%p);
}
int main ()
{
	//freopen("fun.in","r",stdin);
	//freopen("fun.out","w",stdout);

	scanf("%lld%lld",&n,&y);
	printf("%lld\n",fun(n,y)%p);

	return 0;
}





Measured memory_bytes: 3232
#include<stdio.h>
#define N 100
#define INF 100000000

int n, color[N], A[N][N], B[N], C[N];

void prim()
{
  int min, i, j;
  for(i = 0; i < n; i++)
    {
      B[i] = INF;
      C[i] = -1;
      color[i] = 0;
    }
  B[0] = 0;

  while(1)
    {
      min = INF;
      for(i = 0; i < n; i++)
	{
	  if(color[i] != 1 && B[i] < min)
	    {
	      min = B[i];
	      j = i;
	    }
	}
      if(min == INF)
	{
	  break;
	}
      color[j] = 1;
      for(i = 0; i < n; i++)
	{
	  if(color[i] != 1 && A[j][i] < B[i] && A[j][i] >= 0)
	    {
	      C[i] = j;
	      B[i] = A[j][i];
	    }
	}
    }
}

int main()
{
  int i, j, c;
  c = 0;
  scanf("%d", &n);
  for(i = 0; i < n; i++)
    {
      for(j = 0; j < n; j++)
	{
	  scanf("%d", &A[i][j]);
	}
    }
  prim();
  for(i = 0; i < n; i++)
    {
      c += B[i];
    }
  printf("%d\n", c);
  return 0;
}



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

using namespace std;
using LL = long long;

constexpr int N = 1e5 + 5;

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

    int n, m;
    cin >> n >> m;
    vector< int> wacnt(n + 1);

    int ac = 0, pen = 0;
    for (int i = 0; i < m; i++) {
        int x; string v;
        cin >> x >> v;
        if (v == "AC") {
            if (wacnt[x] != -1) {
                ac++; pen += wacnt[x];
            }
            wacnt[x] = -1;
        }
        else {
            if (wacnt[x] != -1) {
                wacnt[x]++;
            }
        }
    }
    cout << ac << ' ' << pen << "\n";
}

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

#define y1 dmytxdy
#define pb push_back
#define fi first
#define se second
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;

template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}

ll readint(){
	ll x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

int n,tot;
int v[100005],nxt[100005],h[100005],dep[100005],siz[100005];
pll a[100005];
vector<pii> ans;

void addedge(int x,int y){v[++tot]=y; nxt[tot]=h[x]; h[x]=tot;}

void dfs(int u){
	for(int p=h[u];p;p=nxt[p]){
		dep[v[p]]=dep[u]+1;
		dfs(v[p]);
	}
}

int main(){
	n=readint();
	for(int i=1;i<=n;i++) a[i]=mp(readint(),i);
	for(int i=1;i<=n;i++) siz[i]=1;
	sort(a+1,a+n+1);
	for(int i=n;i>=2;i--){
		ll tmp=a[i].fi-(n-2*siz[i]);
		int x=lower_bound(a+1,a+n+1,mp(tmp,0ll))-a;
		ans.pb(mp(a[x].se,a[i].se));
		addedge(a[x].se,a[i].se);
		siz[x]+=siz[i];
	}
	dfs(a[1].se);
	ll sum=0;
	for(int i=1;i<=n;i++) sum+=dep[i];
	if(sum!=a[1].fi) return printf("-1\n"),0;
	for(auto r:ans) printf("%d %d\n",r.fi,r.se);
	return 0;
}

Measured memory_bytes: 9928
#include <stdio.h>
int main(void)
{
  int R;
  scanf("%d",&R);
  if(R<1200)
  {
    printf("ABC");
  }
  else
  {
    if(R<2800)
    {
      printf("ARC");
    }
    else
    {
      printf("AGC");
    }
  }
  return 0;
}

Measured memory_bytes: 128
const BKRT = "\n";
const SPAC = " ";
const NOSP = "";

function Main(input){
	input = [].concat(...input.split(BKRT).map(a=>a.split(SPAC)));
  const strShift = ()=>input.shift();
  const intShift = ()=>~~input.shift();
  
  var A = intShift();
  var B = intShift();
  var C = intShift();
  
  var AB = [~~Math.min(A,B),~~Math.max(A,B)];
  
  return AB[0] < C && C < AB[1]?"Yes":"No";
}

// If you are interested in the algorithms I used, 
// there is no need to read down from this line.

((b,c,d)=>"undefined"!=typeof require?console.log(Main(require("fs").readFileSync("/dev/stdin","utf8"))):[b=b.split("\n").slice(1,-1).join("\n"),c=function(){try{return Main(b)}catch(f){return f.stack||f.message}}(),d=typeof c,"string"==d||(c=JSON.stringify(c)),$("<form>").append([[10,b],0,[1,d],0,[10,c]].map(f=>$(f?"<textarea>":"<br>",f&&{rows:f[0],cols:40,text:f[1]}))).appendTo("body")])(`
7 3 1
`);

Measured memory_bytes: 21064
#include<iostream>
#include<math.h>
#include<bits/stdc++.h>
#define ll long long int
#define hell 1000000007LL
using namespace std;
ll power(ll x, ll y, ll z){ 
    if(y==0)
     return 1;
    else
    {
        ll p=power(x,y/2,z);
        if(y%2==0)
         return (p*p)%z;
        else
        return (x*((p*p)%z))%z;
    }}
ll gcd(ll x,ll y)
{
    if(y==0)
     return x;
    else
    return gcd(y,x%y);
}
ll po(ll x)
{
    ll c=0;
    while(x>0)
    {
        x=x&(x-1);
        c++;
    }
    return c;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
    ll k,p=1;
    cin>>k;
    for(ll i=1;i<=1000000;i++)
    {
      ll z=(7*p)%k;
      if(z==0){
       cout<<i;
       exit(0);}
      p=(p*10+1)%k;
    }
    cout<<-1;}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <bitset>
using namespace std;

const int INF = 100001;

int main(void)
{
    long N, M;
    cin >> N >> M;
    // vector<vector<bool>> road(N, vector<bool>(N, false));
    map<int, vector<int>> road;
    for (int  i = 0; i < M; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;

        road[a].push_back(b);
        road[b].push_back(a);
    }

    vector<int> where_from(N, -1);
    where_from[0] = 1;
    
    // <room>
    queue<int> que;
    que.push(0);

    while (!que.empty())
    {
        int room = que.front();
        que.pop();

        for (int i = 0; i < road[room].size(); i++)
        {
            // 初めて訪れたら
            if(where_from[ road[room][i] ] == -1)
            {
                que.push( road[room][i] );
                where_from[ road[room][i] ] = room;
            }
        }
    }
    
    // いけるか
    for (int i = 1; i < N; i++)
    {
        if (where_from[i] < 0)
        {
            cout << "No" << endl;
            return 0;
        }
    }
    
    cout << "Yes" << endl;
    for (int i = 1; i < N; i++)
    {
        cout << where_from[i] + 1 << endl;
    }

    return 0;
}

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

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

  int n = stoi(a + b);

  int root_n = sqrt(n);

  if (root_n * root_n == n) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main() {
    int N,M; cin >> N >> M;
    vector<pair<int,int>> pos(N);
    vector<pair<int,int>> point(M);
    REP(i,N){
        cin >> pos[i].first >> pos[i].second;
    }
    REP(i,M){
        cin >> point[i].first >> point[i].second;
    }

    REP(i,N){
        int dis = INF;
        int cp;
        REP(j,M){
            if(abs(pos[i].first-point[j].first) + abs(pos[i].second-point[j].second) < dis){
                dis = abs(pos[i].first-point[j].first) + abs(pos[i].second-point[j].second);
                cp = j+1;
            }
        }
        cout << cp << endl;
    }


    return 0;
}

Measured memory_bytes: 3596
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<list>
#include<stack>
#include<queue>
#include<cctype>
#include<iomanip>
#include<functional>
#include<numeric>
#include<map>
#include<set>
#define EPS 1e-10
using namespace std;
typedef long long llong;

int main() {
	int k, t;
	cin >> k >> t;
	vector<int>a(t);
	for (int i = 0; i < t; i++) {
		cin >> a[i];
	}
	if (t == 1) {
		cout << k - t << endl;
		return 0;
	}
	auto it = max_element(a.begin(), a.end());
	int index = distance(a.begin(),max_element(a.begin(), a.end()));
	(*it)--;
	//cout << "index is " << index << endl;
	//for (int i = 0; i < t; i++) {
	//	cout << a[i] << " ";
	//}
	//cout << endl;
	for (int cnt = 1; cnt < k; cnt++) {
		int max = -(1<<21);
		int p ;
		
		for (int i = 0; i < t; i++) {
			if (i == index)continue;
			if (max < a[i]) {
				max = a[i];
				p = i;
			}
		}
		//cout << "index is " << index << endl;
		a[p]--;
		index = p;
		bool f = true;
		for (int i = 0; i < t; i++) {
			if (i == p)continue;
			if (a[i] != 0)f = false;
		}
		if (f)break;
		//for (int i = 0; i < t; i++) {
		//	cout << a[i] << " ";
		//}
		//cout << endl;
		
	}
	//for (int i = 0; i < t; i++) {
	//	cout << a[i] << " ";
	//}
	//cout << endl;
	cout << *max_element(a.begin(), a.end())  << endl;
	//int max = *max_element(a.begin(), a.end());
	//vector<int>::iterator it = max_element(a.begin(), a.end());
	//(*it)--;
	//int x = 0;
	//for (int cnt = 1; cnt < k; cnt++) {
	//	auto g = max_element(a.begin(), it);
	//	auto h = max_element(it + 1, a.end());
	//	if (*h == 0 && *g == 0)break;
	//	if (*g > *h) {
	//		(*g)--;
	//		it = g;
	//	}
	//	else {
	//		(*h)--;
	//		it = h;
	//	}
	//}
	//cout << *max_element(a.begin(), a.end()) << endl;
	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val string = readLine()!!
    if (string[2] != string[3]) {
        println("No")
        return
    }
    // string[2] == string[3]
    if (string[4] == string[5]) {
        println("Yes")
    } else {
        println("No")
    }
}


Measured memory_bytes: 31908
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
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;
}
 
const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
}
ll lcm(ll x,ll y){
  ll g=gcd(x,y);
  return x/g*y;
}

using Graph=vector<vector<int>>;
Graph G;

int main(){
  //input
  ll n,k;
  cin >> n >> k;
  vector<ll>h(n);
  rep(i,n) cin >> h[i];
  
  //initialization
  ll dp[100010]={};
  rep(i,100010)dp[i]=INFL;
  dp[0]=0;
  
  //compute
  rep(i,n){
    for(int j=1;j<=k;j++){
      if(i+j<n)dp[i+j]=min(dp[i+j],dp[i]+abs(h[i+j]-h[i]));
    }
  }
  
  //output
  cout << dp[n-1] << endl;
  
  
}
    


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define int long long
#define all(v) v.begin(), v.end()
#define sc(a) scanf("%l64d", &a)
#define pr(a) printf("%l64d", a)

using namespace std;

const int INF = 1e18;
const int MAXN = 1e5 + 1;
const int M = 1e9 + 7;

main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    //freopen("", "r", stdin);
    //freopen("", "w", stdout);
    int n;
    cin >> n;
    if (n % 10 == 9 || n / 10 == 9)
        cout << "Yes";
    else
        cout << "No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    string d[4] = {"dream", "dreamer", "erase", "eraser"};
    string s;
    cin >> s;
    int len = s.size();

    while(len != 0){
        for(int i=0;i<4;i++){
            string tmp = "";
            if(len < d[i].size()){
                continue;
            }
            tmp = s.substr(len - d[i].size(),d[i].size());
            if (tmp.compare(d[i])==0){
                s = s.substr(0,len-d[i].size());
                len = s.size();
                goto loop;
            }
        }
        printf("NO\n");
        return 0;
        loop:;
    }
    printf("YES\n");
}


Measured memory_bytes: 512
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"
#include "stack"
#include "queue"

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

int main()
{
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  int size = s.size();
  int cnt[100100];
  cnt[0] = 0;
  for (int i = 0; i < size; i++)
  {
    cnt[i + 1] = cnt[i] + (s[i] == 'A' && s[i + 1] == 'C' ? 1 : 0);
  }
  int l, r;

  for (int i = 0; i < q; i++)
  {
    cin >> l >> r;
    l--;
    r--;
    cout << cnt[r] - cnt[l] << "\n";
  }
}


Measured memory_bytes: 1408
#include<iostream>
using namespace std;
int main(){
  int ans = 1;
  int n; cin >> n;
  int odd = 1;
  for(int i = 0; i < n; i++){
    ans *= 3;
    int a; cin >> a;
    if(a % 2 == 0) odd *= 2;
  }
  cout << ans - odd;
}

Measured memory_bytes: 3568
#include<stdio.h>
int main(void)
{
	int N,i,p[10];
	int a,sum=0;

	scanf("%d",&N);
	scanf("%d",&p[0]);

	for(i=1;i<N;i++){
		scanf("%d",&p[i]);
		if(p[i]>p[0]){
			a=p[0];
			p[0]=p[i];
			p[i]=a;
		}
	}

	sum+=p[0]/2;

	for(i=1;i<N;i++){
		sum+=p[i];
	}

	printf("%d",sum);
}

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

int main()
{
    int N;
    map<int, int> A;
    cin >> N;
    for (int i = 1; i <= N; i++)
    {
        int a;
        cin >> a;
        A.insert(make_pair(a, i));
    }
    for (int i = 1; i <= N; i++)
    {
        cout << A[i] << " ";
    }
    return 0;
}

Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 1e6 + 7;
const int Inf = 1 << 30;
const ll INF = 1ll << 60;
#define mst(x) memset(x, 0, sizeof(x))
priority_queue <int> qua;
ll a[maxx];
vector <ll> vec;
int n, k;
ll ans;
 
void Init() {
	cin >> n >> k;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 1; i <= n; i++) {
		ll sum = 0;
		for(int j = i; j <= n; j++) {
			sum += a[j];
			vec.push_back(sum);
		}
	}
}
 
void solve() { 
	for(int bit = 59; bit >= 0; bit--) {
		int cnt = 0; 
		int sz = vec.size();
		for(int i = 0; i < sz; i++) {
			ll dd = 1ll << bit;
			if(vec[i] & dd) cnt++;
		}
		if(cnt < k) continue;
		vector <ll> tmp;
		tmp.clear();
		for(int i = 0; i < sz; i++) {
			ll dd = 1ll << bit;
			if(vec[i] & dd) tmp.push_back(vec[i]);
		}
		vec = tmp; 
		ans += 1ll << bit;
	}
}
 
int main() {
	Init();
	solve();
	cout << ans << endl;
}

Measured memory_bytes: 6128
package main

import "fmt"

func main() {
	var n int
	var cardflags [4][13]bool
	var kind string // 0:スペード 1:ハート 2:クラブ 3:ダイヤ
	var number int
	fmt.Scanln(&n)
	for i := 0; i < n; i++ {
		fmt.Scanln(&kind, &number)
		number--
		switch kind {
		case "S":
			cardflags[0][number] = true
		case "H":
			cardflags[1][number] = true
		case "C":
			cardflags[2][number] = true
		case "D":
			cardflags[3][number] = true
		}
	}
	for i := 0; i < 4; i++ {
		for j := 0; j < 13; j++ {
			if !cardflags[i][j] {
				switch i {
				case 0:
					fmt.Println("S", j+1)
				case 1:
					fmt.Println("H", j+1)
				case 2:
					fmt.Println("C", j+1)
				case 3:
					fmt.Println("D", j+1)
				}
			}
		}
	}
}



Measured memory_bytes: 1132