akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3")

#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/rope"

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define f first
#define s second

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

struct custom_hash 
{
    static uint64_t splitmix64(uint64_t x) 
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const 
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

vector<vector<int>> pts;
int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, d;
    cin >> n >> d;
    pts.assign(n, vector<int>());
    F0R(i, n)
    {
        F0R(j, d)
        {
            int x; cin >> x;
            pts[i].pb(x);
        }
    }
    ll res = 0;
    F0R(i, n - 1)
    {
        FOR(j, i + 1, n)
        {
            ll dist = 0;
            F0R(k, d) dist += (pts[i][k] - pts[j][k]) * (pts[i][k] - pts[j][k]);
            ll d = (ll) sqrt(dist);
            if(dist == d * d) res++;
        }
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 256
program main
  implicit none
  integer :: n, q, l, r, i, j
  character(100000) :: s
  integer, allocatable :: is_a_of_ac(:)

  read (*, *) n, q
  allocate (is_a_of_ac(0:n - 1))
  read (*, *) s

  is_a_of_ac(:) = 0
  do i = 1, n - 1
    if (s(i:i + 1) == "AC") is_a_of_ac(i) = 1
    is_a_of_ac(i) = is_a_of_ac(i) + is_a_of_ac(i - 1)
  end do

  do j = 1, q
    read (*, *) l, r
    write (*, "(i0)") is_a_of_ac(r - 1) - is_a_of_ac(l - 1)
  end do
end program main


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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<double, double> dP;

int main() {
    int n,m;
    cin >> n >> m;
    cout << n*m << endl;
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <vector>
#define SIZE 305

using namespace std;
bool vi[SIZE];
int a[SIZE][SIZE];

int main()
{
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> a[i][j];
	int ans = n;
	for (int i = 1; i <= m; i++) {
		int cnt[SIZE] = { 0 };
		for (int j = 1; j <= n; j++) {
			for (int k = 1; k <= m; k++) {
				if (!vi[a[j][k]]) {
					cnt[a[j][k]]++;
					break;
				}
			}
		}
		int index = -1;
		int n_max = -1;
		for (int j = 1; j <= m; j++) {
			if (cnt[j] > n_max) {
				n_max = cnt[j];
				index = j;
			}
		}
		ans = min(ans, n_max);
		vi[index] = true;
	}
	
	cout << ans << endl;
}

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

int sum_of_digit(string s)
{
  int sum = 0;
  for (int i = 0; i < s.size(); i++)
  {
    sum += (s.at(i) - '0');
  }
  return sum;
}

int main()
{
  while (1)
  {
    string s;
    cin >> s;
    if (s == "0")
    {
      break;
    }
    cout << sum_of_digit(s) << endl;
  }
}


Measured memory_bytes: 3068
#include "bits/stdc++.h"
//#include "atcoder/all"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
//using namespace atcoder;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	if(n == m) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


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

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> h(N);
  for (int i = 0; i < N; i++) {
    cin >> h[i];
  }
  sort(h.begin(), h.end());
  ll ans = INF;
  for (int i = 0; i + K - 1 < N; i++) {
    ans = min(ans, h[i + K - 1] - h[i]);
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

char s[1005];

int main() {
	int k;
	scanf("%d", &k);
	scanf("%s", s);
	
	int l = strlen(s);
	
	if (l <= k) printf("%s\n", s);
	else {
		for (int i = 0; i < k; i++) printf("%c", s[i]);
		printf("...\n");
	}
}


Measured memory_bytes: 3760
#include <stdio.h>

int main(void){
  int fig;
  scanf("%d" ,&fig);
  fig %= 10;
  if(fig == 3){
    printf("bon");
  }else if(fig == 0 || fig == 1 || fig == 6 || fig == 8){
    printf("pon");
  }else{
    printf("hon");
  }
  
  return 0;
}

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

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

Measured memory_bytes: 3600
def solve(s, k):
    z = set()
    for i in range(1, k+1):
        for j in range(len(s)-i+1):
            z.add(s[j:j+i])
    return sorted(list(z))[k-1]


def main():
    s = input()
    k = int(input())
    result = solve(s, k)
    print(result)


if __name__ == "__main__":
    main()


Measured memory_bytes: 66276
N,D = map(int,input().split())

# print(N/(2*D+1))
# print(int(N/(2*D+1)))
if (N/(2*D+1)-int(N/(2*D+1)))>0:
    print(int(N/(2*D+1))+1)
else:
    print(int(N/(2*D+1)))



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

int main() {
    int a, b, c, x;
    cin >> a >> b >> c >> x;

    int cnt = 0;
    for (int i = 0; i <= a; i++) {
        for (int j = 0; j <= b; j++) {
            for (int k = 0; k <= c; k++) {
                if (i * 500 + j * 100 + k * 50 == x) {
                    cnt++;
                }
            }
        }
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
// "header" {{{
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <tuple>

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int> 
#define int long long
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1000000007;

inline double sqrt( const double &x) 
{
	double         xHalf = 0.5 * x;
	int64_t  tmp   = 0x5FE6EB50C7B537AAl - ( *(int64_t*)&x >> 1);
	double         xRes  = * (double*)&tmp;

	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	return xRes * x;
}
// }}}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,a,b,c,d,e;
	cin >> n >> a >> b >> c >> d >> e;
	int minv = min({a,b,c,d,e});
	cout << ((n - minv) + minv - 1) / minv + 5 << '\n'; 
	return 0;	
}


Measured memory_bytes: 256
from collections import defaultdict

N = int(input())
D = list(map(int, input().split()))

MOD = 998244353

p = defaultdict(int)
for d in D:
    p[d] += 1

if p[0] == 1 and D[0] == 0:
    ans = 1
    for i in range(max(D)):
        ans *= pow(p[i], p[i + 1], mod=MOD)
        ans %= MOD
        if ans == 0:
            break

    print(ans)

else:
    print(0)


Measured memory_bytes: 24132
import itertools
def main():
    n,m,k=map(int, input().split())
    a=[int(i) for i in input().split()]
    b=[int(i) for i in input().split()]
    a = [0]+list(itertools.accumulate(a))
    b = [0]+list(itertools.accumulate(b))
    res = 0
    j = m
    best=0
    for i in range(n+1):
        if(a[i]>k):
            break
        while(b[j] > k-a[i]):
            j-=1
        res = max(res,i+j)
    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 41852
#include<stdio.h>

int main(void){
  int N,A,B;
  scanf("%d%d%d",&N,&A,&B);
  if((N*A)>=B){
  printf("%d\n",B);
  }
  if((N*A)<B){
  printf("%d\n",N*A);
  }
   

}

Measured memory_bytes: 128
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	int res = 0;
	int a;
	for (int i = 0; i < n; ++i) {
		cin >> a;
		res ^= a;
	}

	if (res) {
		cout << "No\n";
	} else {
		cout << "Yes\n";
	}

	return 0;

}

Measured memory_bytes: 256
n, k = map(int, input().split())
teleport_list = list(map(int, input().split()))
t_cycle = [1]
c_set = set([1])
now = 1
while len(t_cycle) == len(c_set):
  now = teleport_list[now-1]
  t_cycle.append(now)
  c_set.add(now)

start_cycle = t_cycle[-1]
before_cycle_len = t_cycle.index(start_cycle)
cycle_len = len(t_cycle) - t_cycle.index(start_cycle) - 1

if k <= before_cycle_len:
  print(t_cycle[k])
else:
  print(t_cycle[(k-before_cycle_len)%cycle_len + before_cycle_len])

Measured memory_bytes: 125056
import java.util.Scanner;

public class Main {

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

        int a = sc.nextInt(); int b = sc.nextInt(); int x = sc.nextInt();
        double h = x / ((double)a * (double)a);
        if (h >= b / 2.0) {
            System.out.println(Math.atan2(b - h, a / 2.0) * 180.0 / Math.PI);
        } else {
            System.out.println(Math.atan2(b, 2.0 * x / ((double)a * (double)b)) * 180.0 / Math.PI);
        }
    }

}


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

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N; cin >> N;
  ll ac = 0;
  ll wa = 0;
  ll tle = 0;
  ll re = 0;
  for (ll i = 0; i < N; i++) {
    string S; cin >> S;
    if (S == "AC") {
      ac++;
    }else if (S == "WA") {
      wa++;
    }else if (S == "TLE") {
      tle++;
    }else if (S == "RE") {
      re++;
    }
  }
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;

  return 0;
}



Measured memory_bytes: 3656
import bisect

def main():
    N = int(input())
    L = [int(i) for i in input().split()]
    L.sort()
    count = 0
    for i in range(N-2):
        for j in range(i+1, N-1):
            k = bisect.bisect_left(L, L[i] + L[j])
            k -= 1
            count += k - j
    print(count)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
import java.util.Arrays;
import java.util.Collections;
import java.util.Random;
import java.util.Scanner;

public class Main {

    static class D {
        int x;
        int y;
    }

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

        String s = sc.next();
        char[] chars = s.toCharArray();

        int n = 0;
        for (int i = 0; i < chars.length/2; i++) {
            if(chars[i]!=chars[chars.length-i-1]) n++;
        }
        System.out.println(n);
    }
}


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

ll euclid_gcd(ll A, ll B) {
  while (1) {
    if (A > B && B != 0)  A = A % B;
    if (B > A && A != 0)  B = B % A;
    if (A == B || A == 0 || B == 0)  break;
  }
  return max(A,B);
}

int main() {
  ll A,B;
  scanf("%ld%ld", &A, &B);
  ll gcd = euclid_gcd(A, B);
  int sq = sqrt(gcd), ans = 1;
  for (int i=2; i < sq + 2; i++) {
    if (gcd % i == 0) {
      while (gcd % i == 0)  gcd /= i;
      ans++;
    }
  }
  if (gcd > 1)  ans++;
  cout << ans << endl;
}

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

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

long long MOD = 1000000000 + 7;

int main(){
  cout << setprecision(10);
  int H,W;
  cin >> H >> W;

  vector<vector<int>> left(H, vector<int>(W,0));
  vector<vector<int>> right(H, vector<int>(W,0));
  vector<vector<int>> up(H, vector<int>(W,0));
  vector<vector<int>> down(H, vector<int>(W,0));

  vector<vector<char>> v(H, vector<char>(W));

  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cin >> v.at(i).at(j);
    }
  }

  auto check = [&H,&W](int i, int j){
    if(i < 0 || i >= H ) return false;
    if(j < 0 || j >= W ) return false;
    return true; 
  };

  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      if(v.at(i).at(j) == '#'){
        continue;
      }
      if(check(i,j-1) && v.at(i).at(j-1) == '.'){
        left.at(i).at(j) = left.at(i).at(j-1) + 1;
      } 
      if(check(i-1,j) && v.at(i-1).at(j) == '.'){
        up.at(i).at(j) = up.at(i-1).at(j) + 1;
      } 
    }
  }

  for(int i = H-1; i >= 0; i--){
    for(int j = W-1; j >= 0; j--){
      if(v.at(i).at(j) == '#'){
        continue;
      }
      if(check(i,j+1) && v.at(i).at(j+1) == '.'){
        right.at(i).at(j) = right.at(i).at(j+1) + 1;
      } 
      if(check(i+1,j) && v.at(i+1).at(j) == '.'){
        down.at(i).at(j) = down.at(i+1).at(j) + 1;
      } 
    }
  }

  int max_val = 0;
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      if(v.at(i).at(j) == '#') continue;

      int tmp_val = 1;
      tmp_val += left.at(i).at(j) + right.at(i).at(j);
      tmp_val += up.at(i).at(j) + down.at(i).at(j);

      max_val = max( tmp_val, max_val);
    }
  }
  cout << max_val << endl;

}


