akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define sll(x) scanf("%lld",&x)
#define prll(x) printf("%lld ",x)
#define pri(x) printf("%d ",x)
#define si(x) scanf("%d",&x)
#define el cout << "\n"
#define pb push_back
#define f first
#define s second
#define arrondi(a) (long long)floor(a+0.5);
#define NIL -1
ll N=500005;
ll MAX=9223372036854775807;
ll MOD=1000000007;
long double PI =4*atan(1);
ll n , m ,k;
ll nbr;

int main()
{
	IOS;
	 std::cout << std::setprecision(30);
    vector<vector<ll>> A(3,vector<ll>(3,0));
    vector<vector<ll>> dp(3,vector<ll>(3,0));
    for (ll i=0;i<3;i++)
    {
        for(ll j=0;j<3;j++)
        {
            cin >> A[i][j];
        }
    }
    ll n;
    cin >> n;
    for( ll i=0;i<n;i++)
    {
        ll x;
        cin >> x;
        for (ll i=0;i<3;i++)
    {
        for(ll j=0;j<3;j++)
        {
            if(x==A[i][j])
                dp[i][j]=1;
        }
    }

    }

    bool B=true;
    for(int i=0;i<3;i++)
    {
        for(int j=0;j<3;j++)
        {
            B= B&&(dp[i][j]);

        }
        if(B==true)
            return cout << "Yes",0;
        B=true;
    }
    for(int i=0;i<3;i++)
    {
        for(int j=0;j<3;j++)
        {
            B=B & (dp[j][i]);
        }
         if(B==true)
            return cout << "Yes",0;
        B=true;
    }
    if((dp[0][0] && dp[1][1] && dp[2][2]) || (dp[0][2] && dp[1][1] && dp[2][0]))
        return cout << "Yes",0;
    cout << "No";
    cout.precision(30);
    return 0;
}


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

int main(void){
  char s[10]; int i, x = 0, y = 0;
  scanf("%s", &s);
  if(s[0] != 'A'){
    printf("WA\n");
    return 0;
  }
  for(i=2; i<=strlen(s)-2; i++){
    if(s[i] == 'C'){
      x++;
    }
  }
  for(i=0; i<=strlen(s)-1; i++){
    if(s[i] - 'a' < 0){
      y++;
    }
  }
  if(x == 1 && y == 2){
    printf("AC\n");
  }else{
    printf("WA\n");
  }
  return 0;
}


Measured memory_bytes: 128
from bisect import bisect_right
n = int(input())
a, b = map(int, input().split())
p = list(map(int, input().split()))
p.sort()

idx_a = bisect_right(p, a)
idx_b = bisect_right(p, b)

ans = min(idx_a, idx_b - idx_a, n - idx_b)
print(ans)


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

int main(){
  vector<int> a(2);
  while(1){
    cin>>a[0]>>a[1];
    if(a[0]==a[1]&&a[0]==0)break;
    sort(a.begin(),a.end());
    cout<<a[0]<<" "<<a[1]<<endl;
    
  }
}



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

using namespace std;

using ll = long long;

class UnionFind {
  vector<ll> par, h;
public:
  UnionFind(ll size) : par(size, 0), h(size, 0) {
    for (int i = 0; i < size; ++i) {
      par[i] = i;
    }
  }
  void unite(ll u, ll v) {
    u = root(u), v = root(v);
    if (u == v) return;
    if (h[u] < h[v]) {
      par[u] = v;
    }
    else {
      par[v] = u;
    }
    if (h[u] == h[v]) ++h[u];
  }
  bool isUnited(ll u, ll v) {
    return root(u) == root(v);
  }
  ll root(ll v) {
    if (par[v] == v) return v;
    return par[v] = root(par[v]);
  }
};

template<class Calc>
class EdgeDpOnForest {
public:
  using T = typename Calc::type;
  struct Edge {
    ll to, rev;
    T value;
  };
private:
  ll n;
  void dfs1(ll v, ll pv) {
    ll idx = -1;
    vector<T> values;
    for (int i = 0; i < G[v].size(); ++i) {
      const Edge& e = G[v][i];
      if (e.to == pv) {
        idx = i;
        continue;
      }
      dfs1(e.to, v);
      values.push_back(e.value);
    }
    // 根以外では親から入る辺の値を更新
    if (idx >= 0) {
      const Edge& e = G[v][idx];
      G[e.to][e.rev].value = Calc::merge(values);
    }
  }
  void dfs2(ll v, ll pv) {
    vector<T> values;
    for (auto&& e : G[v]) values.push_back(e.value);
    values = Calc::evaluate(values);
    for (int i = 0; i < G[v].size(); ++i) {
      const Edge& e = G[v][i];
      if (e.to == pv) continue;
      G[e.to][e.rev].value = values[i];
      dfs2(e.to, v);
    }
  }
public:
  UnionFind uf;
  vector<vector<Edge>> G;
  EdgeDpOnForest(ll n) : n(n), uf(n), G(n) {}
  void add(ll u, ll v) {
    assert(!uf.isUnited(u, v));
    G[u].push_back({v, ll(G[v].size())});
    G[v].push_back({u, ll(G[u].size())-1});
    uf.unite(u, v);
  }
  void dp() {
    vector<bool> used(n, false);
    for (int i = 0; i < n; ++i) {
      if (used[uf.root(i)]) continue;
      dfs1(i, -1);
      used[uf.root(i)] = true;
    }
    used.assign(n, false);
    for (int i = 0; i < n; ++i) {
      if (used[uf.root(i)]) continue;
      dfs2(i, -1);
      used[uf.root(i)] = true;
    }
  }
  size_t size() const {
    return G.size();
  }
};

