akhauriyash/Code-Regression huggingface dataset:
using System;



class Program
{
    static void Main(string[] args)
    {
        Input CInput = new Input();
        int[,] input = new int[(int) Input.Define.MAX_ArraySize, (int) Input.Define.ArraySize2d];
        int num = 0;
        input = CInput.Multiline_int(' ' ,2, ref num);

        for (int i = 0; i < num; i++)
        {
            if (input[i,0] <= input[i,1]) Console.WriteLine("{0} {1}", input[i,0], input[i,1]);
            else Console.WriteLine("{0} {1}", input[i,1], input[i,0]);
        }
    }








    class Input
    {
        public enum Define
        {
            MAX_ArraySize = 1000000,
            ArraySize2d = 2,                // 2?¬?????????????[][?] ???????
        }

        public string Line1_string()
        {
            return Console.ReadLine();
        }

        public int Line1_int()
        {
            var input = Console.ReadLine();
            return int.Parse(input);
        }

        public int[] Line1_int(int chr, int num)
        {
            var input = Console.ReadLine();
            var split = input.Split(' ');
            int[] spliti = new int[100];
            for (int i = 0; i < num; i++)
            {
                spliti[i] = int.Parse(split[i]);
            }
            return spliti;
        }

        public int[] Multiline_int(ref int datanum)
        {
            int i = 0;
            int[] data = new int[(int)Input.Define.MAX_ArraySize];
            while (true)
            {
                var input = Console.ReadLine();
                var value = int.Parse(input);
                if (value == 0) break;
                data[i] = value;
                i++;
            }
            datanum = i;
            return data;
        }
        /// <summary>
        /// ?????°??????int??????????????????????????????
        /// </summary>
        /// <param name="chr">???????????????</param>
        /// <param name="num">?????????????????????????????°</param>
        /// <param name="datanum">??????????????????????????°</param>
        /// <returns></returns>
        public int[,] Multiline_int(int chr, int num, ref int datanum)
        {
            int i = 0;
            int[,] data = new int[(int) Input.Define.MAX_ArraySize, (int) Input.Define.ArraySize2d];
            while (true)
            {
                var input = Console.ReadLine();
                var split = input.Split(' ');
                int[] spliti = new int[100];
                for (int j = 0; j < num; j++)
                {
                    spliti[j] = int.Parse(split[j]);
                }
                if (spliti[0] == 0 && spliti[1] == 0) break;
                data[i,0] = spliti[0];
                data[i,1] = spliti[1];
                i++;
            }
            datanum = i;
            return data;
        }

    }
}

Measured memory_bytes: 26828
N, K, T, U, V, L = map(int, input().split())
ans = 0
l = 0
t = 0
k = 0
for _ in range(N + 1):
    if _ == N:
        d = L
    else:
        d = int(input())
    length = d - l
    l = d
    while t > 0 or k > 0:
        if t > 0:
            if t * V >= length:
                tmp = (t * V - length) / V
                ans += t - tmp
                t = tmp
                if K > k:
                    k += 1
                else:
                    t = T
                length = 0
                break
            else:
                length = length - t * V
                ans += t
                t = 0
                if k > 0:
                    k -= 1
                    t = T
        elif k > 0:
            k -= 1
            t = T
    if length > 0:
        ans += length / U
        if K > k:
            k += 1
        else:
            t = T
print(ans)


Measured memory_bytes: 5616
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000009
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define int ll
#define Endl endl


signed main(){
    string S,T;
    int A[100]={};
    int D[6]={1,0,0,1,1,1};
    cin >> S;T=S;
    REP(i,T.size()){
        if(T[i]=='A'){
            T.erase(i,1);
            i--;
        }
    }
    if(T!="KIHBR"){
        cout << "NO" << endl;return 0;
    }
    int a=0;
    REP(i,S.size()){
        if(S[i]=='A'){
            A[a]++;
        }else{
            a++;
        }
    }
    REP(i,a+1){
        if(A[i]>D[i]){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}   


Measured memory_bytes: 256
#include<stdio.h>
int main(void) {
	int i, j, n, x, m[100], g = 0, w, h = 0,k = 0;
	scanf("%d%d", &n, &x);
	for (i = 0; i < n; i++) {
		scanf("%d", &m[i]);
	}
	w = m[0];
	for (i = 1; i < n; i++) {
		if (w > m[i])w = m[i];
	}
	for (i = 0; i < n; i++) {
		g += m[i];
		h++;
		if (g > x) {
			g -= m[i];
			h--;
			k = 1;
			break;
		}
	}
	if(k == 0)h += ((x - g) / w);
	printf("%d\n", h);
	return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] arr = sc.next().toCharArray();
		int k = sc.nextInt();
		int[] weight = new int[5];
		weight[4] = 1;
		for (int i = 3; i >= 0; i--) {
			weight[i] = weight[i + 1] * 27;
		}
		TreeSet<Integer> set = new TreeSet<>();
		for (int i = 0; i < arr.length; i++) {
			int prev = 0;
			for (int j = 0; j < 5 && i + j < arr.length; j++) {
				prev += (arr[i + j] - 'a' + 1) * weight[j];
				set.add(prev);
			}
		}
		int target = 0;
		for (int i = 0; i < k; i++) {
			target = set.pollFirst();
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < 5; i++) {
			int x = target / weight[i];
			if (x == 0) {
				break;
			}
			sb.append((char)(x + 'a' - 1));
			target %= weight[i];
		}
		System.out.println(sb);
	}
}


