akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
using namespace std;
 
typedef long long ll;
 
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;

#define INF 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { debug(itr); }
 
template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    string s,t;
    cin >> s >> t;
    cout << t << s << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
using namespace std;
typedef long long ll;

#define mod (1000000007)

int main(void)
{
    int n,k;
    cin >> n >> k;
    vector<ll> x(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }

    ll res = 1000000000000000;
    for (int left = 0, right = left + k - 1; right < n; left++, right++) {
        if (x[left] * x[right] == 0) {
            if (x[left] < 0) {
                res = min(res, -x[left]);   
            } else {
                res = min(res, x[right]);   
            }
        } else if (x[left] * x[right] > 0) {
            if (x[left] < 0) {
                res = min(res, -x[left]);
            } else {
                res = min(res, x[right]);
            }
        } else {
            if (-x[left] < x[right]) {
                res = min(res, -x[left] * 2 + x[right]);
            } else {
                res = min(res, -x[left] + x[right] * 2);
            }
        }
    }

    cout << res << endl;
}


Measured memory_bytes: 1024
#!/usr/bin/env python3
import sys
import math
INF = float("inf")


def solve(N: int):

    debug = False
    SN = str(N)
    keta = int(math.log10(N)+1)
    count = 0
    for i in range(1, N+1):
        first = str(i)[0]
        last = str(i)[-1]
        if last == "0":         # 考えない
            continue
        # ひとけた
        if first == last:
            count += 1
        # ふたけた
        if int(last+first) <= N:
            count += 1
        if keta < 3:
            continue
        # 3桁以上keta桁未満
        for j in range(3, keta):
            count += 10**(j-2)
        # keta桁
        # Nを超えない数
        if last < SN[0]:
            count += 10**(keta-2)
        elif last == SN[0]:
            # 間の桁について、i桁までまで考える。
            DP = [[0]*2 for _ in range(keta-1)]
            DP[0][False] = 1
            for j in range(1, keta-1):
                DP[j][False] = DP[j-1][False]*1
                DP[j][True] = DP[j-1][True]*10 + DP[j-1][False]*int(SN[j])
            count += DP[-1][True]
            if SN[-1] >= first:
                count += 1
    print(count)
    return


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
    solve(N)


if __name__ == '__main__':
    main()


