akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

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

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; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,k;
  cin>>n>>k;
  string s;
  cin>>s;
  vector<int>flip;
  flip.push_back(0);
  if(s[0]=='0')flip.push_back(0);
  rep(i,n-1){if(s[i]!=s[i+1])flip.push_back(i+1);}
  flip.push_back(n);
  if(s[n-1]=='0')flip.push_back(n);

  int l=2*k+1;
  int res=0;
  for(int i=0;i+l<flip.size();i+=2)chmax(res,flip[i+l]-flip[i]);
  if(l>=flip.size())res=n;
  cout<<res<<endl;


  return 0;

}


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

#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;

typedef tree<
ll,
null_type,
less<ll>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
// ordered_set X;
// *X.find_by_order(i) = ith largest element (counting from zero)
// X.order_of_key(k) = number of items in X < k (strict lt)


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

    ll Q, H, S, D, N;
    cin >> Q >> H >> S >> D >> N;

    ll ans = 4*N*Q;
    ans = min(ans, 2*N*H);
    ans = min(ans, N*S);
    
    if (N % 2 == 0) {
        ans = min(ans, (N/2)*D);
    } else {
        ans = min(ans, (N/2)*D + S);
        ans = min(ans, (N/2)*D + 2*H);
        ans = min(ans, (N/2)*D + 4*Q);
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
  unsigned long n, k, sum = 0;
  cin >> n >> k;
  vector<unsigned long> h(n);
  if(n < k){
      k = n;
  }
  for(int i = 0; i < n; i++){
      cin >> h[i];
  }
  sort(h.begin(), h.end());
  for(int i = 0; i < n - k; i++){
      sum += h[i];
  }
  cout << sum << endl;
}

Measured memory_bytes: 1920
#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() {
  int a, b, m; cin >> a >> b >> m;
  vector<int> A(a); rep(i, a) cin >> A[i];
  vector<int> B(b); rep(i, b) cin >> B[i];
  vector<int> x(m), y(m), c(m);
  rep(i, m) {
    cin >> x[i] >> y[i] >> c[i]; x[i]--; y[i]--;
  }
  int Min = 2e9;
  rep(i, m) Min = min(Min, A[x[i]] + B[y[i]] - c[i]);
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  Min = min(Min, A[0] + B[0]);
  cout << Min << endl;
  return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;

void solve() {
  char c;
  cin >> c;
  if (c <= 'Z') {
    cout << "A\n";
  } else {
    cout << "a\n";
  }
}

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

  solve();
  return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()


using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;

int ans;
int a[10005];

int main(void) {
    int n, m, sum = 0;
    cin >> n >> m;
    rep(i, 0, m) scanf("%d", &a[i]);
    rep(i, 0, m) sum += a[i];

    ans = n - sum;
    printf("%d\n", ans>=0 ? ans : -1);
    

	return 0;
}


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

from collections import defaultdict
d = defaultdict(int)

for a in A:
    d[a]+=1

l = sorted(d.values())
M = len(d.keys())
if M<=K:
    print(0)
else:
    print(sum(l[:M-K]))


Measured memory_bytes: 99280
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
const int INF=1e9+7;
const int N=205;
char map[N][N];
int c[N],d[N][N];
queue<int>q;
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%s",map[i]+1);
	}
	while(!q.empty())q.pop();
	memset(c,-1,sizeof(c));
	c[1]=0;
	int p=0;
	q.push(1);
	while(!q.empty()){
		int u=q.front();
		q.pop();
		for(int i=1;i<=n;i++){
			if(map[u][i]-'0'==1){
				if(c[i]==-1){
					c[i]=c[u]^1;
					q.push(i);
				}
				else if(c[i]==c[u]){
					p=1;
					break;
				}
			}
		}
		if(p==1)break;
	}
	if(p==1){
		printf("-1");
		return 0;
	}
	
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(map[i][j]-'0'==0){
				d[i][j]=INF;
			}
			else{
				d[i][j]=1;
			}
		}
	}
	for(int k=1;k<=n;k++){
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				d[i][j]=min(d[i][j],d[i][k]+d[k][j]); 
			}
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(i==j)continue;
			ans=max(ans,d[i][j]);
		}
	}
	printf("%d",ans+1);
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll  long long
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define pb push_back
#define Max(x,y,z) max(x,max(y,z))
#define f first
#define s second
#define lbd lower_bound
#define sz(x)       (ll)x.size()
#define pi 3.1415926536
#define mod 1000000007
using namespace std;
void solve()
{
    ll n,m,k,x,y=0,res=0,l,cnt=0,sum=0,z,sum1=0,cnt1=0,h,res1;
    vector<pair<ll,ll>> v;
    rep(i,0,5)
    {
        cin>>x;
        if(x%10)
        v.pb({10-x%10,x});
        else
        v.pb({0,x});
    }
    sort(v.begin(),v.end());
    rep(i,0,4)
    {
        if(v[i].f==0)
            sum+=v[i].s;
        else
            sum+=(v[i].s+v[i].f);
    }
    sum+=v[4].s;
    cout<<sum;



}
int main()
{   speed_up
    ll t;
   // cin>>t;
    t=1;
    while(t--)
        solve();
}


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

