akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
struct edge {
	int from, to, cost;
	edge(int from, int to, int cost) : from(from), to(to), cost(cost) {}
	edge() {}
};
bool operator<(edge l, edge r) {
	return l.cost < r.cost;
}
const int INF = 1000000000;
class UnionFind {
	vector<int> data;
	int root(int a) {
		return data[a] < 0 ? a : data[a] = root(data[a]);
	}
public:
	UnionFind(int n) : data(n, -1) {}
	bool Find(int a, int b) {
		return root(a) == root(b);
	}
	void Union(int a, int b) {
		a = root(a);
		b = root(b);
		if (a == b) return;
		if (data[a] < data[b]) {
			data[a] += data[b];
			data[b] = a;
		}
		else {
			data[b] += data[a];
			data[a] = b;
		}
	}
	int Size(int a) {
		return -data[root(a)];
	}
};


int main()
{
	int N, M, K, Q;
	cin >> N >> M >> K >> Q;
	vector<int> A(M), B(M), L(M);
	vector<vector<edge>> G(N);
	for (int i = 0; i < M; i++) {
		cin >> A[i] >> B[i] >> L[i]; A[i]--; B[i]--;
		G[A[i]].push_back(edge(A[i], B[i], L[i]));
		G[B[i]].push_back(edge(B[i], A[i], L[i]));
	}
	vector<int> d(N, INF);
	priority_queue<P, vector<P>, greater<P>> pq;
	for (int i = 0, F; i < K; i++) {
		cin >> F;
		pq.push(P(0, F - 1));
	}
	while (!pq.empty()) {
		auto p = pq.top(); pq.pop();
		if (d[p.second] != INF) {
			continue;
		}
		d[p.second] = p.first;
		for (auto e : G[p.second]) {
			if (d[e.to] == INF) {
				pq.push(P(p.first + e.cost, e.to));
			}
		}
	}
	vector<pair<int, edge>> v(M);
	for (int i = 0; i < M; i++) {
		v[i].first = min(d[A[i]], d[B[i]]);
		v[i].second = edge(A[i], B[i], L[i]);
	}
	sort(v.begin(), v.end(), greater<pair<int, edge>>());
	vector<int> S(Q), T(Q);
	for (int i = 0; i < Q; i++) {
		cin >> S[i] >> T[i]; S[i]--; T[i]--;
	}
	vector<int> l(Q, -1), r(Q, M - 1);
	for (int i = 0; i < 50; i++) {
		vector<vector<int>> bi(M);
		for (int j = 0; j < Q; j++) {
			bi[(l[j] + r[j]) / 2].push_back(j);
		}
		UnionFind uf(N);
		for (int j = 0; j < M; j++) {
			uf.Union(v[j].second.from, v[j].second.to);
			for (auto v : bi[j]) {
				if (uf.Find(S[v], T[v])) {
					r[v] = j;
				}
				else {
					l[v] = j;
				}
			}
		}
	}
	for (int i = 0; i < Q; i++) {
		cout << (S[i] == T[i] ? d[S[i]] : v[r[i]].first) << endl;
	}
	return 0;
}

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

A = list(map(int , input().split()))

Alive = 0

for a in A:
	if a != 0:
		Alive += 1

while Alive > 1:
	for j in range(N):
		prevaj = A[j]
		if A[j] != 0:
			for k in range(N):
				A[k] = A[k] % A[j]
				A[j] = prevaj
	Alive = 0
	for a in A:
		if a != 0:
			Alive += 1


print(sum(A))

Measured memory_bytes: 14224
#include <stdio.h>
#include <string.h>
 
int main()
{
    long long n;
    scanf("%lld",&n);
    char x[100]={0};
    int i=0;
    n--;
    while(n>=0){
        x[i]=n%26+'a';
        n/=26;
        i++;
        n--;
    }
    for(int j=i-1;j>=0;j--){
        printf("%c",x[j]);
    }
    return 0;
}

Measured memory_bytes: 3164
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>

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

using namespace std;
int main(void){
  string s,t;
  cin >> s >> t;

  int ans = 0;
  rep(i,s.length()){
    if(s[i] != t[i])ans++;
  }

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


Measured memory_bytes: 3852
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0);cin.tie();cout.tie();
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 9223372036854775807;
const ll mininf = -9223372036854775807;
const ll nax = 0;
ll n;
unordered_map<ll, ll>mep;

int main(){
	IOS
	cin >> n;
	ll arr[n+5];
	for(ll i=0;i<n;i++){
		cin >> arr[i];
		mep[arr[i]]++;
	}
	ll total=0;
	for(auto i:mep){
		total+=(i.second*(i.second-1))/2;
	}
	for(ll i=0;i<n;i++){
		cout << total-(mep[arr[i]]*(mep[arr[i]]-1))/2+((mep[arr[i]]-1)*(mep[arr[i]]-2))/2 << '\n';
	}
}

Measured memory_bytes: 11588
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < int(n); ++i)
#define REPE(i, a, b) for (int i = (a); i <= int(b); ++i)
#define SZ(x) ((int)(x).size())
#define ALL(x) x.begin(), x.end()
#define PB push_back
#define EB emplace_back
using LL = long long;
using PII = pair<int, int>;
#define F first
#define S second