Measured memory_bytes: 67200
#include<cstdio>
#include<cstring>
#include<algorithm>
#define clr(x) memset(x,0,sizeof(x))
#define MN 603
using namespace std;
inline int in(){
    int x=0;bool f=0;char c;
    for (;(c=getchar())<'0'||c>'9';f=c=='-');
    for (x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');
    return f?-x:x;
}
const int dx[4]={1,1,-1,-1};
const int dy[4]={1,-1,1,-1};
int col[MN][MN],X[MN],Y[MN],num[4];
int n,m,d1,d2,tot,cnt,res;
bool vis[MN][MN];
inline bool check(int x,int y){
	return ((x>=0)&&(y>=0)&&(x<m)&&(y<m)&&(!vis[x][y]));
}
inline void dfs(int x,int y,bool c){
	vis[x][y]=1;col[x][y]=(col[x][y]<<1)+c;
	for (int i=0;i<cnt;++i)
	for (int j=0;j<4;++j)
	if (check(x+dx[j]*X[i],y+dy[j]*Y[i])) 
	dfs(x+dx[j]*X[i],y+dy[j]*Y[i],c^1);
	
}
inline void sol(int d){
	clr(X);clr(Y);clr(vis);cnt=0;
	for (int i=0;i<m;++i){
		if(i*i>d) break;
		for (int j=0;j<m;++j) 
		if (i*i+j*j==d) X[cnt]=i,Y[cnt]=j,++cnt;
	}
	for (int i=0;i<m;++i)
	for (int j=0;j<m;++j) if (!vis[i][j]) dfs(i,j,0);
}
int main()
{
	n=in();d1=in();d2=in();m=(n<<1);
	sol(d1);sol(d2);tot=0;
	for (int i=0;i<m;++i)
	for (int j=0;j<m;++j) ++num[col[i][j]];
	for (int i=0;i<4;++i) if (num[i]>=n*n) res=i;
	for (int i=0;i<m;++i)
	for (int j=0;j<m;++j){
		if (res==col[i][j]) ++tot,printf("%d %d\n",i,j);
		if (tot==n*n) return 0;
	}return 0;
}

Measured memory_bytes: 15744
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repeq(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define rep1(i,x,n) for(int (i)=(x);(i)<(int)(n);(i)++)
#define rep1eq(i,x,n) for(int (i)=(x);(i)<=(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using Int = long long;

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
typedef pair<int,int> P;
typedef std::priority_queue<int> IntPrioQueue;
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue;

//少数点表示
//cout << std::fixed << std::setprecision(14) << 値

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n-1) cin >> a[i];

    map<int,int> mp;
    rep(i,n-1){
        mp[a[i]]++;
    }

    rep1eq(i,1,n){
        auto itr = mp.find(i);
        if(itr != mp.end()){
            int ans = itr->second;
            cout << ans << endl;
        }else{
            cout << 0 << endl;
        }
    }
    return 0;

}

