akhauriyash/Code-Regression huggingface dataset:
/*
      بسم اللہ الرحمن الرحیم
    Bismillahir Rahmanir Raheem.
    In the name of Allah, Most Gracious, Most Merciful.

*/
/*
    Masum
    RUET
    CSE-19
    #1903086
    NDC
    #11901058
*/

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

#define int long long
#define ld long double
#define endl '\n'
#define watch(x) cout << (#x) << " is " << x << endl;
/***********************MASUM**********************/

void sol();
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    /* Test cases */
    bool isT = 0;
    if (isT) {
        int t;
        cin >> t;
        while (t--)
            sol();
    } else
        sol();
    return 0;
}

void sol() {
    /* Remember about test cases --> exits or not */

    for (int i = 1; i < 6; i++) {
        int x;
        cin >> x;
        if (x == 0) cout << i;
    }
}

Measured memory_bytes: 3608
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int N=sc.nextInt();
    int[] bricknumber=new int[N];
    int[] index=new int[N+2];//iのあったbricknumberのindex
    int last=N;
    
    for(int h=0;h<N;h++){
      bricknumber[h]=sc.nextInt();
    }
    
    index[0]=0;
    for(int k=1;k<=N;k++){
      index[k]=-1;
    }
    
    for(int i=1;i<=N;i++){
      for(int j=index[i-1];j<N;j++){
        if(bricknumber[j]==i){
          index[i]=j;
          break;
        }
      }
      if(index[i]==-1){
        last=i-1;
        break;
      }
      
    }
    if(last==0){
      last=N+1;
    }
    
    System.out.println(N-last);
    
  }
}

Measured memory_bytes: 83308
#include <iostream>
using namespace std;
int main(void){
    int  N;
    cin>>N;
    int i;
    for(i=1;i<=N;i++){
        int K,P;
        int a;
        cin>>K>>P;
        a=K%P;
        if(a==0) cout<<P;
        else cout<<a;
        cout<<endl;
    }
   
     
}


Measured memory_bytes: 3104
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long t = sc.nextLong();
		long a = sc.nextLong();
		long k = sc.nextLong();
		sc.close();
		System.out.print(k <= t ? t - k : 0);
		System.out.print(" ");
		System.out.println(k - t > 0 ? Math.max(a - (k - t), 0) : a);
	}

	public static int arrayMax(int[] array) {
		int ans = Integer.MIN_VALUE;
		for (int i = 0; i < array.length; i++) {
			if (array[i] > ans)
				ans = array[i];
		}
		return ans;
	}

	public static int[] arrayInt(Scanner sc, int n) {
		int[] array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		return array;
	}

	public static long[] arrayLong(Scanner sc, int n) {
		long[] array = new long[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextLong();
		}
		return array;
	}

	public static double[] arrayDouble(Scanner sc, int n) {
		double[] array = new double[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextDouble();
		}
		return array;
	}
}


Measured memory_bytes: 23252
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * 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);
        OutputWriter out = new OutputWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int A = in.nextInt(), B = in.nextInt();
            if (A < 10 && B < 10) {
                out.printLine(A * B);
            } else {
                out.printLine(-1);
            }
        }

    }

    static class OutputWriter {
        PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void printLine(Object... objects) {
            print(objects);
            writer.println();
        }

        public void close() {
            writer.close();
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tokenizer = null;

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
        }

        public String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(in.readLine());
                }
                return tokenizer.nextToken();
            } catch (IOException e) {
                return null;
            }
        }

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

    }
}



Measured memory_bytes: 21588
N=int(input())
arr=list(map(int,input().split()))
ans=1
kari=1
for i in range(N-1):
    kari=max(kari,arr[i]-1)
    
    if kari>arr[i+1]:
        ans=0
        
        break


    
if ans==0:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 20712
import Data.List
import GHC.Exts

main :: IO()
main = do
  _ <- getLine
  a <- sortOn Down <$> map read . words <$> getLine
  let b = sum [x | (i,x) <- zip [0..] a, even i]
  let c = sum [y | (i,y) <- zip [0..] a, odd i]
  print $ b - c

Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
int main(void){
    int N, K;
    cin >> N >> K;
    vector<int> x(N);
    for(int i = 0; i < N; i++){
        cin >> x[i];
    }
    int res = 0;
    for(int i = 0; i < N; i++){
        if (x[i]*2 >= (K-x[i])*2){
            res += (K-x[i])*2;
        }else{
            res += x[i]*2;
        }
    }
    cout << res;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s, t; cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  cout << (s < t ? "Yes\n" : "No\n");
  return 0;
}

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

using namespace std;

