akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include<iostream>
#include<fstream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<climits>
#include<set>
#include<map>
#include<cmath>
#include<iomanip>
#include<iterator>
#include<queue>
#include<stack>
#include<cctype>
#include<deque>
#include<time.h>
#include<bitset>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<sstream>
#include<random>

//by Skeef79

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:16777216")
#define pb push_back
#define en '\n'
#define for0(i,n) for(int i = 0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vec vector
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

const int INF = 2000000000;
const ll LINF = 2000000000000000000;

template<typename T> void print(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}

template<typename T> void print(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}

template<typename T> void print(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << ' ';
		cout << en;
	}
}

template <typename T> void input(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cin >> a[i];
}

template<typename T> void input(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cin >> a[i];
}

template<typename T> void input(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
		for (int j = 0; j < a[i].size(); j++)
			cin >> a[i][j];
}

void solve()
{
	int n;
	cin >> n;
	vector<int> a(n);
	input(a);
	set<int> st;
	int ans = 0;

	for (auto to : a)
	{
		if (st.lower_bound(to) == st.begin())
			ans++;
		st.insert(to);
	}
	cout << ans;

}

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

#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif

	int tst = 1;
	//cin >> tst;
	while (tst--)
	{
		solve();
	}
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;
bool LTE(double a,double b) { return equals(a,b) || a < b; }
bool LT(double a,double b) { return !equals(a,b) && a < b; }

void compute() {

}

int main() {
  int x,y;
  cin >> x >> y;
  int ans = 0;
  if( x == 3 ) {
    ans += 100000;
  } else if( x == 2 ) {
    ans += 200000;
  } else if( x == 1 ) {
    ans += 300000;
  }

    if( y == 3 ) {
    ans += 100000;
  } else if( y == 2 ) {
    ans += 200000;
  } else if( y == 1 ) {
    ans += 300000;
  }
  if( x == 1 && y == 1 ) {
    ans += 400000;
  }
  cout << ans << endl;
  
  compute();
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const unsigned int MOD = 1000000007;
#define ll long long
#define PI 3.1416
string day[]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
vector<string>v;
void dfs(string str,string t="",int cnt=0){
    if(cnt==2){
        v.push_back(t);
        return;
    }else{
        for(int i=0;i<str.size();i++){
            dfs(str,t+str[i],cnt+1);
        }
    }
}
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int a,b;
    while(cin>>a>>b){
        cout<<(a*b)-(a+b-1)<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll ; 
typedef long double ld ;
typedef pair<ll , ll> pll ;

const ll N = 2e5 + 30 , Mod = 1e9 + 7 ;
const ll SQ = 330 ;

int main () {
    ios::sync_with_stdio(0), cin.tie(0) ;
    ll n;
    cin >>n;
    ll po = 1;
    for (int i = 0 ; i < n ; i ++) {
    	ll x;
    	cin >> x;
    	if (x == po) po ++;
	}
	if (po == 1) return cout << -1, 0;
	cout <<n - po + 1 << endl;
    
    return (0) ;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;


class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;

    List<int>[] es;

    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int M = cin.nextInt();
        es = new List<int>[N];
        for (int i = 0; i < N; i++)
        {
            es[i] = new List<int>();
        }

        for (int i = 0; i < M; i++)
        {
            int a = cin.nextInt() - 1;
            int b = cin.nextInt() - 1;
            es[a].Add(b);
            es[b].Add(a);
        }

        int ans = M;

        for (int i = 0; i < N; i++)
        {
            foreach (var j in es[i])
            {
                if (i > j) continue;
                bool[] used = new bool[N];
                Queue<int> q = new Queue<int>();
                q.Enqueue(j);
                used[j] = true;
                while(q.Count != 0)
                {
                    int now = q.Dequeue();
                    if(now == i)
                    {
                        ans--;
                        break;
                    }
                    foreach (var next in es[now])
                    {
                        if (used[next]) continue;
                        if (now == j && next == i) continue;
                        used[next] = true;
                        q.Enqueue(next);
                    }
                }
            }
        }

        Console.WriteLine(ans);
    }

}

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 13396
from collections import deque
N,M = map(int,input().split())
list_edge = [[] for _ in range(N)]
deg = [0]*N
for _ in range(M):
    a,b = map(int,input().split())
    list_edge[a-1].append(b-1)
    deg[b-1] += 1
que = deque()
for v in range(N):
    if deg[v]==0:
        que.append(v)
dp = [0]*N
while que:
    v = que.popleft()
    list_nv = list_edge[v]
    for nv in list_nv:
        deg[nv] -= 1
        if deg[nv]==0:
            que.append(nv)
            dp[nv] = max(dp[v],dp[v]+1)
print(max(dp))

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

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

lint lcm(lint x, lint y) { return x/gcd(x,y)*y; }

lint C(lint n, lint k) {
  if(n == k) { return 1; }
  else if(n < k) { return 0; }
  else if(k == 0) { return 1; }
  else if(k == 1) { return n; }
  else return C(n-1,k-1) + C(n-1,k);
}

lint P(lint n, lint k) {
  if(k == 1) { return n; }
  return (n*(P(n-1,k-1)%1000000007)%1000000007);
}


int main() {
  int k,t; cin >> k >> t;
  vector<int> a(t); for(int i=0;i<t;i++) { cin >> a[i]; }
  
  sort(a.begin(),a.end());
  int sum=0;
  for(int i=0;i<t-1;i++) { sum += a[i]; }
  
  cout << max(0,(a[t-1]-1)-sum) << endl;

  return 0;
}


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

#define ll long long
#define f first
#define s second
#define inf 1e15

#define N 300005

string s;
int n,m,x,y;
int a[N];

int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
	int t=1;
//	cin>>t;
	while(t--){
	    
	    
	    cin>>n;
	    for(int i=0;i<n;i++){
	        cin>>a[i];
	    }
	    
	    sort(a,a+n);
	    
	    ll ans=0;
	    
	    for(int i=0;i<n;i++){
	        for(int j=i+1;j<n;j++){
	            for(int k=j+1;k<n;k++){
	                
	                if(a[i]!=a[j] && a[j]!=a[k]){
	                    
	                    if(a[i]+a[j]>a[k]){
	                        
	                       // cout<<i+1<<" "<<j+1<<" "<<k+1<<" %\n";
	                        ans++;
	                    }
	                }
	                
	            }
	        }
	    }
	    
	    cout<<ans<<"\n";
	    
	    
	}
	return 0;
}


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

