akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int h,w,n;cin >> h >> w >> n;
    int cnt = 0;
    if(h > w)
    {
        while(n > 0)
        {
            cnt++;
            n -= h;
        }
    }
    else
    {
        while(n > 0)
        {
            cnt++;
            n-= w;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;//list用
using System.Text;//StringBuilder用
using System.Collections;
using System.Linq;
class Program
{
static int result;
static List<int> s=new List<int>();
  static List<int> t=new List<int>();
  static int N;
  
    static void Main()
    {
      N=int.Parse(Console.ReadLine());
  Read();
s.Sort();
      result=s[N/2]-s[N/2-1];
                    Console.WriteLine(result.ToString());
    }

static void Read()
{
  string[] tmp=Console.ReadLine().Split(' ');
for(int i=0;i<N;i++){s.Add(int.Parse(tmp[i]));}
}
}

Measured memory_bytes: 17504
#include<cstdio>
#include<algorithm>
int A[50005], C[25];
using namespace std;
int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 0; i < m; i++)
        scanf("%d", &C[i]);
    for (int i = 1; i <= n; i++) 
        A[i] = 1e10;
    A[0] = 0;
    for (int i = 0; i < m; i++)
        for (int v = C[i]; v <= n; v++)
            A[v] = min(A[v], A[v - C[i]] + 1);
    printf("%d\n", A[n]);
    return 0;
}


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e17;
int n;
ll a[55], ans, ma, mi;
bool check()
{
    for (int i = 0; i < n; i++) {
        if (a[i] >= n) return false;
    }
    return true;
}
int max_id()
{
    ll ma = 0;
    int maxi = -1;
    for (int i = 0; i < n; i++) {
        if (a[i] > ma) {
            ma = a[i];
            maxi = i;
        }
    }
    return maxi;
}
int min_id()
{
    ll mi = INF;
    int mini = -1;
    for (int i = 0; i < n; i++) {
        if (a[i] < mi) {
            mi = a[i];
            mini = i;
        }
    }
    return mini;
}
int main()
{
    scanf("%d", &n);
    ma = 0;
    for (int i = 0; i < n; i++) {
        scanf("%lld", &a[i]);
        ma = max(ma, a[i]);
        mi = min(mi, a[i]);
    }
    if (ma < n * (n + 1)) {
        while (!check()) {
            int t = max_id();
            for (int i = 0; i < n; i++) {
                if (i != t) a[i]++;
                else a[i] -= n;
            }
            ans++;
        }
        printf("%lld\n", ans);
    }
    else {
        int t1 = max_id(), t2 = min_id();
        while (a[t1] - a[t2] > 1000) {
            //printf("max: a[%d] = %lld, min: a[%d] = %lld\n", t1, a[t1], t2, a[t2]);
            ll x = (a[t1] - a[t2]) / (n + 1);
            a[t1] -= n * x;
            a[t2] += x;
            for (int i = 0; i < n; i++) {
                if (i != t1 && i != t2) a[i] += x;
            }
            t1 = max_id(), t2 = min_id();
            ans += x;
        }
        t2 = min_id();
        ll st = a[t2] - n;
        for (int i = 0; i < n; i++) {
            a[i] -= st;
        }
        ans += st * n;
        while (!check()) {
            int t = max_id();
            for (int i = 0; i < n; i++) {
                if (i != t) a[i]++;
                else a[i] -= n;
            }
            ans++;
        }
        printf("%lld\n", ans);
    }
    return 0;
}


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

int main(){
    int n; cin >> n;
    vector<int> t(n+1), x(n+1), y(n+1);

    x[0] = y[0] = t[0] = 0;
    rep(i,n){
        cin >> t[i+1] >> x[i+1] >> y[i+1];
    }

    for(int i = 0; i < n; i++){
        int l = abs(x[i] - x[i+1]) + abs(y[i] - y[i+1]);
        if(l > t[i+1]){
            put("No");
            return 0;
        }else if(abs(abs(t[i+1] - t[i]) - l) % 2 == 1){
            put("No");
            return 0;
        }
    }
    put("Yes");
}

