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

public class Main {
    private static final Scanner scn = new Scanner(System.in);
    private static final List<IntegralRectangle> RECTANGLES;
    private static final int MAX = 150;

    static {
        RECTANGLES = new ArrayList<>();
        Main main = new Main();
        for(int y = 1; y < MAX; y++) {
            for(int x = -~y; x < -~MAX; x++) {
                RECTANGLES.add(main.new IntegralRectangle(y, x));
            }
        }
        Collections.sort(RECTANGLES);
    }

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        int height;
        int width;
        while((height = scn.nextInt()) > 0 | (width = scn.nextInt()) > 0) {
            IntegralRectangle base = new IntegralRectangle(height, width);
            for(IntegralRectangle rectangle : RECTANGLES) {
                if(base.compareTo(rectangle) < 0) {
                    System.out.println(rectangle);
                    break;
                }
            }
        }
    }

    class IntegralRectangle implements Comparable<IntegralRectangle> {
        private int height;
        private int width;

        public IntegralRectangle(int height, int width) {
            this.height = height;
            this.width  = width;
        }

        private int squareDiagonal() {
            return height * height + width * width;
        }

        @Override
        public int compareTo(IntegralRectangle another) {
            if(this.squareDiagonal() > another.squareDiagonal()) {
                return 1;
            } else if(this.squareDiagonal() < another.squareDiagonal()) {
                return -1;
            } else {
                if(this.height != another.height) {
                    return this.height > another.height ? 1 : -1;
                } else {
                    return 0;
                }
            }
        }

        @Override
        public String toString() {
            return height + " " + width;
        }
    }
}

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

using namespace std;



int main()
{

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


   unsigned long long int sum = 0;


                for (auto it = mp.begin(); it!=mp.end(); it++)
                    sum +=   it->second * (it->second-1)/2;

//cout << sum;

    for (int i=0; i<n; i++)
        {
            cout << sum  - mp[a[i]] +1 << "\n";



        }







}


Measured memory_bytes: 10240
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