int main() {
  int n;
  cin >> n;
  map<int, int> m;
  REPE(i, 1, n) {
    int t = i;
    for (int j = 2; t > 1; ++j) {
      int cnt = 0;
      while (t % j == 0) {
        t /= j;
        cnt++;
      }
      if (cnt) m[j] += cnt;
    }
  }
  LL ans = 1;
  for (auto it : m)
    ans = ans * (it.S + 1) % 1000000007;
  cout << ans << endl;
  return 0;
}



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

int main(){
    int A,B,X,Y;
    cin >> A >> B;
    X = (A * 100 + 7) / 8;
    Y = 8*B/10;
    if(X/10 == B) cout << X << endl;
    else if(Y == A) cout << 10*B << endl;
    else cout << "-1" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#include <stack>
 
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f3f3f3f3fLL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
 
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
ll MOD = 1000000007;
//ll MOD=998244353;
typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
int N;
int K;
vi a;
int dp[114514];
int main(){
	cin>>N>>K;
	rep(i,114514)dp[i]=0;
	rep(i,N){
		int x;
		cin>>x;
		a.pb(x);
	}
	int mi = *min_element(all(a));
	rep(i,mi)dp[i]=1;
	rep(i,114514){
		int x = 1;
		rep(j,N){
			if(i-a[j]>=0){
				if(dp[i-a[j]]==1)x=0;
			}
		}
		dp[i]=x;
	}
	if(dp[K]==0)cout<<"First"<<endl;
	else cout<<"Second"<<endl;
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;
int line[200001];
int linep_r[200001];

int main(){
	int N;
	long long A[200001];
	cin >> N;
	for (int i=0; i<N; i++) {
		cin >> A[i];
	}
	for (int i=0; i<N; i++) {
		long long line_n = i - A[i];
		if (line_n < 0) {
			cout << -1 << endl;
			return 0;
		}
		line[line_n] = line[line_n] > A[i] ? line[line_n] : A[i];
	}

	long long ans = 0;

	int linep_max = 0;
	for (int i=0; i<200001; i++) {
		linep_max = linep_max > line[i]+i ? linep_max : line[i]+i;
		linep_r[i] = linep_max;
	}
	for (int i=1; i<N; i++) {
		if (i <= linep_r[i-A[i]-1]) {
			cout << -1 << endl;
			return 0;
		}
	}

	for (int i=0; i<200001; i++) {
		ans += line[i];
	}
	cout << ans << endl;



	return 0;
}



Measured memory_bytes: 3328
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;

const int INF = 1<<30;
ll gcd(ll a, ll b){
  if(a>b)swap(a, b);
  if(a==0)return b;
  return gcd(a, b%a);
}
int main(){
  ll n, m;cin>>n>>m;
  string s, t;cin>>s>>t;
  ll l=n*m/gcd(n, m);
  bool valid=true;
  for(int i=0;i<gcd(n, m);i++){
    if(s[l/m*i]!=t[l/n*i]){valid=false;break;}
  }
  if(valid)cout<<l<<endl;
  else cout<<-1<<endl;
}


Measured memory_bytes: 512
#include<stdio.h>
#define N 1000

int main(void){
  int i,num,j;
  char ch[N][1010];
  char hoge;

  scanf("%d%c",&num,&hoge);
  for(i=0;i<num;i++){
    for(j=0;;j++){
      scanf("%c",&ch[i][j]);
      if(ch[i][j]=='\n'){
        break;
      }
    }
    ch[i][j]=0;
  }
  for(i=0;i<num;i++){
    for(j=0;ch[i][j]!=0;j++){
      if(ch[i][j+6]!=0 && ch[i][j]=='H'){
        if(ch[i][j+1]=='o' &&
            ch[i][j+2]=='s' &&
            ch[i][j+3]=='h' &&
            ch[i][j+4]=='i' &&
            ch[i][j+5]=='n' &&
            ch[i][j+6]=='o'){
          ch[i][j+6]='a';
        }
      }
      printf("%c",ch[i][j]);
    }
    printf("\n");
  }
  return 0; 
}

Measured memory_bytes: 0
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<utility>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define vint(a,n) vint a(n); rep(i, n) cin >> a[i];
#define vll(a,n) vll a(n); rep(i, n) cin >> a[i];
#define ALL(n) begin(n),end(n)
#define RALL(n) rbegin(n),rend(n)
#define MOD (1000000007)
// #define MOD (998244353)
#define INF (2e9)
#define INFL (2e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
using vint=vector<int>;
using vll=vector<ll>;
using vbool=vector<bool>;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
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 (b<a) { a=b; return 1; } return 0; }

int main()
{
    int n; cin >> n;
    int z = 0;
    map<int, int> m;
    vint a(n);
    rep(i, n){
        cin >> a[i];
        if(a[i]==0) z++;
        m[a[i]]++;
    }

    if(z==n) {pr("Yes"); return 0;}
    if(n%3!=0) {pr("No"); return 0;}

    if(z > 0){
        if(m.size()>2) pr("No");
        else {
            if(m.size()==2 && n%3==0 && z==n/3) pr("Yes");
            else pr("No");
        }
        return 0;
    }

    if(m.size()!=3) {pr("No"); return 0;}

    vint b, c;
    for(auto p: m) {
        c.push_back(p.second);
        b.push_back(p.first);
    }
    // prvec(b);
    if(c[0]!=c[1] || c[1]!=c[2]) {pr("No"); return 0;}
    if(((b[0]^b[1])^b[2])==0) {pr("Yes");}
    else pr("No");
    // pr(1^3^5);
    return 0;}

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

#define llt long long int
#define modm 1000000007

int main(){
	int n,m,ans=0;
	string s1,s2;
	cin>>s1>>s2;
	for(int i=0;i<s1.length();i++){
		if(s1[i]!=s2[i])
			ans++;
		}
	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 3828
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

int gcd(int x, int y) {
  if(y==0) return x;
  return gcd(y, x%y);
}

int main()
{
  int K;
  cin >> K;
  int res = 0;

  FOR(i,1,K){
    FOR(j, 1, K){
      int n = gcd(i, j);
      FOR(k, 1, K) {
        res += gcd(n, k);
      }
    }
  }

  cout << res << endl;
}

Measured memory_bytes: 3624
N,M=map(int,input().strip().split())
P,Y=[0]*M,[0]*M
all=[]
for i in range(M):
    P[i],Y[i]=map(int,input().strip().split())
    all.append([P[i],Y[i],i])
x=1
all.sort()
for i in range(M):
    if all[i][0]==all[i-1][0]:
        x+=1
        all[i][1]=x
    else:
        x=1
        all[i][1]=x
x=1
for i in range(M):
    if all[0][0]==all[i][0]:
        all[i][1]=x
        x+=1
    else:
        break
all.sort(key=lambda x: x[2])
for i in range(M):
    print((str(all[i][0]).rjust(6,'0')+str(all[i][1]).rjust(6,'0')))


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

/* #pragma */
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

/*alias*/
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define itn int

/*struct*/
struct aaa {
	aaa() {
		cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);
	};
}aaaaaaa;

/*template*/
template<class T>constexpr bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>constexpr bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

/* func */
constexpr int32_t GCD(int32_t a, int32_t b){return b ? GCD(b, a%b) : a;}
constexpr int64_t GCD(int64_t a, int64_t b){return b ? GCD(b, a%b) : a;}
constexpr int32_t LCM(int32_t a, int32_t b){return a / GCD(a, b) * b;}
constexpr int64_t LCM(int64_t a, int64_t b){return a / GCD(a, b) * b;}

/* const */
constexpr int32_t INF = 1001001001;
constexpr int64_t LINF = 1001001001001001001ll;
constexpr int32_t MOD = 1e9 + 7;
constexpr int32_t EPS = 1e-9;
constexpr int32_t dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 }, dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
//constexpr int32_t dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};


