akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

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

using namespace std;

int main(){
	int n,a0,b0,c0; cin>>n>>a0>>b0>>c0;
	vector<string> s(n);
	rep(i,n) cin>>s[i];

	vector<vector<tuple<int,int,int>>> S(n+1);
	S[n]={{0,0,0}};
	for(int i=n-1;i>=0;i--){
		vector<tuple<int,int,int>> tmp;

		for(auto [a,b,c]:S[i+1]){
			if(s[i]=="AB"){
				tmp.emplace_back(a+1,max(b-1,0),c);
				tmp.emplace_back(max(a-1,0),b+1,c);
			}
			else if(s[i]=="BC"){
				tmp.emplace_back(a,b+1,max(c-1,0));
				tmp.emplace_back(a,max(b-1,0),c+1);
			}
			else{
				tmp.emplace_back(a+1,b,max(c-1,0));
				tmp.emplace_back(max(a-1,0),b,c+1);
			}
		}

		sort(tmp.begin(),tmp.end());
		tmp.erase(unique(tmp.begin(),tmp.end()),tmp.end());

		rep(j,tmp.size()){
			auto [aj,bj,cj]=tmp[j];
			bool ok=true;
			rep(k,tmp.size()) if(j!=k) {
				auto [ak,bk,ck]=tmp[k];
				if(ak<=aj && bk<=bj && ck<=cj) ok=false;
			}
			if(ok) S[i].emplace_back(tmp[j]);
		}
	}

	auto check=[&](int a,int b,int c,int i){
		for(auto [ai,bi,ci]:S[i]){
			if(a>=ai && b>=bi && c>=ci) return true;
		}
		return false;
	};

	if(!check(a0,b0,c0,0)) return puts("No"),0;

	puts("Yes");
	rep(i,n){
		if(s[i]=="AB"){
			if(check(a0+1,b0-1,c0,i+1)){ puts("A"); a0++; b0--; continue; }
			if(check(a0-1,b0+1,c0,i+1)){ puts("B"); a0--; b0++; continue; }
		}
		else if(s[i]=="BC"){
			if(check(a0,b0+1,c0-1,i+1)){ puts("B"); b0++; c0--; continue; }
			if(check(a0,b0-1,c0+1,i+1)){ puts("C"); b0--; c0++; continue; }
		}
		else{
			if(check(a0+1,b0,c0-1,i+1)){ puts("A"); a0++; c0--; continue; }
			if(check(a0-1,b0,c0+1,i+1)){ puts("C"); a0--; c0++; continue; }
		}
	}

	return 0;
}


Measured memory_bytes: 19608
#include<iostream>
using namespace std;
int main()
{
	int n,k,x,y,sum=0;
	cin>>n>>k>>x>>y;
	if(k<n)
	{
		for(int i=1;i<=k;i++)
			sum+=x;
		for(int i=k+1;i<=n;i++)
			sum+=y;
	}
	else
		sum=n*x;
	cout<<sum<<endl;
	return 0;
}

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

int main(int argc, const char * argv[]) {
    char S[4];
    cin>>S;
    if(S[0]=='R'){
        if(S[1]=='R'){
            if(S[2]=='R'){
                cout<<3<<endl;
            }else{
                cout<<2<<endl;
            }
        }else{
            cout<<1<<endl;
        }
    }else{
        if(S[1]=='R'){
            if(S[2]=='R'){
                cout<<2<<endl;
            }else{
                cout<<1<<endl;
            }
        }else{
            
            if(S[2]=='R'){
                cout<<1<<endl;
            }else{
                cout<<0<<endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3164
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		long[] l = new long[n];

		for (int i=0; i<n; i++){
			l[i] = sc.nextLong();
		}
		Arrays.sort(l);
		int ans = 0;
		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[i] != l[j] && l[j] != l[k] && l[i] != l[k]){
						if (l[i] + l[j] > l[k]){
							ans++;
						}
					}
				}
			}
		}
		System.out.println(ans);
	}


}

Measured memory_bytes: 36532
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>

using namespace std;
typedef long long ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
#define rep(i, n) for(int i = 0;i < n;i++)
const int INF = 1LL << 30;

int MOD = 1000000007;

int dp[5005][5005];

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

    int n,k; cin >> n >> k;
    std::vector<ll> v(n);
    rep(i,n) cin >> v[i];

    ll ans = 0LL;

    rep(total,k+1){
        rep(left, total+1){

            int tmp_left = left;

            priority_queue<ll, std::vector<ll>, std::greater<ll>> pq;

            int popnum = k-total;
            int right = total - tmp_left;
            
            if(total > n){
                popnum = total - n;
                right = n;
                tmp_left = 0;
            }

            //cout << "Total: " << total << " Left: " << tmp_left << " Right: " << right << " Popnum: " << popnum << endl;

            rep(i, tmp_left) pq.push(v[i]);
            rep(i, right) pq.push(v[n-i-1]);
            
            
            ll tmp = 0LL;

            rep(i, popnum){
                if(pq.size() == 0) break;

                if(pq.top() < 0){
                    pq.pop();
                } else break;
            }
            

            while( !pq.empty()){
                tmp+= pq.top();
                pq.pop();
            }

            ans = max(ans, tmp);
        }
    }

    cout << ans << endl;

    return 0;
}

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