Measured memory_bytes: 13496
def resolve():
    N, M = map(int, input().split())
    complete = [False] * (N + 1)
    wans= [0] * (N + 1)
    ac = 0
    wc = 0
    for _ in range(M):
        p, ans = input().split()
        p = int(p)
        if complete[p]:
            continue
        if ans == 'AC':
            complete[p] = True
            ac += 1
            wc += wans[p]
        else:
            wans[p] += 1
    print(ac, wc)

resolve()

Measured memory_bytes: 46296
package main

import (
	"bufio"
	"errors"
	"fmt"
	"log"
	"os"
	"strconv"
	"strings"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	line, err := reader.ReadString('\n')
	if err != nil {
		log.Fatalln(err)
	}
	line = strings.Replace(line, "\n", "", -1)

	elems := strings.Split(line, " ")
	s := newStack(100)
	for _, elem := range elems {
		switch elem {
		case "+", "-", "*":
			num1, err := s.pop()
			if err != nil {
				log.Fatalln(err)
			}
			num2, err := s.pop()
			if err != nil {
				log.Fatalln(err)
			}

			switch elem {
			case "+":
				if err := s.push(num2 + num1); err != nil {
					log.Fatalln(err)
				}
			case "-":
				if err := s.push(num2 - num1); err != nil {
					log.Fatalln(err)
				}
			case "*":
				if err := s.push(num2 * num1); err != nil {
					log.Fatalln(err)
				}
			}
		default:
			n, err := strconv.Atoi(elem)
			if err != nil {
				log.Fatalln(err)
			}
			if err := s.push(n); err != nil {
				log.Fatalln(err)
			}
		}
	}
	result, err := s.pop()
	if err != nil {
		log.Fatalln(err)
	}
	fmt.Println(result)
}

type stack struct {
	data []int
	top  int
	max  int
}

func newStack(capacity int) *stack {
	return &stack{
		data: make([]int, capacity),
		top:  -1,
		max:  capacity,
	}
}

