akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

#define N 300000

int n,a[N],d[N],sg[N];
bool vis[N];
vector<int> vec[N];
queue<int> q;

void solve(int x){
	d[x]=0;
	for (int i:vec[x]) vis[i]=1;
	for (int i=0;vis[i];++i) sg[x]=i+1;
	for (int i:vec[x]) vis[i]=0;
	int y=a[x],z=x;
	for (;d[y];y=a[y],z=a[z]){
		for (int i:vec[y]) vis[i]=1;
		vis[sg[z]]=1;
		for (int i=0;vis[i];++i) sg[y]=i+1;
		for (int i:vec[y]) vis[i]=0;
		vis[sg[z]]=0;
	}
	if (sg[x]!=sg[z]) return;
	int t=sg[x]; sg[x]=t+1;
	for (int i:vec[x]) vis[i]=1;
	for (int i=t+1;vis[i];++i) sg[x]=i+1;
	for (int i:vec[x]) vis[i]=0;
	y=a[x],z=x;
	for (;d[y];y=a[y],z=a[z]){
		for (int i:vec[y]) vis[i]=1;
		vis[sg[z]]=1;
		sg[y]=0;
		for (int i=0;vis[i];++i) sg[y]=i+1;
		for (int i:vec[y]) vis[i]=0;
		vis[sg[z]]=0;
	}
	if (sg[z]==t) return;
	puts("IMPOSSIBLE");
	exit(0);
}

int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;++i){
		scanf("%d",a+i);
		++d[a[i]];
	}
	for (int i=1;i<=n;++i)
		if (!d[i]) q.push(i);
	while (!q.empty()){
		int x=q.front(); q.pop();
		for (int i:vec[x]) vis[i]=1;
		for (int i=0;vis[i];++i) sg[x]=i+1;
		for (int i:vec[x]) vis[i]=0;
		vec[a[x]].push_back(sg[x]);
		if (!(--d[a[x]])) q.push(a[x]);
	}
	for (int i=1;i<=n;++i)
		if (d[i]){
			solve(i);
			break;
		}
	puts("POSSIBLE");
	
	return 0;
}
			

Measured memory_bytes: 13824
n = int(input())

t, a  = map(int, input().split()) # 変数、比較対象

h =  list(map(int, input().split())) # 標高

def temp(t, h):
    return t - h * 0.006

# 差分を計算する

dif = [abs(a - temp(t, i)) for i in h]

print(dif.index(min(dif))+1)

Measured memory_bytes: 3060
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
using namespace std;
typedef pair<int,int> P;
double dat[100][100];
int dp[6][1010];//動的計画法
int prime[10000001];
char str[1010][1010];
vector<pair<int,int> > pc[100001];
int ABS(int a){return max(a,-a);}
int main(){
	int n,k,x,y,ans;
	cin>>n>>k>>x>>y;
	if(n<=k) cout<<n*x<<endl;
	else cout<<k*x+(n-k)*y<<endl;
    return 0;
}

Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
#include<string.h>
#include<stdlib.h>
#include<math.h>

long A,B,C;

int main(){
	const char* ans[2] = {"Yes","No"};
	std::cin>>A>>B>>C;
	std::cout << (A<=C&&C<=B?ans[0]:ans[1]) << std::endl;
	return 0;
}

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

int main()
{
	int N;
	cin >> N;

	vector<int> W;
	int total_w = 0;
	for (int i = 0; i < N; i++) {
		int w;
		cin >> w;
		W.push_back(w);
		total_w += w;
	}

	int s1 = 0;
	int min_abs = total_w;
	for (int i = 0; i < N - 1; i++) {
		s1 += W[i];
		int s2 = total_w - s1;
		min_abs = min(min_abs, abs(s1 - s2));
	}

	cout << min_abs << endl;
}






Measured memory_bytes: 3604
/*
これを入れて実行
g++ code.cpp
./a.out
*/

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = { -1, 0, +1, 0 };
int dx4[4] = { 0, +1, 0, -1 };
int dy8[8] = { -1, -1, 0, 1, 1, 1, 0, -1 };
int dx8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
	return f.second > s.second;
}

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

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

ll nCr(ll n, ll r){
	if (r == 0 || r == n){
		return 1;
	}
	else if (r == 1){
		return n;
	}
	return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
	r = n - r;
	ll ret = 1;
	for (ll i = n; i >= r + 1; i--) ret *= i;
	return ret;
}

//-----------------------ここから-----------

int main(void){
	int n, m;
	cin >> n >> m;

	bool red[100100] = { false };
	vector<int> bnum(n, 1);

	red[0] = true;

	for (int i = 0; i < m; i++){
		int x, y;
		cin >> x >> y;
		x--;
		y--;

		if (red[x]){
			red[y] = true;
		}

		bnum[x]--;
		bnum[y]++;

		if (bnum[x] == 0){
			red[x] = false;
		}
	}

	int ans = 0;

	for (int i = 0; i < n; i++){
		if (red[i] && bnum[i] > 0){
			ans++;
		}
	}

	cout << ans << endl;


} 


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//using ll = long long;
using P = pair<int,int>;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int x,y,score = 0;
	cin >> x >> y;
	score = max(0ll,(4 - x) * 100000) + max(0ll,(4 - y) * 100000);
	if(x == 1 && y == 1) score += 400000;
	cout << score << endl;
}