int gcd(int a, int b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
  
// Function to find gcd of array of 
// numbers 
int findGCD(int arr[], int n) 
{ 
    int result = arr[0]; 
    for (int i = 1; i < n; i++) 
    { 
        result = gcd(arr[i], result); 
  
        if(result == 1) 
        { 
           return 1; 
        } 
    } 
    return result; 
} 
  
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
	#ifndef ONLINE_JUDGE 
    freopen("input.txt", "r", stdin); 
    freopen("output.txt", "w", stdout); 
    #endif
    int n,ans=0;
    cin>>n;
    for(int i=1; i<=n; i++){
        for(int j=1; j<=n; j++){
            for(int k=1; k<=n; k++){
                int arr[]={i,j,k};
                ans+=findGCD(arr,3);
            }
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3584
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 2222222222222222222LL;
//const ll mod = 1000000007LL;
const ll mod = 998244353LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,0,-1,0,1,1,-1,-1 }, dy[9] = { 0,0,1,0,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222


double dp[333][333][333];
ll a[333];




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


  cin >> n;
  ll x = 0, y = 0, z = 0;
  rep(i, n) {
    cin >> tmp;
    if (tmp == 1) x++;
    else if (tmp == 2) y++;
    else z++;
  }
  double e = 0;
  dp[x][y][z] = 1;

  rrep(k, n + 1) rrep(j, n + 1) rrep(i, n + 1) {
    if (i + k + j) e += dp[i][j][k] * (double)n / ((double)i + j + k);
    if (i) dp[i - 1][j][k] += dp[i][j][k] * (double)i / ((double)i + j + k);
    if (j) dp[i + 1][j - 1][k] += dp[i][j][k] * (double)j / ((double)i + j + k);
    if (k) dp[i][j + 1][k - 1] += dp[i][j][k] * (double)k / ((double)i + j + k);
  }

  cout.precision(10);
  cout << fixed << e << endl;
  


  return 0;
}

Measured memory_bytes: 262272
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    long sum = 0;
    HashMap<Integer,Integer> a = new HashMap<Integer,Integer>();
    for (int i = 0;i<n;i++){
      int b = scan.nextInt();
      sum += b;
      if (a.get(b) == null){
        a.put(b,1);
      }
      else{
        int m = a.put(b,1);
        a.put(b,m+1);
      }
    }

    int m = scan.nextInt();
    for (int j=0;j<m;j++){
      int a1 = scan.nextInt();
      int a2 = scan.nextInt();
      if (a.get(a1) == null){
        System.out.println(sum);
        continue;
      }
      int gg = a.put(a1,0);
      sum += gg*(a2-a1);
      System.out.println(sum);
      if (a.get(a2) == null){
        a.put(a2,gg);
      }
      else{
        int mm = a.put(a2,0);
        a.put(a2,mm+gg);
      }
    }


  }
}


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

using namespace std;

/*****************MACRO*****/

#define ll long long
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

/*******CONSTANT***********/
#define INF (1<<30) //infinity value
#define EPS 1e-9
#define MOD 10000007
#define SIZ 1005
#define PI (acos(-1))


int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll cnt=0;
    for(int i=0; i<1000; i++){
        int c[3] = {i / 100, (i / 10) % 10, i % 10};///******VITAL LINE copied
        ///eg: 25 hole: c[]= 0 2 5 hobe
        int pos= 0;
        for(ll j=0; j<s.size(); j++){
            int dig= s[j]-'0';
            //cout<<dig<<"\n";
            if(dig==c[pos]) pos++;

            if(pos==3) break;
            ///***this was the most vital line; na hole to c[4] egulao check kore ulta palta answer
        }
        if(pos==3) cnt++;
    }
    cout<<cnt<<"\n";

    return 0;
}

/**********************************************************************************

###Onekgula Wrong answer:

for(int i=0; i<1000; i++){
        int c[3] = {i / 100, (i / 10) % 10, i % 10};///******VITAL LINE copied
        ///eg: 25 hole: c[]= 0 2 5 hobe
        int pos= 0;
        for(ll j=0; j<s.size(); j++){
            int dig= s[j]-'0';
            if(dig==c[pos]) pos++;
        }
        if(pos==3) cnt++;
    }
    cout<<cnt<<"\n";






*************************************************************************************/


Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_set>
#include <bitset>
#include <time.h>
#include <limits.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) (int)x.size()
#define sz(x) (int)x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
typedef tuple<int, int, int> t3;

int N, M;
vector <pii> lv[200020];
ll T[1<<19], C[1<<19];

void pushdown(int rt) {
	if(C[rt]) {
		T[rt<<1] += C[rt], C[rt<<1] += C[rt];
		T[rt<<1|1] += C[rt], C[rt<<1|1] += C[rt];
		C[rt] = 0;
	}
}

void update(int rt, int l, int r, int s, int e, ll val) {
	if(s <= l && r <= e) {
		C[rt] += val;
		T[rt] += val;
		return;
	}
	pushdown(rt);
	int m = (l + r) >> 1;
	if(s <= m) update(rt<<1, l, m, s, e, val);
	if(m < e) update(rt<<1|1, m+1, r, s, e, val);
	T[rt] = max(T[rt<<1], T[rt<<1|1]);
}

ll read(int rt, int l, int r, int s, int e) {
	if(s <= l && r <= e) return T[rt];
	pushdown(rt);
	int m = (l + r) >> 1;
	ll res = -1e18;
	if(s <= m) res = max(res, read(rt<<1, l, m, s, e));
	if(m < e) res = max(res, read(rt<<1|1, m+1, r, s, e));
	return res;
}