Measured memory_bytes: 25372
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String x = sc.next();
        ArrayList<Integer> digits = new ArrayList<>();
        for (char i : x.toCharArray()) {
            digits.add(i - '0');
        }
        int ans = digits.stream().mapToInt(i -> i).sum();
        for (int i = 0; i < x.length(); i++) {
            if (digits.get(i) != 0) {
                ans = Math.max(ans, digits.stream().limit(i).mapToInt(j -> j).sum() + digits.get(i) - 1 + (x.length() - i - 1) * 9);
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 28116
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;
const long long mod = 1e9 + 7;
const int maxn = 1005;

int p[maxn],m;
void initial()
{
    int vis[maxn];
    int i,j;
    memset(vis,0,sizeof(vis));
    for(i = 2;i <= 1000;i++)
    {
        if(!vis[i])
        {
            for(j = (i << 1);j <= 1000;j += i)
                vis[j] = 1;
        }
    }
    m = 0;
    for(i = 2;i <= 1000;i++)
        if(!vis[i]) p[m++] = i;
}
int cal(int n,int p_i)
{
    return n < p_i ? 0 : (n/p_i + cal(n/p_i,p_i));
}

int main()
{
    int n;
    int i;
    long long sum = 1;
    initial();
    scanf("%d",&n);
    for(i = 0;i < m;i++)
    {
        sum = sum * (cal(n,p[i]) + 1) % mod;
    }
    printf("%lld\n",sum);

    return 0;
}


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

using ll = long long;
using namespace std;
const int INFint = 2e9+1;
const ll INFll = 2e18+1;
ll MOD=1e9+7;

int main(){
  int H,W,N;
  cin>>H>>W>>N;
  vector<int> A(N);
  for(int i(0);i<N;i++){
    cin>>A[i];
  }
  int G[100][100] = {0};
  int tmp(0);
  for(int h(0);h<H;h++){
    if(h%2==0){
      for(int w(0);w<W;w++){
        G[h][w] = tmp+1;
        A[tmp]--;
        if(A[tmp] == 0) tmp++;
      }
    }else{
      for(int w(W-1);w>=0;w--){
        G[h][w] = tmp+1;
        A[tmp]--;
        if(A[tmp] == 0) tmp++;
      }
    }
  }
  for(int h(0);h<H;h++){
    for(int w(0);w<W;w++){
      cout << G[h][w]<< " ";
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 384
// Problem : C - One Quadrillion and One Dalmatians
// Contest : AtCoder - AtCoder Beginner Contest 171
// URL : https://atcoder.jp/contests/abc171/tasks/abc171_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// writer: w33z8kqrqk8zzzx33
#include <bits/stdc++.h>
using namespace std;

#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define fi first
#define se second
#define pb push_back
 
#define ll long long
#define pii pair<int, int>
//#define int ll
const int MOD = 1000000007;

string gt(ll idx, int len) {
	string ans;
	rep(i, len) {
		ans += 'a' + idx % 26;
		idx /= 26;
	}
	reverse(ans.begin(), ans.end());
	return ans;
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    ll n; cin >> n; n--;
    ll cur = 26, l = 1;
    while(n >= cur) { l++; n -= cur; cur *= 26; }
    cout << gt(n, l) << endl;
}



Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

void insertionSort(vector<int>& A, int n) {
  for (int k = 0; k < n; k++) {
    cout << A[k] << (k == n - 1 ? ln : " ");
  }
  
  for (int i = 1; i < n; i++) {
    int v = A[i];
    int j = i - 1;

    while (j >= 0 && A[j] > v) {
      A[j + 1] = A[j];
      j--;
    }
    A[j + 1] = v;

    for (int k = 0; k < n; k++) {
      cout << A[k] << (k == n - 1 ? ln : " ");
    }
  }
}

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

  int n;
  cin >> n;

  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  insertionSort(a, n);

  return 0;
}


Measured memory_bytes: 3196
#include<bits/stdc++.h>
using namespace std;
int main(){
    string str;
    int Q;
    cin>>str;
    cin>>Q;
    bool r_flag= false;
    queue<char> q;
    stack<char> s;
    while(Q--){
      int Ti;
      cin>>Ti;
      if(Ti == 1){
        r_flag = !r_flag;
      }
      else{
          int Fi; char ch;
          cin>>Fi>>ch;
          if(Fi == 1 && !r_flag){
              s.push(ch);
          }
          if(Fi == 1 && r_flag){
              q.push(ch);
          }
          if(Fi == 2 && !r_flag){
              q.push(ch);
          }
          if(Fi == 2 && r_flag){
              s.push(ch);
          }
      }
    }
   string temp = "";
   while(s.size() > 0){ char c =s.top(); s.pop(); temp += c;}
   
    temp += str;
    while(q.size() > 0){ char c = q.front(); q.pop(); temp += c;}   
   
   if(r_flag)  reverse(temp.begin(), temp.end());
     
    cout<<temp<<endl;
}

Measured memory_bytes: 1248
#include <bits/stdc++.h>
#define mp make_pair
#define X first
#define Y second
#define pii pair<ll,ll>
#define x1 dlfjl
#define x2 dkfj
#define MOD 1000000007
#define y1 dskgj
#define y2 dskfj
#define SQ 320
#define N 8388607
typedef int ll;
using namespace std;
ll n,i,j,k,x,y,z,m,q,h,l,timer;
ll a[505][505];
string s;
vector<pii> f;
bool good(ll x, ll y)
{
    return (x >= 0 && x < n && y >= 0 && y < m);
}
int main() {
    //freopen("input.txt","r",stdin);
    string pat = "RGBY";
    cin >> n >> m >> k;
    for (i = 0; i < n; i++)
    {
        for (j = 0; j < m; j++)
        {
            ll x = ((i+j)%(2*k) >= k?0:1);
            x += ((i-j+20000*k)%(2*k) >= k?0:2);
            //cout << x;
            printf("%c",pat[x]);
        }
        cout << endl;
    }
    return 0;
}


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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);

int main(int argc, char* argv[]) {
  long long N;
  scanf("%lld", &N);

  ll ans = 0;
  rep(i, 1, N + 1) {
    string s = to_string(i);
    if (sz(s) % 2 == 0) continue;
    ans++;
  }

  cout << ans << endl;
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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 A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
	int H,W;
	int N;
	int a[10000];
	int map[100][100];

	scanf("%d %d",&H,&W);
	scanf("%d",&N);

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

	int x = 0;
	int y = 0;
	for(int i=0;i<N;i++){
		for(int j=0;j<a[i];j++){
			map[x][y] = i+1;

			if(x%2 == 0){
				if(y==H-1){
					x++;
				}else{
					y++;
				}
			}else if(x%2 == 1){
				if(y==0){
					x++;
				}else{
					y--;
				}
			}
		}
	}

	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			printf("%d ",map[j][i]);
		}
		printf("\n");
	}


	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<cmath>
#include<iomanip>
#include<string.h>
#include<stdio.h>
#include <algorithm>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	long long int n;
	int i,j;
	long long int u;
	long long int p[40];
	while(cin>>n)
	{
		if(n==0)
		{
			cout<<0<<endl;
			continue;
		}
		u=n;
		i=0;
		while(u!=1)
		{
			p[i]=abs(u%(-2));
			u=(u-p[i])/(-2);
			i++;
		}
		p[i]=1;
		for(;i>=0;i--)
		cout<<p[i];
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
H,W,A,B=map(int,input().split())

ans=[]
base="0"*A+"1"*(W-A)
nbase="1"*A+"0"*(W-A)

for i in range(B):
    ans.append(base)
for i in range(H-B):
    ans.append(nbase)

for i in range(H):
    print(ans[i])

Measured memory_bytes: 41616
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n,m,c; cin >> n >> m >> c;
  vector<int> b(m);
  int ans = 0;
  int sum = 0;
  for(int i = 0; i < m; i++){
    cin >> b.at(i);
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j < m; j++){
      int a; cin >> a;
      sum += a * b.at(j);
    }
    if(sum + c > 0) ans++;
    sum = 0;
  }
  cout << ans;
}

Measured memory_bytes: 3600
import collections
n,k = map(int, raw_input().split(' '))
heights = [int(raw_input()) for _ in range(n)]
heights.sort()
q = collections.deque([])
r =  float('inf') 
for h in heights:
	q.append(h)
	if len(q) == k + 1: q.popleft()
	if k and len(q) == k:
		r =min(r, q[-1] - q[0])
print r if k else 0

Measured memory_bytes: 85920
#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
using namespace std;

int main() {
	string c;
	cin>>c;
	if(c=="a"||c=="i"||c=="u"||c=="e"||c=="o") printf("vowel\n");
	else printf("consonant\n");
	return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <vector>
using namespace std;
const int MOD =1000000007;
int main(){
  int N,M;cin>>N>>M;
  vector<bool>issafe;
  issafe.assign(N+1,true);
  for (int i=0;i<M;++i){
    int a;cin>>a;
    issafe[a]=false;
  }
  vector<int>dp(N+1,0);
  dp[0] = 1;
  if (issafe[1]) dp[1] = 1;
  for (int i = 2; i <= N; ++i) {
    if (issafe[i-1])dp[i]+=dp[i-1];
    if (issafe[i-2])dp[i]+=dp[i-2];
    dp[i]%=MOD;
  }
  //dp[N]%=MOD;
  cout<<dp[N]<<endl;
}

Measured memory_bytes: 640
import numpy as np

N,A,B,C = map(int,input().split())
target = [A,B,C]
l = []
#ans = math.inf

for _ in range(N):
    l.append(int(input()))


def calc2(v):
    res = 0
    for i in range(3):
        if len(v[i])==0:
            return np.inf
        res += 10*(len(v[i])-1) + abs(sum(v[i]) - target[i])
    return res

v=[[],[],[],[]]
def dfs2(depth=0):
    #global ans
    if depth == N:
        return calc2(v)
    #else:
    ans = np.inf
    for i in range(4):
        #next_v = v.copy()
        #print(i, v, depth, l)
        v[i].append(l[depth])
        ans = min(ans,dfs2(depth+1))
        del v[i][-1]

    return ans

print(dfs2())

Measured memory_bytes: 18464
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++) 
#define all(v) begin(v),end(v)
using ll = long long;

int main() {
  int d,n;cin>>d>>n;
  int ans=1;
  rep(i,d)ans*=100;
  if(n==100)n++;
  cout<<ans*n<<endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++) 
#define rep(i,n); for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b); 
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a=a%b;}return max(a,b);
}
int dx[]={0,1,0,-1,1,-1,-1,1};
int dy[]={1,0,-1,0,1,1,-1,-1};
const int MOD = 1e9+7;
const int INF = 1e18+10;

