akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int n, m;
    cin >> n >> m;

    int lmax = 0, rmin = n;
    for (int i = 0; i < m; i++) {
        int l, r;
        cin >> l >> r;
        lmax = max(l, lmax);
        rmin = min(r, rmin);
    }

    cout << max(rmin - lmax + 1, 0) << "\n";
    return 0;
}

Measured memory_bytes: 888
n = gets.to_i
a = gets.split.map(&:to_i)

a.sort!
b = a.uniq

MAX = 10**6

ok = Array.new(MAX+1, false)

b.each do |x|
    ok[x] = true
end

for i in 0...b.size
    x = b[i]
    j = 2
    while ok[x] && x*j <= MAX
        ok[x*j] = false
        j += 1
    end
end

for i in 0...n
    ok[a[i]] = false if (i != 0 && a[i-1] == a[i]) || (i != (n-1) && a[i] == a[i+1])
end

ans = 0
ok.each do |k|
    ans += 1 if k
end

puts ans

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

#define INF ((1<<30)-1)  //int32_t
#define MOD 1000000007
#define MOD2  

#define all(a)  (a).begin(),(a).end()

#define mkp make_pair
#define pb push_back

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



int main(){
    bool flag=true;
    ll ans=0,sum=0;

    string s,zero="0";
    cin >>s;

    s = to_string(0) + s;

    ll dp[s.size()][13]={};
    dp[0][0] = 1;

    for (int i = 1; i < s.size(); i++){
        for (int j = 0; j < 13; j++){
            
            if(s[i] == '?'){
                for (int ki = 0; ki < 10; ki++){
                    int m = (j*10 + ki)%13;
                    dp[i][m] =(dp[i][m]  + dp[i-1][j])%MOD;
                }
                
            }else{
                int si = (int)(s[i] - '0');
                int m = (j*10 + si)%13;
                dp[i][m] = (dp[i][m] + dp[i-1][j])%MOD;
            }
        }
        
    }

    //cout <<fixed<<setprecision(16)<< << endl;
    cout << dp[s.size()-1][5] << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 10620
N = int(input())
h = list(map(int, input().split()))

dp = [0]*N

for i in range(N):
  if i == 0:
    dp[0] = 0
    continue
  if i == 1:
    dp[1] = abs(h[1]-h[0])
    continue
    
  dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i-2] + abs(h[i]-h[i-2]))

print(dp[N-1])

Measured memory_bytes: 13928
#118_D
ch={1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}

n,m=map(int,input().split())
a=list(map(int,input().split()))

dp=[-1 for _ in range(n+1)]
dp[0]=0
for i in range(1,n+1):
    res=-1
    for x in a:
        if i-ch[x]>=0:
            res=max(res,dp[i-ch[x]]*10+x)
    dp[i]=res
    
print(dp[n])

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

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

        {
            string[] input = Console.ReadLine().Split(' ');
            int D = int.Parse(input[0]);
            int N = int.Parse(input[1]);
            if ( (D == 0) && (N != 100) ) { Console.WriteLine(N);}
            if ( (D == 0) && (N == 100) ) { Console.WriteLine(101);}
            if ( (D == 1) && (N != 100) ) { Console.WriteLine(100*N);}
            if ((D == 1) && (N == 100)) { Console.WriteLine(10100);}
            if ((D == 2) && (N != 100) ) { Console.WriteLine(10000*N);}
            if ((D == 2) && (N == 100)) { Console.WriteLine(1010000);}
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <vector>
#include <queue>
#include <string.h>
using namespace std;

struct edge{int to, cap, rev;};

vector< vector<edge> > G(100);
int level[100];
int iter[100];
int INF = 100000000;

void bfs(int s){
  memset(level, -1, sizeof(level));
  queue<int> que;
  level[s] = 0;
  que.push(s);
  while(!que.empty()){
    int v = que.front();
    que.pop();
    for(int i = 0; i < G[v].size(); ++i){
      edge &e = G[v][i];
      if(e.cap > 0 && level[e.to] < 0){
	level[e.to] = level[v] + 1;
	que.push(e.to);
      }
    }
  }
}

int dfs(int v, int t, int f){
  if(v == t) return f;
  for(int &i = iter[v]; i < G[v].size(); ++i){
    edge &e = G[v][i];
    if(e.cap > 0 && level[v] < level[e.to]){
      int d = dfs(e.to,t,min(f,e.cap));
      if(d > 0){
	e.cap -= d;
	G[e.to][e.rev].cap += d;
	return d;
      }
    }
  }
  return 0;
}

int max_flow(int s, int t){
  int flow = 0;
  for(;;){
    bfs(s);
    if(level[t] < 0) return flow;
    memset(iter,0,sizeof(iter));
    int f;
    while((f = dfs(s,t,INF)) > 0){
      flow += f;
    }
  }
}



int main(){
  int V, E;
  cin >> V >> E;
  int u, v, c;
  for(int i = 0; i < E; ++i){
    cin >> u >> v >> c;
    G[u].push_back((edge){v,c,G[v].size()});
    G[v].push_back((edge){u,0,G[u].size()-1});
  }
  cout << max_flow(0, V-1) << endl;;
  return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const int mod=1000000007;
const int mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

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

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n,m;
	cin >> n >> m;
	cout << n*(n-1)/2+m*(m-1)/2 << endl;
	return 0;
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        x: i64,
        y: i64,
    }

    let mut ans = 0;

    if x <= 3 {
        ans += (4 - x) * 100000;
    }

    if y <= 3 {
        ans += (4 - y) * 100000;
    }

    if x == 1 && y == 1 {
        ans += 400000;
    }

    println!("{}", ans);
}


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

