akhauriyash/Code-Regression huggingface dataset:
n=int(input())
l=[]
for i in range(n):
    s=input()
    k=s.split()
    x=int(k[1])

    c=[k[0],x]
    l.append(c)
# print(l)
m=[]
for i in range(n):
    m.append(l[i][0])


# print(l)
m.sort()
# print(m)

boolean=[False for i in range(n)]

for i in range(n):
    tmp=0
    for j in range(n):
        if(m[i]==l[j][0]):
            if(boolean[j]==False):
                if(tmp<l[j][1]):
                    tmp=l[j][1]
    for x in range(n):
        if(l[x][1]==tmp):
            boolean[x]=True
            print(x+1)

Measured memory_bytes: 39280
n = int(input())
d = list(map(int,input().split()))
mod =  998244353

cnt = [0]*n

if d[0] != 0:
    print(0)
    exit()

for e in d:
    cnt[e] += 1

if cnt[0] != 1:
    print(0)
    exit()

res = 1
for i in range(1,n):
    if cnt[i] != 0:
        if cnt[i-1] == 0:
            print(0)
            exit()
        res = res*pow(cnt[i-1],cnt[i],mod)%mod

print(res%mod)


Measured memory_bytes: 53556
#include<bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int ll;

// int dp[3000][3000];
int n, m;
// int find(string s, string t, int i, int j) {
// 	if (i >= n || j >= m)
// 		return 0;

// 	if (dp[i][j] != -1)
// 		return dp[i][j];

// 	if (s[i] == t[j])
// 		return dp[i][j] = find(s, t, i + 1, j + 1) + 1;

// 	return dp[i][j] = max(find(s, t, i + 1, j), find(s, t, i, j + 1));
// }


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

	string s, t;
	cin >> s >> t;
	n = s.length(), m = t.length();
	// dp.resize(n + 1, vector<int>(m + 1, -1));
	// memset(dp, -1, sizeof(dp));
	// find(s, t, 0, 0);
	vector<vector<int>> dp(n + 1, vector<int>(m + 1));
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (s[i - 1] == t[j - 1])
				dp[i][j] = dp[i - 1][j - 1] + 1;
			else
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
		}
	}

	int i = n, j = m;
	string res;
	while (i > 0 && j > 0) {
		if (s[i - 1] == t[j - 1]) {
			res += s[i - 1];
			i--;
			j--;
		} else {
			if (dp[i][j - 1] > dp[i - 1][j])
				j--;
			else
				i--;
		}
	}
	reverse(res.begin(), res.end());
	cout << res;
	return 0;
}


Measured memory_bytes: 38512
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1
//{
#include<bits/stdc++.h>
using namespace std;
#define hi cerr<<"hi"<<endl;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1
#define sysp system("pause")
#define PI acos(-1)
#define pf push_front

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

int n,flg,ans;
string s,t;

main(){
	cin>>n>>s>>t;
	ans=n*2;
	rep(i,n){
		string p,q;
		for(int j=i;j<n;j++)p+=s[j];
		for(int j=0;j<n-i;j++)q+=t[j];
		if(p==q){
			ans-=(n-i);
			break;
		}
	}
	dans;
}

Measured memory_bytes: 256
import sys
 
f_i = sys.stdin
 
n, q = map(int, f_i.readline().split())
 
S = set(frozenset([i]) for i in range(n))
 
def unite(sets, v1, v2):
    s1 = None
    s2 = None
    for s in sets:
        if v1 in s and v2 in s:
            return None
        elif v1 in s:
            s1 = s
        elif v2 in s:
            s2 = s
        if s1 and s2:
            break
    sets.discard(s1)
    sets.discard(s2)
    s3 = s1.union(s2)
    sets.add(s3)
 
def same(sets, v1, v2):
    for s in sets:
        if v1 in s and v2 in s:
            print(1)
            break
        elif v1 in s or v2 in s:
            print(0)
            break
 
for l in f_i:
    com, x, y = map(int, l.split())
    if com == 0:
        unite(S, x, y)
    else:
        same(S, x, y)

Measured memory_bytes: 12464
N_MAX = 45 # 0 ≤ n ≤ 44
F = [None] * N_MAX


def fibonacci(n):
    if n == 0 or n == 1:
        F[n] = 1
        return F[n]

    if F[n] != None:
        return F[n]

    F[n] = fibonacci(n - 1) + fibonacci(n - 2)

    return F[n]



n = int(input())
print(fibonacci(n))



Measured memory_bytes: 5600
x1, y1, x2, y2 = map(int, input().split())

diff_x = x2 - x1
diff_y = y2 - y1

x3 = x2 + (-diff_y)
y3 = y2 + diff_x
tmp = diff_x
diff_x = -diff_y
diff_y = tmp

x4 = x3 + (-diff_y)
y4 = y3 + diff_x


print(x3,y3,x4,y4)

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

int main(){
    int n; cin >> n;
    rep(i,n){
        char c; cin >> c;
        if(c == 'Y'){
            cout << "Four" << endl;
            return 0;
        }
    }
    cout << "Three" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        int a = scanner.nextInt();
        int b = scanner.nextInt();
        boolean total = ((a + b) % 3 == 0);

        if (a % 3 == 0 || b % 3 == 0 || total) {
            result = "Possible";
        }

        System.out.println(result);

    }
}

Measured memory_bytes: 21588
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;
int in(){
    int temp;
    scanf("%d",&temp);
    return temp;
}


int Mdist(pair<int,int>p1, pair<int,int>p2){
    return abs(p1.first - p2.first) +  abs(p1.second - p2.second);
}

