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

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

#ifndef __MACRO_H__
#define __MACRO_H__

#define all(collection) (collection).begin(), (collection).end()  // begin to end
#define rep(i, begin, end) for (ll i = begin; i < end; i++)       // repeat
#define repr(i, begin, end) for (ll i = begin; end < i; i--)      // repeat reverse
#define size(collection) ((ll) (collection).size())               // collection size

#endif


int main(void)
{
	ll n, k; cin >> n >> k;
	string s; cin >> s;

	ll ans = 0;
	ll group = 1;
	rep(i, 0, size(s)-1)
	{
		if (s[i] != s[i + 1])
			group++;
		if (s[i] == s[i + 1])
			ans++;
	}

	while (group >= 3)
	{
		ans += 2;
		group-=2;
		k--;
		if (k == 0)
			break;
	}

	if (0 < k)
		ans = size(s)-1;

	cout << ans;
	return 0;
}

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

typedef long long int ll;

int main()
{
    ll a, b;
    cin >> a >> b;
    if(a < b){
        for(ll i = 0;i < b;i++){
            cout << a;
        }
    }
    else{
        for(ll i = 0;i < a;i++){
            cout << b;
        }
    }


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#define ll long long
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define fd(i, l, r) for (int i = r; i >= l; i--)
using namespace std;
inline ll read()
{
	ll x = 0, f = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9')
	{
		if (ch == '-')
			f = -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9')
	{
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	return x * f;
}
int n;
int a[100050],b[100050],v[100050];
int a1,a2,b1,b2;
int main()
{
	n = read();
	fo(i,1,n){
		v[i] = read();
	}
	fo(i,1,n){
		if(i&1)a[v[i]]++;
		else b[v[i]]++;
	}
	fo(i,1,100000){
		if(a[i] > a[a1]) a1 = i;
		if(b[i] > b[b1]) b1 = i;
	}
	fo(i,1,100000){
		if(i != a1 && a[i] > a[a2]) a2 = i;
		if(i != b1 && b[i] > b[b2]) b2 = i;
	}
	int ans = n;
	if(a1 == b1) ans = min(n-a[a1]-b[b2],n-a[a2]-b[b1]);
	else ans = n-a[a1]-b[b1];
	cout<<ans;
	//cout<<a1<<" "<<a2<<" "<<b1<<" "<<b2<<endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>
int main(){
int a,b,c,d,i,e=0;
scanf("%d\n%d\n",&a,&b);
for(i=0;i<a;i++){
scanf("%d %d\n",&c,&d);
if(b-d+c<0){
e=0;
break;
}
b=b-d+c;
if(e<b){
e=b;
}
}
printf("%d\n",e);
return 0;
}



Measured memory_bytes: 2040
#ex:[2 5] => a=2 b=5 みたいにしないといけない

a, b = map(int, input().split())

#print(a)
#print(b)


# 2.目的通りの計算をする
# ex:2つの整数AとBの掛け算をやる

answer = a*b

#計算の結果を出力する

print(answer)

Measured memory_bytes: 9052
#include "bits/stdc++.h"
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__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int  long long int
#define pb push_back
#define fe first
#define lb lower_bound 
#define ub upper_bound
#define pii pair<pair<int,int>,pair<int,int> >
#define se second
#define endl "\n"
#define pi pair<int, int>
#define mi          map<int,int>
#define mii         map<pi,int>
#define vi vector<int> 
#define vvi vector<vi>
#define bs   binary_search
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)	
#define all(c) (c).begin(),(c).end()
#define sz(x)       (int)x.size() 
#define PI 3.14159265358979323846

 const int N=5e5+5;

 int mod= 1e9+7;
 int dx[4]={0,0,+1,-1};
 int dy[4]={+1,-1,0,0};  
 
 
int po(int a, int b) {
	a %= mod;
	int res = 1;
	while (b > 0) {
		if (b & 1)
			res = (res * a) % mod;
		a =(a*a) % mod;
		b >>= 1;
	}
	 return res;	
   }



int k;

vector<string >vs[N]; 

void solve() {
    cin>>k;
    
    vs[1].pb("1");vs[1].pb("2");vs[1].pb("3");vs[1].pb("4");vs[1].pb("5");
    vs[1].pb("6");vs[1].pb("7");vs[1].pb("8");vs[1].pb("9");
    
    //~ for(auto to:vs)
      //~ cout<<to<<endl;
   
    int ind=1; 
    int sum=9;  
    if(k<=9) {
		   rep(i,0,sz(vs[1])) {
			      if(i+1==k) {
					     cout<<vs[1][i]<<endl;
					     return;
					  }
			   }
		}
		
    while(sum<k) {	      
	      rep(i,0,sz(vs[ind])) {			     		   			     
			     rep(j,0,10) {	
					 string p=vs[ind][i];					  
					    int nx1=abs((p[ind-1]-'0')-j);
					    if(nx1<=1) {
							  p+=(j+'0');							  
							  vs[ind+1].pb(p);
							  sum++;
							  if(sum==k) {
								     cout<<p<<endl;
								     return;
								  }
							}
 					 }   
			  }
			  //~ cout<<sum<<endl;
			  ind++;	      
	    }
	    
	    
	  
              
}

    
int32_t main() {
	cool;
	int t=1;	

	//cin>>t;
	while(t--)
	  solve();

  return 0;	   
}


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

vector<ll> a,b;
vector<vector<ll>> dp;

ll func(ll idx, int health){
  	if(health<=0)
      	return 0;
  	if(idx==-1)
		return INF;
     if(dp[idx][health]!=-1)
       	return dp[idx][health];
  	 return dp[idx][health] = min(b[idx]+func(idx, health-a[idx]), func(idx-1,health));
}

int main()
{
  	ll h,n;
	cin>>h>>n;
  	a.resize(n);
  	b.resize(n);
    dp.resize(n+1, vector<ll> (h+1,-1));
    for(int i=0;i<n;i++){
      cin>>a[i];
      cin>>b[i];
    }
  	cout<<func(n-1, h);
  	return 0;
}

Measured memory_bytes: 80768
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;

namespace AtCoder {
    class Program {
        static void Main(string[] args) {

            var input = DateTime.Parse(Console.ReadLine());
            if (input <= new DateTime(2019, 4, 30)) {
                Console.WriteLine("Heisei");
            } else {
                Console.WriteLine("TBD");
            }
        }
    }
}

Measured memory_bytes: 12756
#include<stdio.h>
int main(void)
{
	int t,n,i,g;
	for(i=1;i<=4;i++){
	scanf("%d%d",&t,&n);
	if(t==1){
		g=n*6000;
		printf("%d\n",g);
	}
	else if(t==2){
		g=n*4000;
		printf("%d\n",g);
	}
	else if(t==3){
		g=n*3000;
		printf("%d\n",g);
	}
	else if(t==4){
		g=n*2000;
		printf("%d\n",g);
	}
	}
	return 0;
}

Measured memory_bytes: 600
def solve(n, s, low):
    if n == 0:
        return 1 if s == 0 else 0
    res = 0
    for i in range(low,10):
        if s - i < 0: break
        res += solve(n-1, s-i, i+1)
    return res

while True:
    n, s = map(int, raw_input().split(' '))
    if n == 0: break
    print solve(n, s, 0)

Measured memory_bytes: 4212
#include<stdio.h>
#include<deque>
#include<algorithm>
using namespace std;
int main()
{
	int n,i,x,f,s;
	while(scanf("%d",&n),n)
	{
		deque<int>p[2],d(2*n);p[0].resize(n),p[1].resize(n);
		deque<int>::iterator z;
		for(s=f=i=0;i<2*n;++i)d[i]=i+1;
		for(i=0;i<n;++i)scanf("%d",&x),p[0][i]=x;
		sort(p[0].begin(),p[0].end());
		set_difference(d.begin(),d.end(),p[0].begin(),p[0].end(),p[1].begin());
		while(!p[0].empty()&&!p[1].empty())
		{
			if(z=upper_bound(p[s].begin(),p[s].end(),f),z!=p[s].end())f=*z,p[s].erase(z);
			else f=0;
			s=!s;
		}
		printf("%d\n%d\n",p[1].size(),p[0].size());
	}
	return 0;
}

Measured memory_bytes: 0
N = input()
if int(N[-1]) == 2 or int(N[-1]) == 4 or \
        int(N[-1]) == 5 or int(N[-1]) == 7 or \
        int(N[-1]) == 9:
    print('hon')
elif int(N[-1]) == 0 or int(N[-1]) == 1 or \
        int(N[-1]) == 6 or int(N[-1]) == 8:
    print('pon')
else:
    print('bon')

Measured memory_bytes: 61672
#include <iostream>

using namespace std;

string translate[] = {"afkpuz", "bglqv.", "chmrw?", "dinsx!", "ejoty "};

int main()
{
    string s;

    while (cin >> s) {
        string out;
        bool flag = true;

        for (int i = 0; i < s.size(); i += 2) {
            int col = s[i] - '0';
            int row = s[i + 1] - '0';

            if (col < 1 || col > 6 || row < 1 || row > 5) {
                cout << "NA\n";
                flag = false;
                break;
            }
            
            out.push_back(translate[row - 1][col - 1]);
        }
        if (flag)
            cout << out << endl;
    }

    return 0;
}

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

int main(void) {

	std::string N;
	std::cin >> N;

	// calculate S(N)
	int total = 0;
	for (int i = 0; i < (int)N.size(); i++) {
		total += N[i] - '0';
	}

	int n = atoi(N.c_str());
	std::string ans = (n % total == 0) ? "Yes": "No";
	std::cout << ans << std::endl;
	return 0;
}



Measured memory_bytes: 256
// Hint: Don't look, No need, Let'em Play.

#include <bits/stdc++.h>
#include "bits/stdc++.h"

using namespace std;

#define int long long
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#ifndef bhupixb
    #define var(...)
    #define stl(...)
#endif

using hr_clock = chrono::high_resolution_clock;

struct Timer_ {
    private: chrono::time_point<hr_clock> start_;
    public: Timer_(); ~Timer_();
}_;

#define single_test

void solve() {
    int n;
    cin >> n;
    cout << n + n * n + n * n * n << '\n';
}

signed main() {
    fast;
    int t = 1;
    #ifndef single_test
        cin >> t;
    #endif
    while (t--) {
        // Timer_ _;
        solve();
    }

    return 0;
}

Timer_::Timer_() {
    start_ = hr_clock::now();
}

Timer_::~Timer_() {
    #ifdef bhupixb
    cerr << "took: " << chrono::duration_cast<chrono::microseconds>(hr_clock::now() - start_).count() / 1000 << " ms\n";
    #endif
}


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

int main(){
  long long x,a=0,b=0,ans;
  cin>>x;
  while(x>=500){
    x-=500;
    a++;
  }
  while(x>=5){
    x-=5;
    b++;
  }
  ans=1000*a+5*b;
  cout<<ans;
}

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end



int main(){
   int n; scanf("%d",&n);
   vector<int> a(n),pos(n+1);
   rep(i,0,n){scanf("%d",&a[i]); pos[a[i]]=i+1;}
   set<int> st; st.insert(0); st.insert(n+1);
   ll ans=0;
   rep(i,0,n){
      ll add=i+1;
      auto it=st.lower_bound(pos[i+1]); it--;
      add*=(pos[i+1]-*it);
      it=st.upper_bound(pos[i+1]);
      add*=(*it-pos[i+1]);
      ans+=add; st.insert(pos[i+1]);
   }
   printf("%lld\n",ans);
   return 0;
}

Measured memory_bytes: 11136
import java.util.Scanner;
class Main {

	public void small() {

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();

		int b = sc.nextInt();

		if(a < b) {

			System.out.println("a < b");

		} else {

			if(a > b) {

				System.out.println("a > b");

			} else {

				System.out.println("a == b");

			}

		}

	}

	public static void main(String[] args) {

		new Main().small();

	}

}

Measured memory_bytes: 26188
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1e18,MOD=1e9+7;
const int iINF=1e9;
int main(){
    ll m,d,ans=0;
    cin>>m>>d;
    for(int i=1;i<=m;i++){
        for(int j=10;j<=d;j++){
            if(j%10>=2&&j>=20&&(j/10)*(j%10)==i)ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P;

int main(){
	int H,W;
	char c[100][101];

	scanf("%d %d",&H,&W);
	for(int i=0;i<H;i++){
		scanf("%s",c[i]);
	}

	char ans[200][101];
	for(int i=0;i<H;i++){
		printf("%s\n",c[i]);
		printf("%s\n",c[i]);
	}

	return 0;
}


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

typedef long long ll;
typedef string st;
typedef vector<int> vi;
typedef vector<st> vs;
#define rep(i, n) for(int i = 0; i < n; i++)
#define fogg(i,a,b) for(int i = (a); i <= (b); i++)
#define ford(i,a,b) for(int i = (a); i >= (b); i--)
#define test int t; cin >> t; while(t--)
#define debug(x) cout << '>' << #x << ':' << x << "\n";
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair



int main() {
    int n;
    cin >> n;
    int a[n],b[n];
    rep(i,n){
        cin >> a[i];
        b[i]=a[i];
    }
    sort(a,a+n);
    for(int i=0;i<n;i++){
        if(b[i]==a[n-1]){
            cout << a[n-2]<<endl;
        }
        else{
            cout << a[n-1]<<endl;
        }
    }
return 0;
}

Measured memory_bytes: 3200
#include<stdio.h>
#include<iostream>

int main(){

  long long a, b, c;
  
  long long ans;
  
  std::cin>>a>>b>>c;
  
  if(c-(a+b)>0){
    long long r, l;
    
    r = (c-(a+b))*(c-(a+b));
    l = 4*a*b;
    
    if(r>l){
      std::cout<<"Yes";
    }else{
      std::cout<<"No";
    }
    
    
  }
  else{
    std::cout<<"No";
  }
  
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp
 
using namespace std;
 
typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end()) // ちゃんとユニークな配列にする。連続した値を除去して切り出す。
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;
 
int main() {
  int N;
  int size;
  cin >> N;
  vector<int> A;
  rep(i, N) {
    cin >> size;
    A.pb(size);
  }
  sort(all(A));
 
  vector<int> B;
    rep(i, N) {
    cin >> size;
    B.pb(size);
  }
  sort(all(B));
 
  vector<int> C;
  rep(i, N) {
    cin >> size;
    C.pb(size);
  }
  sort(all(C));
 
  long long result = 0;
  rep(i, N) {
    // DEBUG(i);
    int b = B[i];
    long long countA;
    if (A[0] >= b) {
      countA = 0;
    } else {
      decltype(A)::iterator ita = lower_bound(A.begin(), A.end(), b);
      countA = ita - A.begin();
    }
  
 
    // DEBUG(countA);
    long long countC;
    if (b >= C[N-1]) {
      countC = 0;
    } else {
      decltype(C)::iterator itc = upper_bound(C.begin(), C.end(), b);
      countC = N - (itc - C.begin());
    }
 
    // DEBUG(countC);
    result = result + (countA * countC);
  }
  cout << result << endl;
}


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

int main(){
    int n; cin >> n;
    for(int i = 0; i < n; i++){
        int a; cin >> a;
        if(a % 2 == 0){
            if(a % 3 == 0 || a % 5 == 0){
                continue;
            }else{
                cout << "DENIED" << endl;
                return 0;
            }
        }
    }
    cout << "APPROVED" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

long long gcd(long long a, long long b)
{
    if (a < b) {
        return gcd(b, a);
    }
    if (b == 0) {
        return a;
    }

    return gcd(b, a % b);
}

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

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

    long long t[n];
    for (int i = 0; i < n; i++) {
        cin >> t[i];
    }

    long long ans = 1;
    for (int i = 0; i < n; i++) {
        ans = lcm(ans, t[i]);
	}
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
using ll = long long;

//LLONG_MAX
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
using namespace std;

int N, K;
int A[1001];

vector<int> s;
vector<int> pick;
vector<int> temp;

signed main()
{
	cin >> N >> K;
	REP(i, N) cin >> A[i];

	s.reserve(1000000);
	pick.reserve(1000000);
	temp.reserve(1000000);

	for (int i = 0; i < N; i++)
	{
		int a = 0;
		for (int j = i; j < N; j++)
		{
			a += A[j];
			s.push_back(a);
		}
	}

	pick = s;
	bool is_pick = false;
	for (int i = 62; i >= 0; i--)
	{
		int mask = (1LL << i);
		temp.clear();
		for (int p : pick)
		{
			if ((p & mask) > 0)
			{
				temp.push_back(p);
				is_pick = true;
			}
		}
		if (temp.size() >= K)
		{
			pick = temp;
		}
	}

	if (!is_pick)
	{
		cout << 0 << endl;
	}

	int ans = 0;
	ans = pick[0];
	for (int p : pick)
	{
		ans &= p;
	}
	cout << ans << endl;
}








Measured memory_bytes: 13824
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<functional>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<random>
#include<set>
#include<stack>
#include<string>
#include<utility>
#include<vector>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REPR(i,n)   FORR(i,n,0)
#define int long long

using namespace std;
typedef pair<int, int> pii;

const int modp=1e+9+7;
int n,k,a[110]={0};
int dp[110][100010]={0};

signed main() {
	cin>>n>>k;
    rep(i,n){
        cin>>a[i+1];
    }
	
    dp[0][0]=1;
    rep(i,n+1){
        rep(j,k+1){
            if(i==0&&j==0){
                continue;
            }
            if(i>=1){
                dp[i][j]+=dp[i-1][j];
                dp[i][j]%=modp;
                if(j-a[i]-1>=0){
                    dp[i][j]+=modp;
                    dp[i][j]-=dp[i-1][j-a[i]-1];
                    dp[i][j]%=modp;
                }
            }
            if(j>=1){
                dp[i][j]+=dp[i][j-1];
                dp[i][j]%=modp;
            }
        }
    }
	
  if(k>=1){
    cout<<(dp[n][k]-dp[n][k-1]+modp)%modp<<endl;
  }
  else{
  	cout<<dp[n][k]<<endl;
  }
  /*
  rep(i,n+1){
  	rep(j,k+1){
    	cout<<dp[i][j]<<" ";
    }
    cout<<endl;
  }
  */
	
	return 0;
}


Measured memory_bytes: 80128
n = int(input())
ab = []
for i in range(n):
  a, b = map(int,input().split())
  ab += [[a,b]]
ab.sort(key=lambda x:x[1])
x = 0
ans = 'Yes'
for c in ab:
  x += c[0]
  if x > c[1]:
    ans = 'No'
    break
print(ans)

Measured memory_bytes: 84952
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

/* Starry Sky Tree */
//0-index

struct StarrySkyTree{
  typedef ll Type;
  int segn2;
  vector<Type> data, s_data;
  function<Type(Type, Type)> merge;

  StarrySkyTree(function<Type(Type, Type)> merge, int n): merge(merge)
  {
    for(segn2=1; segn2<n; segn2*=2);
    data.assign(segn2*2, 0);
    s_data.assign(segn2*2, 0);
  }

  StarrySkyTree(int n): //Original Ver.
    StarrySkyTree([](Type a, Type b){ return min(a, b); }, n) {}

  //get value of [a,b)
  Type query(int a, int b, int l = 0, int r = -1, int k = 0){
    if(r == -1) r = segn2;
    if(r <= a || b <= l) return LLINF; //大きさに注意
    if(a <= l && r <= b) return data[k] + s_data[k];
    return merge(query(a, b, l, (l+r)/2, k*2+1), query(a, b, (l+r)/2 , r, k*2+2)) + s_data[k];
  }

  //add x to [a,b)
  Type add(int a, int b, Type x, int l = 0, int r = -1, int k = 0){
    if(r == -1) r = segn2;
    if(a <= l && r <= b)
      s_data[k] += x;
    else if(a < r && l < b)
      data[k] = merge(add(a, b, x, l, (l+r)/2, k*2+1), add(a, b, x, (l+r)/2, r, k*2+2));

    return data[k] + s_data[k];
  }

};

int main(){
  int N, A, B;
  int p[SIZE];

  cin >> N >> A >> B;

  for(int i=0;i<N;i++)
    cin >> p[i];

  StarrySkyTree seg(N+1);

  for(int i=0;i<N;i++){
    ll minVal = seg.query(0, p[i]);

    seg.add(0, p[i], A);
    seg.add(p[i]+1, N+1, B);

    ll q = seg.query(p[i], p[i]+1);
    seg.add(p[i], p[i]+1, minVal - q);
  }

  ll ans = seg.query(0, N+1);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 512
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <fstream>
#include <iostream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <ext/random>
#include <ext/rope>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using ull = unsigned long long;
using vi = std::vector<int>;
using vl = std::vector<int64>;
using pii = std::pair<int, int>;
using pii = std::pair<int, int>;
using pll = std::pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(_) (_).begin(), (_).end()
#define rall(_) (_).rbegin(), (_).rend()
#define print(_) std::cout << (_) << '\n'
#define debug(_) std::cerr << #_ << ": " << (_) << '\n'
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
template<typename T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  os << "{";
  for (size_t i = 0; i < vec.size(); ++i) {
    os << vec[i] << ",}"[i == vec.size() - 1];
  }
  return os;
}
template<typename T, typename U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << "{" << p.first << " " << p.second << "}";
}
// constant
const int INF = (1<<30) - 1;  // 1.073741823e9
const int64 INF64 = (1LL<<62) - 1;  // 4.611686018427387903e18
const int MOD = 1000000007;

const int MAX = 2e5;
//const int MOD = 1e9 + 7;
int64 fac[MAX] = {}, inv[MAX] = {}, finv[MAX] = {};

void make_table() {
  fac[0] = 1; fac[1] = 1;
  finv[0] = 1; finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; ++i) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

int64 com(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);

  int h, w, a, b; cin >> h >> w >> a >> b;

  make_table();

  int64 ans = 0;

  for (int i = 0; i <= h - a - 1; ++i) {
    ans += com(b - 1 + i, b - 1) * com(w - b - 1 + h - 1 - i, w - b - 1) % MOD;
  }

  cout << ans % MOD << '\n';

  return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  int c;
  c = a * b;
  
  if (c % 2 == 0) {
    cout << "Even" << endl;
  } else {
    cout << "Odd" << endl;
  }
}


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

int main()
{
  int a[3];
  int five=0;
  int seven=0;
  for(int i=0;i<3;i++)
{
cin>>a[i];
    if(a[i]%5==0)
    {
      five++;
    }
    if(a[i]%7==0)
    {
      seven++;
    }
}
 
  if(five==2&&seven==1)
  {
    cout<<"YES"<<endl;
  }
  else 
  {
    cout<<"NO"<<endl;
  }
  return 0;
}

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

int main(){
	int x,y,z,k;
	cin>>x>>y>>z>>k;
	vector<ll> A(x);
	vector<ll> B(y);
	vector<ll> C(z);

	for(int i = 0; i < x; i++) cin>>A[i];
	for(int i = 0; i < y; i++) cin>>B[i];
	for(int i = 0; i < z; i++) cin>>C[i];

	sort(C.rbegin(),C.rend());
	priority_queue<pair<ll,int>> pairs;

	for(int i = 0; i < x; i++){
		for(int j = 0; j < y; j++){
			pairs.push({A[i]+B[j]+C[0],0});
		}
	}

	for(int i = 0; i < k; i++){
		auto top = pairs.top();
		pairs.pop();
		cout<<top.first<<endl;
		if(top.second == z-1){
			continue;
		}
		pairs.push({top.first - C[top.second] + C[top.second+1], top.second+1});
	}
	
}

Measured memory_bytes: 18796
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;

int N,M,S,T;
vector<pair<int, int> > G[100100];

const long long mod = 1000000007;

pair<vector<long long>, vector<long long> > dist(int s)
{
	vector<long long> dist(N,1e18);
	priority_queue<pair<long long, int> > Q;
	Q.push({0,s}); dist[s] = 0;
	while (!Q.empty()){
		int x = Q.top().second; long long c = -Q.top().first; Q.pop();
		if (dist[x] < c) continue;
		for (auto &p : G[x]){
			int y = p.first;
			long long nc = p.second + c;
			if (dist[y] > nc){
				Q.push({-nc,y});
				dist[y] = nc;
			}
		}
	}

	vector<long long> cnt(N);
	cnt[s] = 1;
	vector<pair<long long, int> > st;
	for (int i=0;i<N;i++) st.push_back({dist[i],i});
	sort(st.begin(),st.end());
	for (auto &p : st){
		int x = p.second;
		for (auto &p : G[x]){
			int y = p.first, c = p.second;
			if (dist[y] == dist[x] + c) cnt[y] = (cnt[y] + cnt[x]) % mod;
		}
	}
	return {dist, cnt};
}

int main()
{
	scanf ("%d %d %d %d",&N,&M,&S,&T); S--; T--;
	for (int i=0;i<M;i++){
		int x,y,c; scanf ("%d %d %d",&x,&y,&c); x--; y--;
		G[x].push_back({y,c});
		G[y].push_back({x,c});
	}

	auto p = dist(S);
	auto q = dist(T);

	long long u = p.first[T];
	long long ans = p.second[T]; ans = ans * ans % mod;
	if (u % 2 == 0) for (int i=0;i<N;i++){
		if (p.first[i] == u / 2 && q.first[i] == u / 2){
			long long now = p.second[i] * q.second[i] % mod;
			ans = (ans + mod - now * now % mod) % mod;
		}
	}

	vector<bool> can(N);
	for (int i=0;i<N;i++) if (p.first[i] + q.first[i] == u) can[i] = 1;
	for (int i=0;i<N;i++) if (can[i] && p.first[i] < u/2){
		for (auto &e : G[i]){
			int j = e.first;
			if (can[j] && q.first[j] < u/2 && p.first[i] + e.second + q.first[j] == u){
				long long now = p.second[i] * q.second[j] % mod;
				ans = (ans + mod - now * now % mod) % mod;
			}
		}
	}
	printf ("%lld\n",ans);


	return 0;
}

Measured memory_bytes: 16936
N = int(input())
src = [int(input())-1 for i in range(N)]
ids = [None] * N
for i,a in enumerate(src):
    ids[a] = i

longest = seq = 1
for i1,i2 in zip(ids, ids[1:]):
    if i1 < i2:
        seq += 1
    else:
        longest = max(longest, seq)
        seq = 1
longest = max(longest, seq)
print(N - longest)


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

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

  string Yaki = "YAKI";
  int count = 0;
  for (int i = 0; i < 4; i++) {
    if (Yaki[i] == S[i]) count++;
  }

  if (count == 4) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
s=input()
a=0
if len(s)==1:
    print(a)
else:
    s_t = s[:int(len(s)/2)], s[int(len(s)/2):]
    a += int(s_t[0][:1] != s_t[1][-1:])
    for i in range(1, len(s_t[0])):
        a += int(s_t[0][i:i+1] != s_t[1][-(i+1):-i])
    print(a)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
using namespace std;

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

long long lcm(long long a,long long b){
	long long gcdOfab = gcd(a,b); 
	return a / gcdOfab * b;
}
int main(){
	int N;
	long long result = 1;
	cin >> N;

	for(int i = 0; i < N; i++){
		long long  t;
		cin >> t;
		result = lcm(result,t); 
	}
	cout << result << endl;
	return 0;
}

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

using pii = pair<int, int>;

int main() {
    vector<pii> ans;
    for(int lp = 0; lp < 2; ++lp) {
        int n; cin >> n;
        for(int i = 0; i < n; ++i) {
            int h, m; cin >> h >> m;
            ans.emplace_back(h, m);
        }
    }
    sort(begin(ans), end(ans));
    ans.erase(unique(begin(ans), end(ans)), end(ans));
    const int n = ans.size();
    for(int i = 0; i < n; ++i) {
        if(i != 0) printf(" ");
        printf("%d:%02d", ans[i].first, ans[i].second);
    }
    printf("\n");
}



Measured memory_bytes: 3228
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    while (true) {
      String x = sc.nextLine();
      if (x.equals("0")) {
        break;
      } else {
        int answer = 0;
        for (int i=0;i<x.length();i++)
          answer += Integer.parseInt(String.valueOf(x.charAt(i)));
        System.out.println(answer);
      }

    }
    sc.close();
  }
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

#define gap ' '
#define L(i) ((i) - (&i))
#define mp make_pair
#define debug puts("WHAP")

const int MAXN = 100;
const int MAX = 1e5;
const int mxn = 1e5;
const int MOD = 1e9+7;
const int INF = 1e9;
const int N = 50;

int main(){
	int n; cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; ++i)
		cin >> a[i];
	for(int i = n-1; i > 0; --i){
		if(a[i] < a[i-1])
			a[i-1]--;
	}	
	for(int i = 0; i < n-1; ++i)
		if(a[i] > a[i+1]){
			cout << "No" << "\n";
			return 0;
		}
	cout << "Yes" << "\n";
	return 0;
}


Measured memory_bytes: 3684
/*
{

AuThOr Gwj
*/
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define R(a) cin>>a
#define R2(a,b) cin>>a>>b
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
/*}
*/
int n;
const int MOD=998244353;
LL quick(LL A,LL B){
	if(!B) return 1ll;
	LL rest=quick(A,B>>1);
	rest*=rest;
	rest%=MOD;
	if(B&1){
		rest*=A;
		rest%=MOD;
	}
	return rest;
}
LL inv(LL A){
	return quick(A,MOD-2);
}
const int MAXNUM=1e6+1;
LL v[MAXNUM];
int a[200000+20];
vector<int> have[MAXNUM];
void go_to_check(){
//	rb(i,1,10){
//		LL tmp=0;
//		rb(j,1,i){
//			if(i%j==0){
//				tmp+=v[j];
//				tmp%=MOD; 
//			}
//		}
////		if(tmp!=inv(i)){
////			cout<<"Erro!"<<i<<endl;
////		}
//	}
}
int main(){
	fastio;
	R(n);
	rb(i,1,n)
	{
		R(a[i]);
	}
	rb(i,1,1000000)
		v[i]=inv(i);
	rb(i,1,1000000)
	{
		for(int j=i+i;j<=1000000;j+=i){
			v[j]-=v[i];
			v[j]+=MOD;
			v[j]%=MOD;
		}
	}
	rb(i,1,n){
		for(int j=1;j*j<=a[i];j++){
			if(a[i]%j==0){
					have[j].PB(a[i]);
					if(a[i]!=j*j){
						have[a[i]/j].PB(a[i]); 
					}
			}
		}
	}
	LL rest=0;
	rb(i,1,1000000){
		if(have[i].size()<2) continue;
		LL sum=0;
		LL tmp_rest=0;
//		cout<<i<<":{";
		for(auto it:have[i]){
//			cout<<it<<","; 
			tmp_rest+=sum*it%MOD;
			tmp_rest%=MOD;
			sum+=it;
			sum%=MOD; 
		}
//		cout<<"}\n";
//		cout<<tmp_rest*(v[1]+v[2])%MOD<<endl; 
		tmp_rest*=v[i];
		tmp_rest%=MOD;
//		cout<<tmp_rest<<endl;
		rest+=tmp_rest;
		rest%=MOD;
//		cout<<rest<<endl;
	}
	cout<<rest<<endl;
	return 0;
}

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

int main(void){
  int n,k,ans;
  vector<int> v;
  
  cin >> n >> k;
  for (int i=0; i<n; i++){
    int t; cin >> t;
    v.push_back(t);
  }
  sort(v.begin(), v.end());
  ans = 0;
  for (int i=0; i<k; i++) ans += v[i];
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

/*================================================
	GCD function
================================================*/
int gcd(int a, int b) {
	if (a < b) return gcd(b, a);
	int r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}

int A[100000];

int main()
{
	int N, K, g;
	bool ans = false;

	cin >> N >> K;
	rep(i, N) cin >> A[i];

	sort(A, A + N);

	if (N == 1) {
		if (A[0] == K) ans = true;
		else ans = false;
	}
	else if (A[N - 1] < K) ans = false;
	else {
		rep(i, N - 1) {
			if (i == 0) g = gcd(A[i], A[i + 1]);
			else g = gcd(g, A[i + 1]);
		}

		if ((A[N - 1] - K) % g == 0) ans = true;
		else ans = false;
	}

	cout << (ans ? "POSSIBLE" : "IMPOSSIBLE") << endl;

	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include<math.h>
#include<string>
#include<iomanip>
#include <limits>
using namespace std;

int main()
{
long long a,b,c,d; cin>>a>>b>>c>>d;
if(a*b>c*d)
    cout<<a*b;
else
    cout<<c*d;

}


Measured memory_bytes: 3640
import fractions


def run(t, a, b, c, d):
    ret = []
    for i in range(t):
        ret.append(check(a[i], b[i], c[i], d[i]))
    return ret


def check(a, b, c, d):
    if a < b:
        return 'No'
    if d < b:
        return 'No'
    if c < b:
        g = fractions.gcd(b, d)
        amodb = a % b
        if g == 1:
            if b - 1 > c:
                return 'No'
        elif g == b:
            if amodb > c:
                return 'No'
        else:
            if (b - g) > c:
                return 'No'
    return 'Yes'


def read_line():
    t = int(input())
    a = []
    b = []
    c = []
    d = []
    for i in range(t):
        at, bt, ct, dt = list(map(int, input().split()))
        a.append(at)
        b.append(bt)
        c.append(ct)
        d.append(dt)
    return (t, a, b, c, d)


def main():
    t, a, b, c, d = read_line()
    ret = run(t, a, b, c, d)
    for i in range(t):
        print(ret[i])


if __name__ == '__main__':
    main()


Measured memory_bytes: 5460
#include<iostream>
#include <algorithm>
using namespace std;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;

int main () {
    int n,c=0;
    cin >> n;
    int a[n];
    for (int i=0;i<n;i++) cin >> a[i];
    sort(a,a+n);
    for (int i=0;i<n-2;i++) {
        for (int j=i+1;j<n-1;j++) {
            for (int k=j+1;k<n;k++) {
                if(a[i]!=a[j] && a[j]!=a[k] && a[i]+a[j]>a[k] && a[j]+a[k]>a[i] && a[i]+a[k]>a[j]) {
                    //debug(a[i]); debug(a[j]); debug(a[k]);
                    c++;
                }
            }
        }
    }
    cout<<c;
    return 0;
}

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

#define pb push_back
#define ff first
#define ss second

const long long MAXN = 3e3 + 21, inf = 1e18 + 21, LG = 20;

int n;
double ans;
double p[MAXN], dp[MAXN][MAXN];

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++)
	cin >> p[i];

    dp[1][1] = p[1];
    dp[1][0] = (1 - p[1]);
    
    for (int i = 2; i <= n; i++) {
	for (int j = 1; j <= i; j++)
	    dp[i][j] = dp[i - 1][j] * (1 - p[i]) + dp[i - 1][j - 1] * p[i];
	dp[i][0] = dp[i - 1][0] * (1 - p[i]);
    }

    for (int i = (n + 1) / 2; i <= n; i++)
	ans += dp[n][i];

    cout << fixed << setprecision(10) << ans << '\n';
    return 0;
}


Measured memory_bytes: 69376
N = int(input())
A_list = [int(x) for x in input().split()]
now = 0
for a in A_list:
    now = a - now
ans = [str(now)]
for a in A_list[:-1]:
    now = (a - now//2) * 2
    ans.append(str(now))
print(" ".join(ans))


Measured memory_bytes: 74852
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
		Scanner scan = new Scanner(System.in);

        long X = scan.nextLong();
        int year= 0;
        long money=100;
        while(money<X){
            money= (long) (money*1.01);
            year++;
        }
        System.out.println(year);
    }
}



Measured memory_bytes: 35616
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
	static void Main()
	{
		var s = Console.ReadLine();

		Console.WriteLine("2018" + s.Substring(4));

		//デバッグ実行での確認用。そのまま提出しても問題なし
		Console.ReadKey();
	}
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++) 
#define all(v) begin(v),end(v)
using ll = long long;

int main() {
  int x,n;cin>>x>>n;
  vector<int>p(n),vec(102);
  rep(i,n){
    cin>>p[i];
  vec[p[i]]=1;
  }
  int ans=1e9,a;
  rep(i,102){
    if(vec[i]==0){
      if(abs(x-i)<ans){
        ans=abs(x-i);
        a=i;
      }
    }
  }
  cout<<a<<endl;
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdbool.h>

#define ln "\n"
#define reps(i,a,b) for(int (i)=(a); (i)<(b); ++(i))
#define rep(i,n) for(int (i)=0; (i)<(n); ++(i))
#define repst(i,a,b) for(int (i)=(a); (i)<=(b); ++(i))
#define rept(i,n) for(int (i)=0; (i)<=(n); ++(i))
#define reprt(i,a,b) for(int (i)=(a); (i)>=(b); --(i))
#define repr(i,n) for(int (i)=(n); (i)>=0; --(i))
#define repn(i,a,b,n) for(int (i)=(a); (i)<(b); (i)+=(n))
#define repnt(i,a,b,n) for(int (i)=(a); (i)<=(b); (i)+=(n))
#define PI M_PI

typedef long double ld;
typedef long long ll;

const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;
const double EPS = 1e-9;

/*********TEMPLATE**********/

int main() {

  int i,j,N,A,B,C,X,Y[110];
  while(1) {
    scanf("%d %d %d %d %d",&N, &A, &B, &C, &X);
    //printf("%d %d %d %d %d\n",N,A,B,C,X);
    if (N==0 && A==0 && B==0 && C==0 && X==0) break;
    rep(i,N) scanf("%d", &Y[i]);
    //rep(i,N) printf("%d ", Y[i]);
    //printf(ln);

    // jは現在のリールの位置
    j=0;

    for (i=0; i<10001; i++) {
      // 合致したら、リールを右に
      if (X==Y[j]) {
        j++;
      }

      // 次のXを求める
      X = (A * X + B) % C;

      // すべてのりーるがおわったら
      if (j>=N) break;
    }
    if (i<=10000) printf("%d\n",i);
    else printf("-1\n");
  }

  /*
  0
  3
  255
  -1
  198
  199
  10000
  -1
  */

  return 0;

}



Measured memory_bytes: 2048
#include <iostream>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>
#include <chrono>
#include <ctime>

using namespace std;

#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define MP make_pair
#define PB push_back

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

int main() {
	int x, y, ans = INT_MAX;
	cin >> x >> y;
	rep(i, 4) {
		int X, Y, c;
		switch (i) {
		case 0:
			X = x;
			Y = y;
			c = 0;
			break;
		case 1:
			X = x;
			Y = 0 - y;
			c = 1;
			break;
		case 2:
			X = 0 - x;
			Y = y;
			c = 1;
			break;
		case 3:
			X = 0 - x;
			Y = 0 - y;
			c = 2;
			break;
		}
		if (X <= Y) {
			c += Y - X;
			ans = ans > c ? c : ans;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;using vll = vector<ll>;
int main(){
  ll n, m;
  cin >> n >> m;
  if (n/2019 != m/2019) {
    cout << 0 << endl;
    return 0;
  }
  
  n %= 2019;
  m %= 2019;
  
  ll minx = 1000000000;
  for (ll i = n; i <= m-1; i++) {
    for (ll j = i+1; j <= m; j++) {
      ll x=i*j;
      x %= 2019;
      minx = min(x, minx);
    }
  }
  
  cout << minx << endl;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  int N, A, B, count=1, sum=0;
  cin >> N >> A;
  for (int i=0; i<N-1; i++) {
    cin >> B;
    if (B==A) { 
      ++count;
    }
    else {
      sum+=count/2;
      count=1;
    }
    A=B;
  }
  sum+=count/2;
  cout << sum;
  return 0;
}

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

template <typename T>
class BinaryIndexedTree
{
    vector<T> arr;
    T initial_value;
    long long size;
    function<T(T, T)> operation;

public:
    BinaryIndexedTree(const long long N, function<T(T, T)> func, T init)
    {
        set_size(N);
        set_initial_value(init);
        initialize_array();
        set_operation(func);
    }

    void set_size(const long long N)
    {
        this->size = N + 1;
    }

    void set_initial_value(const T init)
    {
        this->initial_value = init;
    }

    void initialize_array()
    {
        this->arr = vector<T>(size, initial_value);
    }

    void initialize_array(const T init)
    {
        set_initial_value(init);
        initialize_array();
    }

    void set_operation(const function<T(T, T)> func)
    {
        this->operation = func;
    }

    void update(long long idx, T value)
    {
        while (idx <= this->size)
        {
            this->arr[idx] = this->operation(this->arr[idx], value);
            idx += (idx & -idx);
        }
    }

    T query(long long idx)
    {
        T ret = this->initial_value;
        while (idx > 0)
        {
            ret = this->operation(ret, this->arr[idx]);
            idx -= (idx & -idx);
        }
        return ret;
    }
};

int main()
{
    int N;
    string S;
    cin >> N >> S;
    S = " " + S;

    vector<BinaryIndexedTree<int>> bit(
        26,
        BinaryIndexedTree<int>(N + 1, [](int a, int b) { return a + b; }, 0));

    for (int i = 1; i <= N; i++)
    {
        bit[S[i] - 'a'].update(i, 1);
    }

    int Q;
    cin >> Q;
    for (int q = 0; q < Q; q++)
    {
        int t;
        cin >> t;
        if (t == 1)
        {
            int i;
            char c;
            cin >> i >> c;

            bit[S[i] - 'a'].update(i, -1);
            bit[c - 'a'].update(i, 1);
            S[i] = c;
        }
        if (t == 2)
        {
            int l, r;
            int ans = 0;
            cin >> l >> r;
            for (int i = 0; i < 26; i++)
            {
                if (bit[i].query(r) - bit[i].query(l - 1) > 0)
                {
                    ans++;
                }
            }
            cout << ans << endl;
        }
    }
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 1000010
#define rep(i,n) for (int i = 0; i < (n); ++i)
const ll mod = 1e9+7;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int x;
    cin >> x;
    int N = x/100;
    int ans = x - N * 100;
    int l[5] = {5, 4, 3, 2, 1};
    int cnt = 0;
    rep(i, 5) {
        while(1) {
            if (ans - l[i] < 0) break;
            ans -= l[i];
            cnt ++;
        }
    }

    if (ans == 0 and cnt <= N) {
        cout << "1" << endl;
    }else {
        cout << "0" << endl;
    }
    
}



Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)

N, M = map(int, input().split())
adjL = [set() for _ in range(N)]
for _ in range(M):
    A, B = map(int, input().split())
    A, B = A-1, B-1
    adjL[A].add(B)

def getCycle(adjL):
    def dfs(vNow):
        if isAvails[vNow]:
            anss.append(vNow)
            return vNow
        useds[vNow] = True
        isAvails[vNow] = True
        for v2 in adjL[vNow]:
            vRet = dfs(v2)
            if vRet == vNow or vRet == numV:
                return numV
            elif vRet != -1:
                anss.append(vNow)
                return vRet
        isAvails[vNow] = False
        return -1

    numV = len(adjL)
    useds = [False] * numV
    anss = []
    for vSt in range(numV):
        isAvails = [False] * numV
        if useds[vSt]: continue
        vRet = dfs(vSt)
        if vRet == numV:
            return anss[::-1]
    return []

cycle = getCycle(adjL)

if not cycle:
    print(-1)
    sys.exit()

isAvails = [False] * N
v2s = [-1] * N
for i in range(len(cycle)):
    isAvails[cycle[i]] = True
    v2s[cycle[i-1]] = cycle[i]

while True:
    adjL2 = [set() for _ in range(N)]
    a, b = -1, -1
    for v in cycle:
        for v2 in adjL[v]:
            if isAvails[v2]:
                adjL2[v].add(v2)
                if v2s[v] != v2:
                    a, b = v, v2

    if (a, b) == (-1, -1):
        print(len(cycle))
        print('\n'.join(map(lambda x: str(x+1), cycle)))
        break

    adjL = adjL2

    cycle = []
    isAvails = [False] * N
    v2s[a] = b
    v = a
    while not isAvails[v]:
        cycle.append(v)
        isAvails[v] = True
        v = v2s[v]


Measured memory_bytes: 4468