int main(){
    using namespace std;

    unsigned long N;
    cin >> N;

    vector<unsigned long> A(N), B(N);
    for(auto&& i : A)cin >> i;
    for(auto&& i : B)cin >> i;
    unsigned long t{static_cast<unsigned long>(max_element(begin(A), end(A)) - begin(A))};
    rotate(begin(A), begin(A) + t, end(A));
    rotate(begin(B), begin(B) + t, end(B));
    A.push_back(A[0]);
    B.push_back(B[0]);

    vector<unsigned long> C(N + 1);
    C[0] = 10000000000000;
    C[1] = 10000000000000;

    for(unsigned long i{2}; i <= N; ++i)C[i] = 2 * C[i - 1] - 2 * B[i - 1] - C[i - 2];

    for(unsigned long i{0}; i <= N; ++i)A[i] += C[i] -= C.back();

    vector<unsigned long> convex_hull{0, 1};
    const auto& is_convex = [&A](unsigned long i, unsigned long j, unsigned long k) -> bool {
        return j * A[k] + k * A[i] + i * A[j] < j * A[i] + k * A[j] + i * A[k];
    };
    for(unsigned long i{2}; i < N + 1; ++i){
        while(convex_hull.size() >= 2 && !is_convex(convex_hull.end()[-2], convex_hull.end()[-1], i))convex_hull.pop_back();
        convex_hull.push_back(i);
    }
    unsigned long ans{0};
    for(unsigned long i{0}; i + 1 < convex_hull.size(); ++i)ans += (convex_hull[i + 1] - convex_hull[i] + 1) * A[convex_hull[i]] + (convex_hull[i + 1] - convex_hull[i] - 1) * A[convex_hull[i + 1]];

    string S;
    {
        stringstream ss;
        ss << setprecision(12) << ((ans - 2 * accumulate(C.begin(), C.end(), 0UL)) % (2 * N)) / (2.0L * N);
        S = ss.str();
    }
    S.erase(S.begin());
    cout << (ans - 2 * accumulate(C.begin(), C.end(), 0UL)) / (2 * N) << S << endl;

    return 0;
}

Measured memory_bytes: 11368
#include <iostream>
#include <string>
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;

int dp[101010][2][2][2][2][2][2]; // pos, less,has3 ,has5,has7,not 3,5,7, seaquence 0

int main() {
    string A;
    cin >> A;
    int n = A.length();
    int ans = 0;

    dp[0][0][0][0][0][1][1] = 1;
    rep (i, n) {
      rep (j, 2) rep (k, 2) rep (l, 2) rep (m, 2) rep (p, 2) rep(q,2){
          int lim = j ? 9 : A[i] - '0';
          rep (d, lim + 1) {
              (dp[i + 1][j || d < lim][k || d == 3][l || d == 5][m || d == 7][(p||q) && ((d==3) || (d==5) || (d==7))][q && (d==0)] += dp[i][j][k][l][m][p][q]);
          }
      }
    }



    rep(j,2) ans += dp[n][j][1][1][1][1][0];

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


Measured memory_bytes: 256
S = input()

alpha = "abcdefghijklmnopqrstuvwxyz"
c = [0] * 26

for i in range(len(S)):
    for j in range(26):
        if S[i] == alpha[j]:
            c[j] += 1

if max(c) <= 1:
    print("yes")
else:
    print("no")

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

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int a=Integer.parseInt(sc.next());
		if(n==1) {
			if(a==2) {
				System.out.println(3);
			}
			else {
				System.out.println(2);
			}
		}
		else if(n==2) {
			if(a==1) {
				System.out.println(3);
			}
			else {
				System.out.println(1);
			}
		}
		else if(n==3) {
			if(a==1) {
				System.out.println(2);
			}
			else {
				System.out.println(1);
			}
		}
	}
}

Measured memory_bytes: 21844
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif 


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

    string S;  cin >> S;
    int N = S.size();

    const ll MOD = 1e9 + 7;
    const int M = 13;
    vvl dp(N + MGN, vl(M + MGN, 0));
    dp[0][0] = 1;

    int dig = 1;
    for(int i=1; i<=N; i++) {
        if (S[N-i]=='?') {
            for (int d = 0; d<=9; d++) {
                for(int j=0; j<M; j++) {
                    dp[i][(j + d*dig) % M] += dp[i-1][j];
                    dp[i][(j + d*dig) % M] %= MOD;
                }
            }
        } else {
            int d = S[N-i] - '0';
            for(int j=0; j<M; j++) {
                dp[i][(j + d*dig) % M] += dp[i-1][j];
                dp[i][(j + d*dig) % M] %= MOD;
            }
        }

        dig *= 10;
        dig %= M;
    }

    ll ans = dp[N][5];
    cout << ans << endl;

    return 0;
}

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