int main(int argc, char const *argv[]) {

    int cnt1 = 0, cnt2 = 0, cnt3 = 0;
    int n; cin >> n;

    for (int i = 0; i < n; i ++) {
        int x; scanf("%d", &x);
        if (x % 4 == 0) cnt2 ++;
        else if (x % 2 == 0) cnt1 ++;
        else cnt3 ++;
    }

    if (cnt2 + 1 >= cnt3 && !cnt1) puts("Yes");
    else if (cnt2 >= cnt3) puts("Yes");
    else puts("No");
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}


int main() {
  ll n; cin >> n;
  ll m = 1ll<<n;
  V s(m);
  rep(i, m) cin >> s[i];
  sort(all(s));
  reverse(all(s));

  vector<bool> used(m, false);
  set<int> ind;
  used[0] = true;
  ind.insert(0);

  rep(i, n) {
    int j = 0;
    for (auto e : ind) {
      for (; j < m; j++) {
        if (used[j]) continue;
        if (s[e] <= s[j]) continue;
        used[j] = true;
        break;
      }
      if (j == m) {
        cout << "No" << endl;
        return 0;
      }
    }
    rep(j, m) {
      if (used[j]) ind.insert(j);
    }
  }
  cout << "Yes" << endl;
  return 0;
}


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

const int INF = 1e9 + 5;

int main(int argc, char const *argv[])
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll int n;
    cin>>n;
    vector<ll int> arr(n);
    // for(ll int& i: arr){
    // 	scanf("%lld",&i);
    // }
    for(ll int i=0;i<n;i++){
    	cin>>arr[i];
    }    
    vector<ll int> dp(n,INF);
    dp[0] = 0;
    ll int zero = 0;
    for(ll int i=0;i<n;i++){
    	// dp[i] = min(abs(arr[i]-arr[i-1])+dp[i-1],abs(arr[i]-arr[max(i-2,zero)])+dp[max(i-2,zero)]);
    	for(int j :{i+1,i+2}){
    		if(j<n)
    			dp[j] = min(dp[j],dp[i] + abs(arr[i]-arr[j]));
    	}
    }
    cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <functional>
#include <map>
using namespace std;

int N, H[10008], maxn = 0, sum = 0;

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> H[i];
		if (maxn <= H[i]) { sum++; }
		maxn = max(maxn, H[i]);
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long dp(int now,int sum,int cnt);
int n,a;
int x[59];
long long memo[59][2509][59];

int main(){
  memset(memo,-1,sizeof(memo));
  cin>>n>>a;
  for(int i=0;i<n;i++){
    cin>>x[i];
  }
  cout<<dp(0,0,0)-1<<endl;
  return(0);
}

long long dp(int now,int sum,int cnt){
  long long rec=0;
  if(memo[now][sum][cnt]!=-1)return memo[now][sum][cnt];
  if(now==n){
    if(a*cnt==sum)return 1;
    else return 0;
  }
  rec+=dp(now+1,sum,cnt);
  rec+=dp(now+1,sum+x[now],cnt+1);
  return memo[now][sum][cnt]=rec;
}


Measured memory_bytes: 68480
import Data.List

