akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
#define int 		long long
#define vi 			vector<int>
#define vec(x) 		vector<x>
#define matrix 		vector<vector<int>>
#define pii 		pair<int,int>
#define rep(i,s,e)  for(int i=s;i<e;i++)
#define rrep(i,e,s) for(int i=e;i>=s;i--)
#define MOD			1000000007
#define pb 			push_back
#define ff 			first
#define ss 			second		
#define w(x)		int x; cin>>x; while(x--)
const int INF=1e18;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
// find_by_order(k-1)  returns iterator to kth element starting from 0; Returns the kth smallest element
// order_of_key(k) returns count of elements strictly smaller than k;Returns the number of elements less than k
// erase,insert same as normal set

const int mxn=1e5+13;
int n,m;

vector<int> graph[mxn];

int dp[mxn];

int calc(int node){	
	if(graph[node].size()==0) return 0;

	if(dp[node]!=-1) return dp[node];

	int ans=0;
	for(auto c:graph[node]){
		ans=max({1+calc(c),ans});
	}

	return dp[node]=ans;
}

void solve(){
	cin>>n>>m;

	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		graph[a].pb(b);
	}

	memset(dp,-1,sizeof(dp));

	int ans=-INF;
	for(int i=1;i<=n;i++){
		ans=max(calc(i),ans);
	}

	cout<<ans<<endl;

}
 
int32_t main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt","r",stdin);
// 	freopen("output.txt","w",stdout);
// #endif
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 8576
X = 0
N, T = map(int, input().split())

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

X = T
for i in range(1, N):
    if t[i - 1] + T <= t[i]:
        X += T
    else:
        X += T - (t[i - 1] + T - t[i])

print(X)