#define ll long long int

ll solve(int i,vector<ll> v,int n,vector<ll> &dp)
{
    if(i==n-1) return 0;

    if(dp[i]!=-1) return dp[i];
    ll cur = LONG_MAX;
    if(i+1 < n)
    {
        cur = min(cur,abs(v[i]-v[i+1]) + solve(i+1,v,n,dp));
    }

    if(i+2 < n)
    {
        cur = min(cur,abs(v[i]-v[i+2]) + solve(i+2,v,n,dp));
    }
    dp[i] = cur;
    return cur;
}

ll bottomUp(vector<ll> v)
{
    int n = v.size();
    vector<ll> dp(n);

    dp[n-1] = 0;
    for(int i = n-2;i >=0;i--)
    {
        if(i==n-2)
        {
            dp[i] = abs(v[i]-v[i+1]);
        }
        else dp[i] = min( abs(v[i]-v[i+1]) + dp[i+1] ,
        abs(v[i]-v[i+2]) + dp[i+2] );
    }

    return dp[0];
}

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

    vector<ll> v(n);
    for(int i = 0;i<n;i++) cin>>v[i];

    // vector<ll> dp(n,-1);
    // cout<<solve(0,v,n,dp);
    cout<<bottomUp(v);
}


Measured memory_bytes: 2560
#----------------------------------------------------------
P = 10**9 + 7
N = 100001 #使う最大値+1以上にする、値に注意3*10^5とかにしとくと安心
inv = [0] + [1] # 1/x
finv = [1] + [1] # 1/x!
fac = [1] + [1] # x!
for i in range(2,N):
  inv += [inv[P % i] * (P - int(P / i)) % P]
  fac += [(fac[i-1] * i) % P]
  finv += [(finv[i-1] * inv[i]) % P]

def comb(a, b):
    if a<b or a<0 or b<0:
        return 0 # error
    return (fac[a] * ((finv[b] * finv[a-b]) % P)) %P
#----------------------------------------------------------

n=int(input())
x=list(map(int,input().split()))
s = [0] * n
for i in range(n):
    s[i] = x[i] + (s[i-1] if i>0 else 0)
ans=0

for i in range(n-1):
    t = (x[n-1]-x[n-2-i])%P
    t = (t * (fac[n-1]*inv[i+1])%P)%P
    ans=(ans+t)%P
for i in range(1, n-1):
    t = (s[n-2] - s[i-1] - s[n-2-i])%P
    p = (((fac[n-1] * inv[i])%P) * inv[i+1])%P
    ans = (ans + (t*p)%P)%P

print(ans%P)


Measured memory_bytes: 26700
#include <bits/stdc++.h>
#include <string.h>
#include <vector>
//s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a; i<n; i++)
#define r0 return 0
#define INF (int)1e15
#define MOD 1000000007

 int main(){

 long long n; cin>>n;
 long long a[n];

  long long sum=0;

 for(int i=0;i<n;i++)
 {
    cin>>a[i];
     sum += a[i]-1;
 }

cout<<sum<<endl;

 return 0;
 }

Measured memory_bytes: 3620
#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}, dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int main() {
	int h, w;
	scanf("%d%d", &h, &w);
	char a[h][w + 5];
	rep(i, h) scanf("%s", a[i]);
	rep(i, h) {
		rep(j, w) {
			if (a[i][j] == '#') {
				printf("#");
				continue;
			}
			int cnt = 0;
			rep(k, 8) {
				int nx = i + dx[k], ny = j + dy[k];
				if (nx < 0 or h <= nx or ny < 0 or w <= ny) continue;
				if (a[nx][ny] == '#') cnt++;
			}
			printf("%d", cnt);
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 256
k = int(input())
li = [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]
print(li[k-1])

Measured memory_bytes: 2940
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int M = sc.nextInt();
        long digits = 0L;
        long sum = 0L;
        for (int i=0;i<M;i++) {
            long d = sc.nextLong();
            long c = sc.nextLong();
            digits += c;
            sum += d*c;
        }
        System.out.println((sum-1)/9+digits-1);
    }
}

Measured memory_bytes: 92244
from collections import deque
import sys, copy, itertools,bisect
input = sys.stdin.readline
  
n = int(input())
A = []
for i in range(n):
  a = int(input())
  A.append(a)
  
A.reverse() #逆順に変更

LDS =[A[0]] #初期値導入
#LDS=Longest Decreasing Subsequence
 
for i in range(1,n):
  x = A[i]
  index = bisect.bisect_right(LDS,x) #二分探索、right:同値は追加
  if index == len(LDS):
    LDS.append(x) #単純に後ろに追加する
  else:
    LDS[index]  = x
    #配列LDSの中で二分探索し、A[i]より大きい最小の位置を求め、その数字を置き換える  


#print(LDS)
print(len(LDS))    

Measured memory_bytes: 99056
using System;
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();
            var count = 0;
            for(var i =1;i<S.Length;i++)
            {
                if (S[i - 1] != S[i]) count++;
            }
            Console.WriteLine(count);
        }
    }

Measured memory_bytes: 11232
#include<bits/stdc++.h>
using namespace std;
#define int long long
int inf=1e18;

