akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<math.h>

using namespace std;

typedef unsigned long long ull;
#define B1 100000007
#define B2 1000000007
#define MOD ((1UL<<61)-1)

bool rolling_hash(string const& S, int t_start, int m){
    ull power_of_B_1 = 1, power_of_B_2 = 1;
    int s_start = t_start + m;
    for(int k = 0; k < m; k++){
      power_of_B_1 *= B1, power_of_B_2 *= B2;
    }

    // S[i:]とTの先頭m文字のハッシュ値sh,thを計算
    ull sh1 = 0, sh2 = 0, th1 = 0, th2 = 0;
    for(int k = 0; k < m; k++){
      th1 = th1 * B1 + S[t_start + k], th2 = th2 * B2 + S[t_start + k];
      sh1 = sh1 * B1 + S[s_start + k], sh2 = sh2 * B2 + S[s_start + k];
    }

    for(int k = 0; k + s_start < S.length(); k++){
      if(sh1 == th1 && sh2 == th2) return true;
      if(k + s_start < S.length()){
        sh1 = sh1 * B1 + S[s_start + m + k] - S[s_start + k] * power_of_B_1;
        sh2 = sh2 * B2 + S[s_start + m + k] - S[s_start + k] * power_of_B_2;
      }
    }
  return false;
}

int main(){
  int n;
  string S;
  // 入力
  cin >> n >> S;

  // 一致する最大文字数を２分探索
  int ng = n+1, ok = 0, mid = 0;
  while(ng - ok > 1){
    mid = (ng + ok) / 2;
    bool mached = false;
    // Sのi文字目をtの先頭として,t = S[i:i+mid], s = S[i+mid:]
    for(int i = 0; i < n; i++){
      if(i + mid*2 > n) break;
      if(rolling_hash(S, i, mid)){
        mached = true;
        break;
      }
    }
    if(mached) ok = mid;
    else ng = mid;
  }
  cout << ok << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Comparator;
import java.util.PriorityQueue;
public class Main {
  public static void main(String[] args) {
    Main m = new Main();
    m.run();
  }
  private void run() {
    final long INF = 10000000000L;
    try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in));) {
      int q = Integer.parseInt(br.readLine());
      PriorityQueue<Long> l = new PriorityQueue<>(Comparator.reverseOrder()); l.offer(-INF);
      PriorityQueue<Long> r = new PriorityQueue<>(Comparator.naturalOrder()); r.offer(INF);
      long x = 0L; long y = 0L; long m = 0L;
      for (int k=0;k<q;k++) {
        String[] s = br.readLine().split("\\s+");
        int t = Integer.parseInt(s[0]);
        if (t == 2) {
          System.out.println(m+" "+(x+y));
        } else {
          y += Long.parseLong(s[2]);
          long a = Long.parseLong(s[1]);
          long lb = l.peek();
          long ub = r.peek();
          if (a < lb) {
            x += lb-a;
            r.offer(l.poll());
            l.offer(a); l.offer(a);
          } else if (ub < a) {
            x += a-ub;
            l.offer(r.poll());
            r.offer(a); r.offer(a);
          } else {
            l.offer(a); r.offer(a);
          }
          m = l.peek();
        }
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}

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

// Begin {{{
using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, s, n) for (i64 i = (s); i <= (n); ++i)
#define VAR(Type, ...) Type __VA_ARGS__; IN(__VA_ARGS__)
#define Float(x) OUTN(fixed, setprecision(x));

#ifdef DEBUG
#define dump(...) _dump(#__VA_ARGS__, __VA_ARGS__);
#else
#define dump(...)
#endif

using i64 = int_fast64_t;
using pii = pair<i64, i64>;

template <class A, class B>
inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }

template <class A, class B>
inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

// IN
void IN() {}
template <class Head, class... Tail>
void IN(Head&& head, Tail&&... tail) {
  cin >> head;
  IN(forward<Tail>(tail)...);
}

// OUTS
void OUTS() {}
template <class Head, class... Tail>
void OUTS(Head&& head, Tail&&... tail) {
  cout << head << " \n"[sizeof...(tail)==0];
  OUTS(forward<Tail>(tail)...);
}

template <class T>
void OUTS(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e==&vec.back()]; }

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

// OUTL
void OUTL() {}
template <class Head, class... Tail>
void OUTL(Head&& head, Tail&&... tail) {
  cout << head << "\n";
  OUTL(forward<Tail>(tail)...);
}

