akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <bitset>
#include <set>
#include <complex>
#include <cmath>
#include <cstring>
#include <map>
using namespace std;
using ll = long long;
using ppp = pair<pair<int, int>, pair<int, int>>;
#define MOD 1000000007
#define INF 1LL << 59
const int MAX = 510000;
const long long mod = 917120411LL;

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 sieve[1000010];
void make_sieve()
{
    for (int i = 0; i < 1000010; ++i)
        sieve[i] = true;
    sieve[0] = sieve[1] = false;
    for (int i = 0; i * i < 1000010; ++i)
    {
        if (sieve[i])
        {
            for (int j = 2; j * i < 1000010; ++j)
            {
                sieve[i * j] = false;
            }
        }
    }
}

int GCD(ll a, ll b)
{
    if (a < b)
        swap(a, b);
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}

int A[100010];
int rd[100010], ld[100010];
int main()
{
    int N;
    cin >> N;
    for (int i = 0; i < N; ++i)
    {
        cin >> A[i];
    }

    rd[1] = A[0];
    ld[1] = A[N - 1];

    for (int i = 1; i < N; ++i)
    {
        rd[i + 1] = GCD(rd[i], A[i]);
        ld[i + 1] = GCD(ld[i], A[N - i - 1]);
    }

    int ans = 0;
    for (int i = 0; i <= N - 1; ++i)
    {
        ans = max(ans, GCD(rd[i], ld[N - i - 1]));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1408
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <string>

using namespace std;

int main() {

	set<int> s;
	s.insert(6);
	int d = 6;
	for (int i = 0; d <= 300000; i++) {
		if (i % 2 == 0) d += 2;
		else d += 5;
		s.insert(d);
	}
	//cout << "Finish!" << endl;

	while (1) {
		int n;
		cin >> n;
		if (n==1) break;

		vector<int> v;
		
		d = 6;
		bool flag = false;
		for (int i = 0; d <= n; i++) {
			//cout << "i : " <<i<<" d : "<<d<<endl;
			if (flag) {
				if (i % 2 != 0) d += 2;
				else d += 5;
			}
			flag = true;

			if (n%d == 0 && (s.find(n/d)!=s.end() || n/d == 1)) {
				bool t = true;

				for (int k = 2; k*k <= d; k++) {
					if (d%k == 0 && (k % 7 == 1 || k % 7 == 6)) {
						t = false;
						break;	
					}
				}

				/*
				for (set<int>::iterator it = s.begin(); it != s.end(); it++) {
					if (d%*it == 0 && *it < d) {
						t = false;
						break;
					}
				}
				*/

				if(t) v.push_back(d);
			}
		}

		cout << n<<":";
		for (int i = 0; i < v.size(); i++) cout << " " << v[i];
		cout << endl;

	}


	return 0;
}

Measured memory_bytes: 7084
K,A,B = map(int,input().split(' '))

ans = 0
if B <= A + 2:
	ans = 1+K
else:
	if K <= A:
		ans = 1 + K
	else:
		K -= A-1
		if K % 2 == 1:
			ans += 1
			K -= 1
		N = K//2
		ans += A+(B-A)*N

print(ans)




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

int main() {
  int test;
  cin >> test;
  
  string content;
  cin >> content;

  int len = content.length();

  if(len > test){
    content = content.substr(0, test) + "...";
  }

  cout << content << endl;
}


Measured memory_bytes: 3640
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll ans = min(a, b) + min(c, d);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a,b,c,d=0,e,f,g;
  cin >>a>>b;
  c=b/2;
  d=min(a,c),a-=d,b-=d*2;
  d+=b/4;
  cout <<d<<'\n';
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from sys import stdin
import numpy as np

ns = lambda: stdin.readline()[:-1] # s = ns()
ni = lambda: int(stdin.readline()) # N = ni()
na = lambda: list(map(int, stdin.readline().split())) # Arr = na()

def factorize(x):
    fct = []
    fct2 = []
    if x == 1:
        fct.append(1)
        return fct
    b = 1
    while b * b <= x:
        if x%b == 0:
            fct.append(b)
            fct2.append(x//b)
        b += 1
    fct.extend(fct2[::-1])
    return fct

N, X = na()
xarr = np.array(na())

diff = np.abs(xarr - X)
min_d = diff.min()

fac = factorize(min_d)

for x in fac[::-1]:
    flag = 1
    for d in diff:
        if d % x != 0:
            flag = 0
            break
    if flag == 1:
        print(x)
        exit()
    


Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
int main()
{
    map<string,int> m;
    string t;
    int n;
    cin >> n;
    for(int i = 0;i < n;++i){
        cin >> t;
        if(m.count(t))
        {
            m[t]++;
        }
        else
        {
            m.insert(make_pair(t,1));
        }
    }
    int e;
    cin >> e;
    for(int i = 0;i < e;++i)
    {
        cin >> t;
        if(m.count(t))
        {
            m[t]--;
        }
        else
        {
            m.insert(make_pair(t,0));
        }
    }
    int sum = 0;
    for(auto i : m)
    {
        if(i.second > sum)
        {
            sum = i.second;
        }
            
    }
    cout << sum << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.logging.Logger;

public class Main {
	public static void main(String[] args) {
		printAnswer();
	}

	private static void printAnswer() {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Logger logger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
		try {
			String sentence = br.readLine().toUpperCase();
			System.out.println(sentence);
		} catch (IOException e) {
			e.printStackTrace();
			logger.info("An exception occurs.");
		}
	}
}

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

#define _GLIBCXX_DEBUG

//vector<int> A(M), B(M);
//vector<vector<char>> answer(N, vector<char>(N, '-'));

int main() {
  string s, t;
  int ans = 0;
  
  cin >> s >> t;
  
  if(s[0] == t[0]) ans++;
  if(s[1] == t[1]) ans++;
  if(s[2] == t[2]) ans++;
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3624
#include <iostream>
using namespace std;
int main( void )
{
  ios::sync_with_stdio(false);
  int r, g, b;
  cin >> r >> g >> b;
  if( (r*100 + g*10 + b) % 4 == 0 )
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  long x,y,tmp;
  scanf("%ld %ld",&x,&y);
        if (x<y)
        {
          tmp = x;
          x = y;
          y = tmp;
        };

  while( y > 0)
    {
      tmp = y;
      y = x%y;
      x = tmp;
    }
  printf("%ld\n",x);
  return 0;
}

Measured memory_bytes: 592
#include<bits/stdc++.h> 
#define ll long long 
#define pb push_back 
#define vec vector<int> 
#define fo(i,n) for (int i = 0; i < n; i++)
#define so(v) sort(v.begin(), v.end())
#define fi first
#define se second 
using namespace std;  
int main()
{
  string s;
   
    cin>>s;
  
  
  
       if(s=="RRR")
       {
           cout<<3;
       }
       else if(s=="SSS")
       {
           cout<<0;
       }
       else if(s=="SRR" || s=="RRS")
       {
           cout<<2;
       }
       else {
        cout<<1;
       }
   
   
}

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

int main(void){
    int n,m,c,ans=0;
    cin>>n>>m>>c;
    vector<int> b(m),a(m);
    
    for (int i=0;i<m;i++) cin >> b.at(i);
    for (int j=0;j<n;j++) {
        int buf=0;
        for (int i=0;i<m;i++) {
            cin >> a.at(i);
            buf+=b.at(i)*a.at(i);
        }
        if (buf+c>0) ans++;
    }
    cout << ans <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
using ll = long long;
const ll mod = 1000000007;
const ll INF = 100000000000000000LL;
signed main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<min(a,b)+min(c,d)<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
inline int read(){
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){
        if(c=='-')f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9'){
        x=(x<<3)+(x<<1)+c-'0';
        c=getchar();
    }
    return x*f;
}
int a,b; 
int main(){
	a=read(),b=read();
	if((a+b)&1){
		cout<<"IMPOSSIBLE"<<endl;
	}
	else{
		cout<<(a+b)/2<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
from itertools import accumulate

INF = 10**18

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

S = [0] + list(accumulate(A))

dp = [[INF for j in range(N + 1)] for i in range(N + 1)]

for i in range(N):
    dp[i][i + 1] = 0
    
for k in range(1, N + 1):
    for i in range(0, N - k + 1):
        for j in range(i, i + k + 1):
            dp[i][i + k] = min(dp[i][i + k], dp[i][j] + dp[j][i + k] + S[i + k] - S[i])

print(dp[0][N])

Measured memory_bytes: 75100
use proconio::input;

#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::ops::*;

#[derive(Clone, Debug, Default)]
struct Struct;

//#[proconio::fastout]
fn main() {
    input! {
        x: usize,
    }
    let mut ans = 0;
    let mut money = 100;
    while money < x {
        ans += 1;
        money += money/100;
    }

    println!("{}", ans);
}


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

const int N = 200;
const int S = 100005;
const int mo = 1e9 + 7;

int n, x;
int a[N + 5];
int f[N + 5][S + 5];

int main() {
#ifdef Wearry
  freopen("in", "r", stdin);
  freopen("out", "w", stdout);
#endif

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

  sort(a, a + n, greater<int>()); 

  f[0][x] = 1;
  for (int i = 0; i < n; ++i) 
    for (int j = 0; j <= x; ++j) if (f[i][j]) {
      f[i + 1][j % a[i]] = (f[i + 1][j % a[i]] + f[i][j]) % mo;
      f[i + 1][j] = (f[i + 1][j] + 1ll * f[i][j] * (n - 1 - i)) % mo;
    }

  int ans = 0;
  for (int i = 0; i <= x; ++i) {
    ans = (ans + 1ll * f[n][i] * i) % mo;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 78208
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt(), k = scanner.nextInt();
        String s = scanner.next();
        int[] a = new int[s.split("1+").length + s.split("0+").length + (s.charAt(0) == '0' ? 1 : 0)];
        if (a.length == 1 || s.matches("0+")) {
            System.out.println(s.length());
            return;
        }
        Arrays.fill(a, 1);
        a[a.length - 1] = 0;
        int i = -1;
        if (s.charAt(0) == '0') {
            a[0] = 0;
            i++;
        }
        char last = ' ';
        for (char ch : s.toCharArray()) {
            if (ch == last) {
                a[i]++;
            } else {
                i++;
            }
            last = ch;
        }

        int[] sum = new int[a.length];
        for (int j = 0; j <= Math.min(k * 2, a.length - 1); j++) {
            sum[0] += a[j];
        }
        for (int j = 2; j < a.length - k * 2; j += 2) {
            sum[j / 2] = sum[j / 2 - 1] - a[j - 1] - a[j - 2] + a[j + k * 2 - 1] + a[j + k * 2];
        }

        Arrays.stream(sum).max().ifPresent(System.out::println);

    }
}

Measured memory_bytes: 37952
# -*- coding: utf-8 -*-
#ARC098C
import sys
import math

n=int(input())
#tmp = input().split()
#hoge = list(map(lambda a: int(a), tmp))
s=input()

sumw=[]
sumw.append(0)
for i in range(1,n+1):
	if(s[i-1]=="W"):
		tmp = sumw[i-1]+1
	else:
		tmp = sumw[i-1]
	sumw.append(tmp)
sume=[]
sume.append(0)
for i in range(1,n+1):
	if(s[n-i]=="E"):
		tmp = sume[i-1]+1
	else:
		tmp = sume[i-1]
	sume.append(tmp)

mini=sume[n-1]
for i in range(2,n+1):
	if(i == n):
		tmp=sumw[n-1]
	else:
		tmp=sumw[i-1]+sume[n-i+1]
	
	mini=min(mini,tmp)

#print(sumw)
#print(sume)
#print(n)
#print(s)
print(mini)




Measured memory_bytes: 18044
using System;
using System.Collections.Generic;
using System.Linq;
namespace CsProgramSpace
{
    class Program
    {
        static void Main(string[] args)
        {
            List<List<string>> u = new List<List<string>>();
            List<int> res = new List<int>();
            List<string> li = new List<string>();
            int c = 0;
            int cc = 0;
            while(true)
            {
                li = Console.ReadLine().Split(' ').Select(_ => (_)).ToList();
                
                foreach(string s in li)
                {
                    if (c == 1 && s == "?") cc = 3;
                    c++;
                }
                if (cc != 3)
                    u.Add(li);
                else break;
                cc = 0;
                c = 0;
            }
            foreach(List<string> lis in u)
            {
                string[] temp = lis.ToArray();
                switch (temp[1])
                {
                    case "+":
                        res.Add(int.Parse(temp[0]) + int.Parse(temp[2]));
                        break;
                    case "-":
                        res.Add(int.Parse(temp[0]) - int.Parse(temp[2]));
                        break;
                    case "*":
                        res.Add(int.Parse(temp[0]) * int.Parse(temp[2]));
                        break;
                    case "/":
                        res.Add(int.Parse(temp[0]) / int.Parse(temp[2]));
                        break;
                }
            }
            foreach(int d in res)
            {
                Console.WriteLine(d);
            }
        }
    }
}


Measured memory_bytes: 16468
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
typedef long long int ll;
using namespace std;
using Graph = vector<vector<int> >;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int A,B;
cin>>A>>B;
int ans=0;
if(A>B*2){
    ans=A-B*2;
}
cout<<ans<<endl;

//system("pause");
return 0;
}

Measured memory_bytes: 256
public class Main{
  static int[] a;
  static int infi = 2000000;
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
    int v, e, i, j, k;
    int[][] d, dp;

    v = sc.nextInt(); e = sc.nextInt();
    d = new int[v][v]; a = new int[v + 1];
    for(i = 0;i < v;i++)for(j = 0;j < v;j++)d[i][j] = infi;
    for(;e-- > 0;)d[sc.nextInt()][sc.nextInt()] = sc.nextInt();
    a[0] = 1;
    for(i = 0;i < v;i++)a[i + 1] = a[i] * 2;
    dp = new int[a[v]][v];
    for(i = 0;i < a[v];i++)for(j = 0;j < v;j++)dp[i][j] = infi;
    dp[a[v] - 1][0] = 0;

    for(i = a[v] - 1;i >= 0;i--)
      for(j = 0;j < v;j++)if(dp[i][j] != infi && isin(i, j))
        for(k = 0;k < v;k++)if(j != k && isin(i, k) && d[k][j] < infi){
          if(dp[i][j] + d[k][j] < dp[i - a[j]][k])
            dp[i - a[j]][k] = dp[i][j] + d[k][j];
        }
    if(dp[0][0] != infi)out.println(dp[0][0]);
    else out.println("-1");

    sc.close();
  }
  private static boolean isin(int s, int v){
    return (v == 0 || ((s % a[v + 1]) / a[v]) == 1);
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 32596
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
const long long LINF=1e18;
template<typename T>
void chmin(T &a,T b){
  if(a>b)a=b;
}
template<typename T>
void chmax(T &a,T b){
  if(a<b)a=b;
}

signed main(){
  int x,k;cin>>x>>k;
  vector<int> r(k); for(int &p:r)cin>>p;
  r.push_back(LINF);
  int q;cin>>q;
  vector<P> qu(q); for(P &p:qu){int t,a;cin>>t>>a;p=P(t,a);}
  int now=0,de=0,fl=1,low=0,high=x;
  int A=x;
  for(P _:qu){
    int t=_.first,a=_.second;
    while(now<=k&&r[now]<=t){
      de+=fl*(r[now]-(now>0?r[now-1]:0));
      chmin(high,x+de);
      chmax(low,de);
      A-=fl*(r[now]-(now>0?r[now-1]:0));chmax(A,0LL);chmin(A,x);
      fl*=-1;now++;
    }
    int ans,w=-de-fl*(t-(now?r[now-1]:0));
    if(a<low)ans=low+w;
    else if(a>high)ans=high+w;
    else ans=a+w;
    if(high<low)ans=A-fl*(t-(now?r[now-1]:0));
    chmax(ans,0LL);
    chmin(ans,x);
    cout<<ans<<endl;
  }
}


Measured memory_bytes: 3568
import java.util.Scanner;
public class Main {
   
    public static void main(String[] args) { 
		Scanner sc = new Scanner(System.in);
int X=sc.nextInt();
int Y=sc.nextInt();
int Z=sc.nextInt();
        System.out.printf("%d %d %d",Z,X,Y);

    } 
}

Measured memory_bytes: 20948
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define FIR first
#define UB upper_bound
#define LB lower_bound
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;

signed main(){
  double r,g;
  cin>>r>>g;
  cout<<2*g-r<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
const int mod=(int)1e9+7;
int main() {
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    int N;
    cin>>N;
    cout<<"ABC"<<N;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pq priority_queue
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
const ll MAX=510000;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};
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; }

bool com(string a,string b){
    if(a.size()!=b.size()) return a.size()<b.size();
    else return a<b;
}

int main(){
    ll a=0,b=3,ans=0;
    string S;
    cin>>S;
    vector<string> v={"3","5","7"};
    while(1){
        for(ll i=a;i<b;i++){
            string t=v[i];
            v.push_back(t+'3');
            v.push_back(t+'5');
            v.push_back(t+'7');
        }
        a=b;
        b=v.size();
        if(v[a-1].size()==S.size()) break;
    }
    v.push_back(S);
    sort(v.begin(),v.end(),com);
    for(ll i=0;i<v.size();i++){
        ll c3=0,c5=0,c7=0;
        for(ll j=0;j<v[i].size();j++){
            if(v[i][j]=='3') c3++;
            else if(v[i][j]=='5') c5++;
            else if(v[i][j]=='7') c7++;
        }
        if(c3&&c5&&c7) ans++;
        if(v[i]==S){
            cout<<ans<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 5432
#include <iostream>
#include <cmath>
#include <cstdio>

int main() {
	int x, h;
	double x1, S;
	
	while(1) {
		std::cin >> x >> h;
		if(!x && !h) break;
		
		x1 = sqrt( (double)(h*h) + (double)(x*x)/4.0 );
		
		S = (double)(x*x) + (x1*x)*2.0;
		
		//std::cout << S << std::endl;
		std::printf("%.6f\n", S);
	}
	return 0;
}

Measured memory_bytes: 1192
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define akumanosuuji = 666;
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
ll MAX(ll a,ll b,ll c){return max(a,max(b,c));}
ll MIN(ll a,ll b,ll c){return min(a,min(b,c));}
const ll mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << min(a,b) + min(c,d) << endl;
}

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

namespace _0608
{
    public class Program

    {
        public static void Main(string[] args)
        {
            int a = ReadInt();
            int b = ReadInt();
            int c = ReadInt();
            int d = ReadInt();
            int p = ReadInt();
            Console.WriteLine(Math.Min(a * p, p <= c ? b : b + d * (p - c)));
        }

        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }
        static string WriteAr(int[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }
        static string WriteAr(double[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }
        static string WriteAr(long[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }

    }

}



Measured memory_bytes: 15968
#include <stdio.h>

int main(void)
{
    size_t a, b, c;
    scanf("%zu %zu %zu", &a, &b, &c);
    for (size_t n = 1; n <= b; ++n) {
        if ((n * a % b) % b == c) {
            puts("YES");
            return 0;
        }
    }
    puts("NO");
    return 0;
}


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

using ll = long long;

using namespace std;

struct uftree {
    int n, *par, *rank, *size;
    uftree(int N) : n(N) {
        par = new int[(size_t)N];
        rank = new int[(size_t)N];
        size = new int[(size_t)N];
        for (int i = 0; i < N; i++) {
            par[i]  = i;
            rank[i] = 0;
            size[i] = 1;
        }
    }
    int root(int x) {
        if (par[x] == x)
            return x;
        else {
            int r         = root(par[x]);
            size[x]       = size[par[x]];
            return par[x] = r;
        }
    }
    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (rank[x] > rank[y])
            par[y] = x;
        else {
            par[x] = y;
            if (rank[x] == rank[y]) rank[y]++;
        }
        size[x] += size[y];
        size[y] = size[x];
    }
    int get_size(int x) {
        root(x);
        return size[x];
    }
    bool same(int x, int y) { return root(x) == root(y); }

    // 集合の数をカウントする関数
    // 1..nのつもりでやってる場合も0をカウントしちゃうので注意
    int count_sets() {
        int cnt = 0;
        bool used[n];
        fill(used, used+n, false);
        for (int i=0; i<n; i++) {
            if (used[root(i)]) continue;
            cnt++;
            used[root(i)] = true;
        }
        return cnt;
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    uftree uft(n);
    for (int i=0, ai, bi; i<m; i++) {
        cin >> ai >> bi;
        ai--; bi--;
        uft.unite(ai, bi);
    }
    vector used(n, false);
    int ans = 1;
    for (int i=0; i<n; i++) {
        if (!used[uft.root(i)]) {
            used[uft.root(i)] = true;
            ans = max(ans, uft.get_size(i));
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 5968
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void)
{
  string s;
  cin >> s;
  int l = s.length();
  int r[2019] = {0};
  ll t = 0,p = 1;
  r[0]++;
  for(int i = l-1;i>=0;i--)
  {
    char a = s[i];
    t = t%2019 + p * (int)(a-'0')%2019;
    r[t%2019]++;
    p = p * 10 % 2019;
  }
  ll c = 0;
  for(int i = 0;i<2019;i++)
  {
    int m = r[i];
    c += m * (m-1)/2;
  }
  cout << c << endl;
  return 0;
}


Measured memory_bytes: 3736
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

#pragma GCC target("avx,avx2")
using namespace std;

    
int main(void){
  string st;cin>>st;
  int x_num=count(st.begin(),st.end(),'x');
  if(x_num>=8)cout<<"NO"<<endl;
  else cout<<"YES"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(ll, N, K);

  ll ans = 0;

  if (K == 0) {
    print(N * N);
    return;
  }

  rep(i, K + 1, N + 1) {
    ll d = (N / i);
    ll n = d * (i - K) + max(N - (i * d) - K + 1, 0LL);
    ans += n;
  }
  print(ans);
}


Measured memory_bytes: 256
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    let X = parseInt(arg[0].split(" ")[0]);
    const N = parseInt(arg[0].split(" ")[1]);
    
    if(!arg[1]) {
      console.log(X);
      return;
    }
  
    const P = arg[1].split(" ").map(n=>parseInt(n));
    let cnt = 1;
    
    while(true) {
        if(P.indexOf(X) === -1) {
            console.log(X);
            return;
        }
      
        let answer1;
        let answer2;
      
        if(P.indexOf(X - cnt) === -1) {
            answer2 = X - cnt;
            console.log(answer2);
            return;
        }
        
        if(P.indexOf(X + cnt) === -1) {
            answer1 = X + cnt;
            console.log(answer1);
            return;
        }
       
      	cnt++;
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29652
// 標準入力
var fs = require('fs'),
length = fs.fstatSync(process.stdin.fd).size,
buffer = new Buffer(length),
bytesRead = fs.readSync(process.stdin.fd, buffer, 0, length, 0),
input = buffer.toString('utf8', 0, bytesRead).split('\n');
main();
    
// ここから
function main(){
  var primeNumbers = calcPrimeNumbers();
  var primeCounts = new Int32Array(50001);

  for(var i = 1; i < 5133; i++){
    var pni = primeNumbers[i];
    for(var k = 1; k <= i; k++){
      var sum = pni + primeNumbers[k];
      if(sum > 50000)
        break;
        primeCounts[sum]++;
    }
  }
  var i = 0;
  while(c = +input[i++]){
    console.log(primeCounts[c]);
  }
  
}
   
function calcPrimeNumbers(){
  var max = 49999;
  var primeNumbers = new Int8Array(max + 1);
   
  // 除外
  primeNumbers[0] = primeNumbers[1] = 1;
  for(var i = 2, maxI = ~~Math.sqrt(max); i <= maxI; i++){
    if(primeNumbers[i]){
      continue;
    }
       
    for(var j = (i<<1); j <= max; j+=i){
      primeNumbers[j] = 1;
    }
  }
   
  var primeNums = new Int32Array(5134);
  var c = 0;
  for(var i = 1; i <= max; i++){
    if(!primeNumbers[i]){
      primeNums[++c] = i;
    }
  }
     
  return primeNums;
}

Measured memory_bytes: 13588
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
 
ll modExp(ll base, ll power) {
    if (power == 0) {
        return 1;
    } else {
        ll cur = modExp(base, power / 2); cur = cur * cur; cur = cur % MOD;
        if (power % 2 == 1) cur = cur * base;
        cur = cur % MOD;
        return cur;
    }
}

ll inv(ll base) {
    int g = MOD, r = base, x = 0, y = 1;
    while (r != 0) {
        int q = g / r;
        g %= r; swap(g, r);
        x -= q * y; swap(x, y);
    }
    return x < 0 ? x+MOD : x;
}

ll mul(ll A, ll B) {
	return (A*B)%MOD;
}

ll add(ll A, ll B) {
	return (A+B)%MOD;
}

ll dvd(ll A, ll B) {
    return mul(A, inv(B));
}

ll sub(ll A, ll B) {
    return (A-B+MOD)%MOD;
}


vi primes, leastFac;
void compPrimes(int N) {
	F0R(i, N) {
		leastFac.pb(0);
	}
	leastFac[0] = 1; leastFac[1] = 1;
	FOR(i, 2, N) {
		if (leastFac[i] == 0) {
			primes.pb(i);
			leastFac[i] = i;
		}
		for (int j = 0; j < sz(primes) && i*primes[j] < N && primes[j] <= leastFac[i]; j++) {
			leastFac[i*primes[j]] = primes[j];
		}
	}
}

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

    int N = 3;
    int K; cin >> K;
    compPrimes(MX);
    int cf[MX];
    cf[0] = 0; cf[1] = 0;
    bool sf[MX];
    sf[0] = true; sf[1] = true;
    FOR(i, 2, MX) {
        cf[i] = 1 + cf[i / leastFac[i]];
        sf[i] = sf[i / leastFac[i]] && leastFac[i] != leastFac[i / leastFac[i]];
    }

    ll ans = 0;
    ll cnt[K+1];
    FOR(i, 1, K+1) {
        cnt[i] = modExp(K/i, N);
    }
    FOR(i, 1, K+1) {
        ll cur = cnt[i];
        for (int j = i * 2; j <= K; j+=i) {
            if (!sf[j/i]) continue;
            if (cf[j] % 2 == cf[i] % 2) {
                cur += cnt[j]; cur %= MOD;
            } else {
                cur -= cnt[j]; cur += MOD; cur %= MOD;
            }
        }
        ans += cur * i; ans %= MOD;
//        cout << cur << nl;
    }
    cout << ans << nl;

	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  string s; cin>>s;
  ll l=0;
  rep(i,n){
    if(s[i]=='(') l++;
    else{
      l=max(l-1,0LL);
    }
  }
  rep(i,l) s.push_back(')');
  n=s.size();
  ll r=0;
  rrep(i,n){
    if(s[i]==')') r++;
    else{
      r=max(r-1,0LL);
    }
  }
  if(r){
    string tmp=string(r,'(');
    s=tmp+s;
  }
  cout<<s<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 8
#define FREE -1
#define NOT_FREE 1
#define true 1;
#define false 0;

int row[N], col[N], dpos[2 * N -1], dneg[2 * N -1];

int X[N][N];

void initialize() {
	int i;
	for ( i = 0; i < N; i++) { row[i] = FREE, col[i] = FREE; }
	for ( i = 0; i < 2 * N - 1; i++) { dpos[i] = FREE, dneg[i] = FREE; }
}

void printBoard() {
	int i, j;
	for ( i = 0; i < N; i++) {
		for ( j = 0; j < N; j++) {
			if ( X[i][j]) {
				if ( row[i] != j) return;
			}
		}
	}
	for ( i = 0; i < N; i++) {
		for ( j = 0; j < N; j++) {
			printf(( row[i] == j) ? "Q" : ".");
		}
		printf("\n");
	}
}

void recursive( int i) {
	int j;
	if ( i == N) {
		printBoard();
		return ;
	}

	for ( j = 0; j < N; j++) {
		if (NOT_FREE == col[j] ||
			NOT_FREE == dpos[i + j] ||
			NOT_FREE == dneg[i - j + N - 1]) continue;
		// (i, j)にクイーンを配置する
		row[i] = j;
		col[j] = dpos[i + j] = dneg[i - j + N - 1] = NOT_FREE;
		recursive(i + 1);
		// (i, j)に配置されているクイーンを取り除く
		row[i] = col[j] = dpos[i + j] = dneg[i - j + N - 1] = FREE;
	}
	// クイーンの配置に失敗
}

int main() {
	int i, j;
	int k, r, c;

	initialize();

	for ( i = 0; i < N; i++) {
		for ( j = 0; j < N; j++) X[i][j] = false;
	}

	scanf("%d",&k);
	for ( i = 0; i < k; i++) {
		scanf("%d%d",&r,&c);
		X[r][c]  = true;
	}

	recursive(0);

	return 0;
}



Measured memory_bytes: 2112
N=int(input())
S=input()

if len(S)==1:
    print("No")
elif len(S)%2==0:
    A=N/2
    MAE=S[:int(A)]
    #print(MAE)
    B=N/2
    USHIRO=S[int(B):]
    #print(USHIRO)
    
    if MAE==USHIRO:
        print("Yes")
    else:
        print("No")
    
else:
    print("No")
    



Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
		ll x,k,d;
		cin>>x>>k>>d;
  		if(x<0)
          x=-x;
		ll can=min(k,x/d);
		x-=can*d;
		k-=can;
		if(k%2==0)
			cout<<abs(x)<<endl;
		else
			cout<<abs(x-d)<<endl;
}


Measured memory_bytes: 3600
n = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
i = int(input())
print(n[i-1])

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

#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define MOD 1000000007

#define trace1(x)                    cout <<#x<<": "<<x<< endl;
#define trace2(x, y)                 cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)              cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)           cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;

typedef long long ll;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    ll i,j,n,m,a,b,c;
    cin>>a>>b>>c;
    cout<<max(ll(0),c-(a-b));
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int r, c, i, j;
	cin >> r >> c;

	int k, t;
	int* row = new int[c+1];
	for( j = 0; j < c+1; ++j) 
		row[j] = 0;

	for( i = 0; i < r; ++i){
		t = 0;
		for(j = 0; j < c; ++j){
			cin >> k;
			cout << k << " ";
			t += k;
			row[j] += k;
		}
		cout << t << "\n";
		row[c] += t; 
	}

	for( j = 0; j < c+1; ++j){
		cout << row[j];
		if( j != c )
			cout << " ";
	}

	cout << "\n";

	delete[] row;

	return 0;
}

Measured memory_bytes: 1200
//{{{
#include<algorithm>
#include<cmath>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(printde) FUNC(printdbe) FUNC(printdwe) FUNC(printdu);
#endif
template <template <class T, class = std::allocator<T>> class V, class E>
istream& operator >> (istream& in, V<E>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vector<int> hs(n); cin >> hs;
    sort(hs.begin(), hs.end());
    cout << n - (lower_bound(hs.begin(), hs.end(), k) - hs.begin()) << '\n';
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
const int MAXN=100007,MAXM=200007,MAX=1061109567;
typedef long long ll;
struct node {
	int v,w;
	node(int x=0,int y=0) {
		v=x,w=y;
	}
};
int deg[MAXN],X,n,m,x1,y,x2,tot[MAXN];
ll pos[MAXN];
bool vis[MAXN];
char c;
vector<node> edge[MAXN];
int read() {
	X=0,c=getchar();
	while(!isdigit(c))c=getchar();
	while(isdigit(c))X=(X<<1)+(X<<3)+c-'0',c=getchar();
	return X;
}
bool ok;
bool check(int &u) {
	vis[u]=true;
	for(int i=0; i<tot[u]; i++) {
		if(vis[edge[u][i].v]) {
			if(pos[edge[u][i].v]-edge[u][i].w!=pos[u])return false;
		} else {
			pos[edge[u][i].v]=pos[u]+edge[u][i].w;
			if(!check(edge[u][i].v))return false;
			else continue;
		}
	}
	return true;
}
int main() {
		n=read(),m=read();
		if(!m){
			cout<<"Yes";
			return 0;
		}
		for(int i=0; i<m; i++) {
			x1=read(),x2=read(),y=read();
			tot[x1]++;
			deg[x2]++;
			edge[x1].push_back(node(x2,y));
		}
		for(int i=0; i<n; i++)if(!deg[i]&&tot[i]) {
				ok=1;
				if(!check(i)) {
					cout<<"No";
					return 0;
				}
			};
		if(!ok) {
			cout<<"No";
			return 0;
		}
		cout<<"Yes";
		return 0;
}


Measured memory_bytes: 10496
#include <bits/stdc++.h>
#define N 300005
using namespace std;

int n;
vector<int> msprime;
bool prime[N + 5] = {0};

void sprime() {
  int i, j;
  for(i = 0; i <= N; ++i)
    if(i % 7 == 1 || i % 7 == 6) msprime.push_back(i);
  for(i = 1; i < msprime.size(); ++i) {
    if(!prime[msprime[i]])
      for(j = 1; msprime[i] * msprime[j] <=
                 msprime[msprime.size() - 1];
          ++j)
        prime[msprime[i] * msprime[j]] = 1;
  }
}

int main() {
  int i, now;
  sprime();
  while(1) {
    cin >> n;
    if(n == 1) break;
    cout << n << ":";
    for(i = 1; i <= msprime.size(); ++i) {
      if(msprime[i] > n) break;
      if(prime[msprime[i]] || n % msprime[i] != 0) continue;
      now = n / msprime[i];
      if(find(msprime.begin(), msprime.end(), now) !=
         msprime.end())
        cout << " " << msprime[i];
    }
    cout << endl;
  }
  return 0;
}


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

int main(){
	int k, a, b;
  cin >> k >> a >> b;
  for(int i = a; i <= b; i++){
    if(i % k == 0) {
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;
}

Measured memory_bytes: 3604
#![allow(unused_imports)]
#![allow(dead_code)]
use std::cmp::*;
use std::collections::*;

const NOTHING: usize = std::usize::MAX;

fn main() {
    let n = readln();
    let cs: Vec<i64> = readln();
    let mut gr: Vec<Vec<usize>> = vec![vec![];n];
    for _ in 0..n - 1 {
        let (a, b): (usize, usize) = readln();
        gr[a - 1].push(b - 1);
        gr[b - 1].push(a - 1);
    }
    let gr = gr;

    if n == 2 {
        if cs[0] == cs[1] {
            println!("YES");
        } else {
            println!("NO");
        }
        return;
    }
    let mut root = 0;
    for v in 0..n {
        if gr[v].len() > 1 {
            root = v;
            break;
        }
    }

    if let Some(0) = dfs(&gr, root, NOTHING, &cs) {
        println!("YES");
    } else {
        println!("NO");
    }
}

fn dfs(gr: &Vec<Vec<usize>>, v: usize, parent: usize, cs: &Vec<i64>) -> Option<i64> {
    let len = gr[v].len() - 1;
    if len == 0 {
        return Some(cs[v]);
    }

    let mut children: Vec<i64> = Vec::with_capacity(len);
    for &nv in &gr[v] {
        if nv == parent {
            continue;
        }
        if let Some(c) = dfs(gr, nv, v, cs) {
            children.push(c)
        } else {
            return None;
        }
    }

    let s: i64 = children.iter().fold(0, |acc, &x| acc + x);
    let m: i64 = children.iter().fold(0, |acc, &x| max(acc, x));

    let t = 2 * cs[v] - s;

    if t >= 0 && (s - t) <= 2 * min(s / 2, s - m) && s - t >= 0 {
        Some(t)
    } else {
        None
    }

}

fn get_line() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_string()
}

fn get_chars() -> Vec<char> {
    get_line().chars().collect()
}

fn readln<T: Read>() -> T {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    T::read(buf.trim_right())
}

trait Read {
    fn read(s: &str) -> Self;
}

macro_rules! read_impl{
    ($($t:ty)*) => ($(
        impl Read for $t {
            fn read(s: &str) -> $t{
                s.parse().unwrap()
            }
        }
    )*)
}
read_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }

impl<T: Read> Read for Vec<T> {
    fn read(s: &str) -> Self {
        s.split_whitespace().map(T::read).collect()
    }
}

impl<A: Read, B: Read> Read for (A, B) {
    fn read(s: &str) -> Self {
        let tokens: Vec<_> = s.split_whitespace().collect();
        (A::read(tokens[0]), B::read(tokens[1]))
    }
}

impl<A: Read, B: Read, C: Read> Read for (A, B, C) {
    fn read(s: &str) -> Self {
        let tokens: Vec<_> = s.split_whitespace().collect();
        (A::read(tokens[0]), B::read(tokens[1]), C::read(tokens[2]))
    }
}


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

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long
#define TBMod 1000000007

int main(int argc, char const *argv[])
{
	int a,p;
	scanf("%d%d",&a,&p);
	printf("%d\n", (3 * a + p) / 2);
	return 0;
}


Measured memory_bytes: 128
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};

const int MAX = 510000;
in fac[MAX], finv[MAX], inv[MAX];
//fac:n!  ,  finv:1/n  ,  inv:1/n!
// テーブルを作る前処理
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;
    }
}
// 二項係数計算
in 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 main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    COMinit();
    int n,k;
    cin>>n>>k;
    vector<int> a(n);
        rep(i,n) cin>>a.at(i);
    sort(all(a));
    in ans=0ll;
    rep(i,n){
        ans +=COM(i,k-1)*a[i];
        ans %=MOD;
    }
    rep(i,n){
        ans -=COM(n-1-i,k-1)*a[i];
        ans %=MOD;
        ans +=MOD;
        ans %=MOD;
    }
    cout<<ans<<endl;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

typedef long long LL;
typedef pair<int, int> pii;

const int INTINF = 1e9;
const LL LLINF = 1e18;

void solve()
{
    LL a, b, x;
    cin >> a >> b >> x;

    cout << b / x - (a != 0 ? (a - 1) / x : -1) << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}

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



int main(int argc, char const *argv[])
{
	for(;;)
	{
		int h, w, hhww, th, tw, thhww = 1e9, ah, aw, ahhww = 1e9;
		cin >> h >> w;
		hhww = h * h + w * w;
		if(h == 0 && w == 0) break;

		for (int th = 1; th < 150; ++th)
		{
			for (int tw = th+1; tw <= 150; ++tw)
			{
				thhww = th*th+tw*tw;
				if((hhww < thhww || (hhww == thhww && h < th)) && (thhww < ahhww || (thhww == ahhww && th < ah)))
				{
					ahhww = thhww;
					ah = th;
					aw = tw;
				}
			}
		}

		cout << ah << " " << aw << endl;
	}
	
	return 0;
}

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

// clang-format off
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); --(i))

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define endl '\n'
#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

void solver() {
    int N = input(), M = input();
    int X = input(), Y = input();
    vector< int > x(N), y(M);
    cin >> x >> y;
    x.push_back(X);
    y.push_back(Y);

    whole(sort, x);
    whole(sort, y);
    
    cout << (x.back() < y.front() ? "No War" : "War") << endl;
}

signed main(int argc, char *argv[]) {
    solver();
}


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

a=[int(input()) for _ in range(n)]

count=1
right=a[0]
for i in range(100000+1):
    #print(right,"right")
    if right==2:
        print(count)
        break
    else:
        right=a[right-1]
        count+=1

else:
    print(-1)

Measured memory_bytes: 7084