int main(){
  ll a,v;
  cin>>a>>v;
  ll b,w;
  cin>>b>>w;
  ll t;
  cin>>t;
  ll d = abs(a-b);
  if(d+w*t<=v*t){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main{

	static final Scanner	s	=new Scanner(System.in);

	public static void main(String args[]){
		input();
		solve();
	}

	private static void input(){
	}

	private static void solve(){
		String in=s.next();
		int a=114514,z=-114514;
		for(int i=0;i<in.length();i++) {
			if(in.charAt(i)=='A')
				a=Math.min(a,i);
			if(in.charAt(i)=='Z')
				z=Math.max(z,i);
		}
		System.out.println(z-a+1);
	}
}


Measured memory_bytes: 28356
while true
  n = gets.chomp.to_i
  break if n == 0

  mat = []
  vsum = (0..n).map{0}

  n.times do
    cs = gets.chomp.split(" ").map{|s| s.to_i}

    hsum = cs.inject{|sum, c|  sum + c}
    cs.push hsum
    mat.push cs

    (0..n).each{|i| vsum[i] += cs[i]}
  end
  mat.push vsum

  mat.each do |hl|
    hl.each{|c| printf("%5d", c)}
    puts
  end
end

Measured memory_bytes: 6136
# -*- coding: utf-8 -*-

n, x = map(int, input().split())
variants = [int(input()) for i in range(n)]

variants.sort()
# print(variants)

doughnuts = 0
for v in variants:
    if x >= v:
        x -= v
        doughnuts += 1

doughnuts += x // variants[0]
print(doughnuts)
        

Measured memory_bytes: 2940
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline int read()
{
	int f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
const int MAXN=405;
int n,H;
int rt[MAXN],in[MAXN],ot[MAXN],ok[MAXN],vis[MAXN];
int findrt(int x){return rt[x]==x?rt[x]:rt[x]=findrt(rt[x]);}
int main()
{
	n=read();H=read();
	for(int i=1;i<=2*H;i++)rt[i]=i;
	for(int i=1;i<=n;i++)
	{
		int a=read(),b=read(),c=read(),d=read();
		int l,r;
		if(!c)l=a;else l=-c;
		if(!d)r=-b;else r=d;
		l+=H;r+=H;
		int p=findrt(l),q=findrt(r);
		if(p!=q)rt[p]=q;
		++ot[l];++in[r];vis[l]=vis[r]=1;
	}
	for(int i=-H;i<0;i++)if(in[i+H]<ot[i+H])return puts("NO"),0;
	for(int i=1;i<=H;i++)if(in[i+H]>ot[i+H])return puts("NO"),0;
	for(int i=-H;i<0;i++)ok[findrt(i+H)]|=in[i+H]!=ot[i+H];
	for(int i=1;i<=H;i++)ok[findrt(i+H)]|=in[i+H]!=ot[i+H];
	for(int i=1;i<=2*H;i++)if(vis[i]&&!ok[findrt(i)])return puts("NO"),0;
	puts("YES");
	return 0;
}


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

int main(){
	int n;
	long long sum=1,sj=1;
	cin>>n;
	int a[n+1];
	for(int i=1;i<=n;i++){
		cin>>a[i];
		sum*=3;
		if(a[i]%2==0){
			sj*=2;
		}
	}
	cout<<sum-sj;
	return 0;
}

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

int main()
{
    ll n;
    cin >> n;

    if(n%2)
    {
        cout << 0 << endl;
        return 0;
    }
    ll ans = 0;
    n /= 2;

    while(n>=5)
    {
        ans += n/5;
        n /= 5;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
<?php
  declare(strict_types=1);

  $mod = (int)pow(10, 9) + 7;

  fscanf(STDIN, "%i", $n);

  $power = 1;
  for ($i = 1; $i <= $n; ++$i)
  {
      $power *= $i;
      $power %= $mod;
  }

  echo $power,PHP_EOL;


Measured memory_bytes: 4856
# https://atcoder.jp/contests/m-solutions2019/submissions/5741430
from functools import reduce
from operator import mul
import sys

input = sys.stdin.readline

MOD = 10 ** 6 + 3


def inv(n):
    return pow(n, MOD - 2, MOD)


def mod_mul(x, y):
    return mul(x, y) % MOD


fact = [1]
for n in range(1, MOD):
    fact.append((fact[-1] * n) % MOD)
    # d>1 の数列を d=1 となる数列に変換する
    # MODの倍数を含む数列の積は0になるので,
    # MODの倍数を含まない区間の積が計算できればよい
    # そのような区間の右端はMOD-1であり,fact[MOD-1]が計算できればよい

Q = int(input())
for _ in range(Q):
    x, d, n = map(int, input().split())

    if x == 0:
        print(0)
        continue

    if d == 0:
        print(pow(x, n, MOD))
        continue

    xd = (x * inv(d)) % MOD
    if MOD - xd < n:
        print(0)
        continue

    dn = pow(d, n, MOD)
    print(reduce(mod_mul, (fact[xd + n - 1], inv(fact[xd - 1]), dn)))


Measured memory_bytes: 93804
s = list(input())
count = 0

if s[0] == "A":
    for i in range(2,len(s)-1):
        if s[i] == "C":
            count += 1
    if count != 1:
        print("WA")
        exit()
    else:
        number = s.index("C")
else:
    print("WA")
    exit()

del s[number]
del s[0]

for j in s:
    c = j.lower()
    if c == j:
        continue
    else:
        print("WA")
        exit()
print("AC")


Measured memory_bytes: 3064
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=100000;
const int MOD=1000000007;

int n;
int a[MAXN];
int cnt[MAXN];

int solve() {
	if(n%2==1&&cnt[0]!=1) return 0;
	int fst=n%2==0?1:2,deg=n/2;
	REP(i,deg) {
		//printf("\t%d\n",fst+2*i);
		if(cnt[fst+2*i]!=2) return 0;
	}
	int ret=1; REP(i,deg) ret=2*ret%MOD; return ret;
}

void run() {
	scanf("%d",&n); REP(i,n) scanf("%d",&a[i]);
	memset(cnt,0,sizeof(cnt)); REP(i,n) ++cnt[a[i]];
	printf("%d\n",solve());
}

int main() {
	run();
	return 0;
}


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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, k;
  cin >> n >> k;
  vector<int> v(n);
  ll res = 0;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }

  map<ll, p> mp;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < i; j++) {
      if(v[i] > v[j]) mp[i].first++;
    }
    for (int j = i + 1; j < n; j++) {
      if(v[i] > v[j]) mp[i].second++;
    }
  }
  // ll a = 1000000001ll * 1000000000ll;
  // cout << a << endl;

  for(auto a : mp){
    ll tmp = (a.second.second % MOD) * ((((1ll + k) * k) / 2ll) % MOD);
    tmp %= MOD;
    res += tmp;
    res %= MOD;
    tmp = (a.second.first % MOD) * ((((-1ll + k) * k) / 2ll) % MOD);
    tmp %= MOD;
    res += tmp;
    res %= MOD;
  }


  cout << res << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <numeric> // accumulate(begin,end,初期値)
#include <string>
#include <cstdio>
#include <queue>
#include <stack>
#include <set>
#include <cmath>

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<x<<endl
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<#a<<':'<<a<<endl

const ll INF = 1e9+7;

// 各桁の和
template<typename T>inline T digit(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;}
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}


class tree{
public:
  tree* par;
  vector<tree*> chi;
  int cnt;
};

int cnt(int a,int b){
  int count = -1;
  while(a){
    a /= b;
    ++count;
  }
  return count;
}


int main() {
  cin.tie(0); ios::sync_with_stdio(0);
  int h,w;cin>>h>>w;
  vector<string> a(h);rep(i,h)cin>>a[i];
  rep(i,h){
    bool all_white = a[i].find("#") == string::npos;
    if(all_white){
      a.erase(a.begin()+i);
      --i;--h;
    }
  }


  rep(i,w){
    bool all_white = true;
    rep(j,h){
      all_white &= a[j][i] != '#';
    }
    if(all_white){
      rep(j,h){
        a[j].erase(a[j].begin()+i);
      }
      --i;--w;
    }
  }

  rep(i,h){
    print(a[i]);
  }
  return 0;
}

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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int N, D, X;
  cin >> N >> D >> X;
  vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  vector<int> choco(D + 1, 0);
  for (int i = 0; i < N; ++i) {
    for (int j = 0, d = j * A[i] + 1; d < D + 1; ++j, d = j * A[i]+ 1) {
      ++choco[d];
    }
  }
  int ans = accumulate(choco.begin(), choco.end(), 0) + X;
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
import sys
from collections import Counter

N = int(input())
V = list(map(int, sys.stdin.readline().rsplit()))

Ceven = Counter(V[::2])
Codd = Counter(V[1::2])

res = 0
even, odd = Ceven.most_common(2), Codd.most_common(2)
if even[0][0] != odd[0][0]:
    res = N - even[0][1] - odd[0][1]
else:
    if len(Ceven) == len(Codd) == 1:
        res = N // 2
    else:
        res = min(
            N - even[1][1] - odd[0][1],
            N - even[0][1] - odd[1][1]
        )
print(res)


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

int main (){
  int n; cin >>n;
  int AC=0,WA=0,TLE=0,RE=0;
  vector<string> s(n);
  rep(i,n){
    cin >> s[i];
    if(s[i]=="AC") AC++;
    else if(s[i]=="WA") WA++;
    else if(s[i]=="TLE") TLE++;
    else if(s[i]=="RE") RE++;
  }
  cout << "AC x " << AC << endl;
  cout << "WA x " << WA << endl;
  cout << "TLE x " << TLE << endl;
  cout << "RE x " << RE << endl;
  return 0;
}

Measured memory_bytes: 6424
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define lint long long
#define pii pair<int, int>
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i > (b); --i)
#define REP(i, n) FOR(i, 0, n)
#define SZ(v) ((int)v.size())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define FILLINF(a) memset(a, 0x3f, sizeof(a))
#define POW(n) (1LL << (n))
#define POPCNT(n) (__builtin_popcount(n))
#define IN(i, a, b) ((a) <= (i) && (i) <= (b))
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a > b) { a = b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a < b) { a = b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(begin(a), end(a)); }
template <typename T> inline void REV(T& a) { reverse(begin(a), end(a)); }
template <typename T> inline void UNI(T& a) { sort(a.begin(), a.end()); a.erase(unique(a.begin(), a.end()), a.end()); }
template <typename S, typename T> inline T LB(S& v, T a) { return *lower_bound(begin(v), end(v), a); }
template <typename S, typename T> inline int LBP(S& v, T a) { return lower_bound(begin(v), end(v), a) - begin(v); }
template <typename S, typename T> inline T UB(S& v, T a) { return *upper_bound(begin(v), end(v), a); }
template <typename S, typename T> inline int UBP(S& v, T a) { return upper_bound(begin(v), end(v), a) - begin(v); }
template <typename S, typename T> ostream& operator << (ostream& os, const pair<S, T>& p) { os << p.first << " " << p.second; return os; }
template <typename S, typename T> istream& operator >> (istream& is, pair<S, T>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator << (ostream& os, const vector<T>& v) { for (int i = 0; i < v.size(); ++i) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator >> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e, v); }
const lint MOD = 1000000007;
const lint INF = 0x3f3f3f3f3f3f3f3f;
const double PI = 3.14159265358979323846;
const double EPS = 1e-10;



