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

int main(){
  long long N,P;
  string S;
  cin>>N>>P>>S;
  if(P==2){
    long long ans=0;
    for(long long i=0;i<N;i++){
      if((S.at(i)-'0')%2==0){
        ans+=i+1;
      }
    }
    cout<<ans<<endl;
  }else if(P==5){
    long long ans=0;
    for(long long i=0;i<N;i++){
      if((S.at(i)-'0')%5==0){
        ans+=i+1;
      }
    }
    cout<<ans<<endl;
  }else{
    vector<long long> s(N),a(N),count(P,0);
    long long res=1;
    for(long long i=0;i<N;i++){
      a.at(i)=res;
      res*=10;
      res%=P;
      s.at(i)=S.at(i)-'0';
    }
    reverse(s.begin(),s.end());
    long long x=0;
    for(long long i=0;i<N;i++){
      x+=a.at(i)*s.at(i);
      x%=P;
      count.at(x)++;
    }

    long long ans=count.at(0)*(count.at(0)+1)/2;
    for(long long i=1;i<P;i++){
      ans+=count.at(i)*(count.at(i)-1)/2;
    }
    cout<<ans<<endl;
  }
}


Measured memory_bytes: 3716
#include <iostream>

int main() {
  std::string s;
  std::cin >> s;
  char tmp = '0';
  unsigned ret = 0u;
  for (const auto &i : s) {
    if (i != tmp) {
      ++ret;
      tmp = i;
    }
  }
  std::cout << ret - 1;
  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<double,int,double> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf=sizeof(Def)==sizeof(long long)?9e18:1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	ll n,m;
	cin>>n>>m;
	vp in(n);
	rep(i,n)cin>>in[i].first>>in[i].second;
	sort(all(in));
	ll out=inf;
	rep(i,n-1)loop(j,i+1,n){
		vi t;
		loop(k,i,j+1)t.pb(in[k].second);
		sort(all(t));
		if((int)t.size()-m+1>0)rep(k,t.size()-m+1)
			out=min(out,(in[j].first-in[i].first)*(t[k+m-1]-t[k]));
	}
	cout<<out<<endl;
}









Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
int nxt[64][200010];
vector<int> v[200010];
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    int A[200010];
    rep(i, N) {
        cin >> A[i];
        A[i]--;
        v[A[i]].push_back(i);
        v[A[i]].push_back(N + i);
    }
    rep(i, 200010) sort(v[i].begin(), v[i].end());
    rep(i, N) {
        //cout << i << " " << *lower_bound(v[A[i]].begin(), v[A[i]].end(), i + 1) << endl;
        int k = *lower_bound(v[A[i]].begin(), v[A[i]].end(), i + 1);
        nxt[0][i] = k - i;
    }
    rep(i, 60) {
        rep(j, N) {
            int state0 = j;
            int state1 = state0 + nxt[i][state0 % N] + 1;
            int state2 = state1 + nxt[i][state1 % N];
            nxt[i + 1][j] = state2 - state0;
        }
    }
    //rep(i, N) cout << nxt[0][i] << " " << nxt[1][i] << endl;
    int x = 0;
    while(x < (K - 2) * N) {
        int k = 0;
        while(x + nxt[k + 1][x % N] < (K - 2) * N) k++;
        x += nxt[k][x % N] + 1;
        //cout << x << endl;
    }
    //cout << "!" << x << endl;
    set<int> st;
    deque<int> que;
    while(x < K * N) {
        if(st.find(A[x % N]) != st.end()) {
            while(que.size() && que.back() != A[x % N]) {
                st.erase(que.back());
                que.pop_back();
            }
            if(que.size()) {
                st.erase(que.back());
                que.pop_back();
            }
        } else {
            que.push_back(A[x % N]);
            st.insert(A[x % N]);
        }   
        //cout << que.size() << " " << x << " " << A[x % N] << endl;
        x++;
    }
    while(que.size()) {
        cout << que.front() + 1;
        que.pop_front();
        if(que.size()) cout << " ";
    }
    cout << endl;


    return 0;
}
// 0 1 2 3 4 5 6 7 8 9 0 1 
// 1 2 3 1 2 3 1 2 3 1 2 3

Measured memory_bytes: 122468
#include <bits/stdc++.h>
using namespace std;
const int maxn=112345;
int n,a,b,d[maxn],res,dd[maxn];
vector<int> G[maxn];
void dfs(int u,int fa,int dep) {
    d[u]=dep;
    for (int i=0;i<(int)G[u].size();++i) {
        int v=G[u][i];
        if (v==fa) continue;
        dfs(v,u,dep+1);
    }
}
void dfs2(int u,int fa,int dep) {
    dd[u]=dep;
    if ((int)G[u].size()==1) res=max(res,d[u]-(d[u]>dd[u]));
    for (int i=0;i<(int)G[u].size();++i) {
        int v=G[u][i];
        if (v==fa) continue;
        if (d[v]<=dep+1) continue;
        dfs2(v,u,dep+1);
    }
}
int main()
{
    scanf("%d%d%d",&n,&b,&a);
    for (int i=0;i<n-1;++i) {
        int a,b;scanf("%d%d",&a,&b);
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dfs(a,-1,0);
    dfs2(b,-1,0);
    printf("%d\n",res);
    return 0;
}


Measured memory_bytes: 13184
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <tuple>  // std::tuple std::get
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;

#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (int i=0; i < (int)(n); i++)  // 0 ~ n-1
#define REPN(i, n) for (int i=1; i <= (int)(n); i++)  // 1 ~ n
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
typedef long long ll;

const int MOD = 1000000007;  // 1 000 000 007


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

    // input
    string str;
    cin >> str;
    
    // calculation
    int sum = 700;
    REP(i, str.length()) if (str[i] == 'o') sum += 100;
    cout << sum << "\n";
    return 0;
}