/*----------------------------------------------*/


signed main(){
  int n;
  cin>>n;
  vi a(n);
  rep(i,n){
    char c;cin>>c;
    a[i]=c-'a';
  }
  vi memo(n);
  rep(i,n-1){//...[i]/[i+1]...
    int count=0; 
    vi check(26,0),find(26,0);
    FOR(j,0,i) check[a[j]]++;
    FOR(j,i+1,n-1) if(check[a[j]]) find[a[j]]++;
    rep(j,26) if(find[j]) memo[i]++;
  }
  int ans=0
  rep(i,n-1)chmax(ans,memo[i]);
  cout<<ans<<endl;
  
  return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 100000;
const long long inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<int,P> PP;
typedef pair<int,PP> PPP;
struct edge { int to;  int cost; };

vector<int>G[100006];
int v[100006], d[100006], c[100006];
int dp[100006][11];

void dfs(int V, int D, int C) {
	if (D < 0)return;
	for (int i = D; i <= 10; i++) {
		if (dp[V][i] >= 0) return;
	}
	dp[V][D] = C;
	rep(i, G[V].size()) {
		dfs(G[V][i], D - 1, C);
	}
	return;
}

signed main() {
	int n, m; cin >> n >> m;
	rep(i, m) {
		int a, b; cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	int q; cin >> q;
	rep(i, q) {
		cin >> v[i] >> d[i] >> c[i];
		v[i]--;
	}
	rep(i, n)rep(j, 11)dp[i][j] = -1;
	for (int i = q - 1; i >= 0; i--) {
		dfs(v[i], d[i], i);
	}

	rep(i, n) {
		int ac = 0;
		rep(j, 11) {
			if (dp[i][j] != -1) {
				ac = c[dp[i][j]];
				break;
			}
		}
		cout << ac << endl;
	}
}

Measured memory_bytes: 17780
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define PI 3.141592653589793

int main(){
  int N; cin >> N; ll a[N], b[N];
  pair<ll, int> p[N];
  rep(i, N){
    cin >> a[i] >> b[i];
    p[i] = {a[i]+b[i], i};
  }
  sort(p, p+N, greater<>()); ll ans = 0;
  rep(i, N){
    if(i%2==0) ans+=a[p[i].second];
    else ans-=b[p[i].second];
  }
  cout << ans << endl;
}

Measured memory_bytes: 3328
#include <stdio.h>

int main(void)
{
  int n;
  scanf("%d",&n);
  
  int a[n] , count = 0 ,s =1;
  for(int i = 0;i < n;i++){
    scanf("%d",&a[i]);
  }
  
  while(s){
  for(int i = 0;i < n;i++){
    if(a[i]%2!=0){
      s = 0;
  }
    int temp = a[i];
    a[i] = temp/2;
  }
  count ++;
}
    
  printf("%d",count-1);
    
    return 0;
  }


Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <limits>


#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#define deg_to_rad(deg) (((deg)/360)*2*M_PI)
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)

using namespace std;

int main()
{
  int n;
  cin >>n;
  if(n%2==0)
  {
    cout << n/2-1;
  }
  else
  {
    cout <<n/2;
  }

	return 0;
}





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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    ll r, d, x; cin >> r >> d >> x;

    for (int i = 0; i < 10; ++i) {
        x = r * x - d;

        cout << x << endl;
    }
}