using namespace std;

int res[64];

int main()
{
  int n;
  memset(res, 0, sizeof res);

  for(int a=0;a<10;a++)
    for(int b=0;b<10;b++)
      for(int c=0;c<10;c++)
	for(int d=0;d<10;d++)
	  res[a+b+c+d]++;
  
  while(scanf("%d", &n) != -1)
    printf("%d\n", res[n]);

  return 0;
}

Measured memory_bytes: 1024
import qualified Data.ByteString.Char8 as B
import Data.Char
import Data.List

a#b = abs$a-b

main = B.interact$B.pack.show.f.unfoldr(B.readInt.B.dropWhile isSpace)
f (n:h1:h2:hv)=snd $ fst $ foldl' proc ((0,h1#h2),take n (h1:h2:hv)) [3..n]
proc ((u1,u2),h1:h2:h3:hv) _ = ((u2, min (u1+h1#h3) (u2+h2#h3)), h2:h3:hv)


Measured memory_bytes: 16764
n = int(input())
z = [list(map(int,input().split())) for _ in range(n)]


def set_height(i,x,y):
	ans = z[i][2] + abs(z[i][0] - x) + abs(z[i][1] - y)
	return ans


answer = 0
for j in range(0,101):
	for k in range(0,101):
		flag = 1
		for l in range(0,n):
			if z[l][2] != 0:
				answer = set_height(l,j,k)
				break

		for l in range(0,n):
			if z[l][2] == 0:
				if answer > set_height(l,j,k):	
					flag = 0
					break
			else:
				if answer != set_height(l,j,k):
					flag = 0
					break
		if flag == 1 and answer > 0 :
			test = map(str,(j,k,answer))
			print(" ".join(test))


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

int main() {
  int N, sum;
  cin >> N;
  int n = N;
  while (n > 0) {
    sum += n % 10;
    n /= 10;
  }
  if (N % sum == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(a,b,c) for(int a=b;a<c;++a)
#define repeq(a,b,c) for(int a=b;a<=c;++a)
#define debug(x) cerr<<(#x)<<": "<<x<<endl
typedef long long ll;
const int B=1e5;
int f[B];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	rep(i,0,B)
		f[i]=0;
	int n, a;
	cin >> n;
	rep(i,0,n)
	{
		cin >> a;
		++f[a];
	}
	int best = 0;
	rep(i,1,B-1)
		best=max(best,f[i-1]+f[i]+f[i+1]);
	cout << best << endl;
}


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

int main(){
	int N;
	cin >> N;
	N%=10;
	if(N==3){
		cout << "bon" << endl;
	}else if(N==0||N==1||N==6||N==8){
		cout << "pon" << endl;
	}else{
		cout << "hon" << endl;
	}
	return 0;
}

Measured memory_bytes: 3584
S = input()
T = input()
#区間を決める
for i in range(len(S)-len(T),-1,-1):
    S_ = S[i:i+len(T)]
    frag = 1
    for j in range(len(T)):
        if S_[j] == T[j] or S_[j] == '?' :
            #print(S_[j],T[j])
            if not j == len(T)-1:
                continue
        else:
            break
            frag = 0
        if frag == 1:
            #print(S_)
            #print(S[:i] ,T ,S[len(T)+2:])
            ans = S[0:i] + T + S[len(T)+i:]
            ans = ans.replace('?','a')
            print(ans)
            exit()
print("UNRESTORABLE")


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

#define all(c) ((c).begin()), ((c).end())
#define dump(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define REP(i, a, b) for (int i = a; i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define mp make_pair
#define fst first
#define snd second
#define pb push_back
#define debug( fmt, ... ) \
        fprintf( stderr, \
                  fmt "\n", \
                  ##__VA_ARGS__ \
        )

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1 << 30;
const double EPS = 1e-10;

double zero(double d) {
    return d < EPS ? 0.0 : d;
}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

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

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &a) {
    os << '[';
    rep(i, a.size()) os << (i ? " " : "") << a[i];
    return os << ']';
}

string toString(int i) {
    stringstream ss;
    ss << i;
    return ss.str();
}

const int MOD = 1000000007;
// a^k
ll fpow(ll a, ll k, int M) {
    ll res = 1ll;
    ll x = a;
    while (k != 0) {
        if ((k & 1) == 1)
            res = (res * x) % M;
        x = (x * x) % M;
        k >>= 1;
    }
    return res;
}

struct prepare {
	prepare() {
	    cout.setf(ios::fixed, ios::floatfield);
	    cout.precision(8);
	    ios_base::sync_with_stdio(false);
	}
} _prepare;

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

    vector<pii> A(N);
    rep(i, N) {
        int t;
        cin >> t;
        A[i] = mp(t, i);
    }

    sort(all(A));

    vi d(N);
    ll ans = 0;
    rep(i, N) {
        d[i] = abs(A[i].second - i);
        if(d[i] % 2 != 0)
            ans++;
    }

    cout << (int)ceil((double)ans/2) << endl;

	
	
    return 0;
}


Measured memory_bytes: 1536
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        int n = sc.nextInt();
        long[] T = new long[n];
        long[] A = new long[n];
        for (int i = 0; i < n; i++) {
            T[i] = sc.nextInt();
            A[i] = sc.nextInt();
        }
        for (int i = 1; i < n; i++) {
            if(A[i-1]>A[i]||T[i-1]>T[i]) {
                long k = max(ceil(A[i - 1], A[i]), ceil(T[i - 1], T[i]));
                //out.println(k);
                A[i] *= k;
                T[i] *= k;
            }
        }
        out.println(A[n-1]+T[n-1]);
    }
    static long ceil(long a,long b){
        return a%b==0?a/b:a/b+1;
    }
}