struct graph{

struct edge{int to,cst;};
struct pos{int i,d;
	pos(){};
	pos(int i_,int d_){i=i_,d=d_;};
	bool operator<(const pos& r)const{return d>r.d;}
};


vector<vector<edge>>g;
vector<bool>used;
int n;

vector<int>dist;
priority_queue<pos> pq;

	graph(){};
	graph(int n_){
	n=n_;
	g.resize(n);
	used.assign(n,false);
	dist.resize(n,inf);
	};

	void add_edge(int x,int y,int cst){
		g[x].push_back(edge({y,cst}));
		g[y].push_back(edge({x,cst}));
	}

	void set_dist(int y){
		dist[y]=0;
		bool first=true;
		 pq.push(pos(y,0));
		while(!pq.empty()){
			pos x=pq.top();pq.pop();
			if(dist[x.i]<x.d)continue;
			first=false;
			for(auto&& w:g[x.i]){
				if(dist[w.to]> x.d+w.cst){
					dist[w.to]=x.d+w.cst;
					pq.push(pos(w.to,dist[w.to]));
				}
			} 
		}	
	}

};


signed main(){
	int n,m,s,t;cin>>n>>m>>s>>t;s--;t--;
	graph g1(n),g2(n);
	for(int i=0;i<m;i++){
		int x,y,a,b;cin>>x>>y>>a>>b;x--;y--;
		g1.add_edge(x,y,a);
		g2.add_edge(x,y,b);
	}
	g1.set_dist(s);
	g2.set_dist(t);	
	int money=1e15;
	int cst=inf;
	vector<int>cs(n);
	for(int i=n-1;i>=0;i--){
		cst=min(cst,g1.dist[i]+g2.dist[i]);
		cs[i]=cst;
	}
	for(auto&& w:cs)cout<<money-w<<endl;
}


Measured memory_bytes: 20216
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <iomanip>
#include <string>
using namespace std;

int main(){

string S;

getline(cin,S);

int x=S.size();

for(int i=0;i<=x-1;++i){

  if((S.at(i)>= 'a') && (S.at(i)<='z')){
    S.at(i)=toupper(S.at(i));
cout << S.at(i);
  }
  else if((S.at(i)>= 'A') && (S.at(i)<='Z')){
    S.at(i)=tolower(S.at(i));
cout << S.at(i);
  }
  else {
    cout << S.at(i);
  }

}

cout << endl;

}


Measured memory_bytes: 3216
a,b,m=map(int, input().split())

a_l = list(map(int, input().split()))
b_l = list(map(int, input().split()))
m_l = []
for i in range(m):
    m_l.append(list(map(int, input().split())))
score = float('inf')
min_norm = min(a_l) + min(b_l)
sale_l = []
for m_ in m_l:
    sale_l.append(a_l[m_[0]-1]+b_l[m_[1]-1] - m_[-1])
print(min(min_norm,min(sale_l)))

Measured memory_bytes: 42412
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

std::string s;
int K;
std::vector<std::string>res;

int main()
{
	in >> s >> K;
	rep(i, s.length())
	{
		for (int j = 1; j <= std::min<int>(K, s.length() - i); ++j) res.push_back(s.substr(i, j));
	}
	std::sort(res.begin(), res.end());
	res.erase(std::unique(res.begin(), res.end()), res.end());
	out << res[K - 1] << std::endl;
	return 0;
}


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

typedef long long ll;

const int maxN = 16;
int N, a[maxN][maxN];
ll dp[1 << maxN], scores[1 << maxN];
vector<int> rem;

void pre_process() {
    for (int mask = 0; mask < (1 << N); mask++) {
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                if ((mask & (1 << i)) && (mask & (1 << j))) {
                    scores[mask] += a[i][j];
                }
            }
        }
    }
}

void rec(int pos, int grp, int mask, ll score) {
    if (pos == (int) rem.size()) {
        dp[mask] = max(dp[mask], score + scores[grp]);
        return;
    }
    rec(pos + 1, grp, mask, score);
    rec(pos + 1, grp ^ (1 << rem[pos]), mask ^ (1 << rem[pos]), score);
}

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

    cin >> N;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cin >> a[i][j];
        }
    }
    pre_process();
    for (int mask = 0; mask < (1 << N); mask++) {
        rem.clear();
        for (int i = 0; i < N; i++) {
            if (!(mask & (1 << i))) {
                rem.push_back(i);
            }
        }
        rec(0, 0, mask, dp[mask]);
    }
    cout << dp[(1 << N) - 1];

    return 0;
}

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

using namespace std;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15);
  }
} initializer;