///******************************** C o n t a i n e r ********************************///

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

///*********************************** C o n s t ***********************************///

const int       N=1e6+123;
const double    PI = acos(-1);
const ll        MOD=1000000007;                 ///1e9+7
ll dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};       ///first 4 for adjacent
ll dy[] = {0, +1, 0, -1, +1, -1, +1, -1};
ll dx8[]= {+1, +1, -1, -1, +2, +2, -2, -2};    ///knights move
ll dy8[]= {+2, -2, +2, -2, +1, -1, +1, -1};

///********************************** M a r c o ***********************************///

#define pb push_back
#define F first
#define S second
#define test int tc; cin>>tc; while(tc--)
#define forn(i,n) for(i=0;i<n;i++)
#define rforn(i,n) for(i=n-1;i>=0;i--)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) x.size()
#define el <<'\n'
#define sp <<' '
#define print(a) {for(auto x:a)cout<<x<<" ";cout<<endl;}
#define mem(a,b) memset(a, b, sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) (a)*(a)

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

///*********************************** F u n c t i o n ***********************************///

ll powmod(ll a,ll b){ a%=MOD;if(!a) return 0;ll pr=1;while(b>0){if(b&1){pr*=a;pr%=MOD;--b;}a*=a;a%=MOD;b/=2;}return pr;}
ll modinverse(ll a){return powmod(a,MOD-2);}
bool isPrime(ll n){ if(n<=1)return false;if(n<=3)return true;if(n%2==0 or n%3==0)return false;for(ll i=5;i*i<=n;i+=6){if(n%i==0 or n%(i+2)==0)return false;}return true;}
void seive(bool a[]){ll mx=sqrt(N),ii,jj;for(ii=3;ii<=mx;ii+=2)if(!a[ii])for(jj=ii*ii;jj<N;jj+=2*ii)a[jj]=true;}
void numofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<N;jj+=ii){if(jj==ii*ii) a[jj]++; else a[jj]+=2;}}}
void sumofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<N;jj+=ii){if(jj==ii*ii) a[jj]+=ii; else a[jj]+=ii+jj/ii;}}}

///**************************************************** C o d e ****************************************************///
///-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=///



void _case()
{
    string a;
    cin>>a;
    map<char,ll> m;
    for(auto i:a) m[i]++;
    if(sz(m)!= 2) cout<<"No" el;
    else cout<<"Yes" el;
}

main()
{
    fastio();
    _case();

}


///Thank you.


///Brainless_Loco Terminates Here!


Measured memory_bytes: 3616
#include <bits/stdc++.h>
typedef long long ll;
#define reps(i,s,n) for(ll (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(ll (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
using namespace std;
const ll KEY=1e18;

ll gcd(ll a, ll b) {
  if(a==0) return b;
  if(a>b) return gcd(a%b, b);
  else return gcd(b%a, a);
}