int main() {

    priority_queue<int> p;
    p.push(in());p.push(in());p.push(in());
    
    if (p.top() == 7){
        p.pop();
        if (p.top() == 5){
            p.pop();
            if (p.top() == 5){
                cout << "YES" << endl;
                p.pop();
                return 0;
            }
        }
    }
    cout << "NO" << endl;
    return 0;
    
}


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  ll N, M, V, P;
  cin >> N >> M >> V >> P;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];

  sort(rall(A));

  int ok = 0;
  int ng = N;

  while (abs(ok - ng) > 1) {
    int mid = (ok + ng) / 2;

    if (mid < P) {
      ok = mid;
      continue;
    }

    vector<ll> a = A;
    ll cnt = V * M;
    REP(i, mid, N) {
      if (cnt <= 0) break;
      cnt -= M;
      a[i] += M;
    }
    rep(i, P - 1) {
      if (cnt <= 0) break;
      cnt -= M;
      a[i] += M;
    }

    bool flg = true;
    REP(i, P - 1, mid) if (a[i] > a[mid]) flg = false;
    if (!flg) {
      ng = mid;
      continue;
    }

    REP(i, P - 1, mid) {
      if (cnt <= 0) break;
      cnt -= (a[mid] - a[i]);
    }

    if (cnt > 0)
      ng = mid;
    else
      ok = mid;
  }

  cout << ok + 1 << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstring>
#include <cmath>
#include <cstdio>

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(){
    int L,A,B,C,D;
    cin >> L >> A >> B >> C >> D ;
    cout << L - max(A/C+(A%C!=0),B/D+(B%D!=0)) << endl;
    return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<functional>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;

int main(){
    int N;
    map<char,int> mp;
    cin>>N;
    for(int i=0;i<N;i++){
        string s;
        cin>>s;
        mp[s[0]]++;
    }
    string s="MARCH";
    LL ans=0;
    for(int i=0;i<3;i++){
        for(int j=i+1;j<4;j++){
            for(int k=j+1;k<5;k++){
                ans+=(LL)mp[s[i]]*(LL)mp[s[j]]*mp[s[k]];
            }
        }
    }
    cout<<ans;
    


    
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
    static int max(ArrayList<Integer> cards){
	int max = cards.get(0);
	int count = 0;
	for (int i = 0; i < cards.size(); i++){
	    if (max < cards.get(i)){
		max = cards.get(i);
		count = i;
	    }
	   
	}
	 return count;
    }
	
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	ArrayList<Integer> cards = new ArrayList<Integer>();
	for (int i = 0;i < N; i++){
	    cards.add(sc.nextInt());
	}
        int[] score = {0,0};
	int max = 0;
	int count = 0;
	while (cards.size() > 0){
	    score[count % 2] += cards.get(max(cards));
	    //System.out.println((count%2) + " " + score[count % 2]);
	    cards.remove(max(cards));
	    count++;
	}
	System.out.println(score[0] - score[1]);
    }
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

void solve_abc_a() {
	ll k, a, b;
	//ll ans = 0;
	string ans = "NG";

	cin >> k >> a >> b;

	rep2(i, a, b + 1) {
		if (i % k == 0) {
			ans = "OK";
			break;
		}
	}

	cout << ans << "\n";

	return;
}

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

	solve_abc_a();

	return 0;
}

Measured memory_bytes: 3648
n,a,b = list(map(int,input().split()))
s = list(input())
ok = 0
rank = 1
for i in s:
    if ok >= a+b:
        print('No')
    elif i == 'a':
        print('Yes')
        ok += 1
    elif i == 'b':
        if rank <= b:
            print('Yes')
            rank += 1
            ok += 1
        else:
            print('No')
    else:
        print('No')

Measured memory_bytes: 4712
#include <cstdio>
#include <bitset>
#include <numeric>
using namespace std;
 
int const N = 1000001;
int spf[N], s[17], d, i, j, k;
bitset<N> u;
char const* r = "pairwise";
 
int main() {
    while (++i < N)spf[i] = i;
    for (i = 2; i * i < N; i++)
        for (j = i * i; j < N; j += i)
            if (spf[j] == j)
                spf[j] = i;
    for (scanf("%*d"); ~scanf("%d", &j); k = 0) {
        d = std::gcd(d, j);
        for (; j > 1; j /= i) {
            s[k++] = i = spf[j];
            if (u[i]) r = "setwise";
        }
        while(k--)u.set(s[k]);
    }
    printf("%s coprime\n", d > 1 ? "not" : r);
    return 0;
}


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

int main(void){

	int N,t[100005],x[100005],y[100005];
	cin >> N;
	t[0]=0;x[0]=0;y[0]=0;
	for(int i=1;i<=N;i++){
		cin >> t[i] >> x[i] >> y[i];
	}

	for(int j=1;j<=N;j++){
		if(((t[j]-t[j-1])-((x[j]-x[j-1])+(y[j]-y[j-1])))%2!=0||(t[j]-t[j-1])<((x[j]-x[j-1])+(y[j]-y[j-1]))){
			goto P;
		}
	}

	cout << "Yes" << endl;
	return 0;

	P:
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 1408
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}
func fSum(a []float64) float64 {
	x := 0.
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n, k := iScan(), iScan()
	a := iSScan(n)
	x := sum(a)
	d := make([]int, 0)
	for i := 1; i*i <= x; i++ {
		if x%i == 0 {
			d = append(d, i)
			if i != x/i {
				d = append(d, x/i)
			}
		}
	}
	sort.Sort(sort.Reverse(sort.IntSlice(d)))
	for _, v := range d {
		y := make([]int, n)
		z := make([]int, n)
		for i := 0; i < n; i++ {
			y[i] = a[i] % v
		}
		sort.Ints(y)
		yy := make([]int, n)
		copy(yy, y)
		for i := 0; i < n; i++ {
			z[i] = v - y[i]
		}
		for i := 1; i < n; i++ {
			y[i] += y[i-1]
		}
		for i := n - 2; i >= 0; i-- {
			z[i] += z[i+1]
		}
		c := 0
		for i := 0; i < n-1; i++ {
			c += yy[i]
			if y[i] == z[i+1] {
				break
			}
		}
		if c <= k {
			fmt.Println(v)
			break
		}
	}
}