ll M;

struct Merger {
  using type = ll;
  // その頂点から出ていく値から入ってくる値を計算する
  static vector<type> evaluate(const vector<type>& value) {
    const ll n = value.size();
    vector<type> L(n+1, 1), R(n+1, 1);
    for (int i = 0; i < n; ++i) {
      L[i+1] = (L[i] * value[i]) % M;
    }
    for (int i = n-1; i >= 0; --i) {
      R[i] = (R[i+1] * value[i]) % M;
    }
    vector<type> res(n);
    for (int i = 0; i < n; ++i) {
      res[i] = (L[i] * R[i+1] + 1) % M;
    }
    return res;
  }
  // (辺数-1)個の出ていく値から1個の入ってくる値を計算する
  static type merge(const vector<type>& value) {
    ll res = 1;
    for (auto&& x : value) {
      res = (res * x) % M;
    }
    res = (res + 1) % M;
    return res;
  }
};

int main() {
  ll n; cin >> n >> M;
  EdgeDpOnForest<Merger> dp(n);
  for (int i = 0; i < n-1; ++i) {
    ll a, b; cin >> a >> b; --a, --b;
    dp.add(a, b);
  }
  dp.dp();
  for (int i = 0; i < n; ++i) {
    ll ans = 1;
    for (auto&& e : dp.G[i]) {
      ans = (ans * e.value) % M;
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 20480
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;

const ll MOD = 998244353;

int main()
{
    int n;
    string s;
    cin >> n >> s;
    int r[100002], g[100002], b[100002];
    int nr = 0, ng = 0, nb = 0;
    for(int i = 0; i < n * 3; i++){
        if(s[i] == 'R'){
            r[nr] = i;
            nr++;
        }
        if(s[i] == 'G'){
            g[ng] = i;
            ng++;
        }
        if(s[i] == 'B'){
            b[nb] = i;
            nb++;
        }
    }
    int c[300002];
    for(int i = 0; i < n; i++){
        if(r[i] < g[i] && r[i] < b[i]){
            if(g[i] < b[i]) {c[r[i]] = 0; c[g[i]] = 1; c[b[i]] = 2;}
            else {c[r[i]] = 0; c[g[i]] = 2; c[b[i]] = 1;}
        }
        if(g[i] < r[i] && g[i] < b[i]){
            if(r[i] < b[i]) {c[r[i]] = 1; c[g[i]] = 0; c[b[i]] = 2;}
            else {c[r[i]] = 2; c[g[i]] = 0; c[b[i]] = 1;}
        }
        if(b[i] < g[i] && b[i] < r[i]){
            if(g[i] < r[i]) {c[r[i]] = 2; c[g[i]] = 1; c[b[i]] = 0;}
            else {c[r[i]] = 1; c[g[i]] = 2; c[b[i]] = 0;}
        }
    }
    ll ans = 1;
    int left = 0, mid = 0, right = 0;
    for(int i = 0; i < n * 3; i++){
        if(c[i] == 0){
            ans = ans * (n - left) % MOD;
            left++;
        }
        if(c[i] == 1){
            ans = ans * (left - mid) % MOD;
            mid++;
        }
        if(c[i] == 2){
            ans = ans * (mid - right) % MOD;
            right++;
        }
    }
    cout << ans << endl;
}

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

using namespace std;

using ll = long long;

struct UnionFind {
    //各要素が属する集合の代表(根)を管理する
    //もし、要素xが根であればdata[x]は負の値を取り、-data[x]はxが属する集合の大きさに等しい
    vector<int> data;

    UnionFind(int sz) : data(sz, -1) {}

    bool unite(int x, int y) {
        x = find(x);
        y = find(y);
        bool is_union = (x != y);
        if (is_union) {
            if (data[x] > data[y]) swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return is_union;
    }

    int find(int x) {
        if (data[x] < 0) { //要素xが根である
            return x;
        } else {
            data[x] = find(data[x]); //data[x]がxの属する集合の根でない場合、根になるよう更新される
            return data[x];
        }
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    int size(int x) {
        return -data[find(x)];
    }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m, K;
    cin >> n >> m >> K;

    UnionFind uf(n);
    vector<int> cnt(n, 0);
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        uf.unite(a, b);
        cnt[a]++;
        cnt[b]++;
    }

    vector< vector<int> > g(n);
    for (int i = 0; i < K; ++i) {
        int c, d;
        cin >> c >> d;
        --c; --d;
        g[c].push_back(d);
        g[d].push_back(c);
    }

    for (int i = 0; i < n; ++i) {
        int ans = uf.size(i) - 1 - cnt[i];
        for (int j : g[i]) {
            if (uf.same(i, j)) --ans;
        }
        cout << ans << " \n"[i + 1 == n];
    }
    return 0;
}

Measured memory_bytes: 6784
#include <stdio.h>

int main(){
	int i, j, N, minj, tmp, count=0;
	int A[100];

	scanf("%d", &N);
	for(i=0; i<N; i++){
		scanf("%d", &A[i]);
	}
	for(i=0; i<N; i++){
		minj=i;
		for(j=i; j<N; j++){
			if(A[j] < A[minj]){
				minj=j;
			}
		}
		if(i != minj){
			tmp=A[i];
			A[i]=A[minj];
			A[minj]=tmp;
			count++;
		}
	}
	for(i=0; i<N-1; i++){
		printf("%d ", A[i]);
	}
	printf("%d\n", A[i]);
	printf("%d\n", count);

	return 0;
}

Measured memory_bytes: 1772
N = int(input())
S = input()
 
cnt = [0]*11
i = 0
T = ''
for s in S:
  cnt[int(s)]+=1
  if min(cnt)<=3:
    T += s
#print(T)
ans = 0
P = []
for a in range(10):
  A = str(a)
  k = 0
  ind1 = -1
  while k < len(T)-2:
    t = T[k]
    if A == t:
      ind1 = k
      break
    k += 1
  if ind1 == -1:
    continue
  for b in range(10):
    B = str(b)
    l = ind1+1
    ind2 = -1
    while l < len(T)-1:
      t = T[l]
      if B == t:
        ind2 = l
        break
      l += 1
    #print(a,b,ind1,ind2)
    if ind2 == -1:
      continue
    for c in range(10):
      C = str(c)
      m = ind2+1
      while m < len(T):
        t = T[m]
        if C == t:
          ans += 1
          break
        m += 1
print(ans)

Measured memory_bytes: 64092
#include <iostream>

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    if (a < b){
        cout << "a < b" << endl;
    }else if (a > b){
        cout << "a > b" << endl;
    }else{
        cout << "a == b" << endl;
    }
    return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);
const int limit = 100010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

//------------------------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    while (cin >> a >> b) {
        string s = to_string(a + b);
        cout << s.length() << endl;
    }
    return 0;
}




Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                   \
  ifstream in("abc159/abc159_c.txt"); \
  cin.rdbuf(in.rdbuf());
#else
#define INPUT_FILE
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
const int INF = 100100100;
const ll LINF = 1e18+100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int L;
  cin >> L;

  long double l = (long double)L / 3;
  long double ans = pow(l, 3);
  printf("%6Lf", ans);
}

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