int main(){
  ll N,K;
  cin >> N >> K;
  vector<ll> a(N);
  ll max = 0;
  rep(i,N){
    cin >> a[i];
    if(max<a[i]) max = a[i];
  }
  ll key = a[0];
  for(ll i=1;i<N;i++){
    key = gcd(key,a[i]);
  }
  if(K%key==0 && max>=K) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 1024
while true
    size = gets.chomp.split.map(&:to_f).sort
    break if size == [0, 0, 0]
    limit = (size[0] / 2) ** 2 + (size[1] / 2) ** 2
    gets.to_i.times{puts (gets.to_i ** 2 > limit) ? "OK" : "NA"}
end



Measured memory_bytes: 6908
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#include "queue"
#include "functional"
#include "map"
#include "unordered_map"
#include "set"
#include "stack"

#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 llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
typedef long long ll;
using namespace std;

int a, b;
char c[100][100];

int main() {
	cin >> a >> b;
	a--;
	b--;
	lp(50)
		LP(100, j)
			c[i][j] = '.';
	lp(50)
		LP(100, j)
			c[i + 50][j] = '#';
	lp(b)
		c[(i / 50) * 2][(i % 50) * 2] = '#';
	lp(a)
		c[99 - (i / 50) * 2][99 - (i % 50) * 2] = '.';
	cout << 100 << sp << 100 << endl;
	lp(100) {
		LP(100, j)
			cout << c[i][j];
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
def solve(fld)
  $h.times do |y|
    fld[y].each_cons(2).with_index do |(a, b), x|
      if a != b
        fld[y][x], fld[y][x+1] = fld[y][x+1], fld[y][x]
        return true if search(adjust(fld.transpose.map{|ar| ar.reverse} ))
        fld[y][x], fld[y][x+1] = fld[y][x+1], fld[y][x]
      end
    end
  end
  false
end
  
def search(fld)
  return true if fld.flatten.all?{ |v| !v }
  nfld = erase(fld, $w, $h, erase(fld.transpose, $h, $w).transpose)
  return false if nfld == fld
  search(adjust(nfld))
end
  
def erase(fld, r, c, nfld = fld)
  r.times do |y|
    fld[y].each_cons($n).with_index do |ar, x|
      next unless ar[0]
      if ar.all?{ |v| v == ar[0] }
        while x < c && ar[0] == fld[y][x]
          nfld[y][x] = nil
          x += 1
        end
      end
    end
  end
  nfld
end
  
def adjust(fld)
  $w.times do |x|
    fld[x].map! { |v| v if /[A-Z]/ =~ v }.compact!
  end
  fld.map!{|ar| ar.fill(nil, ar.size...$h) }
end
  
$h, $w, $n = gets.split.map(&:to_i)
fld = $h.times.map{ gets.chomp.split('').map{ |v| v if /[A-Z]/ =~ v } }
puts solve(fld) ? 'YES' : 'NO'

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

int n,m;
int a[31];

int main(){
    cin>>n>>m;
    for(int i=0;i<n;i++){
        int k;
        cin>>k;
        for(int i=0;i<k;i++){
            int A;
            cin>>A;
            a[A]++;
        }
    }
    int ans=0;
    for(int i=1;i<=30;i++){
        if(a[i]==n) ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N;
vector<ll> A;
void input(){
    fast_io();
    cin >> N;
    A = fetch_vec<ll>(N);
}

int solve(){
    sort(A.begin(),A.end(),greater<ll>());
    ll ans = 0LL;
    vector<ll> Ans;
    for (int i = 0; i < N; i++)
    {
        if(i==0) {
            Ans.push_back(A[i]);
        }
        else{
            Ans.push_back(A[i]);
            Ans.push_back(A[i]);
        }
    }
    ans = accumulate(Ans.begin(),Ans.begin()+(N-1),0LL);    
    cout << ans << endl;
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 8988
from collections import Counter

n, p = list(map(int, input().split()))

s = input()


a = 0
t = list(map(int, list(s)))
t.reverse()


if p == 2:
    for i in range(n):
        if t[i] % 2 == 0:
            a += len(t) - i 
elif p == 5:
    for i in range(n):
        if t[i] % 5 == 0:
            a += len(t) - i 

else:
    u = []
    k = 1
    l = 0
    for i in t:
        l = (l + i*k) % p
        u.append(l)
        k = k * 10 % p

    c = Counter(u)
    a += c[0]
    for i in c.values():
        if i > 1:
            a += i * (i-1) // 2


print(a)




Measured memory_bytes: 13612
n = int(input())
x = list(map(int,input().split()))
l = sorted(x)
for i in range(n):
    if x[i] <  l[(n+1)//2]:
        print(l[(n+1)//2])
    elif x[i] >= l[(n+1)//2 - 1]:
        print(l[(n+1)//2 - 1])

Measured memory_bytes: 26016
n = int(input())
s = list(input())

import collections
c = collections.Counter(s)

ans = c["R"] * c["B"] * c["G"]

for i in range(n-2):
    for j in range(i+1,n-1):
        x = s[i]
        y = s[j]
        
        if x != y:
            if "R" not in [x,y]:
                if 2*j-i < n:
                    if s[2*j-i] == "R":
                        ans -= 1
                    
            elif "G" not in [x,y]:
                if 2*j-i < n:
                    if s[2*j-i] == "G":
                        ans -= 1
                    
            else:
                if 2*j-i < n:
                    if s[2*j-i] == "B":
                        ans -= 1
    
print(ans)

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

using ll = long long;
const ll amari = 1e9+7;
#define ben(a) a.begin(),a.end()
#define pb(a,b) a.push_back(b)

int main(){
	string s;
	cin >> s;
	int ans = 0;
	for(int i = 0; i < s.size(); i++){
		if(s[i] == 'A'){
			ans = i;
			break;
		}
	}
	for(int i = s.size() - 1; i >= 0; i--){
		if(s[i] == 'Z'){
			ans = i - ans;
			break;
		}
	}
	cout << ans+1 << endl;
	return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long LL;

vector<int> tu[200005];
int n;
bool dfs(int son,int fa,int t)
{
	int i,k;
	for(i=0;i<tu[son].size();i++)
	{
		k=tu[son][i];
		if(k==n&&t<=2)
			return true;
		if(t>2)
			return false;
		if(dfs(k,son,t+1)==true)
			return true;
	}
}
int main()
{
	int x,y,i,m;
 //freopen("in.txt","r",stdin);
 //freopen("out.txt","w",stdout);
	cin>>n>>m;
	for(i=1;i<=m;i++)
	{
		cin>>x>>y;
		tu[x].push_back(y);
		tu[y].push_back(x);
	}
	//memset(vis,0,sizeof(vis));
	//vis[1]=1;
	if(dfs(1,0,1)==false)
	{
		cout<<"IMPOSSIBLE"<<endl;
	}
	else
	{
		cout<<"POSSIBLE"<<endl;
	}
 return 0;
}

Measured memory_bytes: 12016
// By Mohit Gupta
#include <bits/stdc++.h>
using namespace std;
//DEBUG 
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define printint(v) copy(begin(v), end(v), ostream_iterator<int>(cout," "))
#define printintv(s,e) copy(s,e, ostream_iterator<int>(cout," "))
#define forstl(i,v) for(auto &i: v)
#define all(v) (v).begin(), (v).end()
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits (for ints only diff for ll)
//https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html for other in built
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define pb push_back
#define fi first
#define se second
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef pair<int,int> p32; 
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef map<int,int> m32;
#pragma GCC optimize ("-O2")
const int LIM = 5e5+5, MOD = 998244353;
int t,n,m,k,x,y;
 
 
int32_t main()
{
    IOS;
    int s,w;
    cin>>s>>w;
    if(w>=s) cout<<"unsafe"<<ln;
    else cout<<"safe"<<ln;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int main()
{
    int N;
    cin >> N;
    cout << 24 + 24 - N << endl;
    return 0;
}

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

using namespace std;

int main()
{
    string s;
    long long int n=0,i=0;
    cin>>s;
    
    while(s[i]!='\0')
    {
        n+=(int(s[i])-48);
        i++;
    }
    if(n%9==0)
    {
        cout<<"Yes"<<endl;
    }
    else
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3756
#include<stdio.h>

int main(){
  int i,j,k=0;
  int N;
  scanf("%d",&N);
  int A[N];
  for(i=0;i<N;i++){
    scanf("%d ",&A[i]);
    if(A[i]%2 == 1){
      puts("0");
      return 0;
    }
  }
  
  while(1){
    for(i=0;i<N;i++){
      if(A[i] %2 == 1){
        printf("%d\n",k);
        return 0;
      }
      A[i] /=2;
    }
    k++;
  }
  
  return 0;
}


Measured memory_bytes: 128
# import math
# import decimal
# import queue
# import bisect
# import heapq
# import time
# import itertools

mod = int(1e9+7)
INF = 1<<39

def main():
    s = input()
    if len(s) == 2:
        print(s)
    else:
        t = []
        for i in range(3):
            t.insert(0,s[i])
        print(''.join(t))
    return

if __name__=='__main__':
    main()

Measured memory_bytes: 38256
/*by freesteed*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fill(x,c) memset(x,c,sizeof(x))
#define fi first
#define se second
typedef long long ll;typedef pair<int,int> PII;const ll mod=1e9+7;const int N = 1e6+10;ll a[N];
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int main() {
	//ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	string s,t,u;
	int aa,bb;
	cin>>s>>t>>aa>>bb>>u;
	if(u==s)cout<<aa-1<<" "<<bb;else cout<<aa<<" "<<bb-1;
  	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a1,b1,k;
	bool a[105]={false},b[105]={false};
	vector<int> lcd;
	scanf("%d%d%d",&a1,&b1,&k);
	for(int i=1;i<=a1;i++){
		if(a1%i==0) a[i]=true;
	}
	for(int i=1;i<=b1;i++){
		if(b1%i==0) b[i]=true;
	}
	for(int i=104;i>=0;i--){
		if(a[i]==true&&b[i]==true) lcd.push_back(i);
	}
	printf("%d\n",lcd[k-1]);
	return 0;
}

Measured memory_bytes: 256
S,N,A,K,i,T,U;
main()
{
	scanf("%d",&N);
	for(i=0;i<N;i++)
	{
		scanf("%d%d",&A,&K);
		while(T=A/K+1,U=A%K%T)A=A/K*K-T+U;
		S^=T-1;
	}
	puts(S?"Takahashi":"Aoki");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n,l[105],ans;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>l[i];
	sort(l,l+n);
	for(int i=0;i<n;i++)
		for(int j=i+1;j<n;j++)
		{
			if (l[i]==l[j])
				continue;
			for(int k=j+1;k<n;k++)
			{
				if (l[i]==l[k]||l[j]==l[k])
					continue;
				if (l[i]+l[j]>l[k])
					ans++;
				else
					break;
			}
		}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
#define llx(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len) {char ss[len];scanf("%s",ss);(st)=ss;}
using namespace std;
int n,m,i,j,ans=1<<30;
int cnt(int x)
{
	int ans=0;
	while (x)
	{
		ans+=x%10;
		x/=10;
	}
	return ans;
}
int main()
{
	cin>>n;
	for (i=1;i<n;i++)
	{
		ans=min(ans,cnt(i)+cnt(n-i));
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a);i<(b);++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD 1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a:A) cin >> a;} 

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

int N, M; cin >> N >> M;
VI a(M), b(M), c2(M, 0); //i 番目の鍵で　0bc2[i] の宝箱が開く
// VVI c(M);
rep(i, 0, M){
    cin >> a[i] >> b[i];
    // c[i].resize(b[i]); 
    rep(j, 0, b[i]){
        int c; cin >> c;
        c2[i] |= (1 << (c-1));
    } 
}

// if (accumulate(ALL(c2), 0LL, bit_or<int>()) != ((1LL<<N) - 1)){
//     cout << "-1\n";
//     return 0;
// }

// cost[key][opend] = key 個目までの鍵で、0b(opend)を開ける最小コスト
// opend は2進数N桁
VVI cost(M+1, VI(1LL<<N, INF));
cost[0][0] = 0;
rep(i, 0, M){
    cost[i][0] = 0;
    rep(j, 0, 1LL<<N){
        cost[i+1][j | c2[i]] = min(cost[i+1][j | c2[i]], cost[i][j] + a[i]);
        cost[i+1][j] = min(cost[i+1][j], cost[i][j]);
    }
}

if (cost[M][(1LL<<N)-1] < INF)
    cout << cost[M][(1LL<<N)-1] <<"\n";
else 
    cout << "-1\n";

return 0;
}
// コンテスト前はtemplate振り返り。
// 書いて考える．場合分け．情報整理．
// 単純に分かる量から．愚直解を実装して研究．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP(小さい問題から大きな問題)
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性→二分探索
// 存在判定：構成方法，入力の特徴
// 構築問題。極端解を試す。
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// コーナーケース。境界値。数表出力プログラム作る
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 32384
n = int(input())

def popcount(x):
    return bin(x).count('1')

g = [[-1 for j in range(n)] for i in range(n)]

for i in range(n):
    a = int(input())
    for j in range(a):
        x, y = map(int, input().split())
        x -= 1
        g[i][x] = y

ans = 0
for i in range(1 << n):
    d = [0 for _ in range(n)]
    for j in range(n):
        if i >> j & 1:
            d[j] = 1
    ok = True
    for j in range(n):
        if d[j]:
            for k in range(n):
                if g[j][k] == -1:
                    continue
                if g[j][k] != d[k]:
                    ok = False
    if ok:
        ans = max(ans, popcount(i))

print(ans)

Measured memory_bytes: 45916
package main

import "fmt"

func gcd(x, y int) int {
	for y > 0 {
		x, y = y, x%y
	}
	return x
}

func lcm(x, y int) int {
	return x / gcd(x, y) * y
}

func main() {
	var x int
	fmt.Scan(&x)

	fmt.Println(lcm(x, 360) / x)
}


Measured memory_bytes: 1768
<?php
    function f($x){
        if($x < 10)return $x;
        return $x % 10 + f(floor($x / 10));
    }
    $n;
    fscanf(STDIN, "%d", $n);
    $m = f($n);
    if($n % $m == 0){
        echo "Yes\n";
    }else{
        echo "No\n";
    }
    //echo "$m\n";
?>


Measured memory_bytes: 3576
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#include <math.h>
using namespace std;

int main(){
	int H, W , D;
	scanf("%d %d %d",&H,&W,&D);
	int max_q = (H*W)/D+1;
	vector<vector<vector<int> > > vv(D, vector<vector<int> >( max_q, vector<int>(2)));
	for(int i = 0; i< H; i++){
		for(int j = 0; j < W ; j++){
		int temp;
		scanf("%d", &temp);		
		vv[temp %D][temp/D][0] = i;
		vv[temp %D][temp/D][1] = j;
		}
	}
	vector<vector<int> > sum(D, vector<int>(max_q));
	for (int i = 0; i< D; i++){
		for (int j = 0; j < max_q;j++){
			if (1 <= i + D *j <= H*W){
				if (j == 0 or i+ D *j == 1 ) sum[i][j] = 0;
				else{
					int x  =abs(vv[i][j][0] -vv[i][j-1][0]);
					int y = abs(vv[i][j][1] -vv[i][j-1][1]);
					sum[i][j] += x + y+   sum[i][j-1];
				}
			}		
		}
	}
	int Q;
	scanf("%d",&Q);
	for (int i = 0 ; i <Q; i++){
		int R,L;
		scanf("%d %d",&L,&R);
		int ans = sum[R%D][R/D] - sum[R%D][L/D]; 
		printf("%d\n",ans);
	}	
	return 0;
}


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

constexpr int INF=(int)1e9;

struct edge{
	int from,to,cost;
	edge()=default;
	edge(int _f,int _t,int _c) : from(_f),to(_t),cost(_c) {}
};

int n,m;

int dp[100][100];

edge edges[1000];

int main() {
	std::cin>>n>>m;
	int a,b,c;
	for(int i=0;i<n;++i){
		for(int j=0;j<n;++j)
			dp[i][j]=INF;
	}
	for(int i=0;i<m;++i){
		std::cin>>a>>b>>c;
		--a;
		--b;
		dp[a][b]=c;
		dp[b][a]=c;
		edges[i]=edge(a,b,c);
	}
	for(int i=0;i<n;++i){
		for(int j=0;j<n;++j){
			for(int k=0;k<n;++k)
				dp[j][k]=std::min(dp[j][k],dp[j][i]+dp[i][k]);
		}
	}

	int ans=0;

	for(int i=0;i<m;++i){
		int a=edges[i].from;
		int b=edges[i].to;
		if(dp[a][b]<edges[i].cost)
			++ans;
	}
	std::cout<<ans<<std::endl;
	return 0;
}

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

int main(){
    string s;
    cin >> s;
    int ans = 700;
    rep(i,3){
        if(s[i] == 'o') ans += 100;
    }

    cout << ans << endl;
    
}

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

typedef long long LL;

const int N = 1e5;

int n,x;
int li[N+5];

int main(){
	cin >> n >> x;
	for(int i=1;i<=n;i++){
		cin >> li[i];
	}
	LL ans = 0LL;
	for(int i=2;i<=n;i++){
		int tmp = li[i-1] + li[i];
		int dif = max(0,tmp-x);
		ans += (LL)dif;
		li[i] = max(0,li[i]-dif);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N,M;
  	cin >> N >> M;
  	int a[N],b[N];
  	for(int i=0;i<N;i++)cin >> a[i] >> b[i];
  	int c[M],d[M];
  	for(int i=0;i<M;i++)cin >> c[i] >> d[i];
  	for(int i=0;i<N;i++){
      	int min_dis = abs(a[i]-c[0])+abs(b[i]-d[0]),checkpoint =1;
    	for(int j=1;j<M;j++){
        	int dis = abs(a[i]-c[j])+abs(b[i]-d[j]);
          	if(min_dis > dis){
            	min_dis = dis;
              	checkpoint =j+1;
            }
        }
    cout << checkpoint << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()

{
	int a; int b; int c; int d;
	cin >>a>>b>>c;

	if (a > b){
		d = a;
		a = b;
		b = d;
	}
	if (b > c){
		d = b;
		b = c;
		c = d;
	}
	if (a > b){
		d = a;
		a = b;
		b = d;
	}
	cout << a <<" "<< b <<" " << c << endl;
	return 0;
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repR(i, n) for(int i = n; i >= 0; ++i)
#define FDS(i, n) for(ll i = 0; i < n; ++i)
#define FDSR(i, n) for(int i = n; i >= 0; ++i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define FORR(i, m, n) for(int i = m;i >= n;--i)
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define itn int
#define ednl endl
using namespace std;
typedef long long ll;template<typename TypeInt>TypeInt G_C_D(TypeInt a, TypeInt b){if (a < 0) a = -a;if (b < 0) b = -b;while (b != 0) {a %= b;if (a == 0) return b;b %= a;}return a;}template<typename TypeInt>
TypeInt G_C_D(const std::vector<TypeInt> &list){TypeInt a = list[0];for (size_t i = 1; i < list.size(); ++i) {a = G_C_D(a, list[i]);}return a;}template<typename TypeInt>TypeInt L_C_M(TypeInt a, TypeInt b) {if( a == 0 && b == 0)return 0;return a / G_C_D(a, b) * b;}
template<typename TypeInt>TypeInt L_C_M(const std::vector<TypeInt> &list){TypeInt a = list[0];for (size_t i = 1; i < list.size(); ++i) {a = L_C_M(a, list[i]);}return a;}

int main(){
	int N;
	cin>>N;
	FDS(i,25){
		FDS(j,15){
			if(i*4+j*7==N){
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	cout<<"No"<<endl;
}

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

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

#define vi vector<int>
#define vll vector<long long>
#define ll long long
#define ull unsigned long long
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL)
#define nl cout<<'\n'
#define pb push_back
#define mp make_pair
#define pi pair<int,int>
#define pll pair<long long,long long>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<ll,ll> >
#define si set<int>
#define sll set<long long>
#define all(v) (v).begin(),(v).end()
#define Unique(x)           (x).erase(unique(all(x)), x.end())
#define v_present(vec,x)  (find(all(vec),x)!=(vec).end())
#define present(myset,x)    ((myset).find(x)!=(myset).end())
#define Cprint(c)  for(auto i:(c)) { cout<<i<<" "; } nl
#define trace2(x,y) cout<<x<<" "<<y<<endl;
#define trace3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl;
#define trace4(x,y,z,a) cout<<x<<" "<<y<<" "<<z<<" "<<a<<endl;
ll mod = 1e9+7;
const int MAX = 1e5+5;

using namespace std;

//dp[i]=true when first person maing move with i stones remaining wins


int main()
{
    FAST_IO;
    int n,k;
    cin>>n>>k;
    vi a(n);
    for(int i=0;i<n;i++)
        cin>>a[i];
    vector<bool> dp(k+1);

    for(int stones=0;stones<=k;stones++){
        for(int curr=0;curr<n;curr++){
            if(stones-a[curr]>=0 && dp[stones-a[curr]]==false){
                dp[stones]=true;
            }
        }
    }

    if(dp[k]==true){
        cout<<"First";
    }
    else{
        cout<<"Second";
    }

    return 0;

}

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

int main(){
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    int t = 0;
    int a = 0;
    while(A > 0){
        A -= D;
        t++;
    }
    while(C > 0){
        C -= B;
        a++;
    }
    if(a <= t){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }


    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds; 
#define ll          unsigned long long int

#define pb          push_back
#define pii         pair<int,int>
#define F           first
#define S           second
#define vi          vector<int>
#define vli          vector<ll>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define M_PI        3.14159265358979323846
#define mp          make_pair
#define sz(x)       (int)x.size()
#define matrix      vector<vector<ll>>
#define forn(i,a,b)  for(int i=a;i<b;i++)
#define eps 0.0000000001
#define all(a)      (a).begin(),(a).end()
#define ordered_set     tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> 
 
const long long INF = (long long) 1e11+1;
const long long mod = (long long) 998244353;
const long long hell = (long long) 1000000007;

ll power(ll x,ll y)
{
  ll res=1;
  while(y>0){
    if(y%2) res=(x*res);
    x=(x*x);    
    y=y/2;
  }
  
  return res%mod;
}
 
ll modinv(ll x){
  return power(x,hell-2);
}

ll gcd(ll a,ll b)
{
    while( b != 0)
	{
		ll  t = b;
		b= a %t;
		a = t;
	}
	return a;
}

void fastIO() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
    

void solve(){
    int k;
    cin>>k;
    string s;
    cin>>s;
    
    int n=s.length();
    
    if(n<=k)
    cout<<s;
    else{
        cout<<s.substr(0,k)<<"...";
    }
}

int main(){
   fastIO();
   int test;
   //cin>>test;
   test=1;    
   
   while(test--)
   solve();
}


Measured memory_bytes: 3656
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<int,int>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<typename G>
struct DLCA{
    const int Log;
    vector<int> dep;
    const G &g;
    vector<vector<int>> table;
    explicit DLCA(const G &g):g(g),dep(g.size()),Log(32-__builtin_clz(g.size())){
        table.assign(Log,vector<int>(g.size(),-1));
    }
    //各点に番号付
    void dfs(int idx,int par,int d){
        table[0][idx]=par;
        dep[idx]=d;
        for(auto &to:g[idx]){
            if(to!=par)dfs(to,idx,d+1);
        }
    }
    //構築
    void build(){
        dfs(0,-1,0);
        for(int k=0;k<Log-1;k++){
           for(int i=0;i<table[k].size();i++){
               if(table[k][i]==-1)table[k+1][i]=-1;
               else table[k+1][i]=table[k][table[k][i]];
           }
        }
    }
    //２点の最小共通祖先を探す
    int query(int u,int v){
       if(dep[u]>dep[v])swap(u,v);
       for(int i=Log-1;i>=0;i--){
           if(dep[v]-dep[u]&(1<<i))v=table[i][v];
       }
       if(u==v)return u;
       for(int i=Log-1;i>=0;i--){
           if(table[i][u]!=table[i][v]){
               u=table[i][u];
               v=table[i][v];
           }
       }
       return table[0][u];
    }
    //２点間距離
    int dist(int u,int v){
        int par=query(u,v);
        return abs(dep[u]-dep[par])+abs(dep[v]-dep[par]);
    }
};
int main(){
int n,u,v;
cin>>n>>u>>v;
u--;v--;
 V<V<int>> t(n);
 for(int i=0;i<n-1;i++){
     int a,b;
     cin>>a>>b;
     t[--a].push_back(--b);
     t[b].push_back(a);
 }
 DLCA<V<V<int>>> tree(t);
 tree.build();
 int ans=0;
 int d=tree.dist(u,v);
 for(int i=0;i<n;i++){
     int a=tree.query(u,i);
     int b=tree.dist(a,u),c=tree.dist(a,v);
     if(b>=c){
     chmax(ans,d/2);
     }
     else{
         chmax(ans,tree.dist(v,i)-1);
     }
 }
 cout<<ans<<endl;
}

Measured memory_bytes: 15352
import java.util.*
import java.math.*
import java.lang.Math.*

val readString: ()->String = {readLine()!!}
val readInt: ()->Int = {readLine()!!.toInt()}
val readLong: ()->Long = {readLine()!!.toLong()}
val readIntArray: ()->IntArray = {readLine()!!.split(' ').map{it.toInt()}.toIntArray()}
val readLongArray: ()->LongArray = {readLine()!!.split(' ').map{it.toLong()}.toLongArray()}
val errPrintln: (String)->Unit = {msg -> System.err.println(msg)}
val MOD = 1e9.toLong()+7
val INF = Int.MAX_VALUE/2
val LINF = Long.MAX_VALUE/2
data class IntPair(val first: Int, val second: Int)
data class To(val idx: Int, val cost: Long)


class Bellman(val eg: Array<ArrayList<To>>, val start: Int) {
    private var dist = LongArray(0)
    init {
        val N = eg.size
        dist = LongArray(N){-LINF}
        dist[start] = 0L
        for (i in 0 until N-1) {
            var updating = false
            for (x in 0 until N) {
                for (t in eg[x]) {
                    val y = t.idx
                    if (dist[x] + t.cost > dist[y]) {
                        dist[y] = dist[x] + t.cost
                        updating = true
                    }
                }
            }
            if (!updating) break
        }
    }

    private fun hasPositiveCycle(i: Int): Boolean {
        val N = eg.size
        val ndst = dist.clone()
        for (x in 0 until N)  {
            for (t in eg[x]) {
                val y = t.idx
                if (ndst[x] + t.cost > ndst[y]) {
                    ndst[y] = ndst[x] + t.cost
                }
            }
        }
        return ndst[i] != dist[i]
    }

    fun distance(i: Int): Long{
        return if(hasPositiveCycle(i)) LINF else dist[i]
    }
}


fun solve(eg: Array<ArrayList<To>>): Long {
    val N = eg.size

    val bm = Bellman(eg, 0)

    return bm.distance(N-1)
}


fun main(args: Array<String>) {
    val (N, M) = readIntArray()
    val eg = Array(N){ArrayList<To>()}
    for (i in 0 until M) {
        var (a, b, c) = readLongArray()
        a--;b--;
        eg[a.toInt()].add(To(b.toInt(), c))  // 有向グラフ
    }

    val ans = solve(eg)

    if (ans == LINF) println("inf")
    else println(ans)
}


Measured memory_bytes: 43636
mp = {}
mp[" "] = "101"
mp["'"] = "000000"
mp[","] = "000011"
mp["-"] = "10010001"
mp["."] = "010001"
mp["?"] = "000001"
mp["A"] = "100101"
mp["B"] = "10011010"
mp["C"] = "0101"
mp["D"] = "0001"
mp["E"]="110"
mp["F"]="01001"
mp["G"]="10011011"
mp["H"]="010000"
mp["I"]="0111"
mp["J"]="10011000"
mp["K"]="0110"
mp["L"]="00100"
mp["M"]="10011001"
mp["N"]="10011110"
mp["O"]="00101"
mp["P"]="111"
mp["Q"]="10011111"
mp["R"]="1000"
mp["S"]="00110"
mp["T"]="00111"
mp["U"]="10011100"
mp["V"]="10011101"
mp["W"]="000010"
mp["X"]="10010010"
mp["Y"]="10010011"
mp["Z"]="10010000"

gyaku = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?"

while s=gets
  s=s.chomp
  t=""
  for i in 0...s.length
    t+=mp[s[i]]
  end
  n = t.length
  t += "0"*((5-n%5)%5)
  n = t.length
  res = ""
  for i in 0...(n/5)
    beg = i*5
    id = 0
    for j in 0...5
      id*=2
      id+=(t[beg+j]=="0" ? 0 : 1)
    end
    res += gyaku[id]
  end
  puts res
end

Measured memory_bytes: 8988
#include <stdio.h>

int main(void)
{
	int N, cnt, i;
	char s[100001];

	scanf("%d %s", &N, s);

	for(i = 0, cnt = 0; i < N; )
	{
		cnt ++;
		for( ++i; i < N && s[i] == s[i-1]; ++i);
	}

	printf("%d\n", cnt);

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N;
	int a[100001];
	vint akind;
	map<int,int> akosu;
	int tori=0;
	scan(N);
	rep1(i,N){
		scan(a[i]);
		if(akosu[a[i]]==0){
			akind.push_back(a[i]);
			akosu[a[i]]=1;
		}
		else akosu[a[i]]++;
	}
	rep(i,akind.size()){
		//printf("%d %d %d\n",i,akind[i],akosu[akind[i]]);
		if(akosu[akind[i]]<akind[i]) tori+=akosu[akind[i]];
		else tori+=akosu[akind[i]]-akind[i];
	}
	prin(tori);
	return 0;
}


Measured memory_bytes: 5496
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

int menu[101][4][4][4];//menue[i??\???][??¨??\????????????][?????\????????????] = 0 or 1????????????????????????????????????
int pasta[101];
int sum;
int n;
//menue[k][a][b]
const int NG = 0, OK = 1;

int pasta_decision(int nannitime=0, int kyou=0, int kinou=0, int ototoi=0)
{
	if (kyou && kyou == kinou && kinou == ototoi) return NG;
	if (pasta[nannitime] != 0 && pasta[nannitime] != kyou) return NG;
	if (nannitime == n) return OK;
	if (menu[nannitime][kyou][kinou][ototoi] != -1) return menu[nannitime][kyou][kinou][ototoi];
	return menu[nannitime][kyou][kinou][ototoi] =
		   (pasta_decision(nannitime + 1, 1, kyou, kinou) +
	       pasta_decision(nannitime + 1, 2, kyou, kinou) +
		   pasta_decision(nannitime + 1, 3, kyou, kinou) ) % 10000;
}

int main()
{
	int k;
	int a, b;
	
	memset(menu, -1, sizeof(menu));
	
	scanf("%d %d", &n, &k);
	for (int i = 0; i < k; i++){
		scanf("%d %d", &a, &b);
		pasta[a] = b;
	}
	printf("%d\n", pasta_decision());
}

Measured memory_bytes: 1220
import java.io.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {

		int A = nextInt();
		int B = nextInt();
		int C = nextInt();
		int D = nextInt();
		while(A>0&&C>0){
			C-=B;
			A-=D;
		}
		if(C<=0){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}

	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 25320
#include<stdio.h>
int main()
{
    int A,B,C;
    scanf("%d %d %d",&A,&B,&C);
    if(A!=B &&A==C){
            printf("Yes");

    }
    else if(A==B && A!=C){
        printf("Yes");
    }
    else if(A!=C && B==C){
        printf("Yes");
    }
    else if(A==C && B!=C){
        printf("Yes");
    }
    else {

        printf("No");
    }
    return 0;
}


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

#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define FASTIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define IN freopen("input.txt", "r", stdin);
#define OUT freopen("output.txt", "w", stdout);
#define LL long long
#define MOD 1000000007
#define INF 1000000000000000000
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)

using namespace std;

const int maxN=101;
const int maxW=1e7+1;
vector<LL> F[maxN];
LL v[maxN];
int w[maxN];

int main()
{
//	IN;OUT;		
	FASTIO;
	int N,W;
	cin >> N >> W;
	for (int i=1; i<=N; i++) {
		cin >> w[i] >> v[i];
		F[i].pb(0);
	}
	F[0].pb(0);
	for (int i=1; i<=W; i++) F[0].pb(-INF);
	for (int i=1; i<=N; i++) 
		for (int j=1; j<=W; j++) {
			LL V = F[i-1][j];
			if (j>=w[i]) V = max(V, F[i-1][j-w[i]] + v[i]);
			F[i].pb(V);
		}
	LL ans = -INF;
	for (int i=1; i<=W; i++) ans = max(ans, F[N][i]);
	cout << ans;
	return 0;
}


Measured memory_bytes: 80252