akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setpercision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
template<class T> inline bool chmin(T& a, T b){
    if(a>b){a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){
    if(a<b){a=b;return true;}return false;}
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main(){
    double a,b;cin>>a>>b;
    ll p=a,q=b;
    cout<<p/q<<" "<<p%q<<" "<<fixed<<setprecision(6)<<a/b<<endl;
    return 0;
}


Measured memory_bytes: 3272
n,k = map(int,input().split())
A = [int(i) for i in input().split()]
A.sort()
F = [int(i) for i in input().split()]
F.sort(reverse=True)

left = -1
right = 10**12
def f(x): return sum(max(A[i]-x//F[i],0) for i in range(n)) <= k
    
while right - left > 1:
    mid = (left+right)//2
    if f(mid): right = mid
    else: left = mid
print(right)

Measured memory_bytes: 119500
use proconio::input;
//use itertools::Itertools;

fn main() {
    input!{n : i128};
    let b_max = |n: i128, a: i128| (n - 1) / a;
    let res : i128 = (1..n).map(|a| b_max(n, a)).sum();
    println!("{}", res);
}

Measured memory_bytes: 2160
#include <iostream>

using namespace std;

int main()
{
    long long A, B;
    cin >> A >> B;
    if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0)
    {
        cout << "Possible" << endl;
    }
    else
    {
        cout << "Impossible" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <climits>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
struct NODE{
	vector<int> to,cost;
};
typedef vector<NODE> G;

int n;

void gentree(G& g,bool done[20],int connect[20][20],int pos){
	rep(i,n){
		if(connect[pos][i] != -1 && done[i] == false){
			g[pos].to.push_back(i);
			g[pos].cost.push_back(connect[pos][i]);
			done[i] = true;	
			gentree(g,done,connect,i);
		}
	}
}


bool find(G &g,int pos,int want){
	if(pos == want)return true;
	
	bool ret = false;
	rep(i,g[pos].to.size())
		ret |= find(g,g[pos].to[i],want);
	return ret;
}

int getCost(G &g,int pos){
	
	int ret = 0;
	rep(i,g[pos].to.size()){
		if( g[g[pos].to[i]].to.size() )
			ret += getCost(g,g[pos].to[i]) + g[pos].cost[i]*2; 
	}
	return ret;
}

int count = 0;

void dfs(G &g,int pos , int end){
	int atode = -1;
	rep(i,g[pos].to.size()){
		if(find(g,g[pos].to[i],end) == true){
			atode = i;
			continue;
		}
		if(g[g[pos].to[i]].to.size()){
			count += getCost(g,g[pos].to[i]) + g[pos].cost[i]*2;
		}
	}
	if(~atode){
		count += g[pos].cost[atode];
		dfs(g,g[pos].to[atode],end);
	}
	return;
}	
	
int main(){
	while(cin >> n,n){
		int connect[20][20];
		rep(i,20)rep(j,20)connect[i][j] = -1;
		rep(i,n-1){
			int a,b,c;cin >> a >> b >> c;
			a--,b--;
			connect[a][b] = connect[b][a] = c;
		}
		int ret = INT_MAX;
		rep(i,n){
			bool done[20] = {0};
			G graph(n);
			done[i] = true;	
			gentree(graph,done,connect,i);
		
			count = 0;
			dfs(graph,i,0);
			ret = min(count,ret);
		}
		cout << ret << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> buttons(N);
  
  for (int n = 0; n < N; n++) cin >> buttons.at(n);
  int answer = 0;
  int pushedButton = 0;
  for (int n = 0; n < N; n++) {
    answer++;
    if (buttons.at(pushedButton) == 2) {    
      cout << answer << endl;
      return 0;
    } else {
      pushedButton = buttons.at(pushedButton) - 1;
    }
  }
  cout << -1 << endl;
}


Measured memory_bytes: 3776
n,k=map(int,input().split())
x = list(map(int,input().split()))
sd=100000000
if n==k:
  sd=min(abs(x[0])+abs(x[0]-x[k-1]),abs(x[k-1])+abs(x[0]-x[k-1]))
else:
  for i in range(n-k+1):
    d=min(abs(x[i])+abs(x[i]-x[i+k-1]),abs(x[i+k-1])+abs(x[i]-x[i+k-1]))
    if sd>d:
      sd=d
print(sd)

Measured memory_bytes: 14564
#include<bits/stdc++.h>
using namespace std;
#define Set(a,b) memset(a,b,sizeof(a))
template<class T>inline void init(T&x){
	x=0;char ch=getchar();bool t=0;
	for(;ch>'9'||ch<'0';ch=getchar()) if(ch=='-') t=1;
	for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+(ch-48);
	if(t) x=-x;return;
}typedef long long ll;
const int N=2e5+10;
int n,m;
int L[N],R[N];
priority_queue<int> Q;
int id[N];
inline bool cmp(int i,int j){return L[i]<L[j]||(L[i]==L[j]&&R[i]>R[j]);}
int stk[N],top=0;
int main()
{
	init(n),init(m);
	for(int i=1;i<=n;++i) init(L[i]),init(R[i]),id[i]=i;
	sort(id+1,id+1+n,cmp);int h=1;
	int mat=0;
	for(int i=1;i<=n;++i) {
		int u=id[i];
		if(L[u]>=h&&h<=m) Q.push(-R[u]),++h,++mat;
		else if(!Q.empty()){
			int r=-Q.top();
			if(R[u]<=r) stk[++top]=R[u];
			else Q.pop(),Q.push(-R[u]),stk[++top]=r;
		}else stk[++top]=R[u];
	}
	sort(stk+1,stk+1+top);reverse(stk+1,stk+1+top);
	int t=m;
	for(int i=1;i<=top;++i) if(t>=h&&stk[i]<=t) --t,++mat;
	printf("%d\n",n-mat);
}


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

using namespace std;

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

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = i64(1e9) + 7;

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

  i64 N, M;
  cin >> N >> M;

  if (abs(N - M) >= 2) {
    cout << 0 << "\n";
    return 0;
  }

  i64 fact[100010];
  fact[0] = 1;
  i64 maxv = max(N, M);
  for (i64 i = 1; i <= maxv; ++i) {
    fact[i] = fact[i-1];
    fact[i] *= i;
    fact[i] %= MOD;
  }

  i64 ans;
  if (N == M) ans = fact[N] * fact[M] % MOD * 2 % MOD;
  else ans = fact[N] * fact[M] % MOD;

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;

#define MOD 1000000007
#define INF 1e9+7
#define rep(i, n) for(int i=0; i<n; ++i)
typedef long long ll;

#define MAX_N 100000
#define MAX_M 100000
#define MAX_V 100
#define MAX_E 100

int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};

int ddx[] = {-1, 0, 1, 0, -1, 1, -1, 1};
int ddy[] = {0, -1, 0, 1, 1, 1, -1, -1};

//--------------------------



int main() {

  int k, x;
  cin >> k >> x;

  for(int i=x-k+1; i<=x+k-1; ++i) {
    if(i==x+k) cout << i << endl;
    else cout << i << " ";
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
	long a[4];
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	if(a[0]%2+a[1]%2+a[2]%2==3)cout<<a[0]*a[1]<<endl;
	else cout<<"0"<<endl;
	return 0;
}

Measured memory_bytes: 256
a=int(input())
b=int(input())
c=int(input())
x=[[0,0,0] for _ in range(3)]
for i in range(-300,301):
    x[0][0]=a
    x[0][1]=b
    x[1][1]=c
    x[0][2]=i-a-b
    x[2][2]=i-a-c
    x[2][1]=i-b-c
    x[1][2]=i-x[0][2]-x[2][2]
    x[1][0]=i-c-x[1][2]
    x[2][0]=i-x[2][1]-x[2][2]
    ok = True
    for j in range(3):
        t=0
        s=0
        for k in range(3):
            t+=x[j][k]
            s+=x[k][j]
        ok = ok and (t==i) and (s==i)
    ok = ok and (x[0][0]+x[1][1]+x[2][2]==i) and (x[0][2]+x[1][1]+x[2][0]==i)
    if not ok:
        continue
    for j in range(3):
        print(x[j][0],x[j][1],x[j][2])
    break

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

#define ll long long
#define ld long double
#define ull unsigned long long
#define endl "\n"
#define MohamedMotaz ios::sync_with_stdio(0); cin.tie(0); ios_base::sync_with_stdio(0);

using namespace std;









int main()
{
	MohamedMotaz;
	ll x;
	cin >> x;
	cout << ceil(x / 2.0);


}





















Measured memory_bytes: 384
n,k=map(int,input().split())
s=list(input())
li=[]
if s[0]=="0":
  a=0
  s.insert(0,"p")
  len_s=len(s)
  for i in range (1,len_s):
    if s[i-1]==s[i]:
      a=a+1
    else:
      li.append(a)
      a=1
  li.append(a)
  if s[n-1]=="0":
    li.append(0)
else:
  a=1
  len_s=len(s)
  for j in range (1,len_s):
    if s[j-1]==s[j]:
      a=a+1
    else:
      li.append(a)
      a=1
  li.append(a)
  if s[n-1]=="0":
    li.append(0)
len_li=len(li)
lis=[0]
t=0
for l in range (0,len_li):
  t=t+li[l]
  lis.append(t)
if 2*k+1>=len_li:
  print(n)
elif k==0:
  import math
  o=math.ceil(len_li/2)
  le=[]
  for f in range (0,o):
    le.append(li[2*f])
    le.sort()
  print(le[len(le)-1])
else:
  import math
  u=0
  w=0
  while w<=len(lis)-2*k-2:
    d=lis[w+2*k+1]-lis[w]
    if u<=d:
      u=d
    w=w+2
  print(u)


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

int main(){
	int w,h;
	cin>>h>>w;
	char **block;
	int **res;
	block = new char*[h];
	res = new int*[h];
	for(int i = 0;i < h;i++){
		block[i] = new char [w+1];
		res[i] = new int [w+1];
	}
	for(int ww = 0;ww < w;ww++){
		for(int hh = 0;hh < h;hh++){
			cin>>block[hh];
		}
	}
	for(int i = 0;i < h;i++){
		int l = -1;
		for(int j = 0;j < w;j++){
			if(block[i][j] == 'c'){
				res[i][j] = 0;
				l = 0;
			}else{
				if(l != -1){
					res[i][j] = ++l;
				}else{
					res[i][j] = -1;
				}
			}
		}
	}
	for(int hh = 0;hh < h;hh++){
		for(int ww = 0;ww < w;ww++){
			cout<<res[hh][ww];
			if(ww != w-1){
				cout<<" ";
			}
		}
		cout<<endl;
	}

	for(int i = 0;i < h;i++){
		delete [] block[i];
		delete [] res[i];
	}
	delete [] block;
	delete [] res;

	return 0;
}

Measured memory_bytes: 1252
#include<stdio.h>
#define N 2000001

int B[N];

main(){
  int i, j, k = 0, n, A[N], C[10001];
  scanf("%d", &n);
  for(i = 1;i < n+1;i++){
    scanf("%d", &A[i]);
    if(A[i] > k){
      k = A[i];
    }
  }
  for(i = 0;i < k+1;i++){
    C[i] = 0;
  }
  for(j = 1;j < n+1;j++){
    C[A[j]]++;
  }
  for(i = 1;i < k+1;i++){
    C[i] = C[i] + C[i-1];
  }
  for(j = n;j > 0;j--){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
  for(i = 1;i < n;i++){
    printf("%d ", B[i]);
  }
  printf("%d\n", B[n]);
  return 0;
}

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

#define ll long long
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;


int main() {
    int N,K;
    cin >> N >> K;
    int a[100];
    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    sort(a, a + N, greater<int>());
    int sum =0;
    for(int j=0;j<K;j++){
        sum += a[j];
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef string str;

int main(){
  ll n;
  cin >> n;
  ll ans = 0;
  REP(i,n){
    ll l,r;
    cin >> l >> r;
    ans += r-l+1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
MAX = 1_000_000

is_prime = [false, false] + [true] * (MAX - 1)

sqrt_n = Math.sqrt(MAX).ceil
(2..sqrt_n).each do |i|
  j = i*i
  loop do
    is_prime[j] = false
    j += i
    break if j > MAX
  end
end

prime_count_list = [0, 0]
count = 0
2.upto(MAX) do |i|
  count += 1 if is_prime[i]
  prime_count_list[i] = count
end

while num = gets.to_i
  return if num == 0
  puts prime_count_list[num]
end

Measured memory_bytes: 31704
#include <stdio.h>
#include <ctype.h>
 
int main(void){
     
    char ch;
    while(1){
        scanf("%c",&ch);
        if(isupper(ch)!=0){
            ch=tolower(ch);
            printf("%c",ch);
        }else if(islower(ch)!=0){
            ch=toupper(ch);
            printf("%c",ch);
        }else{
            printf("%c",ch);
        }
        if(ch=='\n') break;
    }
    return 0;
}


Measured memory_bytes: 2076
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl;
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   " << endl;
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}
 
int main(){
	int N, P;
	cin >> N >> P;
	string S;
	cin >> S;
	reverse(S.begin(), S.end());//*pow(10, i)したときにiがindexと一致するようにする
  if(P==2 || P==5){
		ll ans = 0;
		for(int i=0; i<N; i++){
			if((S[i]-'0')%P !=0) continue;
			//ans += i+1;
      ans += N-i;
		}
		cout << ans << endl;
		return 0;
	}

	

	int wa = 0;//累積和
	int pow_10_i = 1;// pow(10, i)%P
	map<int, int> mp;
	ll ans = 0;
	for(int i=0; i<N; i++){
		mp[wa]++;
		wa += (S[i]-'0')*pow_10_i;
		wa %= P;
		ans += mp[wa];
		pow_10_i = pow_10_i * 10 % P;
	}


	cout << ans << endl;


}


Measured memory_bytes: 4056
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
//typedef __int64 LL;
typedef long long int LL;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef pair<int,int> P;
//typedef pair<LL,LL> PL;

LL INF=100000000000000;

LL d[310][310];
LL e[310][310];
int main(){
	LL n,m,l;
	cin>>n>>m>>l;
	
	for(LL i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(i==j)d[i][j]=0;
			else d[i][j]=INF;
		}
	}
	for(LL i=0;i<m;i++)
	{
		LL a,b,c;
		cin>>a>>b>>c;
		a--,b--;
		d[a][b]=c;
		d[b][a]=c;
	}
	
	for(LL k=0;k<n;k++)
		for(LL i=0;i<n;i++)
			for(LL j=0;j<n;j++)d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
	
	for(LL i=0;i<n;i++)
	{
		for(LL j=0;j<n;j++)
		{
			e[i][j]=INF;
			if(i==j)e[i][j]=0;
			else if(d[i][j]<=l)e[i][j]=1;
		}
	}
	
	for(LL k=0;k<n;k++)
		for(LL i=0;i<n;i++)
			for(LL j=0;j<n;j++)e[i][j]=min(e[i][j],e[i][k]+e[k][j]);
			
			
	LL q;
	cin>>q;
	for(LL i=0;i<q;i++)
	{
		LL s,t;
		cin>>s>>t;
		s--,t--;
		if(e[s][t]==INF)cout<<-1<<"\n";
		else cout<<e[s][t]-1<<"\n";
	} 
	return 0;
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
int a[500001],f[500001],dp[500001];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%1d",&a[i]);
	for(int i=1;i<=n;i++)
	{
		if(a[i]==0)
			f[i]=i;
		else
			f[i]=f[i-1];
	}
	for(int i=1;i<=n;i++)
	{
		dp[i]=dp[i-1];
		if(a[i]==1)
		{
			if(a[i-1]==0&&a[i-2]==1)
				dp[i]=max(dp[i],max(dp[f[i-2]]+i-2-f[i-2],dp[f[i-2]+1]+i-2-f[i-2]-1));
			else if(f[i]>1&&a[f[i]-1]==1)
				dp[i]=max(dp[i],dp[f[i]-2]+i-f[i]);
		}
	}
	printf("%d\n",dp[n]);
	return 0;
}


Measured memory_bytes: 6144
#pragma GCC optimize("Ofast")   //Comment optimisations for interactive problems (use endl)
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define  fastio         ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  randomINIT     mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define  foo(i,a,n)     for(ll i = (a); i <= n; i++)
#define  frr(i,a,n)     for(ll i = (a); i >= n; i--)
#define  fo(i,n)        for(ll i = 0; i < n; i++)
#define  all(x)         (x).begin(),(x).end()
#define  mset(x,val)    memset(x,val,sizeof(x))
#define  newl           cout<<"\n"
#define  pb             push_back
#define  mp             make_pair
#define  s              second
#define  f              first
#define  dline          cerr<<"///REACHED///\n";
#define  deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define  deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define  deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;

const ll   MOD   =  1e+9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;
const ll   MAXN  =  1e+5+7;

vll adj[MAXN];ll visit[MAXN]={};
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1};
int dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};

//<<-----Declare Variable Here------->>//
int t=1;
char s[1005][1005];
ll dp[1005][1005];
ll h,w;
//<<-----Implement Functions Here---->>//
ll solve(ll x,ll y)
{
	if(x>h-1||y>w-1)return 0;
	else if(s[x][y]=='#')return dp[x][y] = 0;
	else if(x==h-1&&y==w-1)return dp[x][y] = 1;
	else if(dp[x][y]!=-1)return dp[x][y];
	else return dp[x][y] = (solve(x+1,y)%MOD+solve(x,y+1)%MOD)%MOD;
}

//<<-----Start of Main--------------->>//
void MAIN(){
		cin>>h>>w;mset(dp,-1);
		for(ll i=0;i<h;i++){for(ll j=0;j<w;j++)cin>>s[i][j];}
		cout<<solve(0,0);
		
}

int main(){
	fastio;randomINIT;

	//cin>>t;
	while(t--){
		MAIN();
	}

    
}

Measured memory_bytes: 12288
n = int(input())
A = [int(input()) for _ in range(n)]
B = sorted(A)
B_M = max(B)
B_M_1 = max(B[:n-1])
for i in range(n):
    if A[i] == B_M:
       print(B_M_1)
    else:
        print(B_M)

Measured memory_bytes: 14136
#ifndef call_from_test
#include<bits/stdc++.h>
using namespace std;
#endif
//BEGIN CUT HERE
template<typename T>
struct DiameterForVertex{
  vector<T> vs,dp;
  vector<vector<int> > G;
  DiameterForVertex(int n):dp(n),G(n){}
  DiameterForVertex(vector<T> vs):vs(vs),dp(vs.size()),G(vs.size()){}

  void add_edge(int u,int v){
    G[u].emplace_back(v);
    G[v].emplace_back(u);
  }

  void dfs(int v,int p,int &s){
    if(p<0) dp[v]=T(0);
    dp[v]+=vs[v];
    if(dp[s]<dp[v]) s=v;
    for(int u:G[v]){
      if(u==p) continue;
      dp[u]=dp[v];
      dfs(u,v,s);
    }
  }

  T build(){
    assert(!vs.empty());
    int s=0;
    dfs(s,-1,s);
    dfs(s,-1,s);
    return dp[s];
  }

  T build(vector<T> us){
    assert(us.size()==dp.size());
    vs=us;
    return build();
  }
};
//END CUT HERE
#ifndef call_from_test
struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;

//INSERT ABOVE HERE

signed AGC033_C(){
  int n;
  cin>>n;
  vector<int> vs(n,1);
  DiameterForVertex<int> G(vs);
  for(int i=1;i<n;i++){
    int x,y;
    cin>>x>>y;
    x--;y--;
    G.add_edge(x,y);
  }
  int ans=G.build();
  cout<<((ans%3!=2)?"First":"Second")<<endl;
  return 0;
}
/*
  verified on 2019/05/07
  https://atcoder.jp/contests/agc033/tasks/agc033_c
*/

signed ARC097_F(){
  int n;
  cin>>n;
  DiameterForVertex<int> G(n);
  vector<int> deg(n,0);
  for(int i=1;i<n;i++){
    int x,y;
    cin>>x>>y;
    x--;y--;
    G.add_edge(x,y);
    deg[x]++;
    deg[y]++;
  }

  string s;
  cin>>s;

  int cnt=(n-1)*2,num=0;
  queue<int> que;
  vector<int> dead(n,0);
  for(int i=0;i<n;i++){
    num+=(s[i]=='W');
    if((deg[i]==1)&&(s[i]=='B')){
      dead[i]=1;
      que.emplace(i);
    }
  }

  while(!que.empty()){
    int v=que.front();que.pop();
    cnt-=2;
    for(int u:G.G[v]){
      if(dead[u]) continue;
      deg[u]--;
      if(deg[u]==1&&(s[u]=='B')){
        dead[u]=1;
        que.emplace(u);
      }
    }
  }

  if(num<=1){
    cout<<num<<endl;
    return 0;
  }

  vector<int> vs(n,0);
  for(int i=0;i<n;i++){
    if(dead[i]) continue;
    vs[i]=deg[i]+(s[i]=='W');
    vs[i]%=2;
    cnt+=vs[i];
  }

  cout<<cnt-G.build(vs)*2<<endl;
  return 0;
}
/*
  verified on 2019/05/07
  https://atcoder.jp/contests/arc097/tasks/arc097_d
*/

signed main(){
  AGC033_C();
  //ARC097_F();
  return 0;
}
#endif


Measured memory_bytes: 20208
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

int const N = 2000 + 5 ;
int n , k , ans = N ;
vector <int> g[N] ;

int dfs (int v , int cc , int par = -1, int h = 0) {
	int ret = 0 ;
	if (h > k) ret ++ ;

	for (int u : g[v])
		if (u != par)
			ret += dfs(u , cc , v , h + (u != cc)) ;

	return ret ;
}

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

	cin >> n >> k ;
	for (int i = 0 ; i < n - 1 ; i ++) {
		int u , v ;
		cin >> u >> v ;
		u -- , v -- ;
		g[u].push_back(v) ;
		g[v].push_back(u) ;
	}

	if (k & 1) {
		k /= 2 ;
		for (int i = 0 ; i < n ; i ++)
			for (int j : g[i])
				ans = min(ans , dfs(i , j)) ;
	}
	else {
		k /= 2 ;
		for (int i = 0 ; i < n ; i ++) {
			ans = min(ans , dfs(i , -1)) ;
		}
	}

	cout << ans << '\n' ;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
const int INF = 100100100;
using namespace std;

int main()
{
  int A, B, C ,D;
  cin >> A >> B >> C >> D;

  int l = A+B;
  int r = C+D;
  if(l>r) cout << "Left" << endl;
  else if(l==r)cout << "Balanced" << endl;
  else cout << "Right" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 50
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S;
ll ans = 0;

int main() {
	cin >> N;
	vector<int>A(N+2,0);
	for (int i = 1; i <= N; i++) {
		cin >> A[i];
		ans += abs(A[i] - A[i - 1]);
	}
	ans += abs(A[N]);
	for (int i = 1; i <= N; i++) {
		ll tmp = ans;
		tmp = tmp + abs(A[i + 1] - A[i - 1]) - abs(A[i] - A[i - 1]) - abs(A[i] - A[i + 1]);
		cout << tmp << endl;
	}
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

namespace
{
	int rec(int i, vi& dp, const vvi& G)
	{
		if (dp[i] != -1)
			return dp[i];
		int res = 0;
		for (auto x : G[i])
		{
			res = max(res, rec(x, dp, G) + 1);
		}
		dp[i] = res;
		return res;
	}
}
void EducationalDP_G()
{
	int N, M;
	cin >> N >> M;
	vvi G(N);

	for (int i = 0; i < M; ++i)
	{
		int x, y;
		cin >> x >> y;
		--x; --y;
		G[x].push_back(y);
	}
	vi dp(N, -1);
	int ret = 0;
	for (int i = 0; i < N; ++i)
		ret = max(ret, rec(i, dp, G));
	cout << ret << endl;
}
int main()
{
	EducationalDP_G();
	return 0;
}

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int gcd(int a, int b) {
	while (a && b) {
		if (a > b) a %= b;
		else b %= a;
	}
	return a + b;
}

int main() {
	int a = ri();
	int b = ri();
	std::cout << (int64_t) a * b / gcd(a, b) << std::endl;
	return 0;
}



Measured memory_bytes: 256
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

int ans[200111];
bool used[200111];
int main()
{
	int n,x;
	get2(n,x);
	if(x==1||x==n+n-1)
	{
		puts("No");
		return 0;
	}
	if(n==2)
	{
		puts("Yes\n1 2 3");
		return 0;
	}
	if(x==n+n-2){ans[n]=x;ans[n-1]=x+1;ans[n+1]=x-1;ans[n-2]=x-2;}
	else{ans[n]=x;ans[n-1]=x-1;ans[n+1]=x+1;ans[n-2]=x+2;}
	for(int i=1;i<n+n;i++)if(ans[i])used[ans[i]]=1;
	int cur=1;
	for(int i=1;i<n+n;i++)
	{
		if(ans[i])continue;
		while(used[cur])cur++;
		ans[i]=cur;
		used[cur]=1;
	}
	puts("Yes");
	for(int i=1;i<n+n;i++)printendl(ans[i]);
	return 0;
}

Measured memory_bytes: 2432
using System;
using System.Linq;

namespace ITP1_11_D {
    class Dice {
        private int[] _dice;

        public Dice(int[] dice) {
            _dice = dice;
        }

        public bool IsSame(int[] arr) {
            string dir = "ENENEN";
            string turn = "RRRR";
            foreach (var d in dir) {
                foreach (var t in turn) {
                    if (_dice.SequenceEqual(arr))
                        return true;
                    Move(t);
                }
                Move(d);
            }
            return false;
        }

        public void Move(char dir) {
            switch (dir) {
                case 'E':
                    Replace(0, 3, 5, 2);
                    break;
                case 'W':
                    Replace(0, 2, 5, 3);
                    break;
                case 'N':
                    Replace(0, 1, 5, 4);
                    break;
                case 'S':
                    Replace(0, 4, 5, 1);
                    break;
                case 'R':
                    Replace(1, 3, 4, 2);
                    break;
            }
        }

        private void Replace(int a, int b, int c, int d) {
            int temp = _dice[a];
            _dice[a] = _dice[b];
            _dice[b] = _dice[c];
            _dice[c] = _dice[d];
            _dice[d] = temp;
        }
    }

    class Program {
        static void Main(string[] args) {
            int n = int.Parse(Console.ReadLine());
            int[] source = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            Dice dice = new Dice(source);
            bool isWrong = true;
            for(int i = 1; i < n; i++) {
                int[] input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                if (dice.IsSame(input)) {
                    isWrong = false;
                    break;
                }
            }
            Console.WriteLine(isWrong ? "Yes" : "No");
        }
    }
}

Measured memory_bytes: 9928
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, FastReader s, PrintWriter out) {
            int a = s.nextInt();
            int b = s.nextInt();
            int c = s.nextInt();
            if (a + b + c >= 22) {
                out.println("bust");
            } else {
                out.println("win");
            }
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



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

int main(void){
	int P,Q,R;
  	int T[3];
	int ans = 1000;
	cin >> P >> Q >> R;
	T[0] = P + Q;
	T[1] = Q + R;
    T[2] = R + P;

  	for (int i = 0; i < 3; i++){
		if( ans > T[i]) ans = T[i];
    }

	cout << ans;
	
  
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
#define maxn 100005
#define sentinel 2000000000
struct card
{
    char suit;
    int value;
};
typedef struct card card;

card L[maxn/2],R[maxn/2];
card a[maxn],b[maxn];
int n;

void _merge(int left,int mid,int right)
{
    int n1=mid-left;
    int n2=right-mid;
    for(int i=0;i<n1;++i)
        L[i]=a[left+i];
    for(int i=0;i<n2;++i)
        R[i]=a[mid+i];
    L[n1].value=R[n2].value=sentinel;
    int i=0,j=0;
    for(int k=left;k<right;k++)
    {
        if(L[i].value<=R[j].value)
            a[k]=L[i++];
        else
            a[k]=R[j++];
    }
}
void mergesort(int n,int left,int right)
{
    int mid;
    if(left+1<right)
    {
        mid=(left+right)>>1;
        mergesort(n,left,mid);
        mergesort(n,mid,right);
        _merge(left,mid,right);
    }
}
int _partition(int n,int p,int r)
{
    card x=b[r];
    int i=p-1;
    for(int j=p;j<r;j++)
    {
        if(b[j].value<=x.value)
        {
            i++;
            card t=b[i];
            b[i]=b[j];
            b[j]=t;
        }
    }
    card t=b[i+1]; b[i+1]=b[r];b[r]=t;
    return i+1;
}
void quicksort(int n,int p,int r)
{
    int q;
    if(p<r)
    {
        q=_partition(n,p,r);
        quicksort(n,p,q-1);
        quicksort(n,q+1,r);
    }
}
int main()
{
    int stable=1;
    scanf("%d",&n);
    for(int i=0;i<n;++i)
    {
        char str[3];
        int x;
        scanf("%s %d",str,&x);
        a[i].suit=b[i].suit=str[0];
        a[i].value=b[i].value=x;
    }
    mergesort(n,0,n);
    quicksort(n,0,n-1);
    for(int i=0;i<n;++i)
    {
        if(a[i].suit!=b[i].suit) stable=0;
    }
    if(stable) printf("Stable\n");
    else printf("Not stable\n");
    for(int i=0;i<n;++i)
    {
        printf("%c %d\n",b[i].suit,b[i].value);
    }
    return 0;
}

Measured memory_bytes: 5096
#pragma GCC optimize("Ofast")
#include<stdio.h>
#include<algorithm>
using namespace std;
int cost[15],num[15][15],temp[15];
int main(){
	int i,j,n,m,k,l,ans;
	scanf("%d%d%d",&n,&m,&k);
	ans=100000000;
	for(i=0;i<n;i++){
		scanf("%d",&cost[i]);
		for(j=0;j<m;j++)
			scanf("%d",&num[i][j]);
	}
	for(i=0;i<(1<<n);i++){
		for(j=0;j<m;j++)
			temp[j]=0;
		int cnt=0;
		for(j=0;j<n;j++){
			if(!(i>>j&1))
				continue;
			cnt+=cost[j];
			for(l=0;l<m;l++)
				temp[l]+=num[j][l];
		}
		bool right=1;
		for(j=0;j<m;j++)
			if(temp[j]<k)
				right=0;
		if(right)
			ans=min(ans,cnt);
	}
	if(ans==100000000)
		puts("-1");
	else
		printf("%d\n",ans);
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
#define mp(a,b) make_pair(a,b)
#define ff first
#define setp(a) setprecision(a)<<fixed
#define ss second
#define fori(v) for(int i=0; i<v; i++)
#define forj(v) for(int j=0; j<v; j++)
#define fork(v) for(int k=0; k<v; k++)
#define forl(v) for(int l=0; l<v; l++)
#define fort(v) for(int t=0; t<v; t++)
#define forz(v) for(int z=0; z<v; z++)
#define ll long long 
#define MAX (int)(pow(10,7) + 10)
#define dim 3
#define pb(a) push_back(a)
// #define cout out
// #define cin in
ll inf = pow(10,18);
ll modulo = pow(10,9) + 7;
double eps = 1e-6;
ifstream in;
ofstream out;


void deal(){
	ll n , m , k;
	cin>>n>>m>>k;
	vector<vector<ll> > g(n, vector<ll>() );
	vector<vector<ll> > bl(n, vector<ll>());
	fori(m){
		ll a,b;
		cin>>a>>b;
		--a, --b;
		g[a].pb(b);
		g[b].pb(a);
	}
	
	fori(k){
		ll a,b;
		cin>>a>>b;
		--a, --b;
		bl[a].pb(b);
		bl[b].pb(a);
	}
	vector<bool> seen(n, 0);
	vector<ll> ans(n, 0);
	fori(n){
		if(!seen[i]){
			vector<ll> bfs(1, i);
			set<ll> cur;
			forj(bfs.size()){
				auto hd = bfs[j];
				cur.insert(hd);
				for(auto& hr : g[hd]){
					if(!seen[hr]){
						seen[hr] = 1;
						bfs.pb(hr);
					}
				}
			}
			fori(bfs.size()){
				set<ll> both;
				ll hd = bfs[i];
				forj(g[hd].size()){
					ll hr = g[hd][j];
					if(cur.find(hr)!=cur.end()){
						both.insert(hr);
					}
				}
				
				forj(bl[hd].size()){
					ll hr = bl[hd][j];
					if(cur.find(hr)!=cur.end()){
						both.insert(hr);
					}
				}
				ans[hd] = cur.size() - both.size();
			}
		}
	}
	fori(n){
		cout<<ans[i]-1<<' ';
	}
}

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	deal();
}



/* 
6 8 
1 2
2 3
3 4
4 1
2 5
3 5
1 6
4 6
*/

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

using i64 = int_fast64_t;
using f64 = double;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

template<i64 M>
struct modint {
    i64 x;

    constexpr modint(const i64 y = 0) noexcept : x(y >= 0 ? y % M : (M - (-y) % M) % M) {}

    constexpr modint operator-() const noexcept { return modint(-x); }
    constexpr modint operator+(const modint &rhs) const noexcept { return modint(*this) += rhs; }
    constexpr modint operator-(const modint &rhs) const noexcept { return modint(*this) -= rhs; }
    constexpr modint operator*(const modint &rhs) const noexcept { return modint(*this) *= rhs; }
    constexpr modint operator/(const modint &rhs) const noexcept { return modint(*this) /= rhs; }

    constexpr modint &operator+=(const modint &rhs) noexcept {
        x += rhs.x;
        if (x >= M) x -= M;
        return *this;
    }

    constexpr modint &operator-=(const modint &rhs) noexcept {
        if (x < rhs.x) x += M;
        x -= rhs.x;
        return *this;
    }

    constexpr modint &operator*=(const modint &rhs) noexcept {
        x = x * rhs.x % M;
        return *this;
    }

    constexpr modint &operator/=(const modint &rhs) noexcept {
        i64 a = rhs.x, b = M, u = 1, v = 0;
        while (b > 0) {
            i64 t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        *this *= u;
        return *this;
    }

    friend ostream &operator<<(ostream &os, const modint &p) {
        return os << p.x;
    }

    friend istream &operator>>(istream &is, modint &a) {
        i64 t;
        is >> t;
        a = modint(t);
        return is;
    }
};

constexpr i64 MOD = 1e9 + 7;
using m64 = modint<MOD>;

m64 modpow(m64 x, i64 n) {
    m64 res = 1;
    while (n > 0) {
        if (n & 1) res *= x;
        x *= x;
        n >>= 1;
    }
    return res;
}

void solve() {
    i64 n;
    cin >> n;
    vector<i64> h(n);
    i64 h0 = 0, h1 = 0;;
    for (auto& e : h) {
        cin >> e;
        h0 = max(h0, e);
    }
    for (auto& e : h) {
        i64 f;
        cin >> f;
        e = min(e, f);
        h1 = max(h1, e);
    }

    if (h0 != h1) {
        cout << 0 << endl;
        return;
    }

    m64 ans = 1;
    h.push_back(0);
    for (i64 l = 0, r = 1; r <= n; r++) {
        if (h[l] == h[r]) continue;
        ans *= modpow(h[l], max(0l, r - l - (h[l] != h0 ? 1 : 2)));
        l = r;
    }
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int h, w, d, q;
  cin >> h >> w >> d;
  map<int, P> mp;
  rep(i, 0, h) rep(j, 0, w) {
    int a;
    cin >> a;
    mp[a] = make_pair(i + 1, j + 1);
  }

  vector<ll> dp(h * w + 1);
  rep(i, 1, h * w + 1) {
    if (i <= d)
      continue;
    dp[i] = dp[i - d] + abs(mp[i].first - mp[i - d].first) +
            abs(mp[i].second - mp[i - d].second);
  }

  cin >> q;
  map<P, int> mpans;
  while (q--) {
    int l, r;
    cin >> l >> r;
    cout << dp[r] - dp[l] << endl;
  }
}


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

using namespace std;

const int maxN = 3000;

int R, G, B, N;
int ans[maxN + 1];

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

	cin >> R >> G >> B >> N;

	ans[0] = 1;
	for (int i = 0; i <= N - R; i++)
		ans[i + R] += ans[i];
	for (int i = 0; i <= N - G; i++)
		ans[i + G] += ans[i];
	for (int i = 0; i <= N - B; i++)
		ans[i + B] += ans[i];

	cout << ans[N] << '\n';

	return 0;
}


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

using namespace std;

#define INF 1000000

int s, e, r, n, m;

int dijk(int d[][101]) {
  int mi, i, j;
  int c[m + 1] = {};
    
  for(i = 0; i <= m; i++) {
    c[i] = INF;
  }
    
  int f[m + 1] = {};
  mi = s;
  c[s] = 0;

  for(i = 0; i < m; i++){
    f[mi] = 1;

    for(j = 0; j <= m; j++) {
      if(f[j] == 1) continue;
      if(c[j] > d[j][mi] + c[mi]) {
	c[j] = d[j][mi] + c[mi];
	//	cout << j << c[j] << endl;
      }
    }

    int MIN = INF * 2;

    for(j = 0; j <= m; j++) {
      if(f[j] == 1) continue;
      if(MIN > c[j]) {
	MIN = c[j];
	mi = j;
      }
    }
  }
  return c[e];
}

  
int main() {
  int i, j,k, a,b, cost, time;
  while(cin >> n >> m, n != 0 || m != 0) {
    int d[101][101] = {};
    int T[101][101] = {};

    
    for(i = 0; i <= m; i++) {
      for(j = 0;j <= m; j++) {
	d[i][j] = T[i][j] = INF;
      }
    }
    
    for(i = 0; i < n; i++) {
      cin >> a >> b >> cost >> time;
      d[a][b] = d[b][a] = cost;
      T[a][b] = T[b][a] = time;
    }
    
    cin >> k;
    for(i = 0; i < k; i++) {
      cin >> s >> e >> r;
      if(r == 0) cout << dijk(d) << endl;
      else cout << dijk(T) << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3108
#include<stdio.h>
#include<string.h>

int main(void){
	char s[21];
	char tmp;
	int i,n;

	scanf("%s",s);
	n=strlen(s);
	for(i=n-1;i>=0;i--){
		printf("%c",s[i]);
	}
	printf("\n");
	return 0;
}

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

#define PI 3.1415926

int main(){

  int a,b,c;
  double S,L,h;

  cin >> a >> b >> c;

  S=(double)a*b*sin((double)c/180*PI)/2;
  h=b*sin((double)c/180*PI);
  
  L= a+b+ sqrt(a*a + b*b - 2*a*b*cos((double)c/180*PI) );

  printf("%.8lf\n%.8lf\n%.8lf\n",S,L,h);

  return 0;
}

Measured memory_bytes: 1196
// #include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>

#define rep(i,n) for (int i = 0; i < n; ++i)
#define repr(i,n) for (int i = n; i > 0; --i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

const int MAX = 100;
const int INF = (1<<12);

int main() {
  int h1,m1,h2,m2,k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  int h, m;
  m = (h2 * 60 + m2) - (h1 * 60 + m1) - k;
  cout << m << endl;
  return 0;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int a, b;
    cin >> a >> b;
    
    int ans = a*b;

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

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

using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 5;
typedef pair<int, int> pi;

vector<pi> v;

bool cmp(pi a, pi b) {
    return a.second == b.second ? a.first < b.first : a.second < b.second;
}

int main() {
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        int a, b;
        cin >> a >> b;
        v.push_back(make_pair(a, b));

    }
    sort(v.begin(), v.end(), cmp);
    int ans = 0;
    int now = v[0].second;
    for (auto i :v)
        if (now <= i.first) {
            now = i.second;
            ans++;
        }

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

Measured memory_bytes: 1400
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int px[90005], py[90005], cost[90005];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w, d, a;
    cin >> h >> w >> d;
    rep(i,h)rep(j,w){
        cin >> a;
        px[a] = i;
        py[a] = j;
    }
    for(int i = d+1; i <= h*w; i++){
        cost[i] = cost[i-d] + abs(px[i]-px[i-d]) + abs(py[i]-py[i-d]);
    }
    int q, l, r;
    cin >> q;
    rep(i,q){
        cin >> l >> r;
        cout << cost[r] - cost[l] << endl;
    }
    return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;

vector<int> tonari[200005];

int main() {
    int N; cin>>N;
    vector<int> p(N);
    for (int i = 0; i < N; ++i) {
        cin>>p[i];
    }

    int ans=0;
    bool cont=false;

    for (int i = 0; i < N; ++i) {
        if(p[i]==i+1) {
            if (cont) {
                cont = false;
            } else {
                ans++;
                cont = true;
            }
        }else{
            cont=false;
        }
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 5376
h, w = map(int, input().split())
s = [["."]+list(input())+["."] for _ in range(h)]
s.insert(0, ["." for _ in range(w+2)])
s.append(["." for _ in range(w+2)])
ans = "Yes"
# for i in s:
#     print(i)
for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j] == "#":
            if not(s[i][j+1]=="#" or s[i][j-1]=="#" or s[i+1][j]=="#" or s[i-1][j]=="#" ):
                ans = "No"
print(ans)

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

int main() {
    int N, A, Q;
    cin >> N;
    map<int, int>mp;
    ll ans = 0;
    rep(i, N) {
        cin >> A;
        mp[A]++;
        ans += A;
    }
    cin >> Q;
    rep(i, Q) {
        int B, C;
        cin >> B >> C;
        mp[C] += mp[B];
        ans += (C - B) * (ll)mp[B];
        mp[B] = 0;
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 7900
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
const ll INF = 1LL<<60;
const ll mod=1e9+7;
using namespace std;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }


int main(){
    string t;
    ll ans=0;
    cin>>t;
    rep(i,0,t.length()){
        if(t[i]=='?')t[i]='D';
    }
   // rep(i,0,t.length())if(t[i]=='D')ans++;
   // rep(i,0,t.length()-1)if(t[i]=='P'&&t[i+1]=='D')ans++;
    //cout<<ans<<endl;
    cout<<t;
}

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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

ll gcd(ll a, ll b)
{
    if (a < b)
        gcd(b, a);
    if (b == 0)
        return a;
    int r;
    while ((r = a % b))
    {
        a = b;
        b = r;
    }
    return b;
}

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

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

    if (a + b >= x && a <= x)
        cout << "YES" << endl;
    else
    {
        cout << "NO" << endl;
    }
}


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

const int MAXN = 100010;

template<typename T> inline T read() {
	T x(0), f(1);
	char ch = getchar();
	for(; !isdigit(ch); ch = getchar()) if(ch=='-') f=-1;
	for(; isdigit(ch); ch = getchar()) x = (x*10)+ (ch^48);
	return x * f;
}

int e, st[MAXN], to[MAXN<<1];
int nxt[MAXN<<1];
inline void Add(int u, int v) {
	to[++e] = v, nxt[e] = st[u];
	st[u] = e;
}

int n, K, ans, fa[MAXN];
int dep[MAXN];
int dfs(int u) {
	int maxd = dep[u];
	for(int i = st[u]; i; i = nxt[i]) {
		int v = to[i];
		dep[v] = dep[u]+1;
		maxd = max(maxd, dfs(v));
	}
	if(u != 1 && maxd-dep[u] == K-1) {
		if(fa[u] != 1) ans++;
		return 0;
	}
	return maxd;
}

int main() {
	n = read<int>(), K = read<int>();
	ans += (read<int>() != 1);
	for(int i = 2; i <= n; i++) {
		fa[i] = read<int>();
		Add(fa[i], i);
	}

	dfs(dep[1] = 1);

	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 6912
#include<iostream>
using namespace std;
string T[4]={"AC","WA","TLE","RE"};
int cnt[4];
main()
{
	int N;cin>>N;
	for(;N--;)
	{
		string s;cin>>s;
		for(int i=0;i<4;i++)if(T[i]==s)cnt[i]++;
	}
	for(int i=0;i<4;i++)cout<<T[i]<<" x "<<cnt[i]<<endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <string>
#include <bitset>
#include <set>

using ll = long long;
using namespace std;

int main(void) {
	int n, k;
	cin >> n >> k;
	
	vector<ll> p(n);
	for(int i = 0; i < n; ++i) {
		cin >> p[i];
	}
	
	vector<double> exval(n);
	for(int i = 0; i < n; ++i) {
		exval[i] = (p[i] + 1) / 2.0;
	}
	
	vector<double> sum(n + 2, 0);
	for(int i = 0; i < n; ++i) {
		sum[i + 1] += sum[i] + exval[i];
	}
	
	double ans = 0.0;
	for(int i = 0; i + k <= n; ++i) {
		ans = max(ans, sum[i + k] - sum[i]);
	}
	
	printf("%.15lf\n", ans);
	
	return 0;
}


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

int main () {
  string s;
  int a;
  cin >> a;
  cin >> s;
    
  
  if (3200 <= a) {
    cout << s << endl;
  }
  if (3199 >= a) {
    cout << "red" << endl;
  }
    
  
  
}

Measured memory_bytes: 256