using namespace std;

#define llong long long int
#define ldouble long double
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) x.begin(), x.end()
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)

const static int MOD = 1000000000 + 7;
const static llong INF = 1LL << 60;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

vector<bool> visited;
vector<vector<int> > g;
vector<int> distance_from_zero, distance_from_N;

void dfs1(int s, int d) {
    if (visited[s] == true) return;

    visited[s] = true;
    distance_from_zero[s] = d;
    rep(i, g[s].size()) {
        dfs1(g[s][i], d + 1);
    }

    return;
}

void dfs2(int s, int d) {
    if (visited[s] == true) return;

    visited[s] = true;
    distance_from_N[s] = d;
    rep(i, g[s].size()) {
        dfs2(g[s][i], d + 1);
    }

    return;
}

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

    int n;
    cin >> n;
    g.resize(n);
    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        g[a - 1].push_back(b - 1);
        g[b - 1].push_back(a - 1);
    }

    visited.resize(n, false);
    distance_from_zero.resize(n, 0);
    dfs1(0, 0);

    visited.clear();
    visited.resize(n, false);
    distance_from_N.resize(n, 0);
    dfs2(n - 1, 0);

    int f_cnt = 0, s_cnt = 0; 
    rep(i, n) {
        if (distance_from_zero[i] <= distance_from_N[i]) ++f_cnt;
        else ++s_cnt;
    }

    if (f_cnt > s_cnt) cout << "Fennec" << endl;
    else cout << "Snuke" << endl;

    return 0;
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+7;
ll a[maxn],sum[maxn];
int main()
{
	int n;scanf("%d",&n);ll tot=0;
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]),sum[i]=sum[i-1]+a[i],tot+=a[i];
	if(tot%2==0)
	{
		int pos=lower_bound(sum+1,sum+n+1,tot/2)-sum;
		if(sum[pos]==tot/2)
		{
			cout<<0<<endl;
			return 0;
		}
		else
		{
			cout<<min(2*sum[pos]-tot,tot-2*sum[pos-1])<<endl;
			return 0;
		}
	}
	else
	{
		int pos=lower_bound(sum+1,sum+n+1,tot/2)-sum;
		cout<<min(2*sum[pos]-tot,tot-2*sum[pos-1])<<endl;
	}
	
}

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

using namespace std;