int main() {
  int x, y = 0;
  cin >> x;
  x = abs(x);
  for (int i = 0; ; ++i) {
    y += i;
    if (x <= y) {
      cout << i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>

using namespace std;

int main(){

	int w,n,left,right;
	scanf("%d",&w);
	int array[w+1];
	for(int i=0;i<w+1;i++)array[i]=i;
	scanf("%d",&n);

	for(int i=0;i<n;i++){
		scanf("%d,%d",&left,&right);
		swap(array[left],array[right]);
	}

	for(int i=1;i<=w;i++){
		printf("%d\n",array[i]);
	}

	// return 0;
}



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

using namespace std;

typedef long long ll;
#define SWAP(x,y,z) {if ( y > z ) swap(y,z); if ( x > y ) swap(x,y); if (y > z) swap(y,z);}


double const eps = 1e-10;
ll const mod = 1e9+7;

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

    string a,b,c;
    cin >> a >> b >> c;

    if ( a[a.size()-1] == b[0] )
        if ( b[b.size()-1] == c[0] ) cout << "YES";
        else cout << "NO";
    else cout << "NO";

    return 0;

    // 274751WM
}


Measured memory_bytes: 256
N = int(input())
T = input().split(' ')
T = [int(T[i]) for i in range(N)]
SUM = sum(T)
M = int(input())
for i in range(M):
  P, X = input().split(' ')
  P = int(P)
  X = int(X)
  A = SUM - T[P-1] + X
  print(A)


Measured memory_bytes: 9168
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <cstring>

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define vi vector <int>
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))
#define fname "searching"

const int inf = (int)1e9;
const ll INF = (ll)1e18;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int mod = (int)1e9 + 7;

string s;
char c[100100];
int a[30];

int main(){
	// freopen("input.txt", "r", stdin);
	// freopen(fname".in", "r", stdin);
	// freopen(fname".out", "w", stdout);
	scanf("%s", c);
	s = c;
	for(int i = 0; i < sz(s); ++i){
		a[s[i] - 'a']++;
	}
	for(int i = 0; i < 26; ++i){
		if(a[i] == 0){
			printf("%c\n", (char)('a' + i));
			return 0;
		}
	}
	printf("None\n");
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
    std::string s;
    cin >> s;
    std::string chk = "hi";
    int len = s.size()/2;
    std::string ans;
//    to_string(N).size()
    for (int i = 0; i < len; i++) {
        ans += chk;
    }
//    cout << "ans :" << ans << endl;
    if(s.size()%2 == 0 && ans == s){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;        
    }

}

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

using namespace std;
const int maxn=1e6+111;
int v[maxn], N, p[maxn];
map<int, int> cnt;
int main(){
    scanf("%d", &N);
    for (int i=1; i<=N; i++) scanf("%d", &p[i]), cnt[p[i]]++;
    sort(p+1, p+1+N);
    int ans=0;
    for (int i=1; i<=N; i++){
        if (v[p[i]]) continue;
        if (cnt[p[i]]==1)ans++;
        for (int j=1; j*p[i]<=p[N]; j++) v[j*p[i]]=1;
    }
    printf("%d", ans);
}

Measured memory_bytes: 16952
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<ll, int> P;

int main()
{
	int n; cin>>n;
	string s[55];
	ll c[55];
	for(int i=0; i<n; i++){
		cin>>s[i]>>c[i];
	}
	const ll INF=1e18;
	ll ans=INF;
	for(int i=0; i<n; i++){
		string t=s[i];
		reverse(t.begin(), t.end());
		if(s[i]==t) ans=min(ans, c[i]);
	}
	vector<P> g[2020];
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			bool ok=1;
			for(int k=0; k<min(s[i].size(), s[j].size()); k++){
				if(s[i][k]!=s[j][(int)s[j].size()-1-k]){
					ok=0;break;
				}
			}
			if(!ok) continue;
			string t=s[i]+s[j], tr=t;
			reverse(tr.begin(), tr.end());
			if(t==tr){
				g[0].push_back({c[i]+c[j], 0});
			}else{
				int l=abs((int)s[i].size()-(int)s[j].size());
				if(s[i].size()<s[j].size()){
					g[0].push_back({c[i]+c[j], 40*j+20+l});
				}else{
					g[0].push_back({c[i]+c[j], 40*i+l});
				}
			}
		}
	}
	for(int i=0; i<n; i++){
		for(int l=1; l<(int)s[i].size(); l++){
			for(int j=0; j<n; j++){
				bool ok=1;
				for(int k=0; k<min(l, (int)s[j].size()); k++){
					if(s[i][(int)s[i].size()-l+k]!=s[j][(int)s[j].size()-1-k]){
						ok=0;break;
					}
				}
				if(!ok) continue;
				string t=s[i].substr((int)s[i].size()-l)+s[j], tr=t;
				reverse(tr.begin(), tr.end());
				if(t==tr){
					g[40*i+l].push_back({c[j], 0});
				}else{
					int m=abs(l-(int)s[j].size());
					if(l<s[j].size()){
						g[40*i+l].push_back({c[j], 40*j+20+m});
					}else{
						g[40*i+l].push_back({c[j], 40*i+m});
					}
				}
			}
		}
	}
	for(int i=0; i<n; i++){
		for(int l=1; l<(int)s[i].size(); l++){
			for(int j=0; j<n; j++){
				bool ok=1;
				for(int k=0; k<min(l, (int)s[j].size()); k++){
					if(s[i][l-1-k]!=s[j][k]){
						ok=0;break;
					}
				}
				if(!ok) continue;
				string t=s[j]+s[i].substr(0, l), tr=t;
				reverse(tr.begin(), tr.end());
				if(t==tr){
					g[40*i+20+l].push_back({c[j], 0});
				}else{
					int m=abs(l-(int)s[j].size());
					if(l<s[j].size()){
						g[40*i+20+l].push_back({c[j], 40*j+m});
					}else{
						g[40*i+20+l].push_back({c[j], 40*i+20+m});
					}
				}
			}
		}
	}
	ll d[2020];
	for(int i=0; i<40*n; i++) d[i]=INF;
	d[0]=0;
	priority_queue<P, vector<P>, greater<P>> que;
	que.push({0, 0});
	while(!que.empty()){
		P p=que.top(); que.pop();
		int x=p.second;
		if(p.first>d[x]) continue;
		for(auto q:g[x]){
			int y=q.second;
			if(d[y]>d[x]+q.first){
				d[y]=d[x]+q.first;
				que.push({d[y], y});
			}
		}
	}
	for(int x=0; x<40*n; x++){
		for(auto q:g[x]){
			int y=q.second;
			if(y==0){
				ans=min(ans, d[x]+q.first);
			}
		}
	}
	if(ans<INF) cout<<ans<<endl;
	else cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 3712
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1000100011;
// clang-format on

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<char> vowel = {'a', 'i', 'u', 'e', 'o'};
  char c;
  cin >> c;

  bool ans = false;
  REP(i, 5) { ans |= vowel[i] == c; }
  cout << (ans ? "vowel" : "consonant") << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MX = 1000001;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> isprime(MX);
  for (int &i : a) {
    cin >> i;
    isprime[i]++;
  }
  bool pairwise = true;
  for (int i = 2; i < MX; i++) {
    int cnt = 0;
    for (int j = i; j < MX; j += i) cnt += isprime[j];
    if (cnt > 1) pairwise = false;
  }
  if (pairwise) {
    cout << "pairwise coprime" << endl;
    return 0;
  }
  int g = 0;
  for (int i = 0; i < n; i++) g = gcd(g, a[i]);
  if (g == 1) {
    cout << "setwise coprime" << endl;
    return 0;
  }
  cout << "not coprime" << endl;
  return 0;
}