Measured memory_bytes: 44524
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
long long MOD=1e9+7;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);    
    int n;
    cin>>n;
    int a[n];
    int m[n]={};
    int x=0;
    int y=0;
    int z=0;
    long long ans=1; 

    for(int i=0;i<n;i++){
        cin>>a[i];
        if(x==a[i]){
            m[i]++;
            x++;
        }
        if(y==a[i]){
            if(m[i]==0){
                y++;
            }
            m[i]++;
        }
        if(z==a[i]){
            if(m[i]==0){
                z++;
            }
            m[i]++;
        }
        ans*=m[i];
        ans%=MOD;

    }
    cout<<ans;
    
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
 
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
        String str;
        String[] arrStr;
        StringBuilder output = new StringBuilder();
        int a,b;
        try {
 
            while(true){
                str = br.readLine();
 
                if(str.equals("0 0")){
                    // ??????
                    break;
                }
 
                arrStr = str.split(" ");
                a = Integer.parseInt(arrStr[0]);
                b = Integer.parseInt(arrStr[1]);
 
                if(a<b){
                    output.append(a).append(" ").append(b).append("\n");
                }else{
                    output.append(b).append(" ").append(a).append("\n");
                }
            }
            System.out.print(output.toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Measured memory_bytes: 25256
N = int(input())

t = 1
a = 1
for i in range(N):
    T,A = map(int,input().split())
    r = max((t-1)//T,(a-1)//A) + 1
    t = T * r
    a = A * r
    #print(r,t,a)

print(t + a)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>

#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define REV(i,a,n) for(int i=n;i>=a;--i)
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define show(n) cerr<<#n<<" = "<<n<<endl
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl

//ここからAtCoder向けdefine
#define yes cout << "YES" << endl
#define no cout << "NO" << endl

using namespace std;

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using pint = pair<int,int>;

const int INF = ~(1 << 31);

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vi vec(n);
    rep(i, n){
        cin >> vec[i];
    }
    sort(rall(vec));

    int a = 0, b = 0;
    rep(i, n){
        if(i % 2 == 0){
            a += vec[i];
        }else{
            b  += vec[i];
        }
    }
    cout << a - b << endl;

    return 0;
}

Measured memory_bytes: 384
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, cos, radians, pi, sin
from operator import mul
from functools import reduce
from operator import mul

mod = 10 ** 9 + 7
sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]


n = I()
G = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = LI()
    G[a - 1] += [b - 1]
    G[b - 1] += [a - 1]

cond = [(-INF, INF) for _ in range(n)]
k = I()
for _ in range(k):
    v, p = LI()
    cond[v - 1] = (p, p)

ans = [0] * n
visited = [0] * n
def f(u):
    visited[u] = 1
    max_ret = cond[u][1]
    min_ret = cond[u][0]
    u_flg = max_ret % 2 if max_ret == min_ret else -1
    for v in G[u]:
        if visited[v]:
            continue
        x, y, flg = f(v)
        if flg != -1 and u_flg == flg:
            print("No")
            exit()
        max_ret = min(max_ret, y + 1)
        min_ret = max(min_ret, x - 1)
    if min_ret > max_ret:
        print("No")
        exit()
    cond[u] = (min_ret, max_ret)
    return min_ret, max_ret, u_flg

f(0)
print("Yes")
visited = [0] * n
ans = [-1] * n
ans[0] = cond[0][0]
def f2(u):
    visited[u] = 1
    for v in G[u]:
        if visited[v]:
            continue
        ans[v] = ans[u] + 1 if cond[v][0] <= ans[u] + 1 <= cond[v][1] else ans[u] - 1
        f2(v)

f2(0)
print(*ans, sep="\n")

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

int main(){
    ll n; cin >> n;
    vector<ll> a(n), b(n), c(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++) cin >> b[i];
    for(int i = 0; i < n; i++) cin >> c[i];
    ll ans = 0;
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    for(int i = 0; i < n; i++){
        ll anum = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
        ll cnum = c.end() - upper_bound(c.begin(), c.end(), b[i]);
        ans += anum * cnum;
    }
    cout << ans << endl;
}

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

int main()
{
    int n, s[10010], q, t[510];
    cin >> n;
    for (int i = 0; i < n; i++) cin >> s[i];
    cin >> q;
    for (int i = 0; i < q; i++) cin >> t[i];

    int cnt = 0;
    for (int i = 0; i < q; i++) {
        for (int j = 0; j < n; j++) {
            if (s[j] == t[i]) {
                cnt++;
                break;
            }
        }
    }

    cout << cnt << endl;


    return 0;
}



Measured memory_bytes: 3140
#include <iostream>
#include <vector>
#include <queue>

template <class Cost = int>
struct Edge {
    int src, dst;
    Cost cost;
    Edge(int src = -1, int dst = -1, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = int>
using Graph = std::vector<std::vector<Edge<Cost>>>;

using lint = long long;

constexpr int S = 100;

void solve() {
    int n, m;
    std::cin >> n >> m;

    std::vector<int> ss(3);
    for (auto& s : ss) std::cin >> s;

    Graph<> rgraph(n);
    while (m--) {
        int u, v;
        std::cin >> u >> v;
        --u, --v;
        rgraph[v].emplace_back(v, u);
    }

    std::vector<std::vector<lint>> rss(n, std::vector<lint>(S + 1, 0));
    for (int v = 0; v < n; ++v) {
        rss[v][0] = (1LL << v);
    }
    for (int x = 1; x <= S; ++x) {
        for (int v = 0; v < n; ++v) {
            for (auto e : rgraph[v]) {
                int u = e.dst;
                rss[v][x] |= rss[u][x - 1];
            }
        }
    }

    std::vector<int> dist(n, -1), flag(n, 0);
    dist[n - 1] = 0, flag[n - 1] = 0b111;
    for (int d = 0;; ++d) {
        std::queue<int> que;
        for (int v = 0; v < n; ++v) {
            if (dist[v] == d) que.push(v);
        }
        if (que.empty()) break;

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

            for (int i = 0; i < 3; ++i) {
                for (int u = 0; u < n; ++u) {
                    if (!((rss[v][ss[i]] >> u) & 1) ||
                        (flag[u] >> i) & 1) continue;

                    flag[u] |= (1 << i);
                    if (flag[u] == 0b111) dist[u] = d + 1;
                }
            }
        }
    }

    if (dist[0] == -1) {
        std::cout << "IMPOSSIBLE" << std::endl;
    } else {
        std::cout << dist[0] << std::endl;
    }
}

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

    solve();

    return 0;
}



Measured memory_bytes: 3284
class Combination:
    def __init__(self, mod, max_num):
        self.mod = mod
        self.fac = [0] * max_num
        self.finv = [0] * max_num
        self.inv = [0] * max_num

        self.fac[0], self.fac[1] = 1, 1
        self.finv[0], self.finv[1] = 1, 1
        self.inv[1] = 1

        for i in range(2, max_num):
            self.fac[i] = self.fac[i-1] * i % mod
            self.inv[i] = mod - self.inv[mod % i] * (mod // i) % mod
            self.finv[i] = self.finv[i - 1] * self.inv[i] % mod

    def calc(self, n, k):
        if n < k:
            return 0
        if n < 0 or k < 0:
            return 0
        return self.fac[n] * (
            self.finv[k] * self.finv[n - k] % self.mod) % self.mod


n, k = map(int, input().split())

com = Combination(1000000007, 510000)
base = n - k + 1

for i in range(k):
    if i == 0:
        print(base)
    else:
        print(com.calc(n - k + 1, n - k - i) * com.calc(k - 1, i) % 1000000007)


Measured memory_bytes: 54640
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int a,b,h,m;
	double ans=0.0;
	cin >>a>>b>>h>>m;
	double angle=0.0;
	angle=(double)m/30;
	clog<<angle<<endl;
	angle=abs(angle-(angle/12+(double)h/6));
	clog<<angle<<endl;
	angle*=PI;
	ans=sqrt(a*a+b*b-2*a*b*cos(angle));
	printf("%.10lf\n",ans);
}

Measured memory_bytes: 4292
#ifdef HIRO
#include "../stdc++.h"
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#include <bits/stdc++.h>
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;

int main() {
#ifdef HIRO
  string file_path(QUIZ);
  ifstream cin(file_path + "/input.txt");
  std::cin.rdbuf(cin.rdbuf());
#endif
  // int n;
  // int m;
  // cin >> n;
  // cin >> m;
  string s;
  cin >> s;
  int a, b;
  a = stoi(s.substr(0, 2));
  b = stoi(s.substr(2, 2));
  bool aok = a >= 1 && a <= 12;
  bool bok = b >= 1 && b <= 12;
  if(aok && bok)
    cout << "AMBIGUOUS" << endl;
  else if(!aok && bok)
    cout << "YYMM" << endl;
  else if(aok && !bok)
    cout << "MMYY" << endl;
  else if(!aok && !bok)
    cout << "NA" << endl;

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



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// ----------------------R00TDADA------------------------------
#define rep(i, a, b) for (__typeof((b)) i = (a); i < (b); i++)
#define nrep(i, a, b) for (__typeof((b)) i = (a); i > (b); i--)
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define ppi pair<int, int>
#define pppi pair<ppi, int>
#define vi vector<int>
#define vii vector<ppi>
#define viii vector<pppi>
#define vs vector<string>
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define M_PI 3.14159265358979323846
#define rootdada ios_base::sync_with_stdio(false)
#define int long long
#define M 1000000007
#define MAX 100005

signed main()
{

    rootdada;
    int n;
    cin >> n;
    int c = 0;
    rep(i, 1, n / 2 + 1)
    {
        if (i != n - i)
            c++;
    }
    cout << c << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int a[3];
    for(int i = 0; i < 3; i++)
        scanf("%d",&a[i]);
    int sum = a[0] + a[1] + a[2];
    if(sum >= 22)
        puts("bust");
    else 
        puts("win");
    return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#define INF  100000000
using namespace std;
int field[101][101];
void dijik(int s,int g);
int n;
int main(void){
   int k;
   while(scanf("%d%d",&n,&k),n+k){
      memset(field,0,sizeof(field));
      for(int i = 1;i <= n;i++){
         for(int j = 1;j <= n;j++){
            if(i == j) continue;
            field[i][j] = INF;
         }
      }

      for(int i = 0;i < k;i++){
         int f; scanf("%d",&f);
         if(f == 0){
            int a,b;scanf("%d%d",&a,&b);
            dijik(a,b);
         }
         else{
            int c,d,e; scanf("%d%d%d",&c,&d,&e);
            field[c][d] = min(field[c][d],e);
            field[d][c] = min(field[d][c],e);
         }
      }
   }
   return 0;
}

void dijik(int s,int g){
   int cost[101]; for(int i = 1;i <= n;i++) cost[i] = INF;
   int flag[101] = {0};
   cost[s] = 0;
   while(1){
      int idx = -1;
      for(int i = 1;i <=n;i++){
         if(flag[i] == 0 && (idx == -1 || cost[idx] > cost[i])){
            idx = i;
         }
      }
      if(idx == -1){
            break;
      }
      flag[idx] = 1;
      if(idx == g){
         if(cost[idx] == INF){
               printf("-1\n");
         }

         else{
            printf("%d\n",cost[idx]);
         }
         return;
      }

      for(int i = 1;i <= n;i++){
         cost[i] = min(cost[i],cost[idx]+field[idx][i]);
      }
   }
   return;
}

Measured memory_bytes: 1244
#include <iostream>
#include <bits/stdc++.h>
#define loop(N) for(int i=0;i<N;i++)
#define vi vector<int>
#define vs vector<string>
#define vl vector<long long int>
#define vpi vector<pair<int,int>>
#define msi map<string,int>
#define mil map<int,long long int>
#define lli long long int
#define plli pair<lli,lli>
using namespace std ;
void ps(string i){
    cout << i << endl;
}

template <class T>
void pt(T s){
    cout << s << endl;
}

void pi(int i){
    cout << i << endl;
}

template <class T>
void pv(vector<T> v){
    loop(v.size()){
        pt<T>(v[i]);
    }
}
/*********************************reused****************************/

int main()
{
    string s1,s2;
    cin >> s1 >>s2;
    if(s1[0]==s2[2] && s1[1]==s2[1] && s1[2]==s2[0])
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
    return 0;
}



Measured memory_bytes: 256
// abc066_a
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int A, B, C;
    cin >> A >> B >> C;

    vector<int> v{A, B, C};
    int x = *max_element(ALL(v));
    int sm = accumulate(ALL(v), 0);

    print(sm - x);


    return 0;
}


Measured memory_bytes: 256
H,W,D=map(int,input().split())
position=[None]*(H*W+1)
for i in range(H):
  A=list(map(int,input().split()))
  for j in range(len(A)):
    position[A[j]]=[i,j]

dp=[0]*(H*W+1)

for i in range(1,len(dp)):
  if i+D>=len(dp):
    continue
  dp[i]=abs(position[i+D][0]-position[i][0])+abs(position[i+D][1]-position[i][1])

dpsum=[0]*(H*W+1)

for i in range(1,len(dp)):
  if i-D>=0:
    dpsum[i]=dpsum[i-D]+dp[i]
  else:
    dpsum[i]=dp[i]

Q=int(input())
for i in range(Q):
  L,R=map(int,input().split())
  if L==R:
    print(0)
  elif L-D>0:
    print(dpsum[R-D]-dpsum[L-D])
  else:
    print(dpsum[R-D])


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

num4 = 0
num2 = 0
num1 = 0
for i in A:
    if i % 4 == 0:
        num4 += 1
    elif i % 2 == 0:
        num2 += 1
    else:
        num1 += 1

if (num2 != 0) & (num4 >= num1):
    print('Yes')
elif (num2 == 0) & (num4 + 1 >= num1):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 62704
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
#define pb push_back

void solve(){
    double w, h, x, y;
    cin >> w >> h >> x >> y;
    if(x == w/2.0 && y == h/2.0){
        printf("%.10f 1\n", w*h/2.0); 
    }
    else{
        printf("%.10f 0\n", w*h/2.0); 
    }
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  int n;
  cin>>n;
  ll x=1;
  ll y=1;
  rep(i,0,n){
    int t,a;
    cin>>t>>a;
    ll b,c;
    b=(t+x-1)/t*t;
    c=(a+y-1)/a*a;
    if(b/t*a>=c){
      x=b;
      y=b/t*a;
    }
    else{
      x=c/a*t;
      y=c;
    }
  }
  cout<<x+y<<endl;
}


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

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

using namespace std;

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

  int absmax_i=0;
  rep(i,n) if( abs(a[i]) > abs(a[absmax_i]) )absmax_i=i;

  cout<<2*n-1<<endl;
  rep(i,n)cout<<absmax_i+1<<' '<<i+1<<endl;
  if(a[absmax_i]>0){
    rep(i,n-1)cout<<i+1<<' '<<i+2<<endl;
  }else{
    rep(i,n-1)cout<<n-i<<' '<<n-(i+1)<<endl;
  }

//rep(i,n)cout<<a[i]<<' ';cout<<endl;

  return 0;
}

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

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

using namespace std;

int main(){
  double a,b,x;cin>>a>>b>>x;

  double theta;
  if(x>a*a*b*0.5){
    theta=atan(2*(a*a*b-x)/(a*a*a));
  }else{
    theta=atan(a*b*b/(2*x));
  }

//  cout<<theta<<endl;
  cout<<fixed<<setprecision(10)<<theta/(M_PI/180.0);

  return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


fn main() {
    let n = read::<usize>();
    let l = read::<i64>();
    let mut ans = 0;
    let mut m:i64 = 10000;
    for i in 0..n {
        ans += l+i as i64;
        if m.abs() > (l+i as i64).abs() {
            m = l+i as i64;
        }
    }
    println!("{}", ans-m);
}


Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int main() {
	int n, m,t1,t2;
	cin >> n >> m;
	int* h = new int[n];
	bool* is_good = new bool[n];
	for (int i = 0;i < n;i++) {
		cin >> h[i];
		is_good[i] = true;
	}
	for (int i = 0;i < m;i++) {
		cin >> t1 >> t2;
		if (h[t1 - 1] == h[t2-1]) {
			is_good[t1 - 1] = is_good[t2 - 1] = false;
		}
		else if (h[t1-1] > h[t2-1]) {
			is_good[t2-1] = false;
		}
		else {
			is_good[t1-1] = false;
		}
	}
	int cnt = 0;
	for (int i = 0;i < n;i++) {
		if (is_good[i])cnt++;
	}
	cout << cnt << endl;
}


Measured memory_bytes: 3680
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}
void OUT(bool b){cout<<(b?"YES":"NO")<<endl;}
void Out(bool b){cout<<(b?"Yes":"No")<<endl;}
void out(bool b){cout<<(b?"yes":"no")<<endl;}
template<class T>
void puta(T&&t){cout<<t<<endl;}
template<class H,class...T>
void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}

