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

class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    HashSet <String> hs = new HashSet<String>();
    int N = scanner.nextInt();
    int A[] = new int[1000000];
    int n=0;
    String Command,Word;

    for(int i=0;i<N;i++){
      Command = scanner.next();
      if(Command.equals("insert")){
        Word = scanner.next();
        hs.add(Word);
      }else{
        Word = scanner.next();
        if(hs.remove(Word)){
          hs.add(Word);
          A[n] = 1;
          n++;
        }else{
          n++;
        }
      }
    }

    for(int i=0;i<n;i++){
      if(A[i]==0){
        System.out.println("no");
      }else{
        System.out.println("yes");
      }
    }

  }
}



Measured memory_bytes: 278028
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	int n;
	cin>>n;
	if(n<105){
		cout<<0<<endl;
	}else{
		int sum=0,i,j;
		for(i=105;i<=n;i++){
			if(i%2==1){
				int num=0;
				for(j=1;j<=i;j++){
					if(i%j==0){
						num++;
					}
				}
				if(num==8){
					sum++;
				}
			}	
		}
		cout<<sum<<endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define N 100
#define INF 2000000000
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;

int n;
int M[N][N],color[N],d[N],p[N];
   //M??????????????????color????¨??????¶???(0,1,2),d????????????????°???????????¨????
   //p???MST???????°???¨?????¨??????????????????????????????

void Prim() {
	for (int i = 0;i < n;i++) d[i] = INF;
	d[0] = 0;  //?????????????????????????????§???????????§????´???????????????????????????????
	p[0] = -1;  //??????????????????????????????????????????

	int u;
	while (true) {
		int min = INF;
		for (int i = 0;i < n;i++) {
			if(color[i]!=BLACK&&min>d[i]){
				min = d[i];
				u = i;
			}
		}

	if (min == INF) break;

	color[u] = BLACK;

	for (int v = 0;v < n;v++) 
		if(color[v]!=BLACK&&M[u][v]!=-1)
			if (M[u][v] < d[v]) {
				d[v] = M[u][v];
				p[v] = u;
				color[v] = GRAY;
			}

	}

	int sum = 0;
	for (int i = 0;i < n;i++) sum += d[i];
	cout << sum << endl;
		
}

int main() {
	cin >> n;
	for (int i = 0;i < n;i++)
		for (int j = 0;j < n;j++) {
			cin >> M[i][j];
			if (M[i][j] == -1) M[i][j] = INF;
		}

	Prim();

}

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

using ll=int64_t;

int main() {
  int N; cin >>N;
  int ans=0;
  for (int i=1;;i++) {
    if (N<i*i) {
      ans=(i-1)*(i-1);
      break;
    }
  }
  cout <<ans <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

signed main()
{
    int n;
    string s;
    cin >> n >> s;
    vector<int> r, g, b;
    for (int i = 0; i < n; i++)
    {
        if(s[i]=='R'){
            r.push_back(i);
        }
        if(s[i]=='G'){
            g.push_back(i);
        }
        if(s[i]=='B'){
            b.push_back(i);
        }
    }
    int cnt = 0;
    for (int i = 0; i < r.size(); i++)
    {
        for (int j = 0; j < g.size(); j++)
        {
            int x = abs(g[j] - r[i]);
            int y = b.size();
           // cerr << y << endl;
            if (binary_search(ALL(b), r[i] - x))
            {
                y--;
            }
            if(binary_search(ALL(b),r[i]+x)){
                y--;
            }
            if (binary_search(ALL(b), g[j] - x))
            {
                y--;
            }
            if (binary_search(ALL(b), g[j] + x))
            {
                y--;
            }
            if (r[i] - g[j] < 0 && (g[j] - r[i]) % 2 == 0)
            {
                int z = r[i] + ( -r[i] + g[j]) / 2;
                if (binary_search(ALL(b), z))
                {
                    y--;
                }
            }
            if (r[i] - g[j] > 0 && (r[i] - g[j]) % 2 == 0)
            {
                int z = g[j] + (r[i] - g[j]) / 2;
                if (binary_search(ALL(b), z))
                {
                    y--;
                }
            }

            cnt += y;
        }
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>

int main() {
    int n, t = 0;
    scanf("%d", &n);
    if (n % 2 == 1) {
        printf("No\n");
        return 0;
    }

    char s[n];
    scanf("%s", s);
    
    for (int i = 0; s[i] != '\0'; i++) {
        if (s[i] == s[(n / 2) + i]) {
            t++;
        }
    }

    if (t == n / 2) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 1624
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int n,k,h[100001];
	int i,j,x,dp[100001];
	scanf("%d %d",&n,&k);
	for(i=0;i<n;i++) scanf("%d",&h[i]);
	for(i=0;i<=n;i++) dp[i]=1000000000;
	dp[0]=0; x=0;
	for(i=0;i<n-1;i++){
		for(j=1;j<=k;j++){
			x=h[i]-h[i+j];
			if(x<0) x=-x;
			if(i+j<n&&dp[i+j]>x+dp[i]){
			dp[i+j]=x+dp[i];
			}
		}
	}
	printf("%d\n",dp[n-1]);
	return 0;
}

Measured memory_bytes: 4500
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int count = sc.nextInt();
		for(int k = 0; k < count; k++) {
			String x = sc.next();
			String y = sc.next();
			int s = x.length();
			int t = y.length();
			int[][] table = new int[s + 1][t + 1];
			
			
			for(int i = 1; i <= s; i++) {
				for(int j = 1; j <= t; j++) {
					if(x.charAt(i - 1) == y.charAt(j - 1)) {
						table[i][j] = table[i - 1][j - 1] + 1;
					}else {
						table[i][j] = Math.max(table[i - 1][j], table[i][j - 1]);
					}
				}
			}
			System.out.println(table[s][t]);
		}
	}
}


Measured memory_bytes: 64068
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue> 
#include <tuple>
#include <map>
 
using namespace std;

typedef long long ll;

int main() {
	cin.tie(0);

    int A, B, C;

    cin >> A >> B >> C;

    int x = C - (A - B);

    if(x < 0) {
        x = 0;
    }

    cout << x << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

#define FOR(i,a,b) for (int i = a; i < b; ++i)
#define FORR(i,a,b) for (int i = b - 1; i >= a; --i)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,0,n)

int main() {
	ll A;
	double B;
	cin >> A >> B;
	cout << A * (ll)round(B * 100) / 100 << endl;
	return 0;
}

Measured memory_bytes: 3720
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1111111111;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif
template<size_t N> struct solve {

	lint ans[N];

	constexpr solve() {

		for (int i = 1; i <= 9; i++) {
			ans[i] = i;
		}
		int st = 1, idx = 10;
		while (idx <= N) {

			if (ans[st] % 10 != 0) {
				ans[idx++] = ans[st] * 10 + ans[st] % 10 - 1;
			}
			ans[idx++] = ans[st] * 10 + ans[st] % 10;
			if (ans[st] % 10 != 9) {
				ans[idx++] = ans[st] * 10 + ans[st] % 10 + 1;
			}
			st++;

		}

	}

};

solve<100000> S;

int main() {

	int N;
	scanf("%d", &N);
	printf("%lld", S.ans[N]);

	return 0;
}

Measured memory_bytes: 1024
#include <string>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <math.h>
 
using namespace std;
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
 
	int x,y;
    int sum = 0;
	cin >> x >> y;
    vector<int> vec(x);
    for(int i=0; i<x; i++){
      cin >> vec.at(i);
    }
    sort(vec.begin(), vec.end());
    for(int i=0; i<y; i++){
      sum += vec.at(i);
    }
    cout << sum;
  
}

Measured memory_bytes: 3616
#include<iostream>
#include<map>

using namespace std;
const int MOD = 1e9 + 7;

int N;

long long pow(long long x, int n) {
    long long res = 1;
    while (0 < n) {
        if(n % 2 != 0)
            res = res * x % MOD;
        x = x * x % MOD;
        n /= 2;
    }
    return res;
}

int main() {
    cin >> N;
    int num;
    map<int, int> order;
    for (int i = 0; i < N; i++){
        cin >> num;
        order[num]++;
    }

    for(auto index : order) {
        if( (index.first == 0 && index.second != 1) || ( N % 2 == 0 && index.second != 2)) {
            cout << 0 << endl;
            return 0;
        }
    }

    cout << pow(2, N / 2) << endl;
    return 0;
}

Measured memory_bytes: 6540
#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 <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 <cctype> // isupper, islower, isdigit, toupper, tolower, islower
#include <math.h>

#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
//using ll = long long; using ld = long double;
//using P = pair<int, int>;
long long n, m, x, y, z;
const long long template_arry_size = 1000625;
long long a[template_arry_size];
long long b[template_arry_size];
long long c[template_arry_size];
string s, t;
long long ans = 0;

void solve(int tc = 0) {
    cin >> n;
    rep(i,n) cin >> a[i];
    long long worst = 0;
    rep(i,n) {
        if (worst > a[i]) {
            ans += worst - a[i];
        }
        worst = max(worst,a[i]);
    }
    cout << ans << endl;
}

int main(){

    solve();

}


Measured memory_bytes: 5196
#include <iostream>
#include <stack>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

int main() {
	string section;
	int all_area = 0, tmp;
	stack<int> down;
	stack< pair<int, int> > areas;

	cin >> section;

	for(int i = 0;i < section.size();i++) {
		if(section.at(i) == '\\') {
			down.push(i);
		} else if(section.at(i) == '/' && !down.empty()) {
			tmp = down.top(); down.pop();
			all_area += (i - tmp);
			int a = i - tmp;

			while(!areas.empty() && areas.top().first > tmp) {
				a += areas.top().second; areas.pop();
			}

			areas.push(make_pair(tmp, a));
		} 
	}

	vector<int> ans;

	while(!areas.empty()) {
		ans.push_back(areas.top().second); areas.pop();
	}

	reverse(ans.begin(), ans.end());

	cout << all_area << endl;

	cout << ans.size();

	for(int i = 0;i < ans.size();i++) {
		cout << " " << ans.at(i);
	}

	cout << endl;

	return 0;
}

Measured memory_bytes: 3208
#include <iostream>
#include <vector>
#define PB push_back
using namespace std;
int absint(int a){ return a<0?-a:a; }
int solve(vector<int> a,vector<int> b)
{
  if(a.size()!=b.size()) return 1000;
  int answer=0;
  for(int i=0;i<a.size();++i)
    answer+=absint(a[i]-b[i]);
  return answer;
}
vector<int> bit1(vector<int> a)
{
  vector<int> answer;
  for(int i=0;i<a.size();++i)
    if(a[i]==1) answer.PB(i);
  return answer;
}
int main(void)
{
  vector<int> a,b,c;
  int n,m;
  cin >> n >> m;
  for(int i=0;i<n;++i){
    int tmp;
    cin >> tmp;
    a.PB(tmp);
  }
  for(int i=0;i<m;++i){
    int tmp;
    cin >> tmp;
    for(int j=0;j<tmp;++j){
      b.PB(i%2);
      c.PB((i+1)%2);
    }
  }
  int answer=1000;
  int tmp = solve(bit1(a),bit1(b));
  if(answer>tmp) answer=tmp;
  tmp = solve(bit1(a),bit1(c));
  if(answer>tmp) answer=tmp;
  cout << answer << endl;
  return 0;
}

Measured memory_bytes: 1220
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N; cin>>N;
    vint a(N),b(N);
    REP(i,N) cin>>a[i];
    REP(i,N) cin>>b[i];

    for(int i=1;i<N;i++) a[i]+=a[i-1];
    for(int i=1;i<N;i++) b[i]+=b[i-1];

    int ans=a[0]+b[N-1];
    for(int i=1;i<N;i++){
        ans=max(ans,a[i]+b[N-1]-b[i-1]);
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
	vint v(3, 0);
	v[0] = 1;

	char r, k, l;
	while(cin >> r >> k >> l)
		swap(v[r-'A'], v[l-'A']);
	
	rep(i, 3)
		if(v[i])
			cout << char('A' + i) << endl;
}

Measured memory_bytes: 0
answer_counts = {'AC': 0, 'WA': 0, 'TLE': 0, 'RE': 0}
n = int(input())
for i in range(n):
    s = input()
    answer_counts[s] += 1

for k, v in answer_counts.items():
    print("%s x %s" % (k, v))


Measured memory_bytes: 9196
<?php
  $n = trim(fgets(STDIN));
  $t = explode(" ", trim(fgets(STDIN)));
  $m = trim(fgets(STDIN));
  for($i=0; $i<$m; $i++){
      $tt = $t;
      fscanf(STDIN, "%d %d", $p,$x);
      $tt[$p-1] = $x;
      echo array_sum($tt)."\n";
  }

Measured memory_bytes: 4728
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main () {
    double x1, x2, y1, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    cout << fixed << setprecision(8) << sqrt (pow (x2 - x1, 2) + pow (y2 - y1, 2)) << "\n";
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

class UnionFind{
private:
	::std::vector<int_fast32_t> par;
	size_t n;

public:
	UnionFind(){}
	UnionFind(size_t n):n(n){
		par.resize(n, -1);
	}

	uint_fast32_t find(uint_fast32_t x){
		return par[x] < 0 ? x : par[x] = find(par[x]);
	}

	size_t size(uint_fast32_t x){
		return -par[find(x)];
	}

	bool unite(uint_fast32_t x, uint_fast32_t y){
		x = find(x);
		y = find(y);
		if(x == y) return false;
		if(size(x) < size(y)) std::swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

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

int64 N, M;

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

	cin >> N >> M;
	vector<int64> a(M), b(M);
	REP(i, M) cin >> a[i] >> b[i];
	UnionFind uf(N);
	int64 now = N*(N-1)/2;
	vector<int64> res;
	for(int64 i = M-1; i >= 0; i--) {
		a[i]--; b[i]--;
		int64 sa = uf.size(a[i]), sb = uf.size(b[i]);
		res.push_back(now);
		if (uf.unite(a[i], b[i])) {
			now -= sa*sb;
		}
	}
	REP(i, M) {
		cout << res[M-i-1] << endl;
	}
}


Measured memory_bytes: 4596
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <vector>
#include <string.h>
using namespace std;

int main() {
	int A,B,keta=1;
	bool ans=false;
	cin>>A>>B;
	for(int i=B;i>0;i/=10)keta*=10;
	for(int i=0;i<4000;i++)
	{
		if(i*i==A*keta+B){
			ans=true;
			break;
			}
	}
	cout<<((ans)?"Yes":"No");
	}

Measured memory_bytes: 256
'use strict';

function Main(INPUT) {
    const input = INPUT.split("\n")[0].split(" ");
    const A = parseInt(input[0], 10);
    const B = parseInt(input[1], 10);

    console.log(A + B >= 10 ? "error" : A + B);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 21064
#include <iostream>
#include <fstream>
#include <iomanip>
#include <math.h>
#include <limits.h>
#include <algorithm>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <string>
#include <string.h>
#include <sstream>
#include <ctime>

using namespace std;

#define eps 1e-12
#define pi 3.14159265358979323846
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define bgn begin
#define ll long long
#define ld long double
#define ull unsigned long long
#define ii pair<ll,ll>




const int N=2e5+10;
int n,a,k,res,c[N],v[N];



bool cmp(int i,int j)
{
	return c[i]>c[j];
}





void solve()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		c[i]=0;
		v[i]=i;
	}
	for(int i=1;i<=n;i++)
	{
		cin>>a;
		c[a]++;
	}
	sort(v+1,v+n+1,cmp);
	res=0;
	for(int i=1;i<=k;i++)
	{
		res+=c[v[i]];
	}
	res=n-res;
	cout<<res<<"\n";
}

int main()
{
	std::ios::sync_with_stdio(0);
	cin.tie(0);
#ifdef localProject
	freopen("in.txt","r",stdin);
#endif
	solve();
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int r,g,b;
  cin>>r>>g>>b;
  if((g*10+b)%4==0)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;

  return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
#include<cassert>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)

int keta(int a) {
    int c = 0;
    while (a) {
        a /= 10;
        c++;
    }
    return c;
}
bool comp(pair<pii, int> lhs, pair<pii, int> rhs) {
    if (lhs.first.first != rhs.first.first)
        return lhs.first.first < rhs.first.first;
    if (lhs.first.second != rhs.first.second)
        return lhs.first.second < rhs.first.second;
    return lhs.first.first < rhs.first.first;
}
int main() {
    int n, m; cin >> n >> m;
    //n = 10; m = 100;
    vector<pair<pii, int> > v;
    rep(i, m) {
        int p, y; cin >> p >> y;
        //p = (i + 10) / 10; y = i % 10 + 1;
        v.push_back({{p, y}, i});
    }
    sort(v.begin(), v.end(), comp);
    /*
    rep(i, v.size()) {
        cout << v[i].first.first << " " << v[i].first.second << " " << v[i].second << endl;
    }
     */
    vector<string> vv(m);
    int c = 1;
    rep(i, v.size()) {
        rep(j, 6 - keta(v[i].first.first)) {
            vv[v[i].second] += '0';
        }
        vv[v[i].second] += to_string(v[i].first.first);
        if (i == 0) {
            vv[v[i].second] += "000001";
        } else if (v[i].first.first == v[i - 1].first.first) {
            c++;
            rep(j, 6 - keta(c)) {
                vv[v[i].second] += '0';
            }
            vv[v[i].second] += to_string(c);
        } else {
            c = 1;
            vv[v[i].second] += "000001";
        }
    }
    rep(i, vv.size()) {
        cout << vv[i] << endl;
    }
}


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

int main() {
    string S;
    cin >> S;
    vector<int> num(26);
    for (int i=0; i<S.size(); i++) num.at(S.at(i)-'a')++;
    char answer = '\0';
    for (int i=0; i<26; i++) {
        if (num.at(i) == 0) {
            answer = i + 'a';
            break;
        }
    }
    if (answer == '\0') cout << "None" << endl;
    else cout << answer << endl;
}

Measured memory_bytes: 512
#define dbg(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
#define dpri(x) dbg(#x ": %d\n", x)
#define dprs(x) dbg(#x ": %s\n", x)
#include <stdio.h>
#include <string.h>
typedef long long ll;
const int MYINF = 1e9+7;
typedef int bool;
const bool true = 1;
const bool false = 0;
 
#define MAX_N 64
 
typedef struct node_st {
    int left, right;
    int pre, in;
} node_t;
 
int n;
int preorder[MAX_N];
int inorder[MAX_N];
node_t nd[MAX_N];
 
void recons(int id, int base , int n) {
    int pre, in, remain_left, remain_right;
    if (id == 0) return;
 
    pre = nd[id].pre;
    in = nd[id].in;
    remain_left = (in - base);
    remain_right = n - remain_left - 1;
 
    if (remain_left > 0) {
        nd[id].left = preorder[pre+1];
        recons(nd[id].left, base, remain_left);
    }
 
    if (remain_right > 0) {
        nd[id].right = preorder[pre+remain_left+1];
        recons(nd[id].right, in+1, remain_right);
    }
}
 
void postorder(int id) {
    static const char *sp = "";
    if (!id) return;
    if (nd[id].left) postorder(nd[id].left);
    if (nd[id].right) postorder(nd[id].right);
    printf("%s%d", sp, id);
    sp = " ";
}
 
int main(int argc, char **argv)
{
    int i;
 
    memset(nd, 0, sizeof(node_t) * MAX_N);
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d", &preorder[i]);
        nd[preorder[i]].pre = i;
    }
    for (i = 0; i < n; i++) {
        scanf("%d", &inorder[i]);
        nd[inorder[i]].in = i;
    }
 
    recons(preorder[0], 0, n);
    postorder(preorder[0]);
    puts("");
 
    return 0;
}



Measured memory_bytes: 2108
main = do
  s <- getLine

  putStrLn $ if part s "AKIHABARA" && part "KIHBR" s then "YES" else "NO"

  where
    part [] _ = True
    part (x:_) [] = False
    part (x:xs) (y:ys)
      | x == y = part xs ys
      | x /= y = part (x:xs) ys

Measured memory_bytes: 380
n = int(input())
a = list(map(int,input().split()))
count = 0
for i in range(n-1):
    flag = 0
    min_j = i
    for j in range(i,n):
        if a[j] < a[min_j]:
            min_j = j
            flag = 1
    if flag:
        a[i], a[min_j] = a[min_j], a[i]
        count += 1
print(" ".join(map(str,a)))
print(count)

Measured memory_bytes: 7716
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define PDD pair<double, double>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (1 << (x))
using namespace std;

LL modinv(LL a){
    LL b = MOD, u = 1, v = 0;
    while(b){
        LL t = a / b;
        a -= t * b;swap(a, b);
        u -= t * v;swap(u, v);
    }
    u%=MOD;
    if(u < 0) u += MOD;
    return u;

}

LL exp(LL a, LL b){
    LL sum = a;
    LL res = 1;
    while(b){
        if(b&1){
            res = (res * sum)%MOD;
        }
        sum = (sum * sum) % MOD;
        b>>=1;
    }
    return res;
}

int N, M;
int mx[]={1, 1, 1, 0, -1, -1, -1, 0}, my[]={1, 0, -1, -1, -1, 0, 1, 1};

int main(){
    while(cin>>M>>N&&N){
        vector<vector<int> > m(N+2, vector<int>(M+2, 0));
        REPA(i, N+1){
            REPA(j, M+1){
                cin >> m[i][j];
            }
        }
        int ans = 0;
        REPA(i, N+1){
            REPA(j, M+1){
                if(!m[i][j])continue;
                ++ans;
                queue<PII> que;
                que.push(PII(i, j));
                m[i][j]=0;
                while(!que.empty()){
                    PII d = que.front();
                    que.pop();
                    REP(i, 8){
                        int nx = d.first + mx[i];
                        int ny = d.second + my[i];
                        if(!m[nx][ny])continue;
                        m[nx][ny]=0;
                        que.push(PII(nx, ny));
                    }
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}




Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
using P = pair <int, int>;
 
 
int main() {
    string s;
    cin >> s;
    int n = s.size();
    queue<char> que;
    que.push(s[0]);
    rep(i,n-1){
        if(s[i]!=s[i+1]) que.push(s[i+1]);
    }
    cout << que.size()-1 << endl;

}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
using namespace __gnu_pbds;
using namespace std;
/*
int dx[]={-1,1,0,0};
int dy[]={0,0,-1,1};
*/
#define ull unsigned long long int
#define ll long long int
#define MAX 1000000007
//1e9+7
#define pll pair<ll,ll>
#define pii pair<int,int>
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FO ifstream fin("a.in");ofstream fout("a.out");
#define TEST int testcase;cin>>testcase;while(testcase--)
#define all(x) (x).begin(),(x).end()
#define mset0(x) memset((x), 0, sizeof((x)));
#define mset1(x) memset((x), -1, sizeof((x)));
#define endl "\n"
#define plll pair<ll,pll>
typedef tree<ll,null_type,less<ll>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
FO
void solve(){
    int n,k;
    cin>>n>>k;
    int arr[n];
    for(int i=0;i<n;i++) cin>>arr[i];
    sort(arr,arr+n);
    int sum=0;
    for(int i=0;i<k;i++) sum+=arr[i];
    cout<<sum;
    return;
}
int main(){
    //IO FO
    //TEST
    solve();

    return(0);
}


Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;
const long long int INF = 99999999999999999;

struct edge {
	long long int from, to, cost;
};
edge ed[200101];
long long int d[201000];
long long int V, E;

void Bellman_Ford(int s) {
	for (int i = 0; i < V; i++) { d[i] = INF; }
	d[s] = 0;
	while (true) {
		bool update = false;
		for (int i = 0; i < E; i++) {
			edge e = ed[i];
			if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
				d[e.to] = d[e.from] + e.cost;
				update = true;
			}
		}
		if (!update) { break; }
	}
}

int main() {
	complex<long double>cmpmp;
	const long long int mod = 1000000007;
	map<long long int, long long int>mp;
	//cout << fixed << setprecision(10);
	long long int  color[505][505], n, c, value[50][5] = {},res=0,h,w;
	string str;
	cin >> h>>w;
	for (int i = 0; i <= 9; i++) {
		for (int j = 0; j <= 9; j++) {
			ed[10 * i + j].from = j;
			ed[10 * i + j].to = i;
			cin>>ed[10 * i + j].cost;
		}
	}
	V = 10;
	E = 100;
	Bellman_Ford(1);
	for (int i = 0; i <h; i++) {
		for (int j = 0; j <w; j++) {
			cin >> color[i][j];
			if (color[i][j] != -1) {
				res+=d[color[i][j]];
			}
		}
	}
	cout << res  << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define R register
namespace IO{
	char buf[1<<15],*S,*T;
	inline char gc(){
		if (S==T){
			T=(S=buf)+fread(buf,1,1<<15,stdin);
			if (S==T) return EOF;
		}return *S++;
	}
	inline int read(){
		R int x; R bool f; R char c;
		for (f=0; (c=gc())<'0'||c>'9'; f=c=='-');
		for (x=c^'0'; (c=gc())>='0'&&c<='9'; x=(x<<1)+(x<<3)+(c^'0'));
		return f?-x:x;
	}
	const int outlim=1<<20;int cnt=0;
	char outbuf[outlim+5],*SS=outbuf;
	inline void pc(char c){
		*SS++=c;++cnt;if (cnt==outlim)
			fwrite(outbuf,1,outlim,stdout),SS=outbuf,cnt=0;
	}
	inline void write(int x){
		if (x>9) write(x/10);
		pc(x%10^'0');
	}
	void endfile(){
		if (cnt)
			fwrite(outbuf,1,cnt,stdout);
		fclose(stdin);fclose(stdout);
	}
}
#define MN 200005
#define M (1<<18)
int vl[MN],cnt[MN],n,m,T[M<<1];
inline void rw(int k,int x){
	if (k<1) return;
	if (!T[k+=M]) for (; k; k>>=1) ++T[k];
	else{
		if (~x) ++T[k];
		else if (!(--T[k])) for (; k>>=1; ) --T[k];
	}
}
int main(){
	n=IO::read(),m=IO::read();
	for (R int i=1; i<=n; ++i) ++cnt[vl[i]=IO::read()],rw(vl[i]-cnt[vl[i]]+1,1);
	for (R int i=1,x,y; i<=m; ++i){
		x=IO::read(),y=IO::read();
		--cnt[vl[x]];rw(vl[x]-cnt[vl[x]],-1);
		vl[x]=y;rw(y-cnt[y],1);++cnt[y];
		IO::write(n-T[1]);IO::pc('\n');
	}IO::endfile();return 0;
}

Measured memory_bytes: 5760
import java.util.Scanner;

/**
 * B - Common Raccoon vs Monster
 * アライグマはモンスターと戦っています。
 * モンスターの体力は H です。
 * アライグマはN 種類の必殺技を使うことができ、i 番目の必殺技を使うとモンスターの体力をAi 減らすことができます。
 * 必殺技を使う以外の方法でモンスターの体力を減らすことはできません。
 * モンスターの体力を0 以下にすればアライグマの勝ちです。
 * アライグマが同じ必殺技を 2 度以上使うことなくモンスターに勝つことができるなら Yes を、できないなら No を出力してください。
 */
public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner( System.in );
        // モンスターの体力
        int h = sc.nextInt();
        // アライグマが使うことができる必殺技の数
        int n = sc.nextInt();
        // アライグマが必殺技で減らせるモンスターの体力を合算
        int sum = 0;
        for( int i = 0; i < n; i++ ) {
            sum += sc.nextInt();
        }

        System.out.println( sum >= h ? "Yes" : "No" );

        sc.close();
    }
}

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

S = input()
N = len(S) + 1

l = [0]*N
r = [0]*N

tmp_l = 0
for i in range(N-1):
	if S[i] == "<":
		tmp_l += 1
		l[i+1] = tmp_l
	else:
		tmp_l = 0

tmp_r = 0
for i in range(N-2, -1,  -1):
	if S[i] == ">":
		tmp_r += 1
		r[i] =tmp_r
	else:
		tmp_r = 0

t = [max(r[i], l[i]) for i in range(N)]
ans = 0
for i in range(N):
	ans += max(l[i], r[i])

#print(l)
#print(r)
#print(t)

print(ans)


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

int main() {
  int N,K;
  cin >> N >> K;
  int a = 1;

  for(int i = 0 ; i < N ; ++i){
    if(a * 2 < a + K) a *= 2;
    else a += K;
  }

  cout << a << endl;
}


Measured memory_bytes: 256
#include <set>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <iostream>
#include <map>

#define mp make_pair

using namespace std;

const map<char, char> m = {
  mp('T', 'a'),
  mp('L', 'i'),
  mp('U', 'u'),
  mp('R', 'e'),
  mp('D', 'o')
};

const string t[] = {
  "w", "", "k", "s", "t", "n", "h", "m", "y", "r"
};


int main(){
  string s; cin >> s;
  const int n = s.size();
  REP(i,n/2){
    if(s.substr(2 * i, 2) == "0U") cout << "nn";
    else cout << t[s[2 * i] - '0'] <<  m.at(s[2 * i + 1]);
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 1200
#include <stdio.h>

int main(void){
        char s[1200];
        int i=0;
        scanf("%[^\n]",s);
        while(s[i]){
                if(s[i]>='a' && s[i]<='z')
                        s[i]+=('A'-'a');
                else if(s[i]>='A' && s[i]<='Z')
                        s[i]+=('a'-'A');
                i++;
        }
        printf("%s\n",s);
        return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)
#define repv(x, arr) for (auto &x : arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a, b) make_pair(a, b)
#define op(i) cout << (i) << endl;
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 2147483600;
const ll infl = 1e17;


int main()
{
    int a, b;
    cin >> a >> b;
    vector<vector<char>> ans(100, vector<char>(100));
    cout << "100 100" << endl;
    if (a==1){
        rep(i, 100) rep(j, 100) ans[i][j] = '.';
        rep(i,49){rep(j,49){
                if (b==0)
                    break;
                ans[2*i+1][2*j+1] = '#';
                b--;
        }}
        rep(i,100){
            rep(j, 100) cout << ans[i][j];
            cout << endl;
        }
        return 0;
    }
    if (b==1){
        rep(i, 100) rep(j, 100) ans[i][j] = '#';
        rep(i, 49)
        {
            rep(j, 49)
            {
                if (a == 0)
                    break;
                ans[2*i+1][2*j+1] = '.';
                a--;
            }
        }
        rep(i, 100)
        {
            rep(j, 100) cout << ans[i][j];
            cout << endl;
        }
        return 0;
    }
    rep(i, 50) rep(j, 100) ans[i][j] = '#';
    repf(i, 50,100) rep(j, 100) ans[i][j] = '.';
    a--;
    b--;
    rep(i,24){rep(j,50){
            if (a==0)
                break;
            ans[2*i+1][2*j+1] = '.';
            a--;
    }
    }
    repf(i, 25,50)
    {
        rep(j, 50)
        {
            if (b == 0)
                break;
            ans[2 * i + 1][2 * j + 1] = '#';
            b--;
        }
    }
    rep(i,100)
    {
        rep(j, 100) cout << ans[i][j];
        cout << endl;
    }
}

Measured memory_bytes: 256
/**
 * @author torith
 * @date 2018-10-01
 */

#include <bits/stdc++.h>

typedef long long ll;

using namespace std;

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<int> A;
    for (int i = 0; i < N; ++i) {
        int t; cin >> t;
        A.push_back(t - i - 1);
    }

    sort(A.begin(), A.end());
    if(A.size() == 0) {
        cout << "0" << "\n";
        return 0;
    }

    ll ans = 0;
    if(A.size() % 2 == 0){
        for (int i = 0; i < N; ++i) {
            ans += abs((ll) (A[i] - A[A.size()/2]));
        }

        ll tmp = 0;
        for (int i = 0; i < N; ++i) {
            tmp += abs((ll) (A[i] - A[A.size()/2-1]));
        }
        ans = min(tmp, ans);

    }else{
        for (int i = 0; i < N; ++i) {
            ans += abs((ll) (A[i] - A[A.size()/2]));
        }
    }

    cout << ans << "\n";
}


Measured memory_bytes: 1400
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;

public class Main
{
  public static void main(String[] args) throws FileNotFoundException
  {
    Scanner scanner = new Scanner(System.in);
    int n, m;
    n = scanner.nextInt();
    m = scanner.nextInt();
    if(n != m){
      System.out.println("No");
    }else{
      System.out.println("Yes");
    }
  }
}


Measured memory_bytes: 23508
#include <bits/stdc++.h>
using namespace std;
int N, M, K, S, P, Q, a, b, d1[111111], z[111111]; long long d2[111111]; vector<int> G[111111];
int main() {
	scanf("%d%d%d%d%d%d", &N, &M, &K, &S, &P, &Q);
	queue<int> que1;
	fill(d1, d1 + N, -1);
	for (int i = 0; i < K; i++) {
		scanf("%d", &a); a--; z[a] = 1;
		d1[a] = 0, que1.push(a);
	}
	for (int i = 0; i < M; i++) {
		scanf("%d%d", &a, &b); a--, b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	while (!que1.empty()) {
		int v = que1.front(); que1.pop();
		for (auto &e : G[v]) {
			if (d1[e] == -1) d1[e] = d1[v] + 1, que1.push(e);
		}
	}
	priority_queue<pair<long long, int> > que2; que2.push(make_pair(0, 0));
	fill(d2 + 1, d2 + N, 1LL << 60);
	while (!que2.empty()) {
		int v = que2.top().second; que2.pop();
		for (auto &e : G[v]) {
			if (z[e]) continue;
			long long f = d2[v] + (d1[e] <= S ? Q : P);
			if (d2[e] > f) d2[e] = f, que2.push(make_pair(-d2[e], e));
		}
	}
	cout << d2[N - 1] - (d1[N - 1] <= S ? Q : P) << endl;
	return 0;
}

Measured memory_bytes: 11728
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  int a=0;
  for(int i=1;i<=9;i++){
    for(int j=1;j<=9;j++){
      if(N==i*j){
        a++;
      }
    }
  }
  if(a>0){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  return 0;
}

      


Measured memory_bytes: 256
import math

def parent(i):
    return math.floor(i / 2)

def left(i):
    return 2 * i

def right(i):
    return 2 * i + 1

def get_largest(A, n, i):
    l = left(i)
    r = right(i)
    largest = None
    if l <= n and A[i] < A[l]:
        largest = l
    else:
        largest = i
    if r <= n and A[largest] < A[r]:
        largest = r
    return largest


def max_heapify(A, n, i):
    largest = get_largest(A, n, i)
    x = i
    while largest is not x:
        tmp = A[x]
        A[x] = A[largest]
        A[largest] = tmp
        x = largest
        largest = get_largest(A, n, x)

def build_max_heap(A, n):
    for i in reversed(range(1, math.floor(n/2) + 1)):
        max_heapify(A, n, i)

n = int(input())
heap = [None] + list(map(int, input().split()))

build_max_heap(heap, n)

ans = ''
for i in heap[1:]:
    ans += ' {}'.format(str(i))
print(ans)

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

void solve() {
    int N, Q, K, a, b, c;
    cin >> N;
    vector<vector<pair<int, long long>>> edge(N, vector<pair<int, long long>>());
    for (int i = 0; i < N - 1; i++) {
        cin >> a >> b >> c;
        a--;
        b--;
        edge.at(a).push_back(make_pair(b, c));
        edge.at(b).push_back(make_pair(a, c));
    }
    /*
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < edge.at(i).size(); j++) {
            cout << i << " " << j << " " << edge.at(i).at(j).first << " " << edge.at(i).at(j).second << endl;
        }
    }
    */
    cin >> Q >> K;
    deque<pair<int, long long>> dq{make_pair(K - 1, 0)};
    vector<long long> distance(N, -1);
    distance.at(K - 1) = 0;
    while (!dq.empty()) {
        pair<int, long long> t = dq.front();
        dq.pop_front();
        int v = t.first;
        long long d = t.second;
        for (int i = 0; i < edge.at(v).size(); i++) {
            int u = edge.at(v).at(i).first;
            long long c = edge.at(v).at(i).second;
            if (distance.at(u) > -1) continue;
            distance.at(u) = d + c;
            dq.push_back(make_pair(u, d + c));
            //cout << u << " " << d + c << endl;
        }
    }
    //for (int i = 0; i < N; i++) cout << i << " " << distance.at(i) << endl;
    int x, y;
    for (int i = 0; i < Q; i++) {
        cin >> x >> y;
        cout << distance.at(x - 1) + distance.at(y - 1) << endl;
    }
    return;
}

int main() {
    solve();
}

Measured memory_bytes: 10736
#include <iostream>
#include <string>
#include <map>
using namespace std;
using LL = long long;
 
//~~~~~~~~~~~~~~~~~~~~~_(＾～＾ ｣ ∠)_~~~~~~~~~~~~~~~~~~~~~
 
constexpr LL mod = 1e9 + 7;
 
int main() {
 
    int N;
    cin >> N;
 
    string S;
    cin >> S;
 
    map<char, LL> m;
    for (auto c: S) m[c]++;
 
    LL ans = 1;
    for (auto x: m) {
        ans *= (x.second + 1);
        ans %= mod;
    }
 
    cout << (ans - 1 + mod) % mod;
 
    return 0;
}
 

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

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N; cin >> N;
	string s; cin >> s;
	int ans = 0;
	for (int cut = 1; cut < N; cut++) {
		map<char, int> mask;
		for (int i = 0; i < cut; i++) {
			mask[s[i]] |= 1;
		}
		for (int i = cut; i < N; i++) {
			mask[s[i]] |= 2;
		}
		int cur = 0;
		for (auto m : mask) {
			cur += m.second == 3;
		}
		ans = max(ans, cur);
	}
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    int a,b;
	cin >> a >> b;
	if(a%3==0||b%3==0||(a+b)%3==0){
		cout << "Possible" << endl;
	}
	else{
		cout << "Impossible" << 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 sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    int N,K;
    cin>>N>>K;
    string S;
    cin>>S;
    rep(i,N){
        if(i==K-1){
            cout<<char(S.at(i)+'a'-'A');
        }
        else{cout<<S.at(i);}
    }
    cout<<endl;
}

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

#define pb push_back 

ll const mod=1e9+7;





int main()
{

int a,b,c;
cin>>a>>b>>c;
if(b*c>=a)
{
	cout<<"Yes";
}
else
cout<<"No";

}

Measured memory_bytes: 3632
#include <stdio.h>

int main(void)
{
	int n, a[4], y, x, i;
	while (scanf("%d", &n)!=EOF)
	{
		if (n>9999 || n<1000)
		{
			printf("No\n");
			continue;
		}

		y=n;
		x=1000;
		for (i=0; i<4; i++)
		{
			a[i] = y/x;
			y = y%x;
			x/=10;
		}
		//printf("%d%d%d%d", a[0],a[1],a[2], a[3]);
		if (((a[0] == a[1]) && (a[1] == a[2]) ) || (a[3]==a[2] &&a[2]==a[1]))
		{
			printf("Yes\n");
		}
		else
		{
			printf("No\n");
		}
	}
}

Measured memory_bytes: 128
N = int(input())
num_list = list(map(int, input().split()))
#print(N, num_list)

sorted_list = sorted(num_list)
false_count = 0
for i, j in zip(num_list, sorted_list):
  if i != j:
    false_count += 1
    if false_count > 2:
      print('NO')
      break

if false_count <=2:
	print('YES')


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

#define PI 3.14159265358979323846

using namespace std;

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

	cout << setprecision(11) << fixed;

	double a, b, h, m;
	cin >> a >> b >> h >> m;

	double dh = h + m / 60.0;
	double dm = m / 60.0 * 12.0;

	double d;
	if (dh > dm) {
		d = dh - dm;
	} else {
		d = dm - dh;
	}

	double angle = d / 12.0 * 2 * PI;
	if (angle > PI) angle = 2 * PI - angle;
	double res = sqrt(a * a + b * b - 2 * a * b * cos(angle));
	cout << res << '\n';

	return 0;
}



Measured memory_bytes: 4244
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;
const double PI = 3.14159265358979323846264338;

int main() {
    int a, b, x;
    cin >> a >> b >> x;
    double vol = a * a * b / 2, v;
    if(x <= vol)
        v = (double)a * b * b / (2 * x);
    else
        v = (double)2 * (a * a * b - x) / (a * a * a);
    printf("%.10lf\n", atan(v) * 180 / PI);
    return 0;
}


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

typedef long long ll;
const int N = 1e5 + 10;
ll n, s[N], a[N], b[N], ans;  // a[i] 存的是 s[i] 的最简数，b[i] 是 a[i] 的补数
map<ll, int> num;
map<ll, bool> vis;
int mark[N], p[N], tot;  // 10^{10/3} 以内质数有 326 个，10^{10/3}~10^5 以内质数有 9267 个

void euler(int n) {
    rep(i, 2, n) {
        if (!mark[i]) p[++tot] = i;
        for (int j = 1; j <= tot && p[j] * i <= n; j++) {
            mark[p[j] * i] = 1;
            if (i % p[j] == 0) break;
        }
    }
}

int main() {
    euler(100000);
    cin >> n;
    rep(i, 1, n) scanf("%lld", &s[i]);

    ll k, tmp;
    rep(i, 1, n) {
        k = s[i]; a[i] = b[i] = 1;
        rep(o, 1, tot) {  // 2200 ^ 3 约等于 1e10
            if (k == 1) break;
            ll j = p[o];
            if (j * j * j >= 1e10) break;
            if (mark[j]) continue;

            tmp = 1ll * j * j * j;
            while (k % tmp == 0) k /= tmp;  // 简化
            tmp = 1ll * j * j;
            if (k % tmp == 0) a[i] *= tmp, b[i] *= j;
            else if (k % j == 0) a[i] *= j, b[i] *= tmp;
            while (k % j == 0) k /= j;
        }
        if (k > 1) {
            tmp = (ll)sqrt(k);
            if (tmp * tmp == k) a[i] *= k, b[i] *= tmp;
            else a[i] *= k, b[i] *= k * k;
        }
    }
    rep(i, 1, n) num[a[i]]++;
    rep(i, 1, n) {
        if (vis[a[i]]) continue;
        vis[a[i]] = vis[b[i]] = 1;
        ans += (a[i] == b[i] ? 1 : max(num[a[i]], num[b[i]]));
    }
    printf("%lld\n", ans);
    return 0;
}


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

Q = int(input())

for _ in range(Q):
    q = list(map(int,input().split()))
    if q[0] == 0:
        print(min(A[q[1]:q[2]]))
    else:
        print(max(A[q[1]:q[2]]))


Measured memory_bytes: 5708
#include<stdio.h>
int main() {
	int n, m, a, b, s[200005] = {};
	scanf("%d", &n);
	m = n;
	if (m % 10 == 1)n += 8;
	if (m % 10 == 9)n -=8;
	m /= 10;
	if (m % 10 == 1)n += 80;
	if (m % 10 == 9)n -= 80;
	m /= 10; 
	if (m % 10 == 1)n += 800;
	if (m % 10 == 9)n -= 800;
	

	printf("%d", n);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main() {
	int i,j,k,h,w;
	bool tf;
	char a[52][52];
	cin>>h>>w;
	memset(a,'.',sizeof(a));
	for(i=1;i<=50;i++)
	   for(j=1;j<=50;j++)a[i][j]='.';
	for(i=1;i<=h;i++){
	    for(j=1;j<=w;j++)cin>>a[i][j];
    }  
    for(i=1;i<=h;i++)
        for(j=1;j<=w;j++){
        	if(a[i][j]=='#'){
        	if(a[i+1][j]=='#'||a[i-1][j]=='#'||a[i][j-1]=='#'||a[i][j+1]=='#')tf=true;else{tf=false;cout<<"No";return 0;}
		    }
	}
	cout<<"Yes";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;main(){string s;cin>>s;for(int i=0;i<(int)s.size()-7;++i){string t=s.substr(i,8);sort(t.begin(),t.end());if(t=="AADINNUY"){s=s.substr(0,i)+"AIZUNYAN"+s.substr(i+8);i+=7;}}cout<<s<<endl;}

Measured memory_bytes: 1216