template <class T>
void OUTL(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

// OUTN
void OUTN() {}
template <class Head, class... Tail>
void OUTN(Head&& head, Tail&&... tail) {
  cout << head;
  OUTN(forward<Tail>(tail)...);
}

template <class T>
void OUTN(vector<T> &vec) { for (auto &e : vec) cout << e; }

// DEGUG
template <class T>
void _dump(const char *s, T&& x) {
  clog << '{';
  while(*s != '\0') clog << *(s++);
  clog << ": " << x << '}' << "\n";
}

template <class Head, class... Tail>
void _dump(const char *s, Head&& head, Tail&&... tail) {
  clog << '{';
  while(*s != ',') clog << *(s++);
  clog << ": " << head << "}, ";
  for (++s; !isgraph(*s); ++s);
  _dump(s, forward<Tail>(tail)...);
}
// }}} End

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

  VAR(int, N);

  vector<int> a(N);
  rep(i, N) {
    IN(a[i]);
  }

  i64 maxv = 0;
  rep(i, N) {
    rep(j, N) {
      chmax(maxv, abs(a[j] - a[i]));
    }
  }

  OUTL(maxv);
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int k;
	int x;
	int yen=500;
	int sum;
	
	scanf("%d %d",&k,&x);
	sum=k*yen;
	if(x<=sum){
		printf("Yes");
	}
	else{
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 3144
def solve(n,a):
  even = 0
  
  for i in range(n):
    if a[i] % 2 == 0:
      even += 1
  
  return 3**n - 2**even
  
def main():
  N = int(input())
  a = list(map(int,input().split()))
  print(solve(N,a))
  
main()


Measured memory_bytes: 61944
// Problem : C - Many Requirements
// Contest : AtCoder - AtCoder Beginner Contest 165
// URL : https://atcoder.jp/contests/abc165/tasks/abc165_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std; 
#define ll long long int
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define INF LLONG_MAX
#define PI acos(-1)
const ll MOD = 1e9 + 7;
#define fir first
#define sec second
#define all(x) x.begin(),x.end()
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(c,a,b) for(ll c=a;c<b;c++)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define min_heap priority_queue<pll,vector<pll>,greater<pll> >
ll dx4[]={-1,1,0,0};
ll dy4[]={0,0,-1,1};
ll dx8[]={-1,-1,-1,0,1,1,1,0};
ll dy8[]={-1,0,1,1,1,0,-1,-1};
bool isvalid(ll x,ll y,ll n,ll m)
{
    return (x>=0 and y>=0 and x<n and y<m);
}
ll isprime[1000];
vector<ll> prime;
void sievetoprime(ll n)
{
    mem(isprime,true);
    for(ll p=2;p*p<=n;p++)
    {
        if(isprime[p]==true)
        {
            for(ll i=p*p;i<=n;i+=p)
                isprime[i]=false;
        }
    }
}
ll lcm(ll a,ll b)
{
    return (a/__gcd(a,b))*b;
}
ll n,m,q;
ll v[51][4];
ll ans=0;
void check(vector<ll> &a)
{
	ll sum=0;
	rep(i,0,q)
	{
		ll a1=v[i][0],b1=v[i][1],c1=v[i][2],d1=v[i][3];
		if(a[b1]-a[a1]==c1)
			sum+=d1;
	}
	ans=max(ans,sum);
}
void dfs(vector<ll> &curr)
{
	if(curr.size()==n+1)
	{
		check(curr);
		return;
	}
	ll d=curr.back();
	for(ll i=d;i<=m;i++)
	{
		curr.pb(i);
		dfs(curr);
		curr.pop_back();
	}
}
void solve()
{
    cin>>n>>m>>q;
    rep(i,0,q)
    {
    	rep(j,0,4)
    	{
    		cin>>v[i][j];
    	}
    }
    vector<ll> p;
    p.pb(1);
    dfs(p);
    cout<<ans;
}
int main()
{
    ll inpoup = 0;
    if(inpoup==1)
    {
        #ifndef ONLINE_JUDGE
            freopen("input.txt","r",stdin);
            freopen("output.txt","w",stdout);
        #endif
    }
    IOS
    ll t;
    t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
}

Measured memory_bytes: 3684
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<pair<int,int>> vec(n);
  int i;
  for(i=0;i<n;i++){
    cin >> vec.at(i).first;
    vec.at(i).second=i+1;
  }
  sort(vec.begin(),vec.end());
  for(i=0;i<n;i++){
    cout << vec.at(i).second << " ";
  }
}


Measured memory_bytes: 1536
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input! {
        n: usize,
        s: chars,
        t: chars,
    }
    for i in 0..n {
        print!("{}{}", s[i], t[i]);
    }
    println!();
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>> 
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

int N;
  string S;
  cin >> N >> S;
  string mae = S.substr(0, N), ushi = S.substr(N, N);

  // 後ろ文字列たちから得られる反転ペアたちを作っておく
  map<pair<string,string>, long long > ma;
  for (int bit = 0; bit < (1<<N); ++bit) {
    string a = "", b = "";
    for (int i = 0; i < N; ++i) {
      if (bit & (1<<i)) a += ushi[i];
      else b += ushi[i];
    }
    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());
    auto p = make_pair(a, b);
    ++ma[p];
  }

  // 前半文字列から作られるペアが後ろにもあるかどうかを判定する
  long long res = 0;
  for (int bit = 0; bit < (1<<N); ++bit) {
    string a = "", b = "";
    for (int i = 0; i < N; ++i) {
      if (bit & (1<<i)) a += mae[i];
      else b += mae[i];
    }
    auto p = make_pair(a, b);
    res += ma[p];
  }

  cout << res << endl;



}

Measured memory_bytes: 60940
import sys
import decimal # 10進法に変換，正確な計算

def input():
    return sys.stdin.readline().strip()

def main():
    n = int(input())
    s, t = input().split()
    for i in range(n):
        print(s[i], end="")
        print(t[i], end="")
    
    
main()

Measured memory_bytes: 5076
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int D = Integer.parseInt(sc.next());
		int N = Integer.parseInt(sc.next());
		sc.close();

		if(N != 100) {
			int answer = (int)(N * Math.pow(100, D));
			System.out.println(answer);
			return;
		}else {
			int answer = (int)(101 * Math.pow(100, D));
			System.out.println(answer);
			return;
		}
	}

}