Measured memory_bytes: 764
#include<iostream>
#include<cstdio>
#include<algorithm>
#define LL long long

using namespace std;

int main()
{
	
	LL n;
	cin>>n;
	int ans=0,num=0;
	int cnt=0x3f3f3f3f,x;
	for(int i=0;i<n;i++)
	{
		cin>>x;
		if(x<=cnt) num++,cnt=x;
		else num=1,cnt=x;
		ans=max(ans,num);
	}
	cout<<ans-1<<endl;
	return 0;
 } 

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AOJ
{
	class Program
	{
		static void Main(string[] args)
		{
			string s = "";
			while ((s = Console.ReadLine()) != null)
			{
				var d = double.Parse(s);
				var w =
					(d <= 48) ? "light fly" :
					(48 < d && d <= 51) ? "fly" :
					(51 < d && d <= 54) ? "bantam" :
					(54 < d && d <= 57) ? "feather" :
					(57 < d && d <= 60) ? "light" :
					(60 < d && d <= 64) ? "light welter" :
					(64 < d && d <= 69) ? "welter" :
					(69 < d && d <= 75) ? "light middle" :
					(75 < d && d <= 81) ? "middle" :
					(81 < d && d <= 91) ? "light heavy" :
					(91 < d) ? "heavy" : "";
				Console.WriteLine(w);
			}
		}
	}
}

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

int N, M, X;
vector<int> C(12);
int A[12][12];
int ans;

void dfs(int c, int pay, vector<int>&p)
{
        vector<int> cp(M);
        for (int i = 0; i < M; ++i) cp[i] = p[i];
        for (int i = 0; i < M; ++i) {
                cp[i] += A[c][i];
        }
        bool judge = true;
        for (int i = 0; i < M; ++i) {
                if (cp[i] < X) {
                        judge = false;
                        break;
                }
        }
        pay += C[c];
        if (judge) {
                if (ans == -1) {
                        ans = pay;
                }
                else if (ans > pay) {
                        ans = pay;
                }
                return;
        }
        for (int i = c+1; i < N; ++i) {
                dfs(i, pay, cp);
        }
}

int main()
{
        cin >> N >> M >> X;
        for (int i = 0; i < N; ++i) {
                cin >> C[i];
                for (int j = 0; j < M; ++j) {
                        cin >> A[i][j];
                }
        }
        ans = -1;
        vector<int> cp(M, 0);
        for (int i = 0;  i < N; ++i) {
                dfs(i, 0, cp);
        }
        cout << ans << endl;
}


Measured memory_bytes: 3624
use std::io::{self, BufRead, BufWriter, Write};

fn solve<R, W>(reader: R, mut writer: W)
where
    R: BufRead,
    W: Write,
{
    let mut lines = reader.lines();
    let a_line = lines.next().unwrap().unwrap();
    let mut splited = a_line.trim().split_whitespace();
    let a: u64 = splited.next().unwrap().parse().unwrap();
    let b: u64 = splited.next().unwrap().parse().unwrap();

    let ans = solve_(a, b);
    writeln!(&mut writer, "{}", ans).unwrap();
}

fn solve_(a: u64, b: u64) -> u64 {
    let (a, b) = if a < b { (b, a) } else { (a, b) };

    let mut a_low = 0;
    let mut a_high = a;
    let mut b_low = 0;
    let mut b_high = b;
    let mut digit = 1;
    let mut ans = 0;

    loop {
        let a_ith = a_high % 2;
        a_high = a_high / 2;

        let b_ith = b_high % 2;
        b_high = b_high / 2;

        let a_count = if a_ith == 1 {
            a_high * digit + a_low
        } else {
            a_high * digit - 1
        };
        let b_count = b_high * digit + if b_ith == 1 { b_low } else { 0 };

        let count = (a_count as i64 - b_count as i64 + 1) as u64;
        ans += if count % 2 == 0 { 0 } else { digit };

        if a_high == 0 && b_high == 0 {
            break;
        }

        // prepare for next loop
        a_low += a_ith * digit;
        b_low += b_ith * digit;
        digit *= 2;
    }

    ans
}

fn main() {
    let stdio = io::stdin();
    let input = stdio.lock();

    let stdout = io::stdout();
    let output = BufWriter::new(stdout.lock());

    solve(input, output);
}

#[cfg(test)]
mod tests {
    use super::*;

    const TESTS: &'static [(&'static [u8], &'static [u8])] = &[
        (
            br"2 4", br"5
",
        ),
        (
            br"123 456",
            br"435
",
        ),
        (
            br"123456789012 123456789012",
            br"123456789012
",
        ),
    ];

    #[test]
    fn test_d() {
        for &(input, expected) in TESTS {
            let mut output = Vec::new();
            solve(input, &mut output);
            let expected_str = String::from_utf8(expected.to_vec()).unwrap();
            let output_str = String::from_utf8(output).unwrap();
            assert_eq!(expected_str, output_str);
        }
    }
}


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

#define int long long
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define fr(i,j,k) for(i = j; i < (k); i++)
#define all(x) x.begin(), x.end()
#define el '\n'
#define remax(a,b) a = max(a, b)
#define remin(a,b) a = min(a, b)
#define sz(x) int32_t(x.size())

typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpi;
// --------------------------------------------------------------------

const pii dxy[] = { {-1, 0}, {1, 0}, {0, 1}, {0, -1} };
const int mod = 1e9 + 7;
const int INF = 2e18;
const ld EPS = 1e-9;
const int NN = 1e5 + 2;



void solve() {
      int i = 0, j = 0, k = 0, n = 0, m = 0; 
      cin >> n;
      vi a(n);

      fr(i, 0, n) {
            cin >> a[i];
      }

      vi assign;
      fr(i, 0, n) {
            int searchTerm = a[i], idx = -1;
            {
                  int lo = 0, hi = sz(assign) - 1, mid;
                  while(lo <= hi) {
                        mid = lo+hi >> 1;
                        if(assign[mid] < searchTerm) {
                              idx = mid;
                              hi = mid - 1;
                        } else {
                              lo = mid + 1;
                        }
                  }
            }

            if(idx == -1) {
                  assign.pb(searchTerm);
            } else {
                  assign[idx] = searchTerm;
            }
      }     

      cout << sz(assign) << endl;
}

int32_t main() {
      ios::sync_with_stdio(false); cin.tie(0); 
      int T = 1; 
      // cin >> T;
      for(int tc = 1; tc <= T; tc++) {
            solve();
       }
      return 0;
}

Measured memory_bytes: 2168
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T & a, const T & b) {
	if (a < b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T & a, const T & b) {
	if (a > b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}


#define ARRAY_MAX 100005
const int INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

int dx[4] = { 1,0,0,-1 };
int dy[4] = { 0,1,-1,0 };


/******************************************************************************************/



int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);

	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}

	sort(a.rbegin(), a.rend());


	ll sum = 0;

	for (int i = k; i < n; i++)
	{
		sum += a[i];
	}
	cout << sum << endl;


	return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,from,n) for(int i = from; i < n; i++)
#define mreps(i,from,n) for(int i = from; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(all(x), val), x.end())
typedef long long ll;
typedef pair<int, int> P;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll MOD = 1000000007;
int INF = 1001001001;

set<ll> lnum;

void build(string s, int i)
{
    if(i == 0)
    {
        ll tmp = stoll(s);
        lnum.insert(tmp);
        return;
    }
    char last = s.back();
    if(last - '0' > 0)
    {
        string next_1 = s;
        next_1.push_back(last - 1);
        build(next_1,i-1);
    }  
    string next_2 = s;
    next_2.push_back(last); 
    build(next_2,i - 1);
    if('9' - last > 0)
    {
        string next_3 = s;
        next_3.push_back(last + 1);
        build(next_3,i-1);
    }
    return;
}

void solve()
{
    int k; cin >> k;
    rep(i, 10)
    {
        build("1",i);
        build("2",i);
        build("3",i);
        build("4",i);
        build("5",i);
        build("6",i);
        build("7",i);
        build("8",i);
        build("9",i);
    }
    int cnt = 0;
    for(auto e : lnum)
    {
        cnt++;
        if(cnt == k)
        {
            cout << e << endl;
            return;
        }
    }
    return;
}

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


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

int main(){
  int64_t N;
  cin >> N;
  vector<int64_t> L(N + 1);
  L.at(0) = 2;
  L.at(1) = 1;
  for (int i = 2; i < N + 1; i++){
    L.at(i) = L.at(i - 1) + L.at(i - 2);
  }
  cout << L.at(N) << endl;
}


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

// typedef
typedef unsigned long long ull;
typedef unsigned int uint;

// macro
#define REP(index, num) for (auto index = 0; index < num; index++)

using namespace std;

int main()
{
  int N, K;
  cin >> N >> K;
  
  vector<uint> h(N);
  REP(index, N) 
    cin >> h[index];

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

  uint minVal = 1e10;
  REP(index, N - (K - 1))
  {
    uint diff = h[index + (K - 1)] - h[index];
    if (minVal > diff)
      minVal = diff;
  }

  cout << minVal << endl;

}


Measured memory_bytes: 640
import math

ans = 0
N = int(input())
for i in range(N):
    a = int(input())
    if a != 2 and a%2 == 0:
        continue
    b = True
    for j in range(3, int(math.sqrt(a))+1, 2):
        if a%j == 0:
            b = False
    if b:
        ans += 1

print(ans)

Measured memory_bytes: 7776
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        PriorityQueue<Double> pq = new PriorityQueue<>(Collections.reverseOrder());
        long a = 0;
        for ( int i = 0; i < N; i++ ){
            pq.add(sc.nextDouble());
        }
        for ( int j = 0; j < M; j++ ){
            pq.add(pq.poll()/2.0);            
        }
        for ( int i = 0; i < N; i++ ){
            a += pq.poll();        
        }
        System.out.println(a);
    }
}


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