int main() {
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (i % 2 == 0) {
			if (s[i] != 'R' && s[i] != 'U' && s[i] != 'D') {
				cout << "No" << endl;
				return 0;
			}
		}
		else {
			if (s[i] != 'L' && s[i] != 'U' && s[i] != 'D') {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Deque;
import java.util.LinkedList;

class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
Deque<Integer> d=new LinkedList<Integer>();
while(sc.hasNextInt()){
int n=sc.nextInt();
if(n==0){
System.out.println(d.pollFirst());
}
else{
d.offerFirst(n);
}
}
}
}

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

bool match(int cx, int cy, int ch, int x, int y, int h) {
    return (h == max(ch - abs(x - cx) - abs(y - cy), 0));
}

int main() {
    int n;
    cin >> n;
    int a[n][3];
    int maxh = -1;
    rep(i,n) {
        cin >> a[i][0] >> a[i][1] >> a[i][2]; 
        maxh = max(a[i][2], maxh);
    }
    int ans_x, ans_y, ans_h;
    rep(cx,101) {
        rep(cy,101) {
            for (int ch = maxh; ch <= maxh + 100; ch++) {
                bool ok = true;
                rep(i,n) {
                    int x = a[i][0];
                    int y = a[i][1];
                    int h = a[i][2];
                    ok = ok && match(cx, cy, ch, x, y, h);
                }
                if (ok) {
                    ans_x = cx;
                    ans_y = cy;
                    ans_h = ch;
                }
            }
        }
    }
    printf("%d %d %d\n", ans_x, ans_y, ans_h);
}

Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for (int i = 0; i <(int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
int main(){
string s;cin>>s;
bool ok=false;
rep(i,2){
    if(s[i]!=s[i+1])ok=true;
}
if(s[0]!=s[2])ok=true;
if(ok)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}

Measured memory_bytes: 256
s = list(input())

del s[-1]

for i in range(len(s)):
  mid = len(s) // 2
  front = ''.join(s[0:mid])
  rear = ''.join(s[mid:len(s)])
#  print("s:",s)
#  print("mid:",front, rear)
  if len(s) % 2 == 0 and front == rear:
    print(len(s))
    break
  else:
    del s[-1]

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll x;;
  cin>>x;
  for(ll i=-500;i<=500;i++){
    for(ll j=-500;j<=500;j++){
      if(i*i*i*i*i-j*j*j*j*j==x){
        cout<<i<<" "<<j<<endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 3648
a,b,c,d=list(map(int,input().split()))
if c%b==0:
  e=c//b
else:
  e=(c//b)+1
if a%d==0:
  f=a//d
else:
  f=(a//d)+1
if f<e:
  print("No")
else:
  print("Yes")

Measured memory_bytes: 9180
n = int(input())
pos = []
for _ in range(n):
  x,y = map(int,input().split())
  pos.append((x,y))

import math
def distance(p1,p2):
  x1,y1 = p1
  x2,y2 = p2
  return math.sqrt((x1-x2)**2 + (y1-y2)**2)
  
ans = 0
for i in range(n):
  for j in range(n):
    ans += distance(pos[i],pos[j])
print(ans/n)



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

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) ll(x.size()) //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define Umap unordered_map
#define Uset unordered_set

int main(){
    ll n, q, a, b, p, x;
    cin >> n >> q;
    vector<vector<ll>> g(n+1);
    vector<ll> score(n+1), dist(n+1, -1);
    REP(i, n-1){
        cin >> a >> b;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }
    REP(i, q){
        cin >> p >> x;
        score[p] += x;
    }
    queue<int> que;
    int start = 1;
    que.push(start);
    dist[start] = score[1];
    while(que.empty() != true){
        int v = que.front();
        que.pop();
        for(int y : g[v]){
            if(dist[y] == -1){
                dist[y] = dist[v] + score[y];
                que.push(y);
            }
        }
    }
    REP(i, n) cout << dist[i+1] << " ";
    return 0;
}

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

int main(int argc, char const *argv[])
{
	long long n,k;
	cin>>n>>k;
	long long ans=0LL;
	for (long long i = k+1; i <= n; ++i)
	{
		ans+=((n+1LL)/i)*(i-k);
		ans+=max(0LL,((n+1LL)%i)-k);
	}
	if (k==0)
	{
		ans-=n;
	}
	cout<<ans<<endl;
	return 0;
}


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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }
template <class T1, class T2, class Pred = std::less<T2> >
struct sort_pair_second {
    bool operator()(const std::pair<T1,T2>&left, const std::pair<T1,T2>&right) {
        Pred p;
        return p(left.second, right.second);
    }
};

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

    int N; cin >> N;
    int mi = inf;
    REP(i, 1, N) {
      int x = 0, y = 0;
      int num = i;
      while (num) {
        x += num % 10;
        num /= 10;
      }
      num = N - i;
       while (num) {
        y += num % 10;
        num /= 10;
      }
      mi = min(mi, x + y);
    }
    cout << mi << endl;
    return 0;
}

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

int top,c[1000];

void push(int x)
{
  c[++top]=x;
}

int pop()
{
  top--;
  return c[top+1];
}


int main(void)
{
  char s[100];
  int a;
  int b;
  top =0;


  while(scanf("%s",s)!=EOF)
  {
    if(s[0] == '+')
    {
      a=pop();
      b=pop();
      push(a+b);
    }
    else if(s[0] == '-')
    {
      a=pop();
      b=pop();
      push(b-a);
    }
    else if(s[0] == '*')
    {
      a=pop();
      b=pop();
      push(a*b);
    }
    else
    {
      push(atoi(s));

    }
  }
  printf("%d\n",pop());
  return 0;
}



Measured memory_bytes: 2032
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int cnt;
  string a,b;
  cin>>a;
  cin.ignore(numeric_limits<streamsize>::max(),'\n');
  cin>>b;
  for(int i=0;i<3;i++)
  {
    if(a[i]==b[i])
      cnt++;
  }
  cout<<cnt;
  
  return 0;}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <stack>
#include <vector>
#include <random>
#include <unordered_set>
#include <set>
#include <string>
using namespace std;
typedef long long ll;
//#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}


int main(){
  string s;
  cin >> s;
  ll Q,cnt=0;
  cin >> Q;
  vector<char> ff,bb;
  FOR(i,0,Q){
    ll t;
    cin >> t;
    if(t==1){
      //REV(s);
      cnt++;
    }else{
      char c;
      ll f;
      cin >> f >> c;
      if((f==1&&(cnt%2==0))||(f==2&&(cnt%2==1))){
        ff.push_back(c);
      }else{
        bb.push_back(c);
      }
    }
  }
  if(cnt%2==0){
    REV(ff);
    for(auto c:ff){
      cout << c;
    }
    cout<<s;
    for(auto c:bb){
      cout<<c;
    }
    cout<<"\n";
  }else{
    REV(s);
    REV(bb);
    for(auto c:bb){
      cout << c;
    }
    cout<<s;
    for(auto c:ff){
      cout<<c;
    }
    cout<<"\n";
  }
}


Measured memory_bytes: 960
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
#include <vector>
#include <bitset>
#include <queue>
#include <map>
#include <utility>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define MOD 10000000000　+　7    //10億　= 10^9になってる
#define juu 100000               //10万 10e5
#define hyaku 1000000            //100万　10e6
#define mINF -922337200085470000 //llのmax-1桁の小さい方
#define pINF 922337203600070000  //llのmax-1桁のデカい方
#define uINF 1844674407300000000 //ullのmax-1桁してる
#define pi 3.1415926535897932384
ll factor[300];
ll memory[300];
/*素朴法で計算
factorは必ずmemset(factor,0,sizeof(factor));
グローバルであるmemoryに個数を書き込む
memory配列の走査にはfactorの要素を使う*/
void primefac(ll num)
{
    int i = 0, kosuu = 0;
    while (*(factor + i) != 0)
    {
        while (num % *(factor + i) == 0)
        {
            num /= *(factor + i);
            memory[*(factor + i)] += 1;
        }
        if (num == 1)
            break;
        i++;
    }
}
/*グローバルにあるfactorに素数書き込む.個数を返すので配列は-1しろforは<*/
int elast(ll number)
{
    ll tmp = 0;
    int flag = 0;
    *factor = 2;
    for (int i = 3; i <= number; i++)
    {
        flag = 0;
        for (int j = 0; j <= tmp; j++)
        {
            if (i % (*(factor + j)) == 0)
            {
                flag = 1;
                break;
            }
        }
        if (flag)
            continue;
        tmp += 1;
        *(factor + tmp) = i;
    }
    return tmp + 2;
}
/*整数をqsortする為だけのもの*/
long long compare(const long long *a, const long long *b)
{
    if (*a < *b)
        return -1;
    else if (*a > *b)
        return 1;
    return 0;
}
/*intで収まる範囲であってくれ*/
ll nCr(int n, int r)
{
    ll val = 1;
    int i;
    if (r == 0)
        return 1;
    for (i = 0; i < n - r; i++)
    {
        val *= (n - i);
        val /= (i + 1);
    }
    return val;
}
/*intで収まる範囲であってくれ*/
ll nPr(int n, int r)
{
    ll val = 1;
    int i;
    for (i = 0; i < r; i++)
    {
        val *= (n - i);
    }
    return val;
}

void chmin(ll &a, ll b)
{
    if (a > b)
        a = b;
}
void chmax(ll &a, ll b)
{
    if (a < b)
        a = b;
}

/*
qsort(array,length,sizeof(int),(int(*)(const int*, const int*))compare);
使う時これをコピペ
*/


int main()
{
    int K,X;
    cin >> K >> X;
    if((500*K >= X)){
    cout << "Yes";
    }
    else cout << "No";
    return 0;
}


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

int main() {
	string s;cin>>s;
	string s2="CODEFESTIVAL2016";
	int ans=0;
	for(int i=0;i<16;i++){
		if(s2[i]!=s[i])ans++;
	}
	cout<<ans<<endl;
	return 0;
}


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

int main()
{
	int n, m, x;
	cin >> n >> m >> x;
	vector<vector<int>> a(n, vector<int>(m + 1));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m + 1; j++) cin >> a[i][j];
	}

	int ans = INT_MAX;
	for (int bit = 0; bit < (1 << n); bit++) {
		vector<int> algorithm(m);
		int money = 0;
		for (int i = 0; i < n; i++) {
			if (bit & (1 << i)) {
				money += a[i][0];
				for (int j = 1; j <= m; j++) algorithm[j - 1] += a[i][j];
			}
		}
		int flag = true;
		for (const auto& item : algorithm) {
			if (item < x) {
				flag = false;
				break;
			}
		}
		if (flag) ans = min(ans, money);
	}

	if (ans == INT_MAX) cout << -1 << endl;
	else cout << ans << endl;
}


Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  string S_, T;
  cin >> S_ >> T;
  int S_size = (int)S_.size();
  int Tsize = (int)T.size();
  if(S_size < Tsize) {cout << "UNRESTORABLE" << endl; return 0;}
  vector<string> Ss;
  for(int i=0;i<S_size-Tsize+1;i++){
    string S = S_;
    S.replace(i,Tsize,T);
    bool ok = true;
    for(int j=0;j<S_size;j++){
      if(S_[j]!='?'){
        if(S[j] != S_[j]){
          ok = false;
        }
      }
      if(S[j]=='?'){
        S[j] = 'a';
      }
    }
    if(ok){
      Ss.pb(S);
    }
  }
  if(Ss.empty()){cout << "UNRESTORABLE" << endl; return 0;}
  sort(all(Ss));
  cout << Ss[0] << endl;
  return 0;
}


Measured memory_bytes: 256
// @flow

const main = (input /*: string */) => {
  const r = reader(input)
  const n = r.s()

  console.log(['SUN', 'SAT', 'FRI', 'THU', 'WED', 'TUE', 'MON'].indexOf(n) || 7)
}

const reader = (str /*: string*/) => {
  const lines = str.trim().split('\n')
  const s = () => lines.shift() || ''
  const n = () => Number(s())

  const ss = () => s().split(' ')
  const ns = () => ss().map(v => Number(v))

  return { lines, s, n, ss, ns }
}

const getInput = () => require('fs').readFileSync('/dev/stdin', 'utf8')

main(getInput())


Measured memory_bytes: 9420
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var r1 = int.Parse(line[0]);
        var r2 = int.Parse(line[1]);
        var ans = (double)(r1 * r2) / (r1 + r2);
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 13140
import java.util.*;
import java.io.*;
class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int a = sc.nextInt();
        int b = sc.nextInt();
        p(Math.max(0,a-2*b));
    }
    public static String stringCopy(String str) {
        StringBuilder builder = new StringBuilder();
        builder.append(str.toCharArray());
        return builder.toString();
    }
    public static <T> void p(T element) {
	System.out.println(element);
    }
    public static <T> void pp(T element) {
        System.out.print(element);
        }
    public static int min(int a, int b, int c) {
	int min = Math.min(a,b);
	min = Math.min(min,c);
	return min;
    }
    public static int max(int a, int b,int c) {
	int max= Math.max(a,b);
	max = Math.max(max,c);
        return max;
    }
}
class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
 
    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }
 
    private boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
 
    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }
 
    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
 
    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
 
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }
 
    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

