akhauriyash/Code-Regression huggingface dataset:
fn main() {
    let (n, a, b): (i64, i64, i64) = io::readln();

    let h: Vec<i64> = (0..n).map(|_| io::readln()).collect();

    let (mut low, mut high) = (0, 1000000009);
    while high - low > 1 {
        let mid = (low + high) / 2;
        if enough(&h, mid, &a, &b) {
            high = mid;
        } else {
            low = mid;
        }
    }
    println!("{}", high);
}

fn enough(enemies: &Vec<i64>, t: i64, a: &i64, b: &i64) -> bool {
    let bxt = b * t;
    let asb = a - b;
    let sum = enemies.iter().fold(0, |sum, i| {
        let w = i - bxt;
        if w > 0 {
            sum + (w + asb - 1) / asb

        } else {
            sum
        }
    });
    sum <= t
}

pub mod io {
    use std::io;

    pub fn read_line() -> String {
        let mut s = String::new();
        io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }

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

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

    impl Read for String {
        fn read(s: &str) -> Self {
            s.to_string()
        }
    }

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

    macro_rules !def_read {
        ($t : ty) => {
            impl Read for $t {
                fn read(s : &str)->$t { s.parse().unwrap() }
            }
        }
    }

    def_read!(i32);
    def_read!(i64);
    def_read!(isize);
    def_read!(usize);
    def_read!(f32);
    def_read!(f64);

    macro_rules !def_read_tuple {
        ($($t : ident), *) => {
            impl<$($t : Read + Default), *> Read for ($($t), *) {
                fn read(s : &str)->Self {
                    let mut iter = s.split_whitespace();
                    ($($t::read(iter.next().unwrap())), *)
                }
            }
        };
    }

    def_read_tuple!(T0, T1);
    def_read_tuple!(T0, T1, T2);
    def_read_tuple!(T0, T1, T2, T3);
    def_read_tuple!(T0, T1, T2, T3, T4);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int n, k;
  cin >> n >> k;
  VEC<LL> h(n);
  REP(i, 0, n) { cin >> h[i]; }
  sort(ALL(h));
  LL mi = LLONG_MAX;
  REP(i,0,n-k+1){
    LL diff = h[i+k-1] - h[i];
    mi=min(mi,diff);
  }
  cout<<mi<<endl;

  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<functional>
#include<utility>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<list>
using namespace std;
constexpr auto MOD = 1000000007;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
#define rep(i,n) for(int i = 0; i < (n);i++)
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VLL;



int main() {
   const ll ab = 998244353;
   int n;
   cin >> n;
   VI d(n);
   int mx = 0;
   VI cnt(n + 1, 0);
   rep(i, n) { cin >> d[i]; 
   cnt[d[i]]++;
   mx = max(mx, d[i]);
   }
   ll ans = 1;
   if (d[0] == 0 && cnt[0] == 1) {
	  for (int i = 1; i <= mx; i++)
	  {
		 for (int j = 0; j < cnt[i]; j++)
		 {
			ans = (ans*cnt[i - 1]) % ab;
		 }
	  }
	  cout << ans << endl;
   }
   else {
	  cout << 0 << endl;
   }

}


Measured memory_bytes: 1024
import java.util.*;
 
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S = sc.next();
		byte[] asciiCodes;
		String ans = "";

		try {
            asciiCodes = S.getBytes("US-ASCII");
        } catch (Exception e) {
            e.printStackTrace();
            return;
        }
		
		for(int i=0; i<S.length(); i++){
			asciiCodes[i] += N;
			if(asciiCodes[i]>90){
				asciiCodes[i] -= 26;
			}
			//String str = String.valueOf(c);
		}
		try {
            ans = new String(asciiCodes, "US-ASCII");
        } catch (Exception e) {
            e.printStackTrace();
            return;
        }
		System.out.println(ans);
    }
}