//g++ -std=c++14 -Wall --pedantic-errors -o template template.cpp
//g++ -std=c++14 -Wall --pedantic-errors template.cpp
//chcp 65001

#define int int64_t

/*global*/



signed main()
{
	int a, b; cin >> a >> b;
	int kuti{1};
	int cnt{};
	while(kuti < b)
	{
		if(kuti>0)
		{
			kuti--;
			kuti+=a;
			cnt++;
		}
		else return 111111111;
	}
	cout << cnt << '\n';
}

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

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

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int T, H, S;
  while (cin >> T >> H >> S, T != -1) {
    int rem = 2 * 3600 - T * 3600 - H * 60 - S;
    printf("%02d:%02d:%02d\n", rem / 3600, rem / 60 % 60, rem % 60);
    rem *= 3;
    printf("%02d:%02d:%02d\n", rem / 3600, rem / 60 % 60, rem % 60);
  }

  return 0;
}


Measured memory_bytes: 3176
import java.io.{BufferedReader, InputStreamReader}
import java.util

object Main extends App {
  val in = new BufferedReader(new InputStreamReader(System.in))
  val n = in.readLine.toInt
  val a, b, c = in.readLine.split(" ").map(_.toInt)

  util.Arrays.sort(a)
  util.Arrays.sort(b)
  util.Arrays.sort(c)
  
  val ans = {
      var posA, posC = 0

      def findA(tar:Int):Int = {
        while(posA < n && a(posA) < tar) posA += 1
        posA
      }
      def findC(tar:Int):Int = {
        while(posC < n && c(posC) <= tar) posC += 1
        posC
      }

      b./:(0L)((acc,e) => {
        val ac = findA(e)
        val cc = n - findC(e)

        acc +  ac.toLong * cc.toLong
      })
    }

  println(ans)
}

Measured memory_bytes: 76544
#include<cstdio>
using namespace std;
int main()
{
    long long a,b,n;
    scanf("%lld%lld%lld",&n,&a,&b);
    if(((n>1)&&(b>=a))||(n==1&&a==b)){
        printf("%lld\n",(n-2)*(b-a)+1);
    }
    else{
        printf("%d\n",0);
    }
    return 0; 
}

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