Measured memory_bytes: 23124
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   int[] ci= new int[N];
   for(int i = 0;i<N;i++) ci[i] = sc.nextInt();
   Arrays.sort(ci);
   int sum = 0;
   for(int i = 0;i<N;i++) sum += ci[i];
   
   if(sum%10==0)
   {
     for(int i = 0;i<N;i++)
     {
       if(ci[i]%10!=0) 
       {
         sum -=ci[i];
         break;
       }
     }
   }
   if(sum%10==0) System.out.println(0);
   else System.out.println(sum);
 }
}

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

typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define MP make_pair
#define MT make_tuple
#define F first
#define S second
#define PB push_back
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((ll)(x).size())
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define pvd(v) cout << setprecision(16) << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, start_index, num)  (a).begin()+(start_index),(a).begin()+(num)

int main() {
	int h, w, n;
	cin >> h >> w >> n;
	int tmp = max(h, w);
	n += tmp - 1;
	int res = n / tmp;
	pv(res)
	return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>

using namespace std;

/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

ll n2;

struct BIT {
    ll n;
    vll a;
    BIT(ll n = n2) : n(n), a(n + 1, 0) {}
    void add(ll i, ll w){
        for(ll x = i; x <= n; x += x & -x) a[x] += w;
    }
    ll sum(ll i) { // sum of [1, i]
        ll ret = 0;
        for(int x = i; x > 0; x -= x & -x) ret += a[x];
        return ret;
    }
    ll sum(ll l, ll r) { // sum of [l, r]
        return sum(r) - sum(l - 1);
    }
};

void solve() {
    string s;
    ll k;
    cin >> s >> k;
    n2 = s.size();
    BIT b[26];
    queue<ll> q[26];
    for(ll i = 0; i < n2; i++) {
        ll j = s[i] - 'a';
        b[j].add(i + 1, 1);
        q[j].push(i + 1);
    }
    string ans;
    for(ll i = 0; i < n2; i++) {
        for(ll j = 0; j < 26; j++) {
            if(q[j].empty()) continue;
            ll f = q[j].front();
            ll cnt = 0;
            for(ll l = 0; l < 26; l++) {
                cnt += b[l].sum(f - 1);
            }
            if(cnt <= k) {
                ans += 'a' + j;
                q[j].pop();
                b[j].add(f, -1);
                k -= cnt;
                break;
            }
        }
    }
    cout << ans << endl;
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


Measured memory_bytes: 45840
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int n, q;
        int com, x, y;
        RSQ dat;

        n = sc.nextInt();
        q = sc.nextInt();

        dat = new RSQ(n);

        for (int i = 0; i < q; i++) {
            com = sc.nextInt();
            x = sc.nextInt();
            y = sc.nextInt();

            x--;
            if (com == 0) {
                dat.update(x, dat.query(x, x + 1) + y);
            }
            else {
                System.out.println(dat.query(x, y));
            }
        }
    }
}