nub' :: [Int] -> [Int]
nub' [] = []
nub' (x:[]) = [x]
nub' (x0:x1:xs) =
  if x0 == x1
  then nub' (x1:xs)
  else x0:(nub' (x1:xs))

ans' [] _ = []
ans' _ [] = []
ans' (s:ss) (q:qs) =
  if s == q
  then s:(ans' ss qs)
  else
    if s > q
    then ans' (s:ss) qs
    else ans' ss (q:qs)

ans s q =
  let s' = nub' $ sort s
      q' = nub' $ sort q
  in
    length $ ans' q' s'

main = do
  getLine
  s' <- getLine
  getLine
  q' <- getLine
  let s = map read $ words s' :: [Int]
      q = map read $ words q' :: [Int]
      o = ans s q
  print o

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;
typedef tuple<long long, long long, long long> tllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
bool compTuple(const tllint& arg1, const tllint& arg2) { return get<2>(arg1) > get<2>(arg2); }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

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

    int n = 0;
    for(auto is:s) {
        n += is-'0';
    }

    if(n%9==0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3748
#include <iostream>
#include <string>
using namespace std;
int main(){
int sx,sy,tx,ty;
cin >>sx>>sy>>tx>>ty;
for(int i=1;i<=ty-sy;i++) cout <<"U";
for(int i=1;i<=tx-sx;i++) cout <<"R";
for(int i=1;i<=ty-sy;i++) cout <<"D";
for(int i=1;i<=tx-sx;i++) cout <<"L";
cout <<"L";
for(int i=1;i<=ty-sy+1;i++) cout <<"U";
for(int i=1;i<=tx-sx+1;i++) cout <<"R";
cout <<"DR";
for(int i=1;i<=ty-sy+1;i++) cout <<"D";
for(int i=1;i<=tx-sx+1;i++) cout <<"L";
cout <<"U"<<endl;
}



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

int eu[2000],ev[2000],m;
long long n,dist[1000], INF=100000000000000001,ew[2000],ans;
bool inf[1000];
void bf(int s){
	fill(dist, dist+n,INF);
	dist[s]=0;bool up=true;
	for(int k=0;k<n-1;++k){
		for(int e=0;e<m;++e){
			if(dist[eu[e]-1]+ew[e]<dist[ev[e]-1] and dist[eu[e]-1]!=INF ){
				dist[ev[e]-1]=dist[eu[e]-1]+ew[e];
			}
			
		}
	}
	for(int k=0;k<n;k++){
		for(int e=0;e<m;++e){
			if(dist[eu[e]-1]+ew[e]<dist[ev[e]-1] and dist[eu[e]-1]!=INF){
				dist[ev[e]-1]=dist[eu[e]-1]+ew[e];
				inf[ev[e]-1]=true;
			}
			if(inf[eu[e]-1]){
				inf[ev[e]-1]=true;
			}
			
		}
	}
	
}

int main(){
	cin>>n>>m;
	for(int i=0;i<m;i++){
		cin>>eu[i]>>ev[i]>>ew[i];
		ew[i]=-ew[i];
	}
	bf(0);
	if(inf[n-1]){
		cout<<"inf"<<endl;
	}else{
		cout<<-dist[n-1]<<endl;
	}
}

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

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

const ll MOD = (ll)1e9 + 7;
const ll MOD2 = 998244353;
const ll HIGHINF = (ll)1e18;
const ll LOWINF = (ll)1e15;
const long double PI = 3.1415926535897932384626433;

template<typename T> vector<T> make_v(size_t N,T init){return vector<T>(N,init);}
template<typename... T> auto make_v(size_t N,T... t){return vector<decltype(make_v(t...))>(N,make_v(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max<T>(a,b);}
template <class T> void chmin(T& a, const T b){a=min<T>(a,b);}
void YN(bool flg) {cout << ((flg) ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << ((flg) ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << ((flg) ? "yes" : "no") << endl;}

int main() {
	ll r,D,x;
	cin >> r >> D >> x;
	for(int i = 0; i < 10; ++i){
		x = r*x - D;
		cout << x << endl;
	}
	
  
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long 
#define float long double 
#define el '\n'
#define all(a) (a).begin(),(a).end()
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
 
void solve(){
	int n , a , b ;
	cin >> n >> a >> b ; 
	int ans = n/(a+b)*a;
	n = n%(a+b) ;
	cout <<  ans + ( n>a?a:n )  << endl ;
}

signed main(){
	IOS;
	int test = 1; 
	while(test--)
		solve();
	return 0;
}







Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<utility>
#define INF 0x3f3f3f3f
#define PI acos(-1)
#define ll long long
using namespace std;
int main() {
	std::ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	string s;
	cin >> s;
	for (int i = 0; i < s.length(); i++) {
		if (s[s.length()-1]=='3') {
			cout << "bon" << endl;
			return 0;
		}
	}
	for (int i = 0; i < s.length(); i++) {
		if (s[s.length()-1]=='0'||s[s.length()-1]=='1'||s[s.length()-1]=='6'||s[s.length()-1]=='8') {
			cout << "pon" << endl;
			return 0;
		}
	}
	for (int i = 0; i < s.length();i++) {
		if (s[s.length()-1] == '2' || s[s.length()-1] == '4' || s[s.length()-1] == '5' || s[s.length()-1] == '7' || s[s.length()-1] == '9') {
			cout << "hon" << endl;
			return 0;
		}
	}
	
	
	return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#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 equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 2e9 + 5;
const long double EPS = 1e-10;

int main() {
  int q;
  cin >> q;
  vector<pair<ll, ll>> p(q);
  rep(i, q) cin >> p[i].first >> p[i].second;

  rep(i, q) {
    ll l = 0, r = INF;
    while (r - l > 1) {
      ll m = (l + r) / 2, res;
      if (m & 1) res = (m + 1) * (m + 1) / 4;
      else res = m * (m + 2) / 4;

      if (res < p[i].first * p[i].second) l = m;
      else if (res == p[i].first * p[i].second && p[i].first == p[i].second) l = m;
      else r = m;
    }
    cout << l - 1 << endl;
  }



  
  return 0;
}

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

namespace WelcometoAtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            String input = Console.ReadLine();
            String[] splitted = input.Split(' ');
            int N = int.Parse(splitted[0]);
            int M = int.Parse(splitted[1]);
            int[] p = new int[M];
            String[] S = new String[M];
            for (int i = 0; i < M; i++)
            {
                input = Console.ReadLine();
                splitted = input.Split(' ');
                p[i] = int.Parse(splitted[0]);
                S[i] = splitted[1];
            }

            List<Problem> problems = new List<Problem>();
            for(int i = 0; i < N; i++)
            {
                problems.Add(new Problem(0, false));
            }
            int collect = 0;
            int penalty = 0;
            for(int i = 0; i < M; i++)
            {
                if (S[i] == "AC")
                {
                    if (!problems[p[i]-1].isSolved)
                    {
                        problems[p[i]-1].Solved();
                        collect++;
                        penalty += problems[p[i]-1].wrongCount;
                    }
                }
                else
                {
                    problems[p[i]-1].wrongCount++;
                }
            }
            Console.WriteLine(collect + " " + penalty);
        }
    }
    public class Problem
    {
        public int wrongCount;
        public bool isSolved;
        public Problem(int w, bool b)
        {
            wrongCount = w;
            isSolved = b;
        }
        public void Solved()
        {
            isSolved = true;
        }
    }
}


Measured memory_bytes: 25164
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
int  a[maxn];
int dp[maxn];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(int i=1;i<=n/2;i++)
    swap(a[i],a[n-i+1]);
     dp[1]=a[1];
    int k=1;
    for(int i=2;i<=n;i++)
    {
        if(a[i]+1>dp[k])
        dp[++k]=a[i];
        else
        {
            dp[lower_bound(dp+1,dp+1+k,a[i]+1)-dp]=a[i];
        }
    }
    cout<<k<<endl;

    return 0;
}


Measured memory_bytes: 1024
s = input().split()
s = list(map(int,s))
A = s[0]
B = s[1]
C = s[2]
D = s[3]
if A%C > 0:
  i = B//C - A//C
else:
  i = B//C - A//C + 1
if A%D > 0:
  j = B//D - A//D
else:
  j = B//D - A//D + 1
from fractions import gcd
p = (C*D)//(gcd(C,D))
if A%p > 0:
  k = B//p - A//p
else:
  k = B//p - A//p + 1
print(B-A+1-(i + j - k))

Measured memory_bytes: 63980
/*|In The Name of Allah|*/

#include <bits/stdc++.h>

using namespace std;

int n;
int A;
int B;
int AA[45];
int BB[45];
int cost[45];
int dp[45][405][405];

int go(int idx , int a , int b){
    if(idx > n){
        if(a * B == A * b && b != 0 && a != 0)
            return 0;
        return 1e5;
    }
    if(dp[idx][a][b] != -1)
        return dp[idx][a][b];
    int best = go(idx + 1 , a , b);
    best = min(best , cost[idx] + go(idx + 1 , a + AA[idx] , b + BB[idx]));
    return dp[idx][a][b] = best;
}

int main(){
    scanf("%d%d%d" , &n , &A , &B);
    memset(dp , -1 , sizeof dp);
    for(int i = 1; i <= n; i++){
        scanf("%d%d%d" , &AA[i] , &BB[i] , &cost[i]);
    }
    int ans = go(1 , 0 , 0);
    if(ans >= 1e5){
        puts("-1");
        return 0;
    }
    printf("%d\n" , ans);
}


Measured memory_bytes: 29184
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define N 200005
#define mod 1000000007
typedef long long int ll;
typedef long int li;

int n,c[N],val[N];
vector<int> g[N];
bool vis[N];

void dfs(int u,int in) {
    vis[u] = true;
    int new_val = in + c[u];
    val[u] = new_val;
    for(int v : g[u]) {
        if(!vis[v]) {
            dfs(v,new_val);
        }
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    
    int q,u,v,coun;
    cin>>n>>q;
    for(int i=1;i<n;i++) {
           cin>>u>>v;
           g[u].push_back(v);
           g[v].push_back(u);
    }
    for(int i=1;i<=q;i++) {
        cin>>u>>coun;
        c[u] += coun;
    }
    dfs(1,0);
    for(int i=1;i<=n;i++) cout<<val[i]<<" ";
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  if ( A + B > C + D ) cout << "Left" << endl;
  else if ( A + B < C + D ) cout << "Right" << endl;
  else cout << "Balanced" << endl;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
l=[input().split() for i in range(m)]
a=[0 for i in range(n)]
p=[0 for i in range(n)]
for i in range(m):
  if l[i][1]=='AC':
    a[int(l[i][0])-1]=1
  else:
    if a[int(l[i][0])-1]!=1:
      p[int(l[i][0])-1]+=1
cta=0;ctp=0
for i in range(n):
  if a[i]==1:
    cta+=1
    ctp+=p[i]
print(cta,ctp)

Measured memory_bytes: 33896
import java.util.ArrayList;
import java.util.Scanner;

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

        int n = sc.nextInt();
        ArrayList<String> s = new ArrayList<String>();
        for (int i = 0; i < n; i++) {
            s.add(sc.next());
        }

        int m = sc.nextInt();
        for (int i = 0; i < m; i++) {
            String t = sc.next();
            s.remove(t);
        }
        s.sort(null);
        String[] s1 = new String[s.size()];
        s1 = s.toArray(s1);

        int max = 0;
        if (s1.length > 0) {
            int cnt = 1;
            for (int i = 1; i < s1.length; i++) {
                if (s1[i].equals(s1[i-1])) {
                    cnt++;
                    max = Math.max(max, cnt);
                } else {
                    cnt = 1;
                }
            }
            max = Math.max(max, cnt);
        }
        
        System.out.print(max);
    }
}


Measured memory_bytes: 21844
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,stra,straa;
    ll x,y,z;
    char ca,cb,cc;
    cin>>a>>b;
    cout<<(long double)a/b<<endl;

    

    return 0;
}


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

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

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

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

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

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

	int A,B,N;
	while(cin>>A){
		cin>>B>>N;
		
		A %= B;
		int sum=0;
		REP(i,N){
			A *= 10;
			sum += A/B;
			A %= B;
		}
		out(sum);
	}
	
	return 0;
}



Measured memory_bytes: 3124
// mitsui_sumitomo_2019_f
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

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

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    ll T1, T2;
    cin >> T1 >> T2;
    ll A1, A2;
    cin >> A1 >> A2;
    ll B1, B2;
    cin >> B1 >> B2;

    // A1のほうが大きいとする
    if (B1 > A1){
        swap(A1, B1);
        swap(A2, B2);
    }

    ll C1 = A1 - B1;
    ll C2 = A2 - B2;

    //
    if (C1 == 0){
        if (C2 == 0){
            print("infinity");
        } else {
            print(1);
        }
        return 0;
    }

    ll x = C1 * T1;
    ll y = C2 * T2;

    if (C1 * T1 + C2 * T2 > 0){
        print(0);
        return 0;
    }

    if (C1 * T1 + C2 * T2 == 0){
        print("infinity");
        return 0;
    }

    ll d = -(x + y);

    if (d > x){
        print(1);
        return 0;
    }

    if (d == x){
        print(2);
        return 0;
    }

    ll ans;
    if (x % d == 0){
        ll n = x / d;
        ans = 2 * n;
    } else {
        ll n = x / d ;
        ans = 2 * n + 1;
    }
    print(ans);


    return 0;
}


Measured memory_bytes: 256
def divisor(n):
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table

a, b, k = map(int,input().split())
a_l = divisor(a)
b_l = divisor(b)

a_l.sort(reverse=True)
b_l.sort(reverse=True)

cnt = 0
for i in a_l:
    for j in b_l:
        if i == j:
            cnt += 1
            if cnt == k:
                print(i)
                exit()


Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws NumberFormatException, IOException{

        int x;

        try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            x = Integer.parseInt(br.readLine());
        }

        System.out.println(x * x * x);
    }

}



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