Measured memory_bytes: 6340
tmp = list(map(int,input().split()))
n,p,q = tmp[0],tmp[1],tmp[2]
cs = []
for i in range(n):
    cs.append(int(input()))
ans = [sum(cs)]
difs = [p * (q-i) - cs[i] for i in range(n)]
difs.sort(reverse = True)
for i in range(n):
    ans.append(ans[-1] + 2 * i * p + difs[i])
print(max(ans))



Measured memory_bytes: 71196
#include<cstdio>
#include<cstring>

using namespace std;

char ch[110];

int A,B;

void solve()
{
	A=0,B=0;
	int N=strlen(ch);
	for(int i=1;i<N;i++)
	{
		if(ch[i]=='A') A++;
		else if(ch[i]=='B') B++;
	}
	if(A>B) A++;
	else B++;
}

int main()
{
	while(true)
	{
		scanf("%s",ch);
		if(ch[0]=='0') break;
		solve();
		printf("%d %d\n",A,B);
	}
	return 0;
}

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

int main(){
	int N,count=0;
	//??\???
	cin >> N;
	int A[N];
	for(int i=0;i<N;i++)
		cin >> A[i];
	//??卒???
	for(int i=0;i<N;i++){
		int mini = i,flag = 0;
		for(int j=i;j<N;j++)
			if(A[j]<A[mini]){
				mini = j;
				flag = 1;
			}
		if(flag){
			swap(A[i],A[mini]);
			count++;
		}
	}
	//??????
	for(int i=0;i<N;i++){
		if(i>0)	cout<< " ";
		cout<< A[i];
	}
	cout<< endl << count << endl;
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
using namespace std;

vector<long long int> sum;

bool hantei(int index, long long int key,int left,int right) {
	if (sum[index] - sum[left] >= sum[right] - sum[index])return true;
	else return false;
}

int nibutan(long long int key, int left, int right) {
	int ng = left;
	int ok = right-1;

	while (abs(ok - ng) > 1) {

		int mid = (ng + ok) / 2;

		if (hantei(mid, key, left, right))ok = mid;
		else ng = mid;

	}
	if (ok!=left+1&&abs(sum[right] + sum[left] - 2 * sum[ok]) > abs(sum[right] + sum[left] - 2 * sum[ok - 1]))ok--;
	return ok;
}


int main() {
	//cout << fixed << setprecision(10);
	long long int a[200][200], b[200], c, d, n, m,sum=0,cou=0;
	string str;
	cin >> n>>m>>c;

	for (int i = 1; i <= m; i++) {
		cin >> b[i];
	}

	for (int i = 1; i <= n; i++) {
		sum = c;
		for (int j = 1; j <= m; j++) {
			cin >> a[i][j];
			sum += a[i][j] * b[j];
		}
		if (sum > 0) { cou++; }
	}

	cout << cou;
}


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

using namespace std;

int main() {
  int A, B;
  cin >> A >> B;
  int a = 1;
  int cnt = 0;
  while (a < B) {
    --a;
    a += A;
    ++cnt;
  }
  printf("%d\n", cnt);
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };


int main()
{
    #ifdef __LOCAL
        freopen("C_input.txt", "r", stdin);
        freopen("C_output.txt", "w", stdout);
    #endif

    int N,M;
    int __correct, __wrong;
    __correct = __wrong = 0;
    cin >> N >> M;
    vector<bool> AC(N+10,false);
    vector<int> wrongAC(N+10,0);

    for(int i=0;i<M;i++){
        int p;
        string S;
        cin >> p >> S;
        if(AC[p]) continue;
        else{
            if(S=="AC"){
                AC[p] = true;
                __correct++;
                __wrong+=wrongAC[p];
            }
            else if(S=="WA"){
                wrongAC[p]++;
            }
        }

    }

    cout << __correct << " " << __wrong << endl;
    return 0;
}


Measured memory_bytes: 640
///
// File:  d.go
// Author: ymiyamoto
//
// Created on Sat May  5 21:11:32 2018
//
package main

import (
	"fmt"
)

var N int

func isPrime(n int) bool {
	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			return false
		}
	}
	return true
}

func primes5() []int {
	arr := make([]int, 0)
	index := 2
	for len(arr) < N {
		if isPrime(index) && (index%5) == 1 {
			arr = append(arr, index)
		}
		index++
	}
	return arr
}

func main() {
	fmt.Scan(&N)

	arr := primes5()
	for i := 0; i < N; i++ {
		if i != 0 {
			fmt.Print(" ")
		}
		fmt.Print(arr[i])
	}
	fmt.Println()
}


Measured memory_bytes: 512
//waz
#include <bits/stdc++.h>
 
using namespace std;
 
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)((x).size()))
typedef long long int64;
typedef unsigned int uint;
typedef unsigned long long uint64;
 
typedef pair<int64, int64> PII;
typedef vector<int> VI;
 