Measured memory_bytes: 1408
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn solve() {
    input! {
        n: usize,
        pv: [usize; n]
    };

    let mut res = 0;
    let mut min = std::usize::MAX;
    for p in pv {
        if p <= min {
            res += 1;
        }
        min = min.min(p);
    }
    println!("{}", res);
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


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

pow_list = [pow(6, x) for x in range(0, 7)]
for i in range(0, 6):
    pow_list.append(pow(9, i))

dp = [1000000 for _ in range(0, N + 1)]
dp[0] = 0

for pow in pow_list:
    for i in range(pow, N + 1):
        dp[i] = min(dp[i], dp[i - pow] + 1)

print(dp[-1])

Measured memory_bytes: 7064
//??????????????????
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N;
	cin>>N;
	vector<int> A(N);
	for(int i=0; i<N; ++i){
		cin>>A[i];
	}
	
	int kaisuu=0;
	for(int i=0;i<N-1;++i){
		for(int j=0;j<N-1-i;++j){
			if(A[j]>A[j+1]){
				swap(A[j],A[j+1]);
				kaisuu++;
			}
		}
	}

	for(int i=0; i<N-1;++i){
		cout<<A[i]<<" ";
	}
	cout<<A[N-1]<<endl;
	cout<<kaisuu<<endl;
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define sort(v,n) sort(v,v+n);
#define vsort(v) sort(v.begin(),v.end());
#define vvsort(v) sort(v.begin(),v.end(),greater<int>());
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
typedef pair<int,int> p;
typedef pair<ll,ll> lp;
typedef priority_queue<int> pq;
typedef priority_queue<int,vector<int>,greater<int> > rpq;
bool is_uruu(int y) {
        return y % 4 == 0 && (y % 100 != 0 || y % 400 == 0);
}
const ll MOD=1e9+7;
const double PI=acos(-1.0);
//----------------------------------------------------------------------------------------------------------------------------------//
int n;
int a[100001];
int main(){
        cin>>n;
        int k=0;
        for(int i=0; i<n; i++) {
                cin>>a[i];
                if(a[i]%2==1) {
                        k++;
                }
        }
        if(k%2==0) {
                cout<<"YES"<<endl;
                return 0;
        }else{
                cout<<"NO"<<endl;
                return 0;
        }
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define pb push_back
#define pf push_fron
#define INF 1e9
#define PI acos(-1)
typedef long long ll;



int main() {
	
	int a, b, k;
	bool flag = false;
	cin >> a >> b >> k;
	if (k >= (b - a + 2) / 2) {
		for (int i = a; i <= b; i++) {
			cout << i << endl;
		}
	}
	else {

		for (int i = 0; i < k; i++) {
			cout << a + i << endl;
		}
		for (int i = k - 1; i >= 0; i--) {
			cout << b - i << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
import heapq
from operator import itemgetter
from bisect import bisect_right
N, Q = map(int, input().split())
Stop = []
for i in range(N):
    S, T, X = map(int, input().split())
    Stop.append([S - X, X, 0, i])
    Stop.append([T - X, X, 1, i])
Stop.sort(key=itemgetter(0))
q = []
notClosed = [False]*N
A = [(-1, -1)]
for time, pos, lr, idx in Stop:
    if lr==0:
        heapq.heappush(q, (pos, idx))
    else:
        notClosed[idx] = True
        while len(q)>0 and notClosed[q[0][1]]:
            aaa = heapq.heappop(q)[1]

    if len(q):
        A.append((time, q[0][0]))
    else:
        A.append((time, -1))
A0 = list(map(itemgetter(0), A))
for _ in range(Q):
    D = int(input())
    idx = bisect_right(A0, D)

    print(A[idx-1][1])


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

int main()
{
	int N,T,c,t,c2=0,n=0;

	cin >> N>>T;

	for (int i = 0; i < N; i++) {
		cin >> c >> t;

		if (t <= T) {
			if (c2 == 0) {
				c2 = c;
			}
			if (c < c2) {
				c2 = c;
			}
		}
	}

	if(c2==0){
		cout << "TLE" << endl;
	}
	else {
		cout << c2 << endl;;
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{

     public static void main(String []args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        String ans="";
        int n1=n/100;
        int n2=n%100;
        if(n2>n1*10+n1){
            System.out.println((n1+1)*100+(n1+1)*10+n1+1);    
        }else{
            System.out.println(n1*100+n1*10+n1);
        }
    
        
     }
}

Measured memory_bytes: 21716
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Pipes;
using System.Linq;
using System.Numerics;
using System.Reflection.Metadata;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Intrinsics.X86;
using System.Text;
using System.Threading;

namespace AtCoder
{
	public class Program
	{
		private const long p_ = 1000000007;
		static void Main()
		{
			long n = long.Parse(Console.ReadLine());

			long ans = 1;
			for (long i = 1; i <= n; i++) {
				ans = ans * i % p_;
			}

			Console.WriteLine(ans);
		}
	}
}


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

int main()
{
string s;
int zero=0,one=0,a,i;
cin>>s;
for(i=0;i<s.size();i++)
{
   a=s[i]-'0';
   if(i%2==1&&a==0)
    zero++;
   else if(i%2==0&&a==1)
    zero++;

}

for(i=0;i<s.size();i++)
{
   a=s[i]-'0';
   if(i%2==1&&a==1)
    one++;
   else if(i%2==0&&a==0)
    one++;

}
cout<<min(zero,one);

}


Measured memory_bytes: 3744
#include <cstdio>

using namespace std;

int main()
{
 int n;

 while (scanf("%d", &n) && n != -1){
  if (n == 0) printf("0\n");
  else {
   bool flag = false;
   for (int i = 30; i >= 0; i -= 2){
    if ((n >> i) & 3 || flag){
     printf("%d", (n >> i) & 3);
     flag = true;
    } 
   }
   printf("\n");
  }
 }
 return (0);
}

Measured memory_bytes: 1044
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int k,a,b=0;
    cin >> k >> a >> b;

    for (int i = k*(a/k); i <=b; i+=k)
    {
        if(i>=a and i<=b)
        {
            cout << "OK" << endl;
            return 0;
        }    
    }

    cout << "NG" << endl;

    return 0;
}

Measured memory_bytes: 3636
def main():
    _, K = [int(x) for x in input().split()]
    A = [int(x) for x in input().split()]
    history = [1]
    # 場所: index
    history_dict = {1:0}
    last_city = -1
    for x in range(K):
        now = A[history[-1]-1]
        # print(now)
        if now in history_dict:
            last_city = now
            break
        history.append(now)
        history_dict[now] = x+1

    if last_city == -1:
        print(history[-1])
    
    else:
        index = history_dict[last_city]
        mod = (K - index) % (len(history) - index)
        # print(index, len(history) - index, mod)
        print(history[index + mod]) 

if __name__ == "__main__":
    main()


Measured memory_bytes: 32328
#include <bits/stdc++.h>
using namespace std;
int main() {
  int c[10] = {0,2,5,5,4,5,6,3,7,6};  
  int n, m;
  cin >> n >>m;
  vector<int>a(m);
  for (int i = 0; i <m; ++i) cin >> a[i];
  vector<string>dp(n + 10, "");
  auto cmp =[](string a, string b) {
    if (a.size() != b.size()) return a.size() < b.size();
    for (int i = 0; i < a.size(); ++i)
      if (a[i] != b[i])
        return a[i] < b[i];
    
    return false;
  };
  for (int i = 0; i < n; ++i)
    if (i > 0 && dp[i].size() == 0) continue;
  	else {
    	for (auto x: a)
          if (cmp(dp[i +c[x]], dp[i] + char('0' +x)))
              dp[i + c[x]] = dp[i] +char('0' + x);
    }
  cout <<dp[n];
}

Measured memory_bytes: 43264
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
#include<cmath>
#include<deque>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define INF (1LL << 40)
int main() {
	char str[200];
	scanf("%s", str);
	if (str[2] == str[3] && str[4] == str[5]) {
		printf("Yes\n");
	}
	else printf("No\n");
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
int a[100002][5];
int N;
int dp[100002][5];
int funct(int z,int x)
{
  int i;
  i=z;
  int max;
  if(z==N)
  {
    dp[z][x]=0;
    return 0;
  }
  if(x==0)
  {
    if(dp[z+1][1]==-1)
      dp[z+1][1]=funct(z+1,1);
    if(dp[z+1][2]==-1)
      dp[z+1][2]=funct(z+1,2);
    max=dp[z+1][1]>=dp[z+1][2]?dp[z+1][1]:dp[z+1][2];
    dp[i][0]=a[i][0]+max;
  }
  else if(x==1)
  {
    if(dp[i+1][0]==-1)
      dp[i+1][0]=funct(i+1,0);
    if(dp[i+1][2]==-1)
      dp[i+1][2]=funct(i+1,2);
    max=dp[i+1][0]>=dp[i+1][2]?dp[i+1][0]:dp[i+1][2];
    dp[i][1]=a[i][1]+max;
  }
  else
  {
    if(dp[i+1][1]==-1)
      dp[i+1][1]=funct(i+1,1);
    if(dp[i+1][0]==-1)
      dp[i+1][0]=funct(i+1,0);
    max=dp[i+1][1]>=dp[i+1][0]?dp[i+1][1]:dp[i+1][0];
    dp[i][2]=a[i][2]+max;
  }
  return dp[i][x];
}
int main()
{
  int i,max;
  cin>>N;
  for(i=0;i<N;i++)
  {
  	cin>>a[i][0]>>a[i][1]>>a[i][2];
  }
  for(i=0;i<100002;i++)
  {
    dp[i][0]=-1;
    dp[i][1]=-1;
    dp[i][2]=-1;
    dp[i][3]=-1;
  }
  dp[0][0]=funct(0,0);
  dp[0][1]=funct(0,1);
  dp[0][2]=funct(0,2);
  max=dp[0][0]>=dp[0][1]?dp[0][0]:dp[0][1];
  max=max>=dp[0][2]?max:dp[0][2];
  cout<<max<<endl;
  return 0;
}

Measured memory_bytes: 8832
#include<iostream>
#include<string>
using namespace std;
int main(){
	bool Cards[52];
	string p="SHCD",t="";
	int n,r,i;
	char m;
	for (i=52;i;i--)Cards[i-1]=1;
	cin>>n;
	for(i=n;cin>>m>>r,i;i--)Cards[m-83?(m-72?(m-67?(m-68?0:38+r):25+r):12+r):r-1]=0;
	for(i=0;i<52;++i)if(Cards[i])cout<<t+p[i/13]<<" "<<i%13+1<<endl;
}

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

#define int long long

int binpw(int x){
	int ans = 1;
	for(int i = 0; i < x; i++) ans *= 10;
	return ans;
}

signed main()
{
	int x = 1;
	for(; x <= 10 ; ++x)	{
		cout << "? " << binpw(x) << endl;
		fflush(stdout);
		char a;
		cin >> a;
		if(a == 'N'){
			x--;
			break;
		}
	}
	if(x == 11){
		for(int i = 1; i <= 10; i++){
			cout << "? " << binpw(i) - 1 << endl;
			fflush(stdout);
			char a;
			cin >> a;
			if(a == 'Y'){
				cout << "! " << binpw(i - 1);
				return 0;
			}
		}
	}
	int l = binpw(x), r = binpw(x + 1) - 1;
	while(l != r){
		int mid = (l + r) / 2;
		cout << "? " << mid * 10 << endl;
		fflush(stdout);
		char a;
		cin >> a;
		if(a == 'N') l = mid + 1;
		else r = mid;
	}
	cout << "! " << l;
	return 0;
}

Measured memory_bytes: 596
from decimal import *

dp = [0] * 100000

n, k = map(int,input().split())

n_count = n
p_count = 0

while n_count:
    var = n_count * (2 ** p_count)
    if k - 1 < var:
        dp[p_count] += 1
    else:
        while var <= k - 1:
            var *= 2
            p_count += 1
        dp[p_count] += 1
    n_count -= 1

ans = Decimal(0)
for i, d in enumerate(dp):
    if d != 0:
        ans += Decimal(1/n) * (Decimal(1/2) ** i) * d

print(ans)


Measured memory_bytes: 6100
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::Read;
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok().unwrap();
    ret
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

fn solve() {
    let n = get();
    let mut dp = vec![1i64 << 60; n + 1];
    let mut coins = Vec::new();
    {
        let mut c = 1;
        while c <= n {
            coins.push(c);
            c *= 6;
        }
        c = 1;
        while c <= n {
            coins.push(c);
            c *= 9;
        }
    }
    dp[0] = 0;
    for i in 1 .. (n + 1) {
        for &c in coins.iter() {
            if i >= c {
                dp[i] = min(dp[i], dp[i - c] + 1);
            }
        }
    }
    println!("{}", dp[n]);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
#include <iostream>
#include <math.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <stack>

using namespace std;
typedef long long ll;



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



Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define REP(name, start, stop) for (auto(name) = (start); (name) < (stop); (name)++)
using ll = long long;
using vi = vector<ll>;

bool is_palindrome(string s) {
    size_t l = 0;
    size_t r = s.length() - 1;
    for (; l < r; l++, r--) {
        if (s[l] != s[r]) return false;
    }
    return true;
}

int main(void) {
    string s;
    cin >> s;
    size_t len = s.length();
    string l(begin(s), begin(s) + (len - 1) / 2);
    string r(begin(s) + (len + 1) / 2, end(s));
    string ans;
    if (is_palindrome(s) && is_palindrome(l) && is_palindrome(r)) {
        ans = "Yes";
    } else {
        ans = "No";
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

typedef struct pair* ppair;

typedef struct pair {
  int first, second;
} pair;


int size;
pair v[1000000];
int psize;
pair preorder[1000000];
int sorted;

void swap(ppair a, ppair b) {
  pair t = *a;
  *a = *b;
  *b = t;
}

int getp(int begin, int end) {
  int i;
  int p = begin;
  for(i = begin+1; i < end; ++i) {
    if(v[i].first < v[p].first) {
      p = i;
    }
  }
  swap(&v[end-1], &v[p]);
  return end-1;
}

void qsort(int begin, int end) {
  int i, j;
  if(begin >= end) return;
  getp(begin,end);
  preorder[psize++] = v[end-1];
  if(begin+1 == end) return;
  for(i = begin, j = begin; i < end; ++i) {
    if(v[i].second < v[end-1].second) {
      swap(&v[i], &v[j++]);
    }
  }
  swap(&v[j],&v[end-1]);
  qsort(begin, j);
  qsort(j+1, end);
}

int binary_search(int k) {
  int l, r;
  l = 0;
  r = size;
  while(l < r) {
    int m = (l+r)/2;
    if(v[m].second == k) {
      return m;
    } else if(v[m].second < k) {
      l = m+1;
    } else {
      r = m;
    }
  }
  return -1;
}

int main() {
  int i, j;
  int n, k;
  char s[100];
  size = 0;
  sorted = 0;
  scanf("%d", &n);
  for(i = 0; i < n; ++i) {
    scanf("%s", s);
    if(s[0] == 'i') {
      scanf("%d", &k);
      v[size] = (pair){size,k};
      ++size;
      sorted = 0;
    } else if(s[0] == 'p') {
      if(!sorted) {
        psize = 0;
        qsort(0, size);
        sorted = 1;
      }
      for(j = 0; j < size; ++j) {
        printf(" %d", v[j].second);
      }
      printf("\n");
      for(j = 0; j < size; ++j) {
        printf(" %d", preorder[j].second);
      }
      printf("\n");
    } else {
      scanf("%d", &k);
      if(!sorted) {
        psize = 0;
        qsort(0, size);
        sorted = 1;
      }
      printf(binary_search(k)!=-1?"yes\n":"no\n");
    }
  }
  return 0;
}

Measured memory_bytes: 6680
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int N = getint();
	char c;

	ll dp0 = getint();
	ll dp1 = -1e18;
	bool hajimete = 0;
	ll purasu = 0;

	rep(i, N - 1) {
		int a = 0;
		if (ci - cn + 16 > cm) {
			c = getcha(); getcha();
			while ((ct = getcha()) >= '0') a = a * 10 + ct - '0';
		}
		else {
			c = *ci++; ci++;
			while ((ct = *ci++) >= '0') a = a * 10 + ct - '0';
		}

		if (hajimete == 0) {
			if (c == '+') {
				dp0 += a;
			}
			else {
				hajimete = 1;
				dp0 -= a;
			}
		}
		else {
			if (c == '+') {
				purasu += a;
			}
			else {
				dp1 = max(dp1 + purasu + a, dp0 + a - purasu);
				dp0 += purasu - a;
				purasu = 0;
			}
		}
	}
	printf("%lld", max(dp0, dp1) + purasu);

	Would you please return 0;
}

Measured memory_bytes: 256
//Study Scheduling

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
#define cout15(a) printf("%.15f\n",a)
template<class T>inline bool chmin(T& a,T b,bool f){
if(f==1){if(a>b){a=b;return true;}return false;}
else if(f==0){if(a<b){a=b;return true;}return false;}return false;}
typedef pair<ll,string> p;
using g = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    int h,m,hh,mm,k;cin>>h>>m>>hh>>mm>>k;
    if(mm-m<0){
        hh-=1;
        mm+=60;
    }
    int benh=hh-h,benm=mm-m;
    benm+=benh*60;
    benm-=k;
    cout<<benm<<nnn;
    return 0;
}

Measured memory_bytes: 3620
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int a=Integer.parseInt(sc.next());
int b=Integer.parseInt(sc.next());
int c=Integer.parseInt(sc.next());
if(a+b>=c){System.out.println("Yes");}else{System.out.println("No");}
}}

Measured memory_bytes: 23252
#include <iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<limits.h>

#define MOD 1000000007
#define DEBUG 0


using namespace std;

long long int modpow(long long int a, int n) {

	if (n == 0)return 1;
	if (n == 1) return a;

	long long int wk = modpow(a, n / 2);

	long long int ret = 0;
	if (n % 2 == 0) {
		ret = 1;
	}
	else {
		ret = a;
	}

	return (((ret * wk) % MOD) * wk) % MOD;

}

long long int gcd(long long int a, long long int b) {
	long long int tmp;
	if (a < b) {
		tmp = a;
		a = b;
		b = tmp;
	}

	long long int r = a % b;

	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}

long long int lcm(long long int a, long long int b) {

	long long int wk_int;

	wk_int = (a * b) % MOD;
	
	long long int ret;

	ret = (wk_int * modpow(gcd(a, b), MOD - 2)) % MOD;

	return ret;

}

bool isPrime(int n) {
	if (n == 1)return false;
	if (n == 2)return true;

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

	return true;
}


int main()
{

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

	char achar = '0' + a;
	char bchar = '0' + b;

	string astr = "";
	string bstr = "";

	for (int i = 0; i < a; i++) {
		astr.push_back(bchar);
	}
	for (int i = 0; i < b; i++) {
		bstr.push_back(achar);
	}

	string ans;
	if (astr < bstr)ans = astr;
	else ans = bstr;

	cout << ans << endl;


	return 0;

}



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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef vector<bool> vb;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)
#define all(x) x.begin(),x.end()
#define gll greater<ll>()

ll n,m;
vll a;
void solve(){
 cin >> n >> m;
 a.resize(n);
 ll s=0; 
 rep(i,0,n) {
   cin >> a[i];
   s+=a[i];
 }
 sort(all(a),gll);
  
 cout << ((a[m-1] < double(s)/double((4*m)))?"No":"Yes") << endl;
}
int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b;
  cin >> a >> b;
if(a < b){
  cout << "a < b" << endl;
}
  else if (a > b){
      cout << "a > b" << endl;
  } else {
    cout << "a == b" << endl;
  }
}


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

using namespace std;

const long long INF = 1e18;

long long a[305], dp[45][2][2], x, y;

long long solve(int lv, int carry, int flag) {
	if (lv == -1) {
		if (carry == 0) return 0;
		else return -INF;
	}
	if (dp[lv][carry][flag] != -1) return dp[lv][carry][flag];
	
	dp[lv][carry][flag] = -INF;
	
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 2; j++) {
			if ((i ^ j) != ((y >> lv) & 1)) continue;
			int nFlag = flag;
			if (!flag && i > ((a[0] >> lv) & 1)) continue;
			if (!flag && i < ((a[0] >> lv) & 1)) nFlag = 1;
			for (int k = 0; k < 2; k++) {
				int sum = i + j + k;
				int tar = ((x >> lv) & 1) + carry * 2;
				if (sum != tar) continue;
				long long to = solve(lv - 1, k, nFlag);
				
				if (to != -INF) dp[lv][carry][flag] = max(dp[lv][carry][flag], 1LL * i * (1LL << lv) + to);
			}
		}
	}
	
	return dp[lv][carry][flag];
}

int main() {
	int n;
	scanf("%d", &n);
	
	for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
	for (int i = 2; i < n; i++) y ^= a[i];
	x = a[0] + a[1];
	
	memset(dp, -1, sizeof(dp));
	long long res = solve(40, 0, 0);
	
	if (res == -INF || res == 0) return 0 * printf("-1\n");
	
	printf("%lld\n", a[0] - res);
}


Measured memory_bytes: 3796
import java.util.*;
import java.util.stream.Collectors;

public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long N;
        N = sc.nextLong();
        long M;
        M = sc.nextLong();
        long K;
        K = sc.nextLong();

        final Solver solver = new Solver();
        solver.solve(N, M, K, sc);
    }
}