Measured memory_bytes: 25588
#include <iostream>
#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()
using ll = long long;
using Pair = pair<int, int>;
const ll mod = 1e9 + 7;

struct Edge {
  int to, id;
  Edge(int to, int id): to(to), id(id) {}
  friend ostream& operator<<(ostream& os, const Edge& e) {
    os << "(" << e.to << "," << e.id << ")";
    return os;
  }
};

vector<int> path;
bool dfs(int v, int to, vector<vector<Edge>>& edges, int p=-1) {
  if (v == to) {
    path = vector<int>();
    return true;
  }
  for (auto edge: edges[v]) {
    if (edge.to == p) continue;
    if (dfs(edge.to, to, edges, v)) {
      path.push_back(edge.id);
      return true;
    }
  }
  return false;
}

int lsbpos(int x) {
  int lsb = x&(-x);
  if (!lsb) return -1;
  int i=1, pos=0;
  while (!(lsb&i)) {
    i = i << 1;
    pos++;
  }
  return pos;
}

int main(int argc, char const* argv[])
{
  int n;
  cin >> n;

  vector<vector<Edge>> edges(n+1);

  for (int i = 0; i < n-1; i++) {
    int a, b;
    cin >> a >> b;
    Edge e1(b, i);
    Edge e2(a, i);
    edges[a].push_back(e1);
    edges[b].push_back(e2);
  }

  // // debug
  // cout << endl;
  // for (int i = 0; i < n+1; i++) {
  //   cout << i << ": ";
  //   for (auto edge: edges[i]) {
  //     cout << edge << " ";
  //   } cout << endl;
  // }

  int m;
  cin >> m;
  // 各制約のpathをbitで表現したもの
  vector<ll> constraint(m);

  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;

    // edgesからdfsで経路に含まれるedgeのidのリストを取る
    dfs(u, v, edges);
    // edgeのidに対応するbitを立てる
    for (auto elem: path) {
      constraint[i] |= (ll)1<<elem;
    }
  }

  ll ans = 0;
  for (ll i = 0; i < (ll)1<<m; i++) {
    ll constbit = i;
    ll constcount = __builtin_popcountll(constbit);
    ll edge = 0;

    while(constbit) {
      edge |= constraint[lsbpos(constbit)];
      constbit -= constbit&(-constbit);
    }
    ll white = __builtin_popcountll(edge);
    ll count = (ll)1<<(n-1-white);
    // NOTE: count = 1ll<<(n-1-white); と書いてもいい
    if (constcount%2) ans -= count;
    else ans += count;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()
#define dump(v) (cerr << #v << ": " << v << endl)
#define cerr                                                                   \
  if (true)                                                                    \
  cerr

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;

template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

bool chk(ll N, ll A, ll B, const vector<ll> &h, ll T) {
  ll check = 0;
  REP(i, N) {
    if (h[i] - B * T <= 0)
      continue;
    check += (h[i] - B * T + A - B - 1) / (A - B);
  }
  // cout << T << " " << check << endl;
  return check <= T;
}

void solve(long long N, long long A, long long B, vector<long long> h) {
  ll b = 1L << 30;
  ll ans = (b << 1) - 1;

  for (; b; b >>= 1) {
    ll t = ans - b;
    if (chk(N, A, B, h, t))
      ans = t;
  }

  cout << ans << endl;
}

int main() {
  ios::sync_with_stdio(false);
  long long A;
  long long N;
  long long B;
  cin >> N;
  vector<long long> h(N - 1 + 1);
  cin >> A;
  cin >> B;
  for (int i = 0; i <= N - 1; i++) {
    cin >> h[i];
  }
  solve(N, A, B, h);
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;
  cin >> a ;
  int s1 = a / 100;
  int s2 = (a - s1 * 100) / 10;
  int s3 = a - s1*100 - s2*10;
  cout << s1 + s2 + s3 << endl;
}

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

#define ll          long long
#define F           first
#define S           second
#define pb          push_back
#define mp          make_pair
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define ld             long double
#define hell        1000000007
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen ("input.txt","r",stdin);
    freopen ("output.txt","w",stdout);
    #endif
    ll t = 1;
    // cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        vector<ll>a(n),b(n),c(n);
        for (int i = 0; i < n; ++i)
        {
            /* code */cin>>a[i]>>b[i]>>c[i];
        }

        ll dp[n][3]={0};
        dp[0][0]=a[0];
        dp[0][1]=b[0];
        dp[0][2]=c[0];

        // memset(0,dp,sizeof(dp));

        for (int i = 1; i < n; ++i)
        {
            for (int j = 0; j <= 2; ++j)
            {
                if(j==0)
                {
                    dp[i][j]=max(dp[i-1][1],dp[i-1][2])+a[i];
                }
                else if(j==1)
                {
                    dp[i][j]=max(dp[i-1][0],dp[i-1][2])+b[i];
                }
                else
                    dp[i][j]=max(dp[i-1][1],dp[i-1][0])+c[i];
            }
        }


        cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
        
    }

    
    time
    return 0;
}