int popcnt(int x){return __builtin_popcount(x);}
int popcnt(ll x){return __builtin_popcountll(x);}
int bsr(int x){return 31 - __builtin_clz(x);}
int bsr(ll x){return 63 - __builtin_clzll(x);}
int bsf(int x){return __builtin_ctz(x);}
int bsf(ll x){return __builtin_ctzll(x);}

/*他のライブラリを入れる場所*/

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vl a(n);
	rep(i,n)cin>>a[i];
	vl dp(n,INF);
	dp[0]=0;
	rep(i,n){
		if(i+2<n)dp[i+2]=min(dp[i+2],dp[i]+abs(a[i]-a[i+2]));
		if(i+1<n)dp[i+1]=min(dp[i+1],dp[i]+abs(a[i]-a[i+1]));
	}	
	cout<<dp[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<utility>
#include<functional>
#include<cfenv>
#include<cmath>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<set>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define vint vector<int>
#define vvint vector<vint>
#define P pair<ll,ll>
#define INT_MAX 2147483647
#define MOD 998244353
#define PI 3.14159265358979323846
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;

#define MAX 1000000000000

int main(void) {
	int x; cin >>x;


	if (x >= 30) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define pi 3.1415926535897932384626
using namespace std;
      
struct P{
  int x,y;
  bool operator < (const P &a )const{
    //if(y!=a.y)
    return y>a.y;
  };
};

int a,b,c,d,i,k,n,m,e,dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1};
int o[1];
int l[1];
int j[1];

long long x,y,z,mod=1000000007;
string r;
//char r[111];

P u[1];
queue<int> q;

stack<int> s;
map<int,int> p;
vector<int> v;

bool as(P a,P b)
{
  if(a.x==b.x)
  return a.y<b.y;
  return a.x<b.x;
}

int main()
{
  scanf("%d %d",&a,&b);
  if(a<10) b+=100*(10-a);
  printf("%d",b);
}





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

#define ll long long

const int mxN=131071;
int n, lb, rb=1e7;
vector<array<int, 2>> c[mxN];
vector<array<ll, 2>> dp[mxN];

void dfs(int x, int u=0) {
	if(!c[u].size()) {
		dp[u]={{0, 0}};
		return;
	}
	dfs(x, c[u][0][0]);
	dfs(x, c[u][1][0]);
	if(dp[c[u][0][0]].size()>dp[c[u][1][0]].size())
		swap(c[u][0], c[u][1]);
	vector<array<ll, 2>> v1, v2;
	for(array<ll, 2> a : dp[c[u][0][0]]) {
		int p=lower_bound(dp[c[u][1][0]].begin(), dp[c[u][1][0]].end(), array<ll, 2>{x-a[1]-c[u][0][1]-c[u][1][1]+1})-dp[c[u][1][0]].begin()-1;
		if(~p) {
			v1.push_back({a[0]+c[u][0][1], dp[c[u][1][0]][p][1]+c[u][1][1]});
			if(!v2.size()||v2.back()[0]>dp[c[u][1][0]][p][1]+c[u][1][1])
				v2.push_back({dp[c[u][1][0]][p][1]+c[u][1][1], a[0]+c[u][0][1]});
		}
	}
	dp[u].clear();
	for(int i=0, j=v2.size(); i<v1.size()||j; ) {
		array<ll, 2> a;
		if(!j||(i<v1.size()&&v1[i]<v2[j-1]))
			a=v1[i++];
		else
			a=v2[--j];
		if(!dp[u].size()||dp[u].back()[1]>a[1])
			dp[u].push_back(a);
	}
}

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

	cin >> n;
	for(int i=1, a, v; i<n; ++i) {
		cin >> a >> v, --a;
		c[a].push_back({i, v});
	}
	while(lb<rb) {
		int mb=(lb+rb)/2;
		dfs(mb);
		if(dp[0].size())
			rb=mb;
		else
			lb=mb+1;
	}
	cout << lb;
}