int main(){
    int n;
    vector<int>a(10001);
    for(int i=1;i<=100;i++){
        for(int j=1;j<=100;j++){
            for(int l=1;l<=100;l++){
                int v=i*i+j*j+l*l+i*j+l*j+l*i;
                if(v>10000)continue;
                a[v]++;
            }
        }
    }
    cin>>n;
    for(int i=1;i<=n;i++){
        cout<<a[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 3668
// {{{
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
// }}}

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

static constexpr int mod = (int)1e9 + 7;
static constexpr int inf = 100100100;
static constexpr ll linf = 1e18;
static constexpr double eps = 1e-9;
static constexpr double pi = 3.14159265359;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rrep(i, n) for (ll i = n; i >= 0; --i)
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define pb push_back
#define ist insert
#define fst first
#define snd second


int main() {
    // cin.tie(0);
    // ios_base::sync_with_stdio(false);
    ll X, A, B;
    cin >> X >> A >> B;
    X -= A;
    X %= B;
    cout << X << endl;
}


Measured memory_bytes: 888
#include<stdio.h>
int main()
{
	int a,b,c,i,x=0;
	scanf("%d %d %d",&a,&b,&c);
	for(i=0;i<b;i++)
	{
		if((a*i)%b==c)
		{
			x++;
			break;
		}
	}
	if(x==0)
		printf("NO\n");
	else
		printf("YES\n");
	return 0;
}

Measured memory_bytes: 128
def main():
    S = set(input())
    if ('N' in S and 'S' not in S) or ('N' not in S and 'S' in S):
        print('No')
    elif ('E' in S and 'W' not in S) or ('E' not in S and 'W' in S):
        print('No')
    else:
        print('Yes')


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    string s;
    cin >> s;
    string ans = "";
    rep(i,s.size()){
        if(i%2==0) ans = ans+s[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int a,b;
char c;
cin >> a >> c >> b;
if(c == '+'){
cout << a + b << endl;
}
if(c == '-'){
cout << a - b << endl;
}
if(c == '*'){
cout << a * b << endl;
}
if(c == '/'){
cout << a / b << endl;
}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef  long long int ll;
typedef  long double ld;
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define mod 1000000007
#define F first
#define S second 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
//recursions\
#pragma comment(linker, "/stack:200000000")
//loops\
#pragma GCC optimize("unroll-loops")
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,greater_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
using namespace std;

int main()
{
	sync;
	string s;
	cin>>s;
	int flag=1;
	for(ll i=0;i<s.length();i++)
	{
		if(i%2==0&&s[i]=='L')
		flag=0;
		if(i%2==1&&s[i]=='R')
		flag=0;
		
	}
	if(flag)
	cout<<"Yes";
	else
	cout<<"No";
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
    ll N,W;cin>>N>>W;
    vector<ll> w(N),v(N);
    rep(i,0,N-1)cin>>w[i]>>v[i];
    vector<vector<ll>> dp(N+1,vector<ll>(W+1,0));
    rep(i,0,N-1){
        rep(j,0,W){
            dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
            if(j+w[i]<=W)dp[i+1][j+w[i]]=dp[i][j]+v[i];
        }
    }
    cout<<dp[N][W]<<endl;
}


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

int main(){
  string s;
  cin>>s;
  int count=0;
  if(s[0]==s[1])count++;
  if(s[1]==s[2])count++;
  if(s[2]==s[3])count++;
  if(count==0){
    cout<<"Good"<<endl;
  }else{
    cout<<"Bad"<<endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll x, y;
    cin >> x >> y;

    ll ans = 0;
    while(x <= y) {
        x *= 2;
        ans++;
    } 
    
    out(ans);
    re0;
}

Measured memory_bytes: 256
N,K,Q=gets.chomp.split.map(&:to_i)
ans_infos = N.times.each_with_object({}){|n, hash| hash[n+1]=0}
Q.times do
  value = gets.chomp.to_i
  ans_infos[value] += 1
end

ans_infos.each do |k,v|
  point = K-(Q-v)
  if point <= 0
    puts "No"
  else
    puts "Yes"
  end
end

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

typedef long long ll;

int main() {
  int n,t;
  cin >> n >> t;
  vector<ll> a(n);
  ll mod=1000000007;
  for(int i=0; i<n; i++) cin >> a[i];
  sort(a.begin(),a.end());
  ll ans=1;
  for(int i=0; i<n; i++) {
    ans*=distance(lower_bound(a.begin(),a.end(),a[i]-t),a.begin()+i)+1;
    ans%=mod;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1796
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  ll h,w;
  cin >> h >> w;
  vector<vector<string>> s(h,vector<string>(w));
  ll a,b;
  rep(i,h){
    rep(j,w){
      cin >> s[i][j];
      if(s[i][j]=="snuke"){
        a=i,b=j;
      }
    }
  }
  cout << ABC[b] << a+1 << endl;
}

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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int n,m,X,Y; cin >> n >> m >> X >> Y;
  vector<int> x(n),y(m);
  rep(i,n) cin >> x[i];
  rep(i,m) cin >> y[i];

  /*  sort(x.begin(),x.end());
  sort(y.begin(),y.end());
  */
  
  for(int z = X+1;z<=Y;z++){
    bool war_x = false,war_y = false;
    rep(i,n) if(x[i]>=z) war_x = true;
    rep(i,m) if(y[i]<z) war_y = true;
    if(!(war_x) && !(war_y)){
      cout << "No War" << endl;
      return 0;
    }
  }

  cout << "War" << endl;
  
  return 0;
}


Measured memory_bytes: 3612
class UnionFind:
    def __init__(self, data):
        """
        与えられたdataまでの長さの配列を作成
        配列は1から開始する
        それがunionfindの親となり初めは自分自身
        またrankも定義し初期値は0
        """
        self.parent = {}
        self.rank = {}
        for i in range(1, data+1):
            self.parent[i] = i
            self.rank[i] = 1


    def find(self, x):
        """
        与えられた値に対してその親ノードを返却
        """
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x]) # self.parentに入れ直しているのは次findするとき高速になるよう再起により親を直接結んでいる
            return self.parent[x]


    def same(self, x, y):
        """
        与えられた2つの値が同一グループ(親)かチェック
        """
        return self.find(x) == self.find(y)


    def unite(self, x, y):
        """
        与えられた2つの値を同一のグループ(親)にする
        """
        x = self.find(x)
        y = self.find(y)
        if x == y: # すでに同じグループなら何もしない
            return
        if self.rank[x] > self.rank[y]: # ランクが異なる場合小さい方の親を大きい方にする
            self.parent[y] = x
            self.rank[x] += self.rank[y]
            return
        elif self.rank[x] < self.rank[y]:
            self.parent[x] = y
            self.rank[y] += self.rank[x]
            return
        else: # ランクが同じ場合どちらかの親にする その際親にした方の値のランクをあげる
            self.parent[x] = y
            if self.rank[x] == self.rank[y]: self.rank[y] += self.rank[x]
            return

if __name__ == '__main__':
    N,M = map(int, input().split())

    A = []
    B = []
    for i in range(M):
        a,b = map(int, input().split())
        A.append(a)
        B.append(b)

    union_find = UnionFind(N)
    ans = []
    ans.append((N*(N-1))//2)
    for i in reversed(range(1,M)):
        if union_find.same(A[i],B[i]):
            ans.append(ans[-1])
        else:
            a_par = union_find.find(A[i])
            b_par = union_find.find(B[i])
            ans.append(ans[-1]-union_find.rank[a_par]*union_find.rank[b_par])
            union_find.unite(A[i],B[i])

    for num in reversed(ans):
        print(num)

Measured memory_bytes: 31648
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-10;
const ll mod=1e9+7;
const vi emp;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,-0};
const int DX[8]={-1,-1,-1,0,0,1,1,1},DY[8]={1,0,-1,1,-1,1,0,-1};

vl a(7);

int main(){
	for(int i=0;i<7;i++) cin>>a[i];
	ll sum=a[1]*2+(a[0]/2+a[3]/2+a[4]/2)*4;
	ll tmp=a[0]%2+a[3]%2+a[4]%2;
	if(tmp==3) sum+=6;
	if(tmp==2&&a[0]&&a[3]&&a[4]) sum+=2;
	cout<<sum/2<<endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())  # N個の整数, 整数K
A = list(map(int, input().split()))
K += 1
k_bit = format(K, "b")
# 特定の桁に関して、どちらを立てたほうが調べておく
tmp = ""  # 下位桁の情報からappendしていき、最後にreverseを行う
for i in reversed(range(len(k_bit))):  # reversedして上位の桁から見ている
    bit = 1 << i
    count = 0  # i桁目について、ビットが立っている数の個数
    for a in A:
        if a & bit:
            count += 1
    if count > N - count:
        tmp += "0"
    else:
        tmp += "1"
# tmpには最適な答えが入っている
ans = 0  # 最終的な答え
for i in range(len(k_bit)):  # iが対象の桁, 上位から見ている
    if k_bit[i] == "0":
        continue
    x = k_bit[:i] + "0" + tmp[i+1:]
    num = int(x, 2)
    # もとまったnumについてループを回す
    hoge = 0
    for a in A:
        hoge += a ^ num
    ans = max(ans, hoge)
print(ans)


Measured memory_bytes: 14708
def solve(string):
    n, *uvw = map(int, string.split())
    p = [[] for _ in range(n + 1)]
    for u, v, w in zip(uvw[::3], uvw[1::3], uvw[2::3]):
        p[u].append((v, w))
        p[v].append((u, w))
    s = [(1, 0)]
    l = [-1] * n
    while s:
        a, w = s.pop()
        l[a - 1] = w % 2
        for b, c in p[a]:
            if l[b - 1] == -1:
                s.append((b, w + c))
    return "\n".join(str(c) for c in l)


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(n - 1)])))