int main() {
 int N, l, r, sum = 0;
 cin >> N;
  
 for (int i = 0; i < N; i++) {
   cin >> l >> r;
   r = r - l + 1;
   sum += r;
 }
  
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <string>
#include <iostream>
#include <set>

using namespace std;

int main() {
    string s;
    int K;
    cin >> s >> K;

    set<string> data;
    for (int i = 0; i < s.size(); i++) {
      for (int j = 1; j <= K; j++) {
        data.insert(s.substr(i, j));
      }
    }

    int count = 1;
    for(auto itr = data.begin(); itr != data.end(); itr++) {
      if (count == K) {
        cout << *itr << endl;
        break;
      }
      count++;
    }

    return 0;
}


Measured memory_bytes: 1664
s = sss = [_ for _ in input()]

c = 0
for i in range(len(s)):
    if (i % 2 == 0 and s[i] != "0") or (i % 2 == 1 and s[i] != "1"):
        c += 1

print(min(len(s) - c, c))
    

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

int main() 
{
   int N;
   cin >> N;

   vector<int> H(N);
   for (int i = 0; i < N; i++)
      cin >> H.at(i);

   int count = 1;
   int max = H.at(0);
   for (int i = 1; i < N; i++)
   {
      if (max <= H.at(i))
      {
         count++;
         max = H.at(i);
      }
   }
   cout << count << endl;
}


Measured memory_bytes: 256
N = int(input())
x = [] * N
y = [] * N
for i in range(N):
    a, b = list(map(int, input().split()))
    x.append(a)
    y.append(b)
d = 0
ma = x[0] + y[0]
ima = 0
mi = x[0] + y[0]
imi = 0
for i in range(N):
    if x[i] + y[i] < mi:
        mi = x[i] + y[i]
        imi = i
    if x[i] + y[i] > ma:
        ma = x[i] + y[i]
        ima = i
d1 = abs(x[ima] - x[imi]) + abs(y[ima] - y[imi])
ma = - x[0] + y[0]
ima2 = 0
mi = - x[0] + y[0]
imi2 = 0
for i in range(N):
    if -x[i] + y[i] < mi:
        mi = -x[i] + y[i]
        imi2 = i
    if -x[i] + y[i] > ma:
        ma = -x[i] + y[i]
        ima2 = i
d2 = abs(x[ima2] - x[imi2]) + abs(y[ima2] - y[imi2])
if d1 > d2:
    print(d1)
else:
    print(d2)

Measured memory_bytes: 24888
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <stdio.h>
#include <utility>

using namespace std;

struct City{
    int y;
    int p;
    int n;
};

int main(){
    vector<City> city;
    int N,M;

    cin >> N >> M;

    for(int i=0; i<M; i++){
        int p,y;
        City tmp;
        cin >> p >> y;
        tmp.y = y;
        tmp.p = p;
        tmp.n = i;
        city.push_back(tmp);
    }

    std::sort(city.begin(), city.end(), [](City a, City b)->bool{
        return a.y < b.y;
    });

    vector<int> id(N+1, 1);
    for(int i=0; i<city.size(); i++){
        city[i].y = id[city[i].p];
        id[city[i].p]++;
    }

    std::sort(city.begin(), city.end(), [](City a, City b)->bool{
        return a.n < b.n;
    });

    for(int i=0; i<city.size(); i++){
        printf("%06d%06d\n", city[i].p, city[i].y);
    }
}

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

int main(){
    int N;
    cin >> N;
    multiset<int> st;
    for(int i=0; i<(1<<N); i++){
        int a;
        cin >> a;
        st.insert(-a);
    }
    vector<int> now = {*st.begin()};
    st.erase(st.begin());
    for(int i=1; i<=N; i++){
        vector<int> born;
        for(int a : now){
            auto it = st.upper_bound(a);
            if(it == st.end()){
                cout << "No" << endl;
                return 0;
            }
            born.push_back(*it);
            st.erase(it);
        }
        for(int a : born) now.push_back(a);
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 13984
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;

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;}

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
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;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    ll n;
    cin>>n;
    vll a(n);
    rep(i,0,n)cin>>a[i];
    ll mod=1e9+7;
    ll res=0;
    rep(i,0,60){
        ll x=0;
        rep(j,0,n){
            if(a[j]>>i&1){
                x++;
            }
        }
        ll add=(n-x)*x%mod;
        rep(k,0,i){
            add*=2;
            add%=mod;
        }
        res+=add;
        res%=mod;
    }
    cout<<res<<endl;
    return 0;
}




Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) for(int i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; --i)
#define ALL(a) begin(a), end(a)

using ll = long long;
using namespace std;