Measured memory_bytes: 22100
# -*- coding: utf-8 -*-
"""
Created on Sun Jun 23 09:58:43 2019

@author: Yamazaki Kenichi
"""
import sys

N, K = map(int,input().split())

max_n = ((N - 1) * (N - 2)) // 2

if K > max_n:
    ans = -1
    print(ans)
    sys.exit()

uv = []
for i in range(1,N):
    uv.append([N,i])

link_n = max_n - K
counta = 0
for i in range(1,N):
    for j in range(i+1,N):
        if counta == link_n:
            break
        uv.append([i,j])
        counta += 1
    else:
        continue
    break

M = N - 1 + link_n
print(M)
for c in uv:
    print(c[0],c[1])


Measured memory_bytes: 4128
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=Integer.parseInt(sc.next());
        String s=sc.next();
        sc.close();
        char[] c=s.toCharArray();
        ArrayList<Character> ans=new ArrayList<Character>();
        int left=0;
        int right=0;
        int index=0;
        for(int i=0;i<n;i++){
            ans.add(index, c[i]);
            if(c[i]=='('){
                if(left==right){
                    left++;
                }
                else if(left>right){
                    left++;
                }
            }
            else{
                if(left==right){
                    ans.add(0,'(');
                    index++;
                }
                else if(left>right){
                    right++;
                }
            }
            index++;
        }
        for(int i=0;i<left-right;i++) ans.add(')');
        for(int i=0;i<ans.size();i++) System.out.print(ans.get(i));
    }
}

Measured memory_bytes: 21844
# coding: utf-8
push_alice, remove_alice, push_bob, remove_bob = (int(i) for i in input().split())

if push_alice > push_bob:
    start_time = push_alice
else:
    start_time = push_bob

if remove_alice < remove_bob:
    end_time = remove_alice
else:
    end_time = remove_bob

result = end_time - start_time
if result <= 0:
    print('0')
else:
    print('{0}'.format(result))


Measured memory_bytes: 2940
h, w = map(int, input().split())
relation = []
for i in range(h):
    if i % 2 == 0:
        relation.extend((i, j) for j in range(w))
    else:
        relation.extend((i, j) for j in range(w - 1, -1, -1))
field = [list(map(int, input().split())) for _ in range(h)]

buf = []
for (i1, j1), (i2, j2) in zip(relation, relation[1:]):
    if field[i1][j1] % 2 == 1:
        field[i1][j1] -= 1
        field[i2][j2] += 1
        buf.append((i1 + 1, j1 + 1, i2 + 1, j2 + 1))

print(len(buf))
print('\n'.join(' '.join(map(str, line)) for line in buf))


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

signed main(){

  int n;

  cin >> n;

  int ni=1;

  for(int i=0;i<8;i++){
    if(n < ni){
      cout << ni/2 << endl;
      break;
    }else if(n == ni){
      cout << ni << endl;
      break;
    }else{
      ni = ni * 2;
    }
  }

}

Measured memory_bytes: 3596
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	s, _ := reader.ReadString('\n')
	s = strings.TrimSuffix(s, "\n")

	l := len(s)
	sol1 := make([]byte, l)
	for i := 0; i < l; i++ {
		if i % 2 == 0 {
			sol1[i] = '0'
		} else {
			sol1[i] = '1'
		}
	}
	sol2 := make([]byte, l)
	for i := 0; i < l; i++ {
		if i % 2 == 1 {
			sol2[i] = '0'
		} else {
			sol2[i] = '1'
		}
	}
	c1 := dist(s, string(sol1))
	c2 := dist(s, string(sol2))
	if c1 < c2 {
		fmt.Println(c1)
	} else {
		fmt.Println(c2)
	}

}

func dist(s, t string) int {
	count := 0
	if len(s) != len(t) {
		panic("shit")
	}
	for i := range s {
		if s[i] != t[i] {
			count++
		}
	}
	return count
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    ll a; cin >> a;
    ll b; cin >> b;
    cout << max(ll(0), a-b*2) << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder.ABC105.C
{
    class Program
    {
        static void Main()
        {
            var n = int.Parse(Console.ReadLine());
            Console.WriteLine(Decimal2MinusBinaryNumber(n));
        }

        static string Decimal2MinusBinaryNumber(int num)
        {
            string minusBinaryNumber = null;
            while (num != 0)
            {
                if (num % (-2) != 0)
                {
                    num -= 1;
                    minusBinaryNumber = "1" + minusBinaryNumber;
                }
                else minusBinaryNumber = "0" + minusBinaryNumber;
                num /= (-2);
            }
            return minusBinaryNumber ?? "0";
        }
    }
    class Scanner
    {
        string[] s;
        long i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string Next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return Next();
            i = 0;
            return s[i++];
        }

        public int Nextint()
        {
            return int.Parse(Next());
        }
        public int[] Arrayint(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = Nextint() + add;
            }
            return Array;
        }

        public long NextLong()
        {
            return long.Parse(Next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (long i = 0; i < N; i++)
            {
                Array[i] = NextLong() + add;
            }
            return Array;
        }

        public double NextDouble()
        {
            return double.Parse(Next());
        }

        public double[] ArrayDouble(long N, double add = 0)
        {
            double[] Array = new double[N];
            for (long i = 0; i < N; i++)
            {
                Array[i] = NextDouble() + add;
            }
            return Array;
        }

        public decimal NextDecimal()
        {
            return decimal.Parse(Next());
        }

        public decimal[] ArrayDecimal(long N, decimal add = 0)
        {
            decimal[] Array = new decimal[N];
            for (long i = 0; i < N; i++)
            {
                Array[i] = NextDecimal();
            }
            return Array;
        }
    }
}

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