class Pair {
    final int x;
    final int y;

    Pair(int x, int y) {
        this.x = Math.min(x, y);
        this.y = Math.max(x, y);
    }

    @Override
    public int hashCode() {
        return Objects.hash(x, y);
    }

    @Override
    public boolean equals(Object obj) {
        if (!(obj instanceof Pair)) {
            return false;
        }
        final Pair other = (Pair) obj;
        return (this.x == other.x && this.y == other.y);
    }
}

class Solver {
    final List<Integer> parents = new ArrayList<>();
    final List<Integer> ranks = new ArrayList<>();
    final List<Integer> sizes = new ArrayList<>();

    final Map<Integer, Set<Integer>> connected = new HashMap<>();
    public void solve(long N, long M, long K, Scanner sc) {
        for (int i = 0; i < N; i++) {
            parents.add(i);
            ranks.add(0);
            sizes.add(1);

            connected.put(i, new HashSet<>());
        }

        for(int i = 0 ; i < M ; i++){
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            connected.get(a).add(b);
            connected.get(b).add(a);

            unite(a, b);
        }

        for(int i = 0 ; i < K ; i++){
            int c = sc.nextInt() - 1;
            int d = sc.nextInt() - 1;
            if (same(c, d)) {
                connected.get(c).add(d);
                connected.get(d).add(c);
            }
        }

        final List<Integer> answers = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            int ans = sizes.get(root(i)) - connected.get(i).size() - 1;
            answers.add(ans);
        }