func (s *stack) push(n int) error {
	if s.top+1 >= s.max {
		return errors.New("Stack over flow")
	}
	s.top++
	s.data[s.top] = n
	return nil
}

func (s *stack) pop() (int, error) {
	if s.top < 0 {
		return 0, errors.New("Stack under flow")
	}
	ret := s.data[s.top]
	s.top--
	return ret, nil
}


Measured memory_bytes: 1160
def run():
  X = int(input())
  flag = 0
  
  for a in range(-118, 120):
    for b in range(-119, 119):
      if a**5-b**5==X:
        A = a
        B = b
        flag = 1
        break
    if flag==1:
      break
  
  print("{} {}".format(A, B))
  
if __name__ == "__main__":
  run()

Measured memory_bytes: 9096
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <deque>
#include <map>
#include <set>

#define ll long long
#define inf 0x3f3f3f3f
#define il inline

namespace io {

    #define in(a) a=read()
    #define out(a) write(a)
    #define outn(a) out(a),putchar('\n')

    #define I_int ll
    inline I_int read() {
        I_int x = 0 , f = 1 ; char c = getchar() ;
        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 ;
    }
    char F[ 200 ] ;
    inline void write( I_int x ) {
        if( x == 0 ) { putchar( '0' ) ; return ; }
        I_int tmp = x > 0 ? x : -x ;
        if( x < 0 ) putchar( '-' ) ;
        int cnt = 0 ;
        while( tmp > 0 ) {
            F[ cnt ++ ] = tmp % 10 + '0' ;
            tmp /= 10 ;
        }
        while( cnt > 0 ) putchar( F[ -- cnt ] ) ;
    }
    #undef I_int

}
using namespace io ;

using namespace std ;

#define N 100010

ll k = read(), a = read(), b = read();

int main() {
	if(b - a == 1 || k < a || a >= b) {
		printf("%lld\n", k + 1);
		return 0;
	}
	k -= (a - 1);
	ll ans = a;
	ans += k / 2 * (b - a);
	if(k & 1) ++ans;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());
        int n = Integer.parseInt(sc.next());
        int[] nums = {a,b,c};
        Arrays.sort(nums);
        int n_times = 0;
        for (int i = 0; i < n; i++) {
            nums[2] = nums[2] * 2;
        }
        System.out.println(nums[0] + nums[1] + nums[2]);
    }
}


Measured memory_bytes: 20180
#include <iostream>
using namespace std;
int gcd(int a,int b){
    if(a%b)return gcd(b,a%b);
    else return b;
}
int main(){
    int a,b,c;cin>>a>>b>>c;
    cout << a/gcd(a,b)*b/gcd(a,b)*c << endl;
}