int mennseki(int x,int y)
{

	int answer = x*y;
		return answer;

}

int A,B,C,D;

int main()
{	
	cin >> A >> B >> C >> D;

	if (mennseki(A, B) > mennseki(C, D))
		cout << mennseki(A, B) << '\n';

	if (mennseki(A, B) < mennseki(C, D))
		cout << mennseki(C, D) << '\n';

	if (mennseki(A, B) == mennseki(C, D))
		cout << mennseki(C, D) << '\n';

	return 0;

}

Measured memory_bytes: 256
t=input()
prevc = t[0]
if t[0]!='?':
  newt=t[0]
else:
  newt="D"
for i in range(1,len(t)):
  if t[i] == '?':
    if prevc == 'P':
      newt+='D'
    else:
      newt+='D'
  else:
    newt+=t[i]
  prevc=newt[i]
print(newt)

  

Measured memory_bytes: 9532
#include <bits/stdc++.h>
#define ll long long

using namespace std;
ll a[10];

int main()
{
    ll n;  cin >> n;
    for(int i = 0;i<5;i++)  cin >> a[i];
    sort(a , a + 5);
    cout << (n - 1)/a[0] + 5;
    return 0;
}


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

//型定義
typedef long long ll;

//定数
const ll INF=1e+18;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

//省略
using vi  = vector<int>;
using vii = vector<vector<int>>;
using vl  = vector<ll>;
using vll = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(){
    ll x;
    cin>>x;
    if(x==0) cout<<1<<endl;
    else cout<<0<<endl;
}

Measured memory_bytes: 3628
# abc 158
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

N, A, B = map(int, readline().split())

answer = int((N / (A + B))) * A
amari = N % (A + B) 

if amari > A:
    answer += A
else:
    answer += amari

print(answer)

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

using namespace std;
const int maxn = 1005;
int h[maxn], mem;
int q[maxn], top;
bool vis[maxn];
vector<int> ans;
int fuck[maxn];
struct E{
    int v, next;
}e[maxn<<1];

void init(){
    memset(h, -1, sizeof(h));
    memset(vis, 0, sizeof(vis));
    mem = 0;
    top = 0;
}

void add(int u, int v){
    e[mem].v = v;
    e[mem].next = h[u];
    h[u] = mem++;
}

bool dfs(int u){
    q[top++] = u;
    vis[u] = 1;
    for(int i=h[u]; i+1; i=e[i].next){
        int v = e[i].v;
        if(!vis[v]){
            if(dfs(v)){
                return true;
            }
        }
        else{
            for(int j=0; j<top; j++){
                if(q[j]==v){
                    for(int k = j; k < top; k ++){
                            ans.push_back(q[k]);
                    }
                    return true;
                }
            }
        }
    }
    top--;
    return false;
}
int main()
{
    int n, m;
    init();
    scanf("%d%d", &n, &m);
    for(int i=1; i <= m; i++){
        int u, v;
        scanf("%d%d", &u, &v);
        add(u, v);
    }
    for(int i=1; i<=n; i++){
        memset(vis, 0 ,sizeof(vis));
        top = 0;
        if(dfs(i)) break;
    }
    while(1){
        int tmp = ans.size();
        memset(fuck, -1, sizeof(fuck));
        for(int i=0;i<ans.size();i++){
            fuck[ans[i]] = i;
//            printf("%d %d\n", ans[i], i);
        }
        for(int i=0;i<ans.size();i++){
            bool shit=false;
            for(int j=h[ans[i]];j+1;j=e[j].next){
                int v = e[j].v;
                if(fuck[v]==-1) continue;
                if(fuck[v]==fuck[ans[i]]+1||(fuck[v]==0&&fuck[ans[i]]==ans.size()-1))
                    continue;
                vector<int> tans;
                if(fuck[v] > fuck[ans[i]]+1){
                    for(int x=0;x<=fuck[ans[i]];x++){
                        tans.push_back(ans[x]);
                    }
                    for(int x=fuck[v];x<ans.size();x++)
                        tans.push_back(ans[x]);
                    ans = tans;
                }
                else{
                    for(int x=fuck[v];x<=fuck[ans[i]];x++){
                        tans.push_back(ans[x]);
                    }
                    ans = tans;
                }
                shit=true;
                break;
            }
            if(shit) break;
        }
        if(tmp==ans.size())
            break;
    }
    if(ans.size()==0){
        printf("-1\n");
    }
    else{
        printf("%d\n",ans.size());
        for(int i=0;i<ans.size();i++){
            printf("%d\n",ans[i]);
        }
    }
    return 0;
}


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

int op(int a, int b) {return max(a, b);}

int e() {return 0;}

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

    int n, k, a, amax=300001;
    cin >> n >> k;
    segtree<int, op, e> seg(amax);
    rep(i, n) {
        cin >> a;
        seg.set(a, seg.prod(max(a-k, 0), min(a+k+1, amax))+1);
    }
    cout << seg.all_prod() << endl;
}