Measured memory_bytes: 256
//AcFreak

#include<bits/stdc++.h>
#define lint long long int 
#define mp make_pair
#define pb push_back
#define f first
#define INF (lint )(1e9)
#define __ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define s second
#define endl '\n'
#define pii pair<int,int >
using namespace std;
struct pair_hash {
    template <class T1, class T2>
    std::size_t operator () (const std::pair<T1,T2> &p) const {
        auto h1 = std::hash<T1>{}(p.first);
        auto h2 = std::hash<T2>{}(p.second);
        
        return h1 ^ h2;  
    }
};
int dp[505][505];
int cdp[505][505];
int n,m,q;
void init()
{
	for(int i=0;i<505;i++)
	{
		for(int j=0;j<505;j++)
		{
			dp[i][j]=-1;
			cdp[i][j]=0;
		}
	}
}

int  solve(int start,int end)
{
	if(start>n || end<1)
		return 0;
	if(end<start)
		return 0;
	if(start == end)
		return dp[start][end]=cdp[start][end];
	if(dp[start][end] != -1)
		return dp[start][end];

	dp[start][end]=solve(start+1,end)+solve(start,end-1)+cdp[start][end]-solve(start+1,end-1);
	return dp[start][end];
}
int main()
{__	

		init();

		
		cin>>n>>m>>q;
		while(m--)
		{
			int l,r;
			cin>>l>>r;
			cdp[l][r]+=1;
		}
		int i,j;
		j=solve(1,n);
		while(q--)
		{
			int l,r;
			cin>>l>>r;
			cout<<dp[l][r]<<endl;
		}
      return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define maxN 200002
#define maxA 26
using namespace std;

//FILE *fin = freopen("b.in", "r", stdin);

int n;
char a[maxN];

int frq[maxA];

long long ans;

int main()
{
    scanf("%s", a + 1);
    n = strlen(a + 1);
    for (int i = 1; i <= n; ++ i)
        ++ frq[a[i] - 'a'];
    for (int i = 1; i <= n; ++ i)
    {
        -- frq[a[i] - 'a'];
        ans += 1LL * (n - i - frq[a[i] - 'a']);
    }
    printf("%lld\n", ans + 1);
    return 0;
}


Measured memory_bytes: 384
N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

import math
import itertools

if P == Q:
  print(0)
  exit(0)
count = 0
a,b = 0,0
l = list(range(1,N+1))
for v in itertools.permutations(l):
  count += 1
  if v == P:
    a = count
  elif v == Q:
    b = count

print(abs(a-b))


Measured memory_bytes: 3064
#include<stdio.h>
int main(){
       
int a, b, menseki, shuui;
       
scanf("%d %d",&a,&b);
       
menseki = a*b;
shuui = 2*a + 2*b;
       
printf( "%d %d\n",menseki, shuui );
       
return 0;
     
}

Measured memory_bytes: 596
#include<cstdio>
#include<iostream>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<deque>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<limits>
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
using namespace std;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define rep(I,N) up(I,0,N-1)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                                      ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}
inline                                              void out(ld p){printf("%.12Lf\n",p);}
template<class T>inline                             void outml(T p){for_each(all(p),out<decltype(p[0])>);}
template<class T>inline void outol(T V){int n=V.size();rep(i,n)cout<<V[i]<<" \n"[i==n-1];}
inline void solve(void){
  int N;
  in(N);
  vector<int>A(N),B(N);
  ins(A);ins(B);
  priority_queue<int>q;
  long lack=0;
  long cnt=0;
  long sum=0;
  rep(i,N)sum+=A[i]-B[i];
  if(sum<0){
    out(-1);
    return;
  }
  rep(i,N){
    if(A[i]>B[i])q.push(A[i]-B[i]);
    if(A[i]<B[i])lack+=B[i]-A[i],cnt++;
  }
  while(!q.empty()){
    int e=q.top();q.pop();
    if(lack<=0)break;
    lack-=e;
    cnt++;
  }
  if(lack<=0)out(cnt);
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define mx 100007
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;

vector<int>adj[mx];
int deg[mx], lvl[mx];
int ans= 1;
bool vis[mx];
int dp[mx];

int dfs( int u )
{
    if( vis[u] )
        return dp[u];

    dp[u]= 0;

    for( auto v: adj[u] )
        dp[u]= max( dp[u], dfs(v)+1);

    vis[u]= 1;

    return dp[u];
}

int main()
{
    FAST

    int n,m;
    cin>>n>>m;

    for( int i=0;i<m;i++ )
    {
        int p,q;
        cin>>p>>q;

        adj[p].push_back(q);
        deg[q]++;
    }

    for( int i=1;i<=n;i++ )
        if( !deg[i] )
            ans= max( ans, dfs(i) );

    cout<<ans<<endl;
}


Measured memory_bytes: 9856
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

typedef int keytype;

//quicksort(<#keytype *a#>, <#int first#>, <#int last#>)

void quicksort(keytype a[], int first, int last){
    int i, j;
    keytype x, t;
    
    x = a[(first + last) / 2];
    i = first;  j = last;
    for ( ; ; ) {
        while (a[i] < x) i++;
        while (x < a[j]) j--;
        if (i >= j) break;
        t = a[i];  a[i] = a[j];  a[j] = t;
        i++;  j--;
    }
    if (first  < i - 1) quicksort(a, first , i - 1);
    if (j + 1 < last) quicksort(a, j + 1, last);
}

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

int main() {
    double l;
    scanf("%lf",&l);
    l=l/3;
    l=l*l*l;
    printf("%lf",l);
    return 0;
}


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

Ans = 0
for i in range(1,N+1):
  if i % 2 == 1:
    c = 0
    for j in range(1,i+1):
      if i % j == 0:
        c +=1
    if c == 8:
      Ans +=1
print(Ans)

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

int N;int big_n=2000000000;

int main() {
  cin >> N;
  vector<int> A(N);
  vector<int> B(N+1);B.at(0)=-1;
  vector<vector<int>> C(N);
  for (int i=1;i<=N;i++) {
    cin >> A.at(i-1);
    B.at(i)=big_n;
  }
  for (int i=N-1;i>=0;i--) {
    auto ir=upper_bound(B.begin(),B.end(),A.at(i));
    int d=distance(B.begin(),ir);
    B.at(d)=A.at(i);
  }
  int max_c=0;
  for (int i=0;i<=N;i++) {
    if (B.at(i)==big_n) {
      break;
    }
    max_c++;
  }
  cout << max_c-1 << endl;
}

Measured memory_bytes: 3328
//
// Created on 2019-02-09.
//
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
template<class T> bool INRANGE(T x,T a,T b) { return a<=x&&x<=b; }

#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

#define PB push_back
#define INF 1e9
#define MOD 1e9+7
#define EPS 1e-9

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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


    ll K, A, B;
    cin >> K >> A >> B;

    bool zuutoTataku = false;

    ll gain = B-A;
    //cout << "gain " <<gain << endl;


    if (gain <= 3) zuutoTataku = true;

    if (zuutoTataku) {
        cout << K+1 << endl;
        return 0;
    } else {
        ll cost = K -(A-1);
        //cout << "cost " << cost << endl;
        ll num_change = cost/2;
        //cout << "change " << num_change << endl;
        ll num_tataku = cost%2;
        //cout << "tataku "<< num_tataku << endl;
        ll ans = gain*num_change+A + num_tataku;

        cout << ans << endl;
        //if (ans == 48518828981938099) cout << "OK\n";
        return 0;
    }

}

