akhauriyash/Code-Regression huggingface dataset:
class SegTree:
    '''Segment Tree:
    Data structure to answer queries on segments of a sequence.
    '''
    def __init__(self,n,init_num,func):
        '''Create a segment tree.
        :param n: Size
        :type n: int or float (number)
        :param init_num: Initialization number
        :type init_num: int or float (number)
        :param func: Function to use
        :type func: function
        '''
        self.func=func
        self.init_num=init_num
        self.size = 2**(len(bin(n-1))-2)*2-1
        self.tree = [init_num for i in range(self.size)]
     
    def data(self):
        '''Return data.
        '''
        return self.tree[self.size//2:]
 
    def update(self,i,x,update_func):
        '''Update the i-th data by update_func.
            example:
            a[i]<-update_func(a[i],x)
        '''
        i=self.size//2+i
        self.tree[i]=update_func(self.tree[i],x)
        while 1:
            i=(i-1)//2
            self.tree[i]=self.func(self.tree[i*2+1],self.tree[i*2+2])
            if i<=0:
                break
 
    def _check(self,s,t,l,r,_p=0):
        if s<=l and r<=t:
            return self.tree[_p]
        elif r<s or t<l:
            return self.init_num
        else:
            return self.func(self._check(s,t,l,l+(r-l)//2,_p*2+1),self._check(s,t,l+(r-l)//2+1,r,_p*2+2))
 
    def find(self,s,t):
        '''Answer queries on [s,t]segment
        '''
        return self._check(s,t,0,self.size//2)

n,q=map(int,input().split())
st=SegTree(n,0,lambda x,y:x+y)
for i in range(q):
    c,x,y=map(int,input().split())
    if c:
        print(st.find(x-1,y-1))
    else:
        st.update(x-1,y,lambda x,y:x+y)



Measured memory_bytes: 10860
from collections import Counter
n = int(input())
V = list(map(int, input().split()))

even = []
odd = []
for i, v in enumerate(V):
	if i % 2 == 0: even.append(v)
	else: odd.append(v)

cnt_even = Counter(even).most_common(2)
cnt_odd = Counter(odd).most_common(2)

if cnt_even[0][0] != cnt_odd[0][0]:
	ans = len(V) - cnt_even[0][1] - cnt_odd[0][1]
else:
	if cnt_even[0][1] + cnt_odd[0][1] == len(V):
		ans = len(V) // 2

	elif len(cnt_odd) < 2 or len(cnt_even) < 2:
		ans = len(V) - cnt_even[0][1] - cnt_odd[0][1]
	else:
		ans1 = len(V) - cnt_even[0][1] - cnt_odd[1][1]
		ans2 = len(V) - cnt_even[1][1] - cnt_odd[0][1]
		ans = min(ans1, ans2)

print(ans)

Measured memory_bytes: 16092
# -*- coding: utf-8 -*-


def main():
    n, a, b = map(int, input().split())
    count = 0

    for i in range(n):
        ti = int(input())

        if a <= ti < b:
            pass
        else:
            count += 1

    print(count)


if __name__ == '__main__':
    main()


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

const int N = 22e5, mod = 1e9 + 7;

int n, a[21][21], dp[N];

signed main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> a[i][j];
		}
	}
	function <int(int, int)> add = [&](int a, int b) {
		return (a % mod + b % mod) % mod;
	};
	dp[0] = 1;
	for (int k = 1; k < 1 << n; k++) {
		int j = __builtin_popcount(k) - 1;
		for (int i = 0; i < n; i++) {
			if (((k >> i) & 1) && a[j][i]) {
				dp[k] = add(dp[k], dp[k ^ (1 << i)]);
			}
		}
	}
	cout << dp[(1 << n) - 1];
}

Measured memory_bytes: 16640
def factorization(n):
    arr = []
    temp = n
    maxVal = 10 ** 13
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            value = (temp//i) + i - 2
            if value < maxVal :
                maxVal = value
            #arr.append([i, n//i])
            #cnt=0
            #while temp%i==0:
            #    cnt+=1
            #    temp //= i
            #    arr.append(i)
            # arr.append([i, cnt])

    #if temp!=1:
    #    arr.append(temp)

    if maxVal == 10 ** 13:
        maxVal = n - 1

    return maxVal

n = int(input())
print(factorization(n))
'''
factList = factorization(n)

max = 10 ** 13
if len(factList) == 1 :
    print(factList[0] - 1)
    exit()
#factList = sorted(factList, reverse=True)
#print(factList)
pair = [1, 1]
#for i in range(len(factList)) :
#    if pair[0] <= pair[1] :
#        pair[0] *= factList[i]
#    else :
#        pair[1] *= factList[i]
#print(pair)
print(factList)
print(pair)
print(sum(pair) - 2)
'''


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

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define INF (1 << 29)
#define LLINF (1LL << 60)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;

string to_string(string s) { return s; }
template <class S>
string to_string(unordered_set<S> s);
template <class S>
string to_string(set<S> s);
template <class S, class T>
string to_string(map<S, T> m);
template <class T>
string to_string(vector<T> v);

template <class S, class T>
string to_string(pair<S, T> p) {
  return "{" + to_string(p.first) + "," + to_string(p.second) + "}";
}

template <class S>
string to_string(unordered_set<S> s) {
  string ret = "{";
  for (S x : s) ret += to_string(x) + ",";
  return ret + "}";
}

template <class S>
string to_string(set<S> s) {
  string ret = "{";
  for (S x : s) ret += to_string(x) + ",";
  return ret + "}";
}

template <class S, class T>
string to_string(map<S, T> m) {
  string ret = "{";
  for (pair<S, T> x : m) ret += to_string(x) + ",";
  return ret + "}";
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < (int)v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() { cerr << endl; }

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() { cout << endl; }

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  ll X, i;
  cin >> X;
  vector<bool> table(2 * X + 1, 1);
  table[0] = 0;
  table[1] = 0;
  for (i = 2; i <= 2 * X; ++i) {
    if (table[i]) {
      if (i >= X) {
        cout << i << endl;
        return 0;
      }
      for (ll j = 2; i * j <= 2 * X; ++j) table[i * j] = 0;
    }
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
 
class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
 
        int [][][] build = new int [4][3][10];
        int tatemon,floo,roo;
 
        for(tatemon = 0; tatemon < 4; tatemon++){
            for(floo = 0; floo < 3; floo++){
                for(roo = 0; roo < 10; roo++){
 
                build [tatemon][floo][roo] = 0;
 
                }
            }
        }
 
        int n = scan.nextInt();
        int tatemono = 0;
        int floor= 0;
        int room = 0;
        int info,person;
        String result;
 
        for(info = 0; info < n; info++){
                    
        tatemono = scan.nextInt();
        floor = scan.nextInt();
        room = scan.nextInt();
        person = scan.nextInt();
        build [tatemono-1][floor-1][room-1] = build [tatemono-1][floor-1][room-1]+person;
        }
         
                
        for(tatemon = 0; tatemon < 4; tatemon++){
            for(floo = 0; floo < 3; floo++){
                for(roo = 0; roo < 10; roo++){ 
                     
                result = " "+build [tatemon][floo][roo];
                     
                switch(tatemono){
                 case 1: 
                System.out.print(result);
                break;       
                 case 2:
                System.out.print(result);
                break;       
                case 3:
                System.out.print(result);
                break;           
                case 4:
                System.out.print(result);
                break;       
                default:    
                } 
                }
                System.out.println();
            }
            if(tatemon < 3){
            System.out.println("####################");
            }
        }
        
    }
}

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

int main(void){
  int n,money=100000;

  cin >> n;
  for( int i = 0 ; i < n ; i++ ){
    money *= 1.05;
    if( money % 1000 != 0 ) money += 1000 - ( money % 1000 );
  }

  cout << money << endl;

  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

int main(){
    char c;
    cin >> c;
    
    if(c >= 'a' && c <= 'z')cout << 'a';
    else cout << 'A';
}

Measured memory_bytes: 3592
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <queue>
#include <utility>

#define MAX_N (100000)

using namespace std;

int main(int argc, char *argv[]) {
  // read inputs
  int N, as[MAX_N];
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &as[i]);
  }

  // put into priority_queue
  priority_queue<pair<int, int>> que;
  sort(as, as + N);
  int a_prev = as[0], a_cnt = 0;
  for (int i = 0; i < N; i++) {
    if (as[i] == a_prev) {
      a_cnt++;
    } else {
      que.push(pair<int, int>(a_cnt, a_prev));
      a_prev = as[i];
      a_cnt = 1;
    }
  }
  que.push(pair<int, int>(a_cnt, a_prev));

  // solve
  while (1) {
    pair<int, int> p1 = que.top();
    que.pop();
    if (p1.first == 1) {  // done if no elements appear more than once
      que.push(p1);       // put back in que
      break;
    } else if (p1.first >= 3) {  // take 3 cards of this value
      p1.first -= 2;
      que.push(p1);
    } else if (p1.first == 2) {
      pair<int, int> p2 = que.top();
      que.pop();
      p1.first--;
      p2.first--;
      que.push(p1);
      if (p2.first > 0) {
        que.push(p2);
      }
    }
  }
  printf("%d\n", (int) que.size());

  return 0;
}


Measured memory_bytes: 1784
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
//ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
int main() {
	ll x, c = 0;
	cin >> x;
	c += x / 11 * 2;
	x %= 11;
	if (x > 0) {
		c++;
		if (c % 2)x -= 6;
		else x -= 5;
		if (x > 0)c++;
	}
	printf("%lld\n", c);
	return 0;
}


Measured memory_bytes: 256
using System;

namespace cs
{
    public class Program
    {
        public static void Main()
        {
            var input = Console.ReadLine().ToCharArray();
            
            for(int i = 0; i < input.Length-1; i++){

                if(input[i] == input[i+1]){
                    Console.WriteLine("Bad");
                    return;
                }

            }
            Console.WriteLine("Good");

        }
    }
}


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

ll gcd(ll x, ll y)
{
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y)
{
  return x / gcd(x, y) * y;
}

int main()
{
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll e = lcm(c, d);
  cout << b - a + 1 - b / c - b / d + (a - 1) / c + (a - 1) / d + b / e - (a - 1) / e << endl;;
  return 0;
}

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

int main() {
    char hun = getchar(), ten = getchar(), one = getchar();
    if (hun < ten) hun++;
    else if (hun == ten) {
        if (hun < one) hun++;
    }
    for (int i=0; i<3; i++) putchar(hun);
    putchar('\n');
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define in insert
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define mod 1000000007
#define sz(v) (int)(v.size())
#define all(x) x.begin(), x.end()
#define prec fixed << setprecision(12)
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define test int t; cin >> t; while(t--)

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef set<int> si;
typedef map<int, int> mii;
typedef vector<pii> vpi;

void solve() {
	int x, y, b;
	cin >> x >> y;
	rep(a, 0, x) {
		b = x - a;
		if ((2 * a + 4 * b) == y) {
			cout << "Yes";
			return;
		}
	}
	cout << "No";
}

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


#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	// test
	solve();

	return 0;
}

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

using namespace std;

int dp[234567];

int main(){
 memset(dp, 100000, sizeof(dp));
 int N; cin >> N;
 int h[N+2];
 for(int i=1; i<=N; ++i) cin >> h[i];
 dp[1] = 0;
 dp[2] = abs(h[2]-h[1]);
 for(int i=3; i<=N; ++i)
   dp[i] = min(dp[i-1]+abs(h[i-1]-h[i]), dp[i-2]+abs(h[i-2]-h[i]));
 cout << dp[N] << "\n";
 return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>
#include<functional>
#include<unordered_set>
#include<unordered_map>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;
const long long ll_max = 9223372036854775807;
const long long ll_min = -9223372036854775807;
const int int_max = 2147483647;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> ret;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			ret[i] ++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

template<typename T>
T modinv(T a, T m) {
	T b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}



// 繰り返し二乗法
ll pow2(ll n, ll p, ll mod) {
	if (p == 0 || n == 1) {
		return 1;
	}
	else {
		ll ret = pow2(n * n % mod, p / 2, mod);
		if (p % 2 == 1) {
			ret *= n;
		}
		return ret % mod;
	}
}


#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)

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

	rep(i, 0, S.size()-2) {
		if (S[i] == S[i + 1]) {
			cout << i + 1 << " " << i + 2 << endl;
			return 0;
		}
		else if (S[i] == S[i + 2]) {
			cout << i + 1 << " " << i + 3 << endl;
			return 0;
		}
	}
	if (S[S.size() - 2] == S[S.size() - 1]) {
		cout << S.size() - 1 << " " << S.size() << endl;
	}
	else {
		cout << -1 << " " << -1 << endl;
	}

	return 0;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define pb push_back
typedef long long ll;
typedef long double la;
using namespace std;

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

int main(){
    int k,count=0,j=2;
    ll sum = 0;
    cin >> k;
    int a=1,b=1,c=1;
    if(k == 1){
        cout << sum+1 << endl;
        return 0;
    }
    while(1){
        sum += gcd(gcd(a,b),c);
        if(c == k){
            if(b == k){
                if(a == k){
                    c = 1;
                }else{
                    a++;
                    b = 1;
                    c = 1;
                }
            }else{
                b++;
                c = 1;
            }
        }else{
            c++;
        }
        if(a == k && b == k && c == k){
            sum += gcd(gcd(a,b),c);
            cout << sum << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
const int M=1e5+4;
typedef long long ll;
vector<int>v;
int a[M],b[M];
ll s1,s2,req,ans=0;
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++) 
	{
		cin>>a[i];
		s1+=a[i];
	}
	for(int i=0;i<n;i++) 
	{
		cin>>b[i];
		s2+=b[i];
		if(a[i]<b[i])
		{
			req+=b[i]-a[i];
			ans++;
		}
		if(a[i]>b[i]) v.push_back(a[i]-b[i]);
	}
	if(s1<s2)
	{
		cout<<"-1";
		return 0;
	}
	sort(v.begin(),v.end());
	reverse(v.begin(),v.end());
	for(auto x:v)
	{
			if(req<=0) break;
			req-=x;
			ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1404
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N = int(readline())

    f = [0] * (N+1)
    for x in range(1,100):
        for y in range(1,100):
            for z in range(1,100):
                tmp = x*x + y*y + z*z + x*y + y*z + z*x
                if tmp <= N:
                    f[tmp] += 1
    
    print("\n".join(map(str, f[1:])))


if __name__ == "__main__":
    main()


Measured memory_bytes: 70044
/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N_MAX = 5002;

const int MOD = 1e9+7;

int pwr (int a, int b)
{
    if(b == 0)
        return 1;
    if(b & 1)
        return 1LL * a * pwr(a, (b ^ 1)) % MOD;
    int aux = pwr(a, (b >> 1));
    return 1LL * aux * aux % MOD;
}

int n;

int p[N_MAX];

vector <int> rev[N_MAX];

bool visited[N_MAX];

int dfsRev (int u)
{
    visited[u] = true;
    int ans = 1;
    for(int v : rev[u])
        ans += dfsRev(v);
    return ans;
}

int cnt[N_MAX];

void dfs (int u)
{
    visited[u] = true;
    if(visited[p[u]] == false)
        dfs(p[u]);
    for(int v : rev[u])
        if(visited[v] == false)
            dfs(v);
}

int cntTrees;

int cntCycles;

int dp[N_MAX][N_MAX];

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];
    for(int i = 1; i <= n; i++)
        if(p[i] != -1)
            rev[p[i]].push_back(i);
    for(int i = 1; i <= n; i++)
        if(p[i] == -1)
        {
            cntTrees++;
            cnt[i] = dfsRev(i);
        }
    for(int i = 1; i <= n; i++)
        if(visited[i] == false)
        {
            cntCycles++;
            dfs(i);
        }
    int ans = 1LL * (cntTrees + cntCycles) * pwr(n - 1, cntTrees) % MOD;
    for(int i = 1; i <= n; i++)
        if(p[i] == -1)
        {
            ans -= 1LL * (n - cnt[i]) * pwr(n - 1, cntTrees - 1) % MOD;
            if(ans < 0)
                ans += MOD;
        }
    dp[0][0] = 1;
    for(int i = 1; i <= n; i++)
        for(int j = 0; j <= cntTrees; j++)
            if(p[i] == -1)
            {
                dp[i][j] = dp[i - 1][j];
                if(j > 0)
                {
                    dp[i][j] += 1LL * dp[i - 1][j - 1] * cnt[i] % MOD;
                    if(dp[i][j] >= MOD)
                        dp[i][j] -= MOD;
                }
            }
            else
                dp[i][j] = dp[i - 1][j];
    int fact = 1;
    for(int j = 2; j <= cntTrees; j++)
    {
        fact = 1LL * fact * (j - 1) % MOD;
        ans += 1LL * dp[n][j] * pwr(n - 1, cntTrees - j) % MOD * fact % MOD;
        if(ans >= MOD)
            ans -= MOD;
    }
    ans = 1LL * n * pwr(n - 1, cntTrees) % MOD - ans;
    if(ans < 0)
        ans += MOD;
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 101456
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	private static int kaizyou(int n) {
		int ans = 1;
		for(int j = n; j >= 2; j--) {
			ans = ans*j;
		}
		return ans;
	}


	public static void main(String[] args) {

	Scanner sca = new Scanner(System.in);
	// 入力
	int n = sca.nextInt();
	int[] p = new int[n];
	int[] q = new int[n];
    List<Integer> list = new ArrayList<>();
    int c = 0;
    int d = 0;

	int[] zyun = new int[n];
	int[] hikaku = new int[n];

	for(int i = 0; i < n; i++) {
		p[i] = sca.nextInt();
	}
	for(int i = 0; i < n; i++) {
		q[i] = sca.nextInt();
	}

	for(int i = 0; i < kaizyou(n); i++) {
		for(int l = 0; l < n; l++) {
	    	list.add(l+1);
	    }
		int a = i;
		int b = 1;
		for(int j = 1; j <= n; j++) {
			zyun[n - j] = a % b;
			a = a/b;
			b++;
		}
		for(int k = 0; k < n; k++) {
			hikaku[k] = list.get(zyun[k]);
			list.remove(zyun[k]);
		}
		for(int loop = 0; loop < n; loop++) {
			if(hikaku[loop] != p[loop]) {
				break;
			}
			if(loop == n-1) {
				c = i;
			}
		}

		for(int loop = 0; loop < n; loop++) {
			if(hikaku[loop] != q[loop]) {
				break;
			}
			if(loop == n-1) {
				d = i;
			}
		}
	}

	if(c > d) {
		System.out.println(c-d);
	}
	else {
		System.out.println(d-c);
	}
	// 後始末
	sca.close();
	}
}

Measured memory_bytes: 23972
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *c) {return to_string((string) c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<class T>
bool chmax(T &a, T b){if(a < b){a = b; return true;} return false;}
template<class T>
bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;}
void print() {
    cout << endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << " ";
    print(forward<Tail>(tail)...);
}

template <class T>
void print(vector<T> &vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << "\n";
    }
    cout << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
    for (auto& vec : df) {
        print(vec);
    }
}

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

    
    ll d; cin >> d;
    vector<ll> c(26);
    for(int i = 0; i < 26; i++) cin >> c[i];
    vector s(d, vector<ll>(26));
    rep(i,0,d)rep(j,0,26){
        cin >> s[i][j];
    }
    vector<ll> ans, last(26);
    rep(i,0,d){
        Pll temp = {-INF, -1};
        ll t;
        rep(j,0,26){
            t = s[i][j] + c[j] * (i - last[j]);
            chmax(temp, {t, j});
        }
        debug(t, temp);
        ans.emplace_back(temp.second + 1);
        last[temp.second] = i+1;
    }

    print(ans);
}

Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (ll i=0; i<(n); ++i)
typedef long long ll;
bool debug=false;
string yes = "Yes";
string no = "No";
ll mod = 1000000007;

int main(){
  ll n,k; cin >> n >> k;
  vector<ll> v(n+1,0);
  rep(i,n){
    cin >> v[i];
  }
  ll ans = 0;
  rep(a,n+1)rep(b,n+1){
    if(a+b>n||a+b>k)continue;
    ll sum=0;
    priority_queue<ll, vector<ll>, greater<ll>> q;
    rep(i,a){
      sum+=v[i];
      if(v[i]<0)q.push(v[i]);
    }
    rep(i,b){
      sum+=v[n-i-1];
      if(v[n-i-1]<0)q.push(v[n-i-1]);
    }
    ll num = max((ll)0, k-a-b);
    rep(i,num){
      if(q.empty()) break;
      ll t = q.top(); q.pop();
      sum-=t;
    }
    ans = max(ans,sum);
  }
  cout << ans;
  return 0;
}

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

int main(){
  int n, h, w;
  cin >> n >> h >> w;
  int a, b, ans = 0;
  for ( int i = 0; i < n; i++ ){
    cin >> a >> b;
    if ( a >= h && b >= w ) ans ++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
candidates = set()


def init() -> None:
    i = 1
    while i ** 2 <= m:
        if m % i == 0:
            candidates.add(i)
            candidates.add(m // i)
        i += 1


def main() -> None:
    init()
    ans = 0
    for candidate in candidates:
        if candidate * n <= m:
            ans = max(ans, candidate)
    print(ans)


if __name__ == "__main__":
    main()


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

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

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (ll)1e18 + 1;

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

    string S, T;
    std::cin >> S >> T;

    auto ans = 0;
    REP(i, 3) {
        if(S[i] == T[i]) {
            ans++;
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


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

const int INF = (int) 1e12; 
int32_t main()
{
	int n,k;
	cin>>n>>k;

	int h[n] , dp[n];
	for(int i=0;i<n;i++){
		cin>>h[i];
		dp[i] = INF;
	}
    
    dp[0] = 0;

    for(int i=1;i<n;i++){
    	for(int j=1;j<k+1;j++){
    		if(i-j >= 0){
    			dp[i] = min(dp[i] , dp[i-j] + abs(h[i] - h[i-j]));
    			// cout<<i<<"-"<<j<<"-"<<dp[i]<<"\n";

    		}
    	}
    }
    // for(int i=0;i<n;i++)
    	// cout<<dp[i]<<" ";
    cout<<dp[n-1];


	return 0;
}        

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

const int mod = 1e9+7;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

const int MAX_N = 2e6+5;
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} c(MAX_N);



int main() {
  int k; cin >> k;
  string s; cin >> s;
  mint ans = 0;
  int n = s.size();

  rep(i,k+1) {
    mint now = mint(25).pow(i);
    now *= mint(26).pow(k-i);
    now *= c(n+i-1, i);
    ans += now;
  }

  cout << ans << endl;
}


Measured memory_bytes: 36568
#include <bits/stdc++.h>
 
#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
 
struct S002 {
  int n;
  S002& operator > (long& x) {
    n = x;
    return *this;
  }
  S002& operator > (long&& x) {
    n = x;
    return *this;
  }
  S002& operator >= (long& x) {
    if( scanf("%ld", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (double& x) {
    if( scanf("%lf", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (std::string& s) {
    if( not (std::cin >> s) ) exit(0);
    return *this;
  }
  template<typename a>
  S002& operator >= (std::vector<a>& v) {
    v.resize(n);
    for(long i = 0; i < n; ++i) {
      *this >= v[i];
    }
    return *this;
  }
  template<typename a, std::size_t s>
  S002& operator >= (std::array<a, s>& x) {
    for(long i = 0; i < (long)s; ++i) {
      *this >= x[i];
    }
    return *this;
  }
};

long nCr(long n, long r) {
  long res = 1;
  for(long i = 1; i <= r; ++i) {
    res = res * (n - i + 1) / i;
  }
  return res;
}

struct S027 {
  long a, b;
  S027(long a_, long b_) : a(a_), b(b_) {}
  double toDouble() {
    return (double) a / b;
  }
};
bool operator == (S027 x, S027 y) {
  return x.a * y.b == x.b * y.a;
}
bool operator < (S027 x, S027 y) {
  return x.a * y.b < x.b * y.a;
}

struct Solver {
  long n, a, b;
  std::vector<long> xs;
  Solver() {
    S002 reader;
    reader >= n >= a >= b >n>= xs;
  }
  void solve() {
    std::sort(xs.begin(), xs.end());
    std::reverse(xs.begin(), xs.end());
    S027 best(0, 1);
    std::vector<long> bests;
    for(long x = a; x <= b; ++x) {
      long sum = std::accumulate(xs.begin(), xs.begin() + x, (long)0);
      S027 temp(sum, x);
      if( best == temp ) {
        bests.push_back(x);
      }
      else if( best < temp ) {
        bests.clear();
        bests.push_back(x);
        best = temp;
      }
    }
    long res = 0;
    for(long bestN : bests) {
      long r = 0;
      for(long i = 0; i < bestN; ++i) {
        if( xs[i] == xs[bestN - 1] ) r += 1;
      }
      long nn = 0;
      for(long x : xs) {
        if( x == xs[bestN - 1] ) nn += 1;
      }
      res += nCr(nn, r);
    }
    printf("%.20lf\n", best.toDouble());
    printf("%ld\n", res);
  }
};
 
int main() {
  loop std::unique_ptr<Solver>(new Solver())->solve();
  return 0;
}

Measured memory_bytes: 256
//naveen mall
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb               push_back
#define sz(c)            (int)c.size()
#define len(c)           (int)c.length()
#define vec              vector
#define int              long long int
#define all(c)           c.begin(), c.end()
#define rall(c)          c.rbegin(), c.rend()
#define trav(a,i)        for(auto& i: a)
#define fl(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define rfl(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define invect(v,n)       for(int i=0;i<n;i++ ){int arb;cin>>arb;v.pb(arb);}
#define inset(s,n)        forloop(n){int aset;cin>>aset;s.insert(aset);}
#define display(c)        trav(c,i) cout<<i<<" ";cout<<"\n";
#define F                 first
#define S                 second
#define pii               pair<int,int>
#define PB                pop_back
#define endl              "\n"
#define copy(a,b)         copy(all(a),back_inserter(b));
#define section(a,b,w)    set_intersection(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define union(a,b,w)      set_union(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define diff(a,b,w)       set_difference(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define symdiff(a,b,w)    set_symmetric_difference(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));








void dfs(int n,vec<int>v[],bool mark[],int dp[])
 {
   mark[n]=true;
   for(int i=0;i<sz(v[n]);i++)
      {

         if(mark[v[n][i]]==false)
            dfs(v[n][i],v,mark,dp);
        dp[n]=max(dp[n],1+dp[v[n][i]]);


      }





 }







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

vec<int> v[n+1];
for(int i=0;i<m;i++)
   {
     
    int x,y;
    cin>>x>>y;
    //cout<<x<<" "<<y<<endl;
    v[x].pb(y);


   }
// for(int i=1;i<=n;i++)
//        {
//         for(int j=0;j<sz(v[i]);j++)
//               cout<<v[i][j]<<" ";
//             cout<<endl;
//        }

   int dp[n+1];
   memset(dp,0,sizeof(dp));
   bool mark[n+1];
   memset(mark,false,sizeof(mark));

   for(int i=1;i<=n;i++)
      {  if(mark[i]==false)
        {
          dfs(i,v,mark,dp);



        }


    }
    int ans=*max_element(dp,dp+n+1);
    cout<<ans;








  }

signed main()
{fast
    int t;t=1;
   // cin>>t;
    while(t--)

     {
        solve();
     }    
}












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

typedef pair<long long, long long> data_t;

int main(){
  int n,m;
  cin>>n>>m;
  vector<long long> a(n),b(n),c(m),d(m);
  for(int i=0;i<n;i++)
    cin>>a[i]>>b[i];
  for(int i=0;i<m;i++)
    cin>>c[i]>>d[i];
  for(int i=0;i<n;i++){
    long long mindis=abs(a[i]-c[0])+abs(b[i]-d[0]);
    int minnum=0;
    for(int j=0;j<m;j++){
      long long dis=abs(a[i]-c[j])+abs(b[i]-d[j]);
      if(mindis>dis){
        mindis=dis;
        minnum=j;
      }
    }
    cout<<minnum+1<<endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int dp[100001];
ll minCost(int arr[], int n, int k){
	//base condition
	if(n==1) return 0;
	if(n<1) return INT_MAX;
	if(dp[n]!=-1) return dp[n];
	//choice code
	ll mini = INT_MAX;
	for(int i=1; i<=k; i++){
		ll temp = minCost(arr, n-i, k) + (ll)abs(arr[n-1]-arr[n-1-i]);
		mini = min(temp, mini);
	}
	return dp[n] = mini;
}

int main(){
	memset(dp, -1 ,sizeof(dp));
	int n,k; cin>>n>>k;
	int arr[n];
	for(int i=0;i<n;i++) cin>>arr[i];
	ll ans = minCost(arr, n, k);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 8832
#include <bits/stdc++.h>
using namespace std;
#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 fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)
template<class T> bool chmax(T &a,  T b) {if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a,  T b) {if(a>b){a=b; return 1;} return 0;}
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

const int w_max = 100004;

signed main(){
    int n;
    int w;
    cin >> n >> w;
    int weight[n],value[n];
    REP(i,n) cin >> weight[i] >> value[i];

    int dp[2][w_max];

    REP(i,2) REP(j,w_max) dp[i][j] = 0;

    REP(i,n){
        REP(j,w + 1){
            dp[ (i + 1) %2][j] = dp[i %2][j];
            if( j - weight[i] < 0) continue;
            chmax(dp[(i+1) %2][j],dp[i%2][j-weight[i]] + value[i]);
        }
    } 

    cout << dp[n %2][w] << endl;

}

Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
using namespace std;
int main(){
    int H1,H2,M1,M2,K;

    cin >> H1 >> M1 >> H2 >> M2 >> K;

    int time1,time2,time3;
    time1 = (H2 - H1)*60;
    time2 = M2 - M1;


    time3 = time1+time2;

    if(K >= time3)
    {
        cout << 0 << endl;
    }
    else if(K < time3)
    {
        cout << time3 - K << endl;
    }


    
    
    return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>

int main(void) {
	char moziretu[10010];
	int i;
	int joi,ioi;
	while(scanf("%s",moziretu)==1) {
		joi=ioi=0;
		for(i=1;moziretu[i+1];i++) {
			if(moziretu[i]=='O' && moziretu[i+1]=='I') {
				if(moziretu[i-1]=='J')joi++;
				if(moziretu[i-1]=='I')ioi++;
			}
		}
		printf("%d\n",joi);
		printf("%d\n",ioi);
	}
	return 0;
}

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 2005;

/* ...o(^-^)o... */

lint dp[MAX][MAX];

int main(){
    int n; cin >> n;
    vector<P> a(n);
    rep(i, n){
        lint b; cin >> b; a[i] = P(b, i);
    }
    sort(all(a), greater<P>());

    rep(i, n+1) rep(j, n+1){
        if(i + j > n) continue;
        if(i + j == 0){
            dp[i][j] = 0; continue;
        }
        if(i == 0){
            dp[i][j] = dp[i][j-1] + a[i+j-1].fi * abs(n-j-a[i+j-1].se);
            continue;
        }
        if(j == 0){
            dp[i][j] = dp[i-1][j] + a[i+j-1].fi * abs(a[i+j-1].se-i+1);
            continue;            
        }
        dp[i][j] = max(dp[i][j-1] + a[i+j-1].fi * abs(n-j-a[i+j-1].se),
                        dp[i-1][j] + a[i+j-1].fi * abs(a[i+j-1].se-i+1));
    }

    lint ans = 0;
    rep(i, n+1){
        ans = max(ans, dp[i][n-i]);
    }

    out(ans);
}

Measured memory_bytes: 26312
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    string S;
    cin >> S;
    
    cout << S.substr( 0, S.length()-8 ) << endl;
    
    
    return 0;
}

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

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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

const ll MOD = 1e9 + 7;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }

int main() {
   int N;
   cin >> N;
   ll A, B;
   vector<ipair> y;
   for (int i = 0; i < N; i++) {
      cin >> A >> B;
      y.push_back(ipair(A, B));
   }
   sort(y.begin(), y.end(), lessPair);

   ll cnt = 0;
   for (auto it = y.begin(); it != y.end(); ++it) {
      // cout << cnt << endl;
      // cout << it->first << " " << it->second << endl;
      if (cnt + it->first <= it->second) {
         cnt += it->first;
      } else {
         cout << "No" << endl;
         return 0;
      }
   }
   cout << "Yes" << endl;
   return 0;
}


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

//関数


    
    
    
//main関数
int main() {
    
    
    //入力
    long x,y;
    cin>>x>>y;
    
    //計算
    long ans=1;
    
    if(abs(y)>abs(x)){
        ans=abs(y)-abs(x);
        if(x<0){
            ans++;
        }
        if(y<0){
            ans++;
        }
    }else if(abs(y)<abs(x)){
        ans=abs(x)-abs(y);
        if(x>0){
            ans++;
        }
        if(y>0){
            ans++;
        }
    }
    
    //出力
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define RI(x) x = rit()
#define RII(a,b) a = rit(), b = rit()
#define RIII(a,b,c) a = rit(), b = rit(), c = rit()
#define REP(I, N) for(int I=0;I<int(N);I++)
#define REPP(I, N) for(int I=1;I<=int(N);I++)
#define ll long long
#define SZ(x) (int)(x).size()
#define F first
#define S second
#define PB(x) push_back(x)
inline int rit(){
    int f=0,key=1;
    char ch;
    do{
        ch = getchar();
        if(ch=='-') key=-1;;
    }while(ch<'0'||ch>'9');
    do{
        f = f*10+ch-'0';
        ch = getchar();
    }while(ch>='0'&&ch<='9');
    return f*key;
}
using namespace std;
typedef pair<int,int> P;
int r,c,n;
int num[4];
struct st{
	int x,y,idx,dis;
}pt[200005];
map<int,int> mp;
stack<int> stk;
int get_Dis(int x, int y){
	if(!y) return x;
	if(x==c) return c+y;
	if(y==r) return c+r+(c-x);
	return 2*(c+r)-y;
}
int main(void){
	RIII(r,c,n);
	int cur=0;
	for(int i=0;i<n;++i){
		for(int j=0;j<4;++j) RI(num[j]);
		if( (num[0]==0||num[0]==r||num[1]==0||num[1]==c)&&
			(num[2]==0||num[2]==r||num[3]==0||num[3]==c) ){
				mp[cur] = cur+1;
				mp[cur+1] = cur;
				pt[cur].x = num[1];
				pt[cur].y = r-num[0];
				pt[cur].dis = get_Dis(pt[cur].x, pt[cur].y);
				pt[cur].idx = cur++;
				pt[cur].x = num[3];
				pt[cur].y = r-num[2];
				pt[cur].dis = get_Dis(pt[cur].x,pt[cur].y);
				pt[cur].idx = cur++;
			}
	}
	sort(pt, pt+cur,[](st &a, st &b){
		return a.dis < b.dis;
	});
	stk.push(pt[0].idx);
	for(int i=1;i<cur;++i){
		if( !stk.empty()&&mp[pt[i].idx]==stk.top() ) stk.pop();
		else stk.push(pt[i].idx);
	}
	printf("%s\n",stk.empty()?"YES":"NO");
}


Measured memory_bytes: 12928
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    s = S()
    print('A' + s[8] + 'C')

main()



Measured memory_bytes: 83588
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
    cin>>s;
    int size=s.size();
    for(int i=0;i<size;i++){
        if(s[i]=='A'){
            s.erase(s.begin(),s.begin()+i);
            break;
        }
    }
    for(int j=0;j<size;j++){
        if(s[s.size()-1-j]=='Z'){
            s.erase(s.begin()+s.size()-j,s.end());
            break;
        }
    }
    cout<<s.size()<<endl;
    return 0;
}

Measured memory_bytes: 640
n =int(input())
book = []
for i in range(1,n+1):
      s,p = input().split()
      p = int(p)
      book.append((i,s,p))

book.sort(key=lambda x:x[2],reverse=True)
book.sort(key=lambda x:x[1])

for i in range(n):
      print(book[i][0])

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
using namespace std;
char data[8][9];
void solve(int x,int y){
  for(int i=1;i<=3;i++){
    if(x-i>=0&&data[x-i][y]=='1'){
      data[x-i][y]='0';
      solve(x-i,y);
    }
    if(y-i>=0&&data[x][y-i]=='1'){
      data[x][y-i]='0';
      solve(x,y-i);
    }
    if(x+i<8&&data[x+i][y]=='1'){
      data[x+i][y]='0';
      solve(x+i,y);
    }
    if(y+i<8&&data[x][y+i]=='1'){
      data[x][y+i]='0';
      solve(x,y+i);
    }
  }
  return;
}
int main(void){
  int n,x,y;
  scanf("%d",&n);
  for(int i=1;i<=n;i++){
    for(int j=0;j<8;j++){
      scanf("%s",data[j]);
    }
    scanf("%d %d",&y,&x);
    if(data[x-1][y-1]=='1'){
      data[x-1][y-1]='0';
      solve(x-1,y-1);
    }
    printf("Data %d:\n",i);
    for(int j=0;j<8;j++){
      printf("%s\n",data[j]);
    }
  }
  return 0;
}

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

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

    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    if(n == 2){
        cout << a[1] - a[0] << endl;
        cout << a[1] << " " << a[0] << endl;
        return 0;
    }

    vector<pair<int,int>> operation;
    int ans = a[0];

    if(a[n-2] < 0){
        ans = a[n-1];
        for(int i=n-2; i>=0; i--){
            operation.push_back({ans, a[i]});
            ans = ans - a[i];
        }
    }
    else{
        bool flip = false;
        for(int i=n-2; i>=1; i--){
            if(flip == false && (a[i-1] <= 0 || i == 1)){
                operation.push_back({ans, a[i]});
                ans = ans - a[i];
                operation.push_back({a[n-1], ans});
                ans = a[n-1] - ans;
                flip = true;
            }
            else{
                operation.push_back({ans, a[i]}); 
                ans = ans - a[i];
            }
        }
    }
    cout << ans << endl;
    for(auto op : operation) cout << op.first << " " << op.second << endl;
    return 0;
}

Measured memory_bytes: 4556
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int N,x;
  cin >> N >> x;
  vector<int> vec(N);
  rep(i,N){
    cin >> vec[i];
  }
  sort(vec.begin(),vec.end());
  int count=0,sum=0;
  rep(i,N){
    sum+=vec[i];
    if(i==N-1 && sum<x){count=N-1;break;}
    if(sum>x){count=i;break;}
    if(sum==x){count=i+1;break;}
  }
  cout << count << endl;
}




Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
const int maxn=100007;
using namespace std;
int n,l[maxn],r[maxn];
long long ans;
bool cmp(int x,int y){
    return x > y;
}
int main(){
    ios::sync_with_stdio(false);
    cin>>n;
    for (int i=1; i<=n; i++) cin >> l[i] >> r[i];
    sort(l,l+n+1,cmp);
    sort(r,r+n+1);
    for (int i=0; i<=n; i++) {
        if (l[i]-r[i]<=0) break;
        ans+=2*(l[i]-r[i]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(){
    int a, b;
    scanf("%d %d", &a,&b);
    int x = a+b;
    int y = a-b;
    int z = a*b;
    if(x >= y && x >=z)
        printf("%d\n", x);
    else if(y >= x & y >= z)
        printf("%d\n", y);
    else if(z>= x && z >= y)
        printf("%d\n", z);

}


Measured memory_bytes: 128