akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
double EPS=1e-8;
int INF = 1e9;
int MOD=10007;
int dp[1000][1<<3];
int main(){
	string s;
	int n;
	cin>>n>>s;
	dp[0][1<<2]=1;
	for(int i=1;i<=n;i++){
		int t=s[i-1]=='J'?2:s[i-1]=='O'?1:0;
		REP(j,1<<3){
			if(!(j>>t&1))continue;
			REP(k,1<<3){
				bool f=false;
				REP(l,3)if(j>>l&k>>l)f=true;
				if(f){
					dp[i][j]+=dp[i-1][k];
				}
			}
		}
		REP(j,1<<3)dp[i][j]%=MOD;
	}
	int ans=0;
	REP(i,1<<3)ans+=dp[n][i];
	cout<<ans%MOD<<endl;
}

Measured memory_bytes: 1236
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll c(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }

int main(void) {
	ll n, ans = 1;
	cin >> n;
	vector<ll> a(n);
	rep(i, 0, n) {
		cin >> a[i];
		if (a[i] == 0) {
			puts("0");
			return 0;
		}
	}
	rep(i, 0, n) {
		if (ans / 1000 * a[i] > 1000000000000000 || ans * a[i] > 1000000000000000000) {
			puts("-1");
			return 0;
		}
		ans *= a[i];
	}
	printf("%lld\n", ans);
	return 0;
}


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

int main()
{
  int N;
  string C;
  cin >> N;
  
  for (int i = 0; i < N; i++)
  {
  	cin >> C;
    if (C == "Y")
    {
      cout << "Four" << endl;
      return 0;
    }
  }
  cout << "Three" << endl;
}


Measured memory_bytes: 256
x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

d = []
for i in range(x):
    for j in range(y):
        d.append(a[i] + b[j])
d.sort(reverse=True)

e = []
for i in range(min(len(d), k)):
    for j in range(z):
        e.append(d[i] + c[j])
e.sort(reverse=True)

for i in range(k):
    print(e[i])


Measured memory_bytes: 147904
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}


macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn runlength<A: Copy + PartialEq>(xs: &Vec<A>) -> Vec<(A, usize)> {
    let m = xs.len();
    if m == 0 { return vec![]; }
    let mut count = 1;
    let mut result = vec![];
    for i in 0..m {
        if i > 0 {
            if xs[i - 1] == xs[i] {
                count += 1;
            } else {
                count = 1;
            }
        }
        if i == m - 1 || xs[i] != xs[i + 1] {
            result.push((xs[i], count));
        }
    }
    result
}

fn main() {
    let mut sc = Scanner::new();
    let _: usize = sc.cin();
    let s: Vec<char> = sc.cin::<String>().chars().collect();
    put!(runlength(&s).len())
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}


Measured memory_bytes: 6396
import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader r =
			new BufferedReader(new InputStreamReader(System.in),1);
			Stack<Integer> ans = new Stack<Integer>();
			//System.out.flush();
			String s =r.readLine();
			int n = Integer.parseInt(s);
			int maxlength;
			int digit,updigit;
			//char ar[]={'0'};
			//char br[]={'0'};
			int j,i;
		
			for(i=0;i<n;i++){
				ans.clear();
				String as = r.readLine();
				String bs = r.readLine();
				char a[] = as.toCharArray();
				char b[] = bs.toCharArray();
				//for(j=0; j<a.length; j++) ar[j] = a[a.length-1-j];
				//for(j=0; j<a.length; j++) br[j] = b[b.length-1-j];
				if(a.length > b.length) maxlength = a.length;
				else maxlength = b.length;
				updigit = 0;
				digit = 0;

				for(j=0;j<maxlength;j++){
					if(j < a.length && j < b.length){
						digit = (int)a[a.length-1-j] + (int)b[b.length-1-j] - 96 + updigit;
					}else if(j < a.length){
						digit = (int)a[a.length-1-j] - 48 + updigit;
					}else{
						digit = (int)b[b.length-1-j] - 48 + updigit;
					}
					updigit = 0;
					if(digit >= 10){
						digit -= 10;
						updigit = 1;
					}
					ans.push(digit);
				}
				if(updigit >= 1) ans.push(updigit);
				if (ans.size()>80) System.out.print("overflow");
				else while(!ans.empty()) System.out.print(ans.pop());
			    System.out.println("");
			}
	}
}

Measured memory_bytes: 16960
def insert_sort(items)
  puts items.join(" ")
  1.upto(items.size-1) do |i|
    v = items[i]
    j = i - 1
    while j >= 0 && items[j] > v
      items[j+1] = items[j]
      j -= 1
    end
    items[j+1] = v # 挿入
    puts items.join(" ")
  end
end

gets
items = gets.split(" ").map(&:to_i)
insert_sort(items)



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

using namespace std;
using ll = unsigned long long;
constexpr int mod = 1e9+7;
constexpr int md = mod;