Measured memory_bytes: 50292
#include<stdio.h>
int main()
{
 int x;
 int y;
 while(1)
 {
  scanf("%d %d", &x, &y);
  if(x == 0 && y == 0) break;
  if(x < y)
  {
   printf("%d %d\n", x, y);
  }
  else
  {
   printf("%d %d\n", y, x);
  }
 }
 return 0;
}



Measured memory_bytes: 2104
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>
#include<array>


using namespace std;

#define REP(i, n) for(int i = 0;i < (n);++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
//#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
typedef array<int, 3> arr3;
std::random_device rd;
std::mt19937 mt(rd());
constexpr int MOD = 1e9 + 7; constexpr int MAX = 200020;
const double pi = acos(-1); constexpr double EPS = 1e-8;
constexpr ll INF = 1e18;

int dp[1 << 20][20];//[i,i+2^j)の勝者
bool done[1 << 20][20];
string S;
int p[1 << 20];

int winner(int x, int y) {
	if (x > y)swap(x, y);
	if (S[y - x-1] == '1')return y;
	else return x;
}
int func(int i, int j) {
	if (done[i][j])return dp[i][j];
	if (j == 0) {
		done[i][j] = true;
		return dp[i][j] = p[i];
	}
	else {
		done[i][j] = true;
		int x = func(i, j - 1);
		int y = func(i + (1 << (j - 1)), j - 1);
		return dp[i][j] = winner(x, y);
	}
}

