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

using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if(a == b && c != a)
    {
        cout << "Yes";
        return 0;
    }
    if(a == c && b != a)
    {
        cout << "Yes";
        return 0;
    }
    if(b == c && c != a)
    {
        cout << "Yes";
        return 0;
    }
    cout << "No";
    return 0;
}


Measured memory_bytes: 256
a = gets.to_i # 500円枚数
b = gets.to_i # 100円枚数
c = gets.to_i # 50円枚数
x = gets.to_i

count = 0
for i in 0..a
  for j in 0..b
    for k in 0..c
      sum = i * 500 + j * 100 + k * 50
      count += 1 if sum == x
    end
  end
end
puts count


Measured memory_bytes: 1788
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    std::ios::sync_with_stdio(0); cin.tie(0);
    ll l,r;
    cin >> l >> r;
    if(r-l >= 2019 || l % 2019 > r % 2019) {
        cout << 0 << endl;
        return 0;
    }

    l %= 2019;
    r %= 2019;
    ll ans = 2019;
    for(ll i=l;i<r;++i) {
        for(ll j=i+1;j<=r;++j) {
            ans = min(ans, (i*j)%2019);
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
typedef long long ll;
ll min(ll x,ll y){return (x<y)?x:y;}
//dp[v]=(価値vを達成する品物の選び方で、最も軽いときの重さ)
ll dp[100001];
int main(){
  int n;
  ll w;
  scanf("%d%lld",&n,&w);
  for(int i=1;i<=100000;i++)dp[i]=1e14;
  dp[0]=0;
  for(int i=0;i<n;i++){
    ll wi;
    int vi;
    scanf("%lld%d",&wi,&vi);
    for(int j=100000-vi;j>=0;j--){
      dp[j+vi]=min(dp[j]+wi,dp[j+vi]);
    }
  }
  for(int i=100000;i>=0;i--){
    if(dp[i]<=w){
      printf("%d",i);
      return 0;
    }
  }
}

Measured memory_bytes: 896
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) > (b) ? (b) : (a))
#define abs(x) ((x) > 0 ? (x) : -(x))
#define MOD 1000000007 //10^9 + 7
#define endl printf("\n")
typedef long long ll;
#define MAX_N (1 << 17)

int schf[30][100001], schb[30][100001];

int
main(int argc, const char *argv[])
{
  int N, C, s, t, c, t_max = 0, st, go;
  scanf("%d %d", &N, &C);
  for (int i = 0; i < N; i++) {
    scanf("%d %d %d", &s, &t, &c);
    c--;
    t_max = Max(t_max, t);
    if (schb[c][s] == 0) st = s;
    else {
      st = schb[c][s];
      schb[c][s] = 0;
    }
    if (schf[c][t] == 0) go = t;
    else {
      go = schf[c][t];
      schf[c][t] = 0;
    }
    schf[c][st] = go;
    schb[c][go] = st;
  }

  int time[100010] = {};

  for (int i = 0; i < C; i++) {
    for (int j = 1; j <= t_max; j++) {
      if (schf[i][j] != 0) {
	time[j] += 1;
	time[schf[i][j] + 1] -= 1;
      }
    }
  }

  int ans = time[1];
  for (int i = 2; i <= t_max; i++) {
    time[i] += time[i - 1];
    ans = Max(ans, time[i]);
  }

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

  return 0;
}

  


Measured memory_bytes: 23936
import java.util.*;
class Main{
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int N = Integer.parseInt(in.next());
		int M = Integer.parseInt(in.next());
		
		System.out.println((int)(((N-M)*100+M*1900)*Math.pow(2,M)));
	}
}

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