Measured memory_bytes: 31904
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define pq priority_queue
#define ll long long
#define MOD 1000000007
#define INF 2000000000
using namespace std;

ll n, ans, A[101];
double add, m = INF;
int main() {
	cin >> n;
	rep(i, n) {
		cin >> A[i];
		add += A[i];
	}
	add /= n;
	rep(i, n) {
		if (abs(A[i] - add) < m) {
			ans = i;
			m = abs(A[i] - add);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
const long long INF = 1e9;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
//char c;
 
#define Endl endl
 
/*--------------------template--------------------*/

int main() {
    string s,t;
    cin>>s>>t;
    s+=s;
    if(s.find(t)!=string::npos)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


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

using namespace std;

using ll = long long;

const int MAX_V = 10000;
const ll INF = 1e13;

struct Edge {
    int to;
    ll cap;
    int rev;  //行き先、容量、逆辺
    Edge(int to, ll cap, int rev) : to(to), cap(cap), rev(rev) {}
};

vector<Edge> G[MAX_V];
int level[MAX_V];
int iter[MAX_V];

void add_edge(int from, int to, ll cap) {
    G[from].push_back(Edge(to, cap, G[to].size()));
    G[to].push_back(Edge(from, 0, G[from].size() - 1));
}

void bfs(int s) {
    memset(level, -1, sizeof(level));
    queue<int> que;
    level[s] = 0;
    que.push(s);
    while (!que.empty()) {
        int v = que.front();
        que.pop();
        for (int i = 0; i < G[v].size(); i++) {
            Edge& e = G[v][i];
            if (e.cap > 0 && level[e.to] < 0) {
                level[e.to] = level[v] + 1;
                que.push(e.to);
            }
        }
    }
}

ll dfs(int v, int t, ll f) {
    if (v == t) return f;
    for (int& i = iter[v]; i < G[v].size(); i++) {
        Edge& e = G[v][i];
        if (e.cap > 0 && level[v] < level[e.to]) {
            ll d = dfs(e.to, t, min(f, e.cap));
            if (d > 0) {
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

ll max_flow(int s, int t) {
    ll flow = 0;
    while (true) {
        bfs(s);
        if (level[t] < 0) return flow;
        memset(iter, 0, sizeof(iter));
        ll f;
        while ((f = dfs(s, t, INF)) > 0) {
            flow += f;
        }
    }
}

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

    ll ans = 0;
    for (int i = 0; i < n; i++) {
        ll a;
        cin >> a;
        if (a >= 0) {
            ans += a;
            add_edge(0, i + 1, a);
        } else {
            add_edge(i + 1, n + 1, -a);
        }
    }

    for (int i = 1; i <= n; i++) {
        for (int j = i * 2; j <= n; j += i) {
            add_edge(j, i, INF);
        }
    }
    
    ans -= max_flow(0, n + 1);
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;
typedef long long ll;
const ll INF=100000000000000LL;
ll a[100001];

ll r[2]={};
int main() {
	int sx,sy,tx,ty;
	cin>>sx>>sy>>tx>>ty;
	for(int i=0;i<tx-sx;++i)cout<<"R";
	for(int i=0;i<ty-sy;++i)cout<<"U";
	for(int i=0;i<tx-sx;++i)cout<<"L";
	for(int i=0;i<ty-sy+1;++i)cout<<"D";
	for(int i=0;i<tx-sx+1;++i)cout<<"R";
	for(int i=0;i<ty-sy+1;++i)cout<<"U";
	cout<<"L";
	cout<<"U";
	for(int i=0;i<tx-sx+1;++i)cout<<"L";
	for(int i=0;i<ty-sy+1;++i)cout<<"D";
	cout<<"R"<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String input;
        String[] datum;
        int distance, angular = 0;
        double x = 0, y= 0;
        double rad = 0.0;
        
        while(sc.hasNextLine()){
            input = sc.nextLine();
            datum = input.split(",");
            
            if(Integer.parseInt(datum[0]) == 0 && Integer.parseInt(datum[1]) == 0){
                System.out.println((int)x);
                System.out.println((int)y);
                return;
            }
            
            distance = Integer.parseInt(datum[0]);

            rad += Math.PI * angular / 180;
            x += distance * Math.sin(rad);
            y += distance * Math.cos(rad);
            
            angular = Integer.parseInt(datum[1]);
        }
    }
}



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

using namespace std;

int main() {
  int n;
  cin >> n;
  int a[3 * n];
  for (int i = 0; i < 3 * n; i++) {
    cin >> a[i];
  }
  sort(a, a + 3 * n);
  long long int ans = 0;
  for (int i = 0, j = 3 * n - 2; i < n; i++, j -= 2) {
    ans += a[j];
  }
  cout << ans << endl;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ans;
ll f(ll a, ll k)
{
	if(a < k) return 0;
	if(a % k == 0) return a / k;
	else 
	{
		ll d = a / k;
		ll step = (a - d * k + d) / (d + 1);
		return f(a - step * (d + 1), k);
	}
}
int main()
{
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
	{
		ll a, k;
		scanf("%lld%lld", &a, &k);
		ans ^= f(a, k);
	}
	if(!ans)
		puts("Aoki");
	else
		puts("Takahashi");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
 
int main() {
  long long N,ans=0;
	cin>>N;
	vector<long long> L(N);
	rep(i,N)cin>>L[i];
	sort(L.begin(),L.end());
	for(int i=0;i<N-2;++i){
		for(int j=i+1;j<N-1;++j){
			for(int k=j+1;k<N;++k){
				if (L[k]<L[i]+L[j]) ++ans;
			}
		}
	}
	cout<<ans<<"\n";
}

Measured memory_bytes: 3628
#include <stdio.h>

int main (void)
{
  int i, n, array[4];

  scanf("%d", &n);
  for (i = 0; i < 4; i++) {
    array[i] = n % 10;
    n = n / 10;
  }

  if ((array[0] == array[1] && array[1] == array[2]) || (array[1] == array[2] && array[2] == array[3])) {
    printf("Yes");
  } else {
    printf("No");
  }

  return 0;
}

Measured memory_bytes: 128
h,w = map(int,input().split())
a = []
for i in range(h):
    a.append(list(map(int,input().split())))
chk = []
for i in range(h):
    if i % 2 == 0:
        tmp = [(i,j) for j in range(w)]
    else:
        tmp = [(i,w-j-1) for j in range(w)]
    chk += tmp
log = []
for i in range(len(chk)-1):
    c = chk[i]
    nc = chk[i+1]
    if a[c[0]][c[1]] % 2 == 1:
        a[c[0]][c[1]] -= 1
        a[nc[0]][nc[1]] += 1
        log.append(" ".join(map(str,[c[0]+1,c[1]+1,nc[0]+1,nc[1]+1])))
print(len(log))
for l in log:
    print(l)

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

const int N = 100005;
const long long INF = (long long)1e15;

long long f[N][3];
char op[N][2];

int n,a[N];

int main()
{
	scanf("%d",&n);
	for (int i = 1; i < n; i++)
	{
		scanf("%d%s",&a[i],op[i]);
	}
	scanf("%d",&a[n]);
	f[1][0] = a[1], f[1][1] = f[1][2] = -INF;
	for (int i = 2; i <= n; i++)
	{
		if (op[i - 1][0] == '+')
		{
			f[i][0] = std::max(f[i - 1][0], f[i - 1][1]) + a[i];
			f[i][1] = f[i - 1][1] - a[i];
			f[i][2] = f[i - 1][2] + a[i];
		}
		if (op[i - 1][0] == '-')
		{
			f[i][0] = -INF;
			f[i][1] = std::max(f[i - 1][0], f[i - 1][1]) - a[i];
			f[i][2] = std::max(f[i - 1][1], f[i - 1][2]) + a[i];
		}
	}
	printf("%lld\n",std::max(std::max(f[n][0], f[n][1]), f[n][2]));
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1LL << 60;

template <typename T>
void print(const T &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
}

ll cpow(ll num, int n)
{
    ll ret = 1;
    for (int i = 0; i < n; i++)
    {
        ret *= num;
    }
    return ret;
}

const int DIGIT_MAX = 40;
int main()
{
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    bitset<DIGIT_MAX> kbit(k);
    vector<ll> bitcnt(DIGIT_MAX, 0);
    for (int i = 0; i < n; i++)
    {
        bitset<DIGIT_MAX> tmp(a[i]);
        for (int j = 0; j < DIGIT_MAX; j++)
        {
            if (tmp.test(j))
            {
                ++bitcnt[j];
            }
        }
    }
    bool fit_flag = true;
    ll ans = 0;
    for (int i = DIGIT_MAX - 1; i >= 0; i--)
    {
        if (fit_flag && !kbit.test(i))
        {
            ans += bitcnt[i] * cpow(2LL, i);
            continue;
        }
        if (bitcnt[i] >= (n + 1) / 2)
        {
            ans += bitcnt[i] * cpow(2LL, i);
            fit_flag = false;
        }
        else
        {
            ans += (n - bitcnt[i]) * cpow(2LL, i);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4016
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		// スペース区切りの整数の入力
		int b = sc.nextInt();
		int x = sc.nextInt();

		String r = "";
		if ((a + b) < x || x < a) {
			r = "NO";
		} else {
			r = "YES";
		}

		// 出力
		System.out.println(r);
	}
}

Measured memory_bytes: 22996
x=int(input())
p=[True]*(2*x)
p[0]=False
p[1]=False
for i in range(2,x):
    if p[i]:
        for j in range(2*i,2*x,i):
            p[j]=False
ans=x
while p[ans]==False:
    ans+=1
print(ans)

Measured memory_bytes: 10440
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

    static long[][] dp;

    public static void main(String[] args) throws Exception{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        String[] s=br.readLine().split(" ");
        int n=Integer.parseInt(s[0].trim());
        int w=Integer.parseInt(s[1].trim());
        Pair[] pairs=new Pair[n];
        for(int i=0;i<n;i++){
            s=br.readLine().split(" ");
            int wt=Integer.parseInt(s[0].trim());
            long v=Long.parseLong(s[1].trim());
            pairs[i]=new Pair(wt,v);
        }
        dp=new long[n][w+1];
        for(int i=0;i<n;i++) {
            Arrays.fill(dp[i], -1);
        }
        System.out.println(knap(pairs,n-1,w));



    }
    public static long algo(Pair[] pairs,int n,int w){

        long[][] dp=new long[n+1][w+1];
        for(int i=1;i<=n;i++){
            for(int j=1;j<=w;j++){
                long max=0;
                if(j-pairs[i-1].w>=0){
                    max=dp[i-1][j-pairs[i-1].w];
                }
                max=Math.max(max,dp[i-1][j]);
                dp[i][j]=max;
            }
        }
        return dp[n][w];



    }



    public static long knap(Pair[] pairs,int n,int w){
        if(n<0){
            return 0;
        }
        if(dp[n][w]!=-1){
//            System.out.println("used");
            return dp[n][w];
        }


        if(w==0){
            dp[n][w]=0;
            return 0;
        }
        long max=0l;
//        System.out.println(n);
        if(w-pairs[n].w>=0){
                max=pairs[n].v+knap(pairs,n-1,w-pairs[n].w);
        }
         max=Math.max(max,knap(pairs,n-1,w));
        dp[n][w]=max;
        return max;
    }




}


class Pair{
    long v;
    int w;;
    Pair(int w,long v){
        this.v=v;
        this.w=w;
    }

}

Measured memory_bytes: 138944
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<map>
#include<queue>
#include<string>
#include<sstream>
using namespace std;
int inf = 1e9;
int main(){

  int h, w;
  cin >> h >> w;
  vector<string> a(h);
  for(int i=0; i<h; i++) cin >> a[i];

  cout << string(w+2, '#') << endl;
  for(int i=0; i<h; i++){
    cout << "#" << a[i] << "#" << endl;
  }
  cout << string(w+2, '#') << endl;

  return 0;
}


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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

void solve() {
  int n, vT, vA;
  cin >> n >> vT >> vA;
  vT--, vA--;
  vvi to(n);
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  vi dA(n, INF);
  deque<P> q;
  vector<int> used(n);
  q.push_back(P(vA, 0));
  while (!q.empty()) {
    int u, d;
    tie(u, d) = q.front();
    q.pop_front();
    if (used[u]) continue;
    used[u] = 1;
    dA[u] = d;
    for (auto& v : to[u]) {
      q.push_back(P(v, d + 1));
    }
  }
  dump(dA);
  vi dT(n, INF);
  used.clear();
  used.resize(n, 0);
  dump(used);
  q.push_back(P(vT, 0));
  while (!q.empty()) {
    int u, d;
    tie(u, d) = q.front();
    q.pop_front();
    if (used[u]) continue;
    used[u] = 1;
    dT[u] = d;
    dump(u, d);
    if (dA[u] <= d) continue;
    for (auto& v : to[u]) {
      q.push_back(P(v, d + 1));
    }
  }
  dump(dT);
  // int mx = 0;
  // rep(i, n) maxs(mx, dT[i]);
  // int ans = 0;
  // rep(i, n) {
  //   if (dT[i] == mx) maxs(ans, dA[i] - 1);
  // }
  int ans = 0;
  rep(i, n) {
    if (dT[i] < dA[i]) maxs(ans, dA[i] - 1);
  }
  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){if((ll)(a)==inf)cout<<"inf"<<'\n';else if((ll)(a)==-inf)cout<<"-inf"<<'\n';else cout<<a<<'\n';}
template<class T> void outs(T a){if((ll)(a)>=inf-100||(ll)(a)<=-inf+100)cout<<"-1"<<'\n';else cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';if((ll)(v[i])==inf)cout<<"inf";else if((ll)(v[i])==-inf)cout<<"-inf";else cout<<(ll)(v[i]);}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}
vvi wf(ll n,vvp g){
    vvi dis(n,vi(n,inf));
    rep(i,n)dis[i][i]=0;
    rep(i,n)for(auto x:g[i])chmin(dis[i][x.fi],x.se);
    rep(k,n)rep(i,n)rep(j,n)chmin(dis[i][j],dis[i][k]+dis[k][j]);
    return dis;
}
int main(){
    ll n,m,l;cin>>n>>m>>l;
    vvp g(n);
    rep(i,m){
        ll a,b,c;cin>>a>>b>>c;
        a--;b--;
        g[a].eb(b,c);
        g[b].eb(a,c);
    }
    vvi dis=wf(n,g);
    vvp g2(n);
    rep(i,n)rep(j,n)if(dis[i][j]<=l)g2[i].eb(j,1);
    vvi dis2=wf(n,g2);
    ll q;cin>>q;
    rep(tt,q){
        ll s,t;cin>>s>>t;s--;t--;
        outs(dis2[s][t]-1);
    }
}

Measured memory_bytes: 8064
dataset = []
while True:
    n, x = map(int, input().split())
    if n == 0 and x == 0:
        break
 
    dataset.append([n,x])

for data in dataset:
    count = 0
    n, x = data[0], data[1]

    for i in range(1, n):
        for j in range(i+1, n):
            k = x - (j + i)
            if k > j and k <= n:
                count += 1

    print(count)


Measured memory_bytes: 5600
#include<stdio.h>
int Q,c,a,n;
int ans;
int i,j;

int main(){
  scanf("%d",&Q);
  for(i=0;i<Q;i++){
    ans=0;
    scanf("%d %d %d",&c,&a,&n);
    while(c>0&&a>0&&n>0){
      ans++;
      c--;
      a--;
      n--;
    }

    while(c>=2&&a>=1){
      ans++;
      c-=2;
      a--;
    }
    ans+=(c/3);
    printf("%d\n",ans);
  }
  return 0;
}

Measured memory_bytes: 1028