Measured memory_bytes: 11176
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int[] a = new int[3];
		for(int i = 0;i < 3;i++){
			a[i] = saori.saori_hayami();
		}
		Arrays.sort(a);
		int ans = 0;
		for(int i = 0;i < 2;i++){
			ans = Math.abs(a[i] - a[i+1]) + ans;
		}
		System.out.println(ans);
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 22996
h,w=map(int,input().split())
a=[list(map(int,input().split())) for i in range(h)]
cnt=0
for i in range(h):
  for j in range(w):
    if a[i][j]%2:
      cnt+=1
if cnt%2:
  cnt-=1
if cnt==0:
  print(0)
  exit()
ans=[[] for i in range(cnt//2)]
l=0
for i in range(h):
  for j in range(w):
    if cnt==0:
      break
    if i%2:
      if a[i][w-j-1]%2:
        cnt-=1
        if cnt%2==0:
          ans[l].append([i+1,w-j])
          l+=1
      if cnt%2:
        ans[l].append([i+1,w-j])
    else:
      if a[i][j]%2:
        cnt-=1
        if cnt%2==0:
          ans[l].append([i+1,j+1])
          l+=1
      if cnt%2:
        ans[l].append([i+1,j+1])
t=0
for i in range(len(ans)):
  t+=len(ans[i])-1
print(t)
for i in range(len(ans)):
  for j in range(len(ans[i])-1):
    k=ans[i][j]+ans[i][j+1]
    print(*k)

Measured memory_bytes: 53904
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<array>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

#ifdef ONLINE_JUDGE
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
#define int128 __int128
#else
#define int128 long long
#endif

#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(nullptr));

ll  mod = 1e9 + 7;

namespace {
	ll mul(ll a, ll b) {
		ll val = a * b - (ll)((ld)a * b / mod) * mod;
		if (val < 0) val += mod;
		if (val >= mod) val -= mod;
		return val;
	}
	ll poww(ll a, ll b) {
		ll val = 1;
		a %= mod;
		while (b > 0) {
			if (b % 2) val = mul(a, val);
			a = mul(a, a);
			b >>= 1;
		}
		return val % mod;
	}
	ll inv(ll a) {
		return poww(a, mod - 2);
	}
}

ll const maxn = 3e5 + 5;

ll f[maxn];

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n, k; cin >> n >> k;

	ll ans = 0;
	ll flex = poww(k, n);
	//ans += flex;
	ans %= mod;
	
	for (ll i = k; i >= 1; i--) {
		ll kek = k / i;
		ll sm = poww(kek, n); 
		sm %= mod; if (sm < 0) sm += mod;
		f[i] = sm;
		for (ll j = 2 * i; j <= k; j += i) {
			f[i] -= f[j];
			f[i] %= mod; if (f[i] < 0) f[i] += mod;
		}
		ans += mul(f[i], i);
		ans %= mod;
	}

	
	cout << ans << endl;

	return 0;
}

/*

*/

Measured memory_bytes: 4420
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a+b==c || b+c==a || c+a==b) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; string s; cin>>n>>s;
	vector<int>E(n),W(n);
	for(int i=0,cnt=0;i<n;++i){
		if(s.at(i)=='W')++cnt;
		W.at(i)=cnt;
	}
	for(int i=n-1,cnt=0;i>=0;--i){
		if(s.at(i)=='E')++cnt;
		E.at(i)=cnt;
	}
	int ans=0x7FFFFFFF;
	for(int i=0;i<n;++i){
		ans=min(ans,E.at(i)+W.at(i));
	}
	cout<<ans-1<<"\n"s;
}

