akhauriyash/Code-Regression huggingface dataset:
N, M = map(int, input().split())
A = list(map(int, input().split()))
soutouhyou = sum(A)
B = 1 / (4 * M)
C = soutouhyou * B
count = 0
for a in A:
  if a >= C:
    count += 1

if count < M:
  print("No")
else:
  print("Yes")

Measured memory_bytes: 3060
def frog_jump(n, s)
  max = 0
  1.upto(n / 2) do |c|
    k = 0
    point = 0
    used = {}
    while !used.key?(k * c) && !used.key?(n - 1 - k * c) && k * c != n - 1 - k * c && (k + 1) * c < n - 1
      point += s[k * c] + s[n - 1 - k * c]
      used[k * c] = true
      used[n - 1 - k * c] = true
      k += 1
      max = [max, point].max
    end
  end
  max
end

n = gets.to_i
s = gets.split.map(&:to_i)
puts frog_jump(n, s)

Measured memory_bytes: 22556
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] cs = sc.next().toCharArray();
		int t = 0;
		for (int i = 0; i < cs.length; i++) {
			t += cs[i] - '0';
		}
		if (t % 9 == 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 40660
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

int main(){
    int N,R;//コンテスト参加回数と表示レーティング
    std::cin>>N>>R;
    int x;//内部レーティング
    if (N>=10){
        x = R;
    }
    else{
        x=R+100*(10-N);
    }
    std::cout<<x<<std::endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main (String[] args){
        try(Scanner sc = new Scanner(System.in)){
            while(true){
                String str = sc.next();
                if(str.equals("-")){
                    break;
                }
                int n = sc.nextInt();
                for(int i=0;i<n;i++){
                    int len = sc.nextInt();
                    str = str.substring(len)+ str.substring(0,len);
                }
                System.out.println(str);


            }
        }
    }    
}


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

using namespace std;
using ll = long long;

int main() {
    int ans = 0;
    int n;
    string s;
    cin >> n >> s;
    for (int i = 0; i < n - 2; i++){
        if(s[i] == 'A' and s[i+1] == 'B' and s[i+2] == 'C'){
            ans += 1;
        }
    }
    cout << ans;
}


Measured memory_bytes: 256
let () =
    let main () =
        let t1, t2 = Scanf.sscanf (read_line ()) "%d %d" (fun t1 t2 -> t1, t2) in
        let a1, a2 = Scanf.sscanf (read_line ()) "%d %d" (fun a1 a2 -> a1, a2) in
        let b1, b2 = Scanf.sscanf (read_line ()) "%d %d" (fun b1 b2 -> b1, b2) in
        let r =
            if a1 = b1 then (-1) else (
                let m1a = t1 * a1 in
                let m1b = t1 * b1 in
                let m2a = m1a + t2 * a2 in
                let m2b = m1b + t2 * b2 in
                if m2a = m2b then (-1) else
                    if (m1a > m1b && m2a > m2b) || 
                       (m1a < m1b && m2a < m2b) then 0 else (
                           let d1 = t1 * (max a1 b1 - min a1 b1) in
                           let d2 = t2 * (max a2 b2 - min a2 b2) in
                           let rec loop d acc =
                               if d = 0 then acc else
                               if d - d2 > 0 then acc else
                                   if d - d2 + d1 < 0 then acc + 1 else
                                       loop (d - d2 + d1) (acc + 2)
                           in
                           let c = d1 / (d2 - d1) in
                           loop (d1 + (d1 - d2) * c) (2 * c) 
                       )
            )
        in
        if r < 0 then Printf.printf "infinity\n" else Printf.printf "%d\n" r
    in
    main ()

Measured memory_bytes: 2432
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

using namespace std;

typedef  pair<int,int> P;
typedef long long LL;
typedef vector<LL> VEC;


const LL INF=1<<30;
const LL MOD=1000000007;

LL gcd(LL a,LL b){
    if(b==0)return a;

    return gcd(b,a%b);
}

LL kaijo(LL n){
    LL ans=1;
    for(LL i=1;i<=n;++i){
        (ans*=i)%=MOD;
    }
    return ans;
}


int main(){
    int a;
    cin>>a;
    cout<<"ABC"<<a<<endl;
}

Measured memory_bytes: 256
N, T=map(int, input().split())
 
c_list=[]
t_list=[]
ans_list=[]
for i in range(N):
  c,t=map(int, input().split())
  c_list.append(c)
  t_list.append(t)
 
ct_dict=dict(zip(c_list, t_list))  
  
if T<=min(t_list):
  print("TLE")
else:
  for k,v in ct_dict.items():
    if v<=T:
      ans_list.append(k)
 
  print(min(ans_list))

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

int main() {
    int64_t N;
    string s;
    cin >> N >> s;
    //set<string> ans;
    int cnt=0;
    for(int i=0; i<10; i++){
        for(int j=0; j<10; j++){
            for(int k=0; k<10; k++){
                int64_t m=0;
                bool a=0, b=0, c=0;
                while (m<s.size())
                {
                    if(s.at(m)-'0' == i){
                        m++;
                        a=1;
                        break;
                    }
                    m++;
                }
                while (m<s.size())
                {
                    if(s.at(m)-'0'==j){
                        m++;
                        b=1;
                        break;
                    }
                    m++;
                }
                while (m<s.size())
                {
                    if(s.at(m)-'0'==k){
                        m++;
                        c=1;
                        break;
                    }
                    m++;
                }
                if(a && b && c){
                    //string x = to_string(i) + to_string(j) + to_string(k);
                    //ans.insert(x);
                    cnt++;
                }
            }
        }
    }
    cout << cnt << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, w;
    cin >> n >> w;
    int wt[n], val[n];
    for(int i = 0;  i < n;  i++)
        cin >> wt[i] >> val[i];
    long dp[n+1][w+1];
    for(int i = 0;  i <= n;  i++){
        for(int j = 0;  j <= w;  j++)
            if(i == 0  ||  j == 0)
                dp[i][j] = 0;
            else if(wt[i-1] <= j)
                dp[i][j] = max(dp[i-1][j], val[i-1]+dp[i-1][j-wt[i-1]]);
            else
                dp[i][j] = dp[i-1][j];
    }
    cout << dp[n][w] << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

const int M = 100100;

int a[M][3];
int p[M], f[M];
int n;
bool u[M];

void read() {
  cin >> n;
  for (int i = 0; i < 3; ++i)
    for (int j = 0; j < n; ++j) {
      cin >> a[j][i];
      a[j][i]--;
    }
}

void flip(int pos) {
  assert(0 < pos);
  assert(pos + 1 < n);

  swap(p[pos - 1], p[pos + 1]);
  swap(f[pos - 1], f[pos + 1]);
  for (int i = -1; i <= 1; ++i)
    f[pos] ^= 1;
}

void wide(int pos) {
  assert(pos >= 3);
  for (int i = 0; i < 4; ++i)
    f[pos - i] ^= 1;
}


bool ini(int *col, int pos) {
  int id = col[0] / 3;

  for (int i = 0; i < 3; ++i)
    if (id != col[i] / 3)
      return false;

  if (col[1] % 3 != 1)
    return false;
  
  if (id % 2 != pos % 2)
    return false;

  p[pos] = id;
  f[pos] = col[0] % 3 == 2;

  return true;
}

void no() {
  cout << "No\n";
  exit(0);
}

void yes() {
  cout << "Yes\n";
  exit(0);
}

void kill() {
  for (int i = 0; i < n; ++i)
    if (!ini(a[i], i))
      no();

  int cyc[2] = {0, 0};
  for (int x = 0; x < n; ++x)
    if (!u[x]) {
      ++cyc[x % 2];
      int y = x;
      while (!u[y]) {
        u[y] = true;
        y = p[y];
      }
    }


  int parity[] = {((n + 1) / 2 - cyc[0]) % 2, ((n / 2) - cyc[1]) % 2};
  int c[] = {0, 0};
  for (int i = 0; i < n; ++i)
    if (f[i])
      c[i % 2] ^= 1;

  if (c[0] != parity[1] || c[1] != parity[0])
    no();
  else
    yes();

  /*
  for (int i = 0; i < n; ++i)
    cerr << p[i] + 1 << ", " << f[i] << endl;
  */

  for (int i = n - 1; i >= 3; --i)
    if (f[i])
      wide(i);

  if (f[1])
    flip(1);

  for (int i = 0; i < n; ++i)
    cerr << p[i] + 1 << ", " << f[i] << endl;

  if (f[2] || (f[1] && !f[0]))
    no();
  else
    yes();
}

int main() {
  cout.precision(20);
  cout << fixed;
  ios_base::sync_with_stdio(false);
  read();
  kill();
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
struct TreeNode {
	int val;
	TreeNode *left, *right;
	TreeNode(int x) :val(x), left(NULL), right(NULL) {}
};

int main()
{
	//freopen("data_in.txt", "rb", stdin);
	vector<int> vt(4), r{1,4,7,9};
	for (int i = 0; i < 4; ++i) {
		cin >> vt[i];
	}
	sort(vt.begin(), vt.end());
	if (vt == r) cout << "YES";
	else cout << "NO";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H; 
  int W;
  cin >> H >> W;
  for(int i = 0; i < W + 2; i++){
  cout << "#";
  }
  
  cout << endl;

  
  for(int i= 0; i < H; i++){
      string a;
    cin>> a;
  cout << "#" << a << "#" << endl;
  }
    for(int i = 0; i < W + 2; i++){
  cout << "#";
  }
  }

Measured memory_bytes: 256
#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 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;
const int MAX = 1000000010;
const ll MOD = 1000000007;
const double PI = acos(-1);

int main () {
    int N; cin >> N;
    vector<int> dp(N + 1);
    dp[0] = 0;
    for (int i = 1; i <= N; i++) {
        int j = i;
        while (j <= N) {
            dp[j]++;
            j += i;
        }
    }

    ll sum = 0;
    for (int i = 1; i <= N; i++) {
        sum += (ll)i * dp[i];
    }

    cout << sum << endl;
}

Measured memory_bytes: 42308
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define all(vec) vec.begin(),vec.end()
#define ggr getchar(); getchar();return 0;
#define ll long long
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 1)return 1;
	return kai(x - 1)*x;
}

int mod_pow(int x, int y, int moder) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%moder;
		x = x * x%moder;
		y >>= 1;
	}
	return res;
}