Measured memory_bytes: 8488
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int k,n;
    cin>>k>>n;
    int a[1000000];
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    int maxv=a[1]+(k-a[n]);
    for(int i=1;i<=n-1;i++){
        maxv=max(maxv,abs(a[i]-a[i+1]));
    }
    cout<<k-maxv<<'\n';
    return 0;
}

Measured memory_bytes: 4408
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Numerics;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using static Reader;

public static class P
{
    public static void Main()
    {
        var a = NextInt;
        var b = NextInt;
        var c = NextInt;
        Console.WriteLine(Min(b / a, c));
    }
}


static class Reader
{
    const int BUF_SIZE = 1 << 12;
    static Stream Stream = Console.OpenStandardInput();
    static byte[] Buffer = new byte[BUF_SIZE];
    static int ptr = BUF_SIZE - 1;
    static void Move() { if (++ptr >= Buffer.Length) { Stream.Read(Buffer, 0, BUF_SIZE); ptr = 0; } }

    public static int NextInt
    {
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        get
        {
            int res = 0; while (Buffer[ptr] < 48) Move();
            do { res = res * 10 + (int)(Buffer[ptr] ^ 48); Move(); } while (48 <= Buffer[ptr]);
            return res;
        }
    }
}


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

typedef long long ll;
 
using tpl = tuple<int, int, int>;
typedef pair<int,int> pii;

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}


int N;
ll A[101];

ll ceil_l(ll a, ll b){
    return (a + b - 1) / b;
}

ll fin(){

    ll step = 0;
    while(1){
        {
            ll max_v = -1;
            for(int i = 0; i < N; i++){
                max_v = max(max_v, A[i] );
            }
            if(max_v < N){
                return step;
            }
        }

        int max_idx= -1;
        for(int i = 0; i < N; i++){
            if(A[max_idx] <= A[i]){
                max_idx = i;
            }
        }
        for(int i = 0; i < N; i++){
            if(i == max_idx){
                A[i] -= N;
            }
            else{
                A[i]++;
            }
        }
        step++;
    }
}

int main(){

    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        // cout << A[i] << endl;
    }


    {
        ll max_v = -1;
        for(int i = 0; i < N; i++){
            max_v = max(max_v, A[i]);
        }
        if(max_v <= N - 1){
            cout << 0 << endl;
            return 0;
        }
    }

    ll step = 0;
    while(1){
        sort(A, A + N, greater<ll>());

        if(A[0] <= 2 * N){
            step += fin();
            cout << step << endl;
            return 0;
        }


        // 一番大きい要素からN以内の要素はひとまとめにして扱う
        int less_than_n_index = 0;
        int less_than_n_count = 0;
        for(int i = 1; i < N; i++){
            if(abs(A[0] - N) <= A[i]){
                less_than_n_index = i;
                less_than_n_count++;
            }
        }

        // 最後までいったのであれば、終了
        if(less_than_n_index == N - 1){
            ll min_v = 1LL<<60;
            for(int i = 0; i < N; i++)
                min_v = min(min_v, A[i]);

            ll d = max(0LL, min_v - N);

            step += d * N;
            for(int i = 0; i < N; i++){
                A[i] -= d;
            }

            cout << step + fin() << endl;
            return 0;
        }
        
        // 次の要素との差がN以下、または最大値がN以上となる最小の場所まで移動する
        ll next = A[less_than_n_index + 1];
        
        //  (A[0] - (N - less_than_n_count) * i) -  (next + i) <= N
        //  (N - less_than_n_count + 1) * i)  >= -N - next + A[0]
        // i >= (A[0] - N - next) / (N - less_than_n_count + 1)
        ll j = ceil_l(A[0] - N - next, N - less_than_n_count + 1);
        if(A[0] - (N - less_than_n_count) * j <= N){
            j--;
        }

        for(int i = 0; i < N; i++){
            if(i <= less_than_n_index){
                A[i] -= (N - less_than_n_count) * j;
            }
            else{
                A[i] += j * (less_than_n_count + 1);
            }
        }

        // sort(A, A + N, greater<int>());
        // for(int i = 0; i < N; i++){
        //     cout << A[i] << " ";
        // }
        // cout << endl;

        // cout << j << " " << less_than_n_count + 1 <<  endl;

        step += j * (1 + less_than_n_count);

    }

    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void){

  int n,x,count;
  register int i,j,s;

  while(1){
    count = 0;
    scanf("%d %d",&n,&x);
    if((n == 0) && (x == 0)){
      break;
    }
    for(i = 1;i <= n;i++){
      for(j = i + 1;j <= n;j++){
        for(s = j + 1;s <= n;s++){
          if((i != j) && (j != s)){
            if((i + j + s) == x){
              count++;
            }
          }
        }
      }
    }
    printf("%d\n",count);
  }
  return 0;
}

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

#define range 524289
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define _ <<" "<<

using namespace std;

typedef  long long int ll;
typedef vector <ll> vi;
typedef vector<vi> vvi;
typedef pair <ll, ll> ii;
typedef pair<int, pair<int,int> > iii;
typedef vector<ii> vii;
typedef vector<iii> viii;

vvi dp;
vi a;