Measured memory_bytes: 2964
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>
#include <complex>

using namespace std;

#define mod 1000000007

int main()
{
	string s;
	cin >> s;
	if(s == "SUN") cout << 7 << endl;
	else if(s == "MON") cout << 6 << endl;
	else if(s == "TUE") cout << 5 << endl;
	else if(s == "WED") cout << 4 << endl;
	else if(s == "THU") cout << 3 << endl;
	else if(s == "FRI") cout << 2 << endl;
	else cout << 1 << endl;
 }

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

int main(){
    int w,h,x,y;
    cin >> w >> h >> x >> y;
    cout << (double)w*(double)h/(double)2 << " ";
    if(x*2==w&&y*2==h)cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define pb push_back
#define fst first
#define snd second
#define PI (acos(-1))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))

#define MAXN 1123456
#define MOD 1000000007

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vii;
typedef vector<vi> vvi;

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

  int n;
  cin>>n;
  vi a(n), b(n);
  rep(i,0,n)cin>>a[i];
  rep(i,0,n)cin>>b[i];
  ll ans = 0;
  priority_queue<pii> pq;
  rep(i,0,n) if (b[i] > a[i]) pq.push({b[i], i});
  bool good=true;
  while (!pq.empty()) {
    int wtf = pq.top().fst;
    int m = pq.top().snd;
    pq.pop();
    if (b[m] != wtf) continue;
    int y=max(a[m],max(b[(m-1+n)%n], b[(m+1)%n]));
    int sum = b[(m-1+n)%n] + b[(m+1)%n];
    int k = ((b[m] - y + sum - 1) / sum);
    b[m] -= k * sum;
    ans += k;
    if (b[m] != a[m])
      pq.push({b[m],m});
    if (b[m] < a[m]) break;
  }
  rep(i,0,n) {
      if (a[i]!=b[i]) {
        good=false;
        break;
      }
    }
  if (good)cout<<ans<<endl;
  else cout<<-1<<endl;
}



Measured memory_bytes: 9712
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define ll_MAX LONG_LONG_MAX
#define ll_MIN LONG_LONG_MIN
#define pi pair<int,int>
#define endl "\n"
#define MAXN 100005
#define mod 1000000007
using namespace std;

void solve()
{
    
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
    solve();
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll k = max(a*c, a*d);
    ll k1 = max(b*c, d*b);
    cout<<max(k, k1)<<'\n';
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

ll N,M,Q;
ll A[55], B[55], C[55], D[55];
ll ans = 0;
ll i, j, k;
ll mkA[55];

ll calc(){
    ll ret = 0;
    fornum(i,0,Q){
        if(mkA[B[i]-1]-mkA[A[i]-1]==C[i]){
            ret += D[i];
        }
    }
    return ret;
}

ll dfs(ll ii,ll pn){
    if(ii==N){
        return calc();
    }
    ll i = 0;
    ll ret = 0;
    fornum(i,pn,M+1){
        mkA[ii] = i;
        ret = max(ret, dfs(ii + 1, i));
    }
    return ret;
}

int main(){
    scanf("%lld%lld%lld", &N, &M, &Q);
    fornum(i,0,Q){
        scanf("%lld%lld%lld%lld", &A[i], &B[i], &C[i], &D[i]);
    }
    printf("%lld\n", dfs(0, 1));
    return 0;
}

Measured memory_bytes: 3828
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]


class Combinations:
    def __init__(self, max_num, mod):
        self.mod = mod
        self.factorials = [1]
        for i in range(1, max_num + 1):
            self.factorials.append((self.factorials[-1] * i) % mod)
        self.invs = [pow(self.factorials[-1], mod - 2, mod)]
        for i in reversed(range(1, max_num + 1)):
            self.invs.append(self.invs[-1] * i % mod)
        self.invs = self.invs[::-1]

    def __call__(self, n, k):
        if n < 0 or k < 0 or k > n:
            return 0
        return self.factorials[n] * self.invs[k] * self.invs[n - k] % self.mod


MOD = 10**9 + 7

x, y = ril()
a = (2 * x - y) // 3
b = a - x + y
if 3 * a != 2 * x - y:
    print(0)
    exit()

combinations = Combinations(10**6, MOD)
print(combinations(a + b, a))

Measured memory_bytes: 116592
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: i64,
        x: i64,
        m: [i64; n],
    }

    let need: i64 = m.iter().sum();
    if let Some(minm) = m.iter().min() {
        println!("{}", (x - need) / minm + n);
    }
}

Measured memory_bytes: 4352
pub struct Scanner{
    line : Vec<String> ,
    idx : usize
}