Measured memory_bytes: 26708
#include <cstdio>
#include <cctype>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_T T in(int c){T n=0;bool m=false;while(isspace(c)){c=gcu();}if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m?-n:n;}
_in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
_vo(bool b) {pcu('0'+b);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_vo(string s){for(char c:s)pcu(c);}
#endif
_T _vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vl(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

int time() {
	int h = in(), m = in();
	return h * 3600 + m * 60 + in();
}

int main() {
	for (int n; (n = in());) {
		vector<pair<int, int>> t;
		while (n--) {
			t.push_back({time(), 1});
			t.push_back({time(), -1});
		}
		sort(t.begin(), t.end());
		int c = 0, m = 0;
		for (auto a: t)
			m = max(c += a.second, m);
		outl(m);
	}
}


Measured memory_bytes: 2712
#include <bits/stdc++.h>
#define FOR(i, c) for (int i = 0; i < c; i++)
#define MOD 1000000007
using namespace std;

int main() {
  string s;
  cin >> s;
  bool res = s[0] != s[1] && s[2] == s[3] && s[4] == s[5];
  cout << (res ? "Yes" : "No") << endl;
  return 0;
}



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

using namespace std;
typedef long long ll;
const int N = 1e5 + 7;
const int M = 1e6 + 7;
const int INF = 1e9 + 7;
int main()
{
    int x, y, z;
    cin >> x >> y >> z;
    swap(x, y);
    swap(x, z);
    cout << x << " " << y << " " << z << endl;
    return 0;
}


Measured memory_bytes: 256
r, c = map(int, input().split())
sheet = [[0 for i in range(c)] for j in range(r+1)]
for i in range(r):
    sheet[i] = list(map(int, input().split()))
    sheet[i].append(0)
    for j in range(c):
        sheet[i][c] += sheet[i][j]
sheet[r].append(0)
for k in range(c+1):
    for l in range(r):
        sheet[r][k] += sheet[l][k]
for m in range(r+1):
    for n in range(c):
        print(sheet[m][n], end=" ")
    print(sheet[m][n+1])


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

int main() {
  int n, m = 0;
  cin >> n;
  vector<int> v(n);
  rep(i, n) cin >> v[i];
  rep(i, n-1){
    if(v[i] == v[i+1]){
      ++m;
      v[i+1] = 0;
    }
  }
  cout << m << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <set>
using namespace std;

int h,w;

int main(){
    while(true){
        cin>>h>>w;
        if(h==0&&w==0)return 0;
        else{
            for(int i=0;i<h;i++){
                for(int j=0;j<w;j++)cout<<"#";
                cout<<endl;
            }
            cout<<endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3096
N, X = map(int,input().split(" "))
Ls = []
for i in input().split(" "):
  Ls.append(int(i))
Ds = [0]*(N+1)
cnt = 0
for i in range(1,N+1):
  Ds[i] = Ds[i-1] + Ls[i-1]
  if Ds[i] <= X: cnt += 1
print(cnt+1)

Measured memory_bytes: 3064
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import bisect_right
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
d = defaultdict(int)
N = int(input())
for i in range(N):
    s = list(input())[:-1]
    if s[0] == "A":
        d["A"] += 1
    elif s[0] == "W":
        d["W"] += 1
    elif s[0] == "T":
        d["T"] += 1
    else:
        d["R"] += 1
print("AC","x",d["A"])
print("WA","x",d["W"])
print("TLE","x",d["T"])
print("RE","x",d["R"])




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

int main(){
  int N;
  int r=0;
  int b=0;
  string S;
  cin>>N;
  cin>>S;
  for(int i=0;i<N;i++){
    if(S.at(i)=='R')r++;
    if(S.at(i)=='B')b++;
  }
  if(r>b){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
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 T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int dp[1010][2010];

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int s;
    cin>>s;
    COMinit();
    int ans=0;
    for (int i = 0; i < 1000; i++)
    {
        int x=s-3*i;
        if(x<0) break;
        ans+=COM(x+i-1, x);
        ans%=MOD;
    }
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 15596
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>

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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
5
-2 0
-2 0
7 8
9 10
-2 -1
)");
#define cin input
#endif

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

	map<int, multiset<int>> mlx;
	map<int, multiset<int>> mrx;
	REP (i, n)
	{
		int l, r;
		cin >> l >> r;
		mlx[l].insert(r);
		mrx[r].insert(l);
	}

	ll k = 0;
	int c = 0;

	auto ml = mlx;
	auto mr = mrx;
	while (ml.size())
	{
		{
			/*auto it = ml.upper_bound(c);
			if (it == ml.end())
				--it;*/
			auto it = ml.end();
			--it;
			auto it2 = it->second.end();
			--it2;

			int d = abs(c - it->first) > abs(*it2 - c) ? *it2 - c : it->first - c;
			if (it->first <= c && *it2 >= c)
				d = 0;
			k += abs(d);
			c += d;
			//cout << "_" << k << " " << c << ": " << it->first << "-" << *it2 << endl;

			mr[*it2].erase(it->first);
			if (!mr[*it2].size())
				mr.erase(*it2);

			it->second.erase(it2);
			if (!it->second.size())
				ml.erase(it);
		}
		
		if (!ml.size())
			break;

		{
			/*auto it = mr.lower_bound(c);
			if (it != mr.begin())
				--it;*/
			auto it = mr.begin();
			auto it2 = it->second.begin();

			int d = abs(c - it->first) > abs(*it2 - c) ? *it2 - c : it->first - c;
			if (it->first >= c && *it2 <= c)
				d = 0;
			k += abs(d);
			c += d;
			//cout << "_" << k << " " << c << ": " << it->first << "-" << *it2 << endl;
		
			ml[*it2].erase(it->first);
			if (!ml[*it2].size())
				ml.erase(*it2);

			it->second.erase(it2);
			if (!it->second.size())
				mr.erase(it);
		}

	}
	k += abs(c);

	ml = mlx;
	mr = mrx;
	ll k2 = 0;
	c = 0;
	while (ml.size())
	{
		{
			/*auto it = mr.lower_bound(c);
			if (it != mr.begin())
				--it;*/
			auto it = mr.begin();
			auto it2 = it->second.begin();

			int d = abs(c - it->first) > abs(*it2 - c) ? *it2 - c : it->first - c;
			if (it->first >= c && *it2 <= c)
				d = 0;
			k2 += abs(d);
			c += d;
			//cout << "_" << k2 << " " << c << ": " << it->first << "-" << *it2 << endl;
		
			ml[*it2].erase(it->first);
			if (!ml[*it2].size())
				ml.erase(*it2);

			it->second.erase(it2);
			if (!it->second.size())
				mr.erase(it);
		}

		if (!ml.size())
			break;

		{
			/*auto it = ml.upper_bound(c);
			if (it == ml.end())
				--it;*/
			auto it = ml.end();
			--it;
			auto it2 = it->second.end();
			--it2;

			int d = abs(c - it->first) > abs(*it2 - c) ? *it2 - c : it->first - c;
			if (it->first <= c && *it2 >= c)
				d = 0;
			k2 += abs(d);
			c += d;
			//cout << "_" << k2 << " " << c << ": " << it->first << "-" << *it2 << endl;

			mr[*it2].erase(it->first);
			if (!mr[*it2].size())
				mr.erase(*it2);

			it->second.erase(it2);
			if (!it->second.size())
				ml.erase(it);
		}
		
	}
	k2 += abs(c);

	cout << max(k, k2) << endl;

	return 0;
}


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

int main(){
    int w,h,x,y,r;
    scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
    if(x<=w-r&&x>=r&&y>=r&&y<=h-r){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
}


Measured memory_bytes: 3160
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll c[15],a[15][15],b[15];

int main(void){
	int n,m,i,mask,j;
	ll x,tmp,ans=INFLL;
	bool flag;
	std::cin >> n >> m >> x;
	for(i=0; i<n; ++i){
		std::cin >> c[i];
		for(j=0; j<m; ++j){
			std::cin >> a[i][j];
		}
	}
	for(mask=0; mask<(1<<n); ++mask){
		std::fill(b,b+m,0ll);
		tmp = 0ll;
		for(i=0; i<n; ++i){
			if(mask&(1<<i)){
				tmp += c[i];
				for(j=0; j<m; ++j){
					b[j] += a[i][j];
				}
			}
		}
		flag = true;
		for(j=0; j<m; ++j){
			if(b[j]<x){
				flag = false;
				break;
			}
		}
		if(flag){
			ans = std::min(ans,tmp);
		}
	}
	std::cout << ((ans<INFLL)?ans:(-1ll)) << std::endl;
	return 0;
}


Measured memory_bytes: 3608
bingo = []
i = 0
while i < 3
  arr = gets.chomp.split(' ').map(&:to_i).each do |x|
    x = [x,0]
    bingo << x
  end
  i += 1
end
# p bingo
n = gets.chomp.to_i
i = 0

bingo_swicth = false

while i < n
  a = gets.chomp.to_i
  if bingo.index([a,0])
    # p "HI",bingo.index([a,0])
    bingo[bingo.index([a,0])][1] = 1
  end
  i += 1
  if (bingo[0][1] == 1 && bingo[1][1] == 1 && bingo[2][1] == 1) || 
      (bingo[0][1] == 1 && bingo[3][1] == 1 && bingo[6][1] == 1) ||
      (bingo[0][1] == 1 && bingo[4][1] == 1 && bingo[8][1] == 1) ||
      (bingo[1][1] == 1 && bingo[4][1] == 1 && bingo[7][1] == 1) ||
      (bingo[2][1] == 1 && bingo[4][1] == 1 && bingo[6][1] == 1) ||
      (bingo[2][1] == 1 && bingo[5][1] == 1 && bingo[8][1] == 1) ||
      (bingo[3][1] == 1 && bingo[4][1] == 1 && bingo[5][1] == 1) ||
      (bingo[6][1] == 1 && bingo[7][1] == 1 && bingo[8][1] == 1)
    bingo_swicth = true
  end
end
# p bingo
if bingo_swicth
  puts "Yes"
else
  puts "No"
end

Measured memory_bytes: 14344
from itertools import product
n=int(input())
ans=[]
lst=[3,5,7]
for i in range(3,10):
    for v in product(lst,repeat=i):
        if len(set(v))==3:
            ans.append(int("".join(map(str,v))))
answer=0
for i in ans:
    if i<=n:
        answer+=1
print(answer)

Measured memory_bytes: 74612
#include<stdio.h>
#include<string.h>
int main()
{
        char a[20], b[20], c[20];
        scanf("%s %s %s", a, b, c);
        int n=strlen(a);
        if(a[n-1]!=b[0]) printf("NO\n");
        else if(a[n-1]==b[0])
        {
                n=strlen(b);
                if(b[n-1]!=c[0]) printf("NO\n");
                else if(b[n-1]==c[0]) printf("YES\n");
        }
        return 0;
}

Measured memory_bytes: 128
use std::io::{Read, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    let mut iter = input.split_whitespace();

    let a: i32 = iter.next().unwrap().parse().unwrap();
    let b: i32 = iter.next().unwrap().parse().unwrap();

    out.write_fmt(format_args!("{} {} {:.5}\n", a/b, a%b, (a as f64)/(b as f64))).unwrap();

}



Measured memory_bytes: 5052
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String n = sc.next();

        char[] chars = n.toCharArray();

        boolean flg = false;
        for(int i=0;i<chars.length;i++){
            if(i%2==0){
                char temp = chars[i];
                if(temp == 'L'){
                    System.out.println("No");
                    return;
                }
            }else{
                char temp = chars[i];
                if(temp == 'R'){
                    System.out.println("No");
                    return ;
                }

            }
        }
        System.out.println("Yes");


    }
}

Measured memory_bytes: 22996
import copy

D = int(input())
c = list(map(int, input().split()))
s = []
for i in range(D):
    s.append(list(map(int, input().split())))

score = 0
last = [0] * 26
for d in range(D):
    score_max = -999999999
    t_max = -1
    for t in range(26):
        # すべてのtypeのscoreを計算する
        tmp_score = 0
        tmp_last = copy.deepcopy(last)

        # scoreの計算
        tmp_score += s[d][t]
        tmp_last[t] = d + 1
        for _type in range(26):
            tmp_score -= (d + 1 - tmp_last[_type]) * c[_type]
        # 最大値の更新
        if score_max < tmp_score:
            score_max = tmp_score
            t_max = t
    #print(score_max, t_max)
    score += score_max
    last[t_max] = d + 1
    print(t_max + 1)


Measured memory_bytes: 9652
import java.util.*;

public class Main 
{
	public static void main(String[] args) 
	{
		Scanner stdIn = new Scanner(System.in);
		Stack<Integer> stack = new Stack<Integer>();
		while(stdIn.hasNext())
		{
			int num = stdIn.nextInt();
			if(num == 0)
			{
				System.out.println(stack.peek());
				stack.pop();
			}
			else
			{
				stack.add(num);
			}
		}
	}
}

Measured memory_bytes: 12000
//url:
//problem name: Brick Break

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int N; cin >> N;
    veci L(N);
    REP(i,N) cin >> L[i];
    sort(L.begin(),L.end());
    int ans = 0;
    int k = 0;
    REP(i,N-2) {
        k = i;
        for(int j = i + 1; j < N-1; j++) {
            while(k < N && L[k] < L[i] + L[j]) {
                k++;
            }
            ans += k - (j+1);

            if(k == j) k++;
        }
    }

    cout << ans << endl;
}

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

int main()
{
    int a,b,c,d,e,k;
    cin >> a >> b >> c >> d >> e >> k;
    if(e - a > k){
        cout << ":(" << endl;
    }else{
        cout << "Yay!" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 100100;
int n;
vector<int> g[N];
int dp[N];

void dfs(int v, int par) {
	int p = 0, x = 0;
	for (int u : g[v]) {
		if (u == par) continue;
		dfs(u, v);
		while(x & dp[u]) {
			p++;
			x ^= x & ((1 << p) - 1);
		}
		x |= dp[u];
		x ^= x & ((1 << p) - 1);
	}
	dp[v] = x + (1 << p);
}

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%d", &n);
	for (int i = 1; i < n; i++) {
		int v, u;
		scanf("%d%d", &v, &u);
		v--;u--;
		g[v].push_back(u);
		g[u].push_back(v);
	}
	dfs(0, -1);
	int ans = 0;
	while((1 << ans) <= dp[0]) ans++;
	printf("%d\n", ans - 1);

	return 0;
}


Measured memory_bytes: 11776
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include<algorithm>
#include<iomanip>
#include<math.h>
using namespace std;



int main()
{
	int S, W;

	cin >> S >> W;

	if (W >= S) {
		cout << "unsafe";

	}
	else {
		cout << "safe";
	}





	



}

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

int main() {
    int n,k,r,s,p;
    cin >> n >> k >> r >> s >> p;
    string t;
    cin >> t;

    int ans=0;
    queue<char> q;
    for(int i = 0; i < k; i++) {
        if(t[i]=='r'){
            ans += p;
            q.push('r');
        }
        if(t[i]=='s'){
            ans += r;
            q.push('s');
        }
        if(t[i]=='p'){
            ans += s;
            q.push('p');
        }
    }

    for(int i = k; i < n; i++) {
        if(t[i]==q.front()){
            q.pop();
            q.push('a');
        }
        else{
            if(t[i]=='r'){
                ans += p;
                q.push('r');
                q.pop();
            }
            if(t[i]=='s'){
                ans += r;
                q.push('s');
                q.pop();
            }
            if(t[i]=='p'){
                ans += s;
                q.push('p');
                q.pop();
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3812
n = int(input())
a = []
for i in range(n):
    x = int(input())
    a.append(x)
data1 = []
data2 = []
a = sorted(a)
for i in range(n // 2):
    data1.append(a[n - i - 1])
    data2.append(a[i])
    if len(data1) + 1 != n:
        data1.append(a[i])
        data2.append(a[n - i - 1])
index = n // 2
if n % 2 == 0:
    index -= 1

def set_p(data):
    if abs(data1[0] - a[index]) > abs(data1[-1] - a[index]):
        p = 0
    else:
        p = n
    return p
p1 = set_p(data1)
p2 = set_p(data2)
data1.insert(p1, a[index]) 
data2.insert(p2, a[index])
ans = 0
def calc_ans(data):
    ans = 0
    for i in range(1, n):
        ans += abs(data[i] - data[i - 1])
    return ans
    
print(max(calc_ans(data1), calc_ans(data2)))

Measured memory_bytes: 15960
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const double PI=3.1415926535;

int main(){
    int N,L;
    cin>>N>>L;
    int R=N+L-1;
    if(L>0){
        cout<<(L+1+R)*(N-1)/2<<endl;
    }else if(R<0){
        cout<<(L+R-1)*(N-1)/2<<endl;
    }else{
        cout<<(L+R)*N/2<<endl;
    }

}


Measured memory_bytes: 256
from math import gcd
k = int(input())

s = 0
#for a in range(1,k+1):
#    for b in range(1,k+1):
#        for c in range(1,k+1):
#            s += gcd(a,gcd(b,c))

# 全部同じのケース
for i in range(1,k+1):
    s += gcd(i,gcd(i,i))

# １つ違うケース
for i in range(1,k+1):
    for j in range(1,k+1):
        if i != j:
            s += gcd(i,gcd(i,j))*3

# 全部違うケース
for a in range(1,k-1):
    for b in range(a+1,k):
        for c in range(b+1,k+1):
            s += gcd(a,gcd(b,c))*6
            
print(s)


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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    int nmin = min(a, min(b,c));
    int nmax = max(a, max(b,c));
    int nmid = a+b+c-nmin-nmax;
    int ret = 0;
    ret += (nmax - nmin)/2;
    ret += (nmax - nmid)/2;
    if ((nmax - nmid) % 2 == 1 && (nmax - nmin) % 2 == 1)
        ret++;
    else if (((nmax - nmid) % 2 == 1 && (nmax - nmin) % 2 == 0) ||
    ((nmax - nmid) % 2 == 0 && (nmax - nmin) % 2 == 1))
        ret+=2;
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
//==========================================
// ABC131a
//
// 2019/08/18
//==========================================

#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

int main(int argc, char* argv[])
{
  char s[4];
  for(int i=0; i<4; i++) cin >> s[i];

  if(s[0]==s[1] || s[1]==s[2] || s[2]==s[3]) cout << "Bad" << endl;
  else cout << "Good" << endl; 

  return 0;
}

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

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << endl;
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

void solve() {
    long long N, M; cin >> N >> M;
    long long c = N * 2 + M;
    long long s = c / 4;
    if (c - s * 2 <= M) cout << s << '\n';
    else cout << M / 2 << '\n';
}

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

    solve();

    return 0;
} 

Measured memory_bytes: 3608
/* ex3_3 
　　　　　sachiyan*/

#include <stdio.h>
#include <math.h> //math.h の標準ライブラリを使用
int main(void){
    int num, ary, ans; //入力値N,Kと答えansを定義
    scanf("%d %d", &num, &ary); //入力値N,Kを読み取る
    ans = 0; //ansに初期値0を代入
    while(pow(ary, ans) <= num){ //powはmath.hによる累乗を計算する関数
        ans++;  //K進数の最高位を探す　Kのans乗がN以下の時はそれ以上の桁が存在するので繰り返す
    }
    printf("%d\n", ans); //答えansを出力
    return 0;
}

Measured memory_bytes: 128
#include<iostream>

bool isprime( int n )
{
 	for( int i = 2; i * i <= n; i++ ){
	           if( n % i == 0 ) return false;
	}
	
	return true;
}

int main()
{
	int n;
	while( std::cin >> n ){
		int a = n;
	 	while( !isprime( --a ) );
		std::cout << a << " ";
		a = n;
		while( !isprime( ++a ) );
		std::cout << a << std::endl;
	}
	
 	return 0;
}

Measured memory_bytes: 1160
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    H,W = (int(_) for _ in input().split())
    S = []
    V = [(0,1),(0,-1),(1,0),(-1,0),(1,1),(1,-1),(-1,1),(-1,-1)]
    
    for i in range(H):
        S.append(list(_ for _ in input()))
        
    for h in range(H):
        for w in range(W):
            cnt = 0
            if(S[h][w] == '.'):                
                for v in V:
                    if(h+v[0]<H and h+v[0]>=0 and w+v[1]<W and w+v[1]>=0 and S[h+v[0]][w+v[1]]=='#'):
                        cnt += 1
                S[h][w] = cnt
                        
    for h in range(H):
        print(''.join(str(_) for _ in S[h]))
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()


int main() {
    string s;
    cin>>s;

    int n=s.size();
    string t="";
    int i=0;
    for(i=0;i<n-1;i++){
        if(s[i]=='B' && s[i+1]=='C'){
            t+='X';
            i++;
        }
        else t+=s[i];
    }
    if(i==n-1) t+=s[i];

    ll ans=0,cnt=0;
    rep(i,t.size()){
        if(t[i]=='A') cnt++;
        else if(t[i]=='X') ans+=cnt;
        else cnt=0;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 3920
#include <iostream>
#include <vector>
#include <cstdint>

int main() {
  constexpr std::int64_t kModulus = 1000000007;
  int N;
  std::cin >> N;
  std::vector<std::int64_t> A(N);
  for (int i = 0; i < N; ++i) {
    std::cin >> A[i];
  }
  std::int64_t sum = 0;
  std::int64_t sum_products = 0;
  for (int i = 0; i < N; ++i) {
    sum_products = (sum_products + sum * A[i]) % kModulus;
    sum = (sum + A[i]) % kModulus;
  }
  std::cout << sum_products << std::endl;
  return 0;
}


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

using namespace std;
typedef long long ll;
const long double pi=3.14159265358979323846;
#define x  first
#define y  second

bool isP(ll x)
{
    for(int i=2;i<=sqrt(x);i++)
    {
        if(x%i==0)return 0;
    }
    return 1;
}

int main()
{
    cin.tie(0);
    cin.sync_with_stdio(0);
    //freopen("op.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    ll t=1;
    //cin>>t;
    while(t--)
    {
        ll n,s=0,k;
        cin>>n>>k;
        ll a[n];
        for(int i=0;i<n;i++)cin>>a[i];
        sort(a,a+n);
        for(int i=0;i<k;i++)s+=a[i];
        cout<<s;
    }
    return 0;
}


Measured memory_bytes: 3668
#include <bits/stdc++.h>
#include <cstdio>
using namespace std;
#define rep(i, n) for (long i = 0; i < (n); i++)
vector<long> inputVector(long n)
{
    vector<long> vec(n);
    rep(i, n)
    {
        scanf("%d", &vec.at(i));
    }
    return vec;
}
int main()
{
    long n, k;
    long ans;
    // scanf("%d", &x);
    cin >> n >> k;
    set<long> s;
    rep(i, n)
    {
        s.insert(i + 1);
    }
    rep(i, k)
    {
        long d;
        cin >> d;
        vector<long> ll = inputVector(d);
        rep(j, d)
        {

            s.erase(ll.at(j));
            // cout << s.size() << endl;
        }
    }
    // printf("%d\n", x * x * x);
    ans = s.size();
    cout << ans << endl;
}

Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)

const ll MOD = 1e9 + 7;

void solve(istream& cin, ostream& cout) {
  int n, k;
  cin >> n >> k;
  int h;
  int ans = 0;
  REP(i, n) {
    cin >> h;
    if (h >= k) {
      ans++;
    }
  }
  cout << ans << endl;
}

#ifndef TEST
int main() {
  solve(cin, cout);
}
#endif


Measured memory_bytes: 256
chomp($n=<>);
@a=split/\//,$n;
if($a[0]<=2018){
	print "TBD";
}elsif($a[0]<=2019){
	$a[1]=~ s/0([0-9]{1})/$1/;
    if($a[1]<=4){
    	print "Heisei";
    }else{
    	print "TBD";
    }
}

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

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
int n;
double dp[303][303][303];
double sol(vi a){
    if(a[1]==0 and a[2]==0 and a[0]==0) return 0;
    double &ans=dp[a[0]][a[1]][a[2]];
    if(ans!=-1) return ans;
    int c0=n-a[0]-a[1]-a[2];
    double cur=0;
    rep(i,0,3){
        if(a[i]==0) continue;
        a[i]--;
        if(i-1>=0) a[i-1]++;
        cur+=(a[i]+1)*(sol(a)+1);
        if(i-1>=0) a[i-1]--;
        a[i]++;
    }
    return ans=(c0+cur)/(n-c0);
}
void solve(){
    cin>>n;
    rep(i,0,n+1){
        rep(j,0,n+1){
            rep(k,0,n+1){
                dp[i][j][k]=-1;
            }
        }
    }
    vi a(3);
    rep(i,1,n+1){
        int x;
        cin>>x;
        x--;
        a[x]++;
    }
    cout<<fixed<<setprecision(10)<<sol(a)<<endl;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 217472
#include <iostream>
using namespace std;
double x;
int main()
{
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		int t;
		cin >> t;
		x += 1.0 / t;
	}
	printf("%lf",1.0 / x);
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace AizuOnlineJudge
{
    class Program
    {
        static void Main(string[] args)
        {
            string s;
            while ((s = Console.ReadLine()) != "-")
            {
                var n = int.Parse(Console.ReadLine());

                for (var i = 0; i < n; ++i)
                {
                    var h = int.Parse(Console.ReadLine());
                    s = s.Substring(h, s.Length - h) + s.Substring(0, h);
                }
                Console.WriteLine(s);
            }
        }

        private static IEnumerable<IEnumerable<string>> Enumerator()
        {
            while(true)
            {
                var s = Console.ReadLine();
                if (s.Equals("END_OF_TEXT")) yield break;
                yield return s.ToLower().Split(' ');
            }
        }

        /*private static bool IsInput(out int[] arr)
        {
            var s = Console.ReadLine();
            if (s == "0 0") { arr = null; return false; }

            arr = s.Split(' ').Select(int.Parse).ToArray();
            return true;
        }
        // */
    }
}


Measured memory_bytes: 15960
s=input()
t=input()
ans=10000
lt=len(t)
ls=(len(s))
start,last=0,lt
while last<=ls:
    count=0
    j=0
    for i in range (start,last):
        if s[i]!=t[j]:
            count+=1
        j+=1
    ans=min(ans,count)
    start+=1
    last+=1


print(ans)


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

int f(int n) {
    int ans = 0;
    for (int i = 1; i *i <= n; i++) {
        if (n%i == 0)
            ans+=2;
    }
    return ans;
}

int main()
{
    ios::sync_with_stdio(false);
    int n, ans = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        if (i %2 == 1 && f(i) == 8) {
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
N, Q = map(int, input().split())
s = input()
t_list, d_list = list(), list()
for i in range(Q):
    t, d = input().split()
    t_list.append(t)
    d_list.append(d)


def go_away_to_left(idx):
    for t, d in zip(t_list, d_list):
        if s[idx] == t:
            if d == 'L':
                idx = idx - 1
            else:
                idx = idx + 1
        
        if idx == -1:
            return True
        
        elif idx == N:
            return False
    
    return False


def go_away_to_right(idx):
    for t, d in zip(t_list, d_list):
        if s[idx] == t:
            if d == 'L':
                idx = idx - 1
            else:
                idx = idx + 1
        
        if idx == N:
            return True
        
        elif idx == -1:
            return False
    
    return False


def binary_search_left(boundary, pyfunc):
    """search left boundary index where pyfunc returns True
    Args:
        boundary (tuple): [a, b)
        pyfunc
    Returns:
        index (int)
    """
    idx = sum(boundary) // 2
    if pyfunc(idx):
        boundary = (idx, boundary[1])
    else:
        boundary = (boundary[0], idx)
    
    if (boundary[1] - boundary[0]) == 1:
        return boundary[0]
    else:
        return binary_search_left(boundary, pyfunc)


def binary_search_right(boundary, pyfunc):
    """search right boundary index where pyfunc returns True
    Args:
        boundary (tuple): (a, b]
        pyfunc
    Returns:
        index (int)
    """
    idx = sum(boundary) // 2
    if pyfunc(idx):
        boundary = (boundary[0], idx)
    else:
        boundary = (idx, boundary[1])
    
    if (boundary[1] - boundary[0]) == 1:
        return boundary[1]
    else:
        return binary_search_right(boundary, pyfunc)

left = binary_search_left((-1, N), go_away_to_left)
right = binary_search_right((-1, N), go_away_to_right)
if left >= right:
    print(0)
else:
    print(right - left - 1)
# if left >= right:
#     golem_del = N
# else:
#     golem_del = (left - -1) + (N - right)
# print(N - golem_del)


Measured memory_bytes: 85340
def calc(pat, F, P):
    ans = 0
    both = [0 for i in range(N)]
    for i in range(10):
        if pat[i] == 1:
            for j in range(N):
                if F[j][i] == 1:
                    both[j] += 1
    for i in range(N):
        ans += P[i][both[i]]
    return ans

N = int(input())
F = []
for i in range(N):
    F.append(list(map(int,input().split())))
P = []
for i in range(N):
    P.append(list(map(int,input().split())))

zenbu = 2**10
res = []
for i in range(1, zenbu):
    pat = []
    bit = i
    for j in range(10):
        pat.append(bit % 2)
        bit //= 2
    res.append(calc(pat, F, P))

print(str(max(res)))

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

class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        int[] X = Console.ReadLine().Split(' ').Select(o => int.Parse(o)).ToArray();

        Console.WriteLine(Enumerable.Range(1, X.Max()).Select(P => X.Select(Xi => (int)Math.Pow(Xi - P, 2)).Sum()).Min());
    }
}

Measured memory_bytes: 13396
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using INT=mp::cpp_int;
using namespace std;
using ll=long long;
using vec=vector<ll>;
using vect=vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n;i>=0;i--)
#define Pool(i, m, n) for(ll i=n;i>=m;i--)
#define MAX 99999999999ll
#define MIN -99999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(a) cout<<a<<endl
#define putout2(a,b) putout(a);putout(b)
#define putout3(a,b,c) putout(a);putout(b);putout(c)
#define putout4(a,b,c,d) putout(a);putout(b);putout(c);putout(d)
#define putout5(a,b,c,d,e) putout(a);putout(b);putout(c);putout(d);putout(e)
#define Gput(a,b) G[a].push_back(b)
#define cin1(a) cin>>a
#define cin2(a,b) cin>>a>>b
#define cin3(a,b,c) cin>>a>>b>>c
#define cin4(a,b,c,d) cin>>a>>b>>c>>d
#define cin5(a,b,c,d,e) cin>>a>>b>>c>>d>>e
#define sum(v) accumulate(all(v), 0ll)
#define gcd(x,y) __gcd(x,y)
ll ctoi(char c){
	if(c>='0'&&c<='9'){
		return c-'0';
	}
	return 0;
}
ll lcm(ll x,ll y){
  ll z=gcd(x,y);
  return x*y/z;
}
INT LCM(INT x,INT y){
  INT z=gcd(x,y);
  return x*y/z;
}
ll primejudge(ll n){
  if(n<2)return 0;
  else if(n==2)return 1;
  else if(n%2==0)return 0;
  double sqrtn=sqrt(n);
  Loop(i,3,sqrtn+1){
     if(n%i==0){
        return 0;
     }
     i++;
  }
  return 1;
}
INT modinv(INT a, INT m) {
    INT b = m, u = 1, v = 0;
    while (b) {
        INT t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int main() {
  cout << fixed << setprecision(30);
  ll n;
  cin>>n;
  vec p(n);
  vec q(n);
  loop(i,n)cin>>p[i];
  loop(i,n)cin>>q[i];
  vec r(n);
  loop(i,n)r[i]=i+1;
  ll a,b;
  bool pcheck=true;
  bool qcheck=true;
  ll count=0;
  do{
    count++;
  pcheck=true;
  qcheck=true;
    loop(i,n){
    if(p[i]!=r[i])pcheck=false;
    if(q[i]!=r[i])qcheck=false;
    }
    if(pcheck)a=count;
    if(qcheck)b=count;
}while(next_permutation(all(r)));
  putout(abs(a-b));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5 << 28, MOD = 1e9 + 7;

int x, a, b;
void input() {
  cin >> x >> a >> b;
  ;
}
void solve() {
  int z = (b - a + x);
  if (b <= a) {
    cout << "delicious" << endl;
  } else if (a + x >= b) {
    cout << "safe" << endl;
  } else
    cout << "dangerous" << endl;
  ;
  ;
}
signed main() {
  input();
  solve();
  return 0;
}

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

#define MAX_N 200000

using namespace std;

typedef long long lint;

unordered_map <int, int> ap;

long double sum;
long double mx;
long double v[MAX_N + 1];

int main()
{
    int n, k;
    cin >> n >> k;
    for(int i = 1; i <= n; i ++)
    {
        lint nr;
        cin >> nr;
        v[i] = 1.0D * (nr) * (nr + 1) / 2.0D / (1.0D * nr);
    }

    sum = 0;
    for(int i = 1; i <= n; i ++)
    {
        sum += v[i];

        if(i > k)
            sum -= v[i - k];

        mx = max(mx, sum);
    }

    cout << fixed << setprecision(10) << mx << "\n";

    return 0;
}


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

typedef long long ll;

#define int ll
#define pb push_back
#define pii pair<int,int>
#define ff first
#define ss second

const int inf = 1e9;
const ll INF = 1e18;
const int MAX = 1e5+7;

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

    int a,b,q; cin>>a>>b>>q;
    set<int> sh, te;
    for(int i=0;i<a;i++){
        int x; cin>>x;
        sh.insert(x);
    }
    for(int i=0;i<b;i++){
        int x; cin>>x;
        te.insert(x);
    }
    for(int i=0;i<q;i++){
        int x; cin>>x;
        auto it = sh.lower_bound(x), it2 = te.lower_bound(x);
        pii cur1, cur2;
        cur1.ss = (it ==sh.end()) ? INF : *(it);
        cur1.ff = (it == sh.begin()) ? -INF : *(--it);
        cur2.ss = (it2 == te.end()) ? INF : *(it2);
        cur2.ff = (it2 == te.begin()) ? -INF : *(--it2);

        int ans = INF;
        ans = min(ans, max(cur1.ss,cur2.ss) - x);
        ans = min(ans, x - min(cur1.ff,cur2.ff));
        ans = min(ans, 2*(cur1.ss-x) + (x - cur2.ff));
        ans = min(ans, 2*(cur2.ss-x) + (x - cur1.ff));
        ans = min(ans, 2*(x-cur1.ff) + (cur2.ss - x));
        ans = min(ans, 2*(x-cur2.ff) + (cur1.ss - x));
        cout<<ans<<"\n";   
    }
	return 0;
}



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


int main() {
  int N, mini = 1000000, ans = 0 ;
  cin >> N ;
  int A[N] ;
  for(int i=0;i<N;i++){
    cin >> A[i] ;
    if(mini >= A[i]){
      ans++ ;
      mini = A[i] ;
    }  
  }  
    
  cout << ans << endl ;
  return 0 ;
}

Measured memory_bytes: 1024
import re
while True:
    n,t=input().split()
    
    if t=='X':
        break
    
    if '_'in t:
        ans=s.split('_')
    else :
        ans=re.findall(r'[a-z]+|[A-Z][a-z]*',n)
        
    if t=='D':
        ans='_'.join(map(str.lower,ans))
    else :
        ans=''.join(map(str.capitalize,ans))
        if t=='L':
            ans=ans[0].lower()+ans[1:]
    
    print(ans)


Measured memory_bytes: 6516
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    l=list(map(int,input().split()))
    l=[0]+l
    ans=0
    for i in range(len(l)-1):
        ans+=max(l[i+1]-l[i],0)
    print(ans)
resolve()

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define ull unsigned ll
#define pb push_back
#define popb pop_back
#define mt make_tuple
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define pii pair <int,int>
#define piii pair <pii,int>
#define piiii pair <pii,pii>
#define plll pair <pair <ll, ll>, ll>
#define rep0(i,n) for(ll i=0;i<(ll)n;i++)
#define rep1(i,n) for(ll i=1;i<=(ll)n;i++)
#define rep(i,x,y) for(ll i=(ll)x;i<=(ll)y;i++)
#define reprev(i,n) for(ll i=(ll)n;i>=0;i--)
#define all(c) c.begin(),c.end()
#define print(a) rep0(i,a.size()) cout << a[i] << " "
#define hi() cout << "\nHello, I am error. Can you find me? :):):)\n"
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_eppoch().count())
 
using namespace __gnu_pbds;
using namespace std;
using ordered_set =  tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>;

const int mod = 1e9+7;
const long double pi = acos(-1);

ll power(ll x, ll y){
	x %= mod;
	ll ans = 1;
	while(y){
		if(y&1) ans = (ans*x)%mod;
		y /= 2;
		x = (x*x)%mod;
	}
	return ans;
}

void solve(){

	ll n;
	cin >> n;
	ll ans = 0;
	ans += (n*(n+1))/2;
	ll tmp1 = n/3, tmp2 = n/5, tmp3 = n/15;
	ans -= 3*(tmp1*(tmp1+1))/2;
	ans -= 5*(tmp2*(tmp2+1))/2;
	ans += 15*(tmp3*(tmp3+1))/2;
	cout << ans;

	return;
}

int main(){

	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int TC = 1,t = 0;
	// cin >> TC;
	while(t++ < TC){
		// cout << "Case #" << t << ": ";
		solve();
		// cout << "\n";
	}

	cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";

	return 0; 
}

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

int main(void) {
  ll N, M;
  cin >> N >> M;
  vector<ll> A(N);
  REP(i, 0, N) cin >> A[i];

  vector<ll> s(N + 1);
  REP(i, 0, N) s[i + 1] += (s[i] + A[i]) % M;
  sort(s.begin(), s.end());

  ll ans = 0;
  for (ll i = 0; i < s.size();) {
    ll j = i;
    while (j < s.size() && s[i] == s[j]) j++;
    ll d = j - i;
    ans += d * (d - 1) / 2;
    i = j;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
 
using namespace std;

int main(){
	long long n,i;
	scanf("%lld",&n);
	for(i=1;i<=n;i++)
	{
		if(i*i>n)
			break;
	}
	printf("%lld\n",(i-1)*(i-1));
	return 0;
}



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

int main(){
  char a[15],b[15],c[15];
  scanf("%s%s%s",a,b,c);
  printf("%c%c%c",a[0]- 0x20,b[0]- 0x20,c[0]- 0x20);
  return 0;
}

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

int main() {
	int n, m, X, Y;
	cin >> n >> m >> X >> Y;
	int x[110], y[110];
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}
	x[n] = X;
	for (int j = 0; j < m; j++) {
		cin >> y[j];
	}
	y[m] = Y;
	string ans = "No War";
	sort(x, x + n+1); sort(y, y + m+1);
	int xmax = x[n], ymin = y[0];
	if (xmax >= ymin) {
		ans = "War";
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256