int findans(int i, int k){
    if(k<0){
        return 1;
    }
    if(k==0){
        return 0;
    }
    int res = 0;
    // cout<<i<<" "<<k<<endl;
    if(dp[i][k]!=-1) return dp[i][k];
    for (int j = 0; j < a.size(); ++j)
    {
        /* code */
        int temp = findans(1-i, k-a[j]);
        res = res|(!temp);
    }
    return dp[i][k] = res;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	int t = 1;
	// cin>>t;
	while(t--){

        int n, k;
        cin>>n>>k;
        a = vi(n);
        for (int i = 0; i < n; ++i)
        {
            /* code */
            cin>>a[i];
        }
        dp = vvi(2, vi(k+1, -1));
        int res =  findans(0, k);
        if(res) cout<<"First"<<endl;
        else cout<<"Second"<<endl;


	}

    return 0;
}


Measured memory_bytes: 8048
public class Main {

    protected static String calc(String input) {
        final int data = Integer.parseInt(input);

        StringBuilder sb = new StringBuilder();

        for (int i = 1; i <= data; i++) {
            if (check(i)) {
                sb.append(' ');
                sb.append(i);
            }
        }

        return sb.toString();
    }

    static boolean check(int x) {
        if (x % 3 == 0) {
            return true;
        }
        return check0(x);
    }

    static boolean check0(int x) {
        if (x % 10 == 3) {
            return true;
        }
        x /= 10;
        if (x > 0) {
            return check0(x);
        }
        return false;
    }

    public static void main(String[] args) {
        final String line = readLine();
        System.out.println(calc(line));
    }

    private static String readLine() {
        java.util.Scanner s = null;
        try {
            s = new java.util.Scanner(System.in);
            return s.nextLine();
        } finally {
            if (s != null) {
                s.close();
            }
        }
    }
}

Measured memory_bytes: 17988
W=[]
K=[]
for i in range(10):
    S1=int(input())
    W.append(S1)
for j in range(10):
    S2=int(input())
    K.append(S2)
J1=0
J2=0
for k in range(3):
    J1+=max(W)
    W.remove(max(W))
    J2+=max(K)
    K.remove(max(K))
print(J1,J2,sep=' ')  


Measured memory_bytes: 5596
/*

*/
#include<bits/stdc++.h>

using namespace std;
using ll=long long;
#define rep2(i, a, n) for(int i = (a); i < (n); i++)
#define rep(i, n) rep2(i,0,n)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  vector<ll> b(n + 1, 0);
  int mod = 1000000007;

  rep(i,n){
    cin >> a[i];
    b[i + 1] = b[i] + a[i];
  }

  ll ans = 0;

  rep(i,n){
    ll sum = (b[n] - b[i + 1]) % mod;

    ans += a[i] * sum;
    ans %= mod;
  }

  cout << ans << endl;
}

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

int main(){
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;
  if(S[K - 1] == 'A') S[K - 1] = 'a';
  else if(S[K - 1] == 'B') S[K - 1] = 'b';
  else if(S[K - 1] == 'C') S[K - 1] = 'c';
  cout << S << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>

using namespace std;

int main()
{
  uint64_t n, m;
  cin >> n >> m;
  map<uint64_t, uint64_t> mp;
  mp[0] = 1;
  uint64_t accumulate = 0;
  uint64_t ans = 0;
  for (auto i = 0; i < n; i++) {
    uint64_t v;
    cin >> v;
    accumulate += v;
    ans += mp[accumulate % m]++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 4224
import java.util.*;
 
class Main{
    public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		Dice[] xai = new Dice[n];
		for(int i=0; i<n; i++){
			int[] a = new int[6];
			for(int j=0; j<6; j++){
				a[j] = scan.nextInt();
			}
			xai[i] = new Dice(a);
		}

		//??\??????????????????????????????????????°????????´??? "Yes"??????????????????????????\?????????????????´??? "No"?????????
		String ans = "Yes";
		for(int i=0; i<n-1; i++){
			for(int j=1; j<n; j++){
				if(i==j)continue;
				if(xai[i].checkTwoDices(xai[i], xai[j])){
					ans = "No"; //true???????????§????????£????????????No????????????
				}
			}
		}
		System.out.println(ans);
    }
}

class Dice{
	int[] dice;
	public Dice(int[] a){
		dice = new int[6];
		for(int i=0; i<6; i++){
			dice[i] = a[i];
		}
	}
	public void roll(char c){
		int tmp = 0;
		switch(c){
			case 'N':
				tmp = dice[0];
				dice[0] = dice[1];
				dice[1] = dice[5];
				dice[5] = dice[4];
				dice[4] = tmp;
				break;
			case 'W':
				tmp = dice[0];
				dice[0] = dice[2];
				dice[2] = dice[5];
				dice[5] = dice[3];
				dice[3] = tmp;
				break;
			case 'S':
				tmp = dice[0];
				dice[0] = dice[4];
				dice[4] = dice[5];
				dice[5] = dice[1];
				dice[1] = tmp;
				break;
			case 'E':
				tmp = dice[0];
				dice[0] = dice[3];
				dice[3] = dice[5];
				dice[5] = dice[2];
				dice[2] = tmp;
				break;
		}
	}
	public void rotation(){ //???????????????????¨???????????????????
		int tmp = dice[1];
		dice[1] = dice[2];
		dice[2] = dice[4];
		dice[4] = dice[3];
		dice[3] = tmp;
	}

	public boolean checkTwoDices(Dice xai1, Dice xai2){
		if(compareDices(xai1, xai2, 'N', 'W'))return true;
		if(compareDices(xai1, xai2, 'N', 'E'))return true;
		if(compareDices(xai1, xai2, 'S', 'W'))return true;
		if(compareDices(xai1, xai2, 'S', 'E'))return true;
		return false;
	}

	public boolean checkSurface(Dice xai1, Dice xai2){
		if(xai1.dice[0]==xai2.dice[0] && xai1.dice[1]==xai2.dice[1] && xai1.dice[2]==xai2.dice[2] && xai1.dice[3]==xai2.dice[3] && xai1.dice[4]==xai2.dice[4] && xai1.dice[5]==xai2.dice[5]){
			return true;
		}
		return false;
	}

	public boolean compareDices(Dice xai1, Dice xai2, char c1, char c2){
		for(int i=0; i<6; i++){
			for(int j=0; j<6; j++){
				xai2.roll(c1);
				if(checkSurface(xai1, xai2))return true;
				xai2.roll(c2);
				if(checkSurface(xai1, xai2))return true;;
			}
			xai2.rotation();
			if(checkSurface(xai1, xai2))return true;
		}
		return false;
	}

	public int showTop(){
		return dice[0];
	}
}

Measured memory_bytes: 35796
import java.util.Scanner;


	public class Main {

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);

			long k = sc.nextLong();
			long a = sc.nextLong();
			long b = sc.nextLong();
			
			long x = (k+1)/(a+2);
			long rem = k-2*x-a*x+1;
			
			long ret = 0;
			long i = (k-a-1)/2;
			
			if(k==a) {
				System.out.println(k+1);
			}else if(b-a>1) {
				ret = (i+1)*b-i*a+((k-a-1)%2);
				System.out.println(ret);
			}else {
				System.out.println(k+1);
			}
			
		}
		
		
		
	}