int main()
{
    ll N; cin >> N;
    ll maxv = N / 4;

    if (N % 4 == 0) {
        cout << "Yes" << endl;
        exit(0);
    }

    rep (i, maxv) {
        ll k = i * 4;
        if ((N - k) % 7 == 0) {
            cout << "Yes" << endl;
            exit(0);
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 3616
import java.util.*;
 
class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    int n = sc.nextInt();
    int ans = 0;
    for(int i=0; i<=25; i++){
      for(int j=0; j<=14; j++){
        int total = 4*i + 7*j;
        if(n == total){
          ans++;
        }
      }
    }
    if(ans != 0){
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }

    sc.close();
  }
}


Measured memory_bytes: 21972
use std::io::stdin;
use std::str::FromStr;
use std::collections::VecDeque;

fn read_line<T>() -> Vec<T>
where
    T: FromStr,
    <T as std::str::FromStr>::Err: std::fmt::Debug,
{
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect()
}

fn main() {
    let in_vec: Vec<i32> = read_line();
    let k = in_vec[0];

    let mut res: i64 = 0;

    let mut queue: VecDeque<i64> = VecDeque::new();
    for i in 1..10 {
        queue.push_back(i);
    }
    for _i in 0..k {
        let front_num = queue.pop_front().unwrap();
        res = front_num;
        let smallest_digit = front_num % 10;
        if smallest_digit != 0 {
            queue.push_back(front_num * 10 + smallest_digit - 1);
        }
        queue.push_back(front_num * 10 + smallest_digit);
        if smallest_digit != 9 {
            queue.push_back(front_num * 10 + smallest_digit + 1);
        }
    }

    println!("{}", res);
}


Measured memory_bytes: 6396
h = {}
('a'..'z').each { |c| h[c]  = 0 }

while s = gets
  cs = s.downcase.chars
  cs.select! { |c| (c.ord >= 97 && c.ord <= 122) || (c.ord >= 65 && c.ord <= 90) }
  cs.each { |c| h[c] += 1 }
end

h.keys.each { |k| puts "#{k} : #{h[k]}" }

Measured memory_bytes: 6100
#include<bits/stdc++.h>
using namespace std;
map<string,bool> a;
int main()
{
	int n;
	cin>>n;
	char la=' ';
	string h;
	cin>>h;
	la=char(h[h.length()-1]);
	a[h]=true;
	for(int i=1;i<n;i++)
	{
		cin>>h;
		if(a[h] || char(h[0])!=la)
		{
			cout<<"No\n";
			return 0;
		}
		la=h[h.length()-1];
		a[h]=true;
	}
	cout<<"Yes\n";
	return 0;
}

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

using namespace std;

int main(){

  int n;

  cin >> n;

  vector<string> junkai(n);
  
  for(int i = 0;i < n;++i){
	cin >> junkai[i];

	string train;
	int point = 0;
	
	train = junkai[i][0];
	
	for(int j = 1;j < junkai[i].size();j+=3){
	  if(junkai[i][j] == '-' && junkai[i][j+1] == '>'){
		if(train[point + 1] == '\0'){
		  train += junkai[i][j+2];
		}
		point++;
	  }
		
	  else if(junkai[i][j] == '<' && junkai[i][j+1] == '-'){
		if(point == 0)
		  train = junkai[i][j+2] + train;
		else
		  point--;
	  }
	}
	cout << train << endl;
  }
}



Measured memory_bytes: 3160
#include <bits/stdc++.h>
#include <cxxabi.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define LINF    ((ll)1ll<60)
#define INF     ((int)1<<30)
#define EPS     (1e-9)
#define MOD     (1000000007)
template<class S,class T>ostream& operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool b=1;for(auto s:t)os<<(exchange(b,0)||strlen(abi::__cxa_demangle(typeid(S).name(),0,0,0))>20?"":" ")<<s;return os<<endl;}