int main(){
    ll n;
    vector<ll> d(5);
    cin>>n;
    for(int i=0;i<5;++i){
        cin>>d[i];
    }
    ll m = *min_element(d.begin(),d.end());
    ll minut = (n+m-1)/m + 4uLL;
    cout << minut << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s;
    ll k;
    cin>>k>>s;
    if (s.size()<=k)cout<<s;
    else cout<<s.substr(0,k)+"...";
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll N;
  cin  >> N;
  vl a(N);
  rep(i, N) cin >> a[i];

  vl p(N, 0);
  ll b = 1;
  ll cnt = 0;
  p[0] = 1;
  while(true){
    cnt++;
    b = a[b - 1];
    
    if(b == 2){
      cout << cnt << endl;
      return 0;
    }
    if(p[b - 1] == 1){
      cout << -1 << endl;
      return 0;
    }

    p[b - 1] = 1;
  }
  
  return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>

int max(int x,int y){
	if(x>y)return x;
	return y;
}

int min(int x,int y){
	if(x<y)return x;
	return y;
}

int main(){
	int N,A,B;
	scanf("%d%d%d",&N,&A,&B);
	printf("%d %d\n",min(A,B),max(0,A+B-N));
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<(n);i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;

int main(){
    int n ;cin>>n;
    int v[n];
    rep(i,n)cin>>v[i];
    vi e(100005.0),p(100005,0);
    rep(i,n){
        if(i%2==0){
            e[v[i]]++;
        }
        else p[v[i]]++;
    }
    int em=max_element(been(e))-e.begin(),pm=max_element(been(p))-p.begin();
    if(em==pm){
        int ee =e[em],pp=p[pm];
        e[em]=0;p[pm]=0;
        em=max_element(been(e))-e.begin(),pm=max_element(been(p))-p.begin();
        cout<<min(n-ee-p[pm],n-e[em]-pp)<<endl;
    }
    else{
        cout<<n-e[em]-p[pm]<<endl;
    }
}

Measured memory_bytes: 1408
#!/usr/bin/env python3
import sys


def solve(A: int, B: int, N: int):
    if A == 1: return 0

    if N < B:
        x = N
    else:
        md = N % B
        x = int(N - (md + 1))
    return int((A*x)//B) - A * int(x//B)

    # m = -1
    # for i in range(N+1):
    #     x = i
    #     m = max([m, int((A*x)/B) - A * int(x/B)])
    # return m


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    # N = pow(10, 9)
    print(solve(A, B, N))

if __name__ == '__main__':
    main()


Measured memory_bytes: 9144
N = int(input())
S = str(input())
ans = [0 for i in range(0, N + 1)]
for i in range(0, N):
    if S[i] == "I":
        ans[i + 1] = ans[i] + 1
    else:
        ans[i + 1] = ans[i] - 1
print(max(ans))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<n;i++)
#define all(cont) cont.begin(), cont.end()
#define unique(a)  sort(all(a)) , (a).erase(unique((a).begin(), (a).end()),(a).end())
#define rall(cont) cont.rbegin(), cont.rend()
#define sz(x) (int)(x).size()
#define fastio          ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define PB push_back
#define endl "\n"
#define f first
#define s second
#define mset(m,v) memset(m,v,sizeof(m))
#define mod 1000000007
const int N = 2e5 + 5, INF = 1E9 + 7;
#define PI acos(-1.0)
long double EPS = 1e-9;
typedef long long ll;
#define int long long
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpii;
#define pqll_max priority_queue<ll> // max heap. push(),pop(),top(),size(),empty()
#define pqll_min priority_queue<ll,vector<ll>,greater<ll> >
#define lb(v,val)   lower_bound(v.begin(),v.end(),val) //first equal to or lower than [------------
#define ub(v,val)   upper_bound(v.begin(),v.end(),val) //first greater than ------------)
#define bs(v,x) binary_search(v.begin(),v.end(),x)
inline ll add(ll x, ll y) { x += y; if (x >= mod) x -= mod; return x; }
inline ll sub(int x, int y) { x -= y; if (x < 0) x += mod; return x; }
inline ll mul(ll x, ll y) { return (x%mod * 1ll * y%mod) % mod; }
inline ll pwr(ll a, ll b) { ll x = 1 % mod; while (b) { if (b & 1) x = mul(x, a); a = mul(a, a); b >>= 1; }return x % mod; }
inline ll inv(ll a) { return pwr(a, mod - 2) % mod; }
ll gcd(ll a, ll b) { if (!a)return b % mod; return gcd(b%a, a) % mod; }
#define debug(x) cout << #x << " = " << x << endl;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#define in(container) for (auto &it : container) cin>>it;
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
void solve() {
	int a, b, c,k;
	cin >> a >> b >> c>>k;
	int count = 0;
	while (b <= a) {
		b *= 2;
		count++;
	}
	while (c <= b) {
		c *= 2;
		count++;
	}
	if (count <= k) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	
}
signed main()
{
	fastio;
	//cout<<fixed<<setprecision(15);
	//clock_t begin = clock();
	int tc;
	tc = 1;
	//cin >> tc;
	while (tc--) {
		solve();
	}
	//clock_t end = clock();double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;cerr << elapsed_secs;
}


//Error?
// clear lists for every test case
// print new line for each tc
// check for int or ll
// check if problem can be solved without any heavy DS like priority_queue or map



Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
int dp[110][110];
int n;
void WF(){
	lol(k,n){
		lol(i,n){
			lol(j,n){
				dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
			}
		}
	}
}
int main(){
	cin>>n;
	lol(i,n)lol(j,n)dp[i][j]=mod;
	lol(i,n){
		int r,k;cin>>r>>k;r--;
		while(k--){
			int a;cin>>a;a--;
			dp[r][a]=1;
		}
	}
	WF();
	int q;cin>>q;
	while(q--){
		int a,b,c;
		cin>>a>>b>>c;a--,b--;
		int tmp=dp[a][b]+1;
		if(tmp<=c)cout<<tmp<<endl;
		else cout<<"NA"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string s;
  cin >> s;
  
  int count = 0;
  for(int i = 0; i < 3; i++){
    if(s[i] == 'o') count++;
  }
  
  cout << 700 + count * 100 << endl;
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)
	d := []string{"maerd", "remaerd", "esare", "resare"}
	s = Reverse(s)

	if check(s, d) {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

func Reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func check(s string, d []string) bool {
	for i := 0; i < len(d); i++ {
		if len(s) < len(d[i]) {
			continue
		}
		if s[0:len(d[i])] == d[i] {
			if len(s) == len(d[i]) {
				return true
			}
			return check(s[len(d[i]):], d)
		}
	}
	return false
}


Measured memory_bytes: 5888
import itertools
n, m, q = map(int, input().split())
a_tmp = b_tmp = c_tmp = d_tmp = 0
a = []
b = []
c = []
d = []
for i in range(q):
    a_tmp, b_tmp, c_tmp, d_tmp = map(int, input().split())
    a.append(a_tmp)
    b.append(b_tmp)
    c.append(c_tmp)
    d.append(d_tmp)
max = 0
for i in itertools.combinations_with_replacement(range(m), n):
    s = 0
    for j in range(q):
        if i[b[j]-1] - i[a[j]-1] == c[j]:
            s = s + d[j]
    if s > max:
        max = s
print(max)

Measured memory_bytes: 9228
from collections import deque
N,M = map(int, input().split())
E = [[] for _ in range(N)]
memo = [0]*N
for _ in range(N+M-1):
    a,b = map(int, input().split())
    E[a-1].append(b-1)
    memo[b-1] += 1

root = memo.index(0)
rnk = [0]*N
par = [-1]*N

q = deque()
q.append(root)
while q:
    temp = q.popleft()
    u = temp%N
    r = temp//N
    for v in E[u]:
        memo[v] -= 1
        if memo[v] > 0:
            continue
        rnk[v] = r+1
        par[v] = u
        q.append((r+1)*N+v)

for p in par:
    print(p+1)

Measured memory_bytes: 89248
def findGCD(a:int, b:int) -> int:
    # バリデーション　a,bは0以上
    if a <= 0:
        raise ValueError("aは0より大きくなければいけません。(a:{})".format(a))
    elif b <= 0:
        raise ValueError("bは0より大きくなければいけません。(b:{})".format(b))
    
    # ユークリッドの互除法
    while 1:
        if a%b == 0:
            return b
        else:
            a = a%b
        
        if b%a == 0:
            return a
        else:
            b = b%a
            
from functools import reduce

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


gcd = reduce(findGCD, a)

if k % gcd == 0 and k <= max(a):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 14596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
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; }
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;


ll score(vector<ll> vec,vector<ll> A,vector<ll> B,vector<ll> C, vector<ll> D) {
    ll ans = 0 ;
    for (ll i = 0;i<C.size();i++) {
        if (vec.at(B.at(i)-1) - vec.at(A.at(i)-1) == C.at(i)) {
            ans+=D.at(i);
        }
    }
    return ans;
} 


void func(vector<vector<ll>> &All,ll N,ll M, vector<ll> initial) {
    if (initial.size() == N) {
        All.push_back(initial);
        return;
    }

    ll end = initial.at(initial.size()-1);
    for (ll i = end;i<=M;i++) {
        initial.push_back(i);
        func(All,N,M,initial);
        initial.pop_back();
    }
}


int main() {
    ll N,M,Q;
    cin >> N >> M >> Q;
    vector<ll> A;
    vector<ll> B;
    vector<ll> C;
    vector<ll> D;
    for (ll i = 0;i<Q;i++){
        ll a,b,c,d;
        cin >> a >> b >> c >> d;
        A.push_back(a);
        B.push_back(b);
        C.push_back(c);
        D.push_back(d);
    }
    vector<vector<ll>> All;
    for (ll i = 1;i<=M;i++) {
        vector<ll> initial;
        initial.push_back(i);
        func(All,N,M,initial);
    }
    ll ans = 0;
    for (ll i = 0;i<All.size();i++) {
        ans = max(ans,score(All.at(i),A,B,C,D));
    }
    cout << ans << endl;
}


Measured memory_bytes: 14004
#include <bits/stdc++.h>
#include<iostream>
#include<set> 
#include<queue> 
#include<stack> 
#include<vector> 
#include<string> 
#include<numeric> 
#include<algorithm> 
#include<math.h> 
#include<iomanip>
using namespace std;
int main()
{
	long long int n,i,j,a[100005],b[100005],ans=0;
	cin>>n;
	for(i=1;i<=n+1;i++)
	cin>>a[i];
	for(i=1;i<=n;i++)
	cin>>b[i];
	
	for(i=1;i<=n;i++)
	{
		if(a[i]>=b[i])
		{
			ans=ans+b[i];
			a[i]=a[i]-b[i];
			b[i]=0;
			//cout<<" 1 ";
		}
		else if(a[i]<b[i])
		{
			ans=ans+a[i];
			b[i]=b[i]-a[i];
			a[i]=0;
		}
		if(a[i+1]<=b[i])
		{
			ans=ans+a[i+1];
			b[i]=b[i]-a[i+1];
			a[i+1]=0;
			//cout<<" 3 ";
			
		}
		else if(a[i+1]>b[i])
		{
			ans=ans+b[i];
			a[i+1]=a[i+1]-b[i];
			b[i]=0;
			//cout<<" 4 ";
		}
		//cout<<ans<<" ";
	}
	cout<<ans;


	return 0;
}

Measured memory_bytes: 1792
a,b=input().split()
a=int(a)
b=int(b)
d=input().split()
d= [int(n) for n in d]
d.sort(reverse=True)
k=4*b
t=1/k
q=sum(d)
if d[b-1]<t*q:
    print("No")
else:
    print("Yes")

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

int main()
{
  int64_t N, M, a, b, l = 0, ans = 0;
  cin >> N >> M;
  vector<pair<int64_t, int64_t>> vp(M);
  for (int i = 0; i < M; i++)
  {
    cin >> a >> b;
    vp.at(i) = make_pair(b, a);
  }
  sort(vp.begin(), vp.end());
  for (int i = 0; i < M; i++)
  {
    if (vp[i].second < l)
      continue;
    ans++;
    l = vp[i].first;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;

void showArray(int A[], int N){
	for (int p = 0; p < N - 1; p++){
		cout << A[p] << " ";
	}
	cout << A[N - 1] << endl;
}

void insertionSort(int A[], int N){
	int key;
	
	showArray(A, N);
	for (int i = 1; i < N; i++){
		key = A[i];
		int j = i - 1;
		while (j >= 0 && A[j] > key){
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = key;
		showArray(A, N);
	}
}

int main(){

	int N;
	int A[100];

	cin >> N;

	for (int i = 0; i < N; i++){
		cin >> A[i];
	}

	insertionSort(A, N);

	return 0;
}

Measured memory_bytes: 1160
import numpy as np
N, A = map(int, input().split())
x = list(map(int, input().split()))

dp = np.zeros((51, 5001), np.int64)  # 50 * 50 = 2500
dp[0, 2500] = 1   # 2500:0, 0:-2500, 5000:2500

for i in range(N):
    for j in range(5001):
        if dp[i, j] != 0:
            dp[i+1, j] += dp[i, j]
            dp[i+1, j+x[i]-A] += dp[i, j]
print(dp[N, 2500] - 1)  # 1つも選ばないパターンを引く


Measured memory_bytes: 13136
N, K = map(int, input().split())
S = list(str(input()))

if (S[K-1] == 'A'):
  S[K-1] = 'a'
elif (S[K-1] == 'B'):
  S[K-1] = 'b'
elif (S[K-1] == 'C'):
  S[K-1] = 'c'
  
ans = ''.join(S)
    
print(ans)



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

struct points
{
	int x[11];	
};
points point[11];

bool ispf[1000010];

inline void init()
{
	memset(ispf,false,sizeof(ispf));
	for(int i=1;i<=1000;i++)
	{
		ispf[i*i]=true;
	}
}

int main()
{
	init();
	cin>>n>>d;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=d;j++)
		{
			cin>>point[i].x[j];
		}	
	}	
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			int total=0;
			for(int k=1;k<=d;k++)
			{
				total+=(point[i].x[k]-point[j].x[k])*(point[i].x[k]-point[j].x[k]);
			}
			if(ispf[total])
				ans++;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1280
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

long ans = 1000000000l;

void rec(long N, long A, long B, long C, vector<long> l, long a, long b, long c, long i, long acc) {
  if (i == N) {
    if (a == 0 || b == 0 || c == 0) return;
    long tmp = abs(A-a) + abs(B-b) + abs(C-c) + acc;
    ans = min(ans, tmp);
    return;
  }
  rec(N, A, B, C, l, a+l[i], b, c, i+1, acc+10);
  rec(N, A, B, C, l, a, b+l[i], c, i+1, acc+10);
  rec(N, A, B, C, l, a, b, c+l[i], i+1, acc+10);
  rec(N, A, B, C, l, a, b, c, i+1, acc);
}

void solve() {
  long N, A, B, C;
  cin >> N >> A >> B >> C;
  vector<long> l(N);
  rep (i, N) cin >> l[i];
  rec(N, A, B, C, l, 0, 0, 0, 0, -30);
  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define faster() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const long long int infLL = 9000000000000000000;
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(a) (a).begin(),(a).end()
#define mx_int_prime 999999937
const int inf = 2000000000;
const double PI = acos(-1);
const double eps = 1e-9;
typedef long double ld;
#define MOD 1000000007
typedef long long ll;
const int mx=2e5+125;
ll p[mx],a[mx],b[mx];
#define PB push_back
#define endl '\n'
#define S second
#define F first
int main()
{
    faster();
    ll n;
    cin>>n;
    set<ll>s;
    for(int i=0; i<n; i++)
    {
        ll x;
        cin>>x;
        s.insert(x);
    }
    if(s.size()==n)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
    return  0;
}


Measured memory_bytes: 12912
#include <iostream>
using namespace std;
int n, c, p[5000]; bool prime[30001];
int main() {
	for(int i = 2; i <= 30000; i++) prime[i] = true;
	for(int i = 2; i * i <= 30000; i++) {
		if(!prime[i]) continue;
		for(int j = i * i; j <= 30000; j += i) prime[j] = false;
	}
	for(int i = 2; i <= 30000; i++) {
		if(prime[i]) p[c++] = i;
	}
	while(cin >> n, n) {
		int ret = 0;
		for(int i = 0; i < c && p[i] < n; i++) {
			for(int j = i; j < c && p[i] + p[j] < n; j++) {
				int w = n - p[i] - p[j];
				if(prime[w] && p[i] + p[j] > w && w >= p[j]) ret++;
			}
		}
		cout << ret << endl;
	}
}

Measured memory_bytes: 3148
n, X = gets.split(" ").map(&:to_i)
ary = gets.split(" ").map(&:to_i)
ans = (ary.min_by{|x| (x - X).abs} - X).abs
if ans == 1
  puts ans
  exit
end
 
ary.each do |x|
  ans = ans.gcd((x - X).abs)
  if ans == 1
    puts ans
    exit
  end
end
 
puts ans


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

int main() {
  ios::sync_with_stdio(false);
	cin.tie(0);
  ll n;
  cin >> n;
  vector<ll> a(n);
  map<ll,ll>mp1;
  map<ll,ll>mp2;
  rep(i,n){
    cin>>a[i];
    a[i];
    ll a1=a[i];
    mp1[a1+i]++;
    mp2[i-a1]++;
  }
  ll ans=0;
  for( auto i = mp1.begin(); i != mp1.end() ; ++i ){
    ll now1= i->first;
    ll cnt2=mp2[now1];
    ll cnt1=i->second;
  //  cout<<cnt1<<' '<<now1<<' '<<cnt2<<endl;
    ans+=(cnt1*cnt2);
  }
  cout<<ans;

}


Measured memory_bytes: 39080
import kotlin.math.*
import java.io.BufferedReader
import java.io.InputStreamReader
import java.util.*


private var fs = BufferedReader(InputStreamReader(System.`in`))
private fun readLn() = fs.readLine()!! // string line
private fun readStrings() = readLn().split(" ") // list of strings
private fun readLong() = readLn().toLong()
private fun readLongs() = readStrings().map { it.toLong() } // list of ints
private fun readInt() = readLn().toInt() // single int
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun main() {
    solveAtc()
}
fun solveAtc() {
    var input = Scanner(System.`in`)
    input.useLocale(Locale.US)
    var a = input.nextLong()
    var b = input.next()
    var c = b.substringBeforeLast(".").toLong()
    var d = b.toString().substringAfterLast(".").toLong()
    println((d*a)/100L + c*a)
}


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

int main(void)
{
    int totalNumber;
    cin >> totalNumber;

    int* data = new int[totalNumber];
    for (int i = 0; i < totalNumber; i++) cin >> data[i];
    for (int i = 0; i < totalNumber; i++) {
        if (i) cout << ' ';
        cout << data[i];
    }
    cout << endl;

    int currentData;
    for (int i = 1; i < totalNumber; i++) {
        currentData = data[i];

        int j = i - 1;
        while (j >= 0 && data[j] > currentData) {
            data[j + 1] = data[j];
            j--;
        }
        data[j + 1] = currentData;

        for (int i = 0; i < totalNumber; i++) {
            if (i) cout << ' ';
            cout << data[i];
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 1188
n,x,m = map(int,input().split())
first = [0] * (m+1)

a = [x]
first[x] = 1
for i in range(2,m+10):
    x = pow(x,2,m)
    if(first[x] != 0):
        break
    first[x] = i
    a.append(x)

# print(a)

if(i-1 >= n):
    ans = sum(a[:n])
    print(ans)
    exit()

cyc = a[first[x]-1:]
for j in range(1,len(cyc)):
    cyc[j] += cyc[j-1]

ans = sum(a[:first[x]-1])
# print(ans)
rem = n - first[x] + 1
ans += cyc[-1] * (rem//len(cyc))
# print(ans)
if(rem%len(cyc) != 0):
    ans += cyc[rem%len(cyc) - 1]
print(ans)

Measured memory_bytes: 69140
Q = int(input().strip())

NUMS = 100000
fs = [True] * (NUMS + 1)
cs = [0] * (NUMS + 1)

for i in range(2,int(pow(NUMS,0.5))):
    if fs[i]:
        for j in range(i + i, NUMS,i):
            fs[j] = False
for i in range(3,NUMS,2):
    if fs[i] and fs[int((i + 1) / 2)]:
        cs[i] += 1
for i in range(3,NUMS):
    cs[i] += cs[i - 1]

for i in range(0,Q):
    l,r = map(int,input().strip().split())
    print(cs[r] - cs[l - 1])


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

typedef struct Coordinate{
    double x, y;
}cd;


void kock(int n, cd p1, cd p2){
    if(n==0) return;
    cd s, t, u;
    /*p1、p2、からs、t、uを計算*/
    s.x = (2.0*p1.x + p2.x) / 3.0;
    s.y = (2.0*p1.y + p2.y) / 3.0;
    t.x = (2.0*p2.x + p1.x) / 3.0;
    t.y = (2.0*p2.y + p1.y) / 3.0;
    u.x = (t.x - s.x) * cos(M_PI/3.0) - (t.y - s.y) * sin(M_PI/3.0) + s.x;
    u.y = (t.x - s.x) * sin(M_PI/3.0) + (t.y - s.y) * cos(M_PI/3.0) + s.y;

    kock(n-1, p1, s);
    printf("%.8f %.8f\n", s.x, s.y);
    kock(n-1, s, u);
    printf("%.8f %.8f\n", u.x, u.y);
    kock(n-1, u, t);
    printf("%.8f %.8f\n", t.x, t.y);
    kock(n-1, t, p2);
}

int main(void){
    int n;
    cd p1, p2;
    p1.x = p1.y = p2.y = 0.0; p2.x = 100.0;
    scanf("%d", &n);
    printf("%.8f %.8f\n", p1.x, p1.y);
    kock(n, p1, p2);
    printf("%.8f %.8f\n", p2.x, p2.y);

    return 0;
}



Measured memory_bytes: 2092
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int mod = 1000000007;
ll gcd(ll a,ll b){
    if(a<b) gcd(b,a);
    else{
        while(a%b){
            ll r=a%b;
            a=b,b=r;
        }
        return b;
    }
}

int main(){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    a -=1;
    ll ans,ac,ad,ae,bc,bd,be;
    ll lcm= c*d/gcd(c,d);
    ac=a/c;
    ad=a/d;
    ae=a/lcm;
    bc=b/c;
    bd=b/d;
    be=b/lcm;
    ans =(b-bc-bd+be)-(a-ac-ad+ae);
    cout<<ans<<endl;
}


Measured memory_bytes: 256
class Array
	def accum
		ac = Array.new(size + 1)
		ac[0] = 0
		(1..size).each do |i|
			ac[i] = ac[i-1] + self[i-1]
		end
		ac
	end

	def accum!
		(1..size-1).each{|i|
			self[i] += self[i-1]
		}
		self.unshift(0)
	end

	def accum_2d
		ac = map{|r| r.accum}
		(1..size-1).each{|i|
			(1..ac[0].size-1).each{|j|
				ac[i][j] += ac[i-1][j]
			}
		}
		ac.unshift([0] * ac[0].size)
		ac
	end

	def accum_2d!
		each{|r| r.accum!}
		(1..size-1).each{|i|
			(1..self[0].size-1).each{|j|
				self[i][j] += self[i-1][j]
			}
		}
		unshift([0] * self[0].size)
	end
		
	def bsearch_first_index(l = 0, r = size - 1, &pred)
		return nil if l > r
		c = (l + r) / 2 
		if pred[self[c]]
			bsearch_first_index(l, c-1, &pred) || c
		else
			bsearch_first_index(c+1, r, &pred)
		end
	end

	def bsearch_first_item(l = 0, r = size - 1, &pred)
		i = bsearch_first_index(l, r, &pred)
		i ? self[i] : nil
	end

	def bsearch_last_index(l = 0, r = size - 1, &pred)
		return nil if l > r
		c = (l + r) / 2 
		if pred[self[c]]
			bsearch_last_index(c+1, r, &pred) || c
		else
			bsearch_last_index(l, c-1, &pred)
		end
	end

	def bsearch_last_item(l = 0, r = size - 1, &pred)
		i = bsearch_last_index(l, r, &pred)
		i ? self[i] : nil
	end
end

h, w = gets.split.map &:to_i
f = []

h.times do
	f.unshift gets.chomp.split("")
end

pile = Hash.new(0)

(1..h).each do |y|
	x = 0
	len = 0
	loop do
		if (f[y-1][x] == ?#) ^ (y != h && f[y][x] == ?#)
			len += 1
		else
			if len > 0
				a1 = Rational(y, x)
				a2 = (x - len == 0 ? Float::INFINITY : Rational(y, x - len))
				pile[a1] += 1
				pile[a2] -= 1
			end
			len = 0
		end
		x += 1

		if x == w
			if len > 0
				a1 = Rational(y, x)
				a2 = (x - len == 0 ? Float::INFINITY : Rational(y, x - len))
				pile[a1] += 1
				pile[a2] -= 1
			end
			break
		end
	end
end

(1..w).each do |x|
	y = 0
	len = 0
	loop do
		if (f[y][x-1] == ?#) ^ (x != w && f[y][x] == ?#)
			len += 1
		else
			if len > 0
				a1 = (x == 0 ? Float::INFINITY : Rational(y, x))
				a2 = (x == 0 ? Float::INFINITY : Rational(y - len, x))
				pile[a2] += 1
				pile[a1] -= 1
			end
			len = 0
		end
		y += 1

		if y == h
			if len > 0
				a1 = (x == 0 ? Float::INFINITY : Rational(y, x))
				a2 = (x == 0 ? Float::INFINITY : Rational(y - len, x))
				pile[a2] += 1
				pile[a1] -= 1
			end
			break
		end
	end
end 

k = pile.sort.map(&:last).accum.max
k += 1 if f[0][0] == ?#
p k / 2 + 1

Measured memory_bytes: 61792
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	char q1,q2,q3,q4;
	cin >> q1 >> q2 >> q3 >> q4;
	int a,b,c,d,a1,a2,b1,b2;
	a1 = (q3 - '0') *10 ;
	a1 += int(q4 - '0');
	b1 = int(q1 - '0') *10;
	b1 += int(q2 - '0');
	if(a1 <= 12 && a1 >= 1) a2 = 1;
	else  a2 = 0;
	if(b1 <= 12 && b1 >= 1) b2 = 1;
	else  b2 = 0;
	if(a2 == 1 && b2 == 1) cout << "AMBIGUOUS" << endl;
	else if(a2 == 1 && !b2) cout << "YYMM" << endl;
	else if(!a2 && b2 == 1) cout << "MMYY" << endl;
	else cout << "NA" << endl; 
}

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

#define rep(i, n) for (int i = 0; i < n;i++)

int main(){

    int A, B,C;
    cin >> A >> B >> C;
    if(A==B||B==C||A==C){
        if(A!=B||B!=C||A!=C)
        cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
    else
        cout << "No" << endl;

        return 0;
}



Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from fractions import Fraction
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations, accumulate
from operator import add, mul, sub, itemgetter, attrgetter


import sys
# sys.setrecursionlimit(10**6)
# readline = sys.stdin.buffer.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(readline())


def read_int_n():
    return list(map(int, readline().split()))


def read_float():
    return float(readline())


def read_float_n():
    return list(map(float, readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.perf_counter()
        ret = f(*args, **kwargs)
        e = time.perf_counter()

        error_print(e - s, 'sec')
        return ret

    return wrap


class UnionFind():
    def __init__(self):
        self.__table = {}
        self.__size = defaultdict(lambda: 1)
        self.__rank = defaultdict(lambda: 1)

    def __root(self, x):
        if x not in self.__table:
            self.__table[x] = x
        elif x != self.__table[x]:
            self.__table[x] = self.__root(self.__table[x])
        return self.__table[x]

    def same(self, x, y):
        return self.__root(x) == self.__root(y)

    def union(self, x, y):
        x = self.__root(x)
        y = self.__root(y)
        if x == y:
            return False

        if self.__rank[x] < self.__rank[y]:
            self.__table[x] = y
            self.__size[y] += self.__size[x]
        else:
            self.__table[y] = x
            self.__size[x] += self.__size[y]
            if self.__rank[x] == self.__rank[y]:
                self.__rank[x] += 1
        return True

    def size(self, x):
        return self.__size[self.__root(x)]

    def num_of_group(self):
        g = 0
        for k, v in self.__table.items():
            if k == v:
                g += 1
        return g


@mt
def slv(N, M, L):
    lo = 10**6
    uf = UnionFind()
    for i, l in enumerate(L):
        for j in l:
            uf.union(i, j+lo)

    return 'YES' if all(uf.same(0, i) for i in range(1, N)) else 'NO'


def main():
    N, M = read_int_n()
    L = [map(lambda x: x-1, read_int_n()[1:]) for _ in range(N)]
    print(slv(N, M, L))


if __name__ == '__main__':
    main()


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

using namespace std; 
  int main()
  {
    int n,k,i,j;
    cin>>n>>k;
    int a[n];
  
      for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    int dp[k+1];
    dp[0]=2;
    int c;
    for(i=1;i<k+1;i++)
    {
        c=0;
       for(j=0;j<n;j++)
       {
           if(i-a[j]>=0&&dp[i-a[j]]==2)
           {
               c++;
               dp[i]=1;
               break;
           }
       }
       if(c==0)
       dp[i]=2;
    }
    if(dp[k]==2)
    cout<<"Second"<<endl;
    else
    cout<<"First"<<endl;

      return 0;
  }

Measured memory_bytes: 3976
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

int main()
{
	int D;
	in >> D;
	int cnt = 25 - D;
	out << "Christmas";
	rep(i, cnt) out << " Eve";
	out << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define repn(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) for(int i = 0; i < (a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'

#ifdef LOCAL
clock_t timer = clock();
#endif

vi g[100005];
int dp[100005];
int v[100005];
int ind[100005];

void dfs(int cur){
	v[cur] = 1;
	for(int u : g[cur]){
		dp[u] = max(dp[u], dp[cur] + 1);
		ind[u]--;
		if(ind[u] == 0) dfs(u);
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n, m;
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		int a, b;
		cin >> a >> b;
		a--, b--;
		g[a].pb(b);
		ind[b]++;
	}
	for(int i = 0; i < n; i++){
		if(v[i] || ind[i]) continue;
		dfs(i);
	}
	int ans = 0;
	for(int i = 0; i < n; i++){
		ans = max(ans, dp[i]);
	} 
	cout << ans << endl;
#ifdef LOCAL
        cout << "Total Time: " << (double)(clock() - timer) / CLOCKS_PER_SEC << endl;
#endif
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 9984
fn main(){
	let mut s = String::new();
	std::io::stdin().read_line(&mut s).unwrap();
	let vec: Vec<&str> = s.trim().split(' ').collect();
	let n = vec[0].parse::<usize>().unwrap();
	let m = vec[1].parse::<usize>().unwrap();
	let mut b: Vec<bool> = vec![false; n + 1];
	let mut f: bool = false;
	for i in 0..m {
		let mut s = String::new();
		std::io::stdin().read_line(&mut s).unwrap();
		let vec: Vec<&str> = s.trim().split(' ').collect();
		let ia = vec[0].parse::<usize>().unwrap();
		let ib = vec[1].parse::<usize>().unwrap();
		if ia == 1 {
			if b[ib] {
				f = true;
			}
			b[ib] = true;
		} else if ib == n {
			if b[ia] {
				f = true;
			}
			b[ia] = true;
		}
	}
	if f {
		println!("POSSIBLE");
	} else {
		println!("IMPOSSIBLE");
	}
}


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

typedef struct Process
{
	char name[10];
	int time;
}Process;

Process getNameAndTime()
{
	Process p;
	cin >> p.name >> p.time;
	return p;
}

int main()
{
	int nProcess, quantum;
	cin >> nProcess >> quantum;

	queue<Process> scheduledQueue;
	for (int i = 0; i < nProcess; i++)
	{
		scheduledQueue.push(getNameAndTime());
	}

	while (!scheduledQueue.empty())
	{
		static int endTime = 0;
		Process front = scheduledQueue.front();
		if (front.time <= quantum)
		{
			endTime += front.time;
			cout << front.name << " " << endTime << endl;
			scheduledQueue.pop();
		}
		else
		{
			endTime += quantum;
			front.time -= quantum;
			scheduledQueue.pop();
			scheduledQueue.push(front);
		}
	}

	return 0;
}


Measured memory_bytes: 3744
#include <iostream>

using namespace std;;

int n, s, ans;

void dfs(int i, int sum, int num) {
	if (i == n&&sum == s) {
		ans++;
		return;
	}
	for (int j = num; j <= 9; j++) {
		dfs(i + 1, sum + j, j + 1);
	}
	return;
}

int main() {
	while (1) {
		ans = 0;
		cin >> n >> s;
		if (n == 0 && s == 0) {
			break;
		}
		dfs(0, 0, 0);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3012
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int N;
    cin>>N;
    int A[N];
    int sum=0;
    rep(i,N){
        cin>>A[i];
        sum+=A[i];
    }
    int ans=0;
    priority_queue<int> q;

    sort(A,A+N,std::greater<int>());
    q.push(A[0]);
    //q.push(A[0]);
    
    for(int i=1;i<N;i++){
        ans+=q.top();

        q.pop();
        q.push(A[i]);
        q.push(A[i]);

    }
    cout << ans << endl;



    



}


Measured memory_bytes: 6892
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
typedef long long int ll;

int main(){
    int n; cin >> n;
    for(int z=0;z<n;z++){
        int out=0;
        int points=0;
        int run=0;
        while(out<3){
            string s; cin >> s;
            if(s=="OUT")out++;
            else if(s=="HIT"){
                run++;
                if(run==4){
                    points++;
                    run--;
                }
            }
            else{
                points+=(run+1);
                run=0;
            }
        }
        cout << points << endl;
    }
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
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; }


int main(){
    ll k,n; cin>>n>>k;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    vector<ll> cnt(n+1, 0);
    rep(i,n) cnt[a[i]]++;
    sort(cnt.begin(), cnt.end(), greater<ll>());
    ll res=n;
    for(ll i=0; i<k; i++) res-=cnt[i];
    cout<<res<<endl;
    return 0;
}

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

int main(){

  int N, Sum=0, i;
  cin>>N;
  vector<int> A(N+2);
  for(i=1; i<N+1; i++){
    cin>>A[i];
    Sum+=abs(A[i]-A[i-1]);
  }
  A[N+1]=0;
  Sum+=abs(A[N+1]-A[N]);
  
  for(i=1; i<N+1; i++){
    
    cout<<Sum-(abs(A[i]-A[i-1])+abs(A[i+1]-A[i])-abs(A[i+1]-A[i-1]))<<endl;
  }
  return 0;
}

Measured memory_bytes: 3784
//
// べき乗
//
// 参考:
//   https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a#4-%E7%B4%AF%E4%B9%97-an
//
// verified
//   AOJ Course NTL_1_B Elementary Number Theory - Power
//     http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=NTL_1_B&lang=jp
//

/*
    a^n mod. mod を計算する、O(log n)
 */




#include <iostream>
using namespace std;

// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


int main() {
    long long m, n; cin >> m >> n;
    cout << modpow(m, n, 1000000007) << endl;
}


Measured memory_bytes: 3100
// https://atcoder.jp/contests/abc103/tasks/abc103_d
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define EPS (1e-9)
#define INF (1e9)
#define INFL (1e18)
#define MOD (1000000007)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define BIT(n) (1LL << (n))
// ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, a, b;
    cin >> n >> m;
    vector<PII> v;
    REP(i, m) {
        cin >> a >> b;
        v.push_back({a, b});
    }
    sort(ALL(v));
    int minv = INF, ans = 1;
    for (auto x : v) {
        minv = min(minv, x.second);
        if (x.first >= minv) {
            minv = x.second;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

typedef long long ll;

typedef pair<ll,ll> pll;
typedef pair<ll,ll> Node;

#define rep(i,j) for(i=0;i<j;i++)
#define rev_rep(i,j) for(i=j;i>=0;i--)

ll INF=1LL<<62LL;
class Dijkstra
{
public:
  typedef struct Edge{ll to,cost;}Edge;
  vector< vector<Edge> > Graph;//接続リスト

  Dijkstra(ll n)
  {
    vector<Edge> temp;
    Graph.resize(n,temp);
  }

  void add_arc(ll x,ll y,ll c)
  {
    Edge e={y,c};
    Graph[x].push_back(e);
  }

  vector<ll> get_distance(ll s)
  {
    priority_queue< Node ,vector<Node>,greater<Node> > que;//(sからの距離,インデックス)
    vector<ll>ans;
    ll i;
    ans.resize(Graph.size(),INF);
    ans[s]=0;
    que.push(Node(0,s));
    while(!que.empty()){
      Node now=que.top();que.pop();
      ll now_i=now.second;
      //nowへの最小距離でないならスキップ
      if(ans[now_i]<now.first)continue;
      //nowからの辺全てをみる
      rep(i,Graph[now_i].size()){
	Edge e=Graph[now_i][i];
	//nowから行った方が近かったら更新
	if(ans[e.to]>ans[now_i]+e.cost){
	  ans[e.to]=ans[now_i]+e.cost;
	  que.push(Node(ans[e.to],e.to));
	}
      }
    }
    return ans;
  }

};

class BIT
{
public:
  vector<ll> bit;

  BIT(ll n)
  {
    bit.resize(n+1,0);
  }
  ll sum(ll i)
  {
    ll s=0;
    while(i>0){
      s+=bit[i];
      i-=i& (-i);//i& -i はiの最小1bit  <- 2^kを引く
    }
    return s;
  }

  void add(ll i,ll x){
    while(i<=bit.size()){
      bit[i]+=x;
      i+=i& (-i);
    }
  }
};

typedef struct Query{
  ll fs,fe;ll id;
  Query(ll fs_,ll fe_,ll id_):fs(fs_),fe(fe_),id(id_){};
  bool operator<(const Query& right)const{
    return fs!=right.fs?fs<right.fs:fe>right.fe; 
  }
}Query;

int main()
{
  ll n,m,i;
  cin>>n>>m;
  Dijkstra G(n);
  ll q_num;
  vector<Query> query;
  //input
  {
    rep(i,m){
      ll a,b,c;
      cin>>a>>b>>c;
      G.add_arc(a,b,c);
      G.add_arc(b,a,c);
    }
    cin>>q_num;
    rep(i,q_num){
      ll fs,fe;
      cin>>fs>>fe;
      query.push_back(Query(fs,fe,i));
    }
  }
  
  vector<ll> d_s=G.get_distance(0),d_e=G.get_distance(n-1);

  //d_eを座標圧縮
  map<ll,ll> zip;
  {
    vector<ll>temp;
    temp.resize(d_e.size(),0);
    
    copy(d_e.begin(),d_e.end(),temp.begin());
    rep(i,query.size())
      temp.push_back(query[i].fe);


    sort(temp.begin(),temp.end(),greater<ll>() );
    temp.erase(unique(temp.begin(),temp.end()),temp.end());

    rep(i,temp.size())
      zip[temp[i]]=i+1;
    rep(i,d_e.size())
      d_e[i]=zip[d_e[i]];
  }

  vector<pll> distance;
  rep(i,n)
    distance.push_back(pll(d_s[i],d_e[i]));
  sort(distance.begin(),distance.end());

  BIT bit(zip.size());
  vector< pll >::iterator itr=distance.begin();
  vector<ll> ans;
  ans.resize(query.size(),0);
  
  sort(query.begin(),query.end());
  rep(i,query.size())
    {
      while(itr!=distance.end() && itr->first<=query[i].fs){
	bit.add(itr++->second,1);
      }
      ans[query[i].id]=bit.sum(zip[query[i].fe]);
    }

  rep(i,ans.size())
    cout<<ans[i]<<endl;
  
  return 0;
}

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

int findSet(int x, vector<int>& Forest, vector<int>& rank){
    rank[Forest[x]] = rank[x];
    if (Forest[x] == x) return x;
    return Forest[x] = findSet(Forest[x], Forest, rank);
}

void unite(int x, int y, vector<int>& Forest, vector<int>& rank){
    int x_ = findSet(x, Forest, rank);
    int y_ = findSet(y, Forest, rank);
    if (rank[x_] == rank[y_]) {
        Forest[y_] = x_;
        rank[x_]++;
        return;
    }
    if (rank[x_] > rank[y_]) {
        Forest[y_] = x_;
    } else {
        Forest[x_] = y_;
    }
}

int main(){
    int n, q;
    cin >> n >> q;
    vector<int> Forest(n);
    for (int i = 0; i < n; i++) {
        Forest[i] = i;
    }
    vector<int> rank(n, 0);
    for (int i = 0; i < q; i++) {
        int com, x, y;
        cin >> com >> x >> y;
        if (com == 0) {
            unite(x, y, Forest, rank);
        } else {
            cout << (findSet(x, Forest, rank) == findSet(y, Forest, rank)) << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3172