Measured memory_bytes: 23252
def check v
	return true if (v&v).count == 1
	return true if v[0]+1==v[1] && v[1]+1==v[2]
	return false
end

gets.to_i.times{
	an=gets.split(" ").map{|e|e.to_i}
	ac=gets.split(" ")
	count=0
	c=[[],[],[]]
	ac.each_with_index{|v,i|
		c[0].concat [an[i]] if v == "R"
		c[1].concat [an[i]] if v == "G"
		c[2].concat [an[i]] if v == "B"
	}
	max=0
	3.times{|i|
		maxCount=0
		c[i].permutation{|pset|
			count=0
			(pset.length/3).times{|t|
				count += 1 if check(pset[3*t..3*t+2])
			}
			maxCount = count if maxCount < count
		}
		max += maxCount
	}
	p 1 if max >= 3
	p 0 if max < 3
}

Measured memory_bytes: 6120
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

template <typename T>
vector<T> Dijkstra(int s, vector<vector<pair<int, T>>> & G, /*vector<int> & prev,*/ const T INF = 1e9){
    using P = pair<T, int>;
    int V = G.size();
    vector<T> dist(V, INF);
    priority_queue<P, vector<P>, greater<P>> que;
    dist[s] = 0;
    que.emplace(0, s);
    //prev.assign(V, -1);
    while(!que.empty()){
        P p = que.top();
        que.pop();
        int v = p.second;
        if(dist[v] < p.first) continue;
        for(int i = 0; i < G[v].size(); i++){
            int to = G[v][i].first;
            T cost = G[v][i].second;
            if(dist[to] > dist[v] + cost){
                dist[to] = dist[v] + cost;
                //prev[to] = v;
                que.emplace(dist[to], to);
            }
        }
    }
    return dist;
}

signed main() {
    int n, x, y;
    cin >> n >> x >> y;
    x--;
    y--;
    vector<vector<P>> G(n);
    rep(i, n - 1) {
        G[i].emplace_back(i + 1, 1);
        G[i + 1].emplace_back(i, 1);
    }
    G[x].emplace_back(y, 1);
    int ans[n] = {};
    rep(i, n) {
        vector<int> dist = Dijkstra(i, G, INF);
        for (int j = i + 1; j < n; j++){
            ans[dist[j] - 1]++;
        }
    }
    rep(i, n - 1) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Array;
using static AtCoder.Tool;
namespace AtCoder
{
    class AC
    {
        const int MOD = 1000000007;
        const int INF = int.MaxValue / 2;
        const long SINF = long.MaxValue / 2;
        const double EPS = 1e-8;
        static readonly int[] dx = { 0, 1, 0, -1 };
        static readonly int[] dy = { 1, 0, -1, 0 };
        static List<List<int>> G = new List<List<int>>();
        //static List<List<Edge>>G = new List<List<Edge>>();
        //static List<Edge> E = new List<Edge>();

        static void Main(string[] args)
        {
            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);
            var cin = new Scanner();

            int N = int.Parse(Console.ReadLine());
            var s = Console.ReadLine();
            var t = Console.ReadLine();
            if (s == t) { Console.WriteLine(s.Length);return; }
            for (var i = 1; i < N; i++)
            {
                //Console.WriteLine($"{s.Substring(i)} {t.Substring(0, N - i)}");
                if (s.Substring(i) == t.Substring(0, N - i))
                {
                    Console.WriteLine((s + t.Substring(N - i)).Length); return;
                }
            }
            Console.WriteLine((s + t).Length);

            //Console.Out.Flush();
        }
        struct Edge
        {
            public int from;

            public int to;
            public long dist;
            public Edge(int t, long c)
            {
                from = -1;
                to = t;
                dist = c;
            }
            public Edge(int f, int t, long c)
            {
                from = f;
                to = t;
                dist = c;
            }

        }
    }
    public class Scanner
    {
        public int[] ReadSplit()
        {
            return ConvertAll(Console.ReadLine().Split(), int.Parse);
        }
        public long[] ReadSplitL()
        {
            return ConvertAll(Console.ReadLine().Split(), long.Parse);
        }
        public double[] ReadSplitD()
        {
            return ConvertAll(Console.ReadLine().Split(), double.Parse);
        }
    }
    public static class Tool
    {
        static public void Initialize<T>(ref T[] array, T initialvalue)
        {
            for (var i = 0; i < array.Length; i++)
            {
                array[i] = initialvalue;
            }
        }
        static public void Swap<T>(ref T a, ref T b)
        {
            T keep = a;
            a = b;
            b = keep;
        }

        static public void Display<T>(T[,] array2d, int n, int m)
        {
            for (var i = 0; i < n; i++)
            {
                for (var j = 0; j < m; j++)
                {
                    Console.Write($"{array2d[i, j]} ");
                }
                Console.WriteLine();
            }
        }

        static long LPow(int a, int b)
        {
            return (long)Pow(a, b);
        }
    }
}


Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
#define sz(V) ((int)V.size())