int main()
{
  uint64_t n, m;
  cin >> n >> m;
  uint64_t ans = 1;
  for (uint64_t a = 1; a * a <= m; a++) {
    if (m % a == 0) {
      uint64_t b = m / a;
      if (a * n <= m) ans = max(ans, a);
      if (b * n <= m) ans = max(ans, b);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
N = int(input())
s = 0
L = map(int, input().split())
L = sorted(L)
for i in range(N-2): 
    a = L[i]
    for j in range(i+1, N-1, 1):
        b = L[j]
        for k in range(j+1, N, 1):
            c = L[k]
            if a != b and b != c and c != a:
                if (a + b) > c and (b +c) > a and (c + a) > b:
                    s += 1
print(s)                

Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
#define REP(i, n) for(ll i=0; i<(ll)(n); i++)
#define REPD(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

vector<vector<ll>> g;
vector<ll> sign;
int n, m;
// void dfs(int v, int c=1){
//     sign[v] = c;
//     for(auto x: g[v]){
//         if(0<sign[x]  && sign[x]<v+1) continue;
//         dfs(x, v+1);
//     }
// }
int main(){
    cin >> n >> m;
    g.resize(n); sign.resize(n, -1);

    REP(i, m){
        int x, y;   cin >> x >> y;
        x--; y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    //dfs(0);
    queue<int> que;
    que.push(0);

    while(!que.empty()){
        int v = que.front(); que.pop();
        for(auto x: g[v]){
            if(0<sign[x]) continue;
            sign[x] = v+1;
            que.push(x);
        }
    }
    FOR(i, 1, n){
        if(sign[i]<0){
            cout << "No" << endl;
            return 0;
        } 
    }
    cout << "Yes" << endl;
    FOR(i, 1, n) cout << sign[i] << endl;

    
}

Measured memory_bytes: 12680
"""

AtCoder Beginner Contest 144  E - Gluttony


愚直解
・修行の順序は結果に影響しないから、修行を誰に割り振るか：N^K
・メンバーN人をどの問題に当てるか（N人の並べ方）：N!
-> N^K * N! 
間に合わない。

完食にかかる時間のうち最大値がチーム全体の成績なので、
・消化コストAiを修行で下げる
・消化コストAiの大きい人に、食べにくさFiの小さい食べ物を割り当てる
のが良さそう

最大値の最小化、なので、二分探索が使えそうな気もする。

A,F <= 10^6
かかる時間を X 以下にできるか、を考える。
・消化コストが大きい人に、食べにくさが小さい問題を当てるようにする
・Ai * Fi > Xであれば、(Ai - m) * Fi <= X となるような最小のmをカウントする
全メンバーに対しこれを数え上げた時に、
mの合計 > K
であれば、X以下になるように修行することができない（K回までしか修行できず、回数が足りない）ので、最大値の最小はXより上
mの合計 <= K
であれば、X以下になるように修行できるので、最大値の最小はX以下

A*F <= 10^12 までなので、40~50程度繰り返せば行けそう
"""
import math

N,K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))

if K >= sum(A):
    print(0)
    exit()

A.sort(reverse=True)
F.sort()

def is_ok(mid):
    cnt = 0
    for i in range(N):
        if A[i] * F[i] <= mid:
            continue
        else:
            cnt += math.ceil((A[i] * F[i] - mid) / F[i]) # A[i]が1減少するごとにF[i]減るのでF[i]で割る  
    
    return cnt <= K

# okは全員がX以下になる最小値に着地するので、A*F<=10**12 なので＋１して最大のケースにも対応する
ok = 10**12 + 1
# 0ではないことが上で保証されてるので、条件を満たさない最大値の0にしておく
ng = 0
while ok - ng > 1:
    
    mid = (ok + ng) // 2
    #print(ok,ng,mid)
    if is_ok(mid):
        ok = mid
    else:
        ng = mid

#print(ok,ng,mid)
print(ok)

Measured memory_bytes: 119628
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <string>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

long long dist(long long a, long long b) {
	return a * a + b * b;
}

int main() {

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

	int n, d;
	cin >> n >> d;

	int points = 0;
	int a, b;
	for (int i = 0; i < n; ++i) {
		cin >> a >> b;
		if ((long long) d * d >= dist(a, b)) {
			++points;
		}
	}

	cout << points << "\n";

	return 0;

}

Measured memory_bytes: 3652
import java.util.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] s = new int[32];
        int cnt = -1;
        if(n == 0) System.out.println(0);
        while(n != 0){
            s[++cnt] = Math.abs(n) % 2;
            n = (n - s[cnt]) / (-2);
        }
        for(int i = cnt; i >= 0; i--){
            System.out.print(s[i]);
        }
    }
}



Measured memory_bytes: 23124
N = int(input())
mod = 10 ** 9 + 7
keep = [0 for i in range(N + 1)]


def warizan(i, j, remind):
    cnt = 0
    while i % j == 0:
        i = i // j
        cnt += 1
    return cnt + remind, i


for i in range(1, N + 1):
    for j in range(2, N + 1):
        if i % j == 0:
            keep[j], i = warizan(i, j, keep[j])

ans = 1
for i in keep:
    ans = ans * (i + 1) % mod

print(ans)


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


const long long mod = 998244353;

//mod mでの a の逆元を求める
long long modinv(long long a) {
    long long b = mod, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= mod; 
    if (u < 0) u += mod;
    return u;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    
    ll n,k,a;
    cin>>n>>k>>a;
    a *= modinv(100);
    a%=mod;
    ll inv = modinv(n);
    
    ll dp[k+n]={};
    dp[0]=1;
    ll p[k+n]={};
    p[0]=1;
    for(int i=0;i<k-1;i++){
        dp[i+1] = inv*dp[i], dp[i+1] %= mod;
        dp[i+1] *= a, dp[i+1] %= mod;
        p[i+1] = dp[i+1];
        dp[i+1] += dp[i];
        dp[i+1] %= mod;
        if(i+1>=n){
            dp[i+1] += mod - p[i+1-n];
            dp[i+1] %= mod;
        }
    }
    for(int i=k;i<k+n;i++){
        dp[i] = inv*dp[k-1];
        dp[i] %= mod;
        if(i-n>=0){
            dp[k-1] += mod - p[i-n];
            dp[k-1] %= mod;
        }
    }
    ll ans = 0;
    for(int i=0;i<n;i++){
        ans += dp[k+i];
        ans %= mod;
    }
    cout << ans << endl;
    //cout << dp[n+k-1] << endl;
    
    
}


Measured memory_bytes: 6260
N, K = map(int ,input().split())
x = list(map(int, input().split()))
xp = [0]+[xi for xi in x if xi>=0]
size_p = len(xp)-1
xn = [-xi for xi in x if xi<0] + [0]
xn.reverse()
size_n = len(xn)-1

# print('xp',xp)
# print('xn',xn)

min_t = float('inf')
for p in range(K+1):
	n = K-p
	if p>size_p or n>size_n:
		continue
	
	tmp = xp[p]+xn[n]+min(xp[p],xn[n])
	# print('p, size_p, n, size_n',p, size_p, n, size_n)
	# print('xp[p], xn[n]',xp[p], xn[n])
	# print('tmp:',tmp)
	if min_t > tmp:
		min_t = tmp

print(min_t)
	



Measured memory_bytes: 14384
int main(void){
  int n, a, i, s, c = 1;
  
  scanf("%d",&n);
  scanf("%d",&s);
  if(s == 1){
    printf("1");
    return 0;
  }
  
  for(i=0; i<n-1; i++){
    scanf("%d",&a);
    if(a < s){
      s = a;
      c ++;
    }
  }
   
  printf("%d",c);
  return 0;
}
  
               