constexpr int INF = 2147483647; // 2 * 1e9
constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m, k;
	cin >> n >> m >> k;
	REP(i, n + 1){
		REP(j, m + 1){
			if(k == i * m + j * n - 2 * i * j){
				cout << "Yes\n";
				return 0;
			}
		}
	}
	cout << "No\n";
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
const int N=2e5+10;ll sum[N],X[N];
ll a[N];
int main(){
    int n;scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
    sum[1]=X[1]=a[1];
    for(int i=2;i<=n;i++) sum[i]=sum[i-1]+a[i],X[i]=X[i-1]^a[i];
    ll ans=0;int l=1;
    for(int r=1;r<=n;r++){
        for(;sum[r]-sum[l-1]!=(X[r]^X[l-1]);l++);
        ans+=(r-l+1);
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 4864
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main(void){
    int n;
    cin >> n;
    map<int, int> mp;
    for(int i=0; i<n; i++){
        int a; cin >> a;
        mp[a+1]++;
        mp[a]++;
        mp[a-1]++;
    }
    int ans = 0;
    for(int i=-1; i<=100000; i++){
        ans = max(mp[i], ans);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8196
import numpy as np
N = int(input())
ABC = [int(input()) for _ in range(5)]
ABC = np.array(ABC)

check = 0
def counter(ABC, check):
    count = 0
    minABC = min(ABC)
    minidx = np.argmin(ABC)
    amari = N%minABC
    tmp = int(N/minABC) - int(amari==0)
    if check == 0:
        count = len(ABC) - minidx + tmp
    else:
        count = len(ABC) - minidx
    if minidx != 0:
        count += counter(ABC[:minidx], 1)
    return count

count = counter(ABC, 0)
print(count)


Measured memory_bytes: 13580
S = input()
if S[0] == 'R' and S[1] == 'R' and S[2] == 'R':
    print(3)
elif (S[0] == 'R' and S[1] == 'R') or (S[1] == 'R' and S[2] == 'R'):
    print(2)
elif S[0] == 'S' and S[1] == 'S' and S[2] == 'S':
    print(0)
else:
    print(1)

Measured memory_bytes: 61648
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18) + 1;
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int n, m;
vector<int> a, ans;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        int temp;
        cin >> temp;
        temp--;
        a.push_back(temp);
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = a.size() - 1; j >= 0; j--)
        {
            if (a[j] == j)
            {
                ans.push_back(j);
                a.erase(a.begin()+j);
                break;
            }
            if (j == 0)
                return cout << -1 << "\n", 0;
        }
    }
    reverse(ALL(ans));
    rep(i, n)
            cout
        << ans[i] + 1 << "\n";
}


Measured memory_bytes: 256
S = input()

counter = 1
yorn = 1
for foot in S:
    if foot == 'R':
        if counter % 2 == 0:
            yorn=0
            break
    elif foot == 'L':
        if counter % 2 == 1:
            yorn = 0
            break
    counter+=1

if yorn == 1:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
ll n,m,k,ans;
string s,t;
const ll powll = 1LL<<1;

int main(void){
  ans = 0; int out = 0;
  ll h,w; cin >> h >> w >> n;
  int ht = 0; int wt = 0;
  while(ans < n){
    if(h-wt > w-ht){
      ans += h-wt;
      ht++;
    }else{
      ans += w-ht;
      wt++;
    }
    out++;
    // cout << ans << "\n";
  }
  cout  << out << "\n";
}

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

typedef long long ll;

int main () {
    ll N,W;
    cin >> N >> W;

    ll w1;
    vector<vector<ll>> value(4,vector<ll>(1,INT_MAX));
    for(int i=0; i<N; i++) {
	ll w,v;
	cin >> w >> v;
	if( i==0 ) w1 = w;
	value[w-w1].push_back(v);
    }
    for(auto& e : value) {
	sort(e.begin(), e.end());
	reverse(e.begin(), e.end());
	e[0] = 0;
    }
    for(int i=0; i<4; i++) {
	for(int j=0; j<value[i].size()-1; j++) {
	    value[i][j+1] += value[i][j];
	}
    }

    ll ans= 0, sum_v = 0, sum_w = 0;
    for(int i=0; i<value[0].size(); i++) {
	sum_w += i*w1;
	sum_v += value[0][i];
	for(int j=0; j<value[1].size(); j++) {
	    sum_w += j*(w1+1);
	    sum_v += value[1][j];
	    for(int k=0; k<value[2].size(); k++) {
		sum_w += k*(w1+2);
		sum_v += value[2][k];
		for(int l=0; l<value[3].size(); l++) {
		    sum_w += l*(w1+3);
		    sum_v += value[3][l];
		    if( sum_w <= W )	ans = max(ans,sum_v);
		    sum_w -= l*(w1+3);
		    sum_v -= value[3][l];
		}
		sum_w -= k*(w1+2);
		sum_v -= value[2][k];
	    }
	    sum_w -= j*(w1+1);
	    sum_v -= value[1][j];
	}
	sum_w -= i*w1;
	sum_v -= value[0][i];
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static Scanner scanner = new Scanner(System.in);
    public static void main(String[] args) {

        int n = scanner.nextInt();
        int[] a = new int[n];
        int sum = 0;
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
            sum ^= a[i];
        }
        for (int i = 0; i < n; i++) {
            System.out.print((sum ^ a[i])+" ");
        }
	// write your code here
    }
}


Measured memory_bytes: 62220
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int A = in.nextInt();
			int B = in.nextInt();
			int C = in.nextInt();
			out.println(B + Math.min(A + B + 1, C));
			
		}
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		
		public char nextChar() {
			return next().charAt(0);
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		
		public long nextLong() {
			return Long.parseLong(next());
		}

	}
}


Measured memory_bytes: 21460
#include <iostream>
#include <string>
#include <cctype>
#include <algorithm>


auto print = [](auto x){ std::cout << x; };
auto println = [](auto x){ std::cout << x << std::endl; };
auto read = [](auto &x){ std::cin >> x; };

std::string shuffle(std::string, int);