        System.out.println(answers.stream().map(String::valueOf).collect(Collectors.joining(" ")));
    }

    private void unite(int x, int y) {
        int xRoot = root(x);
        int yRoot = root(y);

        if (xRoot == yRoot) return;

        if (ranks.get(xRoot) < ranks.get(yRoot)) {
            parents.set(xRoot, yRoot);
            sizes.set(yRoot, sizes.get(xRoot) + sizes.get(yRoot));
        }
        else {
            parents.set(yRoot, xRoot);
            if (ranks.get(xRoot).equals(ranks.get(yRoot))) {
                ranks.set(xRoot, ranks.get(xRoot) + 1);
            }
            sizes.set(xRoot, sizes.get(xRoot) + sizes.get(yRoot));
        }

    }

    private int root(int x) {
        if (parents.get(x) == x) {
            return x;
        }
        else {
            int root = root(parents.get(x));
            parents.set(x, root);
            return root;
        }
    }

    private boolean same(int x, int y) {
        int xRoot = root(x);
        int yRoot = root(y);

        return xRoot == yRoot;
    }
}



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

bool field[11][10010];
int r, c;

int calc(int bit){
  for(int i = 0 ; i < r ; i++){
    if((1>>i) & (bit)){
      for(int j = 0 ; j < c ; j++){
	field[i][j] = !field[i][j];
      }
    }
  }
  
  int ret = 0;
  for(int i = 0 ; i < c ; i++){
    int a = 0, b = 0;
    for(int j = 0 ; j < r ; j++){
      a += field[j][i];
      b += !field[j][i];
    }
    ret += max(a, b);
  }
  
  for(int i = 0 ; i < r ; i++){
    if(bit >> i & 1){
      for(int j = 0 ; j < c ; j++){
	field[i][j] = !field[i][j];
      }
    }
  }
  
  return ret;
} 