Measured memory_bytes: 384
//AOJ 0031

#include<stdio.h>
#include<iostream>
#include<vector>

using namespace std;

int main(){

	int data[10]={1,2,4,8,16,32,64,128,256,512};

	int num;

	while(cin>>num){
		int tmp=0;
		for(int j=0;j<10;j++){

			if(num%2==1){
				if(tmp==0){
					printf("%d",data[j]);
					tmp++;
				}
				else{
					printf(" %d",data[j]);
				}
			}
			num/=2;
		}
		printf("\n");

	}
	return 0;
}

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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl;

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
struct edge{int from, to; ll cost;};

int used[26][26];

int main(){
    std::ios::sync_with_stdio(0); cin.tie(0);
    string s;
    cin >> s;
    int n = (int)s.length();
    if(s.length() != 26){
        rep(n){
            used[0][(int)(s[i]-'a')] = 1;
        }
        cout << s;
        rep(26){
            if(!used[0][i]){
                putchar('a'+i);
                break;
            }
        }
    }else{
        used[0][(int)(s[0]-'a')] = 1;
        reppp(i, 1, n){
            repp(j, 26){
                if(used[i-1][j]) used[i][j] = 1;
            }
            used[i][(int)(s[i]-'a')] = 1;
        }
        int change_idx = -1, change = -1;
        for(int i=n-2;i>=0;i--){
            reppp(j, (int)(s[i]-'a')+1, 26){
                if(!used[i][j]){
                    change = j;
                    change_idx = i;
                    break;
                }
            }
            if(change_idx != -1) break;
        }
        if(change_idx == -1){
            cout << -1;
        }else{
            cout << s.substr(0, change_idx);
            putchar(change+'a');
        }
    }
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import math

N = int(input())
r = math.sqrt(N)
R = int(r)
if r == R:
    print(len(str(R)))
    quit()
for i in range(R + 1, 3, -1):
    if N % i == 0:
        b = int(N / i)
        if len(str(i)) >= len(str(b)):
            print (len(str(i)))
        else:
            print (len(str(b)))
        quit()
print(len(str(N)))

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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

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

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}