class RSQ extends SegmentTree<Integer> {
    public RSQ(int size) {
        super(size, 0);
    }

    @Override
    protected Integer operator(Integer x, Integer y) {
        return x + y;
    }
}

/**
 * モノイドを乗せられるセグメントツリーの抽象クラス<br>
 * operator メソッドをオーバライドすることで二項演算を定義する<br>
 * データの1点更新と区間に対する質問クエリをO(log(N))で行う
 */
abstract class SegmentTree<T> {

    /** 単位元 */
    protected T e;

    protected int n;
    protected ArrayList<T> tree;

    
    abstract protected T operator(T x, T y);

    /**
     * 要素eで埋められた要素数nmemb個のセグ木を生成
     * @param nmemb 要素数
     * @param e 初期要素(単位元であること)
     */
    public SegmentTree(int nmemb, T e) {
        this.e = e;
        
        n = 1;
        while (n < nmemb) {
            n *= 2;
        }

        tree = new ArrayList<T>(2 * n - 1);
        for (int i = 0; i < 2 * n - 1; i++) {
            tree.add(e);
        }
    }

    /**
     * データを更新する.<br>
     * O(log(N))
     * @param k データの位置
     * @param dat 更新データ
     */
    public void update(int k, T dat) {
        k += n - 1;

        tree.set(k, dat);

        while(k > 0) {
            k = (k - 1) / 2;
            tree.set(k, operator(tree.get(k * 2 + 1), tree.get(k * 2 + 2)));
        }
    }
    