#define gi(x) ((x) = F())
#define gii(x, y) (gi(x), gi(y))
#define giii(x, y, z) (gii(x, y), gi(z))
 
int F()
{
	char ch;
	int x, a;
	while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-');
	if (ch == '-') ch = getchar(), a = -1;
	else a = 1;
	x = ch - '0';
	while (ch = getchar(), ch >= '0' && ch <= '9')
		x = (x << 1) + (x << 3) + ch - '0';
	return a * x;
}
 
const int N = 1 << 20;
 
int a[N], v[N], n;
 
vector<PII> p[N];
 
int son[N][2];
 
bool level[N];
 
vector<PII> A, B;
 
bool work(int x, int64 lim)
{
	p[x].clear();
	if (level[x])
	{
		p[x].pb(mp(0LL, 0LL));
		return 1;
	}
	int ls = son[x][0], rs = son[x][1];
	if (!SZ(p[ls]) || !SZ(p[rs])) return 0;
	if (p[ls].size() > p[rs].size()) swap(ls, rs);
	A.clear(); B.clear();
	int64 L = lim - v[ls] - v[rs];
	int64 mi = 1LL << 35;
	for (int i = 0, j = 0; i < SZ(p[ls]); ++i)
	{
		while (p[ls][i].se > L - mi && j < SZ(p[rs])) mi = min(mi, p[rs][j].fi), ++j;
		if (p[ls][i].se > L - mi) break;
		if (j) A.pb(mp(p[ls][i].fi + v[ls], p[rs][j - 1].se + v[rs]));
	}
	mi = 1LL << 35;
	for (int j = 0, i = 0; j < SZ(p[rs]); ++j)
	{
		while (p[rs][j].se > L - mi && i < SZ(p[ls])) mi = min(mi, p[ls][i].fi), ++i;
		if (p[rs][j].se > L - mi) break;
		if (i) 
		{
			if (SZ(B))
			{
				if (B[SZ(B) - 1].se == p[ls][i - 1].se + v[ls])
					B[SZ(B) - 1].fi = min(B[SZ(B) - 1].fi, p[rs][j].fi + v[rs]);
				else B.pb(mp(p[rs][j].fi + v[rs], p[ls][i - 1].se + v[ls]));
			}
			else B.pb(mp(p[rs][j].fi + v[rs], p[ls][i - 1].se + v[ls])); 
		}
	}
	int i = 0, j = 0;
	while (i < SZ(A) || j < SZ(B))
	{
		if (j >= SZ(B)) p[x].pb(A[i++]);
		else if (i >= SZ(A) || A[i].se > B[j].se) p[x].pb(B[j++]);
		else p[x].pb(A[i++]);
	}
	if (!SZ(p[x])) return 0;
	return 1;
}
 
bool check(int64 lim)
{
	for (int i = n; i; --i) if (!work(i, lim)) return 0;
	return 1;
}
 
main()
{
	gi(n);
	for (int i = 1; i <= n; ++i) level[i] = 1;
	for (int i = 2; i <= n; ++i) 
	{
		gii(a[i], v[i]);
		level[a[i]] = 0;
		if (son[a[i]][0]) son[a[i]][1] = i;
		else son[a[i]][0] = i; 
	}
	int64 x = -1;
	for (int i = 35; ~i; --i)
		if (!check(x + (1LL << i)))
			x += (1LL << i);
	printf("%lld\n", x + 1);
	return 0;
} 

Measured memory_bytes: 56040
def main():
    S = list(input())
    k = 0
    ans = False
    
    while True :
        if len(S) % 2 != 0 :
            break 
        elif k == len(S):
            ans = True
            break
        elif S[k] + S[ k + 1] != "hi":
            break
        else :
            k += 2
    if ans : print("Yes")
    else: print("No")
if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using iii = pair<ii, int>;
#define vt vector
#define pq priority_queue
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define __lcm(a, b) a * b / __gcd(a, b)
const int MOD = 1e9 + 7;
const int INF = 2e9;
const int N = 2e5 + 5;

int D, T, S;

int up(int x, int y) {
    return x % y == 0 ? x / y : x / y + 1;
}

void solve() {
    cin >> D >> T >> S;
    cout << (up(D, S) <= T ? "Yes\n" : "No\n");    
}

int main() {
 
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    solve();
    
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) {
  cout << (expr ? "Yes" : "No") << "\n";
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  lint n, m;
  cin >> n >> m;
  vector<lint> x(n);
  REP(i, n) cin >> x[i];
  vector<lint> y(m);
  REP(i, m) cin >> y[i];
  lint xsum = 0;
  REP(i, n-1) xsum = (xsum + (x[i+1] - x[i]) * (i+1) % MOD * (n-1-i) % MOD) % MOD;
  lint ysum = 0;
  REP(i, m-1) ysum = (ysum + (y[i+1] - y[i]) * (i+1) % MOD * (m-1-i) % MOD) % MOD;
  cout << xsum * ysum % MOD << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>


using namespace std;


void white_cells()
{
  int H, W, h, w;
  cin >> H >> W >> h >> w;

  cout << (H * W) - (h * W) - (H * w) + (h * w) << "\n";
}


void double_helix()
{
  char b;
  cin >> b;

  if (b == 'A') cout << "T\n";
  else if (b == 'T') cout << "A\n";
  else if (b == 'C') cout << "G\n";
  else  cout << "C\n";

}


void five_antennas()
{
  vector<int> a(5);
  for (int i = 0; i < 5; ++i) cin >> a[i];
  int k;
  cin >> k;

  if (a[4] - a[0] > k)
  {
    cout << ":(\n";
    return;
  }
  cout << "Yay!\n";

}

void buttons()
{
  int a, b;
  cin >> a >> b;

  int v_max = 0;
  for (int i = 0; i < 2; ++i) {
    if (a > b) {
      v_max += a;
      --a;
    }
    else
    {
      v_max += b;
      --b;
    }
  }
  cout << v_max << "\n";
}


void biscuit_generator()
{
  int a, b, t;
  cin >> a >> b >> t;

  cout << t / a * b << "\n";
}


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

  s[k - 1] += 32;
  cout << s <<"\n";
}