Measured memory_bytes: 256
N, K = map(int, input().split())
mod = 10 ** 9 + 7

inv = [pow(i, mod - 2, mod) for i in range(1, N + 1)]
table = []
inv_table = []
tmp = 1
inv_tmp = 1
for i in range(N):
    tmp *= (i + 1)
    tmp %= mod
    table.append(tmp)
    inv_tmp *= inv[i]
    inv_tmp %= mod
    inv_table.append(inv_tmp)

def cmb(n, k):
    if n == 0:
        return 1
    if k == 0:
        return 1
    if n == k:
        return 1
    ans = table[n - 1]
    ans *= inv_table[k - 1]
    ans *= inv_table[n - k - 1]
    
    return ans % mod
    
for i in range(1, K + 1): 
    ans = 0
    tmp = cmb(K - 1, i - 1)
    if N - K < i - 1:
        print(ans)
        continue
    else:
        tmp_N = N - K - (i - 1)
        if tmp_N > 0:
            ans += cmb(tmp_N + i, i) * tmp
        else:
            ans += tmp
    print(ans % mod)


Measured memory_bytes: 3572
#071-D
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return input()
n=I()
s1=list(S())
s2=SL()
mod=pow(10,9)+7
s=[]
i=0
if n==1:
    ans=3
elif n==2:
    ans=6
else:
    while i<=n-2:
        if s1[i]==s1[i+1]:
            s.append(2)
            i+=2
        else:
            s.append(1)
            i+=1
    if s1[-1]!=s1[-2]:
        s.append(1)
    if s[0]==1:
        ans=3
    else:
        ans=6
    for i in range(1,len(s)):
        if s[i-1]==1:
            ans*=2
        else:
            if s[i]==2:
                ans*=3
        ans=ans%mod
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
using namespace std;
using ll = long long;
using vi = vector<int>;
const int maxn = 1<<19, mlg = 18, rt = 1<<10, mod = 1e9 + 7;
using ld = long double;
using pi = pair<int, int>;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	int n;
	cin >> n;n<<=1;
	vi a(n);
	for(auto &i : a) cin >> i;
	sort(all(a));
	ll ans = 0;
	for(int i = 0; i < n; i+=2) ans += a[i];
	cout << ans;
} 


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

int sum[200000];
int main(){
	int n,q;string s;cin>>n>>q>>s;
	rep(i,s.size()-1){
		sum[i+1]+=sum[i];
		if(s[i]=='A'&&s[i+1]=='C')sum[i+1]++;
	}
	rep(i,q){
		int l,r;scanf("%d%d",&l,&r);l--;
		printf("%d\n",sum[r-1]-sum[l]);
	}
}

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

using namespace std;

#define rep(i , l , r) for(int i = (l) , ___ = (r) ; i <= ___ ; ++i)
#define per(i , r , l) for(int i = (r) , ___ = (l) ; i >= ___ ; --i)

#define DEBUG(...) fprintf(stderr , __VA_ARGS__)

template<typename T>inline int chkmin(T &x , const T &y){ return x > y ? x = y , 1 : 0; }
template<typename T>inline int chkmax(T &x , const T &y){ return x < y ? x = y , 1 : 0; }