int main ()
{
  std::string str;
  read(str);
  int m, h, temp;

  while (str != "-")
    {
      read(m);
      h = 0;
      for (int i=0; i<m; i++){
        read(temp);
        h += temp;
      }
      h = h % str.length();
      str = shuffle(str, h);
      println(str);
      read(str);
    }
}

std::string shuffle (std::string str, int h)
{
  for (int i=0; i<h; i++)
    {
      auto temp = str.at(0);
      for (int j=0; j<str.length()-1; j++)
        {
          str.at(j) = str.at(j+1);
        }
      str.at(str.length()-1) = temp;
    }
  return str;
}



Measured memory_bytes: 3216
#include <iostream>
using namespace std;
int main(){
    long long N;
    long long M;
      

    cin >> N >>M;


     long long A[M];


 
 

    for (long long j = 0; j<M ;j++){


        cin >> A[j];
    }

    long long sum = 0;

    for (long long i=0 ; i<M; i++){


        sum = sum +A[i];
    }

    if(N -sum>=0){


        cout << N-sum<<endl;


    }
    else{

        cout << -1 << endl;
    }

  

    return 0;

}

Measured memory_bytes: 3700
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int N;
int X[3000], Y[3000];
bool F[5001][5001];
int solve(int P, int Q){
	int xp = X[P];
	int yp = Y[P];
	int xq = X[Q];
	int yq = Y[Q];
	int xs = xp + (yp - yq);
	int ys = yp + (xq - xp);
	int xr = xq + (yp - yq);
	int yr = yq + (xq - xp);
	if ((xs>=0&&xs<=5000)&&(ys>=0&&ys<=5000)&&(xr>=0&&xr<=5000)&&(yr>=0&&yr<=5000)&&F[xs][ys]&&F[xr][yr])return (xq - xp)*(xq - xp) + (yq - yp)*(yq - yp);
	xs = xp - (yp - yq);
	ys = yp - (xq - xp);
	xr = xq - (yp - yq);
	yr = yq - (xq - xp);
	if ((xs >= 0 && xs<=5000) && (ys >= 0 && ys<=5000) && (xr >= 0 && xr<=5000) && (yr >= 0 && yr<=5000) && F[xs][ys] && F[xr][yr])return (xq - xp)*(xq - xp) + (yq - yp)*(yq - yp);
	return 0;
}
int main()
{
	while (true){
		scanf("%d", &N);
		if (N == 0)return 0;
		for (int i = 0; i < N; i++){
			scanf("%d%d", &X[i], &Y[i]);
			F[X[i]][Y[i]] = true;
		}
		int ans = 0;
		for (int i = 0; i < N; i++){
			for (int j = i + 1; j < N; j++){
				ans = max(ans, solve(i, j));

			}
		}
		printf("%d\n", ans);
		for (int i = 0; i < N; i++)F[X[i]][Y[i]] = false;
	}
}

Measured memory_bytes: 25088
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repm(i, m, n) for (int i = (m); i < (int)(n); i++)
#define repr(i, n) for (int i = (n); i > 0; i--)
#define all(vec) vec.begin(), vec.end()
using namespace std;

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

  //int ans;
  string ans;
  vector<int> d = {a, b, c};
  sort(all(d));

  //cout << ans << endl;
  cout << d[0] << " " << d[1] << " " << d[2] << endl;
}


Measured memory_bytes: 3068
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define dump(x) cout << #x << " = " << (x) << endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define SP << " " <<
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

#define int long long

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> p(N);
  REP(i, N) cin >> p[i];
  bool good = true;
  REP(i, N - 1) {
    if(p[i] > p[i + 1]) {
      good = false;
      break;
    }
  }
  if(good) {
    cout << "YES" << endl;
    return 0;
  }
  bool ans = false;
  REP(i, N - 1) {
    FOR(j, i + 1, N) {
      vector<int> q(N);
      REP(k, N) q[k] = p[k];
      swap(q[i], q[j]);
      bool ok = true;
      REP(l, N - 1) {
        if(q[l] > q[l + 1]) {
          ok = false;
          break;
        }
      }
      if(ok) {
        ans = true;
        break;
      }
    }
  }
  if(ans) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int maxn = int(2e5) + 7;
