akhauriyash/Code-Regression huggingface dataset:
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    P = list(map(float, input().split()))

    dp = [[0] * (n + 1) for _ in range(n + 1)]
    dp[0][0] = 1.0

    for i in range(1, n + 1):
        for j in range(1, i + 1):
            dp[i][j] += dp[i - 1][j - 1] * P[i - 1]
            dp[i][j - 1] += dp[i - 1][j - 1] * (1.0 - P[i - 1])

    res = 0
    for i in range(n // 2 + 1, n + 1):
        res += dp[-1][i]

    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 263048
using System;

namespace atcoderA
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int a = int.Parse(Console.ReadLine());
            int b = int.Parse(Console.ReadLine());
            int h = int.Parse(Console.ReadLine());
            int ans = (a + b) * h / 2;
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 11092
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Stack;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String str = br.readLine();
    Stack<String> stack = new Stack<String>();
    for (int i = 0; i < str.length(); i++) {
      if (str.charAt(i) == 'B' && !stack.empty()) {
        stack.pop();
      } else if (str.charAt(i) != 'B') {
        stack.push(String.valueOf(str.charAt(i)));
      }
    }
    System.out.println(String.join("",stack));
  }
}

Measured memory_bytes: 22868
n, m = map(int, input().split())
a = [int(input()) for i in range(m)]

b = [0] * (n+1)

for i in a:
    b[i] = 1

dp = [0] * (n+1)

dp[0] = 1

if b[1] == 1:
    dp[1] = 0
else:
    dp[1] = 1

for i in range(2, n+1):
    if b[i] == 1:
        dp[i] = 0
    else:
        dp[i] = dp[i-1] + dp[i-2]

print(dp[n] % 1000000007)


Measured memory_bytes: 460788
import sys

n, h = map(int, input().split())
a = [list(map(int, x.split())) for x in sys.stdin.readlines()]
a.sort(reverse=True)
b = sorted(a, key=lambda x:x[1], reverse=True)
cnt = 0
for i in b:
    if i[1] < a[0][0]:
        break
    cnt += 1
    h -= i[1]
    if h <= 0:
        print(cnt)
        exit()