template<typename T>inline T read(T &f)
{
	f = 0 ; int x = 1 ; char c = getchar();
	while(!isdigit(c)) x = c == '-' ? -1 : 1 , c = getchar();
	while(isdigit(c)) (f *= 10) += c & 15 , c = getchar();
	return f *= x;
}

using int64 = long long;
using uint64 = unsigned long long;

const int N = 400 + 5;

const double eps = 1e-7;

struct Node
{
	int64 x , y; double theta;
	int operator < (const Node &rhx) const
	{
		return theta < rhx.theta;
	}
} A[N];

int n ;

int64 sX[N] , sY[N];

int main()
{
	// freopen("in" , "r" , stdin);
	read(n);
	rep(i , 1 , n)
	{
		read(A[i].x);
		read(A[i].y);
		A[i].theta = atan2(A[i].x , A[i].y);
	}
	sort(A + 1 , A + 1 + n);
	rep(i , 1 , n) A[i + n] = A[i];
	int64 Ans = 0;
	rep(i , 1 , n * 2)
	{
		sX[i] = sX[i - 1] + A[i].x;
		sY[i] = sY[i - 1] + A[i].y;
	}
	rep(i , 1 , n)
	rep(j , i , i + n - 1)
	{
		int64 X = sX[j] - sX[i - 1];
		int64 Y = sY[j] - sY[i - 1];
		chkmax(Ans , X * X + Y * Y);
	}
	printf("%.15lf\n" , sqrt(Ans)); // ret); // sqrt(Ans));
	// printf("%.12f\n" , fabs(static_cast<long double>(Ans) - ret * ret));	
	return 0;
}


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

bool isok(string  t){
    int n =t.size();
    for(int i=0;i<n/2;i++){
        if(t[i]!=t[n-1-i])
            return false;
    }
    return true;
}
int main(){
    string s;

    cin>>s;
    if (s.size()%2==0){
        cout<<"No"<<endl;
    }else{
        int n= s.size();
        string par1= s.substr(0,(n-1)/2);
        string par2= s.substr((n+1)/2);

        if(isok(par1) && par1==par2){
            cout<<"Yes"<<endl;
        }else{
            cout<<"No"<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        String a = sc.next();
        String b = sc.next();
        
        for(int i = 1; i <= 317; i++){
            if(i*i == Long.parseLong(a+b)){
                System.out.println("Yes");
                return;
            }
        }
        
        System.out.println("No");
    }
}


Measured memory_bytes: 21844
while 1:
    n = int(raw_input())
    if not n:
        break
    ans = 0
    p = 2
    while p**2 <= 2*n:
        if not 2*n % p:
            if (p + 2*n/p) % 2:
                ans += 1
        p += 1
    print ans

Measured memory_bytes: 4200
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
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! {
        a: i32,
        b: i32,
        c: i32,
        x: i32,
    }
    let mut count = 0;
    for ac in 0..(a + 1) {
        for bc in 0..(b + 1) {
            for cc in 0..(c + 1) {
                if 500 * ac + 100 * bc + 50 * cc == x {
                    count += 1;
                }
            }
        }
    }
    println!("{}", count);
}


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

using ll = long long;

const int MOD = 1e9 + 7;
const int MAXN = 410;
int N, C;
int A[MAXN], B[MAXN];
int pw[MAXN][MAXN];
int dp[MAXN][MAXN];

void precomp() {
	for (int i = 0; i < MAXN; i++) {
		pw[0][i] = 1;
	}
	for (int i = 0; i < MAXN-1; i++) {
		for (int j = 0; j < MAXN; j++) {
			pw[i+1][j] = ll(j) * pw[i][j] % MOD;
		}
	}
	for (int i = 0; i < MAXN; i++) {
		for (int j = 1; j < MAXN; j++) {
			pw[i][j] = (pw[i][j] + pw[i][j-1]) % MOD;
		}
	}
}

int main() {
	precomp();
	scanf("%d %d", &N, &C);
	for (int i = 0; i < N; i++) scanf("%d", &A[i]);
	for (int i = 0; i < N; i++) scanf("%d", &B[i]);

	dp[0][0] = 1;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= C; j++) {
			for (int k = 0; k <= C - j; k++) {
				int powSum = pw[k][B[i]] - pw[k][A[i] - 1];
				if (powSum < 0) powSum += MOD;
				dp[i + 1][j + k] = (dp[i + 1][j + k] + ll(powSum) * dp[i][j]) % MOD;
			}
		}
	}
	printf("%d\n", dp[N][C]);

	return 0;
}


Measured memory_bytes: 1536
N,X=map(int,input().split())
Z=[0]+[ 2**(i+2) -3 for i in range(N+1)]
B=[0]+[ 2**(i+1) -2 for i in range(N+1)]
P=[0]+[ 2**(i+1) -1 for i in range(N+1)]
ans=0
def arg(l,i):
    global ans
    if l != 0 :
        if Z[l]/2+1/2 < i :
            ans += (1 + P[l-1])
#            print("uga")
            return  arg( l-1 , i-( (Z[l]-1)/2 + 1 ) ) 

        elif Z[l]/2 +1/2  > i :
 #           print("aho")
            return arg( l-1 , i - 1)

        else :
            ans += P[l-1] + 1
        #    print("hoge")
    else :
        pass
arg(N+1,X)
print(ans)


Measured memory_bytes: 3064
N,x = map(int,input().split())
a = [i for i in map(int,input().split())]