int main() {
	scanf("%d%d", &N, &M);
	for(int i=1;i<=M;i++) {
		int l, r, a; scanf("%d%d%d", &l, &r, &a);
		lv[l].pb(pii(l-1, a));
		lv[r+1].pb(pii(l-1, -a));
	}
	ll ans = 0;
	for(int i=1;i<=N;i++) {
		for(pii e : lv[i]) {
			update(1, 0, N, 0, e.Fi, e.Se);
		}
		ll r = read(1, 0, N, 0, i - 1);
		ans = max(ans, r);
		update(1, 0, N, i, i, r);
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 20096
//#include<iostream>
//#include<cstdio>
//#include<string>
//#include<string>
//#include<algorithm>
//#include<ctime> printf("\n%lldms",clock());
//#include<cmath>
//#include<vector>
//#include<queue>
#include <bits/stdc++.h>
#define lijyya 300010
#define oo 0x3f3f3f3f
#define emmm 100003
#define f1(i,a,b) for (register int i=a;i<=b;++i)
#define f2(i,a,b) for (register int i=a;i<b;++i)
#define f3(i,a,b) for (register int i=a;i>=b;--i)
#define f4(i,a,b) for (register int i=a;i>b;--i)
using namespace std;
typedef long long ll;
template<typename T> inline void checkmax(T &x,T y){x=max(x,y);}
template<typename T> inline void checkmin(T &x,T y){x=min(x,y);}
inline int read(){
	int f=1,x=0;char ch;
	do{
		ch=getchar();if(ch=='-') f=-1;
	}while(ch<'0'||ch>'9');
	do{
		x=x*10+ch-'0';ch=getchar();
	}while(ch>='0'&&ch<='9');
	return f*x;
}

int n,a;
int main(){
	n=read();
	a=read();
	n*=n;
	printf("%d",n-a);
	return 0;
}

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

const int MAX = 210000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll pow(ll n)
{
	if (n == 0) return ll(1);
	if (n == 1) return ll(2);
	if (n % 2 == 1)
	{
		return pow(n-1) * 2 % MOD;
	}
	else
	{
		ll p = pow(n/2);
		return p * p % MOD;
	}
}

int main()
{
	COMinit();
	ll n;
	int a,b;
	cin >> n >> a >> b;
	ll ans = pow(n) - 1;
	ll temp = 1;
	rep(i,a)
	{
		temp = temp * (n-i) % MOD;
	}
	temp = temp * finv[a] % MOD;
	ans = ans - temp;
	if (ans < 0) ans += MOD;
	temp = 1;
	rep(i,b)
	{
		temp = temp * (n-i) % MOD;
	}
	temp = temp * finv[b] % MOD;
	ans = ans - temp;
	if (ans < 0) ans += MOD;
	cout << ans << endl;
	return 0;
}

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

typedef long long ll;
ll INF = 1LL << 60;
int MAX = 100010;

bool
check_prime(int n)
{
  if(n <= 1) return false;
  for(int i = 2; i * i <= n; i++){
    if(n % i == 0) return false;
  }
  return true;
}

int 
main() 
{
  int q; cin >> q;
  vector<int> arr(MAX, 0);
  vector<int> acum(MAX, 0);
  rep(i, 1, MAX){
    if(check_prime(i) &&  check_prime((i + 1) / 2 ))
    arr[i]++;
  }

  rep(i, 1, MAX) acum[i] = acum[i - 1] + arr[i];

  rep(i, 0, q){
    int l, r; cin >> l >> r;
    if(l == r){
      cout << acum[r] - acum[r - 1] << endl;
    }else{
      cout << acum[r] - acum[l - 1] << endl;
    }
  }

  return 0;
}




Measured memory_bytes: 1408
import java.io.IOException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int a = s.nextInt();
		int b = s.nextInt();
		int p1 = n * a;
		int r = p1;
		if(p1 > b){
			r = b;
		}

		System.out.println(r);
	}
}


Measured memory_bytes: 21972
#include<iostream>
#include <algorithm>
#include<string>
#include <numeric>
#include<math.h>
#include <bits/stdc++.h>
using namespace std;

int main(void) {
    int t,x;
    cin>>t>>x;
    printf("%.12f\n",(double)t/x);
    return 0;
}


Measured memory_bytes: 256
import numpy as np
N = input()
N = int(N)
Sdict = {}
n_anagram = 0
D = {"a":2, "b":3, "c":5, "d":7, "e":11, "f":13,"g":17, "h":19, "i":23, "j":29, "k":31, "l":37, "m":41, "n":43,
"o":47, "p":53, "q":59, "r":61, "s":67, "t":71, "u":73, "v":79, "w":83, "x":89, "y":97, "z":1}

S = [input() for _ in range(N)]

for s in S:
    s1 = [D[x] for x in s]
    s2 = np.prod(s1)

    if s2 in Sdict:
        n_anagram = n_anagram + Sdict[s2]
        Sdict[s2] += 1
    else:
        Sdict[s2] = 1
   
print(n_anagram)

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

using namespace std;

int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    set<string> x;
    while(n--)
    {
        string s;
        cin>>s;
        x.insert(s);
    }
    vector<int> p(26);
    for(auto &i:x)
        ++p[i[0]-'A'];
    priority_queue<int> q;
    for(auto &i:p)
        if(i)
            q.push(i);
    int res=0;
    while(1)
    {
        vector<int> temp;
        for(int i=0;i<k;++i)
        {
            if(q.empty())
                break;
            temp.push_back(q.top()-1);
            q.pop();
        }
        if((int)temp.size()!=k)
            break;
        ++res;
        for(auto &i:temp)
            if(i)
                q.push(i);
    }
    printf("%d\n",res);
}


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

int f(int n){
  if(n%2==0) return n/2;
  else return 3*n+1;
}

int main(){
  map<int,bool> used;
  int s; cin >> s;
  used[s]=true;
  int n=1;
  while(!used[f(s)]){
	s=f(s);
    used[s]=true;
    n++;
  }
  cout << ++n << endl;
}


