akhauriyash/Code-Regression huggingface dataset:
import sys
from collections import defaultdict, deque, Counter
import math

# import copy
from bisect import bisect_left, bisect_right
# import heapq

# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def era(n):
    ret = [1 for i in range(n + 2)]
    for i in range(2, int(math.sqrt(n) +3)):
        if ret[i] != 0:
            for j in range(2, n//i + 1):
                ret[i * j] = 0
    rret = []
    for i, r in enumerate(ret):
        if r == 1 and i != 0:
            rret.append(i)

    return rret


def houjyo(n, m, k, kaijyo):
    # kaburi ... k
    # all ... n
    if k == n:
        return 1
    else:
        # kasanarierabi nck * nokorierabi (m - k)p(n-k) - houjyo(+1)
        ret = nck(n,k,kaijyo) * npk(m-k, n-k, kaijyo) # - (k + 1) * houjyo(n, m, k+1, kaijyo)
        # print(nck(n,k,kaijyo) , npk(m-k, n-k, kaijyo))
        return ret % MOD


def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD


def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD


def kaijyo(n):
    ret = [1]
    for i in range(1, n + 1):
        ret.append((ret[-1] * i)% MOD)
    return ret


def solve():
    n, m = getList()
    kukan = []
    for i in range(m):
        a, b = getList()
        kukan.append((a, b))

    kukan.sort(key=lambda x: x[1])
    # for ku in kukan:
    #     print(ku)
    kiru = 0
    ans = 0
    for ku in kukan:
        a, b = ku
        if a >= kiru:
            ans += 1
            kiru = b

    print(ans)

def main():
    n = getN()
    for _ in range(n):
        solve()


if __name__ == "__main__":
    # main()
    solve()

Measured memory_bytes: 84864
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

count = 0
for i in range(N-1,-1,-1):
  n = min(A[i+1],B[i])
  A[i+1] -= n
  B[i] -= n
  count += n
  m = min(A[i],B[i])
  A[i] -= m
  B[i] -= m
  count += m

print(count)

Measured memory_bytes: 24128
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <chrono>
#include <bitset>
#include <map>
#include <queue>
#include <algorithm>
#include <vector>
#include <set>
#include <cstdlib>
using namespace std;


map<int,int> ans;
int main(void){
	int N;
	cin >> N;
	for(int i = 1; i <= 100; i++){
		for(int j = 1; j <= 100; j++){
			for(int k = 1; k <= 100; k++){
				int v = pow(i,2) + pow(j,2) + pow(k,2) + (i*j) + (j*k) + (i*k);
				if(v <=  10000){
					ans[v]++;
				}
			}
		}
	}

	for(int i = 1; i <= N; i++){
		cout << ans[i] << endl;
	}
}


Measured memory_bytes: 4048
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	N = inputInt()
	S = input()
	S = S[:-1]

	tmp = S.split("ABC")
	ans = len(tmp)

	print(ans-1)


if __name__ == "__main__":
	main()


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


int main(void){
    // Your code here!
    int n,m;
    cin>>n>>m;
    
    vector<int> H(n);
    //int a,b;
    //vector<int> s(n);
    vector<int> ans(n,1);
    
    vector<int> A(m);
    vector<int> B(m);
    
    
    for(int i=0;i<n;i++) cin>>H[i];
    
    for(int i=0;i<m;i++){
      cin>>A[i]>>B[i];
      
      if(H[A[i]-1] <= H[B[i]-1]) ans[A[i]-1]= 0;
      if(H[B[i]-1] <= H[A[i]-1]) ans[B[i]-1] = 0;
      
    }
    
    int ct=0;
    
    for(int i=0;i<n;i++) if(ans[i]==1) ct++;
    //for(int i=0;i<n;i++) if(s[i]==0) ct++; 
    cout<<ct<<endl;
    
}


Measured memory_bytes: 4848
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
const int MAX = 2200;
const int MOD = 1e9+7;
template<int mod> struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; }
    ModInt &operator-=(const ModInt &p) { if((x += mod-p.x) >= mod) x -= mod; return *this; }
    ModInt &operator*=(const ModInt &p) { x = (int)(1LL*x*p.x%mod); return *this; }
    ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; }
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const{
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) { t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); }
        return ModInt(u);
    }
    ModInt pow(int e){
        long long a = 1, p = x;
        while(e > 0) {
            if(e%2 == 0) {p = (p*p) % mod; e /= 2;}
            else {a = (a*p) % mod; e--;}
        }
        return ModInt(a);
    }
    friend ostream &operator<<(ostream &os, const ModInt<mod> &p) {
        return os << p.x;
    }
    friend istream &operator>>(istream &is, ModInt<mod> &a) {
        long long x;
        is >> x;
        a = ModInt<mod>(x);
        return (is);
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> s(n), t(m);
    for (int i = 0; i < n; i++) cin >> s[i];
    for (int j = 0; j < m; j++) cin >> t[j];
    
    ModInt<MOD> dp[MAX][MAX];
    for (int i = 0; i < MAX; i++) {
        dp[i][0] = 1;
        dp[0][i] = 1;
    }
    
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            dp[i+1][j+1] = dp[i+1][j] + dp[i][j+1] - dp[i][j];
            if (s[i] == t[j]) dp[i+1][j+1] += dp[i][j];
        }
    }
    
    cout << dp[n][m] << endl;
    return 0;
}

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