print(cnt + -(-h//a[0][0]))

Measured memory_bytes: 35808
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;

template <typename T> struct Combination{

    T mpow(T x,T n){
        T res = 1;
        while(n != 0){
            if(n&1) res = res*x % mod;
            x = x*x % mod;
            n = n >> 1; 
        }
        return res;
    }

    vector<T> fac,ifac;
    constexpr Combination(int max_N) noexcept : fac(max_N,1),ifac(max_N,1){
        fac[0] = 1;
        ifac[0] = 1;
        for(int i = 0;i < max_N;i ++){
            fac[i+1] = fac[i]*(i+1) % mod;
            ifac[i+1] = ifac[i]*mpow(i+1,mod-2) % mod;
        }
    }

    constexpr T comb(T a,T b){
        if(a==0 && b==0) return 1;
        if(a<b || a<0) return 0;
        T tmp = ifac[a-b]*ifac[b] % mod;
        return tmp*fac[a] % mod;
    }
    constexpr T perm(T a,T b){
        if(a==0 && b==0) return 1;
        if(a<b || a<0) return 0;
        return ifac[a-b]*fac[a] % mod;
    }
};

int main(){
    ll h,w,a,b,ans=0;
    cin >> h >> w >> a >> b;
    Combination<ll> c(200001);
    for(int i = 0;i < h-a;i ++){
        ans += c.comb(i+b-1,i)*c.comb(w+h-2-b-i,w-1-b);
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;
typedef long double ld;
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353
#define Graph vector<vector<int>>

int main() {
    ll A, B, C, X, Y; cin >> A >> B >> C >> X >> Y;
    ll cost = 0;
    if (A + B < 2 * C) {
        cost = A * X + B * Y;
    }
    else {
        ll costa = C * 2 * max(X, Y);
        if (X < Y) {
            cost = C * 2 * X + B * (Y - X);
        }
        else {
            cost = C * 2 * Y + A * (X - Y);
        }
        cost = min(cost, costa);
    }
    cout << cost << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <cassert>
#include <fstream>
#include <iomanip>

using namespace std;


int main() {
    
    
    int n;
    cin >> n;
    vector<pair<long long, long long>> v;
    for (int i = 0; i < n; ++i)
    {
        int a, b;
        cin >> a >> b;
        v.push_back(make_pair(b, a));
    }
    
    sort(v.begin(), v.end());
    
    long long current = 0;
    for (int i = 0; i < n; ++i)
    {
        current += v[i].second;
        if (v[i].first < current)
        {
            cout << "No" << endl;
            return 0;
        }
    }
    
    cout << "Yes" << endl;
    
    return 0;
}

Measured memory_bytes: 6384
#include <bits/stdc++.h>  
#include <memory>
using namespace std;  
#define INF 0x3f3f3f3f  
typedef long long ll;  
const int N =  200005;  
#define FI first
#define SE second
typedef pair<int, int>pii;
int mod = 1000000007;
 
 int num[N];
int main()  
{  

   // ios::sync_with_stdio(0);
   int n, k;
   while (~scanf("%d%d", &n, &k))
   {
      for (int i = 0; i < n; i++)scanf("%d", num + i);
         sort(num, num + n);
      ll ans = 0;
      for (int i = n - 1, j = 0; j < k; j++, i--)
         ans += num[i];
      cout<<ans<<endl;
   }
   return 0;
}  

Measured memory_bytes: 256
y,x=[int(i) for i in input().split()]
a=[list(input()) for j in range(y)]
s=0
for i in range(y):
  for j in range(x):
    f=0
    if i-1>=0:
     if a[i-1][j]=='#':
        f+=1
    if j-1>=0:
     if a[i][j-1]=='#':
        f+=1        
    if i+1<=y-1:
     if a[i+1][j]=='#':
        f+=1
    if j+1<=x-1:
     if a[i][j+1]=='#':
        f+=1        
    if a[i][j]=='#' and f==0:
      s=1 
if s==1:
  print('No')
else:
  print('Yes')

Measured memory_bytes: 3064
l=[]
s=int(input())
l.append(s)
r=False
while r==False:
    if(s%2==0):
        #even
        s=s/2
    else:
        s=3*s+1
    if s not in l:
        l.append(s)
    else:
        l.append(s)
        r=True
print(len(l))


Measured memory_bytes: 3060
A = [list(map(int,input().split())) for _ in range(3)]
n = int(input())
num = set([])
for _ in range(n):
  num.add(int(input()))
  
def func(a,b,c):
  if a in num and b in num and c in num:
    return 1
  else:
    return 0
  
r =func(*A[0]) or func(*A[1]) or func(*A[2])
c = func(A[0][0],A[1][0],A[2][0]) or func(A[0][1],A[1][1],A[2][1]) or func(A[0][2],A[1][2],A[2][2])
naname = func(A[0][0],A[1][1],A[2][2]) or func(A[2][0],A[1][1], A[0][2])

print('Yes' if r or c or naname else 'No')

Measured memory_bytes: 3064
def main():
    N = int(input())
    A = list(map(int, input().split()))
    negatives = 0
    zeros = 0
    min_abs = 10**9 + 1
    for a in A:
        if a < 0:
            negatives += 1
        if a == zeros:
            zeros += 1
        min_abs = min(min_abs, abs(a))
    ans = sum(map(abs, A))
    if negatives % 2 == 0 or zeros != 0:
        print(ans)
        return

    ans -= 2*min_abs
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 14412
N, M = map(int, input().split())

if (2 * N > M):
    print(M // 2)
    exit()
elif (2 * N == M):
    print(M // 2)
    exit()
else:
    # 2 * N< M のときはMに余裕があるときはcを2つ使ってSを作成する
    # Mこのうちk個使ってSを作成
    # Mが奇数or偶数で分ける
    if (M % 2 == 0):
        k = M // 2 - N
    else:
        k = (M // 2) - N - 1
    print(min(((M - k) // 2), (N + (k // 2))))


Measured memory_bytes: 9048
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MAX = 1e5+9;
ll dp[100+5][MAX]; int wt[MAX], val[MAX];
int n;
ll f(int i, int w) {
	if(i==n) return 0;
	if(dp[i][w]!=-1) return dp[i][w];
	if(w < wt[i]) return dp[i][w] = f(i+1, w);
	return dp[i][w] = max(f(i+1, w) , val[i] + f(i+1, w-wt[i]));
}
int main() {
	// your code goes here
	int w;
	cin >> n >> w;
	memset(dp, -1, sizeof(dp));
	for(int i=0;i<n;i++) cin >> wt[i] >> val[i];
	cout << f(0, w);
	return 0;
}

Measured memory_bytes: 82304
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

const ll M = 998244353;

int main(){
	string s;
	cin >> s;
	for(int i = 0 ; i+1 < s.size() ; i ++){
		if(s[i] != s[i+1])break;
		if(i+1 == s.size()-1){
			cout << 1 << endl;
			return 0;
		}
	}
	
	if(s.size() == 3){
		if(s[0] != s[1] && s[0] != s[2] && s[1] != s[2]){
			cout << 3 << endl;
			return 0;
		}
	}
	
	static ll dp[200010][2][3][3] = {};
	dp[1][0][0][0] = 1;
	dp[1][0][1][1] = 1;
	dp[1][0][2][2] = 1;
	for(int i = 1 ; i < s.size() ; i ++){
		for(int j = 0 ; j < 3 ; j ++){
			for(int k = 0 ; k < 3 ; k ++){
				dp[i+1][0][j][k] = dp[i][0][(j+3-k)%3][0]+dp[i][0][(j+3-k)%3][1]+dp[i][0][(j+3-k)%3][2]-dp[i][0][(j+3-k)%3][k];
				dp[i+1][1][j][k] = dp[i][1][(j+3-k)%3][0]+dp[i][1][(j+3-k)%3][1]+dp[i][1][(j+3-k)%3][2]+dp[i][0][(j+3-k)%3][k];
				dp[i+1][0][j][k] %= M;
				dp[i+1][1][j][k] %= M;
			}
		}
	}
	
	ll cnt = 0;
	for(int i = 0 ; i < s.size() ; i ++){
		cnt += s[i]-'a';
	}
	cnt %= 3;
	
	ll ret = dp[s.size()][1][cnt][0]+dp[s.size()][1][cnt][1]+dp[s.size()][1][cnt][2];
	
	bool t = true;
	for(int i = 0 ; i+1 < s.size() ; i ++){
		t &= s[i] != s[i+1];
	}
	if(t)ret ++;
	ret %= M;
	cout << ret << endl;
}


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

using namespace std;
using ll = long long;


int main()
{
    int n; cin >> n; n = n % 10;
    if(n == 3) {
        cout << "bon" << endl;
    } else if(n == 0 || n == 1 || n == 6 || n == 8) {
        cout << "pon" << endl;
    } else {
        cout << "hon" << endl;
    }
}

Measured memory_bytes: 3636
path = {1: 0, 2: 0, 3: 0, 4: 0}
odd = 0
for _ in range(3):
    ai, bi = map(int, input().split())
    path[ai] += 1
    path[bi] += 1

for count in path.values():
    if count % 2 == 1:
        odd += 1

if odd == 2:
    print("YES")
else:
    print("NO")


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

const int INF = 1 << 30;
 
int N, P;
vector< tuple< int, int > > g[1000];
 
int T[2][2001];
int dp[1000][1000];
vector< int > ord;
bool v[1000];
int topoidx[1000];
 
int rec(int a, int b)
{
  if(topoidx[a] < topoidx[b]) swap(a, b);
  if(a == N - 1 && b == N - 1) return (0);
  if(~dp[a][b]) return (dp[a][b]);
  int ret = INF;
  if(a == b) {
    for(auto e : g[a]) {
      for(auto f : g[b]) {
        int x1, x2, y1, y2;
        tie(x1, x2) = e;
        tie(y1, y2) = f;
        if(e == f) {
          ret = min(ret, rec(x1, y1) + T[0][x2] + T[1][y2]);
        } else {
          ret = min(ret, rec(x1, y1) + T[0][x2] + T[0][y2]);
        }
      }
    }
  } else {
    for(auto e : g[b]) {
      int x1, x2;
      tie(x1, x2) = e;
      //if(topoidx[x1] < topoidx[a]) {
        ret = min(ret, rec(a, x1) + T[0][x2]);
      //}
    }
  }
  return (dp[a][b] = ret);
}
 
void dfs(int idx)
{
  for(auto to : g[idx]) {
    if(!v[get< 0 >(to)]++) dfs(get< 0 >(to));
  }
  ord.push_back(idx);
}
 
int main()
{
  cin >> N >> P;
  for(int i = 0; i < P; i++) {
    int S, E;
    cin >> S >> E >> T[0][i] >> T[1][i];
    --S, --E;
    g[S].emplace_back(E, i);
  }
  for(int i = 0; i < N; i++) {
    if(!v[i]) dfs(i);
  }
  reverse(ord.begin(), ord.end());
  for(int i = 0; i < N; i++) {
    topoidx[ord[i]] = i;
  }
  g[N - 1].emplace_back(N - 1, 2000);
 
  memset(dp, -1, sizeof(dp));
  cout << rec(0, 0) << endl;
}

Measured memory_bytes: 7148
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
 
check=[-1 for i in range(N)]
  
temp=1
circle=[]
for i in range(K):
  temp=A[temp-1]
  if check[temp-1]==-1:
    check[temp-1]=i
  else:
    circle.append(i-check[temp-1])
    #print(circle)
    break
  #print("temp",temp)
#print((K-i)%len(circle)-1)
if len(circle)!=0:
  amari=(K-i)%circle[0]
  temp=1
  for j in range(i+amari):
    temp=A[temp-1] 

print(temp)

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

int main() {
    int H,A;
    cin >> H >> A;
    if(H%A>0){
        cout << (H/A)+1 << endl;
    }else{
        cout << H/A << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	n %= 1000;
	cout << (1000-n) % 1000;
}

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

int main() {
  int N;
  cin >> N;
  map<ll, ll> m;
  for (int i = 0; i < N; i++) {
    ll A;
    cin >> A;
    m[A]++;
  }

  ll ans = 0;
  for (int i = 0; i <= 100000; i++) {
    ans += m[i] * i;
  }

  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int B, C;
    cin >> B >> C;
    ans -= B * m[B];
    ans += C * m[B];
    m[C] += m[B];
    m[B] = 0;
    cout << ans << endl;
  }
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(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++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int x, y, z;
    cin >> x >> y >> z;
    swap(x, y);
    swap(x, z);
    printf("%d %d %d\n", x, y, z);
    return 0;
}


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

int dp[3003][3003];
string s1,s2;


lli func(lli l1,lli l2){
    if(l1==s1.size() || l2==s2.size()) return 0;
    if(dp[l1][l2]!=-1) return dp[l1][l2];
    if(s1[l1]==s2[l2]) return dp[l1][l2] = 1 + func(l1+1,l2+1);
    lli a=func(l1+1,l2);
    lli b=func(l1,l2+1);
    if(a > b) dp[l1][l2] = a;
    else dp[l1][l2] = b;

    return dp[l1][l2];

}

int main(){
    //string s1,s2;
    cin>>s1>>s2;
    lli i,j,l;

    for(i=0;i<3003;i++){
        for(j=0;j<3003;j++){
            dp[i][j]=-1;
        }
    }
    lli ans=func(0,0);


    vector<char> v;
    i=0;j=0;
    for(i=0;i<=s2.size();i++) dp[s1.size()][i]=0;
    for(i=0;i<=s1.size();i++) dp[i][s2.size()]=0;
    i=0;j=0;
    while(i<s1.size() && j<s2.size()){
        if(dp[i+1][j+1]+1 == dp[i][j] && (dp[i+1][j+1] == max(dp[i+1][j+1] , max(dp[i][j+1], dp[i+1][j])))){
            v.push_back(s2[j]);
            i++;j++;
        }
        else{
            if(dp[i+1][j] > dp[i][j+1]){
                i++;
            }
            else{
                j++;
            }
        }
    }
    for(i=0;i<v.size();i++){
        cout<<v[i];
    }
    cout<<endl;
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> V(N);
  for (int i = N; i > 0; i--) {
    V.at(i - 1) += (N / i) * (N / i) * (N / i);
    int j = i * 2;
    while (j <= N) V.at(i - 1) -= V.at(j - 1), j += i;
  }

  int ans = 0;
  for (int i = 0; i < N; i++) ans += V.at(i) * (i + 1);
  cout << ans << "\n";
}

Measured memory_bytes: 3580
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    ll ans = 0;
    for (int i = 1; i <= n; ++i) {
        for (int j = i; j <= n; j += i) {
            ans += j;
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define Khela ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define llu long long unsigned int
#define pf printf
#define sf scanf
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define pii pair<int ,int>
 
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
 
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}
const int Max=1e9+100;
const int sz=2e5+100;
ll sum[sz];
ll ans[sz];
vector<ll> ad[sz];
void DFS(ll p,ll parent,ll last)
{
    ans[p]=sum[p]+last;
    for(auto xx: ad[p])
    {
        if(xx != parent){
            DFS(xx,p,ans[p]);
        }
    }
}
int main()
{
    Khela
    ll a,b,c,i,j,k,q,p,x,y,ct,ct1,m,l,r,x1,y1,mn,h,sum1,in,z,mid,n,mx;
    char ch;
    double d;
    string str1,str2,str;
    bool bl,bl1;
    int t,cs=1;
    while(cin>>n>>m)
    {
        for(i=0;i<=n;i++) ad[i].clear();
        for(i=1;i<n;i++){
            cin>>p>>q;
            ad[p].push_back(q);
            ad[q].push_back(p);
        }

        memset(sum,0,sizeof sum);
        memset(ans,0,sizeof ans);
        
        while(m--)
        {
            cin>>p>>q;
            sum[p]+=q;
        }

        DFS(1ll,-1,0ll);
        for(i=1;i<=n;i++) cout<<ans[i]<<" ";
        cout<<endl;
        
    }




}

Measured memory_bytes: 25856
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define MOD7 1000000007
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
bool IsPrime(int num){
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2) if (num % i == 0) return false;
    return true;
}
int main(){
    int X;
  	cin >> X;
    for(int x = X; ; x++){
        if(IsPrime(x)){
            cout << x << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3532
// A.cpp
#include <bits/stdc++.h>

using namespace std;

int main()
{
	int n, m, A, B;
	scanf("%d%d%d%d", &n, &m, &B, &A);
	for (int i = 1; i <= n; i++, puts(""))
		for (int j = 1; j <= m; j++)
			if ((i <= A) ^ (j <= B))
				printf("1");
			else
				printf("0");
	return 0;
}

Measured memory_bytes: 3640
#include<stdio.h>
int main(){
  int n;
  scanf("%d", &n);
  int a[n],b[n],i,j;
  for(i=0;i<n;i++){
    scanf("%d", &a[i]);
    b[i]=0;
  }
  int count=0,sum;
  for(i=n-1;i>=0;i--){
    sum=0;
    for(j=i;j<n;j+=i+1){
      sum+=b[j];
    }
    if(sum%2!=a[i]){
      b[i]=1;
      count++;
    }
  }
  printf("%d\n", count);
  if(count!=0){
    for(i=0;i<n;i++){
      if(b[i]==1){
        printf("%d ", i+1);
      }
    }
  }
  return 0;
}

Measured memory_bytes: 2432
#include <algorithm>
#include <iostream>
#include <numeric>

using namespace std;

int round10(int x) {
  int r = x % 10;
  return r ? x - r + 10 : x;
}

int main() {
  int time[5];
  for (int i = 0; i < 5; i++) {
    cin >> time[i];
  }
  int index[5];
  iota(index, index + 5, 0);

  int ans = 10000;
  do {
    int tmp = 0;
    for (int i = 0; i < 4; i++) {
      tmp += round10(time[index[i]]);
    }
    tmp += time[index[4]];
    ans = min(ans, tmp);
  } while (next_permutation(index, index + 5));

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

signed main() {
    string station = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    int n;
    while(cin >> n, n) {
        vector<int> a(n);
        rep(i,0,n) cin >> a[i];
        string s; cin >> s;
        string ans = "";

        int k = 0;
        rep(i,0,s.length()) {
            int idx;
            if('A' <= s[i] && s[i] <= 'Z') idx = s[i] - 'A' + 26;
            else idx = s[i] - 'a';
            // cout << (idx - a[k] + 52) % 52 << endl;
            ans += station[ (idx - a[k] + 52) % 52 ];
            k = (k + 1) % n;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3124
#include<stdio.h>



int parent(int i){
  return (i/2);
  }
int left(int i){
  return 2*i;
}
int right(int i){
  return (2*i + 1);
}

int main( ){
  int i,n,pk,lk,rk;
  int T[100001];
  
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&T[i]);
  }

  for(i=1;i<=n;i++){
    printf("node %d: key = %d, ",i,T[i]);
    pk = parent(i);
    if(pk > 0) printf("parent key = %d, ",T[pk]);
    lk = left(i);
    if(lk <= n) printf("left key = %d, ",T[lk]);
    rk = right(i);
    if(rk <= n) printf("right key = %d, ",T[rk]);
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2028
import java.util.Scanner;
class Main{
  public static void main(String[] args){
  Scanner scanner = new Scanner(System.in);
  
  for(int i = 1; ; i++){
      int x = scanner.nextInt();
      if(x == 0){
          break;
      }
      System.out.println("Case " + i + ": " + x);
    }
  }
}

Measured memory_bytes: 42516
#include <stdio.h>

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

Measured memory_bytes: 1008
//Anshul Gupta


#include<iostream>
#include <fstream>
#include<algorithm>
#include<vector>
#include<utility>
#include<climits>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<assert.h>
#include<iomanip>

using namespace std;
	
#define f first
#define s second
#define sz(a) int((a).size()) 
#define pb push_back 
#define mp make_pair
#define all(c) (c).begin(),(c).end() 
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++) 
#define present(c,x) ((c).find(x) != (c).end()) 
#define cpresent(c,x) (find(all(c),x) != (c).end()) 
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);

typedef long long ll;

typedef struct node{
	ll val,more=0,less=0;
	bool operator <(const node& a){
		return val<a.val;
	}
}node;

typedef pair<int,int> pi;
typedef pair<pi,int> pii;
typedef pair<pi,pi > pi2;

typedef pair<ll,ll> pl;
typedef pair<pl,ll> pll;
typedef pair<pl,pl > pl2;

typedef vector<node> vn;

typedef vector<int> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
typedef vector<pi2 > vpi2;

typedef vector<ll> vl;
typedef vector<pl> vpl;
typedef vector<pll> vpll;
typedef vector<pl2 > vpl2;

const int M=1000000007;


int main(){

	int n,k;
	cin>>n>>k;
	/*ll div=pow(n/k,3);
	if(k&1){
		return cout<<div,0;
	}
	ll fac=pow((n-1)/k+1,3);
	ll r=3*k/2;
	ll temp=(r+2)*(r+1)*r/6-3*(r-k+2)*(r-k+1)*(r-k)/6;
	temp*=fac;
	if(n%k==0){
		temp+=(r)
	}*/

	ll f=0,h=0;
	f=n/k;
	h=((!(k&1))?f + (n%k>=k/2):0);

	cout<<(ll)pow(f,3)+(ll)pow(h,3);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n;
	scanf("%d", &n);
	char a[105], b[105];
	scanf("%s %s", a, b);
	char c[1005];
	int k = 0;
	for (int i = 0; i < n; i++) {
		c[k++] = a[i];
		c[k++] = b[i];
	}
	for (int i = 0; i < k; i++) {
		printf("%c", c[i]);
	}cout << endl;
	return 0;
}

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

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

int main(){
  int  x; cin>>x;
  while(!is_prime(x))x++;
  cout<<x<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

int main(){
    int num[3]={0};
    for (int i=0;i<3;i++) cin >> num[i];
    sort(num,num+3);

    int res=0;
    while (num[0] < num[1]){
	num[0]+=2;
	res++;
    }
    while (num[0] < num[2]){
	num[0]++;
	num[1]++;
	res++;
    }

    if (num[0] == num[1]){
	cout << res << endl;
    } else if (num[1] == num[2]){
	cout << res+1 << endl;
    } else {
	cout << res+2 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

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

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n, m := nextInt(), nextInt()
	a := nextInts(n)

	r := make([]int, n)
	for i := range r {
		if i > 0 {
			r[i] = r[i-1]
		}
		r[i] = (r[i] + a[i]) % m
	}

	ans := 0
	mp := map[int]int{}
	for i := 0; i < n; i++ {
		mp[r[i]]++
		if r[i] == 0 {
			ans++
		}
	}
	for _, v := range mp {
		ans += v * (v - 1) / 2
	}

	puts(ans)
}


Measured memory_bytes: 8576
n, a, b = map(int, input().split())
if a > b:
    print(0)
    exit()
elif a == b:
    print(1)
    exit()
elif n == 1 and b - a > 0:
    print(0)
    exit()
elif n == 2:
    print(1)
    exit()
else:
    mid_num = n - 2
    num_num = b - a + 1
    ans = 0
    ans += (num_num-1) * (mid_num-1) + num_num
    print(ans)


Measured memory_bytes: 3060
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let a: i64 = read(&mut stdin_lock, &mut buf, b' ');
    let b: i64 = read(&mut stdin_lock, &mut buf, b' ');
    let c: i64 = read(&mut stdin_lock, &mut buf, b'\n');

    let ans = if a + b + c >= 22 { "bust" } else { "win" };
    println!("{}", ans);
}


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

#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ll long long
#define ld long double
#define pb push_back
#define MOD 1000000007
#define LLMN LONG_LONG_MIN
#define LLMX LONG_LONG_MAX
#define LDMX LDBL_MAX
#define LDMN LDBL_MIN
#define MAX 1000000
#define pll pair<ll, ll>
#define vl vector<ll>
#define vll vector< vector<ll> >
#define vb vector<bool>
#define vbb vector< vector<bool> >


ll mulmod(ll, ll);
ll fastpower(ll, ll);
void getprime(vector<bool>&);
void getfact(vector<ll>&, vector<ll>&);
ll ncr(ll, ll, vector<ll>&, vector<ll>&);

void solve()
{
	ll n;
	cin>>n;
	string s;
	cin>>s;
	ll w = 0, res = 0;
	for(auto i : s)
	    if(i == 'W')
	        w++;
	for(int i = 0; i < w; i++)
	{
	    if(s[n - 1 - i] == 'R')
	        res++;
	}
	cout<<res<<"\n";
}

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

ll mulmod(ll a, ll b)
{
	ll res = 0; 
	a = a % MOD;
	while(b > 0)
	{
		if (b % 2 == 1)
			res = (res + a) % MOD;
 
		a = (a * 2) % MOD; 
		b /= 2;
	} 
	return res % MOD; 
}

ll  fastpower(ll a, ll n)
{
	ll res = 1;
	while(n > 0)
	{
		if(n % 2 != 0)
		{
			res = (res * a) % MOD;
		}
		n /= 2;
		a = (a * a) % MOD;
	}
	return res;
}

void getprime(vector<bool>&prime)
{
	prime[0] = false;
	prime[1] = false;
	
	for(ll i = 2; i * i <= MAX; i++)
	{
		if(prime[i])
		{
			for(ll j = i*i; j <= MAX; j += i)
				prime[j] = false;
		}
	}
}

void getfact(vector<ll> &fact, vector<ll> &ifact)
{
	fact[0] = 1;
	ifact[0] = 1;
	
	for(ll i = 1; i <= MAX; i++)
	{
		fact[i] = (fact[i-1] * i)%MOD;
		ifact[i] = (ifact[i-1] * fastpower(i, MOD -2) )%MOD;
	}
}

ll ncr(ll n, ll r, vector<ll>&fact, vector<ll>&ifact)
{
	ll res;
	res = (((fact[n] * ifact[r]) % MOD) * ifact[n-r]) % MOD;
	return res;
}

Measured memory_bytes: 3672
import numpy as np

N, M = map(int, input().split())



num_list = np.zeros((N,3))
for i in range(N):
	num_list[i] = list(map(int, input().split()))

num_list = num_list.T

ans = max(
	np.sum(np.sort(num_list[0,:] + num_list[1,:] + num_list[2,:])[::-1][:M]),
	np.sum(np.sort(num_list[0,:] + num_list[1,:] - num_list[2,:])[::-1][:M]),
	np.sum(np.sort(num_list[0,:] - num_list[1,:] + num_list[2,:])[::-1][:M]),
	np.sum(np.sort(num_list[0,:] - num_list[1,:] - num_list[2,:])[::-1][:M]),
	np.sum(np.sort(-num_list[0,:] + num_list[1,:] + num_list[2,:])[::-1][:M]),
	np.sum(np.sort(-num_list[0,:] + num_list[1,:] - num_list[2,:])[::-1][:M]),
	np.sum(np.sort(-num_list[0,:] - num_list[1,:] + num_list[2,:])[::-1][:M]),
	np.sum(np.sort(-num_list[0,:] - num_list[1,:] - num_list[2,:])[::-1][:M])
)
print(int(ans))


Measured memory_bytes: 12520
#include<bits/stdc++.h>
using namespace std;
#define flb(i,a,b) for(int i=a;i<b;i++)
#define ll long long int
#define mp make_pair
#define pb push_back
#define inf (long long)(1e18+1e15)
typedef pair<int,int> ii;
typedef vector <ll> vi;
typedef vector <pair<int,int> > vii;
typedef vector <vector <int> > vvi;
    int calculated[3001][3001];
int main()
{
    string s,t;
    cin>>s>>t;
    int n=s.size(),m=t.size();
    memset(calculated,-1,sizeof(calculated));
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(i==0||j==0)
                calculated[i][j]=0;
            if(s[i-1]==t[j-1])
            {
                calculated[i][j]=1+calculated[i-1][j-1];
            }
            else
                calculated[i][j]=max(calculated[i-1][j],calculated[i][j-1]);
        }
    }
    int i=n,j=m;
    string temp;
    while(i>0&&j>0)
    {
        if(s[i-1]==t[j-1])
        {
            temp.push_back(s[i-1]);
            i--;
            j--;
        }
        else if(calculated[i-1][j]>calculated[i][j-1])
            i--;
        else
            j--;
    }
    reverse(temp.begin(),temp.end());
    cout<<temp;
}


Measured memory_bytes: 35456
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int> > Matrix;

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

long long lcm(int a, int b){
  return (long long)a * b / gcd(a, b);
}

int main(){
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll e = a - (a/c + a/d) + a/lcm(c, d);
  ll f = b - (b/c + b/d) + b/lcm(c, d);

  ll ans = f - e;
  if ((a%c) && (a%d)) ans++;
  cout << (ll)ans << endl;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
H=list(map(int,input().split()))

dellist=[]

for i in range(M):
    A,B=map(int,input().split())
    a=H[A-1]
    b=H[B-1]
    if a==b:
        dellist.append(A)
        dellist.append(B)
    else:
        if a>b:
            dellist.append(B)
        else:
            dellist.append(A)
del_sort=set(dellist)
print(N-len(del_sort))

Measured memory_bytes: 19988
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

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

    int min_a = A[0]; unordered_map<int, int> profit;
    REP(i, 1, N) {
        if (min_a < A[i]) {
            profit[A[i] - min_a]++;
        } else {
            min_a = A[i];
        }
    }

    int max_p = 0, max_cnt = 0;
    for (auto &p : profit) {
        if (max_p < p.first) {
            max_p = p.first;
            max_cnt = p.second;
        }
    }
    cout << max_cnt << endl;
    return 0;
}

Measured memory_bytes: 7684
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);  
	cin.tie(NULL);
	int n;
	string s,t; cin>>n>>s>>t;
	vector<int> v1[n];
	vector<int> v2[n];
	for(int i=0;i<n;i++){
		for(int j=i;j<n;j++){
			v1[i].push_back(int(s[j]));
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<=i;j++){
			v2[i].push_back(int(t[j]));
		}
	}
	bool flag = false;int p;
	for(int i=0;i<n;i++){
		bool check = true;
		for(int j=0;j<v1[i].size();j++){
			if(v1[i][j]!=v2[n-i-1][j]){
				check = false; break;
			}
		}
		if(check==true){
			flag = true; p = n-i-1;
			break;
		}
	}
	if(flag==true){
		int ans = 2*n - v2[p].size();
		cout<<ans<<endl;
	}
	else{
		cout<<2*n<<endl;
	}
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF (1 << 30 - 1)
#define LLINF (1LL << 60)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    double b;
    cin >> A >> b;
  	B = round(b * 100);
    cout << (A * B) / 100LL << endl;
}


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

int main() {
  int N;
  cin >> N ;
  int judge=0;

  // ここにプログラムを追記
  
  for (int i=0;i<N;i++){
    string S;
    cin >> S ;
    if (S=="Y"){
      judge =1;
    }
    
  }
  if (judge==1){
  cout << "Four" << endl;
  }
  else{
    cout << "Three" << endl;

  }
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s1,s2;
char c[105];
int main(){
	cin >> s1 >> s2;
	for(int i=1;i<=s1.size();i++){
		c[2*i-2]=s1[i-1];
		c[2*i-1]=s2[i-1];
	}
	for(int i=1;i<=s1.size()+s2.size();i++){
		printf("%c",c[i-1]);
	}
}

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

#define rep0(i, n) for(int i=0; i<(int)(n);i++)
#define rep1(i, n) for(int i=1; i<=(int)(n);i++)
#define all(x) (x).begin(), (x).end()
#define debug(a) if(flagdebug){cout << "debug (" #a "):" << endl << (a) << endl;}

typedef uint64_t ulint;
typedef int64_t lint;
using namespace std;

lint 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;
bool flagdebug = false;

int main(){
//////////////////////////////////////////////////////
    // flagdebug = true;

    lint a, b;

    cin >> a >> b;

    if( a <= b)
    {
        cout << "unsafe" << endl;
    }
    else
    {
        cout << "safe" << endl;
    }



//    cout << 0 << endl;

//////////////////////////////////////////////////////
// Ctrl + Opt + N to make
    return 0;
}


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

vector<int>E[200000];
int d[200000];

void dfs(int v){
	for(int u:E[v]){
		if(d[u]==-1){
			d[u]=d[v]+1;
			dfs(u);
		}
	}
}
vector<int>ans;
int cnt=1;

bool dfs2(int v,int p){
	ans.push_back(cnt++);
	vector<int>c;
	for(int u:E[v]){
		if(u==p)continue;
		c.push_back(u);
	}
	if(c.size()==0)return 1;
	int id=-1;
	rep(i,c.size()){
		int u=c[i];
		if(E[u].size()!=1){
			if(id!=-1)return 0;
			id=u;
		}
		else{
			if(i==c.size()-1&&id==-1){
				ans.push_back(cnt++);
			}
			else{
				int d=ans.back();ans.pop_back();
				ans.push_back(cnt++);
				ans.push_back(d);
			}
		}
	}
	if(id!=-1)return dfs2(id,v);
	return 1;
}
int main(){
	int n;scanf("%d",&n);
	rep(i,n-1){
		int a,b;scanf("%d%d",&a,&b);a--;b--;
		E[a].push_back(b);
		E[b].push_back(a);
	}
	memset(d,-1,sizeof(d));
	d[0]=0;dfs(0);
	int u=max_element(d,d+n)-d;
	memset(d,-1,sizeof(d));
	d[u]=0;dfs(u);
	int v=max_element(d,d+n)-d;
	if(!dfs2(u,-1)){
		puts("-1");return 0;
	}
	vector<int>res1=ans;
	ans.clear();
	cnt=1;
	dfs2(v,-1);
	if(res1<ans)ans=res1;
	rep(i,ans.size()){
		if(i)printf(" ");
		printf("%d",ans[i]);
	}
	puts("");
}

Measured memory_bytes: 22648
#include<iostream>
#include<string.h>
using namespace std;

#define MAX_N 1000000

int main(){
	int dp[MAX_N];
	int n,m,c[100];

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

	cin>>n>>m;

	for(int i=1;i<=m;i++){
		cin>>c[i];
	}

	for(int i=1;i<=m;i++){
		dp[c[i]]=1;
	}

	for(int i=1;i<=20;i++){
		for(int j=1;j<=n;j++){
			if(dp[j]!=-1){
				for(int k=1;k<=m;k++){
					if(dp[j+c[k]]==-1 || dp[j+c[k]] > dp[j]+1){
						dp[j+c[k]] = dp[j] + 1;
					}
				}
			}
		}
	}

	cout<<dp[n]<<endl;

	return 0;
}

Measured memory_bytes: 5072
#include <bits/stdc++.h>
#define ll long long int
#define i(a,n) int a=n;
#define l(a,n) ll a=n;
#define d(a,n) double a=n;
#define s(a) string a;
#define c(a) ll a; cin>>a;a
#define cd(a) double a; cin>>a;
#define cs(a) string a; cin>>a;
#define ci(a) cin>>a;
#define co(a) cout<<a;
#define cos(a) cout<<a<<" ";
#define con(a) cout<<a<<endl;
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define nl cout<<endl;
#define ca(arr,n) for(ll i=0;i<n;i++) cin>>arr[i];
#define f0(i,a,n) for(ll i=a;i>=n;i--)
#define f(i,n) for(ll i=0;i<n;i++)
#define f1(i,a,n) for(ll i=a;i<n;i++)
#define T ll t=1; cin>>t; while(t--)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;

int main()
{
    fast;
    int x;
    cin>>x;
    if(x>=30) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

/*It's not who I am underneath, but what I do that defines me

MMMMMMMMMMMMMMMMMMMMM.                             MMMMMMMMMMMMMMMMMMMMM
 `MMMMMMMMMMMMMMMMMMMM           M\  /M           MMMMMMMMMMMMMMMMMMMM'
   `MMMMMMMMMMMMMMMMMMM          MMMMMM          MMMMMMMMMMMMMMMMMMM'
     MMMMMMMMMMMMMMMMMMM-_______MMMMMMMM_______-MMMMMMMMMMMMMMMMMMM
      MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
      MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
      MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
     .MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM.
    MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
                   `MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM'
                          `MMMMMMMMMMMMMMMMMM'
                              `MMMMMMMMMM'
                                 MMMMMM 
                                  MMMM
                                   MM
*/


Measured memory_bytes: 3652
import sys

N=int(sys.stdin.readline().rstrip())
HList=list(map(int, sys.stdin.readline().split()))

jumpNum=0
maxJumpNum=0
hBefore=HList[0]
for i in range(1,N):
  if HList[i] <= hBefore:
    jumpNum+=1
  else:
    maxJumpNum=max(maxJumpNum,jumpNum)
    jumpNum=0
  hBefore=HList[i]
maxJumpNum=max(maxJumpNum,jumpNum)

print(maxJumpNum)
  

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

int main() {
  
  for (int i = 0; i < 3000; i++) {
    
    int x, y; cin >> x >> y;
    
    if (x == 0 && y == 0) {
      break;
    }
    
    cout << min(x, y) << " " << max(x, y) << endl;
    
  }
  
}


Measured memory_bytes: 2980
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
using namespace std;
int main(void){
    int n,d,x,a;
    int cnt=0;
    cin >> n >> d >> x;
    rep(i, n){
        cin >> a;
        int D=1;
        cnt+=1;
        while(true){
            D+=a;
            if (D>d) break;
            cnt+=1;
            //cout << D << cnt << endl;
        }
    }
    cout << cnt+x << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
using namespace std;

int read(){
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	return x*f;
}

char c[10000];
int main(){
	int k,m,n;
	n=read();
	scanf("%s",c+1);
	if(n>=3200){
		printf("%s",c+1);
	}
	else printf("red");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s;
    int k;
    cin >> s >> k;
    vector<string> v;
    int n = s.size();
    rep(i,n) rep2(j,1,min(n-i+1,6)) {
        v.pb(s.substr(i,j));
    }
    sort(all(v));
    int cnt = 1;
    string ns = v[0];
    if(k == 1) {
        cout << ns << endl;
        return 0;
    }
    rep2(i,1,v.size()) {
        if(ns == v[i]) continue;
        cnt++;
        if(cnt == k) {
            cout << v[i] << endl;
            return 0;
        }
        ns = v[i];
    }
}


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

int main() {
int64_t h, w;
cin >> h >> w;
  if (h==1 || w==1){
    cout << 1 << endl;
    return 0;
  }

if(h*w%2==0){
cout << h*w/2 << endl;
}
if(h*w%2 != 0){
    cout << h*w/2+1 << endl;
}

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
// DONT USE MEMSET, USE VECTORS

void solve(){
	int a,b,h;
	cin>>a>>b>>h;
	if(a>b) swap(a,b);
	int dif = b-a;
	int ans = a*h + h/2*(dif);
	cout<<ans<<endl;
}

int main(){
	fastread;
	int t = 1;
	// cin>>t;
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s[3];cin>>s[0]>>s[1]>>s[2];
  int now=0;
  int point[3]={};
  while(1){
    if(point[now]==s[now].size())break;
    int a=now;
    now=s[now][point[now]]-'a';
point[a]++;
  }
  cout<<(char)(now+'A')<<endl;
  return 0;
}


Measured memory_bytes: 256
mod = 10**9+7
n,a,b = map(int,input().split())
ans = pow(2,n,mod)-1

comb1 = 1 
for i in range(n-a+1,n+1):
  comb1 *= i
  comb1 %= mod
for i in range(1,a+1):
  comb1 *= pow(i,mod-2,mod)
  comb1 %= mod

comb2=1
for i in range(n-b+1,n+1):
  comb2 *= i
  comb2 %= mod
for i in range(1,b+1):
  comb2 *= pow(i,mod-2,mod)
  comb2 %= mod
  
ans -= (comb1+comb2)
ans %= mod
print(ans)


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

using namespace std;

#define lp(i,n) for(int i = 0; i <n;i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define MP make_pair
#define SZ(v) ((int)((v).size()))
typedef long long ll;

const ll MOD = 1e9 + 7;
const int OO = (int)1e6;
const int N = (int)1e7;

void init(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main() {
	#   ifdef LOCAL_PROJECT
        freopen("in.txt", "r", stdin);
    #   endif
    int l,r;
    scanf("%d%d",&l,&r);
    int mn =1e9+9;
    r = min(l+2019,r);
    for(int i=l;i<r;i++){
        for(int j=i+1;j<=r;j++){
            mn=min(mn,(i%2019)*(j%2019)%2019);
        }
    }
    cout<<mn;
    return 0;
}

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

int main() {

  long long int input, l;

  while( true ) {

    cin >> input >> l;

    if ( input == 0 && l == 0 ) break;

    vector< long long int > a;
    a.push_back( input );

    for ( int i = 0; true; i++ ) {
      long long int c = a[i];

      vector< int > v;
      for ( int j = 0; j < l; j++ ) {
	v.push_back( c % 10 );
	c /= 10;
      }

      sort( v.begin(), v.end() );

      long long int ma = 0;
      long long int mi = 0;

      for ( int j = 0; j < l; j++ ) {
	ma = ma * 10 + v[ v.size() - 1 - j ];
	mi = mi * 10 + v[ j ];
      }

      a.push_back( ma - mi );

      bool flag = false;
      for ( int j = 0; j < a.size() - 1; j++ ) {
	if ( a[j] == a[ a.size() - 1 ] ) {
	  cout << j << " " << a[j] << " " << a.size() - j - 1 << endl;
	  flag = true;
	  break;
	}
      }
      if ( flag ) break;

    }

  }

  return 0;

}

Measured memory_bytes: 1220
#include<bits/stdc++.h>
using namespace std;
int main() {
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  while(a>0 && c>0) {
    c-=b;
    if (c<=0) break;
    a-=d;
  }
  if (c<=0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, s, n) for(int i = s; i < n; i++)
#define rrep(i, s, n) for(int i = s; i > (s)-(n); i--)
#define pr(s) std::cout << s << std::endl
#define prb(s) std::cout << s
using namespace std;



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


  int a, b, x;
  cin >> a >> b >> x;

  pr((a <= x && x <= a + b ? "YES" : "NO"));

  return 0;
}


Measured memory_bytes: 256