Measured memory_bytes: 128
num=[int(i) for i in input().split(" ")]
a=sorted([int(i) for i in input().split(" ")],reverse=True)
b=sorted([int(i) for i in input().split(" ")],reverse=True)
a.append(0)
b.append(0)
n=num[0]
m=num[1]
k=n*m
i_a=0
i_b=0
counter=1
kuhaku=0
#print(a)
#print(b)
while k>0 and counter!=0:
    counter=counter%(10**9+7)
#    print(counter,end=" ")
#    print(kuhaku,end=" ")
#    print(k,end=" ")
#    print(i_a,end=" ")
#    print(i_b)
    if k<a[i_a] and k<b[i_b]:
        counter=0
        break
    if k>a[i_a] and  k>b[i_b]:
        counter=counter*kuhaku
        k-=1
        kuhaku-=1
    elif a[i_a]==b[i_b]:
        kuhaku+=i_a+i_b
        i_a+=1
        i_b+=1
        k-=1
    elif a[i_a]==k:
        counter=counter*i_b
        kuhaku+=(i_b-1)
        i_a+=1
        k-=1
    elif b[i_b]==k:
        counter=counter*i_a
        kuhaku+=(i_a-1)
        i_b+=1
        k-=1
print(counter)
        
        

Measured memory_bytes: 3188
package main

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

////////////////////////////////////////
///        templates                 ///
////////////////////////////////////////

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readBigLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func strSprit(str string) []string {
	cols := strings.Split(str, " ")
	return cols
}

func parseInt(str string) int {
	n, _ := strconv.Atoi(str)
	return n
}

func intSprit(str string) []int {
	strs := strSprit(str)
	cols := make([]int, len(strs))
	for i, v := range strs {
		cols[i] = parseInt(v)
	}
	return cols
}

////////////////////////////////////////
///        end templates             ///
////////////////////////////////////////

func calcs(m map[int]int) (c, max, mn int) {
	c, max, mn = 0, 0, 0
	for k, v := range m {
		if max < v {
			max = v
			mn = k
		}
		c += v
	}
	return c, max, mn
}

func main() {
	line := readBigLine()

	N := parseInt(line)

	ll := readBigLine()
	v := intSprit(ll)

	oddm := make(map[int]int, N)
	evem := make(map[int]int, N)

	for i := 0; i < N; i++ {
		if i%2 == 0 {
			if _, ok := evem[v[i]]; !ok {
				evem[v[i]] = 1
			} else {
				evem[v[i]]++
			}

		} else {
			if _, ok := oddm[v[i]]; !ok {
				oddm[v[i]] = 1
			} else {
				oddm[v[i]]++
			}
		}
	}

	ec, emax, emn := calcs(evem)

	oc, omax, omn := calcs(oddm)

	if emn == omn {
		if ec == emax && oc == omax {
			fmt.Println(N / 2)
			return
		}
		if emax > omax {
			t := omax
			oddm[omn] = 0
			oc, omax, omn = calcs(oddm)
			fmt.Println(ec - emax + oc - omax + t)
			return
		} else if emax < omax {
			t := emax
			evem[emn] = 0
			ec, emax, emn = calcs(evem)
			fmt.Println(ec - emax + oc - omax + t)
			return
		} else {
			t := emax
			evem[emn] = 0
			ec, emax, emn = calcs(evem)
			oddm[omn] = 0
			oc, omax, omn = calcs(oddm)

			if emax > omax {
				fmt.Println(ec - emax + t + oc)
				return

			} else {
				fmt.Println(ec + oc - omax + t)
				return
			}
		}
	} else {
		fmt.Println(ec - emax + oc - omax)
		return
	}

}


Measured memory_bytes: 10368
#include <iostream>
#include <string>
#include <algorithm>

class Solver {
public:
    void solve();
};


void Solver::solve() {
	std::string s;
	std::cin >> s;

	int count1 = 0;
	int count2 = 0;

	for (int i = 0; i < s.size(); ++i) {
		int num = std::stoi(s.substr(i, 1));
		//check even start
		if (num % 2 == i % 2)
			count1++;
		// check odd start
		if (num % 2 != i % 2)
			count2++;
	}
	std::cout << (count1 < count2 ? count1 : count2) << std::endl;
}

int main() {
    Solver solver = Solver();
    solver.solve();
    return 0;
}

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

#define ll long long
#define mod 1000000007

int main() {
    ll n,k;
    cin>>n>>k;
    ll h[n];
    for(ll i=0;i<n;i++){
        cin>>h[i];
    }
    ll dp[n];
    for(ll i=0;i<n;i++)
        dp[i]=0LL;
    ll ans=INT_MAX;
    for(ll i=1;i<n;i++){
        dp[i]=dp[i-1]+abs(h[i]-h[i-1]);
        for(ll j=1;j<= min(k,i);j++)
        dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
    }
    cout<<dp[n-1]<<endl;
    return 0 ;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;


int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    for(int i=0;i<n;i++){
        cin >> h[i];
    }
    vector<ll> dp(n);
    dp[0] = 0;
    dp[1] = max(h[0]-h[1], h[1]-h[0]);

    for(int i=2;i<n;i++){
        dp[i] = min(dp[i-2]+max(h[i]-h[i-2],h[i-2]-h[i]), dp[i-1]+max(h[i]-h[i-1],h[i-1]-h[i]));
    }

    cout << dp[n-1] << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <cmath>
#include <string>

using namespace std;
int main (){
    int k,n;
    cin >> k >> n;
    int a[n];
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }
    int m=0;
    for (int i = 1; i < n; i++){
        m=max(a[i]-a[i-1],m);
    }
    m=max(k+a[0]-a[n-1],m);
    cout << k-m << "\n";
}