int main() {
    string s;
    cin >> s;
    long long ans = 0;
    long long tmp; // +で分割したものを入れる
    for(int bit=0; bit < (1 << (s.size() -1)); bit++){
        tmp = s[0] - '0';
        for(int i=0;i<(s.size()-1);i++){
            if (bit & (1 << i)){
                ans += tmp;
                tmp = 0;
            }
            tmp = tmp*10 + (s[i+1] - '0');
        }
        ans += tmp;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

typedef long long ll;

const int MAX = 100;
int data[100];
int n,k;

ll getmax(){
  ll now = 1;
  for(int i = 0; i < k; i++) now *= data[i];
  ll out = now;
  for(int i = k; i < n; i++){
    now /= data[i-k];
    now *= data[i];
    out = max(now,out);
  }
  return out;
}

int main(){
  while(cin >> n >> k && n+k){
    ll c[2] = {0,0};
    for(int i = 0; i < n; i++) cin >> data[i];
    c[0] = getmax();
    
    for(int i = 0; i < n-1; i++){
      for(int j = i+1; j < n; j++){
	swap(data[i],data[j]);
	c[1] = max(c[1],getmax());
	swap(data[i],data[j]);
      }
    }
    if(c[1] - c[0] < 0) cout << "NO GAME" << endl;
    else cout << c[1] - c[0] << endl;
  }
  return 0;
}

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

int n, m;
int p[100000];
int a[100000], b[100000], c[100000];

int t[100000];

int main()
{
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++){
		scanf("%d", &p[i]);
		p[i]--;
	}
	for (int i = 0; i < n - 1; i++){
		scanf("%d %d %d", &a[i], &b[i], &c[i]);
	}
	
	
	for (int i = 0; i < m - 1; i++){
		int fr = min(p[i], p[i + 1]);
		int to = max(p[i], p[i + 1]);
		t[fr]++;
		t[to]--;
	}
	
	for (int i = 0; i < n - 1; i++){
		t[i + 1] += t[i];
	}
	
	long long res = 0;
	for (int i = 0; i < n; i++){
		long long A = (long long)a[i] * t[i];
		long long B = (long long)b[i] * t[i] + c[i];
		res += min(A, B);
	}
	
	printf("%lld\n", res);
	
	return 0;
}

Measured memory_bytes: 3140
#include<bits/stdc++.h>
using namespace std;
int L[2002][2002],R[2002][2002],U[2002][2002],D[2002][2002];
char s[2000][2000];

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int h,w; cin>>h>>w;
	for(int i=0;i<h;++i){
		for(int j=0;j<w;++j){
			cin>>s[i][j];
		}
	}
	for(int i=1;i<h+1;++i){
		for(int j=1;j<w+1;++j){
			if(s[i-1][j-1]=='.'){
				L[i][j]=L[i][j-1]+1;
				U[i][j]=U[i-1][j]+1;
			}
			if(s[h-i][w-j]=='.'){
				R[h+1-i][w+1-j]=R[h+1-i][w+2-j]+1;
				D[h+1-i][w+1-j]=D[h+2-i][w+1-j]+1;
			}
		}
	}
	int ans=0;
	for(int i=1;i<h+1;++i){
		for(int j=1;j<w+1;++j){
			ans=max(ans,L[i][j]+R[i][j]+U[i][j]+D[i][j]-3);
		}
	}
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 66816
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

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

template <class T1, class T2>
istream& operator >> (istream& in, pair<T1, T2> &p)
{
	in >> p.first >> p.second;
	return in;
}

template <class T>
istream& operator >> (istream& in, vector<T> &v)
{
	for (T &x : v)
		in >> x;
	return in;
}

template <class T>
ostream& operator << (ostream& out, const vector<vector<T>> &v)
{
	for (const vector<T> &x : v)
		out << x << '\n';
	return out;
}

template <class T>
ostream& operator << (ostream& out, const vector<T> &v)
{
	for (const T &x : v)
		out << x << ' ';
	return out;
}

long long gcd (long long a, long long b)
{
	if (b > a)
		swap(a, b);
	return (b ? gcd(b, a % b) : a);
}

using ll   = long long;
using pii  = pair<int, int>;
using pll  = pair<long long, long long>;
using tiii = pair<pair<int, int>, int>;
using vi   = vector<int>;
using vl   = vector<long long>;
using vvi  = vector<vector<int>>;
using vvl  = vector<vector<long long>>;

#define F          first
#define S          second
#define First      first.first
#define Second     first.second
#define Third      second
#define mp         make_pair
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define per(i,b,a) for (int i = (b); i > (a); i--)
#define all(x)     x.begin(), x.end()
#define ret(x)     return cout << x, 0;
#define throwex    throw runtime_error ("Found the error.");

const int h = 1000000007;

int n;
vvi M;
vi a;
vi d;
vi ans;
vi vis;

void dfs(int x)
{
	vis[x] = 1;
	d.push_back(INT_MAX);
	
	int j = upper_bound(all(d), a[x]) - d.begin();
	pii change;
	if(d[j-1] < a[x] and a[x] < d[j])
	{
		change = {j, d[j]};
		d[j] = a[x];
	}

	int f = upper_bound(d.rbegin(), d.rend(), INT_MAX, greater<int>()) - d.rbegin();
	ans[x] = d.size() - 1 - f;

	for(int y : M[x])
		if(!vis[y])
			dfs(y);

	d[change.F] = change.S;
	d.pop_back();
}

signed main()
{
	ios::sync_with_stdio(false);
	#ifdef ONLINE_JUDGE
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.setstate(ios::failbit);
	#endif

	cin >> n;
	a.resize(n);
	cin >> a;
	M.resize(n);
	rep(i,0,n-1)
	{
		int x, y;
		cin >> x >> y;
		x--, y--;
		M[x].push_back(y);
		M[y].push_back(x);
	}
	vis.resize(n);
	ans.resize(n);
	d.push_back(INT_MIN);
	dfs(0);
	for(int x : ans)
		cout << x << '\n';
}


Measured memory_bytes: 28852
import java.io.*;
import java.math.*;
import java.util.*;





public class Main {

    static MyScanner in = new MyScanner();
    static   PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
     static long mod = 1000*1000*1000+7;
    static int max = 200001;
    static int [] dr = {1,-1,0,0};
    static int [] dc={0,0,-1,1};
    static boolean [][] grid;
    static int [] bishopr = {-1,1,-1,1};
    static int [] bishopc = {1,1,-1,-1};
    static long H,W,cnt;
    public static void main(String args[]) throws IOException {
           int N = in.nextInt();
           long ans = pow(10, N)-pow(9, N)-pow(9, N)+pow(8, N);
           while(ans<mod)
            ans+=mod;
            ans%=mod;
            out.println(ans);


        out.flush();
        }
       static boolean isValid (int r, int c){
           if(r>=0&&r<H&&c>=0&&c<W){
               return true;
           }
           return false;
       }
    static    int gcd (int a, int b) {
   return b!=0 ? gcd (b, a % b) : a;
}
        private static void dfs(int r, int c) {
            for(int i=0;i<4;i++){
                int nr = bishopr[i] +r;
                int nc = bishopc[i]+c;
                if(isValid(nr, nc)&&!grid[nr][nc]){
                    cnt++;
                    grid[nr][nc] = true;
                    dfs(nr, nc);
                }
            }
        }

        static boolean isEven(long a) {
            return (a&1)==0;
        }
       static  void swap (int a, int b){

        int temmp = b;
        b=a;
        a = temmp;
        }
        public static long pow(int a,int b){
        long ans=1;
        for(int i=0;i<b;i++){
            ans*=a;
            ans%=mod;
        }
        return ans;
    }
    

    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
   
        public MyScanner() {
           br = new BufferedReader(new InputStreamReader(System.in));
        }
   
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
   
        int nextInt() {
            return Integer.parseInt(next());
        }
   
        long nextLong() {
            return Long.parseLong(next());
        }
   
        double nextDouble() {
            return Double.parseDouble(next());
        }
   
        String nextLine(){
            String str = "";
        try {
           str = br.readLine();
        } catch (IOException e) {
           e.printStackTrace();
        }
        return str;
        }
  
     }
}

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