#[allow(dead_code)]
impl  Scanner{
   fn new() -> Scanner{
       return Scanner{ line: vec![], idx : 0}
   }
   fn next<T: std::str::FromStr> (&mut self) -> T{
       if self.idx == self.line.len() {
           let mut buffer = String::new();
           std::io::stdin().read_line(&mut buffer).ok();

           let a : Vec<&str>  = buffer.trim().split(' ').collect();
           self.line = a.iter().map(|&s| String::from(s)).collect();
           self.idx = 0;
       }
       let ret : T = self.line[self.idx].parse::<T>().ok().expect("Parse error.");
       self.idx += 1;
       ret
   }
   fn next_string(&mut self) -> Vec<char> {
       let s : String = self.next();
       return s.chars().collect::<Vec<char>>();
   }
   fn next_vec<T: std::str::FromStr>  (&mut self, n: usize) -> Vec<T>{
       let mut v : Vec<T>= Vec::with_capacity(n);
       for _i in 0..n {
           v.push(self.next());
       }
       v
   }
}


fn main() {
    let mut scan = Scanner::new();
    let a:i32  = scan.next();
    let b:i32  = scan.next();
    let c:i32  = scan.next();

    println!("{} {} {}", c, a, b);
}


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

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef long double ld;
typedef pair <ll ,ll> pll;
typedef pair <int ,int> pii;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define print(a) {for (auto iiiiiiiiii : a) cout << iiiiiiiiii << ' '; cout << '\n';}
#define fi first
#define se second
#define all(x) (x).begin() , (x).end()

ll next() {ll x; cin >> x; return x;}

const ll inf = 1e18 , mod = 998244353;
const int intf = 2e9 , maxn = 1e5;
const double PI = 3.141592653589 , eps = 1e-8;


void solve(){
    ll s; cin >> s;
    ll k = sqrt(s);
    if (k*k != s) k++;
    ll d = k*k - s;
    vector <ll> ans = {0 , 0 , k , 1 , d , k};
    print(ans);
}

int main()
{
    #ifdef HERE
        freopen("input.txt" , "r" , stdin);
    #else
        //freopen(".in" , "r" , stdin); freopen(".out" , "w" , stdout);
        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    #endif
    cout.precision(20);

    int t = 1;
    while(t --> 0){
        solve();
    }


    #ifdef HERE
        cout << setprecision(3) << fixed << "\n\nRuntime: " << (long double)(clock()) / CLOCKS_PER_SEC << " s.\n";
    #endif
    return 0;
}
/*

*/


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
vector<vector<int> > g;

int mx = 0;
int mxi = 0;
int dfs(int a, int p, int d) {
	if (mx < d) {
		mx = d;
		mxi = a;
	}
	for (int i : g[a]) {
		if (p != i) {
			dfs(i, a, d + 1);
		}
	}
}

int solve(int a) {
	mx = 0;
	mxi = 0;
	dfs(a, -1, 0);

	return mxi;

}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	g.resize(N);
	int res = 0;
	int a, b;
	for (int i = 0; i < N - 1; i++) {
		cin >> a >> b; a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	a = solve(0);
	solve(a);
	mx++;
	if (mx % 3 == 2) {
		cout << "Second" << endl;
	}
	else {
		cout << "First" << endl;
	}
}

Measured memory_bytes: 20608
# 学習用
import bisect
A , B , Q = map(int, input().split())
INF = 10 ** 18
Sa = [-INF] + [int(input()) for s in range(A)] + [INF]
Tb = [-INF] + [int(input()) for s in range(B)] + [INF]
Xq = [int(input()) for s in range(Q)]
for x in Xq:
    b  , d = bisect.bisect_right(Sa,x) , bisect.bisect_right(Tb,x) 
    res = INF 
    for S in [Sa[b -1] , Sa[b]]:
        for T in [Tb[d-1], Tb[d]]:
            d1 , d2 = abs(S-x) + abs(T -S) , abs(T-x)+abs(S-T)
            res = min(res , d1 , d2)
    print(res)

Measured memory_bytes: 17552
#include <iostream>
#define ll long long
using namespace std;

const ll MD = 1e9 + 7, I2 = 5e8 + 4;

int n;
ll res1, res2;

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		ll x; cin >> x; res2 += MD - x * x % MD;
		res2 %= MD;
		res1 += x;
		res1 %= MD;
	}
	cout << (res1 * res1 + res2) % MD * I2 % MD << "\n";
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <bitset>

#define lp(n) for(int i=0;i<n;i++)
#define LP(n,i) for(int i=0;i<n;i++)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define intmin -2147483637
#define llmax 9223372036854775807
typedef long long ll;

using namespace std;

int n,k,mem,cnt2;
ll cnt,mn,a[16];
bool ck[16];

/*ll gcd(ll x,ll y){
	if(y==0)return x;
	return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	ll g=gcd(x,y);
	return x/g*y;
}*/