int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
    int n,k;
    cin>>n>>k;
    vi a(n);
    rep(i,n)cin>>a[i];
    int p=find(all(a),1)-a.begin();
    int l=p,r=n-p-1;
    int ans=ceil((double)l/(k-1))+ceil((double)r/(k-1));
    rep(i,k){
        int nl=l-i,nr=r-(k-i-1);
        ans=min(ans,1+(int)(ceil((double)nl/(k-1))+ceil((double)nr/(k-1))));
    }
    cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N, M;
  cin >> N >> M;
  if (2 * N == M) {
    cout << N << endl;
    return 0;
  }
  if (M > 2 * N) {
    ll ans = N;
    ll res = M - 2 * N;
    ans += res / 4;
    cout << ans << endl;
  } else {
    cout << M / 2 << endl;
  }
  return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
 bool prime(int a){
   if(a<2)
     return false;
   else if(a==2)
     return true;
   else if(a%2==0)
     return false;
   double b=sqrt(a);
    for(int i=3;i<=b;i+=2){
      if(a%i==0){
        return false;
      }
    }
   return true;
 }
signed main(){
  int a;
  cin>>a;
  vector<double> b(a);
  fo(i,a)
    cin>>b[i];
  Sort(b);
  double c=2;
  fo(i,a-1)
    b[i+1]=(b[i]+b[i+1])/c;
  cout<<setprecision(13)<<b[a-1]<<endl;
}