int main() {
    int n; cin >> n;
    using Item = tuple<int, int, char, long long, string>;
    vector<Item> vec;
    while (n--) {
        int v, w; char t; long long d; string s;
        cin >> v >> w >> t >> d >> s;
        vec.emplace_back(v, w, t, d, s);
    }
    sort(vec.begin(), vec.end());
    for (auto e: vec) {
        int v, w; char t; long long d; string s;
        tie(v, w, t, d, s) = e;
        cout << v << " " << w << " " << t << " " << d << " " << s << endl;
    }
    return 0;
}


Measured memory_bytes: 12292
import static java.util.Arrays.*;

import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

	static void tr(Object... os) {
		System.err.println(deepToString(os));
	}

	void solve() {
		String[] words = sc.nextLine().split("[ ,\\.]");
		boolean first = true;
		for (int i = 0; i < words.length; i++) {
			if (3 <= words[i].length() && words[i].length() <= 6) {
				if (first) { first = false; } else out.print(" ");
				out.print(words[i]);
			}
		}
		out.println();

	}

	public static void main(String[] args) throws Exception {
		new Main().run();
	}

	Scanner sc = null;
	PrintWriter out = null;
	public void run() throws Exception {
		sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
		for (;sc.hasNext();) {
			solve();
			out.flush();
		}
		out.close();
	}

}