    /**
     * [l, r)区間の二項演算の結果を返す.<br>
     * O(log(N))
     * @param l 区間の左
     * @param r 区間の右
     * @return 演算結果
     */
    public T query(int l, int r) {
        l += n - 1;
        r += n - 1;

        T d = e;
        while (l < r) {
            if (l % 2 == 0) {
                d = operator(d, tree.get(l));
                l++;
            }
            if (r % 2 == 0) {
                r--;
                d = operator(d, tree.get(r));
            }

            l = (l - 1) / 2;
            r = (r - 1) / 2;
        }

        return d;
    }

    /**
     * デバッグ情報の出力
     */
    public void debugPrint() {
        int cnt = 1;
        int i = 0;

        System.err.printf("n:%d tree.size():%d\n", n, tree.size());

        while (i < 2 * n - 1) {
            for (int j = 0; j < cnt; i++, j++) {
                System.err.printf(" [%d]: ", i);
                System.err.print(tree.get(i));
            }
            System.err.println("");
            
            cnt *= 2;
        }
    }
}



Measured memory_bytes: 105984
s = input()
t = input()
s_l = len(s)
t_l = len(t)
s_l -= (t_l-1)
if(t in s):
    print(0)
    exit()

ma = 0
for si in range(s_l):
    cnt = 0
    for ti in range(t_l):
        if(s[si+ti]==t[ti]):
            cnt += 1
    ma = max(ma,cnt)

print(t_l - ma)


Measured memory_bytes: 8984
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#define ll long long
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
ll read()
{
	ll tmp=0; char f=1,c=getchar();
	while(c<'0'||'9'<c){if(c=='-')f=-1; c=getchar();}
	while('0'<=c&&c<='9'){tmp=tmp*10+c-'0'; c=getchar();}
	return tmp*f;
}
using namespace std;
char s[100];
int main()
{
	scanf("%s",s);
	s[3]='8'; 
	printf("%s\n",s);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    set<int>B;
    for (int i = 0;i<n;i++){
    	int x;
        cin>>x;
        B.insert(x);
    }
    if (B.size()!=n)cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
    return 0;
}