vector<pii> S;
int x[200009], y[200009], K[200009], c;

void er(int i) {
	--K[S[i].second];
	if(!K[S[i].second]) --c;
}

void ad(int i) {
	++K[S[i].second];
	if(K[S[i].second] == 1) ++c;
}

int main() {
	int rn = 1e9, rx = -1e9, bn = 1e9, bx = -1e9;
	int N; scanf("%d",&N);
	for(int i=1; i<=N; i++) {
 		scanf("%d%d", &x[i], &y[i]);
 		if(x[i] > y[i]) swap(x[i], y[i]);
 		rn = min(rn, x[i]); rx = max(rx, x[i]);
 		bn = min(bn, y[i]); bx = max(bx, y[i]);
 		S.push_back({x[i], i});
 		S.push_back({y[i], i});
	}
	long long ans = 1LL * (rx - rn) * (bx - bn);
	sort(S.begin(), S.end());
	for(int i=0, j=0; i<sz(S); i++) {
		if(i) er(i-1);
		while(j < sz(S) && c < N) ad(j++);
		if(c == N) ans = min(ans, 1LL * (bx - rn) * (S[j-1].first - S[i].first));
	}
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 7536
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

S = list(s())
T = list(s())
N = len(S)
ans = 0
for i in range(N):
    if S[i] != T[i]:
        ans += 1
print(ans)

Measured memory_bytes: 13040
//2018.12.15 by ljz
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define LL long long
#define inf 0x3f3f3f3f
#define eps 1e-15
inline int read(){
    res s=0;
    bool w=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')w=1;ch=getchar();}
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=getchar();
    return w?-s:s;
}
inline void _swap(res &x,res &y){
    x^=y^=x^=y;
}
inline int _abs(const res &x){
    return x>0?x:-x;
}
inline int _max(const res &x,const res &y){
    return x>y?x:y;
}
inline int _min(const res &x,const res &y){
    return x<y?x:y;
}
const int N=2e5+10;
namespace MAIN{
    int n,a[N];
    struct P{
        int len,val,l,r;
        P() {}
        P(res len,res val,res l,res r):len(len),val(val),l(l),r(r) {}
    }pos[N];
    int tot;
    bool judge(res x,res lim){
        if(!x)return 0;
        if(pos[x].len>1){
            pos[++tot]=P(1,pos[x].val,x,pos[x].r),pos[pos[x].r].l=tot,pos[x].r=tot,pos[x].len--;
            return judge(tot,lim);
        }
        pos[x].val++;
        if(pos[x].val<=lim)return 1;
        pos[x].val=1;
        return judge(pos[x].l,lim);
    }
    inline bool check(res lim){
        tot=1;
        res now=1;
        pos[1]=P(a[1],1,0,0);
        for(res i=2,len=a[1];i<=n;i++){
            if(a[i]>len){
                pos[++tot]=P(a[i]-len,1,now,0),pos[now].r=tot;
                len=a[i],now=tot;
            }
            else {
                while(len>a[i]){
                    if(pos[now].len>len-a[i])pos[now].len-=len-a[i],len=a[i];
                    else len-=pos[now].len,now=pos[now].l;
                }
                if(pos[now].len>1){
                    pos[++tot]=P(1,pos[now].val,now,0),pos[now].r=tot,pos[now].len--;
                    now=tot;
                }
                if(!judge(now,lim))return 1;
            }
        }
        return 0;
    }
    bool flag=0;
    inline void MAIN(){
        n=read();
        for(res i=1;i<=n;i++){a[i]=read();if(a[i]<=a[i-1])flag=1;}
        if(!flag){puts("1");return;}
        res l=2,r=n;
        while(l<r){
            res mid=(l+r)>>1;
            if(check(mid))l=mid+1;
            else r=mid;
        }
        printf("%d\n",l);
    }
}
int main(){
    MAIN::MAIN();
    return 0;
}

Measured memory_bytes: 4224