Measured memory_bytes: 256
// template version 1.8

// varibable settings {{{
using namespace std;
#include <iostream>
#include <bits/stdc++.h>

#define int long long
const int INF=1e18;
const int MOD=1e9+7;
#define infile "../test/sample-1.in"
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
#define fi first
#define se second

// }}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;

// dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;
// }}}


int solve(){
  int h,w;cin>>h>>w;
  vector<vector<int>> m(h, vector<int>(w));
  rep(i, h){
    string s;cin>>s;
    rep(j,w){
      m[i][j]=(s[j]=='#'?1:0);
    }
  }
  dump_2d(m, h, w);

  vvi d(h, vi(w, INF));
  typedef pair<int, pii> CP; // (cost, pos)
  queue<CP> q;
  rep(i,h)rep(j,w){
    if (m[i][j]==1) q.push(CP(0LL, pii(i, j)));
  }
  while (!q.empty()){
    auto v = q.front(); q.pop();
    int cost = v.first;
    int x = v.second.first;
    int y = v.second.second;
    if (cost < d[x][y]){
      d[x][y] = cost;
      rep(i, 4){
        int nx = x+dx[i];
        int ny = y+dy[i];
        if (0<= nx && nx <= h-1 && 0<=ny && ny <= w-1){
          q.push(mp(cost+1, mp(nx, ny)));
        }
      }
    }
  }
  dump_2d(d, h, w);
  int res=0;
  rep(i,h)rep(j,w){
    chmax(res, d[i][j]);
  }
  cout << res << endl;
  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 115256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <climits>
#include <string.h>
#include <stdio.h>
#define LL long long
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int>
#define piii pair<int, pii >
#define REP(i,n) for (int (i)=0;(i)<(n);(i)++)
#define vi vector<int>
#define vpi vector< pii >
#define INF 2147483647
#define big 19260817
#define pb push_back
#define mp make_pair
using namespace std;
const int Maxk=1005;
string mul(string a,string b){
	int res[Maxk];
	memset(res,0,sizeof(res));
	reverse(a.begin(),a.end());
	reverse(b.begin(),b.end());
	for (int i=0;i<a.length();i++){
		for (int j=0;j<b.length();j++){
			res[i+j]+=(a[i]-'0')*(b[j]-'0');
		}
	}
	for (int i=0;i<Maxk;i++){
		if (res[i]>=10) {
			res[i+1]+=(res[i]/10);
			res[i]%=10;
		}
	}
	string ret;
	bool flag=false;
	for (int i=Maxk-1;i>=0;i--){
		if (flag || res[i]){
			flag=true;
			ret=ret+(char)(res[i]+'0');
		}
	}
	if (ret=="") ret="0";
	return ret;
}
string add(string a,string b){
	if (a.length()<b.length()) swap(a,b);
	while (a.length()!=b.length()){
		b='0'+b;
	}
	for (int i=a.length()-1;i>=0;i--){
		a[i]+=(b[i]-'0');
		if (a[i]>'9' && i){
			a[i]-=10;
			a[i-1]++;
		}
	}
	if (a[0]>'9'){
		a[0]-=10;
		a='1'+a;
	}
	return a;
}
// cf IO: I64d
// atcoder IO: ｌｌｄ
const int Maxn=200005;
set<int> edge[Maxn];
int main(){
	int n,m;
	scanf("%d %d",&n,&m);
	for (int i=0;i<m;i++){
		int u,v;
		scanf("%d %d",&u,&v);
		edge[u].insert(v); 
		edge[v].insert(u);
	}
	for (int i=2;i<=n-1;i++){
		if (edge[1].find(i)!=edge[1].end() && edge[i].find(n)!=edge[i].end()){
		//	cout<<i<<endl;
			printf("POSSIBLE\n");
			return 0;
		}
	}
	printf("IMPOSSIBLE\n");
	return 0;
}

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

int main() {
  int n;
  int ans = 0;
  cin >> n;
  vector<int> b (n-1);
  for (int i=0; i<n-1; i++){
    cin >> b.at(i);
  }
  if (n == 2){
    cout << b.at(0)*2 << endl;
  }
  else if (n == 3){
    cout << b.at(0) + b.at(1) + min(b.at(0),b.at(1)) << endl;
  }
  else{
    for (int i=0; i<n-2; i++){
      ans += min(b.at(i),b.at(i+1));
    }
    cout << ans + b.at(0) + b.at(n-2) << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int sp(int n,int s,int num)
{
    if(!n&!s)return 1;
    if(num>9)return 0;
    return sp(n-1,s-num,num+1)+sp(n,s,num+1);
}
int main()
{
    while(1)
    {
        int n,s;
        cin>>n>>s;if(!n)return 0;
        cout<<sp(n,s,0)<<endl;
    }
    return 0;
}

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

using namespace std;

using int64 = long long;

int main() {
  int64 N, M;
  string S, T;
  cin >> N >> M;
  cin >> S >> T;
  int64 gcd = __gcd(N, M);
  int64 x = N / gcd * M;
  map< int64, char > used;
  for(int64 i = 0; i < N; i++) {
    used[x / N * i] = S[i];
  }
  for(int64 i = 0; i < M; i++) {
    if(used.count(x / M * i)) {
      if(used[x / M * i] != T[i]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  cout << x << endl;
}





Measured memory_bytes: 6144
# downguardさんの回答, を改造
class Graph
  attr_accessor :vertexes

  def initialize
    @vertexes = {}
  end

  def register(index, weights)
    @vertexes[index] = Vertex.new(index, weights)
  end

  def find(index); @vertexes[index]; end

  def each; @vertexes.each{ |_, v| yield v }; end

  def prim
    min_costs = Hash.new{ | h, k | h[k] = Float::INFINITY }
    min_costs[0] = 0

    while true
      min_cost = Float::INFINITY
      selected_vertex = nil
      self.each do | v |
        if !v.selected? && min_costs[v.index] < min_cost
          selected_vertex = v
          min_cost = min_costs[v.index]
        end
      end

      break if selected_vertex.nil?

      selected_vertex.select!

      self.each do | v |
        next if v.selected? || !selected_vertex.neighbor?(v)

        if selected_vertex.cost(v) < min_costs[v.index]
          min_costs[v.index] = selected_vertex.cost(v)
          v.parent = selected_vertex
        end
      end

    end
    sum = 0
    self.each{ | v | sum += v.parent.cost(v) if v.parent }
    sum
  end

end

class Vertex
  attr_accessor :index, :parent

  def initialize(index, weights)
    # @index: 頂点を識別するindex
    # @index_cost_map: 繋がってる辺とコストの対応を示す.
    #                  {1=>2}なら頂点1にコスト2で接続.
    # @selected: 確定済み頂点か示すフラグ.
    @index = index
    @index_cost_map = weights.map.with_index{ | e, i |
      e == -1 ? nil : [i, e]
    }.compact!.to_h
    @selected = false
  end

  def neighbors(graph)
    @neighbors ||= @index_cost_map.keys.map{ | i | graph.find(i) }
  end

  def neighbor?(other)
    @index_cost_map.key?(other.index)
  end

  def cost(other)
    @index_cost_map[other.index]
  end

  def selected?;  @selected; end

  def select!; @selected = true; end

end

n = gets.to_i
graph = Graph.new
n.times do | i |
  graph.register(i, gets.split.map(&:to_i))
end

puts graph.prim



Measured memory_bytes: 7324
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int MOD = 1e9 + 7;

struct node {
    int l, r, s = 0, add = 0;
    node* left = 0, *right = 0;
    node(int l, int r): l(l), r(r) {};
};

typedef node* pnode;

pnode build(int l, int r) {
    if (l == r) return new node(l, r);
    int m = (l + r) / 2;
    pnode root = new node(l, r);
    root->left = build(l, m);
    root->right = build(m + 1, r);
    return root;
}

void push(pnode &root) {
    if (!root->left) {
        root->s += root->add;
        root->add = 0;
        return;
    }
    root->s += root->add * (root->r - root->l + 1);
    root->left->add += root->add;
    root->right->add += root->add;
    root->add = 0;
}

int qsum(pnode root, int l, int r) {
    push(root);
    if (root->l > r || root->r < l) return 0ll;
    if (root->l >= l && root->r <= r) return root->s;
    return qsum(root->left, l, r) + qsum(root->right, l, r);
}

void upd(pnode root, int l, int r, int x) {
    push(root);
    if (root->l > r || root->r < l) return;
    if (root->l >= l && root->r <= r) {
        root->add += x;
        push(root);
        return;
    }
    upd(root->left, l, r, x);
    upd(root->right, l, r, x);
    root->s = root->left->s + root->right->s;
}

vector<int> g[200002];

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        if (u > v) swap(u, v);
        g[v].push_back(u);
    }
    int ans = 0;
    pnode root = build(1, n);
    for (int i = 1; i <= n; i++) {
        for (auto j : g[i]) upd(root, 1, j, 1);
        ans += i * (i + 1) / 2;
        ans -= qsum(root, 1, i);
    }
    cout << ans;
}


Measured memory_bytes: 39544
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000



int main(){
	
	int N;
	cin>>N;
	
	vector<pair<pair<int,int>,char>> P(2*N);
	
	for(int i=0;i<2*N;i++){
		int x,y;
		cin>>x>>y;
		P[i].first = make_pair(x,y);
		if(i<N)P[i].second = 'R';
		else P[i].second = 'B';
	}
	
	sort(P.begin(),P.end());
	
	int ans = 0;
	set<int> y;
	
	for(int i=0;i<2*N;i++){
		if(P[i].second=='R')y.insert(P[i].first.second);
		else{
			auto it = y.lower_bound(P[i].first.second);
			if(it==y.begin())continue;
			it--;
			y.erase(it);
			ans++;
		}
	}
	
	cout<<ans<<endl;
	

		
    return 0;
}


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

//マクロ
#define FOR(i, a, b) for(int i = (a); i < (b), i++)
#define REP(i, n) FOR(i, 0, n);
#define ALL(a) (a).begin(),(a).end()


int main(){
    
    //入力
    int n, d, x; cin >> n >> d >> x;
    vector<vector<int> > p(d, vector<int> (n));
    for(int i = 0; i < d; i++){
        for(int j = 0; j < n; j++){
            cin >> p[i][j];
        }
    }

    int w = x;

    for(int k = 0; k < d - 1; k++){

        vector<int> weight(n);
        vector<int> value(n);
        vector<vector<int> > dp(n, vector<int> (w + 1, 0));
        for(int i = 0; i < n; i++){
            weight[i] = p[k][i];
            value[i] = p[k + 1][i] - p[k][i];
        }

        //dp
        for(int i = 0; i < n; i++){
            for(int j = 0; j <= w; j++){
                if(i == 0){
                    if(j >= weight[i]) dp[i][j] = max(dp[i][j], dp[i][j - weight[i]] + value[i]);
                }else{
                    if(j >= weight[i]) dp[i][j] = max(dp[i][j - weight[i]] + value[i], max(dp[i - 1][j], dp[i - 1][j - weight[i]] + value[i]));
                    else dp[i][j] = dp[i - 1][j];
                }
            }
        }

    
        //cout << dp[n - 1][w] << endl;
        w += dp[n - 1][w];
    }
    cout << w << endl;

    return 0;
}


Measured memory_bytes: 4120
#include <bits/stdc++.h>
using namespace std;
using ll=long long;using ull=unsigned ll;
using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;
using P=pair<int,int>;using PL=pair<ll,ll>;
const int INF=1<<30,MOD=1000000007;const ll LINF=1ll<<60;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _overload3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPARR(i,v) for(int i=0;i<v.size();++i)
#define all(v) (v).begin(),(v).end()
#define uniq(v) sort(all(v));v.erase(unique(all(v)),v.end())
#define bit(n) (1ll<<(n))
template<class T>bool chmax(T&a,const T&b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T&a,const T&b){if(a>b){a=b;return 1;}return 0;}
#define cut(n, Min, Max) max(min(n,Max),Min)
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"":"im")<<"possible"<<endl
#define Poss(n) cout<<((n)?"P":"Imp")<<"ossible"<<endl
template<typename T>ostream&operator<<(ostream&o,const vector<T>&v){for(T i:v)o<<i<<' ';return o;}
template<typename T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<typename T>ostream&operator<<(ostream&o,const set<T>&v){for(T i:v)o<<i<<' ';return o;}
template<typename T,typename U>ostream&operator<<(ostream&o,const pair<T,U>&v){o<<v.first<<' '<<v.second;return o;}

int main(){
    int n;
    cin>>n;
    double s=0;
    string u;
    double x;
    REP(i,n){
        cin>>x>>u;
        if(u=="JPY")s+=x;
        else s+=x*380000.0;
    }
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#define N 1299709
using namespace std;
int prime[N+1];

int i,j;

void init()
{
    for(i=0;i<=N;i+=2)
        prime[i]=0;
    prime[2]=1;
    prime[1]=1;
    for(i=3;i<=N;i+=2)
        prime[i]=1;
    for(i=3;i<=sqrt(N);i+=2)
    {
        if(prime[i])
            for(j=i+i;j<=N;j+=i) prime[j]=0;
    }
}

int n;

void result()
{
    if(prime[n]==1) cout<<"0"<<endl;
    else
    {
        //cout<<"taibangle"<<endl;
        int p=n,q=n;
        while(prime[p]==0)
        {
            p--;
        }
        while(prime[q]==0)
        {
            q++;
        }
        //cout<<p<<"  "<<q<<endl;
        cout<<q-p<<endl;
    }
}

int main()
{
    init();
    while(cin>>n,n)
    {
        result();
    }
    return 0;
}

Measured memory_bytes: 6236
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int H[100010];
    rep(i, N) cin >> H[i];
    int ans = 0;
    int len = 0;
    rep(i, N - 1) {
        if (H[i] >= H[i + 1]) len++;
        else len = 0;
        ans = max(len, ans);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
N,K = list(map(int, input().split()))
p = list(map(int, input().split()))
max_l = 0
Max_l = p[0:K]
S = [0]
s=0
for j in range(N):
    s += p[j]
    S.append(s)

for i in range(N-K+1):
    m = S[K+i]-S[i]
    if m > max_l:
        max_l = m



print((max_l+K)/2)

Measured memory_bytes: 24804
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <iomanip>
using namespace std;
using P = pair<int,int>;
typedef long long ll;


#define rep(i,n) for (int i=0; i<(n); i++)
const int INF =2*1e5+5;
const ll BIG = 1e9+7;
const double PI = 3.141592653589793;

int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    int ans = 0;
    int p_min = INF;
    rep(i, n) {
        p_min = min(p_min, p[i]);
        if(p_min==p[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

vector <int> a;

int main(){
    int n, x;
    cin >> n;
    while(n-- && cin >> x)
        a.push_back(x);
    reverse(a.begin(), a.end());
    int ans[a.size()];
    int st = 0, en = a.size()-1;
    for(int i = 0 ; i < a.size() ; i++)
        if(i%2 == 0) ans[st++] = a[i];
        else ans[en--] = a[i];
    for(int i = 0 ; i < a.size() ; i++)
        cout << ans[i] << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 3828
#include<stdio.h>

struct test{
    signed short mid;
    signed short fin;
    signed short re;
    unsigned char eval;
};

unsigned char evaluate(signed short mid, signed short fin, signed short re);

int main(){
    struct test test[50];
    unsigned short i;
    unsigned short count = 0;

    for(i = 0;i < 50;i++){
        scanf("%d %d %d", &test[i].mid, &test[i].fin, &test[i].re);
        if(test[i].mid == -1 && test[i].fin == -1 && test[i].re == -1){
            break;
        }
        test[i].eval = evaluate(test[i].mid, test[i].fin, test[i].re);
        count++;
    }

    for(i = 0;i < count;i++){
        printf("%c\n", test[i].eval);
    }

    return 0;
}

unsigned char evaluate(signed short mid, signed short fin, signed short re){
    signed short ssW_D_sum;
    unsigned char ubW_D_result;

    ssW_D_sum = mid + fin;

    if(mid == -1 || fin == -1){
        ubW_D_result = 'F';
    }
    else if(ssW_D_sum >= 80){
        ubW_D_result = 'A';
    }
    else if(ssW_D_sum >= 65){
        ubW_D_result = 'B';
    }
    else if(ssW_D_sum >= 50){
        ubW_D_result = 'C';
    }
    else if(ssW_D_sum >= 30){
        if(re >= 50){
            ubW_D_result = 'C';
        }
        else{
            ubW_D_result = 'D';
        }
    }
    else{
        ubW_D_result = 'F';
    }

    return ubW_D_result;
}


Measured memory_bytes: 2040
#ifdef __LOCAL
  #define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b) {if(a<b) {a=b; return true;} return false;}
template<typename T> bool chmin(T &a,T b) {if(a>b) {a=b; return true;} return false;}
#define itn int
#define fi first
#define se second
#define intmax numeric_limits<int>::max()
#define llmax numeric_limits<ll>::max()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>=1;i--)
#define all(vec) vec.begin(),vec.end()
#define sortt(vec) sort((vec).begin(),(vec).end())
#define rsort(vec) sort((vec).rbegin(), (vec).rend())
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;
const ll lnf=1ll<<60;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

const int MAX=2e6+1; //nCrのnのMAX+1
ll fac[MAX],finv[MAX],inv[MAX],sinv[MAX];

void cominit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  sinv[0]=0,sinv[1]=1;
  for (int i=2;i<MAX;i++){
    fac[i]=fac[i-1]*i%mod;
    inv[i]=mod-inv[mod%i]*(mod/i)%mod;
    finv[i]=finv[i-1]*inv[i]%mod;
    sinv[i]=(sinv[i-1]+inv[i]%mod)%mod;
  }
}
ll com(int n,int k){ //1≦k≦n≦10^7
  if (n<k) return 0;
  if (n<0||k<0) return 0;
  return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}

ll per(int n,int k){ //1≦k≦n≦10^7
  if (n<k) return 0;
  if (n<0||k<0) return 0;
  return fac[n]*finv[n-k]%mod;
}

//Add cominit(); in main function.

int main(){
  cominit();
  ll s; cin >> s;
  ll n=s/3;
  mint ans=0;
  rep1(i,n){
    ans+=com(s-3*i+i-1,i-1);
  }
  cout << ans << endl;
}

Measured memory_bytes: 66132
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

ll n;
vec a(2<<17);
mat G(2<<17);
vec dp(2<<17);
vec ans(2<<17);

void dfs(ll u,ll p,ll R) {
  ll l=0,r=R;
  while(r-l>1) {
    ll m=l+r>>1;
    if(dp[m]<a[u])l=m;
    else r=m;
  }
  ll pre=dp[r];
  dp[r]=a[u];
  ans[u]=R==r?R++:R-1;
  for(ll v:G[u]) if(v!=p) dfs(v,u,R);
  dp[r]=pre;
}

int main() {
  cin >> n;
  for(ll i=0;i<n;i++) cin >> a[i];
  vec u(n-1),v(n-1);
  for(ll i=1;i<n;i++) {
    ll u,v;
    cin >> u >> v;
    u--,v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  for(ll i=1;i<=n;i++) dp[i]=2e9;
  dfs(0,-1,1);
  for(ll i=0;i<n;i++) cout << ans[i] << endl;
}

Measured memory_bytes: 39312
#include<stdio.h>
#include<stdlib.h>
int main()
{
	int r=0,n,i,j,p,q,x,y,s[99][2],t[7]={3,2,1,0,-1,-2,-3};
	char m[9][9];
	scanf("%d\n",&n);
	while(r++<n)
	{
		for(i=0;i<8;i++)
			gets(m[i]);
		scanf("%d%d\n",&s[0][0],&s[0][1]);
		s[0][0]--,s[0][1]--;
		for(p=0,q=1;p<q;p++)
		{
			for(j=0;j<7;j++)
			{
				x=s[p][0]+t[j],y=s[p][1]+t[j];
				if(x<8&&x>=0&&m[s[p][1]][x]=='1')
					m[s[p][1]][x]='0',s[q][0]=x,s[q++][1]=s[p][1];
				if(y<8&&y>=0&&m[y][s[p][0]]=='1')
					m[y][s[p][0]]='0',s[q][0]=s[p][0],s[q++][1]=y;
			}
		}
		printf("Data %d:\n",r);
		for(i=0;i<8;i++)
			printf("%s\n",m[i]);
	}
	return 0;
}

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


struct edge
{
    int to;
    long length;
};

// 現在位置 i から dest までの最短経路を深さ優先探索
// これだと O(N^2) の実装なので全然間に合わない
long dfs( int i, int dest, int parent, long d, vector<edge>* V )
{
    if( i == dest ) return d;
    long ans = LONG_MAX;
    for( auto &e: V[i] ){
        if( e.to == parent ) continue;
        ans = min( ans, dfs( e.to, dest, i, d+e.length, V ) );
    }
    return ans;
}

// O(N) の実装
// 探索しながら最短距離を minLength に代入していく
void dfs2( int i, int parent, long d, vector<edge>* V, vector<long>& minLength )
{
    minLength[i] = d;
    for( auto &e: V[i] ){
        if( e.to == parent ) continue;
        dfs2( e.to, i, d+e.length, V , minLength);
    }
}


int main()
{
    int N, Q, K;
    cin >> N;
    vector<int> a(N-1), b(N-1), c(N-1);
    for( int i = 0; i < N-1; ++i ) cin >> a[i] >> b[i] >> c[i];
    cin >> Q >> K;
    vector<int> x(Q), y(Q);
    for( int i = 0; i < Q; ++i ) cin >> x[i] >> y[i];


    vector<edge> V[100001];
    for( int i = 0; i < N-1; ++i ){
        V[a[i]].push_back( (edge){b[i], c[i]} );
        V[b[i]].push_back( (edge){a[i], c[i]} );
    }

    vector<long> minLength(N+1);
    dfs2( K, -1, 0, V, minLength );
    
    for( int i = 0; i < Q; ++i ){
        cout << minLength[x[i]] + minLength[y[i]] << endl;
    }

    return 0;
}

Measured memory_bytes: 19328
class Problem
  attr_accessor *(?a..?z).to_a.map(&:to_sym)
  def initialize
    @n,@a,@b = gets.split.map(&:to_i)
  end

  def solve
    [maxi, mini].join(" ")
  end

  def maxi
    [a,b].min
  end

  def mini
    [a + b - n, 0].max
  end

  def show(ans)
    puts ans
  end
end

Problem.new.instance_eval do
  show(solve)
end

Measured memory_bytes: 14304
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef long double ld;	

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin >> n;
	vector <ll> arr(n);
	for (int z=0;z<n;z++){
		cin >> arr[z];
	}
	ll ans = 0;
	for (int z=0;z<n-2;z++){
		vector <ll> temp;
		for (int x=z;x<z+3;x++){
			temp.push_back(arr[x]);
		}
		sort(temp.begin(),temp.end());
		if (arr[z+1] == temp[1]) ans++;
	}
	cout << ans << endl;
}

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

using namespace std;

const int coin[] = {10, 50, 100, 500};
int pay;
bool first = false;;
int have[4];
int ans[4] = {0};
int min_a = 1000000;

void solve2()
{
    int h[4] = {0};
    int sum = 0;

    for (int i = 0; i < 4; i++)
        sum += coin[i] * have[i];

    int res = sum - pay;
    for (int i = 3; i >= 0; i--) {
        int t = res / coin[i];
        h[i] = t;
        res -= coin[i] * t;
    }
    for (int i = 0; i < 4; i++) {
        if (have[i] - h[i] > 0)
            ans[i] = have[i] - h[i];
        else
            ans[i] = 0;
    }
}

// 全探索
/*
void solve()
{
    for (int a = 0; a <= have[0]; a++)
        for (int b = 0; b <= have[1]; b++)
            for (int c = 0; c <= have[2]; c++)
                for (int d = 0; d <= have[3]; d++) {
                    int money = a * coin[0] + b * coin[1] +
                        c * coin[2] + d * coin[3];
                    if (money < pay)
                        continue;

                    int ress = money - pay;
                    int h[4] = {have[0] - a, have[1] - b, have[2] - c,
                                have[3] - d};


                    for (int i = 3; i >= 0; i--) {
                        int t = ress / coin[i];

                        ress -= coin[i] * t;
                        h[i] += t;
                    }
                        
                    int cnt = 0;
                    for (int i = 0; i < 4; i++)
                        cnt += h[i];
                    if (min_a > cnt) {
                        min_a = cnt;
                        ans[0] = a;
                        ans[1] = b;
                        ans[2] = c;
                        ans[3] = d;
                    }
                }
}
*/

int main()
{
    while (cin >> pay, pay) {

        if (first)
            cout << endl;

        for (int i = 0; i < 4; i++)
            cin >> have[i];
//        solve();
        solve2();
        
        for (int i = 0; i < 4; i++)
            if (ans[i] != 0)
                cout << coin[i] << " " << ans[i] << endl;
        first = true;
    }

    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  string s;
  int T;
  cin >> s >> T;
  deque<char> que;
  rep(i,s.size()) que.push_back(s[i]);
  int t=0;
  while(T--) {
    int z;
    R z;
    if(z==1) t^=1;
    else {
      int x;
      char c;
      cin >> x >> c;
      if((x+t)%2) que.push_front(c);
      else que.push_back(c);
    }
  }
  s="";
  while(!que.empty()) {
    s+=que.front();que.pop_front();
  }
  if(t) reverse(all(s));
  pr(s);
}

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


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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++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 irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;

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 ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,m; cin>>n>>m;
  vector<vpll> G(n);
  rep(i,m){
    ll a,b,c; cin>>a>>b>>c;
    a--,b--;
    G[a].emplace_back(b,c);
    G[b].emplace_back(a,-c);
  }
  vll dist(n);
  vector<bool> visited(n);
  rep(i,n){
    queue<ll> q;
    q.push(i);
    visited[i]=true;
    while(!q.empty()){
      ll v=q.front();
      q.pop();
      for(auto np: G[v]){
        ll nv=np.first, nc=np.second;
        if(!visited[nv]){
          visited[nv]=true;
          dist[nv]=dist[v]+nc;
          q.emplace(nv);
        }else if(dist[nv]!=dist[v]+nc){
          cout<<"No"<<endl;
          return 0;
        }
      }
    }
  }

  cout<<"Yes"<<endl;
}

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

int main() {
  int X, A;
  cin >> X >> A;
  if (X < A)
    cout << 0 << endl;
  else
    cout << 10 << endl;

  return 0;
}

Measured memory_bytes: 256
n = int(input())
s = input()
 
r_cnt = s.count('R')
g_cnt = s.count('G')
b_cnt = s.count('B')
 
ans = r_cnt * g_cnt * b_cnt
 
for i in range(n):
    for d in range(n):
        j = i + d
        k = j + d
        if k >= n:break
        if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            ans -= 1
 
print(ans)

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifdef DEBUG
        freopen("in.txt", "r", stdin);
    #endif
    
    double total = 0;
    int n; cin >> n;
    while (n--) {
        double x; string u; cin >> x >> u;
        if (u == "JPY") {
            total += x;
        } else {
            total += (double)380000 * x;
        }
    }
    
    cout << total << '\n';
    
    return 0;
}


Measured memory_bytes: 256