Measured memory_bytes: 9600
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
struct data{
  string str;
  int era,western;
  bool operator<(const data& right)const{
    return western<right.western;
  }
};
int main(){
  int n,q,qyear,cal,flag,i,j;
  while(1){
    cin >> n >> q;
    if(n==0&&q==0) break;
    vector<data> V(n);
    for(i=0;i<n;i++) cin >> V[i].str >> V[i].era >> V[i].western;
    sort(V.begin(),V.end());
    for(i=0;i<q;i++){
      cin >> qyear;
      flag=0;
      for(j=0;j<n;j++){
    if(j==0){
      if(qyear<=V[j].western){
        cal=V[j].era-V[j].western+qyear;
        if(cal>0){
          cout << V[j].str << ' ' << cal << endl;
        }else cout << "Unknown" << endl;
        flag=1;
        break;
      }
    }else{
      if(V[j-1].western<qyear&&qyear<=V[j].western){
        cal=V[j].era-V[j].western+qyear;
        if(cal>0){
          cout << V[j].str << ' ' << cal << endl;
        }else cout << "Unknown" << endl;
        flag=1;
        break;
      }
    }
      }
      if(flag==0){
    cout << "Unknown" << endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1284
#include <iostream>
#include<vector>
#include<cmath>
#include<iomanip>
#define ll long long
using namespace std;
#define rep2(i,a,n) for(int i=a;i<=n;i++)
int main(void){
    // Your code here!
int n;
cin>>n;

double mid= n/2;
if(n%2==0){
cout<<fixed<<setprecision(6)<<mid/n;    
}else{
    cout<<fixed<<setprecision(6)<<(mid+1)/n;
}
}


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

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    vector<unsigned long> memo(N);
    memo[0] = 1;
    for(unsigned long i{1}; i < N; ++i)memo[i] = 1 + memo[i % __builtin_popcountl(i)];
    string S;
    cin >> S;
    unsigned long popcnt{static_cast<unsigned long>(count(begin(S), end(S), '1'))};
    if(popcnt == 0){
        for(unsigned long i{0}; i < N; ++i)puts("1");
        return 0;
    }if(popcnt == 1){
        if(S.back() == '1'){
            for(unsigned long i{1}; i < N; ++i)puts("2");
            puts("0");
        }else{
            for(unsigned long i{0}; i + 1 < N; ++i)puts(S[i] == '1' ? "0" : "1");
            puts("2");
        }
        return 0;
    }
    unsigned long ps{popcnt - 1}, pl{popcnt + 1};
    reverse(begin(S), end(S));
    vector<unsigned long> diff;
    unsigned long xs{0}, xl{0};
    for(unsigned long i{0}, j{1}, k{1}; i < N; ++i){
        (xs += j * (S[i] & 1)) %= ps;
        (xl += k * (S[i] & 1)) %= pl;
        diff.push_back(S[i] == '1' ? ps - j : k);
        (j <<= 1) %= ps;
        (k <<= 1) %= pl;
    }
    reverse(begin(S), end(S));
    reverse(begin(diff), end(diff));
    for(unsigned long i{0}; i < N; ++i)cout << (S[i] == '1' && ps == 0 ? 0 : memo[S[i] == '1' ? (xs + diff[i]) % ps : (xl + diff[i]) % pl]) << endl;
    return 0;
}

Measured memory_bytes: 7028
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    ll x,k,d; cin>>x>>k>>d;
    x=abs(x);
    ll p=x/d,r=x%d;
    if(k<=p){cout<<x-k*d;}
    else{
       k=k-p;
       if(k%2==0){cout<<r;}
       else{cout<<min(r+d,abs(r-d));}
    }
 }


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define pii pair<int,int>
#define ll long long
#define cl(x,y) memset(x,y,sizeof(x))
#define ct cerr<<"Time elapsed:"<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
#define mp make_pair
#define pb push_back
#define mid ((l+r)>>1)
#define lson x<<1,l,mid
#define rson x<<1|1,mid+1,r
const int N=1e6+10;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int a,b,i,f=1;
	cin>>a>>b;
	for(i=1;i<=1000;i++)
		if(i*8/100==a && i*10/100==b)
		{
			cout<<i<<endl;
			f=0;
			break;
		}
	if(f)
		cout<<-1<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
main(){
		string s;
		cin >> s;
		int n = s.length();
		int sum = 0;
		for (int i = 0; i < n; i++)
		{
			sum += (s[i] - '0');
		}
		if (sum % 9 == 0)
		{
			cout << "Yes" << "\n";
		}
		else
		{
			cout << "No" << "\n";
		}
	
  return 0;
}

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

int main () {
  int n; 
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  int count;
  bool flag = false;
  for (;;) {
    for (int i = 0; i < n; i++) {
      if (a[i] % 2 == 1) flag = true;
      a[i] /= 2;
    }
    if (flag) break;
    count += 1;
  }
  cout << count << endl; 
  return 0;
}

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

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

	int n; cin >> n;
	int a[n+1];
	for(int i =1; i<n+1;i++) a[i]=0;
	int boss;

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

	
	

}


Measured memory_bytes: 4440
from collections import Counter
n, k = map(int, input().split())
a = list(map(int, input().split()))
c = Counter(a)
if len(c.keys()) <= k:
    print(0)
    exit()
else:
    ans = 0
    lis = list(c.values())
    lis.sort()
    l = len(lis) - k
    for i in range(l):
        ans += lis[i]
print(ans)


Measured memory_bytes: 32564
// Vicfred
// https://atcoder.jp/contests/abc054/tasks/abc054_c
// dfs
import std.stdio;

int[][] graph;
bool[] visited;
int ans;

void dfs(int current) {
    bool flag = true;
    for(int i = 1; i <= visited.length - 1; i++) {
        if(!visited[i] && i != current)
            flag = false;
    }

    if(flag) {
        ans += 1;
        return;
    }

    visited[current] = true;

    foreach(neighbor; graph[current]) {
        if(!visited[neighbor])
            dfs(neighbor);
    }

    visited[current] = false;
}

void main() {
    int n, m;
    readf("%s %s\n", &n, &m);

    graph = new int[][](n + 1);
    visited = new bool[n + 1];
    ans = 0;

    foreach(_; 0..m) {
        int a, b;
        readf("%s %s\n", &a, &b);
        graph[a] ~= b;
        graph[b] ~= a;
    }

    dfs(1);

    ans.writeln;
}



Measured memory_bytes: 2836
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long int ll;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s;
	cin >> s;
	string y = s.substr(0, 4);
	string m = s.substr(5, 2);
	string d = s.substr(8, 2);

	if (stoi(y) <= 2019 && stoi(m) <= 4 &&  stoi(d) <= 30)
		cout << "Heisei\n";
	else
		cout << "TBD\n";
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int a,b;
    cin >> a >> b;
    if(b>a){
        cout << "a < b" << endl;
    }else if(a>b){
        cout << "a > b" << endl;
    }else{
        cout << "a == b" << endl;
    }
}


Measured memory_bytes: 3068