//フィボナッチ数列
ll f(ll x){
    ll dp[x+1];
    dp[1]=1;
    dp[2]=1;
    for(ll i=3;i<=x;i++){
        dp[i]=dp[i-1]+dp[i-2];
    }
    return dp[x];
}

//char->int
int ctoi(char c){
    return c-'0';
}



int main(){
    int n;
    cin >> n;
    int a[n];
    rep(i,n) cin >> a[i];

    vector<int> ans(9);
    rep(i,9) ans[i]=0;
    

    for(int i=0;i<n;i++){
        int x = a[i]/400;
        if(x>=8){
            x=8;
        }
        ans[x]++; 
    }

    int sum = 0;

    for(int i=0;i<8;i++){
        if(ans[i]!=0){
            sum++;
        }
    }

    if(sum==0){
        cout << 1 <<" "<< ans[8] << endl;
    }else{
        cout << sum << " " << sum+ans[8] << endl;
    }
}


Measured memory_bytes: 256
pts = [0, 0]
for _ in range(int(input())):
  a, b = input().split()
  if a > b:
    pts[0] += 3
  elif a < b:
    pts[1] += 3
  else:
    pts[0] += 1
    pts[1] += 1

print(pts[0], pts[1])


Measured memory_bytes: 5596
#include <iostream>
#include <cmath>
using namespace std;