Measured memory_bytes: 35856
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
using namespace std;
//cout << fixed << setprecision(0)
int main() { 
  int r,g,b;cin >> r >> g >> b;
  if((r*100+g*10+b)%4==0){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
using namespace std;
int main(){
	int N,M,a;
	while(1){
		cin>>N>>M;
		int a,b;
		bool check[501];
		vector<int> ans,ans2;
		for(int i=0;i<501;i++){
			check[i]=false;
		}
		check[1]=true;
		vector<int> data1,data2;
		if(N==0&&M==0)break;
		for(int i=0;i<M;i++){
			cin>>a>>b;
			data1.push_back(a);
			data2.push_back(b);
		}
		for(int i=0;i<M;i++){
			if(data1[i]==1){
				ans.push_back(data2[i]);
				check[data2[i]]=true;
			}
		}//???????????????
		for(int i=0;i<ans.size();i++){
			for(int j=0;j<M;j++){
				if(data1[j]==ans[i]&&check[data2[j]]==false){
					check[data2[j]]=true;
					ans2.push_back(data2[j]);
				}
				if(data2[j]==ans[i]&&check[data1[j]]==false){
					check[data1[j]]=true;
					ans2.push_back(data1[j]);
				}				
			}
		}
		/*for(int i=0;i<ans2.size();i++){
			cout<<ans2[i]<<endl;
		}*/
		cout<<ans.size()+ans2.size()<<endl;
	}	
}

Measured memory_bytes: 1340
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<map>
#include <typeinfo>
#include <stdlib.h>
#define ll long long
const int MOD = 1000000007;
using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (2 * b == a + c) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char arr[100000];
    scanf("%s",&arr);
    int n=strlen(arr);
    int p=0,a,b;
    for(int i=0;i<n-2;i++)
    {
        if(arr[i]==arr[i+1])
        {
            p=1;
            a=i;
            b=i+1;
            break;
        }
        else if(arr[i]==arr[i+2])
        {
            p=1;
            a=i;
            b=i+2;
            break;
        }
    }
    if(arr[n-2]==arr[n-1])
    {
        p=1;
        a=n-2;
        b=n-1;
    }
    if(p)
    {
        cout<<a+1<<' '<<b+1;
    }
    else
    {
        cout<<"-1 -1";
    }
}

Measured memory_bytes: 384
import java.io.PrintStream;
import java.util.Scanner;
public class Main {
    static final Scanner     sc = new Scanner(System.in);
    static final PrintStream so = System.out;

    public static void main(String[] args) {
        int n = ni();
        char[] a = ns().toCharArray();
        int r = 0;
        int b = 0;
        for (int i = 0; i < n; i++) {
            if (a[i] == 'R') r++;
            else b++;
        }
        so.println(r > b ? "Yes" : "No");
    }

    static int ni() {
        return sc.nextInt();
    }

    static long nl() {
        return sc.nextLong();
    }

    static String ns() {
        return sc.next();
    }

    static int[] nints(int n) {
        return nints(n, 0);
    }

    static int[] nints(int n, int padding) {
        int[] a = new int[padding + n];
        for (int i = 0; i < n; i++)
            a[padding + i] = ni();
        return a;
    }
}


Measured memory_bytes: 22100
#include <bits/stdc++.h>
#include <numeric>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FT first
#define SC second
#define MP make_pair
#define PB push_back

using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pint;
const int INF = 1e9;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}


int main()
{
  ll a, b, c, d ;
  cin >> a >> b >> c >> d ;
  ll e = lcm(c,d) ;
  ll A = (a-1)-((a-1)/c+(a-1)/d-(a-1)/e) ;
  ll B = b-(b/c+b/d-b/e) ;
  
  cout << B - A <<endl ;

  return 0 ;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int k=nxt(),a=nxt(),b=nxt();
    for(int i=a;i<=b;i++)
        if(i%k==0)
        {
            cout<<"OK\n";
            return 0;
        }
        cout<<"NG\n";
    
    return 0;   
}




 
 