void solve() {
	int N; cin >> N;
	cin >> S;
	REP(i, 1 << N) {
		cin >> p[i];
		p[i + (1 << N)] = p[i];
	}
	//REP(i, 1 << N) {
	//	REP(j, N + 1) {
	//		pe(i); pe(j); print(func(i,j));
	//	}
	//}
	//print("1,2");
	//print(func(1, 2));
	REP(k, 1 << N) {
		int res = func(k, N);
		print(res);
	}
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}


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

using namespace std;

int main(void){

  int N;
  cin >> N;

  int r = N % 10;
  int q = (N - r) / 10;
  
  if(r == 9 || q == 9){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
    public static void main (String[] args) throws java.lang.Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        long n = Long.parseLong(st.nextToken()),
            k = Long.parseLong(st.nextToken());
        long[] counts = new long[100001];
        for (int i=0 ; i<n ; i++) {
            st = new StringTokenizer(br.readLine());
            int a = Integer.parseInt(st.nextToken()),
                b = Integer.parseInt(st.nextToken());
            counts[a] += b;
        }
        for (int i=1 ; i<100001 ; i++) {
            k -= counts[i];
            if (k <= 0) {
                System.out.println(i);
                return;
            }
        }
    }
}



Measured memory_bytes: 45012
#include <valarray>
#include <cstdio>
using namespace std;
typedef valarray<int>V;
int n,m;
V s,x,e,z;
void Me(const V &_x,const V &_y){
	int i=0,j;
	for(;i<n;i++)for(j=0;j<n;j++)z[i*n+j]=(_x[slice(i*n,n,1)]*_y[slice(j,n,n)]).sum()%m;
	e=z;
}
void Mx(const V &_x){
	int i=0,j;
	for(;i<n;i++)for(j=0;j<n;j++)z[i*n+j]=(_x[slice(i*n,n,1)]*_x[slice(j,n,n)]).sum()%m;
	x=z;
}
void O(const V &r){
	int i=0;
    for(;i<n-1;i++)printf("%d ",(r[slice(i*n,n,1)]*s).sum()%m);
    printf("%d\n",(r[slice(i*n,n,1)]*s).sum()%m);
}
main(){
	int i,a,b,c,t;
	for(;scanf("%d%d%d%d%d%d",&n,&m,&a,&b,&c,&t),n;){
		s.resize(n);
		for(i=0;i<n;i++)scanf("%d",&s[i]);
		x.resize(0);
		x.resize(n*n);
		e.resize(0);
		e.resize(n*n);
		z.resize(n*n);

		x[0]=b;
		x[1]=c;
		e[0]=1;
		for(i=1;i<n-1;i++){
			x[i*n+i-1]=a;
			x[i*n+i]=b;
			x[i*n+i+1]=c;
			e[i*n+i]=1;
		}
		x[i*n+i-1]=a;
		x[i*n+i]=b;
		e[i*n+i]=1;
		for(;t;t>>=1){
			if(t&1)Me(e,x);
			Mx(x);
		}
		O(e);
	}
}

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