int main(){
  while(cin >> r >> c){
    if(r == 0 && c == 0) break;
    
    for(int i = 0 ; i < r ; i++){
      for(int j = 0 ; j < c ; j++){
	cin >> field[i][j];
      }
    }
    
    int ans = 0;
    for(int i = 0 ; i < (1<<r) ; i++){ //bit know reverse position
      ans = max(ans, calc(i));
    }
    
    cout << ans << endl;
  }
  return 0;
}

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

using namespace std;
using ll  = long long;
using ii  = pair < int , int >;
using i3  = pair < int , ii >;
using vi  = vector < int >;
using vii = vector < ii >;
using vi3 = vector < i3 >;

const int N = 25;
const ll INF = 1e12;
const double eps = 1e-9 , PI = acos(-1);

int n , m;
int a[N];

void solve(){
    scanf("%d" , &n);
    for(int i = 0 ; i < n ; i ++){
        scanf("%d" , &a[i]);
    }
    int ans = 0;
    for(int i = 1 ; i < n-1 ; i ++){
        vi tmp({a[i-1] , a[i] , a[i+1]});
        sort(tmp.begin() , tmp.end());
        if(tmp[1] == a[i])ans ++;
    }
    printf("%d\n" , ans);

}

main(){
    int t = 1;
    //scanf("%d" , &t);

    while( t -- ){
            solve();
    }

    return 0;
}




Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,a) for(int i=start[(a)];i;i=e[i].next)
inline int read()
{
	int sum=0,p=1;char ch=getchar();
	while(!(('0'<=ch && ch<='9') || ch=='-'))ch=getchar();
	if(ch=='-')p=-1,ch=getchar();
	while('0'<=ch && ch<='9')sum=sum*10+ch-48,ch=getchar();
	return sum*p;
}