int n, m, flag[maxn][2], type[maxn];
bool vis[maxn];
char str[maxn];
std::vector<int> edge[maxn];
void addedge(int u, int v) {
	edge[u].push_back(v);
	flag[u][type[v]]++;
}
int main() {
	scanf("%d%d %s", &n, &m, str + 1);
	for (int i = 1; i <= n; i++) type[i] = str[i] - 'A';
	for (int i = 1, u, v; i <= m; i++) {
		scanf("%d%d", &u, &v);
		addedge(u, v);
		addedge(v, u);
	}
	std::queue<int> que;
	int cnt = n;
	for (int i = 1; i <= n; i++) if (flag[i][0] == 0 || flag[i][1] == 0) vis[i] = true, que.push(i);
	while (!que.empty()) {
		assert(que.size() < maxn);
		cnt--;
		int u = que.front();
		que.pop();
		for (int v : edge[u]) {
			if (vis[v]) continue;
			if (--flag[v][type[u]] == 0) que.push(v), vis[v] = true;
		}
	}
	printf("%s\n", cnt ? "Yes" : "No");
	return 0;
}


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

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

  vector<vector<long>> route(n+1);
  vector<vector<long>> score(n+1); 
  for(int s=1; s<=n; s++){ // start
    long now = s;
    vector<bool> seen(n+1, false);
    while(seen[p[now]] == false){
      route[s].push_back(p[now]);
      seen[p[now]] = true;
      score[s].push_back(c[p[now]]);
      now = p[now];
    }
  }

  long ans = score[1][0];
  for(int i=1; i<=n; i++){
    long ssum = score[i][0], len = score[i].size();
    long maxtok = score[i][0], maxtofull = score[i][0];
    for(int j=1; j<len; j++){
      ssum += score[i][j];
      maxtofull = max(maxtofull, ssum);
      if(j < (k%len))
	maxtok = max(maxtok, ssum);
    }
    //    printf("ssum:%ld  maxtok:%ld\n", ssum, maxtok);
    if(k < len){
      ans = max(ans, maxtok);
    }else if(ssum < 0){
      ans = max(ans, maxtofull);
    }else{
      //printf("zen:%ld  mae:%ld\n", ssum*(long)(len/k)+maxtok, ssum*(long)(len/k-1)+maxtofull);
      if(k%len == 0)  maxtok = 0;
      ans = max(ans, ssum*(long)(k/len)+maxtok);
      ans = max(ans, ssum*(long)(k/len-1)+maxtofull);
    }
  }

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