int n, m, a[1145], b[1145], c[1145];
int d[114][114];
bool ta;

signed main() {
	cin >> n >> m;
	rep(i, m) {
		cin >> a[i] >> b[i] >> c[i];
	}
	rep(i, n) {
		rep(j, n) {
			if (i == j)d[i][j] = 0;
			else d[i][j] = INF;
		}
	}
	rep(i, m) {
		d[a[i] - 1][b[i] - 1] = c[i];
		d[b[i] - 1][a[i] - 1] = c[i];
	}
	rep(k, n) {
		rep(i, n) {
			rep(j, n) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
	int ans = m;
	rep(i, m) {
		ta = false;
		rep(j, n) {
			if (d[j][a[i] - 1] - d[j][b[i] - 1] == c[i]) {
				ta = true;
				break;
			}
		}
		if (ta)ans--;
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
ll p2[200005];
int main() {
    init();
    ll N;
    cin >> N;
    p2[0] = 1;
    rep(i, N + 1) p2[i + 1] = p2[i] * 2 % MOD;

    ll AB = 0, A = 0, B = 0;
    map<pair<ll, ll>, ll> mp;
    rep(i,N){
        ll a, b;
        cin >> a >> b;
        if(a==0 and b==0)
            AB++;
        else if(a==0)
            A++;
        else if(b==0)
            B++;
        else{
            if (b < 0) a *= -1, b *= -1;
            ll g = gcd(abs(a), abs(b));
            a /= g, b /= g;
            mp[{a, b}]++;
            // mp[{-b, a}];
        }
    }

    ll ans = AB;
    ll mul = p2[A] + p2[B] - 1;
    repa(p,mp){
        ll a = p.first.first, b = p.first.second, cnt = p.second;
        if (cnt == 0) continue;
        if (a < 0) a *= -1, b *= -1;

        (mul *= p2[cnt] + p2[mp[{-b, a}]] - 1) %= MOD;
        mp[{-b, a}] = 0;
    }

    (ans += mul + MOD - 1) %= MOD;

    cout << ans << endl;
}

Measured memory_bytes: 30164
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int x,a,b;
    scanf("%d%d%d",&x,&a,&b);
    int dis1=abs(a-x);
    int dis2=abs(b-x);
    if(dis1<dis2)
        printf("A\n");
    else
        printf("B\n");
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
//constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

vector<bool> isprime;

void eratos(ll n) {
	isprime.resize(n + 1);
	for (ll i = 0; i <= n; i++) {
		isprime[i] = true;
	}
	isprime[0] = false;
	isprime[1] = false;
	for (ll i = 2; i * i <= n; i++) {
		if (isprime[i]) {
			ll j = i + i;
			while (j <= n) {
				isprime[j] = false;
				j = j + i;
			}
		}
	}
}
int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	eratos(200000);
	vector<ll> pr;
	for (int i = 2; i <= 20000; i++) {
		if (isprime[i]) pr.push_back(i);
	}
	int kkt = 89;
	while (kkt) {
		ll m, a, b; scanf("%lld %lld %lld", &m, &a, &b); if (m == 0 && a == 0 && b == 0) break;
		ll res = 0;
		ll res_p = -1;
		ll res_q = -1;
		for (int i = 0; i < pr.size(); i++) {
			for (int j = i; j < pr.size(); j++) {
				ll p = pr[i];
				ll q = pr[j];
				if (a * q > p* b) break;
				if (p * q > m) break;
				if (chmax(res, p * q)) {
					res_p = p;
					res_q = q;
				}
			}
		}
		cout << res_p << " " << res_q << "\n";
	}
	return 0;

}



Measured memory_bytes: 3312
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class Main {
	public static void main(String[] args) throws IOException {
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
			List<String> vals = br.lines().limit(3).collect(Collectors.toList());
			List<List<Integer>> grid = new ArrayList<>();
			vals.stream().forEachOrdered(v -> {
				grid.add(splitBySpace(v).stream().map(s -> Integer.valueOf(s)).collect(Collectors.toList()));
			});
			
			for(int i = 0; i < grid.size()-1; i++){
				for(int j = i+1; j < grid.size(); j++){
					int sub = grid.get(i).get(0) - grid.get(j).get(0);
					for(int k = 1; k < grid.get(i).size(); k++){
						if(sub != grid.get(i).get(k) - grid.get(j).get(k)){
							System.out.println("No");
							return;
						}
					}
				}
			}
			System.out.println("Yes");
		}
	}


	private static List<String> splitBySpace(String target) {
		return Arrays.asList(target.split("\\s"));
	}

}


Measured memory_bytes: 28372
import random
def dice(a,b,c,d,e,f,l):
    if l == "N":
        return [b,f,c,d,a,e]
    if l == "S":
        return [e,a,c,d,f,b]
    if l == "E":
        return [d,b,a,f,e,c]
    if l == "W":
        return [c,b,f,a,e,d]
d = list(map(int, input().split()))
s = ["W","N","E","S"]
a,b,c,g,e,f = map(int ,input().split())
j = 0
while j <= 10000:
    k = random.randrange(4)
    d = dice(d[0],d[1],d[2],d[3],d[4],d[5],s[k])
    if d[0] == a and d[1] == b and d[2] == c and d[3] == g and d[4] == e and d[5] == f:
        print("Yes")
        break
    if j == 10000:
        print("No")
    j += 1


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

int main() {
  string S;
  cin >> S;

  if (S[S.size() - 1] == '3') {
    cout << "bon" << endl;
  } else if (S[S.size() - 1] == '0' || S[S.size() - 1] == '1' ||
             S[S.size() - 1] == '6' || S[S.size() - 1] == '8') {
    cout << "pon" << endl;
  } else {
    cout << "hon" << endl;
  }

  return 0;
}


Measured memory_bytes: 3628
## C - Modulo Summation
import fractions
N = int(input())
A = list(map(int, input().split()))

gcd = 0
for i in range(1, N):
    gcd = gcd * A[i] // fractions.gcd(gcd, A[i])
print( sum( [ (gcd - 1) % a for a in A] ) )

Measured memory_bytes: 5344
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
constexpr double pi=3.14159265358979;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
using namespace std;

//ワーシャルフロイド法、全点対最短路
const int INFTY=1e9;
vector<vector<int>>d;//d[u][v]は辺uvのコスト、ただし存在しないときINFTY,d[i][i]=0

void warshall_floyd(int V){//Vは頂点数
	for(int k=0;k<V;++k){//経由する頂点
		for(int i=0;i<V;++i){//始点となる頂点
			for(int j=0;j<V;++j)//目的地の頂点
      d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
		}
	}
}



void solve(){
 int n,m,r;
 cin>>n>>m>>r;
 d.resize(n,vector<int>(n,INFTY));
 vector<int>rr(r);
 rep(i,r){
   cin>>rr[i];
   rr[i]--;
 }
 sort(rr.begin(),rr.end());//next_permutationを使うときは必ずソートする
 rep(i,m){
   int a,b,c;
   cin>>a>>b>>c;
   a--;b--;
   d[a][b]=c;
   d[b][a]=c;
 }
 warshall_floyd(n);
 int minv=numeric_limits<int>::max();
 do{
   int cmp=0;
   rep(i,r-1){
     cmp+=d[rr[i]][rr[i+1]];
   }
   minv=min(minv,cmp);
 }while(next_permutation(rr.begin(),rr.end()));
 cout<<minv<<"\n";
 return;
}
 
signed main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
  cout<<fixed<<setprecision(20);
	solve();
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int N = 200000 + 5;
int to;
int n;
ll k;
int a[N];

ll cmp(ll val) {
	int p=to+1;
	ll cnt=0;
	for(int i=to;i>=1 && p<=n;i--) {
		while(val<0 && p<=n && abs((ll)a[i]*a[p])<abs(val)) p++;
		cnt+=max(0,n-p+1);
	}
	return cnt;
}

ll in(int l,int r,ll val) {
	int p=r;
	ll cnt=0;
	for(int i=l;i<p;i++) {
		while(p>0 && (ll)a[i]*a[p]>val) p--;
		cnt+=max(0,p-i);
	}
	return cnt;
}

ll cnt(ll val) {
	return in(1,to,val)+in(to+1,n,val)+cmp(val);
}

int main() {
	cin >> n >> k;
	for(int i = 1; i <= n; i++)
		cin >> a[i];
	sort(a+1,a+n+1);
	for(to = 1; to <= n; to++)
		if(a[to] >= 0)
			break;
	reverse(a+1,a+to);
	to--;
	ll l = -(ll)inf*inf,r = -l;
	while(l <= r){
		ll mid = (l+r)>>1;
		if(cnt(mid) >= k)
			r = mid-1;
		else
			l = mid+1;
	}
	cout << l << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll N; cin >> N;
  vector<ll> dp(N + 1, 1000000);
  dp[0] = 0;
  vector<ll> k = {1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049};
  for(ll i = 0; i < N + 1; i++) {
    for(ll j = 0; j < (ll)k.size(); j++) {
      if(i - k.at(j) < 0) continue;
      dp.at(i) = min(dp.at(i), dp.at(i - k.at(j)) + 1);
    }
  }
  cout << dp.at(N) << endl;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main(){
    int n;
    
    cin >> n;
    int a[n];
    for(int i=0;i<n;++i){
        cin >> a[i];
    }
    for(int i=n-1;i>=1;--i){
        cout << a[i] << " ";
    }
    cout << a[0] << endl;
    
}


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

using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> list(0);
	for(int i =  1; i <= 100; i *= 2){
		list.push_back(i);
	}
	int ans = *(upper_bound(list.begin(), list.end(), n)-1);
	cout << ans << endl;

	return 0;
}


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


int main(){
  int n;
  cin>>n;
  vector<int>l(n);
  rep(i,n){cin>>l[i];}
  sort(l.begin(),l.end());
  int ans=0;
  for(int i=0;i<n-2;i++){
    for(int j=i+1;j<n-1;j++){
      int k=l[i]+l[j];
      int id=lower_bound(l.begin(),l.end(),k)-l.begin();
    //  cout<<id<<' '<<i<<'i'<<j<<'j'<<endl;
      ans+=max(0,id-j-1);
    }
  }
  cout<<ans;
  }



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl "\n"
#define pb push_back
#define ll long long
#define d1(x)  cerr << #x << "--> " << x << endl
#define d2(x,y)  cerr << #x << "--> " << x << " | " << #y << "--> " << y <<endl
#define d3(x,y,z)  cerr << #x << "--> " << x << " | " << #y << "--> " << y <<" | " << #z << "--> "<< z<< endl
#define d4(x,y,z,w)  cerr << #x << "--> " << x << " | " << #y << "--> " << y <<" | " << #z << "--> "<< z << " | "<< #w << "--> " << w <<endl
#define vpll vector<pair<ll,ll>>
#define F first
#define S second
#define T ll tt; cin>>tt; while(tt--)
using namespace std;
ll mode=1ll<<32;
const ll maxn=1e3+10;
ll __lcm(ll a, ll b){ return (a*b)/__gcd(a,b); }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll getRand(ll l, ll r){ uniform_int_distribution<int> uid(l, r); return uid(rng); }


void solve(){
	
	ll n,k,c;
	cin>>n>>k>>c;
	string s;
	cin>>s;
	s="%"+s;
	ll pre[n+1];
	pre[0]=0;
	for (int i=1;i<=n;){
		if (s[i]=='o'){
			pre[i]=pre[i-1]+1;
			for (int j=1;j<=c;j++){
				if (i+j<=n) pre[i+j]=pre[i];
			}
			i=i+c+1;
		}
		else{
			pre[i]=pre[i-1];
			i++;
		}
	}
	ll suf[n+2];
	suf[n+1]=0;
	for (int i=n;i>=1;){
		if (s[i]=='o'){
			suf[i]=suf[i+1]+1;
			for (int j=1;j<=c;j++){
				if ((i-j)>=1) suf[i-j]=suf[i];
			}
			i=i-c-1;
		}
		else{
			suf[i]=suf[i+1];
			i--;
		}
	}
	
	for (int i=1;i<=n;i++){
		if ((pre[i-1]+suf[i+1])>=k){
			
		}
		else{
			cout<<i<<endl;
		}
	}
	
	return;
	
}

int main(){ 
    
    #ifndef ONLINE_JUDGE
  	//	freopen("input.txt", "r", stdin);
    #endif
    srand(time(0)); 
    
    ios::sync_with_stdio(0);
    cin.tie(0);


	//T{ solve(); }
	solve();
		
	
	return 0;
}

Measured memory_bytes: 4944
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long d,n;
	cin>>d>>n;
	if(n==100&&d==0)
	{
		cout<<101<<endl;
		return 0;
	}
	if(d==0)
	cout<<n;
	if(d==1)
	for(int i=100;i<=9999;i+=100)
	{
		if(i/100==n)
		{
			cout<<n*100;
			return 0; 
		}
		if(i/1==n)
		{
			cout<<10100;
			return 0; 
		}
	}
	if(d==2)
	for(int i=10000;i<=999999;i+=10000)
	{
		if(i/10000==n)
		{
			cout<<n*10000;
			return 0;
		}
		if(i/100==n)
		{
			cout<<1010000;
			return 0; 
		}
	}
	return 0;
}

Measured memory_bytes: 256
/*-------property of the half blood prince-----*/

#include <bits/stdc++.h>
#include <dirent.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#define MIN(X,Y) X<Y?X:Y
#define MAX(X,Y) X>Y?X:Y
#define ISNUM(a) ('0'<=(a) && (a)<='9')
#define ISCAP(a) ('A'<=(a) && (a)<='Z')
#define ISSML(a) ('a'<=(a) && (a)<='z')
#define ISALP(a) (ISCAP(a) || ISSML(a))
#define MXX 10000000000
#define MNN -MXX
#define ISVALID(X,Y,N,M) ((X)>=1 && (X)<=(N) && (Y)>=1 && (Y)<=(M))
#define LLI long long int
#define VI vector<int>
#define VLLI vector<long long int>
#define MII map<int,int>
#define SI set<int>
#define PB push_back
#define MSI map<string,int>
#define PII pair<int,int>
#define PLLI pair<LLI,LLI>
#define PDD pair<double,double>
#define FREP(i,I,N) for(int (i)=(int)(I);(i)<=(int)(N);(i)++)
#define eps 0.0000000001
#define RFREP(i,N,I) for(int (i)=(int)(N);(i)>=(int)(I);(i)--)
#define SORTV(VEC) sort(VEC.begin(),VEC.end())
#define SORTVCMP(VEC,cmp) sort(VEC.begin(),VEC.end(),cmp)
#define REVV(VEC) reverse(VEC.begin(),VEC.end())
#define INRANGED(val,l,r) (((l)<(val) || fabs((val)-(l))<eps) && ((val)<(r) || fabs((val)-(r))<eps))
#define INRANGEI(val,l,r) ((val)>=(l) && (val)<=(r))
#define MSET(a,b) memset(a,b,sizeof(a))
using namespace std;
using namespace __gnu_pbds;

//int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={2,1,-1,-2,-1,1};int dy[]={0,1,1,0,-1,-1}; //Hexagonal Direction


//typedef tree < int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > ordered_set;

LLI val[100005];
LLI num[100005];

void printbit(int oka){
    RFREP(i,31,0){
        if((1<<i)&oka)cout<<"1";
        else cout<<"0";
    }
    return;
}

LLI solve(int n, int k){
    LLI mxx = 0;

    FREP(i,1,n)if((num[i]|k)==k)mxx+=val[i];

    FREP(i,0,31){
        //cout<<"bit :"<<i<<" ";
        if((1<<i)>k)break;
        if(!((1<<i)&k))continue;
        LLI sm = 0;
        LLI kr = k-(k%(1<<i))-1;
        //cout<<"considering ";printbit(kr);cout<<"\n";
        FREP(j,1,n){
            if((num[j]|kr)==kr){
                sm+=val[j];
                //cout<<"    at idx "<<j<<" ";
                //printbit(num[j]);
                //cout<<" is considered\n";
            }
        }
        mxx = max(sm,mxx);
    }
    //cout<<"\n";
    return mxx;
}

int main(){
    int n,k;
    cin>>n>>k;
    FREP(i,1,n)cin>>num[i]>>val[i];
    LLI ans = solve(n,k);
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int main(){

  int num,i,*r,maxv,minv;
 
  while(1){

    scanf("%d",&num);
    if(num>=2&&num<=2000000) break;
  }
    r = (int *)malloc(num * sizeof(int));
    for(i=0;i<num;i++){
      scanf("%d",&r[i]);
      if(r[i]<1||r[i]>pow(10,9)) break;
      }
    maxv = r[1]-r[0];
    minv = r[0];
    for(i=1;i<=num-1;i++){
      if(r[i]-minv>maxv)
	maxv = r[i]-minv;
      else
	maxv = maxv;
      
      if(r[i]<minv)
	minv = r[i];
      else
	minv = minv;
    }
    printf("%d\n",maxv);



  return 0;
}



Measured memory_bytes: 2516
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define mod 1000000007
 
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
 
int lcm(int a, int b) { return a * b / gcd(a, b); }
 
int main(){
    ll n, a[5];
    cin >> n >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];

    sort(a, a+5);

    ll ans = ceil((double)n / a[0]) + 4;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int a,b,c,d,e;
    int i,j,sum;
    cin >> a >> b >> c >> d >> e;
    
    if(a < 0){
        i = c * (0 - a);
        j = e * (b - 0);
        sum = i + d + j;
        cout << sum << endl;
    }
    else{
        i = e * (b - a);
        sum = i;
        cout << sum << endl;
    }
}


Measured memory_bytes: 3080
#include<iostream>
using namespace std;
int main(){
  int a,b;
  while(1){
    cin>>a>>b;
    if(a==0&&b==0){
      break;
    }
    if(a>=b){
      cout<<b<<" "<<a<<endl;
    }else if(b>a){
      cout<<a<<" "<<b<<endl;
    }
  }
  return(0);
}

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

int main(){
    int k;
    int a, b;

    cin >> k;
    cin >> a >> b;

    for(int i=a; i<=b; i++){
        if(i%k == 0){
            cout << "OK" << endl;
            break;
        }
        if(i == b) cout << "NG" << endl;
    }

    return 0;
}

Measured memory_bytes: 3624
#include<stdio.h>
 
int main(void){
  
  int N;
  scanf("%d", &N);
  char s[10];
  long long int M = 0;
  long long int A = 0;
  long long int R = 0;
  long long int C = 0;
  long long int H = 0;
  for (int i = 0; i<N; i++) {
    scanf("%s", &s);
    if (s[0] == 'M') M++;
    if (s[0] == 'A') A++;
    if (s[0] == 'R') R++;
    if (s[0] == 'C') C++;
    if (s[0] == 'H') H++;
  }
  
  long long int num = 0;
  num = M*A*R + M*A*C + M*A*H + M*R*C + M*R*H + M*C*H + A*R*C + A*R*H + A*C*H + R*C*H;
  printf("%lld", num);
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
 
#pragma GCC optimize ("O2")
using namespace std;
 
int main()
{
    int N, M;
    cin >> N >> M;
    int L[N], R[N];
    for(int i=0; i<M; i++){
        cin >> L[i] >> R[i];
    }
    int min = 1;
    int max = N;
    for(int i=0; i<M; i++){
        if(min < L[i]){
            min = L[i];
        }
        //printf("min update %d -> %d\n", min, L[i]);
        if(max > R[i]){
            max = R[i];
        }
        //printf("max update %d -> %d\n", max, R[i]);
    }
    if(min > max){
        cout << 0 << endl;
    }else{
        cout << (max-min+1) << endl;
    }
    return 0;
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define pb push_back
#define ins insert

using namespace std;

typedef long long ll;
bool LTE(double a,double b) { return equals(a,b) || a < b; }
bool LT(double a,double b) { return !equals(a,b) && a < b; }

void compute() {

}

int main() {
  int n,a,b;
  cin >> n >> a >> b;
  int mini = INT_MAX;
  int maxi = -INT_MAX;
  for(int i=0;i<=n;++i) {
    int sum = ( a-i + b-i + i );
    if( (a-i) >= 0 && (b-i) >= 0 && ( a-i + b-i + i >= 0 ) && sum <= n )  {
      mini = min(mini,i);
      maxi = max(maxi,i);
    }
  }
  cout << maxi << " " << mini << endl;
  compute();
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    string ss;
    cin>>ss;
    cout<<ss[0]<<ss[1]<<ss[2]<<'\n';
    return 0;
}


Measured memory_bytes: 3640
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
 
from functools import reduce
# from math import *
from fractions import *
N, M = map(int, readline().split())
A = list(map(lambda x: int(x) // 2, readline().split()))

def f(n):
    cnt = 0
    while n % 2 == 0:
        n //= 2
        cnt += 1
    return cnt
t = f(A[0])
for i in range(N):
    if f(A[i]) != t:
        print(0)
        exit(0)
    A[i] >>= t
M >>= t
lcm = reduce(lambda a, b: (a * b) // gcd(a, b), A)
if lcm > M:
    print(0)
    exit(0)

print((M // lcm + 1) // 2)


Measured memory_bytes: 14528
#include <stdio.h>

int main(void){
    int i,dice[7];
    char order[101];
    
    for(i=1;i<7;i++)
        scanf("%d", &dice[i]);
    
    scanf("%s", order);
    
    for(i=0;order[i]!='\0';i++){
        
        dice[0] = dice[1];
        
        switch(order[i]){
                
            case 'E':
                dice[1] = dice[4];
                dice[4] = dice[6];
                dice[6] = dice[3];
                dice[3] = dice[0]; 
                break;
            
            case 'N':
                dice[1] = dice[2];
                dice[2] = dice[6];
                dice[6] = dice[5];
                dice[5] = dice[0]; 
                break;
            
            case 'S':
                dice[1] = dice[5];
                dice[5] = dice[6];
                dice[6] = dice[2];
                dice[2] = dice[0]; 
                break;
                
            case 'W':
                dice[1] = dice[3];
                dice[3] = dice[6];
                dice[6] = dice[4];
                dice[4] = dice[0]; 
                break;

        }
    }
    
    printf("%d\n", dice[1]);
    
    return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;

Int n;

void func(Int cur,int use,Int &counter){
    if(cur>n) return;
    if(use == 0b111) ++counter;
    func(cur*10+7,use|0b001,counter);
    func(cur*10+5,use|0b010,counter);
    func(cur*10+3,use|0b100,counter);
}
int main(){
    cin >> n;
    Int res = 0;
    func(0,0,res);
    cout << res << endl;
}


Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}

import Control.Monad
import Data.List
import Data.Bits
import Debug.Trace
import Data.Maybe
import qualified Data.ByteString.Char8 as C

main :: IO ()
main = do
  [h, w] <- readInts
  [sh, sw] <- readInts
  print $ solve h w sh sw

solve h w sh sw = h * w - sw * h - sh * w + sh * sw

-- 以下ライブラリ

readInts :: IO [Int]
readInts = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

readNInts :: Int -> IO [[Int]]
readNInts = flip replicateM readInts

readIntegers :: IO [Integer]
readIntegers = map (fst . fromJust . C.readInteger) . C.words <$> C.getLine

readNIntegers :: Int -> IO [[Integer]]
readNIntegers = flip replicateM readIntegers

getNLns :: Int -> IO [String]
getNLns = flip replicateM getLine

Measured memory_bytes: 380
#include <bits/stdc++.h>
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define rep(i,l,r) for(int i = (int)l;i<(int)r;i++)
#define td(v) v.begin(),v.end()
#define sz(v) (int)v.size()
//#define M   1000000007 // 1e9 + 7
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
inline ll mod(ll n, ll m){ ll ret = n%m; if(ret < 0) ret += m; return ret; }
ll gcd(ll a, ll b){return (b == 0LL ? a : gcd(b, a%b));}
ll exp(ll a,ll b,ll m){
    
    if(b==0LL) return 1LL;
    if(b==1LL) return mod(a,m);
    ll k = mod(exp(a,b/2,m),m);
    if(b&1LL){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}


int32_t main(){
  fastio;
  int a,b,c,d;
  cin>>a>>b>>c>>d;

  int t=0;
  while(a>0 and c>0){
    if(t==0){
      c-=b;
    }else a-=d;
    t^=1;
  }
  if(c<=0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  // Math -> gcd it all
  // Did u check N=1? Did you switch N,M?
}

Measured memory_bytes: 3652
def solve(n, k, t)
  return 1 if n == 0
  return 0 if k == 0
  ret = 0
  t.downto(Math.sqrt(n / k).to_i) do |x|
    ret += solve(v = n - x * x, k - 1, @cmp[x][v])
  end
  ret
end

@cmp = (0..Math.sqrt(2**15).to_i).map{ |i| (0..2**15).map{ |j| i * i > j ? Math.sqrt(j).to_i : i } }

while n = gets.to_i
  break if n == 0
  puts solve(n, 4, Math.sqrt(n).to_i)
end

Measured memory_bytes: 55972
#include <iostream>
#include <string>

using namespace std;

int main()
{
	int n, x;
	string ans;

	while (true)
	{
		cin >> n >> x;

		if (n == 0 && x == 0)
			break;

		int count = 0;
		for (int i = 1; i <= n; ++i)
			for (int j = i + 1; j <= n; ++j)
				for (int k = j + 1; k <= n; ++k)
					if (i + j + k == x)
						++count;

		ans += to_string(count);
		ans += " ";
	}

	for (int i = 0; i < ans.size(); ++i)
		(ans[i] != ' ') ? cout << ans[i] : cout << endl;

	return 0;
}

Measured memory_bytes: 3204
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 1000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
int n,a[111][111],b[111];
bool check[111111];
signed main(){
	
	
	rep(i,3)rep(j,3)cin>>a[i][j];
	cin>>n;
	rep(i,n)cin>>b[i];
	
	rep(i,n){
	    check[b[i]]=1;
	}
	bool af=false;
	rep(i,3){
	    int f=1;
	    rep(j,3){
	        if(!check[a[i][j]])f=0;
	    }
	    if(f)af=true;
	}
	rep(i,3){
	    int f=1;
	    rep(j,3){
	        if(!check[a[j][i]])f=0;
	    }
	    if(f)af=true;
	}
	if(check[a[0][0]]&&check[a[1][1]]&&check[a[2][2]])af=true;
	if(check[a[2][0]]&&check[a[1][1]]&&check[a[0][2]])af=true;
	if(af)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
const int N=3003;
struct node { int y,next; } a[N<<1];
int head[N],A[N],i,j,k,n,m;
char c;

inline char getc()
{
	#define VV 10000000
	static char s[VV],*l=s,*r=s;
	if (l==r)
		l=s,r=s+fread(s,1,VV,stdin);
	return l==r?0:*l++;
}

int read(){ int z=0; do c=getc(); while (c<'0'||c>'9'); while (c>='0'&&c<='9') z*=10,z+=c-'0',c=getc(); return z; }

void jb(int x,int y)
{
	a[++k]=(node){y,head[x]},head[x]=k,
	a[++k]=(node){x,head[y]},head[y]=k;
}

bool dfs(int w,int sp)
{
	//printf("%d %d\n",i,w);
	for (register int j=head[w];j;j=a[j].next)
		if ((j^1)!=sp)
		{
			int c=a[j].y;
			if (A[w]>A[c]&&!dfs(c,j))
				return 1;
		}
	return 0;
}

int main()
{
	n=read(),k=1;
	for (i=1;i<=n;++i) A[i]=read();
	for (i=1;i<n;++i) jb(read(),read());
	for (i=1;i<=n;++i)
		if (dfs(i,0))
			printf("%d ",i);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    long long int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    long long int cost = 0;
    if(a + b > 2 * c)
    {
        //abを2枚のほうが安い
        if(x < y)
        {
            cost += 2 * x * c;
            y -= x;
            if(b < 2 * c)
            {
                //b一枚のほうが安い
                cost += y * b;
            }else{
                cost += 2 * y * c;
            }
        }else{
            cost += 2 * y * c;
            x -= y;
            if(a < 2 * c)
            {
                //a一枚のほうが安い
                cost += x * a;
            }else{
                cost += 2 * x * c;
            }
        }
    }else{
        cost += a * x + y * b;
    }
    cout << cost << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
	
	int A, B, C;

	scanf("%d %d %d", &A, &B, &C);

	if(A >= B && A >= C){
		printf("%d", A*10+B+C); 
	}
	else if(B >= C && B >= A){
		printf("%d", B*10+A+C); 
	}
	else{
		printf("%d", C*10+A+B);
	}

	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<cmath>

using namespace std;
typedef long long ll;
const ll limit = 1e6+2;
long long p[limit],c[limit],a[limit];
long long t,n,d,temp=0,m;

int main()
{
    cin>>n>>m;
    for(ll i=1;i<=m;i++)
    {
        cin>>a[i];
        temp+=a[i];
    }
    if(temp<=n) cout<<n-temp;
    else cout<<-1;
}


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

int main() {
  int s1s2s3, s1, s2, s3;
  
  cin >> s1s2s3;
  
  s1 = (100 + (s1s2s3 / 100) * 100) / 2 / 100;

  s2 = s1s2s3 - (1 + s1) / 2 * 100;
  s2 = (10 + (s2 / 10) * 10) / 2 / 10;
  
  s3 = s1s2s3 - (1 + s1) / 2 * 100 - (1 + s2) / 2 * 10;
  s3 = (1 + s3) / 2;

  cout << s1 + s2 + s3 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int A, B, C, X; cin >> A >> B >> C >> X;
    int ans = 0;
    for(int a = 0; a <= min(X/500,A); a++)
    {
        for(int b = 0; b <= min((X - 500*a)/100,B); b++)
        {
            if((X - 500*a - 100*b)% 50 == 0 && (X - 500*a - 100*b)/ 50 <= C)
            {
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;

void YesNo(bool x) {
    cout << (x ? "Yes" : "No") << endl;
}

int main() {
    int r, g, b;
    cin >> r >> g >> b;
    int x = r * 100 + g * 10 + b;
    cout << (x % 4 == 0 ? "YES" : "NO") << endl;
    return 0;
}

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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int WWW = 0;WWW < (n);WWW++)cerr << v[WWW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL


typedef long long ll;
typedef pair<ll,ll> P;

const ll mod1 = 1000000007;
const ll mod2 = 1000000009;
const ll seica1 = 114514;
const ll seica2 = 1919810;

#define NODE 555555
pair<ll,ll> f[2][NODE];
ll mod[] = {1000000007,1000000009};
ll kake[] = {114514,1919810};
ll inv[2];
int n;
string str;
map<pair<ll,ll>,ll> mp;

ll m_pow(ll a,ll b,ll p){
	ll ret = 1;
	ll tmp = a;
	for(ll i = 0LL;i < 60;i++){
		if(b & (1LL << i)){
			ret *= tmp;
			ret %= p;
		}
		tmp *= tmp;
		tmp %= p;
	}
	return ret;
}

ll m_inv(ll a,ll p){
	return m_pow(a,p-2,p);
}

void get_f(int num,int type){
	pair<ll,ll> now = MP(1,0);
	pair<ll,ll> prev;
	if(num == n-1){
		prev = MP(1,0);
	}
	else{
		prev = f[type][num+1];
	}
	
	if(str[num] == '<'){
		now.FI = kake[type];
	}
	else if(str[num] == '>'){
		now.FI = inv[type];
	}
	else if(str[num] == '+'){
		now.SE = mod[type] - 1;
	}
	else{
		now.SE++;
	}
	
	ll fir = now.FI * prev.FI % mod[type];
	ll sec = (now.SE * prev.FI % mod[type] + prev.SE) % mod[type];
	f[type][num] = MP(fir,sec);
}

pair<ll,ll> dfs(int num,int type){
	pair<ll,ll> now = MP(1,0);
	pair<ll,ll> prev;
	if(num == 0){
		prev = MP(1,0);
	}
	else{
		prev = dfs(num-1,type);
	}
	
	if(str[num] == '>'){
		now.FI = kake[type];
	}
	else if(str[num] == '<'){
		now.FI = inv[type];
	}
	else if(str[num] == '-'){
		now.SE = mod[type] - 1;
	}
	else{
		now.SE++;
	}
	
	ll fir = now.FI * prev.FI % mod[type];
	ll sec = (now.SE * prev.FI % mod[type] + prev.SE) % mod[type];
	return MP(fir,sec);
}

ll get_x(ll x,ll num,ll type){
	return (f[type][num].FI * x % mod[type] + f[type][num].SE) % mod[type];
}

int main(){
	
	inv[0] = m_inv(kake[0],mod[0]);
	inv[1] = m_inv(kake[1],mod[1]);
	
	cin >> n >> str;
	for(int i = str.size()-1;i >= 0;i--){
		get_f(i,0);
		get_f(i,1);
	}
	
	ll c[2] = {dfs(n-1,0).SE,dfs(n-1,1).SE};
	
	ll ans = 0;
	mp[{0,0}]++;
	for(int i = str.size()-1;i >= 0;i--){
		ans += mp[{get_x(c[0],i,0),get_x(c[1],i,1)}];
		mp[{get_x(0,i,0),get_x(0,i,1)}]++;
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 53636
#include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main()
{
	int n;cin>>n;
	int k;cin>>k;
	map<int,int> mp;
	rep(i,n)
	{
		int foo;
		cin >>foo;
		mp[foo]++;
	}
	vector<int> A;
	 for( auto i = mp.begin(); i != mp.end() ; ++i ) {
      A.push_back(i->second);
  }
  sort(ALL(A),greater<int>());

  int c=0;
  for(int i=k;i<A.size();i++)
  c+=A[i];

  cout<<c<<endl;


	
	return 0;
}

Measured memory_bytes: 10748
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;
use std::ops::Bound::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (n, m) = (v[0], v[1]);
    let mut g = vec![vec![]; n];
    let mut rg = vec![vec![]; n];
    for i in 0..m {
        let v = read_vec::<usize>();
        let (a, b) = (v[0], v[1]);
        add_edge(a, b, &mut g, &mut rg);
    }
    scc(&g, &rg);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

type Graph = Vec<Vec<usize>>;

fn dfs(v: usize, used: &mut Vec<bool>, g: &Graph, vs: &mut Vec<usize>) {
    used[v] = true;
    for &to in g[v].iter() {
        if !used[to] {
            dfs(to, used, g, vs);
        }
    }
    vs.push(v);
}

fn rdfs(v: usize, k: usize, used: &mut Vec<bool>, rg: &Graph, cmp: &mut Vec<usize>) {
    used[v] = true;
    cmp[v] = k;
    for &to in rg[v].iter() {
        if !used[to] {
            rdfs(to, k, used, rg, cmp);
        }
    }
}

fn add_edge(from: usize, to: usize, g: &mut Graph, rg: &mut Graph) {
    g[from].push(to);
    rg[to].push(from);
}

fn scc(g: &Graph, rg: &Graph) -> Vec<usize> {
    let mut used = vec![false; g.len()];
    let mut vs = vec![];
    for v in 0..g.len() {
        if !used[v] {
            dfs(v, &mut used, &g, &mut vs);
        }
    }
    let mut used = vec![false; g.len()];
    let mut cmp = vec![0usize; g.len()];
    let mut k = 0;
    for &i in vs.iter().rev() {
        if !used[i] {
            rdfs(i, k, &mut used, &rg, &mut cmp);
            k += 1;
        }
    }
    let mut orders = vec![vec![]; cmp.iter().max().unwrap() + 1];
    for i in 0..cmp.len() {
        orders[cmp[i]].push(i);
    }
    // debug!(orders);
    println!("{}", orders.len());
    for order in orders {
        print!("{} ", order.len());
        for num in order {
            print!("{} ", num);
        }
        println!("");
    }
    cmp
}


Measured memory_bytes: 86140
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i = a;i < n;i++)
typedef unsigned long long ull;
typedef long long ll;
using namespace std;


ull gcd(ull a,ull b){
	if(!b) return a;
	return gcd(b,a%b);
}

int main(){
	int n,c,t,memo1,memo2,ans = 0;
	bool flag = true;
	cin >> n >> c >> t;
	int a[n];
	
	rep(i,0,n){
		cin >> a[i];
	}
	
	sort(a,a+n);
	
	rep(i,0,n){
		if(!flag){
			memo2++;
			if(memo2 > c || a[i] > memo1){
				flag = true;
			}
		}
		
		if(flag){
			flag = false;
			memo2 = 0;
			memo1 = a[i]+t;
			memo2++;
			ans++;
		}
		
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640