Measured memory_bytes: 7944
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll r, d, x;
    cin >> r >> d >> x;
    for(int i = 1; i <= 10; i++) {
        x = r * x - d;
        cout << x << endl;
    }
    return 0;
}


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

int main(){
  int x,y;
  cin>>x>>y;
  if(x>=y){
  cout<<0<<endl;
  return 0;
  }
  else{
  vector<int>z(y);
  for(int i=0;i<y;i++){
  cin>>z[i];
  }
  sort(z.begin(),z.end());
  vector<int>d(y-1);
  for(int j=0;j<y-1;j++){
  d[j]=z[j+1]-z[j];
  }
  sort(d.begin(),d.end());
  int sum=0;
  for(int k=0;k<y-x;k++){
  sum+=d[k];
  }
  cout<<sum<<endl;
  }
}

Measured memory_bytes: 1024
# Template 1.0
import sys, re
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def sortListWithIndex(listOfTuples, idx):   return (sorted(listOfTuples, key=lambda x: x[idx]))
def sortDictWithVal(passedDic):
    temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))
    toret = {}
    for tup in temp:
        toret[tup[0]] = tup[1]
    return toret
def sortDictWithKey(passedDic):
    return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

s, w = MAP()
if(w>=s):
    print("unsafe")
else:
    print("safe")



Measured memory_bytes: 9952
(defvar N (read))

;結果を蓄積してformatするためのリスト
(defvar result nil)