Measured memory_bytes: 3612
/*
God is not unjust;
he will not forget your work and
the love you have shown him as
you have helped his people and continue to help them.
*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;

#define SZ(x) ((int)x.size())

const int N = (int)1e5+5;
int n, m, a[N], sum[N];
ll res[N];
vector<int> b, g[N];

void solve() {
	int idx = n + 1, cnt = 0;
	for (int i = m; i >= 1; --i) {
		idx = min(idx, g[i][0]);
		cnt += SZ(g[i]);
		res[idx] += ((ll)b[i] - (ll)b[i - 1]) * (ll)cnt;
	}
}

int main() {
	scanf("%d", &n);
	b.push_back(0);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &a[i]);
		b.push_back(a[i]);
	}
	sort(b.begin(), b.end());
	b.resize(distance(b.begin(), unique(b.begin(), b.end())));
	m = SZ(b) - 1;
	for (int i = 1; i <= n; ++i) {
		a[i] = lower_bound(b.begin(), b.end(), a[i]) - b.begin();
		g[a[i]].push_back(i);
	}
	solve();
	for (int i = 1; i <= n; ++i) printf("%lld\n", res[i]);
	return 0;
}


Measured memory_bytes: 8056
n,m = gets.split.map(&:to_i)
hs = gets.split.map(&:to_i)

ways = Array.new(n) {[]}

m.times do
  a,b = gets.split.map(&:to_i)
  ways[a-1].push b-1
  ways[b-1].push a-1
end

count = 0

ways.each.with_index do |way, i|
  h = hs[i]
  top = true

  ways[i].each do |other|
    if hs[other] >= h
      top = false
      break
    end
  end

  if top
    count += 1
  end
end

puts count


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

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

    vector<pair<int, int>> wv(n);
    rep(i, n){
        int t1, t2;
        cin >> t1 >> t2;
        wv[i] = make_pair(t1, t2);
    }

    ll dp[n][w+1];
    rep(i, w+1){
        if(wv[0].first <= i){
            dp[0][i] = wv[0].second;
        }else{
            dp[0][i] = 0;
        }
    }

    for(int i = 1; i <n; i++){
        int w_current = wv[i].first;
        int v_current = wv[i].second;
        rep(j, w+1){
            ll temp = 0;
            if(j>=w_current){
                temp = dp[i-1][j-w_current] + v_current;
            }
             temp = max(temp, dp[i-1][j]);
            dp[i][j] = temp;
        }
    }
    
    cout << dp[n-1][w] << endl;

    return 0;
}


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

int main(){
    string s;
    cin >> s;
    if(s=="SUN")cout << '7' << endl;
    if(s=="MON")cout << '6' << endl;
    if(s=="TUE")cout << '5' << endl;
    if(s=="WED")cout << '4' << endl;
    if(s=="THU")cout << '3' << endl;
    if(s=="FRI")cout << '2' << endl;
    if(s=="SAT")cout << '1' << endl;
    return 0;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

vector<ll> enum_div(ll n){
	vector<ll> ret;
	for(ll i=1;i*i<=n;++i){
		if(n%i==0){
			ret.push_back(i);
			if(i*i!=n){
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}

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

	ll N=in<ll>();
	auto V=enum_div(N);
	ll minN = 1LL<<60;

	for(auto& x:V){
		ll y = N/x;
		ll num = abs(x-1)+(y-1);
		minN=min(minN,num);
	}
	
	out(minN);
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
long long s,f[1000005],a,b,n,k,q;
int main(){
	cin>>n;
	for(k=1;k<=n;k++){
		cin>>a;
		f[a]++;
		s+=a;
	}
	cin>>q;
	while(q--){
		cin>>a>>b;
		f[b]+=f[a];
		s=s-f[a]*a+f[a]*b;
		f[a]=0;
		cout<<s<<endl;
	}
}

Measured memory_bytes: 4272
/*
 * @Author: sunlu
 * @Date: 2020-01-23 15:07:26
 * @LastEditors  : sunlu
 * @LastEditTime : 2020-01-23 15:09:44
 */
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll A,B,C;
int main(){
    cin>>A>>B>>C;
    ll p=max(A,B);
    cout<<ceil((double)C/p);
}

Measured memory_bytes: 256
/*
ЗАПУСКАЕМ 
░ГУСЯ░▄▀▀▀▄░РАБОТЯГУ░░
▄███▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░ 
 */
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>


using namespace std;
template<typename T1, typename T2> inline void chkmin(T1 &a, T2 b) {if (a > b) a = b;}
template<typename T1, typename T2> inline void chkmax(T1 &a, T2 b) {if (a < b) a = b;}
#define files(FILENAME) read(FILENAME); write(FILENAME)
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define all(c) (c).begin(), (c).end()
#define sz(c) (int)(c).size()
#define left left228
#define right right228
#define y1 y1228
#define mp make_pair
#define pb push_back
#define y2 y2228
#define rank rank228
using ll = long long;
using ld = long double;
const string FILENAME = "input";
const int Mod = 998244353;


int sum(int a, int b) {
	return (a + b >= Mod ? a + b - Mod: a + b);
}

int mul(int a, int b) {
	return (ll)a * b % Mod;
}


string s;
int k;
int n;
int dp[305][305][305];


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
 	//read(FILENAME);
 	cin >> s >> k;
 	n = sz(s);
 	int cnt = 0;
 	vector<int> st;
 	int sumr = 0;
 	for (int i = 0; i < n; i++) {
 		if (s[i] == '1') {
 			cnt++; 
 			sumr++;
 		} else {
 			st.pb(cnt);
 			cnt = 0;	
 		}
 	}
 	st.pb(cnt);
 	dp[0][0][0] = 1;
 	int have = sumr;
 	for (int i = 0; i < sz(st); i++) {
 		have -= st[i];
 		for (int need = 0; need <= min(300, k); need++) {
 			for (int bal = 0; bal <= 300; bal++) {
 				if (dp[i][need][bal] == 0) {
 					continue;
 				}
 			//	cout << dp[i][need][bal] << ' ' << i << ' ' << need << ' ' << bal << endl;
	 			for (int j = 0; j <= min(bal, st[i]); j++) {
	 				dp[i + 1][need][bal - j] = sum(dp[i + 1][need][bal - j], dp[i][need][bal]);
	 			}
	 			for (int j = st[i] + 1; j <= 300; j++) {
	 				if (bal + j - st[i] > have) {
	 					break;
	 				}
	 				dp[i + 1][need + j - st[i]][bal + j - st[i]] = sum(dp[i + 1][need + j - st[i]][bal + j - st[i]], dp[i][need][bal]);
	 			}
	 		}
  		}
 	}
 	int ans = 0;
 	for (int need = 0; need <= min(300, k); need++) {
 		ans = sum(ans, dp[sz(st)][need][0]);
 	}
 	cout << ans << '\n'; 
	return 0;	 	
}