void ferris_wheel()
{
  int a, b;
  cin >> a >> b;

  if (a >= 13) cout << b << "\n";
  else if(a >= 6) cout << b / 2 << "\n";
  else cout << 0 << "\n";
}


void apple_pie()
{
  int a, p;
  cin >> a >> p;

  p += 3 * a;

  cout << p / 2 << "\n";
}


void airplane()
{
  vector<int> a(3);
  for (int i = 0; i < 3; ++i) cin >> a[i];

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

  cout << a[0] + a[1] << "\n";
}


int main()
{
  //white_cells();
  //double_helix();
  //five_antennas();
  //buttons();
  //biscuit_generator();
  //changing_a_character();
  //ferris_wheel();
  //apple_pie();
  airplane();
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>

int main() {
  using namespace std;

  int A, B;
  cin >> A >> B;

  int count = 0;
  for (int i=A; i<=B; i++) {
    string s = to_string(i);
    bool flg = true;
    for (int j=0; j<s.length()/2; j++) {
      char a = s[j];
      char b = s[s.length() - j - 1];
      if (a != b) {
        flg = false;
      }
    }
    if (flg) {
      count++;
    }
  }

  cout << count << endl;
  return 0;
}

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

using namespace std;

vector< int > adj;

int digit(int x)
{
    int ans = 0;
    while(x){ ans++; x/= 10;}
    return ans;
}
int main()
{
    int a, b;
    while(cin>> a >> b){
        cout<< digit(a + b) <<'\n';
    }
}

Measured memory_bytes: 2996
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

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

		int N, M;

		String[] nm = scanner.nextLine().split(" ");
		N = Integer.parseInt(nm[0]);
		M = Integer.parseInt(nm[1]);
		String[] as = scanner.nextLine().split(" ");
		scanner.close();

		PriorityQueue<Long> queue = new PriorityQueue<Long>(Comparator.reverseOrder());

		for (int i = 0; i < N; i++) {
			queue.add(Long.parseLong(as[i]));
		}

		for (int i = 0; i < M; i++) {
			long l = queue.remove();
			l /= 2;
			queue.add(l);
		}

		long ans = 0;
		for (int i = 0; i < N; i++) {
			ans += queue.remove();
		}

		System.out.println(ans);
	}
}

Measured memory_bytes: 52404
import javax.xml.crypto.Data;
import java.util.*;
import java.io.*;

public class Main {
    public static int N, K;
    public static int MAX = 60;
    public static long[] x = new long[MAX], y = new long[MAX];


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

        //入力
        /*
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] str = br.readLine().split(" ");
        */

        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        K = sc.nextInt();
        for(int i = 0; i < N; i++) {
            x[i] = sc.nextLong();
            y[i] = sc.nextLong();
        }
        //出力
        solve();
    }

    public static void solve() {
        long ans = 5000000000000000000L;
        for(int i = 0; i < N; i++) {
            for(int j = 0; j < N; j++) {
                for(int k = 0; k < N; k++) {
                    for(int l = 0; l < N; l++) {
                        int count = 0;
                        for(int m = 0; m < N; m++) {
                            if(x[i] <= x[m] && x[m] <= x[j] && y[k] <= y[m] && y[m] <= y[l]) count++;
                        }
                        if(count >= K) ans = Math.min(ans, (x[j] - x[i]) * (y[l] - y[k]));
                    }
                }
            }
        }
        System.out.println(ans);

    }

}

Measured memory_bytes: 24148
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols
    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])
    return ret


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_map_as_int(H):
    '''
    #→1,.→0として読み込む
    '''
    ret = []
    for _ in range(H):
        ret.append([1 if s == '#' else 0 for s in read()[:-1]])
        # 内包表記はpypyでは若干遅いことに注意
        # #numpy使うだろうからこれを残しておくけど
    return ret


# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# 同型→文字数カウントのパターンが同じ
# 標準形→文字数辞書順の最も速いもの


N = read_a_int()


moji = 'abcdefghij'
candi = []
moji = moji[:N]


def dfs(now, i, j):
    # j....いままでで最大の文字のidx
    # 文字を作って返す
    if i == N:
        candi.append(now)
        return
        # return now
    for jj in range(j + 2):
        dfs(now + moji[jj], i + 1, max(j, jj))


dfs('', 0, -1)

print(*sorted(candi), sep='\n')