#include<bitset>

const int maxn=800;

int n,m;
int to[maxn][maxn];

int fa[maxn];

inline int fin(int x){ return x==fa[x]?x:fa[x]=fin(fa[x]);}
inline void merge(int x,int y){x=fin(x);y=fin(y);fa[y]=x;}

int vis[maxn],A[maxn],B[maxn],tot;

void dfs(int u,int col)
{
	vis[u]=col;
	if(col==1)A[tot]++;else B[tot]++;
	REP(v,1,n)if(to[u][v])
	{
		if(vis[v]==col){puts("-1");exit(0);}
		if(!vis[v])dfs(v,3-col);
	}
}

int dp[maxn];

int main()
{
	n=read();m=read();
	REP(i,1,n)REP(j,1,n)to[i][j]=i!=j;
	REP(i,1,m)
	{
		int u=read(),v=read();
		to[u][v]=to[v][u]=0;
	}
	REP(i,1,n)fa[i]=i;
	REP(i,1,n)REP(j,1,n)if(to[i][j])merge(i,j);
	REP(i,1,n)if(!vis[i])++tot,dfs(i,1);
	dp[0]=1;
	REP(i,1,tot)
	{
		DREP(j,n,0)if(dp[j])
		{
			dp[j]=0;
			dp[j+A[i]]=1;
			dp[j+B[i]]=1;
		}
	}
	int ans=0x3f3f3f3f;
	REP(i,0,n)if(dp[i])ans=min(ans,i*(i-1)/2+(n-i)*(n-i-1)/2);
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    long int a[n+1]={0};
    long int ans[n+1]={0};
    int p;
    string s;
    long ac=0;
    long pen=0;
    for(int i=0;i<m;i++)
    {
       // cout<<i<<endl;
        cin>>p;
        cin>>s;
        //cout<<p;
       // cout<<" "<<s<<endl;
        if(s=="AC" && a[p]>=0)
        {
            pen=pen+a[p];
            a[p]=-1;
            ac++;
        }
        else if(s=="WA" && a[p]>=0)
        {
            a[p]++;
        }
        
    }
    cout<<ac<<" "<<pen<<endl;
    return 0;
    
}


Measured memory_bytes: 1792
r1,c1,r2,c2=map(int,input().split())

mod = 10**9+7
MAX_N = 3*10**6

fact = [1]
fact_inv = [0]*(MAX_N+4)
for i in range(MAX_N+3):
    fact.append(fact[-1]*(i+1)%mod)

fact_inv[-1] = pow(fact[-1],mod-2,mod)
for i in range(MAX_N+2,-1,-1):
    fact_inv[i] = fact_inv[i+1]*(i+1)%mod

def comb(n,k,mod):
    if n<k:return 0
    return fact[n] * fact_inv[k] % mod * fact_inv[n-k] %mod

ans=0
ans+=comb(c1+r1,r1,mod)
ans%=mod
ans-=comb(c1+r2+1,r2+1,mod)
ans%=mod
ans-=comb(c2+r1+1,r1,mod)
ans%=mod
ans+=comb(c2+r2+2,r2+1,mod)
ans%=mod

print(ans)


Measured memory_bytes: 199364
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 r;
        while(true){
            if(x >= y){
                r = x % y;
                if(r == 0){
                    System.out.println(y);
                    break;
                }
                x = y;
                y = r;
            }else{
                r = y % x;
                if(r == 0){
                    System.out.println(x);
                    break;
                }
                y = x;
                x = r;
            }
        }
        sc.close();
    }
}


Measured memory_bytes: 26412
n = int(input())
mydict = {}
answer_list = []

for i in range(n) :
    query, wd = input().split()
    
    if query == "insert" :
        mydict[wd] = 1
    else :
        if wd in mydict.keys() : answer_list.append("yes")
        else : answer_list.append("no")
        
for i in answer_list :
    print(i)


Measured memory_bytes: 37100
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
int main(){
  int n;
  cin >> n;
  while(n > 0){
    if(n % 10 == 7){
      cout << "Yes\n";
      return 0;
    }
    n /= 10;
  }
  cout << "No\n";
  return 0;
}

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


int main()
{   
    long long X;

    cin >> X;
    
    long long n = 100;
    long long sum = 0;
    while(n<X){
        sum++;
        n *= 1.01;
    }
    
    std::cout << sum << std::endl;
  
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define title "title"
#define ll long long
#define ull unsigned ll
#define fix(x) fixed<<setprecision(x)
#define pii pair<int,int>
#define vint vector<int>
#define pb push_back
using namespace std;
void Freopen(){
	freopen(title".in","r",stdin);
	freopen(title".out","w",stdout);
}
int read(){
	int g=0,f=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch){if(ch=='-')f=-1;ch=getchar();}
	while('0'<=ch&&ch<='9'){g=g*10+ch-'0';ch=getchar();}
	return g*f;
}
const int N=30;
char s[N];
int n,vis[N];
namespace solve1{
	void Main(){
		for(int i=1;i<=n;i++)cout<<s[i],vis[s[i]-'a']=1;
		for(int i=0;i<26;i++)if(!vis[i]){cout<<(char)(i+'a');break;}
	}
}
namespace solve2{
	void Main(){
		vis[s[n]-'a']=1;	
		for(int i=n-1;i>=1;i--){
			int flag=1;
			for(int j=s[i]-'a'+1;j<26;j++)if(vis[j]){
				s[i]=(char)(j+'a');
				for(int k=1;k<=i;k++)cout<<s[k];
				return void();
			}vis[s[i]-'a']=1;
		}puts("-1");
	}
}
signed main(){
	scanf("%s",s+1);n=strlen(s+1);
	if(n<26)solve1::Main();
	else solve2::Main();
	return signed();
}