;ウキウキ数の個数を保存する
(defvar arr (make-array '(11 10) :initial-element nil))
;(aref arr K M)はK桁で左端がMであるようなウキウキ数の個数を表す
;11桁以上は見る必要ない(最大で3234566667)

;十分でかい数
(defvar infty (1+ N))


;終了時各桁で行う処理
(defun fin (N) 
  (setf result (cons N result)) 
  nil)

;calcは基本的にはK桁で左端がMのウキウキ数の個数を返す
;但しこれ以上計算する必要のないときはnilを返す
;委託先からnilが返された場合、直ちにMをresultに保存し自分もnilを返す
(defun calc (K M)
  (if (= K 1)
      (if (= N 1) (fin M) 
          (progn (decf N) 1))
      
      ;K > 1の場合
      (cond 
        ((>= (or (aref arr K M) infty) N)
         ;まだcalcしてない OR 答えが近い場合
         (if (setf (aref arr K M)
                   (loop for x from (max 0 (1- M)) to (min 9 (1+ M))
                         with temp
                         if (setf temp (calc (1- K) x))
                         sum temp
                         else do 
                         (return nil)))
             (aref arr K M)
             ;計算委託先でnilが返った場合↓が実行される
             (fin M)))
        
        (t ;雑に計算できる場合
         (decf N (aref arr K M))
         (aref arr K M)))))


(loop named outer
      for K from 1 do 
      (loop for M from 1 to 9
            if (not (calc K M)) do
            (return-from outer (format t "~{~A~^~}" result))))

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

int main(){
  int n;
  cin >> n;
  int ans = -1;
  for(int i = 0; i <= 50000; i++) {
    if(i*27/25 == n) ans = i;
  }
  if(ans == -1) cout << ":(" << endl;
  else cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int INF = 100100100;
const double PI = 3.14159265358979323846;
typedef long long ll;
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define REP(i, n) for (ll i = 0; i < (n); ++i)

int main(void) {
  int n;
  cin >> n;
  int judge = n % 10;
  string s;
  if (judge == 3) {
    s = "bon";
  } else if (judge == 0 || judge == 1 || judge == 6 || judge == 8) {
    s = "pon";
  } else {
    s = "hon";
  }
  cout << s << endl;
  return 0;
}

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

#define INF 1e9
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

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


int main() {
    int x, y;
    cin >> x >> y;
    for (int i = 0; i <= x; i++) {
            if (i * 2 + (x - i) * 4 == y) {
                cout << "Yes" << endl;
                return 0;
            }
    }
    cout << "No" << endl;
}


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


int ans[200000];

void inc(int &x, int max_num) {
	x++;
	if (x > max_num) x = 1;
}


void dfs(int cur, int par, int col, vector<pair<int, int>>* edges, int max_num) {
	for (int i = 0; i < (int)edges[cur].size(); i++) {
		int nxt = edges[cur][i].first, eid = edges[cur][i].second;
		if(nxt == par) continue;		
		ans[eid] = col;
		inc(col, max_num);
		dfs(nxt, cur, col, edges, max_num);
	}
}


int main() {
    int N; cin >> N;
    vector<pair<int, int>> edges[N];
    for (int i = 0; i < N - 1; i++) {
        int a, b; cin >> a >> b; a--; b--;
        edges[a].push_back(make_pair(b, i));
        edges[b].push_back(make_pair(a, i));
    }

    int max_edge_num = 0;
	for (int i = 0; i < N - 1; i++) max_edge_num = max(max_edge_num, (int)edges[i].size());

	dfs(1, -1, 1, edges, max_edge_num);
	
	cout << max_edge_num << endl;
	for (int i = 0; i < N - 1; i++) {
        cout << ans[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 8320
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N=in(),K=in();
	auto H=vecin(N);
	int num=0;
	REP(i,N){
		if(H[i]>=K) num++;
	}
	
	out(num);
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint l, r, d;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> l >> r >> d;
	cout << r/d - (l-1)/d << endl;
	
	return 0;
}

Measured memory_bytes: 3580
#include<stdio.h>
int SelectionSort(int *num,int n)
{
 int i = 0;
 int min = 0;
 int j = 0;
 int tmp = 0;
   int count=0;
 for(i = 0;i < n-1;i++)
 {
 	min = i;//每次讲min置成无序组起始位置元素下标
    for(j = i;j < n;j++)//遍历无序组，找到最小元素。
    {
	  if(num[min]>num[j])
	  {
	   min = j;
	  }
	}
	if(min != i)//如果最小元素不是无序组起始位置元素，则与起始元素交换位置
	{
	  tmp = num[min];
	  num[min] = num[i];
	  num[i] = tmp;
	  count++;
	}
 }
 return count;
}

int main()
{
 int num[1000];
 int n;


  int i = 0;
 scanf("%d",&n);
 for(i=0;i<n;i++)
 scanf("%d",&num[i]);
int count=SelectionSort(num,n);;//这里需要将数列元素个数传入。有心者可用sizeof在函数内求得元素个数。
for(i=0; i<n-1; i++)
            printf("%d ",num[i]);
        printf("%d\n",num[i]);
        printf("%d\n",count);
 return 0;
}



Measured memory_bytes: 2044
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  map<int,int>m;
  bool f=false;
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    a/=400;
    if(a>8)a=8;
    m[a]++;
    if(a<8)f=true;
  }
  int ans=0,diff=0;
  for(auto e:m){
    if(e.second>0)ans++;
    if(e.first>=8)diff+=e.second;
  }
  if(diff==0)cout<<ans<<" "<<ans<<endl;
  else if(f)cout<<ans-1<<" "<<ans-1+diff<<endl;
  else cout<<ans<<" "<<ans+diff-1<<endl;
}


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

int main(){
        int i, len;

        char str[200001];

        scanf("%s", str);

        len=strlen(str);

        for(i=0; i<len; i++){
                if(str[i]=='?'){
                        if(str[i-1]=='P'){
                                str[i]='D';
                        }else{
                                str[i]='D';
                        }
                }
        }

        printf("%s", str);

        return 0;
}


Measured memory_bytes: 1924
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 998244353

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

# 座圧（val→key）
def compress(A):
    sorted_A = sorted(set(A))
    Adict = {val:key for key,val in enumerate(sorted_A)}
    return Adict,len(sorted_A),sorted_A

# Binary Indexed Tree（１点加算）
## 1-indexed
class BIT:
    """
    a[1]~a[n]の数列を想定
    """

    def __init__(self,n):
        self.size = n
        self.tree = [0]*(n+1)
 
    def add(self,index,x):
        """
        a[index]にxを加算
        """
        while index <= self.size:
            self.tree[index] += x
            index += index & (-index)
 
    def sum(self,index):
        """
        a[1]~a[index]の和
        """
        s = 0
        while index:
            s += self.tree[index]
            index -= index & (-index)
        return s
 
    def search(self,value):
        """
        sum(index) >= value を満たす最小のindex
        sum(n) < value のとき n+1 を返す
        """
        i = 0
        s = 0
        step = 1 << (self.size.bit_length() - 1)
        while step:
            if i+step <= self.size and s + self.tree[i+step] < value:
                i += step
                s += self.tree[i]
            step >>= 1
        return i + 1

Q = I()
query = []
for _ in range(Q):
    query.append(list(map(int,(input().split()))))

values = []
for i in range(Q):
    if query[i][0] == 1:
        values.append(query[i][1])

comp,n,values = compress(values)

# 位置の管理用
bit1 = BIT(n)

# 和の管理用
bit2 = BIT(n)

cumb = 0
num = 0
for i in range(Q):
    if query[i][0] == 1:
        cumb += query[i][2]
        val = query[i][1]
        num += 1
        p = comp[val]
        bit1.add(p+1,1)
        bit2.add(p+1,val)
    else:
        med = bit1.search((num+1)//2)
        sum_ = (bit2.sum(n)-bit2.sum(med)) - bit2.sum(med-1)
        minus_num = (bit1.sum(n)-bit1.sum(med)) - bit1.sum(med-1)
        print(values[med-1],sum_+cumb-minus_num*values[med-1])

Measured memory_bytes: 100692
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
#include <stack>

using namespace std;
#define ll long long
#define endl '\n'
#define x first
#define y second
#define pb push_back
#define all(k) (k).begin(),(k).end()
#define fr(i,a,b) for(int i=a;i<=(int)b;i++)
#define rf(i,a,b) for(int i=a;i>=(int)b;i--)
#define db(k) cerr << #k<< " = " << k << endl



#define get(a) scanf("%lld",&a)
int32_t main(){
 	//ios::sync_with_stdio(0); cin.tie(0);
	ll n;
	get(n);
	n--;
	cout<<(1+n)*n/2<<endl;
	
	
	
	
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;

#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second

int main(int argc, char **argv) {
	ll n;
	cin >> n;
	REP(i, 100) REP(j, 100) if (4*i + 7*j == n) {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#

import itertools
from collections import Counter
from collections import defaultdict
import bisect
from heapq import heappush, heappop

def main():
    s = list(input())
    if s[0] == s[1] or s[1] == s[2] or s[2] == s[3]:
        print('Bad')
    else:
        print('Good')


if __name__ == '__main__':
    main()


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

typedef long long LL;
const int N = 100010;

int n;
LL a[N * 3];
LL b[N * 3], c[N * 3];

priority_queue< LL, vector<LL>, greater<LL> > q;
priority_queue< LL, vector<LL>, less<LL> > p;

int main()
{
	scanf("%d",&n);
	for (int i = 1;i <= n * 3; i++)	
		scanf("%d",&a[i]);
	for (int i = 1;i <= n; i++){
		q.push(a[i]);
		b[i] = b[i - 1] + a[i];
	}
	for (int i = n * 3;i >= n * 2 + 1; i--){
		p.push(a[i]);
		c[i] = c[i + 1] + a[i];
	}
	for (int i = n + 1;i <= n * 2; i++){
		if (a[i] > q.top()){
			q.push(a[i]);
			b[i] = b[i - 1] + a[i];
		}
		else b[i] = b[i - 1];
		if (q.size() > n){
			b[i] -= q.top();
			q.pop();
		}
	}
	for (int i = n * 2;i >= n + 1; i--){
		if (a[i] < p.top()){
			p.push(a[i]);
			c[i] = c[i + 1] + a[i];
		}
		else c[i] = c[i + 1];
		if (p.size() > n){
			c[i] -= p.top();
			p.pop();
		}
	}
	LL ans = -90000000000000;
	for (int i = n;i <= n * 2; i++){
		if (b[i] - c[i + 1] > ans)
			ans = b[i] - c[i + 1];
	}
	printf("%lld\n",ans);
	return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> vec(N);
    for (int i = 0; i < N; i++)
    {
        cin >> vec.at(i);
    }
    int cnt = 0, ans = 0;
    for (int i = 0; i < N - 1; i++)
    {
        if (vec.at(i) >= vec.at(i + 1)){
            cnt++;
        }
        else {
            ans = max(ans, cnt);
            cnt = 0;
        }
    }
    ans = max(ans, cnt);
    cout << ans;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace  std;
#define f(i,n) 		for(i=0;i<n;i++)
#define fr(i,n,a) 	for(i=n;i>=a;i--)
#define fa(i,a,n) 	for(i=a;i<n;i++)
#define deb(x)		cout<<#x<<" "<<x<<endl;
#define deb2(x,y)	cout<<#x<<","<<#y<<" "<<x<<","<<y<<endl;
#define buf(x)		cout<<"Check"<<x<<endl;
#define ll			long long int 
#define ft			first
#define s			second
#define pb			push_back
#define mp			make_pair
#define do			double
#define all(v)		v.begin(),v.end()	
#define et(v)		for(auto itr:v)
#define mod			1000000007
inline void p(vector<ll> x,int n)	{	int i;f(i,n)cout<<x[i]<<" ";cout<<endl; }
 

 
void solve()
{  	
	ll N,M,i,j,sum=1,pos,neg=0,z=0,a,b;
	
	cin>>N;

	ll res=(!N);
	cout<<res;
	
}
int main()
{	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
	ll t=1,c=1;
	//cin>>t;
	while(t--)
	{
		
 
		//cout<<"Case #"<<c++<<": "<<endl;
		solve();
		cout<<"\n";
		
	}
	return 0;
}

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

int main(){
 long long A,B,K;
  cin >> A >> B >> K;

  if(K<=A){
    cout << A-K << " " << B << endl;
  }
  
  else if(A+B>K && K>A){
    cout << "0 " << B-K+A << endl;
  }
  
  else if(K>=A+B){
    cout << "0" << " " << "0" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sync                    \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0)
#define ss second
#define ff first
#define ll long long
#define mp make_pair
#define endl "\n"
#define pb push_back
#define ld long double
#define M_PI 3.14159265358979323846
#define puss vector
#define ull unsigned long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i >= (a); --i)

double EPS = 0.0000001;
const ll INF = 1000000007;

using namespace std;

int main(){
    int n;
    cin>>n;
    cout<<24+(24-n);
    return 0;
}


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

#define INT_MAX 2147483647

int main(void){
    int N, M, X, Y;
    scanf("%d%d%d%d", &N, &M, &X, &Y);
    
    int *x, *y;
    x = (int*)malloc(N * sizeof(int));
    y = (int*)malloc(M * sizeof(int));

    int i;
    int x_max = X;
    int y_min = Y;

    for(i=0; i<N; i++) {
        scanf("%d", &x[i]);
        if(x[i] > x_max) {
            x_max = x[i];
        }
    }
    for(i=0; i<M; i++) {
        scanf("%d", &y[i]);
        if(y[i] < y_min) {
            y_min = y[i];
        }
    }

    if(X < Y && x_max < y_min) {
        printf("No War\n");
    }
    else{
        printf("War\n");
    }


    free(x);
    free(y);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int H, W,a[2000][2000], res;
string S[2000];
int main(){
	cin >> H >> W;
	for (int i = 0; i < H; ++i) {
		cin >> S[i];
	}
	for (int i = 0; i < H - 1; ++i) {
		for (int j = 0; j < W - 1; ++j) {
			int t = 0;
			for (int k = 0; k < 4; ++k) {
				if (S[i + k % 2][j + k / 2] == '.')++t;
			}
			if (t == 1 || t == 3) {
				a[i][j] = 1;
			}
		}
	}
	for (int i = 0; i < H; ++i) {
		a[i][W - 1] = 1;
		for (int j = W - 2; j >= 0; --j) {
			if (!a[i][j]) {
				a[i][j] = a[i][j + 1] + 1;
			}
		}
	}
	res = max(H, W);
	for (int i = 0; i < W; ++i) {
		vector<pair<int,int>>vec;
		vec.push_back({ -1,0 });
		for (int j = 0; j < H; ++j) {
			while (vec.back().second > a[j][i]) {
				res = max(res, vec.back().second*(j - vec[vec.size() - 2].first));
				vec.pop_back();
			}
			vec.push_back({ j,a[j][i] });
		}
		while (vec.size() >= 2) {
			res = max(res, vec.back().second*(H - 1 - vec[vec.size() - 2].first));
			vec.pop_back();
		}
	}
	cout << res << endl;
	return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    char s[1200]; cin.getline(s, 1200);
    rep(i,strlen(s)){
        if ('a'<=s[i]&&s[i]<='z'){
            cout<<char(s[i]+('A'-'a'));
        }else if('A'<=s[i]&&s[i]<='Z'){
            cout<<char(s[i]+('a'-'A'));
        }else{
            cout<<s[i];
        }
    }
    cout<<"\n";
    return 0;
}



Measured memory_bytes: 3208
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
typedef struct pp
{   char x[50];
    int t,R;
}S;
S s[105];
bool cmp(S a,S b)
{   if(a.R==b.R)return strcmp(a.x,b.x);
    return a.R>b.R;
}
int main()
{   int i,j,T,n,a,u=0;char x[50];
    scanf("%s",x);
    if(x[0]=='S')printf("Cloudy\n");
    else if(x[0]=='C')printf("Rainy\n");
    else printf("Sunny\n");
    return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(),(a).end()
#define FOR(i,n) for(size_t i=0;i<(n);i++)
#define cinv(v,n) for(size_t i=0;i<(n);i++){cin>>(v)[i];}
#define nvec(type,v,n) vector<type> v(n);cinv(v,n)
#define npairs(type1,type2,v,n) vector<pair<type1,type2>> v(n);for(size_t i=0;i<(n);i++){cin>>v[i].first>>v[i].second;}

#define min_index(v) size_t(min_element(all(v))-(v).begin())
#define max_index(v) size_t(max_element(all(v))-(v).begin())
#define min_e(v) *min_element(all(v))
#define max_e(v) *max_element(all(v))

#define count_le(v,a) size_t(upper_bound(all(v),a)-(v).begin())
#define count_lt(v,a) size_t(lower_bound(all(v),a)-(v).begin())
#define count_ge(v,a) size_t((v).end()-lower_bound(all(v),a))
#define count_gt(v,a) size_t((v).end()-upper_bound(all(v),a))

#define order(neq_sl) [](const auto s, const auto l){return neq_sl;}
#define make_lr(v,type,l,r) vector<type> l(n+1),r(n+1);FOR(i,n){l[i+1]=l[i]+v[i];r[i+1]=r[i]+v[n-1-i];}

#define acm accumulate
#define SUM(v) accumulate(all(v),0l)

int main() {
  int n;
  cin>>n;
  npairs(long,long,v,n);
  sort(all(v),order(s.second<l.second));
  for(size_t i=1;i<n;i++){
    v[i].first+=v[i-1].first;
  }
  FOR(i,n){
    if(v[i].first>v[i].second){
      cout<<"No";break;
    }
    if(i==n-1)cout<<"Yes";
  }
}

Measured memory_bytes: 3328