Measured memory_bytes: 1024
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

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

	long long x;
	cin >> x;

	for (long long a = -2000; a * a * a * a * a <= 1e18; ++a) {
		for (long long b = -2000; b * b * b * b * b <= 1e18; ++b) {
			if (a * a * a * a * a - b * b * b * b * b == x) {
				cout << a << " " << b << "\n";
				return 0;
			}
		}
	}

	return 0;

}

Measured memory_bytes: 3556
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int h = s.nextInt(), w = s.nextInt();
		if (h<=w) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}

	}
}


Measured memory_bytes: 21844
#include <stdio.h>

int main(void)
{

	int N;

	scanf("%d", &N);

	if ( N % 2 == 0 ) {
		printf("%d\n", N / 2 );
	} else {
		printf("%d\n", (N / 2) + 1);
	}

	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
static const int64_t mod=1000000007;
int64_t f(int64_t x,int64_t y){
if(y==0)
  return 1;
  else if(y%2==0)
    return (f(x,y/2)*f(x,y/2))%mod;
  else
    return (x*((f(x,y/2)*f(x,y/2))%mod))%mod;
}
int main(){
 int A,B,C,K;cin>>A>>B>>C>>K;
  int64_t sum=0;
  for(int i=0; ;i++){
  if(A<B){sum+=i;break;}
    else
      B*=2;
  } for(int i=0; ;i++){
  if(B<C){sum+=i;break;}
    else
      C*=2;
  }if(sum<=K)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n;
    cin >> n;
    vector<vector<int>> to(n);
    rep(i, n - 1){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    vector<int> p(n, -2);
    p[0] = -1;
    queue<int> que;
    que.push(0);
    while(!que.empty()){
        int v = que.front();
        que.pop();
        for(int t : to[v]){
            if(p[t] != -2)continue;
            p[t] = v;
            que.push(t);
        }
    }
    int dist = 0;
    int v = n - 1;
    while(v != 0){
        v = p[v];
        dist++;
    }
    v = n - 1;
    rep(i, (dist - 1) / 2)v = p[v];
    int sum = 1;
    que.push(v);
    while(!que.empty()){
        int vv = que.front();
        que.pop();
        for(int t : to[vv]){
            if(t == p[vv])continue;
            sum++;
            que.push(t);
        }
    }
    if(sum * 2 < n)cout << "Fennec" << endl;
    else cout << "Snuke" << endl;
    
}

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

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

using ll = long long;

int dp[3100][3100];

int main() {
  string S, T;
  cin >> S >> T;
  int n = S.size();
  int m = T.size();
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (i==0 || j==0) dp[i][j] = 0;
      if (S.at(i) == T.at(j)) dp[i+1][j+1] = max(dp[i][j]+1, max(dp[i][j+1], dp[i+1][j]));
      else {
        dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
      }
    }
  }
  int i = n;
  int j = m;
  string ans;
  while (dp[i][j] != 0) {
    if (dp[i][j] == dp[i-1][j]) {
            --i; // DP の遷移を遡る
        }

        // (i, j-1) -> (i, j) と更新されていた場合
        else if (dp[i][j] == dp[i][j-1]) {
            --j; // DP の遷移を遡る
        }

        // (i-1, j-1) -> (i, j) と更新されていた場合
        else {
            ans = S[i-1] + ans; // このとき s[i-1] == t[j-1] なので、t[j-1] + res でも OK
            --i, --j; // DP の遷移を遡る
        }
  }
  cout << ans << endl;
}

Measured memory_bytes: 37120
import math
def main():
    N,H = map(int, input().split())
    a = [None] * N
    b = [None] * N
    for i in range(N):
        a[i], b[i] = map(int, input().split())
    
    a.sort(reverse=True)
    b.sort(reverse=True)

    m = N
    for i in range(N):
        if b[i] > a[0]:
            continue
        else:
            m = i
            break
    
    for i in range(m):
        H -= b[i]
        if H <= 0:
            print(i+1)
            exit()
    
    print(math.ceil(H / a[0]) + m)


if __name__ == "__main__":
    main()


Measured memory_bytes: 11312
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {
	public static void main(String[] args) {
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
		ArrayList<Integer> inputList = new ArrayList<>(30);

		try {
			while (input.ready()) {
				inputList.add(Integer.valueOf(input.readLine()));
			}
		} catch (IOException e) {
			e.printStackTrace();
		}

		int maxNum = 0;
		for (int num : inputList) {
			if (maxNum < num)
				maxNum = num;
		}

		ArrayList<Integer> primeNumberList = getPrimeNumberList(maxNum);

		for (int num : inputList) {
			int primeNumberCount = 0;
			for (int i = 0; i < primeNumberList.size(); i++) {
				if (num >= primeNumberList.get(i)) {
					primeNumberCount++;
				} else {
					break;
				}
			}
			System.out.println(primeNumberCount);
		}
	}

	public static ArrayList<Integer> getPrimeNumberList(int maxNumber) {
		ArrayList<Integer> primeNumberList = new ArrayList<>();
		primeNumberList.add(2);
		primeNumberList.add(3);
		primeNumberList.add(5);
		primeNumberList.add(7);

		int[] oneDigitList = {1,3,7,9};

		int tmp;
		int sqrtTmp;
		boolean addFlag;
		for (int i = 10; i <= maxNumber; i += 10) {
			for (int oneDigit : oneDigitList) {
				addFlag = true;
				tmp = i + oneDigit;
				sqrtTmp = (int) Math.sqrt(tmp);
				for (int primeNumber : primeNumberList) {
					if (tmp % primeNumber == 0) {
						addFlag = false;
						break;
					}
					if ( sqrtTmp < primeNumber) {
						break;
					}
				}
				if (addFlag) {
					primeNumberList.add(tmp);
				}
			}
		}
		return primeNumberList;
	}
}

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