int main() {
  string s;
  int k;
  cin >> s >> k;
  char pre;
  ll cnt;

  ll ans1 = 0;
  cnt = 1;
  pre = s[0];
  for (int i = 1; i < s.size(); i++) {
    if (pre == s[i]) {
      cnt++;
    } else {
      ans1 += cnt / 2;
      cnt = 1;
      pre = s[i];
    }
  }
  ans1 += cnt / 2;

  if (cnt == s.size()) {
    cout << (s.size() * k) / 2 << endl;
    return 0;
  }

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

  string ss = s + s;
  ll ans2 = 0;
  cnt = 1;
  pre = ss[0];
  for (int i = 1; i < ss.size(); i++) {
    if (pre == ss[i]) {
      cnt++;
    } else {
      ans2 += cnt / 2;
      cnt = 1;
      pre = ss[i];
    }
  }
  ans2 += cnt / 2;

  ll dif = ans2 - ans1;
  cout << ans1 + (k - 1) * dif << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main()
{
    char S[5];
    scanf("%s", S);
    bool flag = false;
    for(int i=0; i<3; i++)
        if(S[i] == S[i+1]) flag = true;
    if(flag == true) std::cout << "Bad" << std::endl;
    else std::cout << "Good" << std::endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
city = [0] * N
for i in range(0, M):
    a, b = map(int, input().split())
    for j in range(1, N+1):
        if a == j or b == j:
            city[j-1] += 1
for n in range(0, N):
    print(city[n])

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)

#define DEBUG

#ifdef DEBUG
#define var_dump(...) fprintf(stdout, __VA_ARGS__)
#define dump(a) cout << a << "\n";
#else
#define var_dump(...) 42
#define dump(a) 42
#endif

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://beta.atcoder.jp/contests/abc083/tasks/abc083_b

int main() {
    ll N, A, B;
    cin >> N >> A >> B;

    ll ans = 0;
    FOR(i, 1, N+1) {
        ll a = i;
        ll sum = 0;
        while(a > 0) {
            sum += a % 10;
            a /= 10;
        }

        if (sum >= A && sum <= B) {
            ans += i;
        }
    }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 0x7fffffff
using namespace std;
typedef long long ll;
int n,a,sum;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a);
        sum+=a-1;
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
import scala.io.Source.stdin

object Main {
  def main(args: Array[String]) = {
    val list = stdin.getLines().map { _.toInt }
    val n = list.next()
    val r0 = list.next()
    val r1 = list.next()
    var max = r1 - r0
    var min = if(r0 > r1) r1 else r0
    for( m <- list ) {
      if( max < m - min) {
        max = m - min
        if( min -m > 0 )
          min = m
      }
      else if( min - m > 0 ) {
        min = m
      }
    }
    println(max)
  }
}

Measured memory_bytes: 64356
#include<bits/stdc++.h>
using namespace std;
#define INS(x) x.begin(),x.end()
    
int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int k;
    cin>>k;

    cout<<a[k-1];
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pi acos(-1.0)
#define pb push_back
#define vi vector<int>
#define mapii map<int , int>
#define mapci map<char, int>
#define mapsi map<string,int>
#define FOR(i,n) for(int i = 0;i<n;i++)
#define CP(n) printf("Case %d: \n",n);
#define fr freopen("input.txt","r",stdin)
#define fw freopen("output.txt","w",stdin)
#define MAX 1000007
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n , k , ans = 0;
    cin>>n>>k;
    while(n)
    {
        n/=k;
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 4
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	ee := make([][]int, n)
	for i := 0; i < n; i++ {
		ee[i] = make([]int, 0)
	}

	for i := 0; i < n-1; i++ {
		a := getNextInt(scanner) - 1
		ee[a] = append(ee[a], i+1)
	}

	fmt.Fprintln(writer, dfs(0, ee))
}

func dfs(i int, ee [][]int) int {
	max := 0
	cc := make([]int, 0)

	for _, to := range ee[i] {
		c := dfs(to, ee)
		cc = append(cc, c)
	}
	sort.Ints(cc)
	n := len(cc)
	for i := 0; i < n; i++ {
		if max < cc[i]+n-i {
			max = cc[i] + n - i
		}
	}
	return max
}


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

shogen = [[] for _ in range(N)]
for i in range(N):
  for j in range(int(input())):
    person, state = map(int, input().split())
    shogen[i].append([person-1, state])

honest = 0
# ビット全探索
for i in range(1, 2**N):
  flag = 0
  # jは桁数
  for j in range(N):
    # iのj桁目が1だったら
    if (i>>j)&1 == 1:
      # j人目の証言を取り出し
      for person, state in shogen[j]:
        # もし証言が不一致ならフラグを立てる?
        if (i>>person)&1 != state:
          flag = 1
          break
  # 証言が一致していたら、honsetの最大値を更新
  if flag == 0:
    honest = max(honest, bin(i)[2:].count('1'))
print(honest)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include <math.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 lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
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() {
int H;
  int W;
  cin >>H >>W;
  char data[H][W];
  rep(i,H) {
rep(j,W) {
  cin>>data[i][j];
}
  }
 vector<bool> row(H,false) ;
  vector<bool> column(W,false);
     rep(i,H) {
rep(j,W) {
  if(data[i][j]=='#') {
     row.at(i)=true;
    column.at(j)=true;
  }
}
     }

   rep(i,H) {
         if(row.at(i)) {
rep(j,W) {
  if(column.at(j)) {
      cout<<data[i][j];
  }
}
           cout<<endl;
         }
   }
                      }
              
  
  
 

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<functional>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X <<":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const ll MOD = 1000000007;
const ll INF = 9e14;
typedef std::pair<ll,ll> P;
struct edge{ int to,cost; };
#define VMAX 100000

ll N,M,K,Q;
ll A[200010],B,C,D,X;
ll ans=INF;
ll F[200010];
string S,T,U;
int main(){
    cin>>N;
    if(N%10==3)cout<<"bon";
    else if(N%10==0||N%10==1||N%10==6||N%10==8)cout<<"pon";
    else cout<<"hon";

}
// cd /mnt/d/Data/Source/ABC/


Measured memory_bytes: 3620
given = list(map(str,input().split()))
stack = []

for j in given:
    try:
        i = int(j)
    except ValueError:
        i = str(j)
    if type(i) == int:
        stack.append(int(i))
    else:
        r = stack.pop()
        l = stack.pop()
        if i=="+":
            stack.append(l+r)
        elif i=="-":
            stack.append(l-r)
        elif i== "*":
            stack.append(l*r)
print(stack[0])
    


Measured memory_bytes: 5604
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<numeric>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
const int MOD = 1000000007;
using ll = long long;
using P = pair<int, int>;

vector<vector<int>> dp;

int main(){
  int h, w;
  cin >> h >> w;
  dp.assign(10, vector<int>(10, INF));
  for(int i = 0; i < 10; ++i){
  	for(int j = 0; j < 10; ++j){
  		int c;
  		cin >> c;
  		dp[i][j] = c;
  	}
  }
  for(int k = 0; k < 10; ++k){
  	for(int i = 0; i < 10; ++i){
  		for(int j = 0; j < 10; ++j){
  			dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
  		}
  	}
  }
  int ans = 0;
  for(int i = 0; i < h; ++i){
  	for(int j = 0; j < w; ++j){
  		int a;
  		cin >> a;
  		if(a != -1)ans += dp[a][1];
  	}
  }

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


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long r;
        r = sc.nextLong();

        final Solver solver = new Solver();
        solver.solve(r);
    }
}