Measured memory_bytes: 17356
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
int main()
{
    int n = 0;
    int i;
    char buf[2*1000000];
    char buf2[2*1000000];
 
    fgets(buf, sizeof(buf),stdin);
    fgets(buf2, sizeof(buf2),stdin);
 
 
	i = 0;
	while(buf[i] != '\0'){
		n++;
		i++;
	}
 
int count = n;
    for (i=0; i<count;i++){
        if(buf[i]==buf2[i]){
            n--;
        }
    }
    printf("%d\n", n);
 
}

Measured memory_bytes: 1972
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	int row = 0;
	int a,b;
	for(int i = 0; i < n ; i++){
		cin>>a>>b;
		if(row ==3)break;
		if(a == b)row++;
		else row = 0;
	}
	if(row==3){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
	
	return 0;
}

Measured memory_bytes: 3688
using System;

	class MainClass
	{
		public static void Main (string[] args)
	{
		while (true) {
			string str = Console.ReadLine ();
			string[] spStr = str.Split (' ');

			int a = int.Parse (spStr [0]);
			int b = int.Parse (spStr [1]);

			if (a == 0 && b == 0) {break;}

			for (int i = 0; i < a; i++) {
				for (int j = 0; j < b; j++) {
					if (i == 0 || i == a - 1 || j == 0 || j == b - 1) {
						Console.Write ("#");
					} else {
						Console.Write (".");
					}
				}
				Console.WriteLine ("");
			}
			Console.WriteLine ("");
		}
	}
}

Measured memory_bytes: 8844
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

int x[100005];
int sums[100005];

const int MAX = 100000;

bool is2017(int i){
    return (x[i] == 2 && x[(i+2)/2] == 2);
}

int main(){
    for(int i = 1; i <= MAX; i++){
        for(int j = i; j <= MAX; j+=i){
            x[j]++;
        }
    }

    for(int i = 3; i <= MAX; i+=2){
        if (is2017(i)) sums[i] = sums[i-2] + 1;
        else sums[i] = sums[i-2];
    }

    int q;
    cin >> q;
    rep(i, q){
        int l, r;
        cin >> l >> r;
        ll ans = sums[r] - sums[l-2];
        cout << ans << endl;
    }
}