Measured memory_bytes: 3108
#include<iostream>
#include<string>
using namespace std;
int main(){
int m;
string s;
string::size_type j;
while(cin>>s){
j=-1;m=0;
while(j=s.find("JOI",j+1),j!=string::npos)m++;
cout<<m<<endl;
j=-1;m=0;
while(j=s.find("IOI",j+1),j!=string::npos)m++;
cout<<m<<endl;
}
return 0;
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
using namespace std;
struct pp
{
  int a,b;
};
pp p[100010];
bool cmp(const pp&a,const pp&b)
{
    if(a.a!=b.a)
    return a.a<b.a;
    return b.a<b.b;
}
int main()
{
    int n,m;
    while(cin>>n>>m)
    {
        for(int i=0;i<m;i++)
            cin>>p[i].a>>p[i].b;
        sort(p,p+m,cmp);
        int Min=p[0].b,s=1;
        for(int i=1;i<m;i++)
        {
            if(p[i].a<Min)
                Min=min(p[i].b,Min);
            else
            {
                Min=p[i].b;
                s++;
            }
        }
        cout<<s<<endl;
    }
    return 0;
}


Measured memory_bytes: 1024
import Control.Applicative

main = do
  [a, op, b] <- words <$> getLine

  if op == "?" then
    return ()
  else do
    print $ calc a op b
    main

calc :: String->String->String->Int

calc a op b
  | op == "+"   = (read a :: Int) + (read b :: Int)
  | op == "-"   = (read a :: Int) - (read b :: Int)
  | op == "*"   = (read a :: Int) * (read b :: Int)
  | op == "/"   = (read a :: Int) `quot` (read b :: Int)
  | otherwise   = 0 

Measured memory_bytes: 3880
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef vector<LL> VI;
typedef vector<VI> VVI;
typedef pair<LL, LL> PII;
typedef vector<string> VS;
inline LL toInt(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(x,c) for(auto x: (c))
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define REVERSE(c) reverse((c).begin(), (c).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define STABLE_SORT(c) stable_sort((c).begin(),(c).end())
#define STABLE_RSORT(c) stable_sort((c).rbegin(),(c).rend())
#define UNIQUE(c) SORT(c); (c).erase(unique((c).begin(), (c).end()), (c).end());
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
const double INF = 1e7;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define dump(x)  cerr << #x << " = " << (x) << endl;


int main() {
	LL N;
	cin >> N;
	VI A(N), B(N), S(N);
	REP(i, N) {
		cin >> A[i] >> B[i];
		S[i] = A[i] + B[i];
	}

	VI index(N);
	REP(i, N) {
		index[i] = i;
	}
	sort(index.begin(), index.end(), [&](LL x, LL y){return S[x] > S[y];});
	
	LL ans = 0;
	for (LL i = 0; i < N; i += 2) {
		ans += A[index[i]];
	}
	for (LL i = 1; i < N; i += 2) {
		ans -= B[index[i]];
	}

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


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int A,B,C,hljs,jz[4][4];
	scanf("%d%d%d",&A,&B,&C);
	hljs=C*3;
	jz[1][1]=A;
	jz[1][2]=B;
	jz[2][2]=C;
	jz[1][3]=hljs-A-B;
	jz[3][1]=hljs-jz[1][3]-C;
	jz[2][1]=hljs-A-jz[3][1];
	jz[2][3]=hljs-C-jz[2][1];
	jz[3][2]=hljs-B-C;
	jz[3][3]=hljs-jz[3][1]-jz[3][2];
	for(int i=1;i<=3;i++)
	{
		for(int j=1;j<=3;j++)
		{
			printf("%d ",jz[i][j]);
		}
		printf("\n");
	}
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>

int main(){
   int N;
   std::cin >> N;

   int a[3];
   a[0] = N/100;
   a[1] = (N - a[0]*100)/10;
   a[2] = N%10;
   int n = a[0];
   if(a[1]>a[0] || a[2]>a[0]) ++n;
   std::cout << n*100 + n*10 + n << std::endl;

   return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define ll long long
#define ull unsigned long long
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define INF (int)1e9+5
using namespace std;
int main(){
	fast;
	int n;
	int k;
	cin>>n;
	cin>>k;
	vector<int> jump;
	jump.pb(-1);
	for(int i=0;i<n;i++){
		int temp;
		cin>>temp;
		jump.pb(temp);
	}
	vector<int> dp(n+1,INF);
	dp[0] = 0;
	dp[1]=0;
	//dp[1] = abs(jump[1]-jump[0]);
	for(int i=2;i<=n;i++){
		//int val2 = dp[i-2]+abs(jump[i] - jump[i-2]);
		for(int j=1;j<=k;j++){
			if(i-j>=1){
				int val = dp[i-j]+abs(jump[i]-jump[i-j]);
				dp[i] = min(dp[i],val);
			}
			else{
				break;
			}
		}
	}
	cout<<dp[n];
	
	return 0;
}


Measured memory_bytes: 1144
#include <bits/stdc++.h>
using namespace std;
int main(){
  
  int N, K;
  cin >> N >> K;
  int x = 1;
  for(int i = 0; i < N; i++){
  if(x <  K){
    x *= 2;
  }else{
    x += K;
  }
 }
  cout << x << endl;
}

Measured memory_bytes: 256
import java.io.BufferedInputStream;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(new BufferedInputStream(System.in));
        int a=sc.nextInt();
        int b=sc.nextInt();
        int flag=0;
        for(int i=b*10;i<=b*10+9;i++)
            if((int)(i*0.08)==a) {
                System.out.println(i);
                flag++;
                break;
            }
        if(flag==0)
            System.out.println("-1");

    }
}

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

int main() {
  string S ;
  cin >> S ;
  int price = 700 ;
  if(S[0]=='o')price+=100;
  if(S[1]=='o')price+=100;
  if(S[2]=='o')price+=100;
  cout << price << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;
  cin >> a;
  int v=0;
  vector<int> j(a);
  for(int i = 0;i < a;i++){
    cin >> j.at(i);}
  vector<int> h(a);
  for(int i = 0;i < a;i++){
    cin >> h.at(i);
  v += h.at(i);}
  vector<int> n(a);
  for(int i = 0;i < a-1;i++){
    cin >> n.at(i);}
  for(int i = 0;i < a-1;i++){
    if(j.at(i)+1==j.at(i+1)){
      v += n.at(j.at(i)-1);}
  }
  cout << v << endl;
  
}

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

B = B[::-1]
A = []
for i in range(N):
  if i == 0:
    A.append(B[0])
  elif i >= N - 1:
    A.append(B[i-1])
  else:
    a = min(B[i],B[i-1])
    A.append(a)
    
print(sum(A))

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

int main() {
    int l, r, d;
    cin >> l >> r >> d;

    int ans = 0;
    for (int i = l; i <= r; i++) {
        if (i % d == 0) ans++;
    }

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


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

int main(){
  int x; cin >> x;
  ll ans = (x/500)*1000 + (x%500)/5*5;
  cout << ans << endl;
    return 0;
}


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

//mod
const int mod = 998244353;
int pow(int x, int y) { //x^y
	int rv = 1;
	for (; y > 0; y >>= 1, x = (long long) x * x % mod)
		if (y & 1)
			rv = (long long) rv * x % mod;
	return rv;
}
int inverce(int x) {
	return pow(x, mod - 2);
}

//comb
const int factMax = 2e5 - 1;
int fact[factMax + 1];
void initializeFact() {
	fact[0] = 1;
	for (int i = 1; i <= factMax; i++)
		fact[i] = (long long) fact[i - 1] * i % mod;
}
int comb(int n, int k) {
	if (k < 0 || n - k < 0)
		return 0;
	int denom = (long long) fact[k] * fact[n - k] % mod;
	return (long long) fact[n] * inverce(denom) % mod;
}
int n, m, k;
long long ans = 0;

int main() {
	initializeFact();

	cin >> n >> m >> k;
	for (int i = 0; i <= k; i++)
		ans += (long long) pow(m - 1, n - 1 - i) * comb(n - 1, i) % mod;
	ans %= mod;
	ans = ans * m % mod;
	if (ans < 0)
		ans += mod;
	cout << ans << endl;
}


Measured memory_bytes: 4412
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class UnionFind():
    def __init__(self):
        self.__table = {}
        self.__size = defaultdict(lambda: 1)
        self.__rank = defaultdict(lambda: 1)

    def __root(self, x):
        if x not in self.__table:
            self.__table[x] = x
        elif x != self.__table[x]:
            self.__table[x] = self.__root(self.__table[x])
        return self.__table[x]

    def root(self, x):
        return self.__table[x]

    def same(self, x, y):
        return self.__root(x) == self.__root(y)

    def union(self, x, y):
        x = self.__root(x)
        y = self.__root(y)
        if x == y:
            return

        if self.__rank[x] < self.__rank[y]:
            self.__table[x] = y
            self.__size[y] += self.__size[x]
        else:
            self.__table[y] = x
            self.__size[x] += self.__size[y]
            if self.__rank[x] == self.__rank[y]:
                self.__rank[x] += 1

    def size(self, x):
        return self.__size[self.__root(x)]

    def num_of_group(self):
        g = 0
        for k, v in self.__table.items():
            if k == v:
                g += 1
        return g

@mt
def slv(N, M, K, AB, CD):
    f = UnionFind()
    for a, b in AB:
        f.union(a, b)

    direct = defaultdict(int)
    for a, b in AB:
        direct[a] += 1
        direct[b] += 1
    block = defaultdict(set)
    for c, d in CD:
        block[c].add(d)
        block[d].add(c)


    ans = []
    for i in range(1, N+1):
        cand = f.size(i)
        for u in block[i]:
            if f.same(i, u):
                cand -= 1
        cand -= direct[i]
        cand -= 1
        ans.append(cand)
    return ans



def main():
    N, M, K = read_int_n()
    AB = [read_int_n() for _ in range(M)]
    CD = [read_int_n() for _ in range(K)]
    print(*slv(N, M, K, AB, CD))

if __name__ == '__main__':
    main()


Measured memory_bytes: 116836
from math import sqrt, floor
q = int(input())
for _ in range(q):
    a, b = map(int, input().split(" "))
    if a == b:
        print(2 * a - 2)
    elif max(a, b) - min(a, b) == 1:
        print(2 * min(a, b) - 2)
    else:
        c = floor(sqrt(a * b))
        if c == sqrt(a*b):
            c -= 1
        if c * (c + 1) >= a * b:
            print(2 * c - 2)
        else:
            print(2 * c - 1)

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


int main() {
  ll a, b;
  cin >> a >> b;
  int k;
  cin >> k;
  for(ll i = a; i <= min(a+k-1,b); ++i){
    cout << i << endl;
  }
  vector<ll> s(k);
  for(ll i = max(b-k+1,a+k); i <= b; ++i){
    cout << i << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>	
#include <limits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <sstream>
#include <iostream>	
#include <algorithm>
#include <functional> 
#include <iomanip>
#include <unordered_map>
#include <fstream>
#include <cstdio>
#include <memory.h>

using namespace std;

int main(void)
{
	int n, t;
	vector <int> a;

	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> t;
		a.push_back(t);
	}
	sort(a.begin(), a.end());
	int sum = 0;
	bool flag = true;
	for (int i = a.size() - 1; i >= 0; i--)
	{
		if (flag == true)
		{
			sum += a[i];
			flag = false;
		}
		else
		{
			sum -= a[i];
			flag = true;
		}
	}
	cout << sum << '\n';
	return 0;
}

Measured memory_bytes: 256
n,q=map(int,input().split())
s=list(input())
li=[0]*n
cnt=0
ans=0

for i in range(n):
  if i==0:
    continue
  if s[i-1]=="A" and s[i]=="C":
    cnt+=1  
  li[i]=cnt
    
for i in range(q):
  l,r=map(int,input().split())
  ans=li[r-1]-li[l-1]
  print(ans)

Measured memory_bytes: 8308
#include<bits/stdc++.h>
using namespace std;
long long ans,n,a[100005];
int main()
{
	cin>>n;
	for(int i=1;i<=n;++i)
	cin>>a[i];
	for(int i=1;i<=n;++i)
	{
		ans+=a[i]/2;
		a[i]%=2;
		if(a[i]&&a[i+1])
		{
			++ans;
			a[i]--;
			a[i+1]--;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+20;
int n,m,a[N];
vector<int> e[N];
int vis[N];
int f[N][15];
struct node{
	int v,d,c;
}q[N];
void fun(int u,int d,int c)
{
	if(f[u][d]!=-1)
		return;
	if(!a[u])//已经被编号大的上过色 
	a[u]=c;
	if(d==0)//边界 
		return;
	for(int i=0;i<e[u].size();i++)
	{
		int v=e[u][i];
		fun(v,d-1,c);
	}
	f[u][d]=1;
}
int main()
{
	while(cin>>n>>m)
	{
		int u,v;
		for(int i=1;i<=n;i++)
			e[i].clear();
		memset(a,0,sizeof(a));
		memset(f,-1,sizeof(f));
		for(int i=0;i<m;i++)
		{
			scanf("%d%d",&u,&v);
			e[u].push_back(v);
			e[v].push_back(u);
		}
		int Q;
		cin>>Q;
		for(int i=0;i<Q;i++)
			scanf("%d%d%d",&q[i].v,&q[i].d,&q[i].c);
		for(int i=Q-1;i>=0;i--)
		{
			fun(q[i].v,q[i].d,q[i].c);
		}
		for(int i=1;i<=n;i++)
			cout<<a[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 23544
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a * b / gcd(a, b);}

ll pow_kai(ll a, ll n) {
    ll x = 1;
    while(n > 0) {
        if(n&1) {
            x = x*a;
        }
        a = a*a;
        n >>= 1;
    }
    return x;
}

int main() {
    int n,m,x,a;
    cin >> n >> m >> x;
    vector<bool> N(n+1, false);
    rep(i,m) {
        cin >> a;
        N[a] = true;
    }
    int cost = 0;
    int cnt1 = 0;
    int cnt2 = 0;
    rep(i,x) {
        if (N[i] == true) {
            cnt1++;
        }
    }
    for(int i=x; i<n+1; ++i) {
        if (N[i] == true) {
            cnt2++;
        }
    }
    cost = min(cnt1, cnt2);
    cout << cost << "\n";

}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define mp make_pair

const int INF = INT_MAX;

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

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

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

	int n, ans;
	cin >> n;

	ans = (n * 360) / gcd(n, 360);

	cout << ans / n << "\n";

	return 0;
}

Measured memory_bytes: 3648
def main():
    _ = int(input())
    ns = list(map(int, input().split(' ')))
    _ = int(input())
    qs = list(map(int, input().split(' ')))
    count = 0
    for q in qs:
        for n in ns:
            if n == q:
                count += 1
                break
    print(count)


if __name__ == '__main__':
    main()



Measured memory_bytes: 6552
#include <iostream>

int fib(int, int[]);

int main()
{
	int n;
	const int size = 44;
	int memo[size + 1];

	for (int i = 0; i < size + 1; i++)
	{
		memo[i] = -1;
	}

	std::cin >> n;

	std::cout << fib(n, memo) << std::endl;

	return 0;
}

int fib(int n, int memo[])
{
	int ans;

	if (n == 0 || n == 1) {
		return 1;
	}
	else {
		if (memo[n] != -1) {
			return memo[n];
		}
		else {
			ans = fib(n - 1, memo) + fib(n - 2, memo);
			memo[n] = ans;
		}
	}

	return ans;
}	

Measured memory_bytes: 3100
def resolve():
    h,w=map(int,input().split())
    mass = []
    length=0
    for i in range(h):
        a=list(input())
        if "#" in a:
            mass.append(a)
            length+=1
    for i in reversed(range(w)):
        total=0
        for j in range(length):
            if mass[j][i]==".":
                total+=1
        if total==length:
            for j in range(length):
                del mass[j][i]
    for i in range(length):
        print("".join(mass[i]))

resolve()

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

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

  // Initialization
  int r_0, r_1;
  cin >> r_0 >> r_1;
  int min_value = min(r_0, r_1);
  int max_delta = r_1 - r_0;

  int r_i;
  for (int i = 0; i < (n - 2); ++i)
  {
    cin >> r_i;

    max_delta = max(max_delta, (r_i - min_value));
    min_value = min(min_value, r_i);
  }

  cout << max_delta << endl;

  return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
 
#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long 
#define ld long double
#define sz(v) int(v.size())
#define all(v) v.begin(), v.end()
 
#define y1 what

using namespace std;
 
const int N = (int) 2e5 + 10;
const int M = (int) 5e5 + 10;
const ll big =  (1LL << 51);
const ll LINF = (ll) 1e18;
const int INF = (int) 1e9 + 7;
const int mod = (int) 1e9 + 7;
const double EPS = (double) 1e-6;
const double PI =  3.14159265359;

int n;
int u[N], v[N];
int pos[N];
int dp[N], pref[N], t[2][N];

bool cmp(int x, int y) {
    return v[x] < v[y];
}

void upd(int row, int x, int y) {
    while (x <= n) {
        if (row == 0)
            t[row][x] = min(t[row][x], y);
        else 
            t[row][x] = max(t[row][x], y);
        x |= x + 1;
    }
}

int get(int row, int x) {
    int ans = (row == 0 ? INF : -INF);
    while (x >= 0) {
        if (row == 0)
            ans = min(ans, t[row][x]);
        else
            ans = max(ans, t[row][x]);
        x &= x + 1, x--;
    }
    return ans;
}

int l[N];

int main() {
    #define fn "balls"
    #ifdef witch
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #else
//        freopen(fn".in", "r", stdin);
//        freopen(fn".out", "w", stdout);
    #endif
    srand(time(0));
    cin >> n;
    vector<int> all;    
    vector<pii> segments;
    for (int i = 1; i <= n; i++) {
        cin >> u[i] >> v[i];
        all.pb(u[i]);
        pos[i] = i;
    }
    sort(all.begin(), all.end());
    for (int i = 1; i <= n; i++) {
        u[i] = upper_bound(all.begin(), all.end(), u[i]) - all.begin();
    }
    sort(pos + 1, pos + n + 1, cmp);
    fill(t[0], t[0] + n + 1, INF);
    fill(t[1], t[1] + n + 1, -INF);
    for (int i = 1; i <= n; i++) {
        l[i] = min(i, get(0, n - u[pos[i]] + 1));
        upd(0, n - u[pos[i]] + 1, i);
    }
    for (int i = n; i >= 1; i--) {
        int r = max(i, get(1, u[pos[i]]));
        segments.pb(mp(l[i], r));
        upd(1, u[pos[i]], i);
    }
    segments.pb(mp(0, 0));
    segments.pb(mp(n + 1, n + 1));
    sort(all(segments));
    dp[0] = pref[0] = 1;
    for (int i = 1, l = 0; i < sz(segments); i++) {
        assert(segments[i - 1].f <= segments[i].f);
        assert(segments[i - 1].s <= segments[i].s);
        while (segments[l].s + 1 < segments[i].f) ++l;
        dp[i] = (pref[i - 1] - (l ? pref[l - 1] : 0) + mod) % mod;
        pref[i] = (pref[i - 1] + dp[i]) % mod;
    }
    cout << dp[sz(segments) - 1];
    return 0;
}

Measured memory_bytes: 9460
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define pb push_back
#define ld long double
#define f first
#define s second
#define in insert
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e18 + 5;
const int mod = 1e9 + 7;
const int  N = 2e5 + 314;
const long double pi = 3.1415926535897932384626433832795;
void solve(){
    int n;
    cin>>n;
    vi v(n);
    for(int i = 0; i < n; i++)cin>>v[i];
    sort(all(v));
    int mn = INF, id = 0;
    for(int i = 0; i < n-1; i++){
        if(mn>abs((v[n-1]+1)/2-v[i])){
            mn=abs((v[n-1]+1)/2-v[i]);
            id=v[i];
        }
    }
    cout<<v[n-1]<<" "<<id;
}
signed main(){
    speed;
    int t=1;
    //cin>>t;
    while(t--)solve();
}

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


int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  int L, R;
  L = A + B;
  R = C + D;
  if (L>R) cout << "Left" << endl;
  else if (L<R) cout << "Right" << endl;
  else cout << "Balanced" << endl;

  return 0;
}


Measured memory_bytes: 3540
# coding: utf-8


def solve(*args: str) -> str:
    n = int(args[0][-1])
    if n == 2 or n == 4 or n == 5 or n == 7 or n == 9:
        ret = 'hon'
    elif n == 0 or n == 1 or n == 6 or n == 8:
        ret = 'pon'
    elif n == 3:
        ret = 'bon'
    return ret


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


Measured memory_bytes: 9180
#include <bits/stdc++.h>
#define INF 2e9
using namespace std;
typedef long long llong;
typedef long double ldouble;
int main()
{
  int N;
  string S, T;
  cin >> N >> S >> T;
  for(int i=0; i<N; i++) cout << S.at(i) << T.at(i);
  cout << endl;
}

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

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

const int MAX { 200010 };
const ll MOD { 1000000007 }, oo { 1LL << 62 };

int solve(int N, const vector<int>& xs)
{
    int m = N + 1, ans = 0;

    for (auto x : xs)
    {
        ans += (x < m ? 1 : 0);
        m = min(m, x);
    }

    return ans;
}

int main()
{
    ios::sync_with_stdio(false);

    int N;
    cin >> N;

    vector<int> xs(N);

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

    auto ans = solve(N, xs);

    cout << ans << '\n';

    return 0;
}


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

int v, e;

int main()
{
    cin >> v >> e;
    vector<vector<ll>> D(v, vector<ll>(v, INF));
    rep(i, e)
    {
        int s, t;
        ll d;
        cin >> s >> t >> d;
        D[s][t] = d;
    }
    rep(k, v) rep(i, v) rep(j, v)
    {
        if (D[i][k] != INF && D[k][j] != INF && D[i][j] > D[i][k] + D[k][j])
        {
            D[i][j] = D[i][k] + D[k][j];
        }
    }
    rep(i, v)
    {
        if (D[i][i] < 0)
        {
            cout << "NEGATIVE CYCLE" << endl;
            return 0;
        }
        D[i][i] = 0;
    }
    rep(i, v) rep(j, v)
    {
        if (D[i][j] == INF)
            cout << "INF";
        else
            cout << D[i][j];
        if (j == v - 1)
            cout << endl;
        else
            cout << " ";
    }
    return 0;
}


Measured memory_bytes: 3232
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i,n) for(int i=0;i<(lint)(n);i++)
#define REP(i,n) for(int i=1;i<=(lint)(n);i++)
#define all(V) V.begin(),V.end()
#define stackReplaceBegin(size)\
	void* p=malloc(size);\
	esp_new=(lint)p+size-1;\
	void * stack_extend_memory_ = malloc(size);\
	void * stack_extend_origin_memory_;\
	char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);\
	*stack_extend_dummy_memory_ = 0;\
	asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
typedef long long lint;
typedef unsigned long long ulint;
typedef std::pair<lint, lint> P;
constexpr int INF = INT_MAX/2;
constexpr lint LINF = LLONG_MAX/2;
constexpr double eps = DBL_EPSILON;
constexpr double PI=3.141592653589793238462643383279;
lint esp_new;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
inline lint gcd(lint a, lint b) {
	while (b) {
		lint c = a;
		a = b; b = c % b;
	}
	return a;
}
inline lint lcm(lint a, lint b) {
	return a / gcd(a, b) * b;
}
bool isprime(lint n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
template<typename T>
T mypow(T a, unsigned int b) {
	if (!b)return T(1);
	if (b & 1)return mypow(a, b - 1) * a;
	T memo = mypow(a, b >> 1);
	return memo * memo;
}
lint modpow(lint a, lint b, lint m) {
	if (!b)return 1;
	if (b & 1)return modpow(a, b - 1, m) * a % m;
	lint memo = modpow(a, b >> 1, m);
	return memo * memo % m;
}
template<typename T>
void printArray(std::vector<T>& vec) {
	rep(i, vec.size() - 1)std::cout << vec[i] << " ";
	std::cout << vec.back() << std::endl;
}
template<typename T>
void printArray(T l, T r) {
	T rprev = r;
	rprev--;
	for (T i = l; i != rprev; i++) {
		std::cout << *i << " ";
	}
	std::cout << *rprev << std::endl;
}
int n,k,p[1010];
int main(){
	std::cin>>n>>k;
	rep(i,n)std::cin>>p[i];
	std::sort(p,p+n);
	int ans=0;
	rep(i,k)ans+=p[i];
	std::cout<<ans<<std::endl;
	return 0;
}


Measured memory_bytes: 3628