int main() {
	int a, b, x;
	cin >> x >> a >> b;
	if ( abs(a - x) > abs(b - x)) {
		cout << "B" << endl;
	} else {
		cout << "A" << endl;
	}
	return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> H(N);
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }
  int res = 0, cnt = 0;
  for (int i = 0; i < N - 1; i++) {
    if (H[i] >= H[i + 1]) {
      cnt++;
    } else {
      cnt = 0;
    }
    res = max(res, cnt);
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 1e9 + 7;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
int main() {
    int n; cin >> n;
    cout << 180 * (n - 2) << endl;
}


Measured memory_bytes: 764
#include <iostream>

using namespace std;
int main()
{
    int k, n, maxim=0, y, cy;
    cin>>k>>n>>y;
    cy=y;
    for(int i=0;i<n-1;i++){
        int x;
        cin>>x;
        maxim=max(maxim, x-y);
        y=x;
    }
    maxim=max(maxim, cy+k-y);
    cout<<k-maxim;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<unordered_map>

int main() {
	std::unordered_map<int, int>mp;

	for (size_t i = 0; i < 3;i++) {
		int temp;
		std::cin >> temp;
		mp[temp] = 1;
	}

	std::cout << mp.size() << std::endl;

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>

using namespace std;

using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;
using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;

int main(int argc, char* argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  
  i32 N, M;
  cin >> N >> M;
  
  unordered_map<i32, i32> ac(N);
  unordered_map<i32, i32> wa(N);
  bool b=false;
  for(i32 i = 0; i < M; ++i) {
    i32 p;
    string S;
    cin >> p >> S;
    p--;
    if(S == "AC" && ac[p] == 0) {
      ac[p]++;
    } else {
        if(ac[p] == 0) {
          wa[p]++;
        }
    }
  }
  
  i32 cnt_ac = 0, cnt_wa = 0;
  for(i32 i = 0; i < N; ++i) {
    if(ac[i]) {
      cnt_ac += ac[i];
    }
    if(wa[i] && ac[i] > 0) {
      cnt_wa += wa[i];
    }
  }
  cout << cnt_ac << " " << cnt_wa << endl;
    
  return 0;
}

Measured memory_bytes: 8192
use std::io;

fn main() {
    let mut str = String::new();
    
    let mut _bytes_read = io::stdin().read_line(&mut str)
        .expect("Failed to read line");
    
    let mut str2 = String::new();
    _bytes_read = io::stdin().read_line(&mut str2)
        .expect("Failed to read line");
    
    let parts: Vec<u32> = str2
        .trim()
        .split( ' ')
        .map(|s| s.parse().expect("Failed to parse"))
        .collect();
    
    if can_swap(parts) {
        print!("YES");
    } else {
        print!("NO");
    }
}

fn can_swap(objs: Vec<u32>) -> bool {
    let mut prev_prev = 0;
    let mut prev = objs[0];
    let mut mismatch_count: u32 = 0;
    let mut prev_lower_bound = 0;
    let mut to_swap = std::u32::MAX;
    for i in 1..(objs.len()) {
        let next = objs[i];
        if prev >= next {
            mismatch_count += 1;
            if mismatch_count > 2 || next <= prev_lower_bound || to_swap <= prev {
                return false;
            }
            
            prev_lower_bound = prev_prev;
            to_swap = prev;
        }
        prev_prev = prev;
        prev = next;
    }
    
    return mismatch_count != 1;
}


Measured memory_bytes: 4352
ls =[]
for i in range(5):
    ls.append(int(input()))
rm = 10
time = 0
for i in ls:
    if i % 10 == 0:
        time += i
    else:
        time += (i//10+1)*10
        rm = min(rm,i%10)
time += rm - 10
print(time)

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

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      int[] seqS = new int[n];
      String[] line = br.readLine().split(" ");
      int c=0;
      for (String s : line)
        seqS[c++] = Integer.parseInt(s);

      int q = Integer.parseInt(br.readLine());
      line = br.readLine().split(" ");
      
      int cnt=0;
      for (String ref : line) {
        if( isExistSeachByBinary(seqS, Integer.parseInt(ref)) )
          cnt++;
      }

      System.out.println(cnt);
    }
  }

  static boolean isExistSeachByBinary(int[] tar, int ref) {
    int left = 0;
    int right= tar.length;
    int mid;
    while( left < right ) {
      mid  = (left + right) / 2;
      if( tar[mid] == ref ) return true;
      else if( tar[mid] > ref ) right = mid;
      else left = mid + 1;
    }

    return false;
  }
}


Measured memory_bytes: 51668
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  bool ans = true;
  cin >> N;
  vector<int> A(N);
  for(int i=0; i<N; i++)
    cin >> A.at(i);
  
  sort(A.begin(), A.end());
  for(int i=0; i<N-1;i++){
    if(A.at(i) == A.at(i+1)){
      ans = false;
      break;
    }
    else
      continue;
  }
  if(ans)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>

#define LL long long int

int cmpLL(const void *n1, const void *n2) {

    if (*(LL *)n1 > *(LL *)n2) {
        return 1;
    } else if (*(LL *)n1 < *(LL *)n2) {
        return -1;
    }

    return 0;
}


int main(void) {

    int n;
    scanf("%d", &n);
    LL *a = (LL *)malloc(n * sizeof(LL));
    LL *b = (LL *)malloc(n * sizeof(LL));
    for (int i = 0; i < n; i ++) {
        scanf("%lld %lld", &a[i], &b[i]);
    }

    qsort(a, n, sizeof(LL), cmpLL);
    qsort(b, n, sizeof(LL), cmpLL);

    int ret;
    if (n % 2 == 1) {
        ret = b[(n - 1) / 2] - a[(n - 1) / 2] + 1;
    } else {
        ret = (b[n / 2 - 1] + b[n / 2]) - (a[n / 2 - 1] + a[n / 2]) + 1;
    }

    printf("%d", ret);

    return 0;
}

Measured memory_bytes: 6380
S = list(input())
T = list(input())
 
Sn = [ord(i)-ord("a") for i in S]
Tn = [ord(i)-ord("a") for i in T]
sub1 = [-1]*26
sub2 = [-1]*26
 
for i in range(len(S)):
    if sub1[Sn[i]] == -1 or sub2[Tn[i]] == -1:
        if sub1[Sn[i]] == -1:
            sub1[Sn[i]] = Tn[i]
        if sub2[Tn[i]] == -1:
            sub2[Tn[i]] = Sn[i]
    if sub1[Sn[i]] != Tn[i] or sub2[Tn[i]] != Sn[i]:
            print("No")
            break
else:
    print("Yes")

Measured memory_bytes: 9776
using System;
using System.Linq;
using System.Collections.Generic;

class P
{
    static void Main(string[] _)
    {
        int n = int.Parse(Console.ReadLine());
        string[] s = new string[n];
        string ans = "";
        for (int i = 0; i < n; i++)
        {
            s[i] = Console.ReadLine();
        }
        for (char c = 'a'; c <= 'z' ; c++)
        {
            int small = int.MaxValue;
            for (int i = 0; i < n; i++)
            {
                int cnt = 0;
                for (int j = 0; j < s[i].Length; j++)
                {
                    if (c == s[i][j])
                    {
                        cnt++;
                    }
                }
                small = Math.Min(cnt, small);
            }
            for (int i = 0; i < small; i++)
            {
                ans += c;
            }
        }
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 11092
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	K := nextInt()
	ans := 0
	for a := 1; a <= K; a++ {
		for b := 1; b <= K; b++ {
			for c := 1; c <= K; c++ {
				ans += gcdof2numbers(a, gcdof2numbers(b, c))
			}
		}
	}
	fmt.Println(ans)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func gcdof2numbers(a int, b int) int {
	if b == 0 {
		return a
	}
	return gcdof2numbers(b, a%b)
}


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

using namespace std;

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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    int youki =  min(a, b+c);
    cout << c - (youki-b);
} 


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

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

constexpr double EPS = 1e-7;
constexpr int INF = 1e9;
#define PI (acos(-1))

constexpr int MOD = 1e9 + 7;

inline int keta(int x) {
	return floor(log10(x)) + 1;
}

inline int pre(int x) {
	return x / pow(10, keta(x) - 1);
}

int main(int argc, char const *argv[]) {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);

	int N;
	cin >> N;

	vector<vector<int>> c(10, vector<int>(10, 0));
	for (int i = 0; i <= N; i++) {
		if (i % 10 == 0) {
			continue;
		}

		c[pre(i)][i % 10]++;
	}
	int ans = 0;
	for (int i = 1; i <= 9; i++) {
		for (int j = 1; j <= 9; j++) {
			ans += c[i][j] * c[j][i];
		}
	}
	cout << ans << endl;
	return 0;
}


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

#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,a,n) for(ll i=a;i<n;i++)

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tiii;
typedef pair<ll, ll> pll;

const int INF = 100000000;
const ll LINF = 1e18+5;

int main() {
    ll H, W, N;
    cin >> H >> W >> N;
    ll ans = N / max(H,W);
    if(N%max(H,W)==0) cout << ans << endl;
    else cout << ans+1 << endl;
    return 0;
}

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

int main(){
    long long n;
    cin >> n;
    long long a[n],b[n],c[n];
    for(long long i=0;i<n;i++) cin >> a[i];
    sort(a,a+n);
    for(long long i=0;i<n;i++) cin >> b[i];
    for(long long i=0;i<n;i++) cin >> c[i];
    sort(c,c+n);
    long long count=0;
    for(long long i=0;i<n;i++){
        long long d,e;
        d=lower_bound(a, a + n, b[i]) - a;
        e=c+n-upper_bound(c,c+n,b[i]);
        count+=d*e;
    }
    cout << count << endl;
}


Measured memory_bytes: 2560
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define mod 1000000007
typedef long long int ll;
ll dp[100001];
int q(const void *a, const void *b){
    return *(ll*)a-*(ll*)b;
}
int min(int a,int b){
  if(a>b)return b;
  return a;
}
int max(int a,int b){
  if(a>b)return a;
  return b;
}
int gcd(int a,int b){
  if(!b)return a;
  return gcd(b,a%b);
}
int main(void) {
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  if(a>=c){
    PRN(0);
  }else if(a+b>=c){
    PRN(c-a);
  }else{
    PRS("NA");
  }
  return 0;
}


Measured memory_bytes: 2132
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10 ** 7)