Measured memory_bytes: 3684
require 'set'; require 'prime'; require 'pp'
INF=Float::INFINITY; MOD=10**9+7
n,k = gets.chomp.split.map(&:to_i)
a = gets.chomp.split.map(&:to_i)
@a = a.sort.reverse
@n = n
@k = k

l = 0
r = 10**9

def ok?(len)
  count = 0
  @n.times do |i|
    break if @a[i] <= len
    count += (@a[i] / len) - 1
    count += 1 if @a[i] % len != 0
    # p [len, 'ok?', i, @a[i], count]
    return false if count > @k
  end
  true
end

while l < r
  mid = (l + r) / 2
  if mid == 0
    l = 1
    break
  end

  # p [[l, r], mid, ok?(mid)]
  if ok?(mid)
    r = mid
  else
    l = mid + 1
  end
end

puts l




Measured memory_bytes: 33020
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    long X = scan.nextLong();
    scan.close();

    int year = 0;
    long Y = 100;
    while(Y < X) {
      Y *= 1.01;
      year++;
    }
    System.out.println(year);
  }
}

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

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

  ll rx = 0, ry = 0, rh = 0;
  for (int i = 0; i <= 100; i++) {
    for (int j = 0; j <= 100; j++) {
      ll H = h[index] + abs(i - x[index]) + abs(j - y[index]);
      if (!H) continue;
      bool res = true;
      for (int z = 0; z < n; z++) {
        if (h[z] != max(H - abs(x[z] - i) - abs(y[z] - j), 0LL)) {
          res = false;
          break;
        }
      }
      if (res && H > 0) {
        rx = i;
        ry = j;
        rh = H;
      }
    }
  }
  cout << rx << " " << ry << " " << rh << endl;
}

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

ll val;