Measured memory_bytes: 30680
#include<stdio.h>
#include<math.h>

int main(){
    int i, j = 0;
    double n = 1, s[1000], avg = 0, sd[10000], tmp = 0, count = 0;
    while(n != 0){
        scanf("%lf", &n);
        if(n == 0) break;
        else count++;
        for(i = 0; i < n; i++){
            scanf("%lf", &s[i]);
            avg += s[i];
        }
        avg = avg / n;
        for(i = 0; i < n; i++){
            tmp += pow(s[i] - avg, 2);
        }
        sd[j] = sqrt(tmp / n);
        j++;
        avg = 0;
        tmp = 0;
    }
    for(i = 0; i < count; i++){
        printf("%lf\n", sd[i]);
    }
    return 0;
}


Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

vector<vector<int>> G;
vector<int> ans;

void dfs(int v, int p){
    for(auto to : G[v]){
        if(to == p) continue;
            ans[to] += ans[v];
            dfs(to, v);
    }
}

int main(){
    int n, q; cin >> n >> q;
    G.resize(n);
    ans.resize(n);
    rep(i,n-1){
        int a, b; cin >> a >> b;
        --a, --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    ans.resize(n);
    rep(i,q){
        int p, x; cin >> p >> x;
        --p;
        ans[p] += x;
    }
    dfs(0, -1);
    rep(i, n) cout << ans[i] << endl;
}

Measured memory_bytes: 23552
#include<cstdio>
#include<algorithm>
using namespace std;

const int sz = 2e5 + 1;
int p[sz], w[sz];

int get(int x) { return x == p[x] ? x : p[x] = get(p[x]); }
void uni(int a, int b) {
	if (a == b) return;
	a < b ? p[b] = a : p[a] = b;
	w[a] = w[b] += w[a];
}

int main()
{
	int N, M, u, v;
	scanf("%d %d", &N, &M);
	for (int i = 1; i <= N; i++) p[i] = i, w[i] = 1;

	while (M--) {
		scanf("%d %d", &u, &v);
		uni(get(u), get(v));
	}

	int res = 0;
	for (int i = 1; i <= N; i++) res = max(res, w[i]);
	printf("%d\n", res);
}

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

using namespace std;

typedef long long ll;

const ll mod=1e9+7;

const int N=6666;

ll n,k;

ll c[N][N];

ll dp[N];

ll C(ll n,ll m)

{

    if(c[n][m]) return c[n][m];

    if(m==0||n==m) return 1;

    if(m==1) return n;

    return c[n][m]=(C(n-1,m-1)+C(n-1,m))%mod;

}

int main()

{

    scanf("%lld%lld",&n,&k);

    int s=n-k;
if(n==k)
dp[0]=1;
    for(int i=1;i<=s;i++)

        dp[i]=C(s-1,i-1);

    for(int i=1;i<=k;i++)

    {

        if(i>n-k+1)

        {

            printf("0\n");

            continue;

        }

        ll ans=0;

        ans=(ans+C(k-1,i-1)*dp[i-1])%mod;

        ans=(ans+C(k-1,i-1)*dp[i]%mod*2%mod)%mod;

        ans=(ans+C(k-1,i-1)*dp[i+1]%mod)%mod;

        printf("%lld\n",(ans%mod+mod)%mod);

    }

}


Measured memory_bytes: 102912
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int N;
  ll L, T;
  while (cin >> N >> L >> T) {
    vector<ll> X(N), W(N);
    for (int i = 0; i < N; i++) {
      cin >> X[i] >> W[i];
    }
    ll cross0 = 0;
    for (int i = 1; i < N; i++) {
      if (W[0] != W[i]) {
        ll d = W[0] == 1 ? X[i] - X[0] : L - (X[i] - X[0]);
        if (d <= 2 * T) {
          ll rem = 2 * T - d;
          ll tmp = rem / L + 1;
          if (W[0] == 1 && rem % L == 0) {
            --tmp;
          }
          cross0 += tmp;
        }
      }
    }
    int label0 = W[0] == 1 ? cross0 % N : (N - cross0 % N) % N;
    vector<ll> pos(N);
    for (int i = 0; i < N; i++) {
      pos[i] = W[i] == 1 ? (X[i] + T) % L : (X[i] - T % L + L) % L;
    }
    ll pos0 = pos[0];
    sort(pos.begin(), pos.end());
    int off = find(pos.begin(), pos.end(), pos0) - pos.begin();
    vector<ll> ans(N);
    for (int i = 0; i < N; i++) {
      int j = (off + i) % N;
      int label = (label0 + i) % N;
      ans[label] = pos[j];
    }
    for (ll x : ans) {
      cout << x << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define pb push_back
#define pii pair<long long,long long>
#define endl '\n'
#define N 100001
int MOD=1000000007;
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};

void solve()
{
    double n; cin>>n;
    double pi = 3.14159265358979323846;
    double t = (double)2;
    cout<<fixed<<setprecision(22)<<t*pi*n;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test;test=1;
    while(test--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3804
//Created by Kira

#include<bits/stdc++.h>
using namespace std;

#define IOS cin.sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pii pair<int,int> 
#define pb push_back
#define vi vector<int> 
using ll = long long;

const int mod = 1e9 + 7;

ll pwr(ll a, ll b);

const int N = 1e5 + 10;

vector<int> g[N];

int n, m, p[N], vis[N];


int main(){
   IOS

    cin>>n>>m;
    
    for(int i = 0; i < m; i++){
        int u, v; cin>>u>>v;
        g[u].pb(v);
        g[v].pb(u);
    }
    memset(p, 0, sizeof p);
    memset(vis, 0, sizeof vis);

    queue<int> q;
    q.push(1);
    

    while(!q.empty()){
        int v = q.front(); q.pop();

        for(auto child : g[v]){
            if(!vis[child]){
                q.push(child);
                p[child] = v;
                vis[child] = true;
            }
        }
    }


    for(int i = 2; i <= n; i++){
        if(p[i] == 0){
            cout<<"No\n";
            return 0;
        }
    }

    cout<<"Yes\n";

    for(int i = 2; i <= n; i++){
        cout<<p[i]<<"\n";
    }





}

ll pwr(ll a, ll b){
   a %= mod;	//Remove mod if not required
   ll res = 1;
   while(b > 0){
    if(b&1)
        res = res * a % mod;
        a = a * a % mod;
    b >>= 1;
    }

    return res;
}



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

using namespace std;

#define PI 3.14159265358979323846264338327950L

int main(void){
    long long ans=0,N,tmp,ans2;
    vector<long long>a,vec;
    cin>>N;

    for(int i=0;i<N;i++){
        cin>>tmp;
        ans=ans^tmp;
        a.push_back(tmp);
    }

    for(long long i=0;i<a.size();i++){
        ans2=ans^a[i];
        cout<<ans2<<" ";
    }
    cout<<endl;



    return 0;
}



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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  string s,t;
  cin >> s >> t;
  
  //cout << fixed << setprecision(10);
  cout << t << s << endl;
  return 0;
}


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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<LL> PQ_DESC;
typedef priority_queue<LL, VL, greater<LL>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef priority_queue<VL> PQ_DESC_VL;
typedef priority_queue<VL, vector<VL>, greater<VL>> PQ_ASC_VL;
typedef priority_queue<PLL> PQ_DESC_PLL;
typedef priority_queue<PLL, vector<PLL>, greater<PLL>> PQ_ASC_PLL;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF*(LL)INF;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void Main()
{
    LL n;cin>>n;
    VL a(n);
    REP(i,n){
        cin>>a[i];
    }

    LL result = 0;
    FOR(i,1,n){
        if(a[i-1] > a[i]){
            result += a[i-1]-a[i];
            a[i] = a[i-1];
        }
    }
    cout<<result<<endl;

    
    
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 4780
class PriorityQueue
  
  def initialize
    @heap = Array.new
    @sz = 0
  end
  
  def push x
    i = @sz
    @sz += 1
    while i > 0 do
      p = ( i - 1 ) / 2
      break if @heap[p] <= x
      @heap[i] = @heap[p]
      i = p
    end
    @heap[i] = x
  end
  
  def pop
    
    ret = @heap[0]
    x = @heap[@sz-=1]
    
    i = 0
    while i * 2 + 1 < @sz do
      a = i * 2 + 1
      b = i * 2 + 2
      a = b if b < @sz && @heap[b] < @heap[a]
      break if @heap[a] >= x
      @heap[i] = @heap[a]
      i = a
    end
    
    @heap[i] = x
    @heap.delete_at(-1)
    ret
  end
  
  def top
    @heap[0]
  end
  
  def any?
    @sz > 0
  end
  
  def empty?
    @sz == 0
  end
  
  def all
    @heap
  end
end
 
n, m = gets.to_s.split.map{|t| t.to_i }
# dr   = Array.new(n){ gets.to_s.split.map{|t| t.to_i } }.sort_by{|d,_|d}

ws = Array.new(m+1){ [] }
n.times do
  a, b = gets.to_s.split
  a, b = a.to_i, b.to_i
  # a <= m and ws[a] << b
  ws[a] << b if a <= m
end
# p ws
pq = PriorityQueue.new
 
ans = 0
cur = 0
(1..m).each do |i|
  
  ws[i].each{ |v| pq.push(-v) }
  pq.any? and ans -= pq.pop
  # p pq
end

puts ans

Measured memory_bytes: 11644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[7],mod=998244353;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n;cin>>n;
    string s;cin>>s;
    a[0]=n;
    ll ans = 1;
    for(ll i=0;i<3*n;i++){
        if(s[i]=='R'){
            if(a[5]>0)ans=(ans*a[5])%mod,a[5]--;
            else if(a[2]>0)ans=(ans*a[2])%mod,a[2]--,a[4]++;
            else if(a[3]>0)ans=(ans*a[3])%mod,a[3]--,a[6]++;
            else ans=(ans*a[0])%mod,a[0]--,a[1]++;
        }
        else if(s[i]=='B'){
            if(a[6]>0)ans=(ans*a[6])%mod,a[6]--;
            else if(a[1]>0)ans=(ans*a[1])%mod,a[1]--,a[4]++;
            else if(a[3]>0)ans=(ans*a[3])%mod,a[3]--,a[5]++;
            else ans=(ans*a[0])%mod,a[0]--,a[2]++;
        }
        else{
            if(a[4]>0)ans=(ans*a[4])%mod,a[4]--;
            else if(a[1]>0)ans=(ans*a[1])%mod,a[1]--,a[6]++;
            else if(a[2]>0)ans=(ans*a[2])%mod,a[2]--,a[5]++;
            else ans=(ans*a[0])%mod,a[0]--,a[3]++;
        }
    }
    cout<<ans;
}

Measured memory_bytes: 720
#include"bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
	int n, cnt1 = 0,cnt2=0;
	bool flag = true;
	cin >> n;
	vector<int>arr(n), ar(n),tmp;
	iota(all(ar), 1);
	rep(i, n)cin >> arr[i];
	tmp = arr;
	while (1) {
		flag = true;
		rep(i, n - 1) {
			if (ar[i] == arr[i]) {
				flag = false;
				swap(arr[i], arr[i + 1]); cnt1++;
			}
		}
		if (flag)break;
	}
	if (arr[n - 1] == ar[n - 1])cnt1++;
	cout << cnt1 << endl;
	return 0;
}



Measured memory_bytes: 4576
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    return C

X,Y=mint()
if (X+Y)%3!=0:
    print(0)
    exit()
k=abs(X-Y)
N=min(X,Y)-k
if N<0:
    print(0)
    exit()
n=2*(N//3)+k
C=comb(n,MOD)
print(C.get(N//3))

Measured memory_bytes: 105524
import scala.io.StdIn._

object Main {
  def cardGame(gameNum: Int): List[Int] = {
    def loop(n: Int, p1: Int = 0, p2: Int = 0): List[Int] = {
      if (n > 0) {
        val cards = readLine().split(" ")
        val sortedCards = cards.sorted

        if (cards(0) == cards(1)) loop(n - 1, p1 + 1, p2 + 1)
        else if (cards(0) == sortedCards(0)) loop(n - 1, p1 + 0, p2 + 3)
        else loop(n - 1, p1 + 3, p2 + 0)
      } else List(p1, p2)
    }

    loop(gameNum)
  }

  def main(args: Array[String]): Unit = {
    val gameNum = readInt()
    println(cardGame(gameNum).mkString(" "))
  }
}

Measured memory_bytes: 44332
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 * @throws NumberFormatException 
	 */
	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String[] tmpArray = br.readLine().split(" ");
		
		int x = Integer.parseInt(tmpArray[0]);
		int y = Integer.parseInt(tmpArray[1]);
		
		System.out.println(x+y/2);
	}

}


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

#define pb                push_back
#define mp                make_pair
#define all(x)            (x).begin(),(x).end()
#define fi                first
#define se                second
#define vc                vector
#define pii               pair<ll,ll>
#define endl              "\n"
#define rep(i,a,b)        for(ll i=a;i<b;i++)
#define repe(i,a,b)       for(ll i=a;i<=b;i++)
#define bac(i,a,b)        for(ll i=a;i>b;i--)
#define bace(i,a,b)       for(ll i=a;i>=b;i--)
#define fast              ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define ll                long long int
#define ld                long double
#define mod1              (ll)(1e9 + (ll)7)
#define mod2              (ll)998244353
#define pi                (float)3.14159265358979323846
#define inf               LLONG_MAX
#define ninf              LLONG_MIN

#define DECIMAL(n)        std::cout << std::fixed << std::setprecision(n)
#define SORT(v)           sort(all(v))
#define RSORT(v)          sort(all(v),greater<ll>())
#define REVERSE(v)        reverse(all(v))

#define pow(i,n)          (ll)pow((ll)i,n)
#define pow2(n)           ((ll)1<<n)
#define sz(x)             (ll)x.size()

typedef std::priority_queue<ll, std::vector<ll>, std::greater<ll> > min_pq;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

inline string inttos(ll a){std::stringstream soso; soso<<a; return soso.str();}
inline ll stoint(const std::string &s) {std::stringstream soso; soso << s; long long x; soso >> x; return x;}
inline std::string inttobin(ll x) {return std::bitset<7>(x).to_string();}
inline void swp(ll &a, ll &b){auto temp=a;a=b;b=temp;}

//pri - 1000000009
//ba  - 937,991,1013,1409,1741,4391

ld modexpo(ld x,ll n)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)
        return modexpo((x*x),n/2);
    else
        return (x*modexpo((x*x),(n-1)/2));
}

ld round_up(ld value, ll decimal_places) {
    //ld multiplier = 100.0;
    ld val = value*100;
    val = floor(val);
    return (val/100);
}

void solve(){
    ll x;
    cin>>x;
    ld intr = 1.01;
    rep(i,1,5000){
        ld ans = intr*100;

        if(x<=ans){
            cout<<i<<endl;
            return;
        }
        intr = intr*1.01;
        intr = round_up(intr,2);
    }

}


signed main(){
    fast
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        //freopen("output.txt","w",stdout);
    #endif
    ll t=1;
    //cin>>t;
    rep(i,0,t){
       solve();
    }

}


Measured memory_bytes: 3636
N = int(input())
L = list(map(int,input().split()))
L.sort()
L.append(0)
EVEN = 0
ODD = 0
cnt = 1
cur = L[0]
i = 0
while i < N:
  if L[i] == L[i+1]:
    cnt += 1
    i += 1
  else:
    if cnt%2 == 0:
      EVEN += 1
    else:
      ODD += 1
    cur = L[i+1]
    i += 1
    cnt = 1
if EVEN%2 == 0:
  print(EVEN+ODD)
else:
  print(EVEN+ODD-1)

Measured memory_bytes: 14004
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    int N; cin >> N;
    string s; cin >> s;
    bool flg = false;

    for(int bit=0; bit<4; bit++){
        string ans = s;
        // first, fix pre 2 characters
        for(int i=0; i<2; i++){
            if(bit&1<<i) ans[i] = 'S';
            else ans[i] = 'W';
        }

        // build ans
        for(int i=2; i<N; i++){
            if((ans[i-1] == 'S' && s[i-1] == 'o') || (ans[i-1] == 'W' && s[i-1] == 'x'))  ans[i] = ans[i-2];
            else if((ans[i-1] == 'S' && s[i-1] == 'x') || (ans[i-1] == 'W' && s[i-1] == 'o')) ans[i] = (ans[i-2] == 'S')? 'W':'S';
        }

        // check phase
        bool ok = true;
        for(int i=0; i<N; i++){
            if(s[i] == 'o'){
                if(ans[i] == 'S'){
                    if(ans[(i-1+N)%N] != ans[(i+1)%N]) ok = false;
                } else {
                    if(ans[(i-1+N)%N] == ans[(i+1)%N]) ok = false;
                }
            } else {
                if(ans[i] == 'S'){
                    if(ans[(i-1+N)%N] == ans[(i+1)%N]) ok = false;
                } else {
                    if(ans[(i-1+N)%N] != ans[(i+1)%N]) ok = false;
                }
            }
        }
        if(ok){
            cout << ans << endl;
            return 0;
        }
    }

    cout << "-1" << endl;
    return 0;

}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int k,s; cin>>k>>s;
    int cnt = 0;
    for(int i=0;i<=k;i++){
        for(int j=0;j<=k;j++){
            int z;
            if(i+j>s) continue;
            else z = s-i-j;
            if(z>=0&&z<=k) {cnt++;
            //cout<<i<<' '<<j<<' '<<z<<endl;
            }
            
        }
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 256
<?php
  list($h, $w) = explode(" ", trim(fgets(STDIN)));

  $ans = PHP_INT_MAX;
  // 横に3つ分ける場合
  $min = intdiv($h, 3);
  $max = intdiv($h+3-1, 3);
  $ans = min($ans, $max*$w - $min*$w);

  // 縦に３つ分ける場合
  $min = intdiv($w, 3);
  $max = intdiv($w+3-1, 3);
  $ans = min($ans, $max*$h - $min*$h);

  // 縦に１つ、横に２つ分ける場合
  // 縦が大きい
  $w1 = intdiv($w+3-1, 3);
  $w2=$w-$w1;
  $h1=intdiv($h, 2);
  $h2=$h-$h1;
  $ans = min($ans, max($h1*$w2, $h2*$w2, $h*$w1)-min($h1*$w2, $h2*$w2, $h*$w1));

  // 縦が小さい
  $w1 = intdiv($w, 3);
  $w2=$w-$w1;
  $h1=intdiv($h, 2);
  $h2=$h-$h1;
  $ans = min($ans, max($h1*$w2, $h2*$w2, $h*$w1)-min($h1*$w2, $h2*$w2, $h*$w1));

  // 横に１つ、縦に２つ分ける場合
  // 横が大きい
  $h1 = intdiv($h+3-1, 3);
  $h2=$h-$h1;
  $w1=intdiv($w, 2);
  $w2=$w-$w1;
  $ans = min($ans, max($h1*$w, $h2*$w2, $h2*$w1)-min($h1*$w, $h2*$w2, $h2*$w1));

  // 横が小さい
  $h1 = intdiv($h, 3);
  $h2=$h-$h1;
  $w1=intdiv($w, 2);
  $w2=$w-$w1;
  $ans = min($ans, max($h1*$w, $h2*$w2, $h2*$w1)-min($h1*$w, $h2*$w2, $h2*$w1));

  echo $ans;

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

int main(){
    LL K;
    cin >> K;
    vector<LL>  a(K), m(K+1), M(K+1);
    for(int i = 0;i < K;i++)    cin >> a[i];
    m[K] = 2, M[K] = 2;
    bool f = true;
    for(int i = K-1;i >= 0;i--){
        m[i] = (m[i+1]+a[i]-1)/a[i]*a[i];
        M[i] = M[i+1]/a[i]*a[i]+a[i]-1;
        if(m[i] > M[i+1] || M[i]-a[i]+1 < m[i+1])   f = false;
    }
    if(f)   cout << m[0] << " " << M[0] << endl;
    else    cout << -1 << endl;
}

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

int main() {
  long long n,k;
  cin>>n>>k;
  long long p[n];
  for (long long i=0;i<n;i++){
    cin>>p[i];
  }
  sort(p,p+n);
  long long ans=0;
  for (long long i=0;i<k;i++){
    ans+=p[i];
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3084
fun main(args: Array<String>) {
  var (a, b, c) = readLine()!!.split(" ").map { it.toInt() }
  if (a == b && b == c && a % 2 == 0) {
    println(-1)
    return
  }
  var ans = 0
  while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
    val x = a / 2
    val y = b / 2
    val z = c / 2
    a = y + z
    b = x + z
    c = x + y
    ans++
  }
  println(ans)
}


Measured memory_bytes: 37940
# /bin/ruby
a, b = gets.split(' ').map do |e|
  e.to_i
end

x = 0
if a > b
  x = a - b
else
  x = b - a
end
if x % 2 == 0
  n = a > b ? a : b
  puts (n - (x/2)).abs
else
  puts "IMPOSSIBLE"
end


Measured memory_bytes: 1788
import sys
import math
import collections
#n = int(input())
#n, m = map(int, input().split())
s = input()
#x = list(map(int, input().split()))

if s[0] == s[1]:
    if s[1] == s[2]:
        print("No")
        sys.exit()

print("Yes")
    


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

using namespace std ;
typedef long long ll;
typedef string str;
typedef pair<int, int> pii;
typedef vector<int> vint;
typedef vector<double> vdou ;
typedef vector<ll> vll;
typedef vector<vint> vvint;
typedef vector<str> vstr;
typedef pair<ll,ll> pll ;
typedef vector<pii> vpii ;
typedef vector<pll> vpll ;

#define REP(i, n) for (ll (i) = 0; (i) < (ll)(n); i++) 
#define FOR(i, a, b) for(ll (i) = a; (i) < (ll)b; i++)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define CHI 1000000000000000003
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define NP next_permutation
#define SZ(x)  (ll)x.size()
#define SP(x)  setprecision((ll)x)

const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const double PI = M_PI;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}
//-----------------------------------------




















//-----------------------------------------
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n ;
  cin >> n ;
  vint p(n) ;
  REP(i,n){
    cin >> p[i] ;
  }
  int ans = 0 ;
  REP(i,n){
    if(i+1==p[i]){
      ans++ ;
    }
  }
  int i=0;
  while(i<n-1){
    if(i+1==p[i] && i+2==p[i+1]){
      ans-- ;
      i += 2 ;
    }
    else{
      i++ ;
    }
  }
  
  cout << ans <<endl ;
  
  
  return 0 ;
}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main {
	
	public static void main(String[] args) throws IOException {
		try (Scanner sc = new Scanner(System.in)) {
			final int N = sc.nextInt();
			
			HashMap<Long, Integer> counts = new HashMap<Long, Integer>();
			for(int i = 0; i < N; i++){
				final long a = sc.nextLong();
				
				if(!counts.containsKey(a)){ counts.put(a, 0); }
				counts.put(a, counts.get(a) + 1);
			}
			
			long answer = 0;
			for(final Entry<Long, Integer> entry : counts.entrySet()){
				final long a = entry.getKey();
				final int cnt = entry.getValue();
				
				if(a > cnt){
					answer += cnt;
				}else{
					answer += (cnt - a);
				}
			}
			System.out.println(answer);
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while (!hasNext()) {
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for (int i = 0; i < n; i++) {
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for (int i = 0; i < n; i++) {
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long

typedef pair<ll, ll> P;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

int main(){
    int n, m;
    cin >> n >> m;
    vector<P > pairs(n);
    REP(i, n) {
        int a, b;
        cin >> a >> b;
        pairs[i] = make_pair(b, a);
    }

    sort(pairs.begin(), pairs.end(), compare_by_b);

    ll now = 0;
    ll ans = 0;
    REP(i, n) {
        now += pairs[i].first;
        if(now > m) {
            ans += (pairs[i].second) * (m - (now - pairs[i].first));
            break;
        } else {
            ans += pairs[i].second * pairs[i].first;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792