def solve(N: int, W: "List[int]"):
    min_abs = 1e+9
    for i in range(N):
        min_abs = min(abs(sum(W[:i]) - sum(W[i:])), min_abs)
    print(min_abs)
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools
# (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    W = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, W)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvv vector<vvl>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvvl(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
//typedef __int128_t lll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n;std::cin >> n;
  vll a(n);re(i, n) std::cin >> a[i];
  vll d(300000, 0);
  re(i, n) d[a[i]]++;
  ll ans = 0;
  re(i, 300000) ans += (d[i]*(d[i]-1))/2;
  re(i, n){
    ll num = d[a[i]];
    ll af = num - 1;
    std::cout << ans - (num*(num-1))/2 + (af*(af-1))/2 << '\n';
  }
  return 0;
}


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

int n;
int hi[100080],dp[100080];


int main()
{
	ios::sync_with_stdio("false");
//	freopen(".in","r",stdin);
//	freopen(".out","r",stdout);
	cin>>n;
	memset(dp,0x3f3f3f3f,sizeof(dp));
	for(register int i=1;i!=n+1;++i)
		cin>>hi[i];
	dp[1]=0;
	for(register int i=1;i!=n+1;++i)
	{
		dp[i+1]=min(dp[i+1],dp[i]+abs(hi[i]-hi[i+1]));
		dp[i+2]=min(dp[i+2],dp[i]+abs(hi[i]-hi[i+2]));
	}
	cout<<dp[n]<<"\n";
	
	
	return 0;
}