ans = 0
if a[-1] > x:
  ans += a[-1] - x
  a[-1] = x


for i in range(N-2,-1,-1):
  if a[i] > x-a[i+1]:
    if x - a[i+1] < 0:
      ans += a[i]
      a[i] = 0
    else:
      ans += a[i] - (x - a[i+1])
      a[i] = (x - a[i+1])

print(ans)

Measured memory_bytes: 14068
S = list(input())

if S[-1] != 'i' or S[0] != 'h':
    print('No')
    exit()

pre = 'i'
for s in S:
    if pre == 'i' and s == 'h':
        pre = 'h'
    elif pre == 'h' and s == 'i':
        pre = 'i'
    else:
        print('No')
        exit()

print('Yes')



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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

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

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


// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, x, m, y, k, z, N;
string s, t, d, c;


// <------------- Implement Functions Here ----------> //



// <------------- Start of main() -------------------> //

void MAIN() {
	cin>>n>>m;
	for(ll i=0;i<n;i++) {
		cin>>s;
		cout<<s;
		newl;
		cout<<s;
		newl;
	}
}

int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}


Measured memory_bytes: 3616
import sys
readline = sys.stdin.buffer.readline
MOD = 10**9+7

def main():
    A = int(readline())
    B = int(readline())
    C = int(readline())
    X = int(readline())
    ans = 0
    for a in range(A+1):
        for b in range(B+1):
            for c in range(C+1):
                if 500*a + 100*b + 50*c == X:
                    ans += 1
    print(ans)

if __name__ == '__main__':
    main()

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

int main() 
{
    int a;
    string s;
    cin>>a;
    cout<<"\n";
    cin>>s;
    
    if (a >= 3200)
    {
        cout<<s;
    }
    
    else 
    {
        cout<<"red";
    }
    
    
    return 0;    
}

Measured memory_bytes: 3580
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);




using namespace std;

const int inf=1e18;
const int mod=1e9+7;
const int M=100009;
inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}


 main()

{
    fast
    int n;
    cin>>n;
    int a[n+5];
    int sum=0;
    f(i,1,n)
    {
        cin>>a[i];
        sum+=a[i];
    }
    int yo=(n*(n+1))/2;
    if(sum%yo!=0)
    {
        cout<<"NO"<<endl;
        return 0;
    }
    int k=sum/yo;
    a[n+1]=a[1];
    for(int i=2;i<=n+1;i++)
    {
        int d=a[i]-a[i-1];
        int magic=k-d;
        if(magic<0)
        {
            cout<<"NO"<<endl;
            return 0;
        }
        if(magic%n!=0)
        {
            cout<<"NO"<<endl;
            return  0;
        }
    }
    cout<<"YES"<<endl;
















    return 0;

}













Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
using namespace std;
map <int, int> M;
int f(int x, int y)
{
    if (x>=y) return x-y;
    return x;
}
main()
{
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        int a;
        cin>> a;
        int X = M[a];
        ans -= f(X , a);
        ans += f(X+1 , a);
        M[a]++;
    }
    cout << ans << endl;

}


Measured memory_bytes: 4736
N,K=map(int,input().split())
a=list(map(int,input().split()))
ans=float('INF')
for i in range(1<<(N-1)):
  cnt,s,t=0,0,a[0]+1
  for j in range(N-1):
    if i>>j&1:
      cnt+=1
      x=a[j+1]
      if x>=t:
        t=x+1
      else:
        s+=t-x
        t+=1
    else:
      t=max(t,a[j+1]+1)
  if cnt>=K-1:
    ans=min(ans,s)
print(ans)