class Solver {
    public void solve(long r) {
        System.out.println(r * r);
    }
}



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

/* using */
using namespace std;

/* main constructor */
struct Fast
{
    Fast()
    {
        std::cin.tie(0);
        ios::sync_with_stdio(0);
        //cout << fixed << setprecision(12);
    }
} fast;

/* template */
template <class T>
bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; }
template <class T>
bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; }

/* define */
#define REP(i, x, n) for (int i = x; i < (int)(n); ++i)
#define RREP(i, x, n) for (int i = x - 1; i >= (int)(n); --i)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) REP(i, 1, n + 1)
#define rrep(i, n) RREP(i, n, 0)
#define each(i, n) for (auto &i : n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define eunique(x) \
    sort(all(x));  \
    (x).erase(unique(all(x)), (x).end())
#define int long long
#define mp make_pair
#define r0 return 0

/* function */
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }

/* const */
const int inf = 1e9 + 7;
const int dxl[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dyl[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dxs[4] = {1, 0, -1, 0};
const int dys[4] = {0, 1, 0, -1};

/* main */
signed main(void)
{
    string s;
    cin >> s;
    int cnt = 0;
    size_t ss = s.size();
    for (int i = 0; i < ss;i++){
        if(s[i]=='o'){
            cnt++;
        }
    }
    if(((15-ss)+cnt)>7){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
    return 0;
}


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

using namespace std;

using ll = long long;
const int maxn = 3010;

ll nums[maxn];
ll dp[maxn][maxn];
int N;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
		
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> nums[i];
	}

	for (int sz = 1; sz <= N; sz++) {
		for (int st = 1; st <= N; st++) {
			int ce = st + sz-1;
			if (ce > N) break;
			if (st == ce) dp[st][ce] = nums[st];
			else {
				dp[st][ce] = max(0-dp[st+1][ce] + nums[st],
					0-dp[st][ce-1] + nums[ce]);
			}

		}
	}

	cout << dp[1][N] << endl;

}

Measured memory_bytes: 70016
program dist_max
  implicit none
  integer, parameter :: inf = lshift(1, 31) - 2
  integer :: n, x, y, a = inf, b = -inf, c = inf, d = -inf, i
  read(*,*) n
  do i = 1, n
    read(*,*) x, y
    a = min(a, x + y)
    b = max(b, x + y)
    c = min(c, x - y)
    d = max(d, x - y)
  end do
  write(*,'(i0)') max(b - a, d - c)
end program dist_max

Measured memory_bytes: 2952
#include<cstdio>
#include<algorithm>

using namespace std;

int n,a,b;
int pro[105];
int one,two,three;

int main()
{
	scanf("%d",&n);
	scanf("%d %d",&a,&b);
	for(int i = 1;i <= n; i++){
		scanf("%d",&pro[i]);
		if(pro[i] <= a) one ++;
		else if(pro[i] > a && pro[i] <= b) two++;
		else three++;
	}
	int ans = min(one,two);	ans = min(ans,three);
	printf("%d\n",ans);
}

Measured memory_bytes: 128
s = input()
l = len(s)

alf=set('abcdefghijklmnopqrstuvwxyz')
for i in range(l):
    if s[i] in alf:
        alf.remove(s[i])

if alf:
    t = list(alf)
    t.sort()
    s+=t[0]
else:
    stock=[]
    for i in range(1,26):
        if s[l-i-1]>s[l-i]:
            stock.append(s[l-i])
        else:
            stock.append(s[l-i])
            stock.sort()
            for j in stock:
                if j>s[l-i-1]:
                    s=s[:l-i-1]+j
                    print(s)
                    exit()
        if i==25:
            print('-1')
            exit()
print(s)


Measured memory_bytes: 3192