Measured memory_bytes: 1024
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 62;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
int n;
int ans = 0;
vector<int> bfs(int s, vector<vector<int>> &g){
    vector<int> res(n, -1);
    queue<pair<int,int>> q;
    q.push({s, 0});
    res[s] = 0;
    while(!q.empty()){
        int now = q.front().first;
        int nowdist = q.front().second;
        q.pop();
        rep(i, g[now].size()){
            int next = g[now][i];
            int nextdist = nowdist + 1;
            if(res[next] != -1) continue;
            res[next] = nextdist;
            q.push({next, nextdist});
        }
    }

    return res;
}

int solve(int s, vector<vector<int>> &g, vector<int> &adist, int &a){
    vector<int> dist(n, -1);
    queue<pair<int,int>> q;
    q.push({s, 0});
    while(!q.empty()){
        int now = q.front().first;
        int nowdist = q.front().second;
        q.pop();
        rep(i, g[now].size()){
            int next = g[now][i];
            int nextdist = nowdist + 1;
            if(dist[next] != -1) continue;
            if(adist[next] < nextdist) continue;
            dist[next] = nextdist;
            q.push({next, nextdist});
        }
    }

    int ma = 0;
    int idx = s;
    rep(i, n){
        //cout << i  << " " << dist[i] << " " << adist[i] << endl;
        if(dist[i] != -1){
            ma = max(ma, adist[i]);
        }
    }

    return max(0, ma - 1);
}
int main(void){
    int t, a;
    cin >> n >> t >> a;
    t--;
    a--;
    vector<vector<int>> g(n);
    vector<int> dist(n, 0);
    rep(i, n - 1){
        int a, b;
        cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<int> adist = bfs(a, g);
    cout << solve(t, g, adist, a) << endl;
    

}

Measured memory_bytes: 7168
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    int N;
    string S;
    scan(N);
    scan(S);

    int ans;

    foreach (i ; 0 .. 1000) {
        auto num = format("%03s", i).to!string;
        if (check(num, S)) {
            ans++;
            debug {
                writeln(num);
            }
        }
    }

    writeln(ans);
}

bool check(string s, string t) {
    debug {
        //writeln(s, " ", t);
    }
    while (!s.empty) {
        while (!t.empty && t.front != s.front) t.popFront();
        if (t.empty) break;
        s.popFront();
        t.popFront();
    }
    return s.empty;
}






void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 2428
import Data.List
import Data.Char
main = getContents >>= putStrLn.show.count.map (map (replace.toUpper)).takeWhile (/="END_OF_TEXT").lines
    where count (x:xs) = length.filter (==x) $words (concatMap (' ':) xs)
          replace c | c `elem` ['A'..'Z'] = c
                    | otherwise           = ' '

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

constexpr int inf = 1e9;
constexpr ll linf = 1e18;

struct edge
{
    int to, cost;
    edge(int to, int cost) : to(to), cost(cost) {}
};

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

    int n; cin >> n;
    vector<vector<edge>> g(n);
    for (int i = 0; i < n - 1; i++) {
        int a, b, c; cin >> a >> b >> c;
        a--, b--;
        g[a].emplace_back(b, c);
        g[b].emplace_back(a, c);
    } 

    int q, k; cin >> q >> k; k--;

    // dijkstra
    vector<ll> d(n, linf);
    priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> que;
    d[k] = 0; que.emplace(0, k);
    while (!que.empty()) {
        auto p = que.top(); que.pop();
        if (d[p.second] < p.first) continue;

        for (auto &e: g[p.second]) {
            if (d[p.second] + e.cost < d[e.to]) {
                d[e.to] = d[p.second] + e.cost;
                que.emplace(d[e.to], e.to);
            }
        }
    }

    while (q--) {
        int x, y; cin >> x >> y;
        x--, y--;
        cout << d[x] + d[y] << '\n';
    }
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  bool ans = false;
  for (int a = 0; a < 15; a++) {
    for (int b = 0; b < 26; b++) {
      if (7*a + 4*b == N) {
        ans = true;
        break;
      }
    }
    if (ans) break;
  }
  
  if (ans) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 764
// AOJ 0099 Surf Smelt Fishing Contest II
// プライオリティキューを使う

#include <iostream>
#include <queue>

using namespace std;

typedef pair<int, int> pii;

const int MAX_N = 1000000;
// 釣った匹数
int surf_smelts[MAX_N + 1];

int
main()
{
    int n, q, i;
    // 最大要素から出てくるプライオリティキュー。
    // ペアの比較の場合は first -> second の順で比較。
    priority_queue<pii> pque;

    cin >> n >> q;

    // 釣った匹数が負になる場合を考慮し、各参加者の初期状態を追加。
    // second が小さいものから出るよう、second は符号を逆にする。
    for (i = 1; i <= n; i++) pque.push(pii(0, -i));

    while (q--) {
        int a, v;

        cin >> a >> v;

        surf_smelts[a] += v;
        pque.push(pii(surf_smelts[a], -a));

        for (;;) {
            int a_max = -(pque.top().second);
            int v_max = pque.top().first;

            if (surf_smelts[a_max] == v_max) {
                cout << a_max << " " << v_max << endl;
                break;
            }

            pque.pop();
        }
    }

    return 0;
}

Measured memory_bytes: 22476