Measured memory_bytes: 9212
# include <bits/stdc++.h>
using namespace std;
int main() {
  int r, g, b;
  cin >> r >> g >> b;
  
  int num = r * 100 + g * 10 + b;
  if(num % 4 == 0){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <cassert>
#include <algorithm>
using namespace std;
typedef pair<int, int> edge;
struct state{
  int cost, coupon, station;
  state(int cost_, int coupon_, int station_):cost(cost_), coupon(coupon_), station(station_){}
  bool operator< (const state &s) const{
    if(cost == s.cost){
      return coupon > s.coupon;
    }
    return cost > s.cost;
  }
};
int djikstra(vector<vector<edge> > graph, int start, int goal, int coupon){
  priority_queue<state> pq;
  pq.push(state(0, coupon, start));
  bool visited[coupon+1][graph.size()];
  fill_n((bool*)visited, (coupon+1) * graph.size(), false);
  while(!pq.empty()){
    state cur = pq.top(); pq.pop();
    if(visited[cur.coupon][cur.station]){
      continue;
    }
    if(cur.station == goal){
      return cur.cost;
    }
    visited[cur.coupon][cur.station] = true;
    for(int i = 0; i < graph[cur.station].size(); ++i){
      int to = graph[cur.station][i].first;
      int c = graph[cur.station][i].second;
      if(cur.coupon > 0){
        pq.push(state(cur.cost+c/2, cur.coupon-1, to));
      }
      pq.push(state(cur.cost+c, cur.coupon, to));
    }
  }
  //assert(false);
  return -1;
}
int main(){
  int c, n, m, s, d;
  while(true){    
    cin >> c >> n >> m >> s >> d;
    if((c|n|m|s|d) == 0){
      break;
    }
    vector<vector<edge> > graph(n+1, vector<edge>());
    for(int i = 0; i < m; ++i){
      int a, b, f;
      cin >> a >> b >> f;
      graph[a].push_back(make_pair(b, f));
      graph[b].push_back(make_pair(a, f));
    }
    cout << djikstra(graph, s, d, c) << endl;
  }
  return 0;
}

Measured memory_bytes: 1312
s = input()
alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]

n = len(s)
ans = n

for v in alphabet:
    key = [s[i] for i in range(n)]
    
    count = 0
    end = False
    while True:
        for i in range(n-count):
            if key[i] != v:
                break
            if i == n-count-1:
                ans = min(ans, count)
                end = True
        if count == n-1:
            break
        
        if end:
            break
        
        count += 1
        for i in range(n-count):
            if key[i] == v or key[i+1] == v:
                key[i] = v

print(ans)

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

using namespace std;

#define ll unsigned long long
#define INF 1234567890
#define N (int)(1e5 + 5)
int t[N], v[N];
void solve()
{
    int a, b, m, min_sum = INF;
    cin >> a >> b >> m;
    int min1 = INF, min2 = INF;
    for(int i = 1; i <= a; ++i)
    {
        cin >> t[i];
        min1 = min(t[i], min1);
    }
    for(int i = 1; i <= b; ++i)
    {
        cin >> v[i];
        min2 = min(v[i], min2);
    }
    min_sum = min1 + min2;
    for(int i = 1; i <= m; ++i)
    {
        int x, y, c;
        cin >> x >> y >> c;
        min_sum = min(min_sum, t[x] + v[y] - c);
    }
    cout << min_sum;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(i64 i = 0; i < N; i++)
#define Rep(i, k, N) for(i64 i = k; i < N; i++)
#define all(v) v.begin(), v.end()
#define eb emplace_back
#define Cout(s) cout << s << endl
string Yes(bool b) {if(b){return "Yes";} else {return "No";}}
string YES(bool b) {if(b){return "YES";} else {return "NO";}}

int main(){
    int H, W, K;
    cin >> H >> W >> K;

    vector<vector<char>> grid(H, vector<char>(W));

    int B = 0;
    rep(h, H)rep(w, W){
        cin >> grid[h][w];
        if(grid[h][w] == '#'){
            B++;
        }
    }
    
    
    i64 ans = 0;
    for(int row = 0; row < (1 << H); row++){
        for(int col = 0; col < (1 << W); col++){
            int cnt = 0;
            auto red_g = grid;
            for(int h = 0; h < H; h++){
                if(row & (1 << h)) {
                    rep(w, W) {
                        cnt += red_g[h][w] == '#';
                        red_g[h][w] = 'r';
                    }
                }
            }
            for(int w = 0; w < W; w++){
                if(col & (1 << w)) {
                    rep(h, H) cnt += red_g[h][w] == '#';
                }
            }
        
            if(B - cnt == K) ans++;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
//void chmin(int &a, int b) { if (a > b) a = b; }
//void chmax(int &a, int b) { if (a < b) a = b; }

const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

//重みある時
using Edge = pair<int,int>;
using Graph = vector<vector<Edge> >;

int main() {
    int n;
    cin >> n;
    set<int> se;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        if(se.count(a)){
            cout << "NO" << endl;
            return 0;
        }
        se.insert(a);
    }

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


Measured memory_bytes: 9600
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
using namespace std;

int main(){
  int n, l;
  cin >> n >> l;
  vector<long long> T(n+2);
  priority_queue<pair<int,int>> pq;
  for(int i = 0; i < n; ++i){
    int a;
    cin >> a;
    pq.emplace(a,i+1);
  }
  long long t = -1;
  while(pq.size()){
    int a = pq.top().first;
    int i = pq.top().second;
    pq.pop();
    long long s = max(T[i-1],T[i+1]);
    s += l-a;
    t = max(t,s);
    T[i] = s;
  }
  cout << t << endl;
}



Measured memory_bytes: 4664
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

L, R = map(int, input().split())

if R-L >=2018:
    print(0)
else:
    ans = ((L%2019)*(R%2019))%2019
    for i in range(L,R+1):
        for j in range(i+1,R+1):
            ans = min(ans, ((i%2019)*(j%2019))%2019)
    print(ans)


Measured memory_bytes: 77588
#include<iostream>
//#include<CastingInterop.h>
#include<string>
using namespace std;

int main()
{
	char a, b;
	cin >> a >> b;
	if (a > b)
		cout << ">";
	else if (a < b)
		cout << "<";
	else
		cout << "=";
}

Measured memory_bytes: 3660
#include<iostream>
#include<string>

int main()
{
    std::string S;
    std::cin >> S;
    int size=0;
    size=S.size();
    int num,Maxnum=0;

    for(int i=0; i<size ;i++)
    {
        if(S[i]=='R')
        {
            num++;
          	if(num > Maxnum)
            {
            	Maxnum=num;
            }
        }
        if(S[i]=='S')
        {
            num=0;
        }
    }
    std::cout << Maxnum << std::endl;
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define all_white first
#define sth_is_black second

using namespace std;

int mod;

int add (int a, int b) {
  return (a + b) % mod;
}
int mul (int a, int b) {
  return (long long) a * b % mod;
}

const int nax = 1e5 + 5;
vector < int > edges[nax], children[nax];
vector < pair < int, int > > downs[nax], pref[nax], suf[nax];
pair < int ,int > down[nax], up[nax];

pair < int ,int > Merge (const pair < int , int >& a, const pair < int , int >& b) {
  pair < int , int > p;
  p.all_white = mul (a.all_white, b.all_white);
  p.sth_is_black = add (mul (a.sth_is_black, add (b.all_white, b.sth_is_black)),
                        mul (a.all_white, b.sth_is_black));
  return p;
}

pair < int , int > process (pair < int , int > p) {
  return {p.all_white, add (p.sth_is_black, p.all_white)};
}

void dfs_one (int a, int parent) {
  pair < int , int > p {1, 0};
  for (int b : edges[a])
    if (b != parent) {
      children[a].push_back (b);
      dfs_one (b, a);
      p = Merge (p, down[b]);
      downs[a].push_back (down[b]);
    }
  down[a] = process(p);
}

void dfs_two (int a, int parent) {
  for (int i = 0; i < (int)children[a].size(); ++i) {
    pair < int ,int > p {1, 0};
    if (i != 0)
      p = Merge (p, pref[a][i - 1]);
    if (i != (int) downs[a].size() - 1)
      p = Merge (p, suf[a][i + 1]);
    if (a != 1)
      p = Merge (p, up[a]);
    int b = children[a][i];
    up[b] = process(p);
    dfs_two(b, a);
  }
}

int main () {
  int n;
  cin >> n >> mod;
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    edges[a].emplace_back (b);
    edges[b].emplace_back (a);
  }
  dfs_one (1, -1);
  for (int a = 1; a <= n; ++a) {
    int k = downs[a].size();
    pair < int , int > p {1, 0};
    for (int i = 0; i < k; ++i) {
      p = Merge (p, downs[a][i]);
      pref[a].push_back (p);
    }
    p = {1, 0};
    for (int i = k - 1; i >= 0; --i) {
      p = Merge (p, downs[a][i]);
      suf[a].push_back (p);
    }
    reverse (suf[a].begin(), suf[a].end());
  }
  dfs_two (1, -1);
  for (int a = 1; a <= n; ++a) {
    pair < int ,int > p {1, 0};
    if (a != 1)
      p = Merge (p, up[a]);
    if (!children[a].empty())
      p = Merge (p, pref[a].back());
    p = process(p);
    cout << p.sth_is_black << '\n';
  }
}


Measured memory_bytes: 40424
#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
using ll=long long;
int main()
{
    int a,b,c,rafi=0,ans;
    cin>>a>>b>>c;
    ans=b/a;
    if(c>ans)
    {
        cout<<ans<<endl;
    }
    else{
        cout<<c<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<vector>
#include<algorithm>
using namespace std;
const int MAXN=2000005;

int N,X,Y;
vector<int> red[MAXN],blue[MAXN];
int dep[MAXN],fa[MAXN];

bool isTable(int u,int v)
{
	if(dep[u]>dep[v])
		swap(u,v);
	if(fa[v]==u||fa[fa[v]]==u||fa[u]==fa[v])
		return false;
	return true;
}

void dfs1(int u)
{
	for(auto v:blue[u])
		if(v!=fa[u])
		{
			fa[v]=u;
			dep[v]=dep[u]+1;
			dfs1(v);
		}
}
int dfs2(int u,int f=0,int step=0)
{
	step++;
	int res=dep[u];
	for(auto v:red[u])
	{
		if(v==f)
			continue;
		if(isTable(u,v))
		{
			puts("-1");
			exit(0);
		}
		res=max(res,dep[v]);
		if(dep[v]>step)
			res=max(res,dfs2(v,u,step));
	}
	return res;
}

int main()
{
	scanf("%d%d%d",&N,&X,&Y);
	for(int i=1;i<N;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		red[u].push_back(v);
		red[v].push_back(u);
	}
	for(int i=1;i<N;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		blue[u].push_back(v);
		blue[v].push_back(u);
	}
	dfs1(Y);
	int ans=dfs2(X)*2;
	printf("%d\n",ans);
	
	return 0;
}


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


int main(){
    string S, T;
    cin >> S >> T;
    

    int sl = S.length();
    int tl = T.length();
    
    
    for(int is = sl - tl; is >= 0; is--){
        tl = T.length();
        int a=1;
        for(int j=0; j < tl; j++){
            if(!(S[is+j]== T[j] || S[is+j]== '?')){
                a=0;
                break;
            }
        }
        if(a==1){
            for(int i=0; i<is ;i++){
                if(S[i]=='?') S[i]='a';
            }
            for(int i=0; i< tl ;i++){
                S[i+is]=T[i];
            }
            for(int i= is +tl; i< sl ;i++){
                if(S[i]=='?') S[i]='a';
            }
            cout << S << endl;
            return 0;
        }

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

Measured memory_bytes: 256
// C - Attention
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N; scanf("%d\n",&N);
	int w = 0, count = 0;
	rp(i, 0, N) if(getchar()=='W') w++; else if(w>0){ w--; count++; }
	cout<< count <<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstdlib>

using namespace std;

int main()
{
  char moji;

  cin >> moji;

  cout << char(moji+1) << endl;


  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int x;
  cin >>n;
  int count=0;
  for(int i=1;i<n;++i){
    x=n/i;
    if(x>1){
  	  for(int j=1;j<=x;j++){
        if(i*j<n) count++;
      }
    }
    else{
      if(i*1<n) count++;
    }
    
  }
  cout <<count<<endl;
}

Measured memory_bytes: 3616
/**
 *    author:  [itmo] enot110
 *    created: 06.05.2017 15:11:05       
**/
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(),a.end()
#define pw(x) (1LL<<(x))

using namespace std;

typedef long long ll;
typedef double dbl;
typedef vector<int> vi;
typedef pair<int, int> pi;

const int inf = 1.01e9;
const dbl eps = 1e-9;

/* --- main part --- */

const int N = 1e5 + 10;

vi v[N];
set<int> s[N];
int dead[N];
int cnt[N];
int deg[N];

int main()
{
    #ifdef home
        assert(freopen("1.in", "r", stdin));
        assert(freopen("1.out", "w", stdout));
    #endif
    int n;
    scanf("%d", &n);
    forn(i, n - 1)
    {
        int x, y;
        scanf("%d%d", &x, &y);
        --x, --y;
        v[x].pb(y);
        v[y].pb(x);
        deg[x]++;
        deg[y]++;
        s[x].insert(y);
        s[y].insert(x);
    }
    if (n == 1) return 0 * printf("First\n");
    forn(i, n) if (sz(v[i]) == 1)
    {
        cnt[v[i][0]]++;
        dead[i] = 1;
        //eprintf("dead %d\n", i);
    }
    set<pi> S;
    forn(i, n) if (!dead[i]) S.insert({-cnt[i], i});

    while (sz(S))
    {
        int x = S.begin()->S;
        S.erase(S.begin());
        if (dead[x]) continue;
        dead[x] = 1;
        //eprintf("x = %d, cnt = %d\n", x, cnt[x]);
        if (cnt[x] > 1) return 0 * printf("First\n");
        for (int y : v[x]) if (!dead[y])
        {
            s[y].erase(x);
            deg[y]--;
            //eprintf("erase %d from %d, deg
            if (deg[y] == 1)
            {
                dead[y] = 1;
                int z = *s[y].begin();
                if (!dead[z])
                {
                    S.erase({-cnt[z], z});
                    cnt[z]++;
                    S.insert({-cnt[z], z});
                }
            }
        }
    }
    printf("Second\n");




        
    


    #ifdef home
        eprintf("time = %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
    #endif
    return 0;
}


Measured memory_bytes: 24064
#include <algorithm>
#include <iostream>
#include <cstdio>
using namespace std;

int a[1000005];
int main() {
	int n;
	cin>>n;
	for (int i = 1; i <= n; i++)
		cin>>a[i];
	sort(a + 1, a + 1 + n, greater<int>());
	for (int i = 1; i <= n; i++)
		if (i + 1 > a[i + 1]) {
			int j = 0;
			for (; a[j + i + 1] == i; j++);
			if ( ( (a[i] - i) & 1) || (j & 1) ) puts("First");
			else puts("Second");
			return 0;
		}
}

Measured memory_bytes: 768
#include <stdio.h>

int main(void){
    int n, i, count=0;
    scanf("%d", &n);
    char s[n];
    scanf("%s", s);
    for (i=0;i<n-2;i++){
        if (s[i]=='A'){
            if (s[i+1]=='B'){
                if (s[i+2]=='C'){
                    count += 1;
                }
            }
        }
    }
    printf("%d", count);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>

using namespace std;

#define PB push_back
#define ALL(v) (v).begin(), (v).end()
#define SZ size()
#define FOR(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
#define REP(i, n) FOR((i), 0, (n))
#define GET(a) cin >> (a)
#define GET2(a, b) cin >> (a) >> (b)
#define GET3(a, b, c) cin >> (a) >> (b) >> (c)
#define SHOW(v) cout << (v) << endl
#define SHOW2(a, b) cout << (a) << " " << (b) << endl
#define SHOW3(a, b, c) cout << (a) << " " << (b) << " " << (c) << endl
#define MOD 1000000007
template<class T> void GETV(T &v) { REP(i, v.size()) { GET(v[i]); } }
template<class T> void SHOWV(T &v) { REP(i, v.size()) { SHOW(v[i]); } }

typedef long long ll;

int main() {
	vector<int> v(5);
	for(int i = 0; i < 5; i++) {
		cin >> v[i];
	}
	
	int ans = 0;
	int tmp = 10;
	for(int i = 0; i < 5; i++) {
		if(v[i] % 10 == 0) {
			ans += v[i];
		}
		else if(v[i] % 10 < tmp) {
			tmp = v[i] % 10;
		}
	}
	
	bool flag = false;
	for(int i = 0; i < 5; i++) {
		if(v[i] % 10 != 0) {
			if(v[i] % 10 == tmp && !flag) {
				flag = true;		
				ans += v[i];
			}
			else {
				ans += v[i] + (10 - v[i] % 10);
			}
		}
	}
	
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

/**
 * @author subaru
 */
public class Main {
    // Great Ocean View
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int count = 0;
        int maxH = 0;
        for (int i = 0; i < N; i++) {
            int h = sc.nextInt();
            if (maxH > h) {
                continue;
            }
            maxH = h;
            count++;
        }
        System.out.println(count);
    }
}


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

int main() {
  string sa,sb,sc;
  cin>>sa>>sb>>sc;
  int a=0,b=-1,c=-1;
  char cur=sa[0];
  char win;
  for(int i=0;;i++){
    if(cur=='a') {
      a++;
      if(a<sa.size()){
        cur=sa[a];
      }
      else {
        win='A';
        break;
      }
    }
    if(cur=='b') {
      b++;
      if(b<sb.size()){
        cur=sb[b];
      }
      else {
        win='B';
        break;
      }
    }
    if(cur=='c') {
      c++;
      if(c<sc.size()){
        cur=sc[c];
      }
      else {
        win='C';
        break;
      }
    }
  }
  cout<<win<<endl;
  return 0;
}

Measured memory_bytes: 256