Measured memory_bytes: 256
X, Y, A, B, C = map(int, input().split())
p = sorted(list(map(int, input().split())))[::-1]
q = sorted(list(map(int, input().split())))[::-1]
r = sorted(list(map(int, input().split())))[::-1]

i = X - 1
j = Y - 1
k = 0

p.append(float("INF"))
q.append(float("INF"))
r.append(-1)

while p[i] < r[k] or q[j] < r[k]:
    if p[i] < q[j]:
        i -= 1
        k += 1
    else:
        j -= 1
        k += 1

ans = 0
if i != -1:
    ans += sum(p[:i+1])
if j != -1:
    ans += sum(q[:j+1])
if k != 0:
    ans += sum(r[:k])

print(ans)

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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

const string YES = "Yes";
const string NO = "No";

void solve(long long H, long long N, std::vector<long long> A){
    cout << (accumulate(ALL(A), 0) < H ? NO : YES) << endl;
}

int main(){
    long long H;
    scanf("%lld",&H);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(H, N, std::move(A));
    return 0;
}


Measured memory_bytes: 1024
n = int(input())
li_city = list(map(int,input().split()))
li_hero = list(map(int,input().split()))
score = 0
for i in range (n):
  if li_hero[i] >= li_city[i] + li_city[i + 1]:
    score += li_city[i] + li_city[i + 1]
    li_city[i + 1] = 0
  elif li_hero[i] >= li_city[i]:
    score += li_hero[i]
    li_city[i + 1] -= li_hero[i] - li_city[i]
  else:
    score += li_hero[i]