# for i in range(1, N + 1):  # 何番目まで使うか
#     mojisyu = moji[:i]  # ここで使う文字種類
#     # 文字種類でaを先頭にできるだけ標準形を列挙したい
#     for j in range(1, i):


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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  string s ;
  cin >> s ;
  stack<char> data;
  data.push(s.at(0));
  
  rep(i,s.size()-1) {
    if(!data.empty()){ 
     if(data.top() != s.at(i+1))
       data.pop();
    else 
      data.push(s.at(i+1));
    }
    else 
      data.push(s.at(i+1));
  }
  
  cout << s.size() - data.size() ;
}


Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(long long (i)=0, i_bound = (long long)(n); (i)<i_bound; ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
signed main(){
    string s; cin>>s;
    ll N = s.size();
    vector<int> tp;
    tp.emplace_back(-N);
    char now = 'R';
    for(int i=1; i<N; i++){
        if(now=='R' and s[i]!=now){
            // R L となるLのindex を記憶
            tp.emplace_back(i);
            now = 'L';
        }
        else if(s[i]!=now){
            now = 'R';
        }
    }
    tp.emplace_back(2*N);
    vector<ll> res(N);
    for(int i=0; i<N; i++){
        if(s[i]=='R'){
            int idx = *lower_bound(ALL(tp), i);
            if((idx-i)%2==0) res[idx]++;
            else res[idx-1]++;
        }
        else{
            int idx = *lower_bound(ALL(tp), i); 
            if(idx>i) idx = *(lower_bound(ALL(tp), i)-1);
            if((i-idx)%2==0) res[idx]++;
            else res[idx-1]++;
        }
    }
    cout << res << endl;
    return 0;
}

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

const int MaxH = 100 + 1, MaxW = 8;

int H, W, K;
int dp[MaxH][MaxW][1 << MaxW];

inline bool check(int S) {
    for (int i = 0; i < W - 1; ++i)
        if ((S & (1 << i)) && (S & (1 << i + 1))) return false;
    return true;
}

inline void update(int &x, int v) {
    x += v;
    x %= 1000000007;
}

void solve() {
    dp[0][0][0] = 1;
    for (int i = 1; i <= H; ++i) for (int S = 0; S < (1 << (W - 1)); ++S) {
        if (check(S) == false) continue;
        for (int Q = 0; Q < (1 << W - 1); ++Q) {
            if (check(Q) == false) continue;
            for (int j = 0; j < W; ++j) {
                if (j != 0 && (S & (1 << j - 1)))
                    update(dp[i][j][S], dp[i - 1][j - 1][Q]);
                else if (j != W - 1 && (S & (1 << j)))
                    update(dp[i][j][S], dp[i - 1][j + 1][Q]);
                else
                    update(dp[i][j][S], dp[i - 1][j][Q]);
                // printf("dp[%d][%d][%d] = %d\n", i, j, S, dp[i][j][S]);
            }
        }
    }

    int ans = 0;
    for (int S = 0; S < (1 << W - 1); ++S)
        if (check(S)) update(ans, dp[H][K - 1][S]);
    cout << ans << endl;
}

int main() {
    cin >> H >> W >> K;
    solve();
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <math.h>
#include <string>    // useful for reading and writing
#include <fstream>   // ifstream, ofstream
#include <sstream>   // istringstream

using namespace std;

int main()
{
    while(1)
    {
    int h, w,flag;
    std::cin >> h >> w;
    if(h==0&&w==0){break;}
    
        for(int i = 0; i < h; i++)
        {
            if( i == 0 || i == h-1)
            {
                for(int j = 0; j < w; j++)
                {
                std::cout<<"#";
                }
            }
            else
            {
                std::cout<<"#";
                for(int j = 1; j < w - 1; j++)
                {
                std::cout<<".";
                }
                std::cout<<"#";
            }

            std::cout<<"\n";
        }
        std::cout<<"\n";
    }
    return 0;
}


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

using namespace std;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    int a, b, c;
    cin >> a >> b >>c;
    if(c >= a && c <= b)
        cout <<"Yes\n";
    else
        cout <<"No\n";
}

Measured memory_bytes: 256
#include <stdio.h>

int gcd(int a, int b){
	int r;
	
	if ((a % b) == 0){
		return (b);
	}
	else {
		r = a % b;
		return (gcd(b, r));
	}
}
int lcm(int a, int b)
{
	return ((a / gcd(a, b)) * b);
	
}
int main(void)
{
	int a, b;
	int g, l;
	while (scanf("%d %d", &a, &b) != EOF){
		g = gcd(a, b);
		l = lcm(a, b);
		printf("%d %d\n", g, l);
	}
	return (0);
}

Measured memory_bytes: 596
import java.util.Arrays;
import java.util.Scanner;

public class Main{
	
	//最大公約数・最小公倍数（セットで使う）
	public static long gcm(long a, long b) {
		long result = a;
		long k = 0;
		long n = b;
		do {
			k = result % n;
			result = n;
			n = k;
		} while(k != 0);
		return result;
	}
	
	public static long lcm(long a, long b) {
		long g;
		g = gcm(a, b);
		return a/g*b;
	}
	
	static long gcd (long a, long b) {
		long temp;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return b;
	}



	//素数判定
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2) if(n%i==0){return false;}
		return true;
	}


	//倍数判定（10進数以外のときに有用）
	static boolean isMultiple (String s, int base, int m) {
		int temp = 0;
		for (int i=0; i<s.length(); i++) {
			temp = (temp*base+Character.getNumericValue(s.charAt(i)))%m;
		}
		if (temp==0) {return true;}
		return false;
	}


	//階乗
	static long factorial (int i) {
		if (i==1) {return 1;}
		else {return i*factorial(i-1);}
	}


	//進数変換
	static String toNbase (String sm, int m, int n) {
		return Long.toString(Long.parseLong(sm,m),n);
	}
	
	public static final long gcd_n(long[] param) {
	    final int len = param.length;
	    long g = gcd(param[0], param[1]);    //gcd(a, b) は以前作ったもの
	    for (int i = 1; i < len - 1; i++) {
	        g = gcd(g, param[i + 1]);       //gcd(a, b) は以前作ったもの
	    }
	    return g;
	}
	
	public static long lcm_n(long[] numbers) {
		long l;
		l = numbers[0];
		for (int i = 1; i < numbers.length; i++) {
			l = lcm(l, numbers[i]);
		}
		return l;
	}
	
	
 public static void main(String[] args) {
	 Scanner sc=new Scanner(System.in);
	 String s=sc.next();
	 s=s.substring(s.indexOf('A'));
	 System.out.println(s.lastIndexOf('Z')+1);
	 
	 
	 
 }
	


}