void _main() {
    string S, T;
    cin >> S >> T;
    cout << T << S << endl;
}

signed main(signed argc, char **argv) {
    if (argc > 1) {
        if (strchr(argv[1], 'i')) freopen("input.txt", "r", stdin);
        if (strchr(argv[1], 'o')) freopen("output.txt", "w", stdout);
    }
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
  ll n,k;
  cin >>n>>k;
  ll s[k];
  for(ll i=0;i<k;i++) s[i]=0;
  for(ll i=1;i<=n;i++) s[i%k]++;
  ll ans=0;
  for(ll a=0;a<k;a++){
    ll b=(k-a)%k;ll c=b;
    if((b+c)%k==0) ans+=(s[b]*s[c]*s[a]);
  }
  cout <<ans<<endl;
}


Measured memory_bytes: 1792
from fractions import gcd 

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

N = int(input())
T = [0]*N
for i in range(N):
    T[i] = int(input())

num = T[0]    
    
for i in range(1, N):
    num = lcm(num, T[i])
print(num)

Measured memory_bytes: 5048
macro_rules! get {
    (Vec<$t:ty>) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let (N, D) = get!(usize, usize);
    let mut X = Vec::new();
    for _ in 0..N {
        X.push(get!(Vec<i32>));
    }

    let mut ans = 0;
    for i in (0..(N - 1)) {
        for j in ((i + 1)..N) {
            let s = X[i].iter().zip(X[j].iter())
                .map(|(y, z)| (y - z).pow(2))
                .sum::<i32>();
            ans += match (1..1000).find(|r| r * r == s) {
                Some(_) => 1,
                _ => 0
            }
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
#!/usr/bin/perl
my ($n) = map { $_ - 0 } split(/\s+/,<STDIN>);
my ($t,$a) = map { $_ - 0 } split(/\s+/,<STDIN>);
my @h = map { $_ - 0 } split(/\s+/,<STDIN>);
my $j = -1;
my $v = 0;
for(my $i=0;$i<=$#h;$i++){
  my $v1 = abs(1000 * $a - ( 1000 * $t - $h[$i] * 6 ));
  if( $j == -1 or $v1 < $v ){
    $v = $v1;
    $j = $i;
  }
}
$j++;
print "$j\n";


Measured memory_bytes: 768
N, M = map(int, input().split())
AB = [(a, b) for _ in range(N) for a, b in [map(int, input().split())] if M - a >= 0]

AB = sorted(sorted(AB, key=lambda x: x[0], reverse=False), key=lambda x: x[1], reverse=True)
x = [0] * M
p = [x for x in range(M)]

cnt = 0
for a, b in AB:
    i = M-a

    s = []
    while i >= 0 and p[i] != i:
        s.append(i)
        i = p[i]
    for j in s:
        p[j] = i - 1

    if i >= 0:
        x[i] = b
        p[i] = i - 1

print(sum(x))


Measured memory_bytes: 23120
n,y = map(int,input().split())

for i in range(y // 10000 + 1):
    for j in range(y // 5000 + 1):
        k = n - i - j
        if 0 <= k and 10000 * i + 5000 * j + 1000 * k == y:
            print(i,j,k,sep=" ")
            exit()
print("-1 " + "-1" + " -1")

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

#define REPp(i, m, n) for(int (i)=(m);(i)<(n);(i)++)
#define REPm(j, m, n) for(int (j)=(m);(j)>(n);(j)--)

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    REPp(i, 0, N) {
        cin >> A[i];
    }
    
    bool flag = 1;
    int count = 0;
    while(flag) {
        flag = 0;
        REPm(j, N - 1, 0) {
            if(A[j] < A[j - 1]) {
                swap(A[j], A[j - 1]);
                count++;
                flag = 1;
            }
        }
    }
    
    REPp(i, 0, N - 1) cout << A[i] << " ";
    cout << A[N - 1] << endl << count << endl;
}


Measured memory_bytes: 3120
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

struct UnionFind{
    vector<int> data;
    UnionFind(int size) : data(size, -1) {}
    bool unionSet(int x,int y){
        x=root(x);y=root(y);
        if(x==y)return 0;
        if(data[y]<data[x])swap(x,y);
        data[x]+=data[y],data[y]=x;
        return 1;
    }
    bool findSet(int x,int y){
        return root(x)==root(y);
    }
    int root(int x){
        return data[x]<0 ? x : data[x]=root(data[x]);
    }
    int size(int x){
        return -data[root(x)];
    }
};
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
  	int a,b;
  	cin>>a>>b;
  	rep(i,1010){
     	 if((int)(i*0.08)==a&&(int)(i*0.1)==b){
           		cout<<i<<endl;
           		return 0;
         }
    }
  	cout<<-1<<endl;
  	
}







Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**9)

def main():
    N = int(input())
    
    h = map(int,input().split())
    a = map(int,input().split())
    
    def segfunc(x,y):
        return max(x,y)
    
    def update(k,x):
        k += num-1
        seg[k] = x
        while k:
            k = (k-1)//2
            seg[k] = segfunc(seg[2*k+1],seg[2*k+2])
            
    def query(p,q):
        if q <= p:
            return ide_ele
        p += num-1
        q += num-2
        ret = ide_ele
        while q-p>1:
            if p&1 == 0:
                ret = segfunc(ret,seg[p])
            if q&1 == 1:
                ret = segfunc(ret,seg[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        ret = segfunc(segfunc(ret,seg[p]),seg[q])
        return ret
        
    ide_ele = 0
    num = 2**N.bit_length()
    seg = [ide_ele]*2*num

    
    dp = [0]*(N+1)
    
    for he,be in zip(h,a):
        tmp = query(0,he)+be
        if tmp > dp[he]:
            dp[he] = tmp
            update(he,tmp)
    
    print(max(dp))

if __name__ == "__main__":
    main()


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

public class Main {
	static int H1;
	static int M1;
	static int H2,M2;
	static int K;
	
	public static void main(String[] args) throws NumberFormatException, IOException {
		read();
	}

	private static void read() throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] words = br.readLine().split("\\s+");
		
		H1  = Integer.valueOf(words[0]);
		M1 = Integer.valueOf(words[1]);
		H2 = Integer.valueOf(words[2]);
		M2 = Integer.valueOf(words[3]);
		K = Integer.valueOf(words[4]);
		
		int minute1 = H1*60 + M1;
		int minute2 = H2*60 + M2;
		int diff = minute2 - minute1;
		
		System.out.println(diff - K);

		br.close();
	}
}

Measured memory_bytes: 34000
<?php

fscanf(STDIN, "%d", $n);
fscanf(STDIN, "%s", $s);

$arr = str_split($s);
$count = count($arr) - 2;

$result = 0;
for ($i = 0; $i < $count; ++$i) {
    if ($arr[$i] === 'A' && $arr[$i + 1] === 'B' && $arr[$i + 2] === 'C') {
        ++$result;
    }
}
echo $result;


Measured memory_bytes: 4728
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P;


int main(){
	int n[1000];
	for(int i=0;i<1000;i++) n[i] = i;
	for(int i=1;i<1000;i++) n[i] += n[i-1];

	int a,b;
	scanf("%d %d", &a, &b);

	printf("%d\n", n[b-a-1]-a);

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#include <cmath>

int gcd( int a, int b){
    if(b==0){
        return a;
    }
    return gcd(b,a%b);
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n,m,sum=0,x;
    cin>>n>>m;
    for(ll i=0;i<m;i++){
        cin>>x;
        sum+=x;
    }
    if(sum>n){
        cout<<-1<<endl;
    }else{cout<<n-sum<<endl;}

    return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	if(a+b==3){
		cout<<"3"<<endl;
	}else if(a+b==4){
		cout<<"2"<<endl;
	}else if(a+b==5){
		cout<<"1"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long MAXN=100100;
long n;
long double a[MAXN];
long num_of_digit=0;

long double read_long() {
	--num_of_digit;
	long double ret=0;char c=getchar();
	while(c<'0' || c>'9') c=getchar();
	while(c>='0' && c<='9') {
		++num_of_digit;
		ret=ret*10+c-'0';
		c=getchar();
	}		return ret;
}

int main() {
	cin>>n;
	register long i;
	for(i=1;i<=n;++i) {
		a[i]=read_long();
		if(a[i]==0) {
			printf("0\n");
			return 0;
		}
	}
	
	if(num_of_digit>18) {
		printf("-1\n");
		return 0;
	}
	
	long double ans=1;
	for(i=1;i<=n;++i) {
		ans*=a[i];
		if(ans>1e18) {
			printf("-1\n");
			return 0;
		}
	}
	printf("%lld\n",(long long)ans);
	return 0;
}

Measured memory_bytes: 5316
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
using namespace std;
static const bool TAKAHASHI_TURN = false;
static const bool AOKI_TURN = true;

class Monster {
public:
    Monster() = default;

    void attack(Monster& enemy) {
        enemy.m_hitPoint -= min(enemy.m_hitPoint, m_attackPoint);
    }

    bool isDead() {
        return m_hitPoint == 0;
    }

    void read() {
        cin >> m_hitPoint >> m_attackPoint;
    }

private:
    int m_hitPoint;
    int m_attackPoint;
};

int main() {
    Monster takahashi, aoki;
    takahashi.read();
    aoki.read();

    for (bool turn = TAKAHASHI_TURN; !takahashi.isDead() and !aoki.isDead(); turn = !turn) {
        switch (turn) {
            case TAKAHASHI_TURN:
                takahashi.attack(aoki);
                break;
            case AOKI_TURN:
                aoki.attack(takahashi);
                break;
        }
    }

    cout << (aoki.isDead() ? "Yes" : "No") << endl;

    return 0;
}



Measured memory_bytes: 3552
a,b,c,d = map(int,input().split())
x=c-a
y=d-b
print('R'*x+'U'*(y+1)+'L'*(x+1)+'D'*(y+1)+'R'+'U'*y+'R'*(x+1)+'D'*(y+1)+'L'*(x+1)+'U')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll GCD(ll a, ll b){ return a ? GCD(b % a, a) : b; }
int main(){
    string s;
    cin>>s;
    string t="+-";
    for(int i=0; i<2; i++){
        for(int j=0; j<2; j++){
            for(int k=0; k<2; k++){
                int tmp=(s[0]-'0');
                if(i==0) tmp+=(s[1]-'0');
                else tmp-=(s[1]-'0');
                if(j==0) tmp+=(s[2]-'0');
                else tmp-=(s[2]-'0');
                if(k==0) tmp+=(s[3]-'0');
                else tmp-=(s[3]-'0');
                if(tmp==7){
                    cout<<s[0]<<t[i]<<s[1]<<t[j]<<s[2]<<t[k]<<s[3]<<"=7"<<endl;
                    return 0;
                }
            }
        }
    }
}

Measured memory_bytes: 256
use strict;
use warnings;

sub sum {
    my $total = 0;
    foreach my $x (@_) {
        $total += $x;
    }
    return $total;
}

chomp (my ($N, $M)= split(/ /, <STDIN>));
chomp (my @A = split(/ /, <STDIN>));

my $total = sum(@A);
my $count = 0;

foreach my $item (@A) {
    if ($total / (4 * $M) <= $item) {
        $count++;
    }
}

if ($M <= $count) {
    print "Yes\n";
} else {
    print "No\n";
}

Measured memory_bytes: 640
//Longest Common Subsequence
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define LINT long long

int main(){
  int q;
  string X, Y;
  int dp[1001][1001]={};
  int m, n;
  int ans;


  cin >> q;
  REP(s, q){
    dp[1001][1001]={};
    cin >> X >> Y;
    m=X.size();
    n=Y.size();
    REP(i, m){
      REP(j, n){
        if(X[i] == Y[j]) dp[i+1][j+1] = dp[i][j]+1;
        else dp[i+1][j+1]=max(dp[i][j+1], dp[i+1][j]);
      }
    }
    cout << dp[m][n] <<endl;
  }


  return 0;
}



Measured memory_bytes: 7060
mod = 10 ** 9 + 7
N, K = map(int, input().split())
cnt = [0 for i in range(K+1)]
for i in range(K, 0, -1):
    tmp_sum = pow(K//i, N, mod)
    for j in range(2, 10**7+1):
        if i*j > K:
            break
        tmp_sum -= cnt[i*j]
    cnt[i] = tmp_sum
ans = sum(cnt[i]*i for i in range(1,K+1)) % mod
print(ans)


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


int main() {
	int x,y;
	cin>>x>>y;
	if((x==1 || x==3|| x==5|| x==7|| x==8|| x==10|| x==12) && (y==1 || y==3|| y==5|| y==7|| y==8|| y==10|| y==12))
        cout<<"Yes";
    else if((x==1 || x==6|| x==9|| x==11) && (y==4 || y==6|| y==9|| y==11))
        cout<<"Yes";
        else if(x==2 && y==2)
                    cout<<"Yes";
        else cout<<"No";
	return 0;
}


Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.function.BinaryOperator;

class SegmentTree<T> {

	private List<T> nodes;
	private T e; // 単位元
	private int n;
	private BinaryOperator<T> operator;

	/**
	 * セグメント木を生成
	 * 
	 * @param n  要素数
	 * @param e  単位元
	 * @param op
	 */
	public SegmentTree(int n, T e, BinaryOperator<T> op) {
		this.e = e;
		this.operator = op;

		n = 1 << (32 - Integer.numberOfLeadingZeros(Math.max(n - 1, 0))); // n以上で最小の2のべき乗
		this.n = n;

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

	//
	public void update(int k, T val) {
		k += n - 1;
		nodes.set(k, val);

		while (k > 0) {
			k = (k - 1) / 2;
			nodes.set(k, operator.apply(nodes.get(2 * k + 1), nodes.get(2 * k + 2)));
		}
	}

	// 区間 [a,b) のoperatorの結果を返す
	// 0-indexed
	public T query(int a, int b) {
		return query(a, b, 0, 0, n);
	}

	private T query(int a, int b, int k, int l, int r) {
		if (a >= r || b <= l) {
			return e;
		}

		if (a <= l && r <= b) {
			return nodes.get(k);
		}

		T vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
		T vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
		return operator.apply(vl, vr);
	}

}

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

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

		SegmentTree<Integer> seg = new SegmentTree<>(n, (1 << 31) - 1, (a, b) -> Math.min(a, b));

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

			switch (com) {
			case 0:
				seg.update(x, y);
				break;
			case 1:
				out.println(seg.query(x, y + 1)); // [x,y] なので半開区間にする
				break;
			}
		}

		sc.close();

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}
}



Measured memory_bytes: 111720
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <sys/timeb.h>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define FOR(NAME, START, NUM) for (ll NAME = START; NAME < (NUM); NAME++)
#define REP(NAME, NUM) for (ll NAME = 0; NAME < (NUM); NAME++)
#define BREP(NAME, NUM) for (ll NAME = (NUM)-1; NAME >= 0; NAME--)
#define ALL(NAME) (NAME).begin(), (NAME).end()
const ll LINF = 1e18;
const int INF = 1e9;
const int mod = 1e9+7;

int main(){
	vector<char> a(4);
	REP(i,4)cin >> a.at(i);
	
	sort(ALL(a));
	
	if(a[0]== a[1] && a[2]==a[3] && a[2]!=a[1])
		cout << "Yes" << endl;
	else cout << "No" << endl;
}


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

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

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
 
    int x, a, b;
    
    scanf("%d%d%d", &x, &a, &b);
    
    if (b-a<=0) {
        printf("delicious");
    } else if (b-a<=x) {
        printf("safe");
    } else {
        printf("dangerous");
    }
    
    return 0;
}



Measured memory_bytes: 1716
using System;

class Program {
  static void Main() {
    var o = Console.ReadLine();
    var e = Console.ReadLine();
    int i = 0;
    for ( ; i < e.Length; i++) {
      Console.Write($"{o[i]}{e[i]}");
    }
    Console.WriteLine(i < o.Length ? $"{o[i]}" : "");
  }
}

Measured memory_bytes: 13140
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <numeric>
#include <climits>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <utility>
#include <cctype>
#include <iterator>
////////////////////////////////////////////////
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define FOR(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define REPe(e, mp) for (auto& e : mp)
#define all(x) x.begin(), x.end()
#define MOD 1000000007  // 1e9+7
using namespace std;
using ll = long long int;
using vecint = vector<int>;
using vecll = vector<ll>;
using vec2int = vector<vector<int>>;
using P = pair<int, int>;
////////////////////////////////////////////////
int main() {
  ////////////////////////////////////////////////
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ////////////////////////////////////////////////
  ll n, m, k;
  cin >> n >> m >> k;
  vecll a(n, 0);
  vecll b(m, 0);
  REPe(e, a) cin >> e;
  REPe(e, b) cin >> e;
  vecll suma(n, 0);
  vecll sumb(m, 0);
  suma[0] = a[0];
  sumb[0] = b[0];
  REP(i, n - 1) suma[i + 1] = suma[i] + a[i + 1];
  REP(i, m - 1) sumb[i + 1] = sumb[i] + b[i + 1];
  auto itr1 = upper_bound(all(sumb), k);
  ll ans = itr1 - sumb.begin();
  REP(i, n) {
    ll tota = suma[i];
    ll totb = k - tota;
    if (totb < 0) continue;
    auto itr = upper_bound(all(sumb), totb);
    // if (itr == sumb.begin()) {
    //   ans = max(ans, (ll)i + 1LL);
    //   continue;
    // }
    // cout << tota << " " << totb << " " << *itr << " " << itr - sumb.begin()
    //  << endl;
    ans = max(ans, (ll)i + 1LL + (ll)(itr - sumb.begin()));
    // cout << ans << endl;
  }
  cout << ans << endl;
}


Measured memory_bytes: 9524
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#define _USE_MATH_DEFINES
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0,1,0,-1 };
const ll dy[4] = { -1, 0, 1,0 };
const ll INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
double mysqrt(double x) {
	double l = 0, r = x;
	for (int i = 0; i < 64; ++i) {
		double m = (l + r) / 2.0;
		if (m*m < x)l = m;
		else r = m;
	}
	return l;
}
///////////////////////////////////////

int N, M;
vector<pii>G[110];
bool ok[110][110];
int d[110];
int pre[110];//最短路の直前の頂点
void dijkstra(int a) {
	priority_queue<pii, vector<pii>, greater<pii>>que;
	REP(i, 110)d[i] = INF;
	REP(i, 110)pre[i] = -1;
	d[a] = 0;
	que.push({ 0,a });
	while (!que.empty()) {
		pii P = que.top();
		que.pop();
		int v = P.second;
		if (d[v] < P.first)continue;
		for (int i = 0; i < G[v].size(); ++i) {
			pii e = G[v][i];
			if (d[e.first] > d[v] + e.second) {
				d[e.first] = d[v] + e.second;
				pre[e.first] = v;
				que.push({ d[e.first],e.first });
			}
		}
	}
}
//頂点tへの最短路
vector<int>get_path(int t) {
	vector<int>path;
	for (; t != -1; t = pre[t]) {
		path.push_back(t);
	}
	return path;
}
int main() {
	cin >> N >> M;
	memset(ok, false, sizeof(ok));
	REP(i, M) {
		int a, b, c;
		cin >> a >> b >> c;
		a--, b--;
		G[a].push_back({ b,c });
		G[b].push_back({ a,c });
		ok[a][b] = true;
		ok[b][a] = true;
	}
	REP(i, N) {
		for (int j = i + 1; j < N; ++j) {
			if (i == j)continue;
			dijkstra(i);
			vector<int>key = get_path(j);
			for (int k = 0; k < key.size()-1; ++k) {
				ok[key[k]][key[k + 1]] = false;
				ok[key[k + 1]][key[k]] = false;
			}
		}
	}
	int ans = 0;
	REP(i, N) {
		REP(j, N) {
			if (ok[i][j])ans++;
		}
	}
	cout << ans/2 << endl;
	return 0;
}

Measured memory_bytes: 256
N = gets.chomp.to_i
s = []
N.times do
  s << gets.chomp
end

h = {}
s.each do |ss|
  sorted_s = ss.split('').sort.join
  h[sorted_s] ||= 0
  h[sorted_s] += 1
end
  
r = 0
h.each do |_, v|
  if v >= 2
    r += v * (v - 1) / 2
  end
end

p r

Measured memory_bytes: 26620
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

vector<vector<pair<int, int>>> g;
vector<ll> dist;

void dfs ( int u, ll d) {
    if ( dist[u] >= 0 ) return;
    dist[u] = d;
    for ( auto p : g[u] ) {
        dfs(p.first, d + p.second);
    }
}

int main(){
    int n;
    cin >> n;
    g.resize(n+1);
    rep(i, n-1) {
        int a, b;
        ll c;
        cin >> a >> b >> c;
        g[a].emplace_back(b, c);
        g[b].emplace_back(a, c);
    }
    int q, k;
    cin >> q >> k;
    dist.assign(n + 1, -1);
    dfs(k, 0);
    rep(i, q) {
        int x, y;
        cin >> x >> y;
        ll ans = dist[x] + dist[y];
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 11136
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value

sys.setrecursionlimit(10**9)

#メモ化再帰
def rec(x):
    global dp
    if dp[x]!=-1:
        return dp[x]
    num = 0
    for a in adj[x]:
        num = max(num, rec(a)+1)
    dp[x] = num
    return num

#入力受け取り
N, M = mi()
x = li2(M)

#隣接リスト作成
adj = [[] for i in range(N)]
for i in range(M):
    x[i][0] -= 1
    x[i][1] -= 1
    adj[x[i][0]].append(x[i][1])

#メモ化再帰を実行
dp = [-1]*N
for i in range(N):
    rec(i)

print(max(dp))

Measured memory_bytes: 75672
N, Y = map(int, input().split())
for a in range(0, N+1):
    for b in range(0, N+1-a):
        c = N-a-b
        if 10000*a+5000*b+1000*c == Y:
            print(a, b, c)
            break
    else:
        continue
    break
else:
    print(-1, -1, -1)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,p,q=1,r,ct=1;
    vector<ll>v;
    cin>>n;
    for(ll i=1;i<=n;i++)
    {
        cin>>p;
        if(i==1) {ct=1;q=p;}
        else {if(p<=q){ct++;q=p;}}
    }
    cout<<ct<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int n,x,a=0,i,j,k;
    while(1){
        scanf("%d %d",&n,&x);
        if(n==0&&x==0){
            break;
        }
        for(i=1; i<=n; i++){
            for(j=1; j<=n; j++){
                for(k=1; k<=n; k++){
                    if((i+j+k)==x&&i!=j&&j!=k&&k!=i){
                        a+=1;
                }
            }
        }
    }
        printf("%d\n",a/6);
        a=0;
    }

     return 0;
}




Measured memory_bytes: 2100
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		//変数の宣言
		double r;
		double Area,Length;
		//値の入力
		//System.out.println("Please input r:");
		Scanner sc = new Scanner(System.in);
		r=sc.nextDouble();
		//計算
		Area=Math.PI*r*r;
		Length=2*Math.PI*r;
		//結果の表示
		System.out.println(String.format("%08f", Area)+" "+String.format("%08f", Length));
	}
}



Measured memory_bytes: 28340
#include<iostream>
#include<string>
//#include<vector>

int main(){
	int a;
	std::string str;

	std::cin>>a>>str;

	if (a < 3200) {
		std::cout << "red" << std::endl;
	}
	else {
		std::cout << str << std::endl;
	}



	
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

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

            int b = int.Parse(Console.ReadLine());

            switch (a)
            {
                case 1:
                    if(b == 2)
                    {
                        Console.WriteLine(3);
                    }
                    else
                    {
                        Console.WriteLine(2);
                    }
                    break;

                case 2:
                    if (b == 1)
                    {
                        Console.WriteLine(3);
                    }
                    else
                    {
                        Console.WriteLine(1);
                    }
                    break;

                case 3:
                    if (b == 2)
                    {
                        Console.WriteLine(1);
                    }
                    else
                    {
                        Console.WriteLine(2);
                    }
                    break;
            }
        }
    }
}