print(score)

Measured memory_bytes: 19116
fun main(args: Array<String>) {
    val x = readLine()!!.toDouble()
    val nearest = x.pow(0.2)
    var i = 0
    while (true) {
        val bigger = ceil(nearest + i)
        val biggerP5 = bigger.pow(5)
        val diff1 = floor((biggerP5 - x).pow(0.2))
        if (biggerP5 - diff1.pow(5) == x) {
            println("${bigger.toInt()} ${diff1.toInt()}")
            return
        }

        val smaller = floor(nearest - i)
        val smallerP5 = smaller.pow(5)
        val diff2 = floor((x - smallerP5).pow(0.2))
        if (smallerP5 + diff2.pow(5) == x) {
            println("${smaller.toInt()} ${-diff2.toInt()}")
            return
        }

        i++
    }
}

fun Double.pow(x: Double) = Math.pow(this, x)
fun Double.pow(x: Int) = Math.pow(this, x.toDouble())
fun ceil(x: Double) = Math.ceil(x)
fun floor(x: Double) = Math.floor(x)

Measured memory_bytes: 34648
#098_C
n=int(input())
s=input()

sw=[0 for i in range(n)]
for i in range(n):
    if i==0:
        sw[0]+=(s[i]=='W')
    else:
        sw[i]=sw[i-1]+(s[i]=='W')
        
ans=10**6
for i in range(n):
    res=(n-i-1)-(sw[-1]-sw[i])
    if i>0:
        res+=sw[i-1]
    ans=min(ans,res)
print(ans)