Measured memory_bytes: 26148
/*
题意：
 
平面上有$n$个点，每个点都有一个位置$x_i$，和向右的速度$v_i$
 
现在要求你对其中的一些点进行染色，当一个点被染色后，在无限距离内与它相遇的点也会被染色
 
问在可能的$2^n$种染色方案中，有多少种染色方案可以使得最后的点全部被染色
 
Sol
 
非常好的dp题。
 
首先考虑若点$i$被染色后，哪些点会被染色
 
最显然的两种情况
 
1. $x_j < x_i$且$v_j > v_i$
2. $x_j > x_i$且$v_j < v_i$
 
当然还有其他的情况，因为题目中的“染色”是一个连锁反应，也就是说$a$被染色，$a$又遇到了$b$，那么$b$也会被染色
 
实际上，当我们把所有点按速度从大到小排序。
 
对于$x_i$，向左找到第一个$x_l < x_i$的最小的$l$(此时同时保证了$v_l$最大)
		   向右找到第一个$x_r > x_i$的最大的$r$(同理保证了$v_r$最小)
 
那么区间$[l, r]$内所有的点都会被染色
 
现在问题转化成了，每个点能覆盖一段区间$[l, r]$，问把区间$[l, N]$覆盖的方案数
 
预处理出每个点能覆盖的区间$[l, r]$，前缀和优化dp即可
 
*/
#include<bits/stdc++.h>
#define Pair pair<int, int>
#define fi first
#define se second
#define MP(x, y) make_pair(x, y)
#define LL long long 
using namespace std;
const int MAXN = 1e6, mod = 1e9 + 7;
inline int read() {
	char c = getchar(); int x = 0, f = 1;
	while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * f;
}
int N, date[MAXN], L[MAXN], R[MAXN], f[MAXN];
struct Node {
	int x, v, id, l, r;
	bool operator < (const Node &rhs) const {
		return v > rhs.v;
	}
}a[MAXN];
int comp(const Node &a, const Node &b) {
	return a.r == b.r ? a.l < b.l : a.r < b.r;
}
void GetL(int *op) {
	vector<Pair> q; 
	for(int i = 1; i <= N; i++) q.push_back(MP(a[i].x, a[i].id));
	sort(q.begin(), q.end());
	for(int i = 1; i <= N; i++) {
		while(!q.empty()) {
			if(a[i].x <= q.back().fi) op[q.back().se] = i, q.pop_back();
			else break;
		}
	}
}
void GetR(int *op) {
	vector<Pair> q; 
	for(int i = 1; i <= N; i++) q.push_back(MP(a[i].x, a[i].id));
	sort(q.begin(), q.end());
	reverse(q.begin(), q.end());
	for(int i = N; i >= 1; i--) {
		while(!q.empty()) {
			if(a[i].x >= q.back().fi) op[q.back().se] = i, q.pop_back();
			else break;
		}
	}
}
int dp() {
	for(int i = 1; i <= N; i++) a[i].r = N - L[i] + 1, a[i].l = N - R[i] + 1;
	sort(a + 1, a + N + 1, comp);
	//for(int i = 1; i <= N; i++) printf("%d %d\n", a[i].l, a[i].r);
	static int s[MAXN], f[MAXN];//f[i]：前i只猫覆盖所有区间的方案
	int ans = 0;
	for(int i = 1, j = 1; i <= N; i++) {
		while(a[j].r < a[i].l - 1) j++;//l有单调性？
		f[i] = (s[i - 1] + mod - s[j - 1] ) % mod;
		if(a[i].l == 1) f[i]++;
		if(a[i].r == N) (ans += f[i]) %= mod;
		s[i] = (s[i - 1] + f[i]) % mod;
	}
	return ans % mod;	
}
main() {
	N = read();
	for(int i = 1; i <= N; i++) a[i].x = read(), a[i].v = read(), a[i].id = i, date[i] = a[i].v;
	sort(date + 1, date + N + 1);
	int num = unique(date + 1, date + N + 1) - date - 1;
	for(int i = 1; i <= N; i++) a[i].v = lower_bound(date + 1, date + num + 1, a[i].v) - date;
	sort(a + 1, a + N + 1);
	GetL(L); GetR(R);
	//for(int i = 1; i <= N; i++) printf("%d %d\n", L[i], R[i]);
	printf("%d", dp() % mod);
 
}

Measured memory_bytes: 16596
#[allow(unused_imports)]
use std::cmp;
use std::collections::BTreeMap;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    #[allow(unused_mut)]
    let mut s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  input! {
    h: i64,
    w: i64,
    n: usize,
    black: [(i64, i64); n],
  }
  let mut map = BTreeMap::new();
  for &(i, j) in &black {
    let i = i - 1;
    let j = j - 1;
    for ti in cmp::max(1, i-1) .. cmp::min(h-1, i+2) {
      for tj in cmp::max(1, j-1) .. cmp::min(w-1, j+2) {
        if let Some(current) = map.get_mut(&(ti, tj)) {
          *current += 1;
          continue;
        }
        map.insert((ti, tj), 1);
      }
    }
  }
  let mut ans = vec![0i64; 10];
  for &v in map.values() {
    ans[v] += 1;
  }
  let sum: i64 = ans.iter().sum();
  ans[0] = (h - 2) * (w - 2) - sum;
  for &a in &ans {
    println!("{}", a);
  }
}