Measured memory_bytes: 11092
N,M = map(int,input().split())
B = [tuple(map(int,input().split())) for _ in range(M)]
P = tuple(map(int,input().split()))

ans = 0

for i in range(2**N):
    flag = True
    for k in range(M):
        on = 0
        
        for j in range(B[k][0]):
            if i>>(B[k][j+1]-1) & 1:
                on += 1
        
        if on%2 != P[k]:
            flag = False
            
    if flag:
        ans += 1
        
print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <stack>
#define INT long long
#define oo 987654321

using namespace std;
string s;
stack<char> st;
int ans;
int main()
{
    ios::sync_with_stdio(false);
    cin>>s;
    for(int i = 0 ; i < s.size() ; i++ )
        if( st.empty() ) st.push(s[i]);
        else
        {
            if( st.top() != s[i] ) st.push(s[i]);
        }
    cout<<st.size()-1<<endl;
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define f first
#define s second
#define pb push_back
signed main()
{
 int a,b,c,k;
 cin>>a>>b>>c>>k;
 if(k<=a)
    cout<<k<<endl;
 else if(k<=a+b)
    cout<<a<<endl;
 else
    cout<<a-(k-a-b)<<endl;
}


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

const long long DIV = 1e9 + 7;

int N;
long long A[400000];
int nom[400000][61] = {0};
int rev[400000][61] = {0};

int main(){
	cin >> N;
	for(int i = 0; i < N; i++){
		cin >> A[i];
	}
	for(int i = N-1; i > 0; i--){
		for(int j = 0; j < 60; j++){
			if(A[i] & (1LL<<j)){
				nom[i][j] = nom[i+1][j] + 1;
				rev[i][j] = rev[i+1][j];
			}
			else{
				nom[i][j] = nom[i+1][j];
				rev[i][j] = rev[i+1][j] + 1;
			}
		}
	}
	long long int ans = 0;
	
	for(int i = 0; i < N-1; i++){
		for(long long j = 0; j < 60; j++){
			int val;
			if(A[i] & (1LL<<j)){
				val = rev[i+1][j];
			}
			else{
				val = nom[i+1][j];
			}
			ans += ((val * ((1LL<<j) % DIV)) % DIV);
			ans %= DIV;
		}
	}

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


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

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

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const double PI = acos(-1.0);

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(50) << setiosflags(ios::fixed);
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int m;
  cin >> m;
  vector<int> b(m);
  rep(i, m) cin >> b[i];

  vector<int> result;
  set_union(all(a), all(b), back_inserter(result));
  for (auto r : result)
    cout << r << endl;
  return 0;
}



Measured memory_bytes: 6476