Measured memory_bytes: 4344
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define INF 1e9

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	map<int, i64> mp;
	int n;
	i64 k;
	cin >> n >> k;
	rep(i, 0, n) {
		int a, b;
		cin >> a >> b;
		if (!mp.count(a)) mp[a] = 0;
		mp[a] += b;
	}
	for (auto &ite : mp) {
		k -= ite.second;
		if (k <= 0) {
			cout << ite.first << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define smax(a, b) ((a) < (b) ? ((a)=(b), true) : false)
#define smin(a, b) ((a) > (b) ? ((a)=(b), true) : false)
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using namespace std;
typedef long long ll;

const ll MAX = 1e18;
ll n, w;
ll item[101][2];
ll dp[101][100001];
int main() {
    cin >> n >> w;
    ll tval = 0;
    for(int i = 1; i <= n; i++)
    {
        //value, weight
        cin >> item[i][1] >> item[i][0];
        tval += item[i][0];
    }

    for(int i = 0; i <= n; i++)
    {
        for(int j = 0; j <= tval; j++)
        {
            dp[i][j] = MAX;
        }
    }

    dp[0][0] = 0;

    for(int i = 1; i <= n; i++)
    {
        for(int j = 0; j <= tval; j++)
        {
            dp[i][j] = dp[i-1][j];
        }
        for(int j = 0; j <= tval; j++)
        {
            if(dp[i-1][j] != MAX)
            {
                dp[i][j + item[i][0]] = min(dp[i][j + item[i][0]], dp[i-1][j] + item[i][1]);
            }
        }
    }

    ll ans = MAX;
    for(int i = 0; i <= tval; i++)
    {
        if(dp[n][i] <= w) ans = i;
    }

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

Measured memory_bytes: 79104
N = int(input())
A = [int(a) for a in input().split()]
t = 0
for a in A[2:]:
    t ^= a
s = sum(A[:2])
if s < t or (s ^ t) & 1:
    print(-1)
    exit()

u = (s - t) // 2
a = A[0]
n = 0
for i in range(40)[::-1]:
    b, c = (t >> i) & 1, (u >> i) & 1
    if b == c == 1:
        print(-1)
        exit()
    if b == 0 and c == 1:
        n += 1 << i
for i in range(40)[::-1]:
    b, c = (t >> i) & 1, (u >> i) & 1
    if b == 1 and c == 0:
        if n + (1 << i) <= a:
            n += 1 << i

if n > a or n == 0:
    print(-1)
else:
    print(a - n)

Measured memory_bytes: 9184
def resolve():
    N = int(input())
    song_list = [input().split() for _ in range(N)]
    sleep_song = input()
    flag = False
    sleep_time = 0
    for name, time in song_list:
        if flag:
            sleep_time += int(time)
        if name == sleep_song:
            flag = True

    print(sleep_time)
resolve()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
const int maxn = 50;
int n, A;
long long dp[maxn + 3][2500 + 3][maxn + 3];
long long arr[maxn + 3];
 
long long solve(long long index, long long sum, long long numberOfChosen)
{
    if(index == n)
    {
        return (numberOfChosen != 0 && sum % A == 0 && numberOfChosen * A == sum);
    }
    if(dp[index][sum][numberOfChosen] != -1)
        return dp[index][sum][numberOfChosen];
    long long ans = 0;
    ans += solve(index + 1, sum, numberOfChosen);
    ans += solve(index + 1, sum + arr[index], numberOfChosen + 1);
    return dp[index][sum][numberOfChosen] = ans;
}
 
int main()
{
    cin >> n >> A;
    for(int i = 0; i < n; i++)
        cin >> arr[i];
    memset(dp, -1, sizeof dp);
    cout << solve(0, 0, 0);
    return 0;
}

Measured memory_bytes: 55168
#include<stdio.h>
#include<string.h>
#include<ctype.h>

int main(void)
{
	char w[11],w2[11];
	char t[1001],t2[1001];
	char s[12] = "END_OF_TEXT";
	int i,x;

	scanf("%s",w);
	for(i = 0;i <11;i++){
		w2[i] = tolower(w[i]);
	}
        x = 0;
	while(1){
		scanf("%s",t);
		if(strcmp(s,t) == 0)break;
		for(i = 0;i < 1001;i++){
			t2[i] = tolower(t[i]);
		}
		if(strcmp(w2,t2) == 0){
			x++;
		}
	}
	printf("%d\n",x);
	return 0;
}

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

using namespace std;

const int MAXN = 55555;

int arr[5*MAXN+1];

vector<int> prime;
vector<int> ans;


int main()
{
  int n;
  scanf("%d",&n);
  for(int i=2;i*i<=MAXN*5;i++)
    for(int j=i*i;j<=MAXN*5;j+=i)
      arr[j] = 1;



  int cnt =0;
  for(int i=6;i<=MAXN;i+=5)
    if(!arr[i]){
      prime.push_back(i);

      if(prime.size()>=n)break;
    }
  for(int i=0;i<n;i++)printf("%d ",prime[i]);
    printf("\n");

  return 0;
}


Measured memory_bytes: 1280
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
 


public class Main {
	static int a1[]= {0,-1,0,1};
	static int b1[]= {-1,0,1,0};
	private static         Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static int K,N;
	static long mod =1000000007;

	public static void main(String[] args) {
		int N=sc.nextInt();
		int ans=0;
		for(int i=0;i<N;i++) {
			int v=sc.nextInt();
			ans+=v-1;
		}p(ans);
	}
	//N==S
	//E==W
//83 S 
	//69E
	//78N
	//87W
	
	//static ArrayList<Integer> cc = new ArrayList<>(10001);
	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	public static int gcd(int a, int b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


Measured memory_bytes: 25972
#include <bits/stdc++.h>
#include <math.h>
#define lli long long int
#include <limits.h>
#include <fstream>
#define F first
#define S second
#define PI 3.141592653589793238
#define pb push_back

using namespace std;

//doesn't work for arrays
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

const lli N=100000;
vector<lli> g[N];
lli low[N],in[N]={0},timer=1;
set<pair<lli,lli>> ans;
bool bridge=0;

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

int main()
{
    //
    ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    lli i,j,tt=1;
    //cin>>tt;
    while(tt--)
    {
        lli n,ans=0;
        cin>>n;
        string s;
        cin>>s;
        i=0;
        j=n-1;
        while(i<j)
        {
            while(i<j && s[i]=='R')
                i++;
            while(i<j && s[j]=='W')
                j--;
            if(i>=j)
                break;
            else
            {
                ans++;
                s[i]='R';
                s[j]='W';
            }
        }
        cout<<ans<<"\n";
    }
    return 0;
}


Measured memory_bytes: 6124
#include <bits/stdc++.h>
#define F first
#define S second
#define MAX 10000003
using namespace std;

typedef long long ll;
ll mod = 1000000007;

ll prime[MAX];
unordered_map<ll, ll> max_map;

// Function to return a^n
ll power(ll a, ll n)
{
    if (n == 0)
        return 1;
    ll p = power(a, n / 2) % mod;
    p = (p * p) % mod;
    if (n & 1)
        p = (p * a) % mod;
    return p;
}

// Function to find the smallest prime factors
// of numbers upto MAX
void sieve()
{
    prime[0] = prime[1] = 1;
    for (int i = 2; i < MAX; i++) {
        if (prime[i] == 0) {
            for (int j = i * 2; j < MAX; j += i) {
                if (prime[j] == 0) {
                    prime[j] = i;
                }
            }
            prime[i] = i;
        }
    }
}

// Function to return the LCM modulo M
ll lcmModuloM(vector<ll> ar, int n)
{

    for (int i = 0; i < n; i++) {
        ll num = ar[i];
        unordered_map<ll, ll> temp;

        // Temp stores mapping of prime factor to
        // its power for the current element
        while (num > 1) {

            // Factor is the smallest prime factor of num
            int factor = prime[num];

            // Increase count of factor in temp
            temp[factor]++;

            // Reduce num by its prime factor
            num /= factor;
        }

        for (auto it : temp) {

            // Store the highest power of every prime
            // found till now in a new map max_map
            max_map[it.first] = max(max_map[it.first], it.second);
        }
    }

    ll ans = 1;

    for (auto it : max_map) {

        // LCM is product of primes to their highest powers modulo M
        ans = (ans * power(it.F, it.S)) % mod;
    }

    return ans;
}

// Driver code
int main()
{
    int n;
    sieve();
    cin>>n;
    vector<ll> v(n);
    for(int i=0;i<n;i++)cin>>v[i];
    ll ans=lcmModuloM(v, n);
    ans%=mod;
    ll re=0;
    for(int i=0;i<n;i++){
        re+=(ans*(power(v[i],mod-2)))%mod;re=re%mod;}
    cout<<re<<endl;
    return 0;
}


Measured memory_bytes: 78976
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
using namespace std;

int main() {
    clock_t cTimeStart, cTimeEnd;
    cTimeStart = clock();           // 現在時刻
    long long total=100000;
    int N;
    cin>>N;
    for(int i=0;i<N;++i){
    	total=total*1.05;
    	if(total%1000>0)total=(total/1000+1)*1000;
    }
    cout<<total<<endl;
    cTimeEnd = clock();           // 現在時刻
//    cout<< "処理時間:" <<(cTimeEnd - cTimeStart)/1000 << "[ms]" << endl;

	return 0;
}

Measured memory_bytes: 1164
#include <iostream>

using namespace std;
void judge(string s);
int main(){
	string s;

	cin >> s;
	judge(s);

}

void judge(string s){
	int i;
	for(i=0;i<s.size()-1;i++){
		if(s[i] == s[i+1]){
			cout << "Bad" << endl;
			return;
		}
	}
	cout << "Good" << endl;
	return;
}

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

int main(){
    int N, A, B;
    string S;
    cin >> N >> A >> B >> S;
    string ans;

    for(int i=0; i<N; i++){
        ans="No";
        if(S.at(i)=='a'){
            if(A+B>0){
                ans="Yes"; 
                A--;
            }
        }
        else if(S.at(i)=='b'){
            if(A+B>0 && B>0){
                ans="Yes";
                B--;
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 3644
input = readlines()
# x, t = input.shift().chomp.split("\s").map{|x| x.to_i}

a = input.shift.chomp.to_i
b = input.shift.chomp.to_i

l = [a, b].sort

if l[0] == 1 && l[1] == 2
  puts 3
elsif l[0] == 1 && l[1] == 3
  puts 2
else
  puts 1
end


Measured memory_bytes: 14260
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(int v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define LLI long long int
#define fst first
#define snd second

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(x) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}


vector<bool> prime_table(int n){
  vector<bool> res(n+1, true);
  res[0] = res[1] = false;
  FOR(i,2,n) if(res[i]) for(int j=2*i; j<=n; j+=i) res[j] = false;
  return res;
}


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

  auto primes = prime_table(10000);

  

  int N;
  while(cin >> N){
    vector<int> a(N+1); cin >> a;
    reverse(ALL(a));

    vector<int> ans;

    int g = 0;
    for(auto x : a) g = gcd(g, abs(x));

    for(LLI i=2; i*i<=g; ++i){
      if(g % i == 0){
	ans.push_back(i);
	while(g % i == 0) g /= i;
      }
    }
    if(g != 1) ans.push_back(g);


    FORE(i,2,N){
      if(not primes[i]) continue;

      vector<int> b(i);

      REP(j,i) b[j] = a[j] % i;

      FORE(j,i,N){
	int t = j%(i-1);
	(b[t?t:i-1] += a[j]) %= i;
      }

      dump(b);

      if(all_of(ALL(b), [&i](int x){return x == 0;})) ans.push_back(i);
    }

    sort(ALL(ans));
    ans.erase(unique(ALL(ans)), ans.end());
    
    
    join(cout, ALL(ans), "\n");
  }
  
  return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> ppiii;
typedef vector<vector<ll>> matrix;

void solve() {
  string s;
  cin >> s;
  int w = 0;
  for(int i = 0; i < 15; i++) {
    if(i >= s.size() || s[i] == 'o') w++;
  }
  if(w >= 8) cout << "YES\n";
  else cout << "NO\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
  solve();
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int y = sc.nextInt();

    int[] data1 = {1,3,5,7,8,10,12};
    int[] data2 = {4,6,9,11};
    int[] data3 = {2};
    int count1 = 0;
    int count2 = 0;
    int count3 = 0;

    for (int i = 0; i < data1.length; i++) {
      if (data1[i] == x) count1++;
      if (data1[i] == y) count1++;
    }

    for (int i = 0; i < data2.length; i++) {
      if (data2[i] == x) count2++;
      if (data2[i] == y) count2++;
    }

    for (int i = 0; i < data3.length; i++) {
      if (data3[i] == x) count3++;
      if (data3[i] == y) count3++;
    }

    if (count1 == 2 || count2 == 2 || count3 == 2) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }

  }

}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef pair<int, int> p;
typedef priority_queue<p> pq;
typedef priority_queue<p, vector<p>, greater<p>> gpq;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;
    ll maxv = -1, minv = INF;

    REP(i, n)
    {
        ll t = 0;
        cin >> t;

        maxv = max(maxv, t);
        minv = min(minv, t);
    }

    cout << maxv - minv << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>

using namespace std;

int main(void)
{
    long long N, A[101], i, j, max=0;

    cin >> N;

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

    for(i=1; i<=N-1; i++){
        for(j=i+1; j<=N; j++){
            if(max < abs(A[i]-A[j])){
                max = abs(A[i]-A[j]);
            }
        }
    }

    cout << max << endl;

    return 0;
}

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

typedef long long ll;
const int MN = 1e5+5;
ll dp[MN][2], n, i, arr[MN];

int main(){
    for(scanf("%lld",&n),i=1;i<=n;i++)
        scanf("%lld",&arr[i]);
    dp[n-1][0]=max(arr[n-1]+arr[n],-arr[n-1]-arr[n]);
    dp[n-1][1]=max(-arr[n-1]+arr[n],arr[n-1]-arr[n]);
    for(i=n-2;i>=1;i--){
        dp[i][0]=max(arr[i]+dp[i+1][0],-arr[i]+dp[i+1][1]);
        dp[i][1]=max(-arr[i]+dp[i+1][0],arr[i]+dp[i+1][1]);
    }
    printf("%lld\n",dp[1][0]);
    return 0;
}


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

int main() {

    int N;
    cin >> N;

    set<string> lottery;
    for (int i = 0; i < N; i++) {
        string s;
        cin >> s;

        lottery.insert(s);
    }

    cout << lottery.size() << endl;

    return 0;
}

Measured memory_bytes: 19212
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll INF=1e15;

int main(){
    ll n,k;
    cin >> n >> k;
    ll ans=k;
    rep(i,n-1){
        ans*=(k-1);
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
 int a , b ,c;
 cin >> a >> b >> c;
 int k = max({a , b , c});
 int l = min({a , b , c});
 if(a == l && b == k)cout << "Yes" << endl;
 else cout << "No" << endl;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    var word = readLine()
    if (word != null) {
        if(word.length != 6){
            return
        }
    }
    if(word?.get(2) ==word?.get(3) && word?.get(4) ==word?.get(5)){
        println("Yes")
    }else{
        println("No")
    }
}



Measured memory_bytes: 31740
mod = pow(10,9) + 7
s=int(input())

dp=[0]*(s+1)
dp[0]=1
 
for i in range(s+1):
	for j in range(0,(i-3)+1):
		dp[i] += dp[j]
		dp[i] %= mod

print(dp[-1] % mod)

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

using namespace std;


//==================
int n, m;
int a[400][400] = {{}};
//==================


bool Check(int x) {
  int cnt[401] = {};
  bool ava[401] = {};
  fill(ava, ava + m + 1, true);

  for(int k = 0; k < m + 1; ++k) {  
    fill(cnt, cnt + 400, 0);

    for(int i = 0; i < n; ++i) {
      int j = 0;
      while(j < m && !ava[ a[i][j] ]) ++j;
      if(j == m) {
        return false;
      }
      else {
        ++cnt[ a[i][j] ];
      }
    }

    bool found = false;
    for(int i = 1; i <= m; ++i) {
      if(cnt[i] > x) {
        ava[i] = false;
        found = true;
      }
    }
    if(!found) {
      return true;
    }
  }
  return false;
}


int main() {
  #ifdef _OFFLINE_
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif

  scanf("%d %d", &n, &m);
  for(int i = 0; i < n; ++i) {
    for(int j = 0; j < m; ++j) {
      scanf("%d", &a[i][j]);
    }
  }

  int l = 0, r = n + 1;
  while(r - l > 1) {
    int mid = (l + r) >> 1;
    if(Check(mid)) {
      r = mid;
    }
    else {
      l = mid;
    }
  }

  int ans = (r <= n && Check(r) ? r : l);
  printf("%d", ans);
}

Measured memory_bytes: 768
#include<iostream>
#include<string>
#include<vector>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<cstdlib>
#include<queue>
#include<utility> //pair
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

typedef long long ll;

int main() {
	//入力;
	ll N, A, B; //A<B;
	cin >> N >> A >> B;

	if ((B - A) % 2 == 0) cout << (B - A) / 2 << endl;

	else {
		if (A - 1 < N - B) cout << A + (B - A - 1) / 2 << endl;
		else cout << N - B + (B - A + 1) / 2 << endl;
	}

	//小数点以下の桁数表示;
	//cout << fixed << setprecision(15);


	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(int argc, const char * argv[]) {
     
    int dice[24][6] = {{2 ,6 ,3 ,4 ,1 ,5},
        {6 ,5 ,3 ,4 ,2 ,1},
        {5 ,1 ,3 ,4 ,6 ,2},
        {4 ,1 ,5 ,2 ,6 ,3},
        {6 ,4 ,5 ,2 ,3 ,1},
        {3 ,6 ,5 ,2 ,1 ,4},
        {1 ,3 ,5 ,2 ,4 ,6},
        {5 ,3 ,6 ,1 ,4 ,2},
        {3 ,2 ,6 ,1 ,5 ,4},
        {2 ,4 ,6 ,1 ,3 ,5},
        {4 ,5 ,6 ,1 ,2 ,3},
        {1 ,5 ,4 ,3 ,2 ,6},
        {2 ,1 ,4 ,3 ,6 ,5},
        {6 ,2 ,4 ,3 ,5 ,1},
        {5 ,6 ,4 ,3 ,1 ,2},
        {4 ,6 ,2 ,5 ,1 ,3},
        {6 ,3 ,2 ,5 ,4 ,1},
        {3 ,1 ,2 ,5 ,6 ,4},
        {1 ,4 ,2 ,5 ,3 ,6},
        {5 ,4 ,1 ,6 ,3 ,2},
        {3 ,5 ,1 ,6 ,2 ,4},
        {2 ,3 ,1 ,6 ,4 ,5},
        {4 ,2 ,1 ,6 ,5 ,3},
        {1 ,2 ,3 ,4 ,5 ,6}};
     
    int num2[6],i,j,count=0,num[6]={0};
     
    for (i = 0; i < 6; i++) {
        scanf("%d",&num[i]);
    }
     
    for (i = 0 ; i < 6; i++) {
        scanf("%d",&num2[i]);
    }
     
    for (i = 0; i < 24; i++) {
         
        for (j = 0; j < 6; j++) {
            if(num[j] != num2[dice[i][j]-1]){
                break;
            }
            count++;
        }
         
        if (count == 6) {
            printf("Yes\n");
            return 0;
        }
         
        count = 0;
    }
     
    printf("No\n");
     
     
    return 0;
}


Measured memory_bytes: 2148
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()
#define MOD 1000000007

bool up[200000];
int cu[200001], cd[200001];

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

    int now = 0;

    REP(i, 200000) up[i] = false;
    REP(i, 2 * N) {
        if ((now % 2 == 0 && S[i] == 'B') || (now % 2 == 1 && S[i] == 'W')) {
            now++;
            up[i] = true;
        }
        else {
            now--;
            if (now < 0) {
                cout << 0 << endl;
                return 0;
            }
            up[i] = false;
        }
    }
    if (now != 0) {
        cout << 0 << endl;
        return 0;
    }

    REP(i, 200001) {
        cu[i] = 0;
        cd[i] = 0;
    }
    REP(i, 2 * N) {
        if (up[i]) cu[i + 1] = cu[i] + 1;
        else cu[i + 1] = cu[i];
        if (!up[2 * N - 1 - i]) cd[i + 1] = cd[i] + 1;
        else cd[i + 1] = cd[i];
    }
    // REP(i, 2 * N + 1) cout << cu[i] << " "; cout << endl;
    // REP(i, 2 * N + 1) cout << cd[i] << " "; cout << endl;

    ll ans = 1, rest = 0;
    REP(i, 2 * N) {
        if (up[i]) {
            ans = (ans * (max(cd[2 * N - i] - rest, N - rest))) % MOD;
            rest++;
            if (rest == N) break;
        }
    }
    rest = 0;
    REP(i, 2 * N) {
        if (!up[i]) {
            ans = (ans * (min(cu[i + 1] - rest, N - rest))) % MOD;
            rest++;
            if (rest == N) break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2308
#include <bits/stdc++.h> 
using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int N;
  cin>>N;
  cout<<pow(N,3)<<endl;
  return 0;
}


Measured memory_bytes: 512
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
if 0 in a:
  print(0)
  exit(0)
res = 1
for x in a:
  res *= x
  if res > 10 ** 18:
    print(-1)
    exit(0)
print(res)


Measured memory_bytes: 82912
import sys
input = sys.stdin.readline

P = 10 ** 9 + 7


def main():
    N = int(input())
    S1 = input().rstrip()
    S2 = input().rstrip()

    if S1[0] == S2[0]:
        ans = 3
        i = 1
        prev = "H"
    else:
        ans = 6
        i = 2
        prev = "W"

    while i < N:
        if S1[i] == S2[i]:
            if prev == "H":
                ans *= 2
            else:
                ans *= 1
            i += 1
            prev = "H"
        else:
            if prev == "H":
                ans *= 2
            else:
                ans *= 3
            i += 2
            prev = "W"
    print(ans % P)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064