Measured memory_bytes: 434380
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
using namespace std;
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() {
    int N;
    cin >> N;
    vl a(N);
    rep(i, 0, N) {
        cin >> a[i];
    }
    int count = 0;
    int top = 0;
    int loop = 0;
    while(true) {
        count = 0;
        top = 0;
        rep(i, 0, a.size()) {
            if (a[i] % 2 != 0) {
                a.erase(a.begin() + i);
            }
            if (a[i] % 2 == 0 && count == 0) {
                a[i] = a[i] / 2;
                ++count;
            }
        }
        if (count == 0) {
            break;
        }
        ++loop;
    }
    cout << loop << endl;
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define ull unsigned long long
#define ld long double

#define mod 1000000007
#define EULER 2.7182818284
#define INF 1000000000

#define pb push_back
#define ins insert
#define IT iterator
#define PQ priority_queue

#define fi first
#define se second
#define maxe max_element
#define mine min_element
#define er erase
#define lb lower_bound
#define ub upper_bound

#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define pi pair<int,int>
#define pll pair<ll,ll>


#define mem(v,i) memset(v,i,sizeof(v)) // v is array. To set all elements to 0 or -1 only. mem(arr,0);


#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORd(i,a,b) for(int i=(a);i>=(b);i--)
#define FORl(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORN(i,n) for(int i=(0);i<(n);i++)
#define FORR(i,n) for(int i=(n);i>=0;i--)
#define bs bitset
#define bpc(a) __builtin_popcount(a)

ll max(ll a,ll b)
{
    if(a>b)return a;return b;
}
ll min(ll a,ll b)
{
    if(a<b)return a;return b;
}

ll mypow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
ll gcd(ll a,ll b)
{
    if(b==0)
    return a;
    return gcd(b,a%b);
}
//..............................!!!!!!Get ready to fight!!!!!!............................
set<ll>vec;
void primeFactors(ll n)  
{  
    
    while (n % 2 == 0)  
    {  
        vec.insert(2);  
        n = n/2;  
    } 
    for (ll i = 3; i <= sqrt(n); i = i + 2)  
    {   
        while (n % i == 0)  
        {  
            vec.insert(i);
            n = n/i;  
        }  
    }
    if (n > 2)  
        vec.insert(n);  
}  

int main()
{
    fast
    ll n;
    cin>>n;
    primeFactors(n);
    //ll i,m=vec.size();
    ll ans=0;
    //sort(vec.begin(),vec.end());
    for(auto it=vec.begin();it!=vec.end();it++)
    {
            ll k=*it;
            ll j=1;
            ll power=pow(k,j);
            while(n%power==0)
            {
                n=n/power;
                ans++;
                j++;
                power=pow(k,j);
                if(n==1)
                break;
            }
            if(n==1)
            break;
        
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 4048
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;
typedef std::int_fast32_t i32;
typedef std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// main.cpp

int main() {
  i64 N, M;
  std::cin >> N >> M;

  std::vector<std::vector<i64>> works(M);
  for (i64 i = 0; i < N; ++i) {
    i64 A_i, B_i;
    std::cin >> A_i >> B_i;
    if (A_i <= M) {
      works[A_i - 1].push_back(B_i);
    }
  }

  std::priority_queue<i64> queue;
  i64 answer = 0;
  for (i64 i = 0; i < M; ++i) {
    for (const i64& gain : works[i]) {
      queue.push(gain);
    }
    if (!queue.empty()) {
      answer += queue.top();
      queue.pop();
    }
  }

  std::cout << answer << std::endl;
  return 0;
}

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n,m;
  cin >>n>>m;
  int a[m+1];
  rep(i,m+1){
    a[i] = 0;
  }
  rep(i,n){
    int k;
    cin >> k;
    rep(j,k){
      int tmp;
      cin>>tmp;
      a[tmp]++;
    }
  }
  int count=0;
  for(int i = 1;i<=m;i++){
   if(a[i] == n)
    count++;
//    cout << a[i] << " ";
  }
//  cout << endl;
  cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

#define NORTH 0
#define EAST 1
#define SOUTH 2
#define WEST 3

int strength( char ch ) {
	if( ch > '0' && ch <= '9' ) return ch - '0';
	if( ch == 'T' ) return 10;
	if( ch == 'J' ) return 11;
	if( ch == 'Q' ) return 12;
	if( ch == 'K' ) return 13;
	if( ch == 'A' ) return 14;
}

int max( int p, int q ) {
	if( p > q ) return p;
	return q;
}

int main(void){

	string ans[] = { "NS", "EW" };

	while( true ) {
		
		int start = WEST;
		char trump;
		string cards[4][52/4];
		int tricks[2] = { 0 };

		cin >> trump;
		if( trump == '#' ) break;

		//カードの情報を取得する
		for(int i = 0; i < 4; i++) {
			for(int j = 0; j < 52/4; j++) {
				cin >> cards[i][j];
			}
		}

		//シュミレート
		for( int i = 0; i < 13; i++) {
			int winner, rank;
			char suit;

			winner = start;
			rank = strength( cards[start][i][0] );
			suit = cards[start][i][1];

			for( int j = 1; j < 4; j++) {
				//スートが現在最強のものと同じ場合
				int tmp = ( start + j ) % 4;
				if( suit == cards[ tmp ][i][1] ){
					if( rank < strength( cards[ tmp ][i][0] ) ) {
						winner = tmp;
						rank = strength( cards[ tmp ][i][0] );
					}
				} else if( cards[ tmp ][i][1] == trump ) {
					//切り札が出る場合
					winner = tmp;
					suit = trump;
					rank = strength( cards[ tmp ][i][0] );
				}
			}

			tricks[ winner % 2 ] ++;
			start = winner;

		}
		cout << ans[ tricks[EAST] > tricks[NORTH] ] << " " << max( tricks[EAST] , tricks[NORTH] ) - 6 << endl;

	}

	return 0;
}

Measured memory_bytes: 1196
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  int A, B;
  cin >> A >> B;
  cout << max(0, A-2*B) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#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 DEBUG(val) cout << #val << " : " << val << endl
#define MOD 1000000007

int main() {
  int n, m;
  cin >> n >> m;
  string s;
  if (n <= m) {
    s = "unsafe";
  } else {
    s = "safe";
  }
  cout << s << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(t) t.begin(), t.end()
#define inrange(i, a, b) (((i)>= min((a), (b))) && ((i) <= max((a), (b))))
#define show(x) cout << #x << " is " << x << "\n";
typedef vector<ll> vi;
#define fi first
#define se second
const ll inf = 9e18;
const ll mod = 1e9 + 7;

void print(ll a[], ll n){for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<"\n";}
ll power(ll x, ll y, ll M = inf){
    ll ans = 1;
    x %= M;
    while(y){
        if(y&1)
            ans = (x * ans) % M;

        x = (x * x) % M;
        y >>= 1;
    }
    return ans;
}
ll modInverse(ll n) {return power(n, mod-2, mod);}
inline ll mul(ll a, ll b){ return (a * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; }
inline ll divi(ll a, ll b){ return mul(a, modInverse(b)); }

//const ll N = 1e5 + 1;
//vector<ll> adj[N];
//bool visited[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

	ll n;
	cin>>n;
	string a[n];
	map<string ,ll> mp;
	for(int i=0;i<n;i++){
		cin>>a[i];
		mp[a[i]]++;
	}
	cout<<mp.size();

	return 0;
}


Measured memory_bytes: 25464
using System;
using System.Linq;

namespace _0338
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            bool found = false;
            int i;
            for (i = 1000; !found; i--)
            {
                if (x[0] % i == 0 && x[1] % i == 0) found = true;
            }
            i++;
            Console.WriteLine(x[0] / i * x[1] / i * x[2]);
        }
    }
}

Measured memory_bytes: 9640
from sys import *

input = stdin.readline
lmi = lambda: list(map(int, input().split()))
mi = lambda: map(int, input().split())
si = lambda: input().strip('\n')
ssi = lambda: input().strip('\n').split()


n, r = mi()
if n >= 10:
    print(r)
else:
    print(r+(100*(10-n)))

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



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

	int N; cin >> N;
	int a[600];
	fill(a, a+600, INT_MAX);
	for (int i = 1; i <= N; i++) {
		cin >> a[i];
	}
	cout << "node 1: key = " << a[1] << ", left key = " << a[2] << ", right key = " << a[3] << ", " << endl;
	for (int i = 2; i <= N; i++) {
		cout << "node " << i << ": key = " << a[i] << ", parent key = " << a[i / 2];
		if (a[i * 2] != INT_MAX) {
			cout << ", left key = " << a[i * 2];
			if (a[i * 2 + 1] != INT_MAX) {
				cout << ", right key = " << a[i*2+1] << ", " << endl;
			}
			else cout << ", " << endl;
		}
		else cout << ", " << endl;
	}
}


Measured memory_bytes: 3096