int main(){
	cin>>n>>k;
	if(n==1){
		cout<<0<<endl;
		return 0;
	}
	lp(n)
		cin>>a[i];
	cnt=0;
	mn=llmax;
	lp(1<<(n-1)){
		mem=i;
		cnt=0;
		cnt2=0;
		LP(n-1,j){
			if(mem%2==1){
				ck[j]=true;
				cnt2++;
			}
			else ck[j]=false;
			mem=mem>>1;	
		}
		if(cnt2==k-1){
			mem=a[0];
			LP(n-1,j){
				if(ck[j]){
					if(mem>=a[j+1]){
						cnt+=mem-a[j+1]+1;
						mem++;
					}
					else{
						mem=a[j+1];
					}
				}
				if(mem<=a[j+1])mem=a[j+1];
			}
//			cout<<static_cast<bitset<8>>(i)<<sp<<cnt<<endl;
			if(mn>cnt)mn=cnt;
		}
	}
	cout<<mn<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
  
  char x,y;
  char z;
  
  cin >> x >> y;

  if(x > y){
    z = '>';
  } else if(x < y){
    z = '<';
  } else {
    z = '=';
  }

  cout << z << endl;    

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define ll long long int

int main() {
	int l, r, d;
	cin >> l >> r >> d;
	
	int x;
	if(l%d == 0) x = 0;
	else x = d - (l % d);
	int y = r % d;

	cout << ((r-y)-(l+x))/d + 1 << endl;
	return 0;
}

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

int main(void){
	char su[N]={'0'};
	int susum=0;
	int j=0;
	
	while(1){
		for(j=0;j<=N;j++){
			scanf("%c",&su[j]);
			if(su[j]=='\n')break;
			susum=susum+(su[j]-'0');
		}	
		if(su[0]=='0')break;
		printf("%d\n",susum);
		susum=0;
	}
	return 0;
}



Measured memory_bytes: 2056
#include<stdio.h>
main()
{
	int a,n,b,c;
	scanf("%d%d%d",&n,&a,&b);
	if(a<b){
		c=a;
		a=b;
		b=c;
	}
	if((a-b)%2==0)printf("Alice\n");
	else printf("Borys\n");
}

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

int main(){
  int N, sum, kotae;
  double ave;
  cin >> N;
  vector<int> s(N); 
  sum = 0;
  kotae = 0;
  for(int i = 0;i < N;i++){
  cin >> s.at(i);
  sum += s.at(i);
  }
  ave = ((double) sum) / N;
  ave = round(ave);
  for(int i= 0;i < N;i++){
  kotae += (s.at(i) - ave) * (s.at(i) - ave);
  }
  cout << kotae << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<long long, long long>;
const int INF = numeric_limits<int>::max();
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

bool is_prime(ll n) {
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) return false;
    }
    return n != 1;
}

vector<vector<int>> d(10, vector<int>(10, 1000000));

void warshall_floyd(int n) {
    rep(k,n) rep(i,n) {
        rep(j,n) {
            d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
        }
    }
}

int main()
{
    ll a, b, k; cin >> a >> b >> k;

    rep(i,k) {
        if (i % 2 == 0) {
            if (a % 2 == 1)
                a--;
            b += a/2;
            a /= 2;
        } else {
            if (b % 2 == 1)
                b--;
            a += b/2;
            b /= 2;
        }
    }
    cout << a << " " << b << endl;
            
    return 0;
}


Measured memory_bytes: 3612
#include<stdio.h>
int main(){
  int n;
  int m,e,j,i;
  while(1){
    scanf("%d",&n);
    if(n==0)break;
    for(i=0;i<n;i++){
      scanf("%d %d %d",&m,&e,&j);
      if(m==100||e==100||j==100)printf("A\n");
      else if(m+e  >=180)printf("A\n");
      else if(m+e+j>=240)printf("A\n");
      else if(m+e+j>=210)printf("B\n");
      else if(m+e+j>=150&&(m>=80||e>=80))printf("B\n");
      else printf("C\n");
    }
  }
  return 0;
}

Measured memory_bytes: 584
a, b, x = map(int, input().split())
flag = True

n = a % x
m = b % x

if n == 0:
    ca = a
else:
    ca = a + (x - n)
    if ca > b:
        flag = False

if m == 0:
    cb = b
else:
    cb = b - m

if flag:
    print((cb - ca) // x + 1)
else:
    print(0)

Measured memory_bytes: 3064
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n = II()
    print((n-2)*180)
    return

#B
def B():
    b = S()
    kati = b.count("o")
    kati += 15 - len(b)
    if kati >= 8:
        print("YES")
    else:
        print("NO")
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    B()


Measured memory_bytes: 39152
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
typedef long long ll;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

    sort(x.begin(), x.end());
    int a = x[n/2-1], b = x[n/2];

    for (int i = 0; i < n; i++) {
        if(xc[i] <= a) {
            cout << b << endl;
        } else if (xc[i] >= b) {
            cout << a << endl;
        } 
    }

    return 0;
}



Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
int main(){
    long n,m;
    cin>>n>>m;
    vector<long[2]> ab(n),cd(m);
    for(int i=0 ; i<n; i++)
        cin>>ab[i][0]>>ab[i][1];
    for(int i= 0; i<m; i++)
        cin>>cd[i][0]>>cd[i][1];
    for(auto st:ab){
        unsigned long min = -1,ma;
        for(int i = 0; i<m; i++){
            long t = abs(st[0]-cd[i][0])+abs(st[1]-cd[i][1]);
            if(t<min){
                min=t;
                ma=i;
            }
        }
        cout<<ma+1<<endl;
    }
}

Measured memory_bytes: 256