Measured memory_bytes: 15520
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long ans = 1;
void mul(int x) {
	ans *= x;
	ans %= mod;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);  
	int n, m;
	cin >> n >> m;
	vector<int> a(n), b(m);
	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for(int i = 0; i < m; i++) {
		cin >> b[i];
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	for(int i = 1; i < n + 1; i++) {
		if(a[i] == a[i - 1]) {
			cout << 0 << endl;
			return 0;
		}
	}
	for(int i = 1; i < m + 1; i++) {
		if(b[i] == b[i - 1]) {
			cout << 0 << endl;
			return 0;
		}
	}
	int cnt = 0;
	for(int i = m * n; i >= 1; i--) {
		auto x = lower_bound(a.begin(), a.end(), i);
		auto y = lower_bound(b.begin(), b.end(), i);
		int xx = a.end() - x;
		int yy = b.end() - y;
		if(*x == i && *y == i) {
			cnt++;
			continue;
		}
		if(*x == i) {
			mul(yy);
			cnt++;
			continue;
		}
		if(*y == i) {
			mul(xx);
			cnt++;
			continue;
		}
		mul(xx * yy - cnt);
		cnt++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


// BIT-------------------------------------------------------

// [0, N-1]ではなく[1, N], 1-indexed
int M;
const int MAX_N = 200000;
vector<ll> bit(MAX_N+1); // bit[1]...bit[N]を使用

ll sum(int a){          // 1～a (1-indexed)の和を求める
  ll ret=0;
  for (int i=a; i>0; i -= i & -i) ret += bit[i];
  return ret;
}

void add(int a, ll x){  // a番目(1-indexed)に x を加える
  for (int i=a; i<=M; i += i & -i) bit[i] += x;
}


int main() {
  int N; cin >>N >>M;
  vector<bool> work(M+1, true);
  work[0] = false;
  // i日目に仕事を受けられるか
  // BITの都合で1-indexedにする
  for (int i=1; i<=M; i++) add(i, 1);
  // 働けるところはBIT上で1にしておく

  vector<pair<ll,ll>> A(N);
  rep(i, N) cin >>A[i].second >>A[i].first;
  rep(i, N) A[i].second--; // BITの都合でデクリメント
  sort(all(A)); reverse(all(A));
  // 報酬が多い順にソート

  ll res = 0;

  rep(i, N){
    ll cost = A[i].first;
    ll day = M - A[i].second;
    // day日かそれより前に仕事を受ければ間に合う
    // day日丁度に受けられるなら受ける
    if (day <= 0) continue;
    if (work[day]){
      res += cost;
      work[day] = false;
      add(day, -1);
    }else{
      // day日より前のうち、仕事を受けられる最も遅い(jが大きい)ところに仕事を入れる
      // BIT上二分探索とかで。
      int s = sum(day);
      if (s == 0) continue; // day日より前で仕事を受けられる日はない
      // BIT上での和がsになる最大のやつを二分探索。そこに仕事を入れる
      int ok = M+1, ng = 0;
      while (abs(ok - ng) > 1){
        int mid = (ok+ng)/2;
        if (sum(mid) >= s) ok = mid;
        else ng = mid;
      }
      res += cost;
      work[ok] = false;
      add(ok, -1);
    }
  }
  cout <<res <<endl;

}


Measured memory_bytes: 3328
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<set>
using namespace std;

int main(){
	string n;
	while(cin>>n){
	int ta[10][10]={{0},{0}};
	for(int i=0;i<10;i++)ta[0][i]=n[i]-'0';
		for(int i=0;i<9;i++){
			for(int j=i+1;j<10;j++){
			int tmp=ta[i][j]+ta[i][j-1];
			if(tmp>=10)tmp-=10;
			ta[i+1][j]=tmp;
			}
		}
		cout<<ta[9][9]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1180
#include <iostream>
using namespace std ;
int main(void)
{
	int N ;
	cin >> N ;
	string s;
	for (int i = 0; i < N; i++)
	{
		cin >> s;
		if ( s == "Y")
		{
			break;
		}

	}

	if ( s != "Y")
	{
		cout << "Three" << endl;
	}
	else
	{
		cout << "Four" <<endl;
	}
	return 0 ;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


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

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)








int main() {
    int n, a, b;
    scanf("%d %d %d", &n, &a, &b);
    int c[3] = {};
    for(int i = 0; i < n; i++){
        int p;
        scanf("%d", &p);
        if(p <= a) c[0]++;
        else if(p <= b) c[1]++;
        else c[2]++;
    }
    printf("%d\n", min({c[0], c[1], c[2]}));
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <ctime>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repq(i,a,n) for(int i=a; i<=n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 999999999

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int const MOD = 1000000007;

int main() {
    int q; cin >> q;
    rep(i,0,q) {
        string s; cin >> s;
        int cnt = 0;
        while(1) {
            // cout << s << endl;
            if(s.length() == 1) break;
            else {
                int ma = 0;
                rep(i,1,s.length()) {
                    string s1 = s.substr(0,i);
                    string s2 = s.substr(i,s.length() - i);
                    ma = max(ma, atoi(s1.c_str()) * atoi(s2.c_str()));
                }
                s = to_string(ma);
                cnt++;
            }
        }
        cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 3212
#include<iostream>
 
using namespace std;
 
int main(){
int timeInSeconds;
cin>>timeInSeconds;
 
int hour=0,minute=0,second=0;
 
if(timeInSeconds>=3600){
hour = timeInSeconds/3600;
timeInSeconds = timeInSeconds%3600;
if(timeInSeconds>=60){
minute = timeInSeconds/60;
timeInSeconds = timeInSeconds%60;
}
second = timeInSeconds;
 
 
}else if(timeInSeconds>=60){
hour = 0;
minute = timeInSeconds/60;
timeInSeconds = timeInSeconds%60;
second = timeInSeconds;
 
 
}else{
hour = 0;
minute = 0;
second = timeInSeconds;
 
}
 
cout<<hour<<":"<<minute<<":"<<second<<endl;
return 0;
}

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

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

    int n, m;
    cin >> n >> m;

    int G[n][n];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(i == j) G[i][j] = 0;
            else G[i][j] = 1e9;
        }
    }

    int E[m][3];
    for(int i = 0; i < m; i++){
        cin >> E[i][0] >> E[i][1] >> E[i][2];
        E[i][0]--; E[i][1]--;
        G[E[i][0]][E[i][1]] = E[i][2];
        G[E[i][1]][E[i][0]] = E[i][2];
    }

    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            for(int k = 0; k < n; k++){
                G[j][k] = min(G[j][k], G[j][i] + G[i][k]);
            }
        }
    }

    int ans = 0;
    for(int i = 0; i < m; i++){
        //最短経路が更新 -> そこを通る必要がない
        if(G[E[i][0]][E[i][1]] == E[i][2]);
        else{
            //だからといって「どの異なる2頂点間の，どの最短経路にも含まれない辺の数」としてカウントしていいんですか？
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256