Measured memory_bytes: 51452
#include <iostream>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;
#define PI 3.14159265
	
int main(void){
	int max=-1000000000;
	int n;
	int min,data;
	cin>>n;
	cin>>min;
	for(int i=0;i<n-1;i++){
		cin>>data;
		if(data-min>max)
			max = data-min;
		if(min>data)
			min = data;
	}
	cout<<max<<endl;
	return 0;
}

Measured memory_bytes: 1164
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
#define fi first
#define se second
#define all(c) c.begin(),c.end()
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void Ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;
const ll mod=1000000007;

int main(){
  int n;
  cin>>n;
  n%=10;
  if(n==2||n==4||n==5||n==7||n==9){
    cout<<"hon"<<endl;
  }
  if(n==0||n==1||n==6||n==8){
    cout<<"pon"<<endl;
  }
  if(n==3){
    cout<<"bon"<<endl;
  }
}

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

#ifdef _PRINTDEBUG
  #include "lib/printdebug.hpp"
#else
  #define printdebug(...) 1
#endif
#define MOD_1_000_000_007 (1000000007)
#define IINF (1<<28)
#define LINF (1LL<<60)
#define rep(i, n)      REP(i, 0, (n))
#define repc(i, n)     REPC(i, 0, (n))
#define REP(i, n, m)   for (int i = (int)(n); i <  (int)(m); i++)
#define REPC(i, n, m)  for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
#define yesno(cond)       YESNO((cond), "Yes", "No")
#define YESNO(cond, a, b) cout << ((cond) ? (a) : (b)) << "\n"

namespace solver {
  using namespace std;
  typedef long long ll;

  string S, T;

  void init() {
    cin >> S;
    cin >> T;
  }

  void solve() {
    yesno(S == T.substr(0, T.size()-1));
  }
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  solver::init();
  solver::solve();
  return 0;
}

Measured memory_bytes: 3656
#include <iostream>

int main() {
	int N, T;
	std::cin >> N >> T;
	int* costs = new int[N];//cost
	int* times = new int[N];//time
	int result = 0;
	for (int i = 0; i < N; i++)
	{
		std::cin >> costs[i] >> times[i];
	}
	for (int i = 0; i < N; i++)
	{
		if (times[i] <= T)
		{
			if (costs[i] < result || result == 0)
			{
				result = costs[i];
			}
		}
	}
	if (result == 0)
	{
		std::cout << "TLE" << "\n";
	}
	else
	{
		std::cout << result << "\n";
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        int k = sc.nextInt();
        for(int i=1;i<=k;i++){
            if(i%2==1){
                if(A%2==1) A--;
                B += A/2;
                A -= A/2;
            } else{
                if(B%2==1) B--;
                A += B/2;
                B -= B/2;
            }
        }
        System.out.print(A);
        System.out.print(" ");
        System.out.print(B);
    }
}


Measured memory_bytes: 21844
import sys
def f(c):
 if sum(c)in c:return 1
 if 5 in c:return 0
 if 4 in c:
  k=c.index(4);c[k]-=3
  if f(c):return 1
  c[k]+=3
 if 3 in c:
  k=c.index(3);c[k]-=3
  if f(c):return 1
  c[k]+=3
 for i in range(7):
  if c[i]and c[i+1]and c[i+2]:
   c[i]-=1;c[i+1]-=1;c[i+2]-=1
   if f(c):return 1
   c[i]+=1;c[i+1]+=1;c[i+2]+=1
n='123456789'
for e in sys.stdin:
 e=list(e)
 a=[i for i in n if f([(e+[i]).count(j)for j in n])]
 if a:print(*a)
 else:print(0)


Measured memory_bytes: 5576
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

//const MAX:usize = 100006;
//const INF:u64 = u64::max_value();

fn main() {
    let mut p:Vec<(i32,i32)> = (0..3).map(|_| {
        let a:i32 = read();
        let b:i32 = read();
        (min(a,b), max(a,b))
        })
        .collect();

    p.sort();
    //debug!(p);

    let mut c:Vec<u32> = vec![0,0,0,0];
    for &(a,b) in p.iter() {
        c[a as usize-1]+=1;
        c[b as usize-1]+=1;
    }
    //debug!(c);

    println!("{}", if c.iter().filter(|&x| *x==3).count() > 0 {"NO"} else {"YES"});

}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> P;
typedef vector<int> Vi;
int const MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { return a = b; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { return a = b; } return false; }

int main(){
  cin.tie(0); ios::sync_with_stdio(false);
    
  Int h,w,ans=MOD; cin>>h>>w;
  for (Int i = 1; i < h; i++){
    chmin(ans,max(i*w,(h-i)*((w%2)?(w/2)+1:w/2))-min(i*w,(h-i)*(w/2)));
    chmin(ans,max(i*w,w*(((h-i)%2)?(h-i)/2+1:(h-i)/2))-min(i*w,w*((h-i)/2)));
  }
  swap(h,w);
  for (Int i = 1; i < h; i++){
    chmin(ans,max(i*w,(h-i)*((w%2)?(w/2)+1:w/2))-min(i*w,(h-i)*(w/2)));
    chmin(ans,max(i*w,w*(((h-i)%2)?(h-i)/2+1:(h-i)/2))-min(i*w,w*((h-i)/2)));
  }
  cout<<ans<<'\n';
}

Measured memory_bytes: 256