int main(){
	scanf("%lld", &val);
	if(val % 2 == 1){
		printf("%lld\n", 0ll);
		return 0;
	}else{
		ll tmps, cnt5 = 0;
		// tmps = 10; while(val / tmps) ans += val / tmps, tmps = tmps * 10;
		val >>= 1;
		tmps = 5; while(val / tmps) cnt5 += val / tmps, tmps = tmps * 5;
		printf("%lld\n", cnt5);
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>

#define maxn 150010
struct Edge {
	Edge *next;
	int to;
} *last[maxn], e[maxn << 1], *ecnt = e;
int deg[maxn];
inline void link(int a, int b)
{
	++deg[a]; ++deg[b];
	*++ecnt = (Edge) {last[a], b}; last[a] = ecnt;
	*++ecnt = (Edge) {last[b], a}; last[b] = ecnt;
}
double f[maxn], g[maxn];
void dfs1(int x, int fa)
{
	for (Edge *iter = last[x]; iter; iter = iter -> next)
		if (iter -> to != fa)
		{
			dfs1(iter -> to, x);
			f[x] += f[iter -> to] / (deg[iter -> to] > 1 ? deg[iter -> to] - 1 : 1) + 1;
		}
}
void dfs2(int x, int fa)
{
	for (Edge *iter = last[x]; iter; iter = iter -> next)
		if (iter -> to != fa)
		{
			g[iter -> to] = (f[x] - f[iter -> to] / (deg[iter -> to] > 1 ? deg[iter -> to] - 1 : 1) - 1 + g[x]) / (deg[x] > 1 ? deg[x] - 1 : deg[x]) + 1;
			dfs2(iter -> to, x);
		}
}
int main()
{
	int n; scanf("%d", &n);
	for (int i = 1; i < n; ++i)
	{
		int a, b; scanf("%d%d", &a, &b); link(a, b);
	}
/*	for (int i = 1; i <= n; ++i)
	{
		memset(f, 0, sizeof (f));
		dfs1(i, 0);
		printf("%.12lf\n", f[i] / deg[i]);
	}*/
	dfs1(1, 0); dfs2(1, 0);
//	printf("%.12lf %.12lf\n", g[2], f[1]);
	for (int i = 1; i <= n; ++i) printf("%.12lf\n", (f[i] + g[i]) / deg[i]);
	return 0;
}

Measured memory_bytes: 16000
#include <iostream>
#include <array>
#include <algorithm>
#include <numeric>

int main(int argc, char const* argv[])
{
    std::array<int, 3> pos;
    std::cin >> pos[0] >> pos[1] >> pos[2];
    std::sort(pos.begin(), pos.end());
    auto sum = std::accumulate(pos.begin(), pos.end()-1, 0);
    std::cout << sum << std::endl;
    return 0;
}


Measured memory_bytes: 256
use std::io;
fn main() {
    let n: u32 = get_line().parse().expect("parse error");
    let a: u32 = get_line().parse().expect("parse error");
    println!("{}", solve(n, a));
}

fn solve<'a>(n: u32, a: u32) -> &'a str {
    if n % 500 <= a {
        "Yes"
    } else {
        "No"
    }
}

fn get_line() -> String {
    let mut inp = String::new();
    io::stdin().read_line(&mut inp).expect("read error");
    inp.trim().to_string()
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <limits.h>
#include <math.h>
#include <algorithm>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <string>
#include <vector>
#include <bitset>
#include <functional>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef double db;
typedef long double ldb;
#define rep(i,a,b) for(i=a;i<b;i++)
#define repu(i,a,b) for(i=a;i<=b;i++)
#define repd(i,a,b) for(i=a;i>=b;i--)
#define repc(i,a,b,c) for(i=a;i<b;i+=c)
#define repcu(i,a,b,c) for(i=a;i<=b;i+=c)
#define repcd(i,a,b,c) for(i=a;i>=b;i-=c)
#define FIN freopen("input.in","r",stdin)
#define FOUT freopen("output.out","w",stdout)
#define CC(a) memset(a,0,sizeof(a))
#define MST(a,b) memset(a,b,sizeof(a))
#define PII pair<int,int>
#define PLL pair<long long,long long>
#define VI vector<int>
#define VL vector<long long>
#define VII vector<PII>
#define VLL vector<PLL>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define pf push_front
 
template<typename T>inline void gn(T &x){
	x=0;T f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
template<typename T>inline void gt(T x){
	if(!x)return;
	gt(x/10);putchar(x%10+'0');
}
 
const LL N=1e6+5;
struct NODE{
	LL i,r,c,num;
}tt,ss;
LL t,n,m,q,ans;
LL MOD=1e9+7,inf=0x1f1f1f1f;
db eps=1e-5;
 
int main()
{
//	ios_base::sync_with_stdio(false);cin.tie(0);
	LL i,j,k,l,ca=0,u,v,tmp;
	cin>>n>>m>>i>>j;
	ans+=i*min(n,m);
	ans+=j*max(0ll,n-m);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int acs(const void *a, const void *b) { 
  return *(int*)a - *(int*)b;
} /* 1,2,3,4.. */
int des(const void *a, const void *b) {
  return *(int*)b - *(int*)a;
} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { 
  return *(char*)a - *(char*)b;
} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) {
  return strcmp(*(const char **)a, *(const char **)b);
} /* aaa,aab.. */
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void) {
  int n, a;
  scanf("%d %d", &n, &a);

  int b = n % 500;
  printf(a >= b ? "Yes\n" : "No\n");
  return 0;
}


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

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		System.out.println((1 << m) * (1900 * m + 100 * (n - m)));
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

Measured memory_bytes: 23892
x1,y1,x2,y2 = map(int,input().split())
x3 = x2 -(y2-y1)
y3 = y2 + (x2 -x1)
x4 = x3 - (x2 -x1)
y4 = y3 -(y2 -y1)

print(x3 , y3 ,x4, y4)

Measured memory_bytes: 38384
#include <cstdio>
#include <vector>
#include <set>
#define MOD 1000000007

using namespace std;

typedef long long ll;

int main() {
    ll n, m, b;
    scanf("%lld%lld", &n, &m);
    vector<bool> s(n + 1);
    vector<ll> dp(n + 1);
    dp.at(0) = 1;
    for (ll i = 0; i < m; ++i) scanf("%lld", &b), s.at(b) = 1;
    for (ll i = 1; i <= n; ++i) if (!s.at(i)) (dp.at(i) = dp.at(i - 1) + (i > 1 ? dp.at(i - 2) : 0)) %= MOD;
    printf("%lld\n", dp.back());
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;

int n,t;
ll a[105],dp[105][105];

ll solve(int i,int j) {
	if (i==j) return 0;
	if (dp[i][j]) return dp[i][j];
	dp[i][j]=INF;
	for (int k=i+1;k<=j;k++)
		dp[i][j]=min(dp[i][j],solve(i,k-1)+solve(k,j)+a[i]*a[k]*a[j+1]);
	return dp[i][j];
}

int main() {
	cin>>n;
	for (int i=1;i<=n;i++) if (i==n) cin>>a[i]>>a[i+1];
	else cin>>a[i]>>t;
	solve(1,n);
	cout<<dp[1][n]<<'\n';
}


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

int main() {
  int N, K;
  cin >> N >> K;
 int count = 0;
  for (int i = 0; i < N; i++) {
	int height;
    cin >> height;
    if (height >= K) {
      count++;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
    
using namespace std;    
typedef long long ll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

int div(ll n){

    int cnt = 0;
    while (n % 2 == 0)
    {
        cnt ++;
        n = n / 2;
    }
    return cnt;
    
}

int main(){
    
    int N;
    cin >> N;
    int ans = 1000000000;
    for(int i = 0; i < N; i++){
        ll val;
        cin >> val;
        ans = min(ans, div(val) );
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import sys

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

ct = 0
for i in range(n):
    if P[i] != i + 1:
        ct += 1
    if ct > 2:
        print('NO')
        sys.exit()
if ct == 2 or ct == 0:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define int long long
using namespace std;
using P=pair<int,int>;
using Graph=vector<vector<int>>;
using ll=long long;

vector<pair<int,int>> soinsuu(int n){
    vector<pair<int,int>> ret;
    for(int i=2;i*i<=n;i++){
        if(n%i !=0) continue;
        int ex=0;
        while(n%i ==0){
            ex++;
            n /= i; //n変更することで、それ以降の約数で割り切れることはない
        }
        ret.push_back(make_pair(i,ex));
    }
    //nが素数だった場合
    if(n!=1) ret.push_back(make_pair(n,1));
    return ret;
}

signed main(){ 
    int n,k;cin>>n>>k;
    int p[n];
    for(int i=0;i<n;i++) cin>>p[i];

    sort(p,p+n);

    cout<<accumulate(p,p+k,0)<<endl;
}  

Measured memory_bytes: 3636
#include <iostream>;
#include <math.h>
using namespace std;

int a[100000];

void sosuu() {
	a[0] = 2;
	int k, z = 1;
	for (int i = 3; i<100000; i++) {
		k = 0;
		for (int j = 0; a[j] <= sqrt(i); j++) {
			if (i%a[j] == 0) {
				k++;
				break;
			}
		}
		if (k == 0) {
			a[z] = i;
			z++;
		}
	}
	return;
}

int nibun(int n, int s, int e){
	if (s >= e) return s;
	if(a[(s + e)/2] < n){
		if(a[(s+e)/2 + 1]>n ){
			return (s + e) / 2;
		}
		return nibun(n, (s + e) / 2 + 1, e);
	}
	else if(a[(s + e) / 2] > n){
		return nibun(n, s, (s + e) / 2 - 1);
	}
	else return (s + e) / 2;
}


int main(){
	sosuu();
	int n, k;
	while(cin >> n){
		int ret = nibun(n, 0, 10000);
		if(n == a[ret]){
			cout << a[ret - 1] << " " << a[ret + 1] << endl;
		}

		else cout << a[ret] << " " << a[ret + 1] << endl;
	}
	return 0;
}

Measured memory_bytes: 3100