int main() {

	int H, A, ans;
	cin >> H >> A;
	ans = 0;
	ans += H / A;
	if((H % A) != 0){
		ans += 1;
	}
	cout << ans;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e2 + 5;
int n;
char a[maxn], b[maxn], c[maxn];
int main() {
    scanf("%d %s %s %s",&n,a+1,b+1,c+1);
    int ans = 0;
    for(int i=1;i<=n;i++) {
        if(a[i]!=b[i] || a[i]!=c[i] || b[i]!=c[i]) {
            if(a[i]==b[i] || a[i]==c[i] || b[i]==c[i]) ans += 1;
            else ans += 2;
        }
    }
    printf("%d",ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

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

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;


void	solve()
{
	int n; ll k;
	vector<int>	visited;

	cin >> n >> k;
	vector<int>	path(n), idx(n + 1, -1);
	rep(i, n) cin >> path[i];

	for (int i = 0, p = path[0]; k; i++) {
		k--;
		if (idx[p] != -1) {
			int d = visited.size() - idx[p];
			int next_i = k % d;
			cout << visited[idx[p] + next_i] << endl;
			break;
		} else if (k == 0){
			cout << p << endl;
		}
		visited.push_back(p);
		idx[p] = i;
		p = path[p - 1];
	}
}

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

	solve();
}

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

//Math/ModInt
template<long long mod = 1000000007>
struct modint{
	long long a;

	modint() : a(0){}
	modint(long long t){
		a = t % mod;
		if(a < 0) a += mod;
	}

	operator long long() const{ return a; }

	bool operator==(const modint &x) const{ return a == x.a; }
	bool operator!=(const modint &x) const{ return a != x.a; }

	modint operator-() const{ return modint(a ? (mod - a) : 0); }
	modint operator~() const{ return pow(mod - 2); }

	modint operator+(const modint &x) const{ return modint(*this) += x; }
	modint operator-(const modint &x) const{ return modint(*this) -= x; }
	modint operator*(const modint &x) const{ return modint(*this) *= x; }
	modint operator/(const modint &x) const{ return modint(*this) /= x; }

	modint &operator+=(const modint &x){
		a += x.a;
		if(a >= mod) a -= mod;
		return *this;
	}
	modint &operator-=(const modint &x){
		a -= x.a;
		if(a < 0) a += mod;
		return *this;
	}
	modint &operator*=(const modint &x){
		a = a * x.a % mod;
		return *this;
	}
	modint &operator/=(const modint &x){
		a = a * (~x).a % mod; 
		return *this;
	}

	modint &operator++(){ return (*this) += 1; }
	modint &operator--(){ return (*this) -= 1; }
	modint &operator++(int){
		modint tmp = *this;
		(*this) += 1;
		return tmp;
	}
	modint &operator--(int){
		modint tmp = *this;
		(*this) -= 1;
		return tmp;
	}

	friend ostream &operator<<(ostream &os,const modint &x){
		return os << x.a;
	}
	friend istream &operator>>(istream &is,modint &x){
		long long t;
		is >> t;
		x = modint(t);
		return is;
	}

	modint pow(long long x) const{
		modint ret = 1,tmp = a;
		for(;x;tmp *= tmp,x >>= 1){
			if(x & 1) ret *= tmp;
		}
		return ret;
	}
};

//Math/Combination
template<class T>
struct Combination{
	vector<T> fact,factinv;
	Combination(int n) : fact(n + 1),factinv(n + 1){
		fact[0] = 1;
		for(int i = 1;i <= n;i++) fact[i] = fact[i - 1] * T(i);
		factinv[n] = ~fact[n];
		for(int i = n;i >= 1;i--) factinv[i - 1] = factinv[i] * T(i);
	}
	T nCr(int n,int r){
		if(r < 0 || n < r) return 0;
		return fact[n] * factinv[r] * factinv[n - r];
	}
};

const int MOD = 1000003;

signed main(){
	int q;
	scanf("%d",&q);
	Combination<modint<MOD>> comb(MOD - 1);
	for(int i = 0;i < q;i++){
		int x,d,n;
		scanf("%d %d %d",&x,&d,&n);
		modint<MOD> mx = x,md = d;
		if(!d) cout << mx.pow(n) << endl;
		else if(n >= MOD) cout << 0 << endl;
		else cout << comb.fact[n] * comb.nCr(-mx / md,n) * (-md).pow(n) << endl;
	}
}


Measured memory_bytes: 16512
# -*- coding: utf-8 -*-
from sys import stdin

s_in = lambda: stdin.readline()[:-1] # s = s_in()
d_in = lambda: int(stdin.readline()) # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split())) # List = ds_in()

H, W, D = ds_in()
A_arr = []
for i in range(H):
    A = ds_in()
    for j, a in enumerate(A):
        A_arr.append((a, [i, j]))

A_arr.sort(key=lambda x: x[0])

Q = d_in()
LR_list = []
for _ in range(Q):
    LR_list.append(ds_in())

Costs = [0] * (H*W)
for i in range(1, D+1):
    s = i
    s_xy = A_arr[s-1][1]
    cost, next_cost = 0, 0
    Costs[s-1] = cost
    s += D
    while s <= H * W:
        xy = A_arr[s-1][1]
        next_cost = abs(xy[0] - s_xy[0]) + abs(xy[1] - s_xy[1])
        cost += next_cost
        Costs[s-1] = cost
        s_xy = xy.copy()
        s += D

for q in LR_list:
    print(Costs[q[1] - 1] - Costs[q[0] - 1])


Measured memory_bytes: 49952
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 1LL << 61;
const ll mod = 1000000007LL;
//const ll mod = 998244353LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,0,-1,0,1,1,-1,-1 }, dy[9] = { 0,0,1,0,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222





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


  cin >> n >> m;
  if (m == 1) {
    cout << "0" << endl;
    return 0;
  }
  n -= m;
  cout << n << endl;




  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int a = sc.nextInt();
		if(x<a){
			System.out.println(0);
		}else{
			System.out.println(10);
		}
	}
}


Measured memory_bytes: 23636
from sys import stdin
count = [0 for x in range(26)]

for line in stdin:
    word = line.lower()
    for i in range(len(word)):
        if word[i].isalpha():
            count[ord(word[i])-ord("a")] += 1

for i in range(26):
    print(chr(i +ord("a")),end="")
    print(" : ",end="")
    print(count[i])
    
        


Measured memory_bytes: 5576
//ABC101-B
#include <stdio.h>

int S(int N){
	if(N == 0){
		return 0;
	}
	else{
		return N % 10 + S(N / 10);
	}
}

int main(){
	int N;
	scanf("%d", &N);
	if(N % S(N) == 0){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}


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

const int N=2e5+20;

int n,a[N],u,v,ans[N];
vector <int> adj[N];
multiset <int> s;

void dfs(int node,int parent=0)
{
	s.insert(a[node]);
	int del=-1;
	auto it=s.lower_bound(a[node]);
	if(++it!=s.end()) del=*it,s.erase(it);
	ans[node]=s.size();
	
	for(auto child:adj[node])
		if(child!=parent) dfs(child,node);
	
	if(del!=-1) s.insert(del);
	s.erase(s.find(a[node]));
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=0;i<n-1;i++)
	{
		scanf("%d%d",&u,&v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

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

Measured memory_bytes: 33520
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>

/*
#include<boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/rational.hpp>
namespace mp = boost::multiprecision;
using Real = mp::number<mp::cpp_dec_float<1024>>;
using Bint = mp::cpp_int;
*/

using namespace std;

#define int long long
#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)
#define FOR(i,n) for((i)=(0);(i)<(n);(i)++)
#define RFOR(i,n) for((i)=((n)-1);(i)>=(0);(i)--)
#define MOD 1000000007


signed main(){
    int A,B;
    cin>>A>>B;
    if(A>=10||B>=10) cout<<"-1"<<endl;
    else cout<<A*B<<endl;
}


Measured memory_bytes: 3640
// inputに入力データ全体が入る
  function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
  input = input.split("\n");
	tmp = input[0].split(" ");
  var N = Number(tmp[0]);
  var X = Number(tmp[1]);
  var Y = Number(tmp[2]);
	//文字列から10進数に変換するときはparseIntを使います
  var ans = [];
  for(i = 0; i<N-1; i++){
    ans[i] = 0;
  }

  for(i=1; i<=N-1; i++){
    for (var j = i+1; j <= N; j++) {
      // i in A, j in A ok
      if(1 <= i && i <= X && 1 <= j && j <= X){
        dis = j-i;
      }
      // i in A, j in B ok
      if(1 <= i && i <= X && X < j && j < Y){
        dis = X-i;

        rootA = j-X;
        rootB = Y-j+1;
        if(rootA < rootB) dis += rootA;
        else dis += rootB;
      }
      // i in A, j in C ok
      if(1 <= i && i <= X && Y <= j){
        dis = X-i + 1 + j-Y;
      }
      // i in B, j in B
      if(X < i && i < Y && X < j && j < Y){
        dis = 0;
        rootA = j-i;
        rootB = i-X + 1 + Y-j;
        if(rootA < rootB) dis += rootA;
        else dis += rootB;
      }
      // i in B, j in C ok
      if(X < i && i < Y && Y <= j){
        dis = j-Y;

        rootA = i-X+1;
        rootB = Y-i;
        if(rootA < rootB) dis += rootA;
        else dis += rootB;
      }
      // i in C, j in C ok
      if(Y <= i && Y <= j){
        dis = j-i;
      }
      ans[dis-1]++;
    }
  }

  ans = ans.join("\n");
	//出力
	console.log('%s', ans);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7884
#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<cmath>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<stack>
#include<sstream>
#include<string>
#include<cassert>
#include<ctime>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
 
int a[200005];
ll b[200005];
ll c[200005];
 
int main() {
	int N;
	scanf("%d", &N);
	memset(a, 0, sizeof(a));
	memset(b, 0, sizeof(b));
	memset(c, 0, sizeof(c));
	for (int i = 0;i < N;i++)scanf("%d", a + i);
	b[0] = a[0];
	for (int i = 1;i < N-1 ;i++) {
		b[i] = b[i - 1] + a[i];
	}
	c[N - 2] = a[N - 1];
	for (int i = N - 3;i >= 0;i--) {
		c[i] = a[i + 1] + c[i + 1];
	}
 
	ll m = 1e18;
	for (int i = 0;i < N - 1;i++) {
		if (b[i] > c[i]) {
			if (m > (b[i] - c[i]))m = b[i] - c[i];
 
		}
		else {
			if (m > (c[i] - b[i]))m = c[i] - b[i];
 
		}
	}
 
	printf("%lld", m);
	return 0;
}

Measured memory_bytes: 4096
using System;
using System.Linq;
using System.Diagnostics;
using System.Collections.Generic;
class P
{
    static void Main()
    {
        string a = Console.ReadLine().PadLeft(110,'0');
        string b = Console.ReadLine().PadLeft(110, '0');
        for (int i = 0; i < a.Length; i++)
        {
            if (a[i] < b[i])
            {
                Console.WriteLine("LESS");
                return;
            }
            else if(a[i] > b[i])
            {
                Console.WriteLine("GREATER");
                return;
            }
        }
        Console.WriteLine("EQUAL");
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define INF (ll)(1e18)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }








int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    /*
    int n;
    cin >> n;
    vector<int> v(n);
    rep(i, n) cin >> v[i];
    */
    
    
    string s[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    string t;
    cin >> t;
    if (t == "SUN") cout << 7 << endl;
    else {
        rep(i, 7) {
            if (t == s[i]) {
                cout << 7 - i << endl;
            }
        }
    }
    
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include<iomanip>
using namespace std;

int main()
{
    int N;
    cin>>N;
    int A[N];
    double sum;
    for(int i =0;i<N;i++)
    {
        cin>>A[i];
    }

    for(int i = 0;i<N;i++)
    {
        sum += (double)1.0/A[i];
    }
    
    cout<<setprecision(20)<<(double)1.0/sum<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner std = new Scanner(System.in);
		int ans = 0;
		String search = std.next().toLowerCase();
		while(std.hasNext()){
			String word = std.next().toLowerCase();
			if(word.equals("END_OF_TEXT")){
				break;
			}else if(word.equals(search)){
				ans++;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 26304
S = list(input())
a=[int(x) for x in S] #int型のリストに変換
a.reverse()
#print(a)
l=[0]*2019
l[0]=1
T=0
d=1

for i in a:
    T+=(int(i)*d)
    T%=2019
    l[T]+=1
    d*=10
    d%=2019
result=0
for n in l:
    result+=n*(n-1)/2
print(int(result))

Measured memory_bytes: 12348
#include<bits/stdc++.h>
using namespace std;
int k,s,ans;
int main()
{
	scanf("%d%d",&k,&s);
	for(int i=0;i<=k;i++)
	{
		for(int j=0;j<=k;j++)
		{
			if(s-i-j>=0&&s-i-j<=k)
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
N = gets.to_i
seqence = gets.chomp.split().map { |e| e.to_i }

puts seqence.join(" ")
for i in 1..(N-1)
  key = seqence[i]
  j = i - 1

  while j >= 0 && seqence[j] > key
    seqence[j+1] = seqence[j]
    j -= 1
  end
  seqence[j+1] = key
  puts seqence.join(" ")
end

Measured memory_bytes: 6112
n = int(input())
ls = [n]
m = 0

for i in range(1, 1000001):
    if int(n%2) == 0:
        n = int(n/2)
    else:
        n = 3*n+1

    if n in ls:
        m = i+1  # 答えは次のインデックス
        break
    ls.append(n)

print(m)

Measured memory_bytes: 2940
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int N, L[10];
  cin >> N;
  for(int i=0; i<N; i++){
    cin >> L[i];
  }
  sort(L, L+N);
  int sum = 0;
  for(int i=0; i<N-1; i++){
    sum += L[i];
  }
  if(L[N-1] < sum) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

dp = [[None]*3 for n in range(N+1)]
dp[0] = [0, 0, 0]

for n in range(1, N+1):
    act = list(map(int, input().split()))
    dp[n][0] = max(dp[n-1][1], dp[n-1][2]) + act[0]
    dp[n][1] = max(dp[n-1][2], dp[n-1][0]) + act[1]
    dp[n][2] = max(dp[n-1][0], dp[n-1][1]) + act[2]

print(max(dp[N]))


Measured memory_bytes: 64492
readline()
nums = readline().chomp().split().map{|i| i.to_i }
thr = 10**18

if nums.any? {|i| i == 0}
    puts(0)
    exit(0)
end

total = nums.inject(1) do |r, i| 
    retVal =  r * i
    if retVal > thr
        puts(-1)
        exit(0)
    end
    retVal
end

puts(total)


Measured memory_bytes: 23436
/////////////////////////////////TEST CASES////////////////////////////////////
/*

*/
/////////////////////////////////////CODE/////////////////////////////////////
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = a ; i > b ; i--)
#define fastio ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define PI 3.14159265
typedef long long ll;
#define VL vector<ll> 
#define IN(inp) ll inp;cin>>inp;
#define pb push_back
#define all(a) a.begin(),a.end()
#define what(A) cout<<#A<<" is "<<A<<endl;
ll MAX = 1000000000;
ll MOD = 1000000007;
int main()
{
	fastio
	//freopen("input.txt", "rt", stdin);
	//freopen("output.txt", "wt", stdout);
	ll test = 1;
	//cin>>test;
	while (test--)
	{
		IN(n);
        if(n>=30)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
	}
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
    using namespace std;
     
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
     
        int a, b; cin >> a >> b;
        cout << max({a + a - 1, b + b - 1, a + b}) << '\n';
    }

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

int main()
{
	char alpha_A[26] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'I', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
	char alpha_a[26] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
	int alpha_count[26] = {};
	char ch;
	
	while (cin >> ch)
	{
		if ('A' <= ch && ch <= 'z')
		{
			for (int i = 0; i < 26; i++)
			{
				if (ch == alpha_A[i] || ch == alpha_a[i])
				{
					alpha_count[i]++;
					break;
				}
			}
		}
	}

	for (int i = 0; i < 26; i++){
		cout << alpha_a[i] << " : " << alpha_count[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 3056
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define sf scanf
#define pf printf
#define pb push_back
#define llu unsigned long long
#define U unsigned int
#define SIZE 1000002
#define pie 3.14159265358979323
#define minuss 1e-6
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
ll  lcm(ll a,ll b)
{
    ll GCD=__gcd(a,b);
    ll lcm=(a*b)/GCD;
    return lcm;
}
ll dp[109][100005];
ll weight[10000],value[10000];
ll total,val;
ll call(ll n,ll c)
{
    if(n==total)
        return 0;
    if(dp[n][c]!=-1)
        return dp[n][c];

    ll res1=0,res2=0;

    if(weight[n]+c<=val)
        res1=value[n]+call(n+1,c+weight[n]);


    res2=call(n+1,c);
    dp[n][c]=max(res1,res2);
    return dp[n][c];

}
int main()
{
    cin>>total>>val;
    for ( int i = 0; i <total; ++i )
        cin>>weight[i]>>value[i];

    memset(dp, -1, sizeof(dp));
    ll ret=call(0,0);
    cout<<ret<<endl;
    return 0;
}

/*


6 15
6 5
5 6
6 4
6 6
3 5
7 2

*/


Measured memory_bytes: 85376
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <tuple>

#define DEBUG(x) cout<<#x<<": "<<x<<endl

using namespace std;

int main(){

	int X, Y, Z, K;

	cin >> X >> Y >> Z >> K;

	long long A[X], B[Y], C[Z];

	for(int i = 0; i < X; i++)
		cin >> A[i];
	for(int j = 0; j < Y; j++)
		cin >> B[j];
	for(int k = 0; k < Z; k++)
		cin >> C[k];

	sort(A, A+X, greater<long long>());
	sort(B, B+Y, greater<long long>());
	sort(C, C+Z, greater<long long>());

	priority_queue<tuple<long long, int, int, int>> pq;
	pq.push(make_tuple(A[0]+B[0]+C[0], 0, 0, 0));
	
	set<long long> s;
	s.insert(0);
	
	vector<long long> ans;

	while(ans.size() < K){
		auto v = pq.top(); pq.pop();
		ans.push_back(get<0>(v));
		for(int i = 0; i < 3; i++){
			int a = get<1>(v);
			int b = get<2>(v);
			int c = get<3>(v);
			switch(i){
				case 0: a++; break;
				case 1: b++; break;
				case 2: c++; break;
			}
			if(a >= X || b >= Y || c >= Z) continue;
			long long hash = a * 1000'000 + b * 1000 + c;
			if(s.find(hash) == s.end()){
				s.insert(hash);
				pq.push(make_tuple(A[a]+B[b]+C[c], a, b, c));
			}
		}
	}

	for(int i = 0; i < ans.size(); i++){
		cout << ans[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <cmath>

using namespace std;

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

  int k = (sqrt(8 * n + 1) + 1) / 2;
  for (--k; k * (k - 1) < 2 * n; ++k)
    ;
  if (k * (k - 1) != 2 * n) {
    cout << "No\n";
    return 0;
  }
  cout << "Yes\n";
  cout << k << '\n';
  long long m = 0;
  for (int i = 0; i < k; ++i) {
    cout << k - 1;
    long long l = i;
    for (int j = 0; j < i; ++j) {
      cout << ' ' << l;
      l += k - j - 2;
    }
    for (int j = i + 1; j < k; ++j) {
      cout << ' ' << ++m;
    }
    cout << "\n";
  };
  
  return 0;
}


Measured memory_bytes: 1408
n, m = map(int, input().split())
h = list(map(int, input().split()))
path = list(list(map(int, input().split())) for _ in range(m))

table = [1]*n

for i in range(m):
    p = path[i]
    if h[p[0]-1] <= h[p[1]-1]:
        table[p[0]-1] = 0
    if h[p[0]-1] >= h[p[1]-1]:
        table[p[1]-1] = 0

        
cnt = 0
for i in table:
    if i == 1:
        cnt += 1
        
print(cnt)

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

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

ll INF=1LL << 60;
signed main() {
    ll H,W,D;
    cin>>H>>W>>D;
    map<ll, PLL> m; // num -> {y,x}
    rep(y,1,H+1)
        rep(x,1,W+1){
            ll n;
            cin>>n;
            m[n] = PLL(y,x);
        }
    ll dist[H*W+1]; // dist[i]: 値iまで到達するためのコスト
    rep(i,1,H*W+1) dist[i]=INF;
    rep(i,1,D+1){
        dist[i]=0;
    }
    rep(i,D+1,H*W+1){
        dist[i] = dist[i-D] + abs(m[i].first - m[i-D].first) + abs(m[i].second - m[i-D].second);
    }
    ll Q;
    cin>>Q;
    rep(k,0,Q){
        ll L,R;
        cin>>L>>R;
        cout<<dist[R]-dist[L]<<endl;
    }
    return 0;
}


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

using namespace std;

int main()
{
  string S;
  cin >> S;
  while(true) {
    S.pop_back();
    if(S.length() % 2 == 0 && S.find(S.substr(S.length() / 2)) == 0) {
      cout << S.length() << endl;
      return (0);
    }
  }
}

Measured memory_bytes: 256
using namespace std;

#include <bits/stdc++.h>

int main(){
    int N, M;
    cin >> N >> M;
    int my_lower_bound = 1;
    int my_upper_bound = N;
    for ( int i = 0; i < M; i ++ ){
        int L, R;
        cin >> L >> R;
        if ( L > my_lower_bound ) my_lower_bound = L;
        if ( R < my_upper_bound ) my_upper_bound = R;
    }
    if ( my_upper_bound >= my_lower_bound ) cout << my_upper_bound - my_lower_bound + 1;
    else cout << 0;
    return 0;
}


Measured memory_bytes: 256
k, n = map(int, input().split())
a = list(map(int, input().split()))

m = 10 ** 12
for i in range(1,len(a)-1):
    r = k - abs(a[i] - a[i-1])
    l = k - abs(a[i] - a[i+1])
    if min(r,l) <= m:
        m = min(r,l)

r = abs(a[-1] - a[0])
l = k - abs(a[1] - a[0])
if min(r,l) <= m:
    m = min(r,l)

r = k - abs(a[-1] - a[-2])
l = abs(a[-1] - a[0])
if min(r,l) <= m:
    m = min(r,l)
    
print(m)


Measured memory_bytes: 26420