akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

constexpr ll MOD = 1000000007;

#ifndef ONLINE_JUDGE
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
#else
#define print(...)
#endif

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

    ll n;
    
    cin >> n;

    ll ans = 1;

    for(ll i=0; i<n; i++){
        ll a;
        cin >> a;

        //print(a);
        if(a == 0 || ans == 0)
            ans = 0;
        else if(ans > 0){
            //print(1000000000000000000.0/a, ans);
            if(1000000000000000000.0/a >= ans)
                ans*=a;
            else
                ans=-1;
            
        }
        
    }
    if(0 > ans || 1000000000000000000 < ans)
        ans=-1;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3656
N = int(input())
saying =[]
people =[]
result = 0

for i in range(N):
    A=int(input())
    people.append(0)
    saying.append([])
    for j in range(A):
        x, y = map(int,input().split())
        saying[i].append(x)
        saying[i].append(y)

for i in range(2**N):

    for j in range(N):
        if(i & 1<<j):
            people[j]=1
        else:
            people[j]=0
    honest = 0
    for j in range(N):
        if people[j]==1:
            for k in range(0, len(saying[j]),2):
                if people[saying[j][k]-1] != saying[j][k+1]:
                    break
            else:
                honest += 1
                continue
            break
    else:
        if honest>result:
            result = honest

print(result)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define clr(arr, x) memset(arr, x, sizeof arr)
#define endl "\n"
#define Accepted 0

const int N = 1e5 + 500;
int n, cap;
vector<pair<long long , long long>> v;
long long mem[108][N];
long long Knapsack(int idx, int curcap)
{
	if (idx == n)
		return 0;

	long long& ret = mem[idx][curcap];
	if (~ret)
		return ret;

	ret = Knapsack(idx + 1, curcap);
	if (curcap - v[idx].first >= 0)
		ret = max(ret, v[idx].second + Knapsack(idx + 1, curcap - v[idx].first));

	return ret;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	clr(mem, -1);
	cin >> n >> cap;
	v = vector<pair<long long, long long>>(n);
	for (int i = 0; i < n; i++)
		cin >> v[i].first >> v[i].second;

	cout << Knapsack(0, cap) << endl;
	return Accepted;
}


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

int main(void)
{
    int N; cin >> N;
    int W[N];
    int allsum = 0;
    int sum1 = 0;
    int sum2 = 0;
    int dif = 10000;
    for(int i = 0; i < N; i++) {
        cin >> W[i];
        allsum += W[i];
    }
    for(int i = 0; i < N-1; i++){
        sum1 += W[i];
        sum2 = allsum - sum1;
        if(abs(sum1-sum2) < dif) dif = abs(sum1-sum2);
    }
    cout << dif << endl;

    return 0;
}

Measured memory_bytes: 256
def solve(N,a):
  visited = [False]*N
  h = 0
  cnt = 0
  while True:
    if visited[h]:
      return -1
    visited[h] = True
    if h == 1:
      return cnt
    cnt += 1
    h = a[h]

N=int(raw_input())
a=[None]*N
for i in xrange(N):
  a[i] = int(raw_input())-1
print solve(N,a)
 

Measured memory_bytes: 6532
# AOJ 0539: Pizza
# Python3 2018.7.1 bal4u

import sys
from sys import stdin
input = stdin.readline
import bisect

while True:
	d = int(input())
	if d == 0: break
	n, m = int(input()), int(input())
	p = [0] + [int(input()) for i in range(n-1)] + [d]
	p.sort()
	ans = 0
	for i in range(m):
		k = int(input())
		if k > 0:
			t = bisect.bisect_left(p, k)
			ans += min(k-p[t-1], p[t]-k)
	print(ans)


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

using ll  = long long;
using vl  = vector<ll>;
using vvl = vector<vl>;
#define rng(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define DEBUG(x) cerr<<__LINE__<<": "<<#x<<" = "<<x<<"\n"

const int inf = 1e9+10;
const int mod = 1e9+7;
struct mint {
    ll x;
    mint(ll x=0) : x((x%mod+mod)%mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (t == 0) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint &operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};
istream& operator>>(istream& i, mint& var) {
    ll tmp; i >> tmp;
    var.x = tmp;
    return i;
}
ostream& operator<<(ostream& o, const mint& var) {
    o << var.x;
    return o;
}

mint ans;
vector<mint> pow2;
int N;
vl size;
vvl edges;

void dfs(int v, int pre) {
    size[v] = 1;
    mint cnt = pow2[N-1];
    for (auto to : edges[v]) {
        if (to == pre) continue;
        dfs(to, v);
        size[v] += size[to];
        cnt -= pow2[size[to]] - 1;
    }
    cnt -= pow2[N - size[v]];
    ans += cnt;
}

int main() {
    cin >> N;
    edges.resize(N);
    size.resize(N);
    pow2.assign(N+1, 1);
    rep(i,N-1) {
        int a, b; cin >> a >> b;
        a--; b--;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }
    rep(i,N) pow2[i+1] = pow2[i] * 2;

    int root = 0;
    dfs(root, -1);
    ans /= pow2[N];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 25728
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define Sort(x) sort((x).begin(), (x).end())
#define Reverse(x) reverse((x).begin(), (x).end())
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15) //15桁まで表示
#define str string
typedef std::pair<int,int> pii;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<ui,ui> puu;
typedef pair<int, int> P;
typedef vector<int> vi;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};
int floor(int a,int b){return (a+b-1)/b;};
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
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;};

int main() {
    str a,b;
    cin >> a>>b;
    if (a=="H"){cout << b << endl;}
    else if(b=="H"){cout << 'D' << endl;}
    else{cout << 'H' << endl;}
}

Measured memory_bytes: 256
import sys


def count_ways(n, x):
    count = 0
    for i in range(1, n - 1):
        for j in range(i + 1, n):
            rest = x - i - j
            if j < rest <= n:
                count += 1
    return count


for line in sys.stdin:
    n, x = map(int, line.strip().split())
    if n == x == 0:
        break
    print(count_ways(n, x))



Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    long a=0;
    cin >> n;
    vector<int> va(n);
    for (int i=0; i<n; i++)
        cin >> va[i];
    sort(va.begin(), va.end(), [](int a, int b){return a>b;});
    for (int i=0; i<n; i++) {
        if (i % 2 == 1)
            a -= va[i];
        else
            a += va[i];
    }
    cout << a << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

H, W = get_ints
A = []
H.times do |i|
  A[i] = get_ints
end

ax = A.map do |arr|
  arr.map { |a| a % 2 }
end

odd_nums = ax.sum do |arr|
  arr.count { |a| a == 1 }
end

position = [0, 0]
last_position = [H-1, (H % 2 == 0) ? 0 : W-1]
moves = []

while !(position[0] == last_position[0] && position[1] == last_position[1])
  y, x = position

  if (y % 2 == 0 && x == W-1) || (y % 2 == 1 && x == 0)
    position[0] += 1
  elsif y % 2 == 0
    position[1] += 1
  else
    position[1] -= 1
  end
  y_dash, x_dash = position

  if ax[y][x] == 1
    moves.push([[y, x], [y_dash, x_dash]])
    ax[y_dash][x_dash] = (ax[y_dash][x_dash] + 1) % 2
  end
end

puts moves.length
moves.each do |from, to|
  puts "#{from[0]+1} #{from[1]+1} #{to[0]+1} #{to[1]+1}"
end


Measured memory_bytes: 45528
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;

string n;

int main(){
    cin>>n;

    rep(i,3){
        if(n[i]=='1') n[i]='9';
        else n[i]='1';
    }

    cout<<n<<endl;
}

Measured memory_bytes: 256
H, W = list(map(int, input().split()))
C = []
for _ in range(10):
    row = list(map(int, input().split()))
    C.append(row)

number_count = {i: 0 for i in range(10)}
for _ in range(H):
    row = list(map(int, input().split()))
    for num in row:
        if num == -1:
            continue
        number_count[num] += 1

for k in range(10):
    for i in range(10):
        for j in range(10):
            C[i][j] = min(C[i][j], C[i][k] + C[k][j])

# for row in C:
    # print(' '.join(map(str, row)))

# print(number_count)
result = 0
for k, v in number_count.items():
    result += C[k][1] * v

print(result)


Measured memory_bytes: 68060
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 400020
inline int read(){
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){
        if(c=='-')f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9'){
        x=(x<<3)+(x<<1)+c-'0';
        c=getchar();
    }
    return x*f;
}
char s[N];
int n,k,c,pos[N],dp[N],las[N],tot[N];
int main(){
	n=read(),k=read(),c=read();
	scanf("%s",s+1);
	int now=1;
	pos[0]=-c;
	int i=1;
	while(now<=n){
		while(now<=n&&s[now]=='x')las[now]=pos[i-1],tot[now]=i-1,++now;
		las[now]=pos[i-1],tot[now]=i-1;
		pos[i]=now;
		for(int j=1;j<=c+1;++j){
			++now;
			tot[now]=i,las[now]=pos[i];
		}
		++i;
	}
	for(int i=n;i>=1;--i){
		if(s[i]=='x')dp[i]=dp[i+1];
		else dp[i]=dp[i+c+1]+1;
	}
	for(int i=1;i<=n;++i){
		if(s[i]=='x')continue;
		if(tot[i]+dp[max(i+1,las[i]+c+1)]<k){
			printf("%d\n",i);
		}
	}
//	getchar();getchar();getchar();
	return 0;
}


Measured memory_bytes: 7040
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
	int n,m;
	char map[110][110];
	memset(map,'0',sizeof(map));
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			cin>>map[i][j];
		}
	}
	for(int i=0;i<=n+1;i++)
	{
		for(int j=0;j<=m+1;j++)
		{
			if(map[i][j]=='0') cout<<"#";  
			else cout<<map[i][j];
			if(j==m+1) cout<<endl; 
		}
	}
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
a = [list(map(int, input().split())) for _ in range(3)]
dx = [0] * 2
dy = [0] * 2
for i in range(2):
  dx[i] = a[0][i + 1] - a[0][i]
for i in range(2):
  dy[i] = a[i + 1][0] - a[i][0]
for i in range(3):
  for j in range(2):
    if a[i][j + 1] - a[i][j] != dx[j]:
      print("No")
      exit(0)
for i in range(3):
  for j in range(2):
    if a[j + 1][i] - a[j][i] != dy[j]:
      print("No")
      exit(0)
print("Yes")


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

using namespace std;


int main()
{
	int n,k;
	cin >> n >> k;
	int arr[n];
	for(int i = 0; i < n; i++) cin >> arr[i];
	int ans = -1, l = 1, r = (int)1e9+7;
	auto possible = [&](int x){
		int cnt = 0;
		for(int len : arr){
			cnt += (len-1)/x;
		}
		return cnt <= k;
	};
	while(l <= r){
		int mid = l+(r-l)/2;
		if(possible(mid)){
			ans = mid;
			r = mid-1;
		}
		else l = mid+1;
	}
	cout << ans;
}


Measured memory_bytes: 4340
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
char a[N];
int vis[2019];
int main() {
  ios::sync_with_stdio(false);
  cin>>a+1;LL ans=0;
  int n=strlen(a+1);
  vis[0]=1;
  int res=0;
  LL bas=1;
  for(int i=n;i>=1;i--){
  	res=res+(a[i]-'0')*bas;
  	res%=2019;
  	ans+=vis[res];
  	vis[res]++;
  	bas*=10;
  	bas%=2019;
  }
  cout<<ans<<'\n';
 	return 0;
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
int main(){
  vector<vector<int>> A(3,vector<int>(3));
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin>>A.at(i).at(j);
    }
  }
  int N;
  cin>>N;
  int count = 0;
  vector<int> B(N);
  vector<vector<int>> C(3,vector<int>(3));
  for(int i=0;i<N;i++){
    cin>>B.at(i);
    for(int j=0;j<3;j++){
      for(int k=0;k<3;k++){
        if(B.at(i)==A.at(j).at(k)){
          C.at(j).at(k)++;
        }
      }
    }
  }
  
  bool ok = false;
  
  int sum0 = 0;
  for(int i=0;i<3;i++){
    sum0+=C.at(0).at(i);
  if(sum0==3){
    ok = true;
  }
  }
  
  
  int sum1 = 0;
  for(int i=0;i<3;i++){
    sum1+=C.at(1).at(i);
  if(sum1==3){
    ok = true;
  }
  }
  
  int sum2 = 0;
  for(int i=0;i<3;i++){
    sum2+=C.at(2).at(i);
  if(sum2==3){
    ok = true;
  }
  }
  
  int sum3 = 0;
  for(int i=0;i<3;i++){
    sum3+=C.at(i).at(0);
  if(sum3==3){
    ok = true;
  }
  }
  
  int sum4 = 0;
  for(int i=0;i<3;i++){
    sum4+=C.at(i).at(1);
  if(sum4==3){
    ok = true;
  }
  }
  
  int sum5 = 0;
  for(int i=0;i<3;i++){
    sum5+=C.at(i).at(2);
  if(sum5==3){
    ok = true;
  }
  }
  
  int sum6 = 0;
  sum6 = C.at(0).at(0)+C.at(1).at(1)+C.at(2).at(2);
  if(sum6==3){
    ok = true;
  }
 
  int sum7 = 0;
  sum7 = C.at(0).at(2)+C.at(1).at(1)+C.at(2).at(0);
  if(sum7==3){
    ok = true;
  }
  
  
  if(ok){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var min = 30; // 今回はceil(log2(最大値))なら何でもいいです

            var N = cin.ReadInt;
          	var array = cin.ReadIntArray(N);
            for (int i = 0; i < N; ++i)
            {
                var A = array[i];
                var c = 0;
                while (A % 2 == 0 && A != 0) { A /= 2; ++c; }
                min = Min(min, c);
            }
            WriteLine(min);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}


Measured memory_bytes: 13268
data class Bridge(val start: Int, val end: Int)

fun main(args: Array<String>) {
    val (n, m) = readLine()?.split(" ")?.map { it.toInt() } ?: return
    val bridges = (0 until m)
        .map {
            val (a, b) = readLine()?.split(" ")?.map { it.toInt() }!!
            Bridge(a, b)
        }

    val counter = mutableListOf<Int>().apply {
        for (i in 0 until n) add(0)
    }
    for (bridge in bridges) {
        counter[bridge.start - 1]++
        counter[bridge.end - 1]++
    }
    counter.withIndex().forEach { println("${it.value}") }
}

Measured memory_bytes: 36112
N = int(input())

ansA = {}
for ch in "abcdefghijklmnopqrstuvwxyz":
  ansA[ch] = 100
temp = {}
for ch in "abcdefghijklmnopqrstuvwxyz":
  temp[ch] = 0

for i in range(N):
  for ch in "abcdefghijklmnopqrstuvwxyz":
    temp[ch] = 0
  st = input()
  for ch in st:
    temp[ch] = temp[ch] + 1
  
  for ch in "abcdefghijklmnopqrstuvwxyz":
    ansA[ch] = min(ansA[ch], temp[ch])
    
for ch in "abcdefghijklmnopqrstuvwxyz":
  print( ch * ansA[ch], end="")
  
  

Measured memory_bytes: 3064
def solve(n)
    lop = 0
    while n >= 10
        s = n.to_s
        n = 0
        (s.size-1).times do |i|
            u,v = s[0..i].to_i, s[(i+1)..-1].to_i
            n = [n,u*v].max
        end
        lop += 1
    end
    lop
end

gets.to_i.times do
    n = gets.to_i
    p solve(n)
end


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

int main() {
	int n, k;
	cin >> n >> k;
	int h[n];
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}

	sort(h, h+n);
	int min = 1e9;
	for (int i = 0; i < n-k+1; i++) {
		if (h[i+k-1] - h[i] < min) {
			min = h[i+k-1] - h[i];
		}
	}
	cout << min << endl;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define N 105
using namespace std;
typedef pair<int,int> P;

vector<int> G[2][N*N];
string s[N];
int num[N][N], idx;
int dy[4]={-1,0,1,0};
int dx[4]={0,1,0,-1};
int h, w;    

void make_graph(){
  
  set<P> memo;
  
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      for(int k=0;k<4;k++){
	int ni=i+dy[k], nj=j+dx[k];
	if(ni<0||nj<0||h<=ni||w<=nj) continue;
	if(num[i][j]!=num[ni][nj]){
	  if(memo.count(P(num[i][j],num[ni][nj]))) continue;
	  memo.insert(P(num[i][j],num[ni][nj]));
	  memo.insert(P(num[ni][nj],num[i][j]));
	  G[idx][num[i][j]].push_back(num[ni][nj]);
	  G[idx][num[ni][nj]].push_back(num[i][j]);
	}
      }
  
}

void dfs(int y, int x, int cnt, int c){
  
  if(num[y][x]!=-1) return;
  num[y][x]=cnt;
  
  if(!c){
    for(int i=0;i<4;i++){
      int ny=y+dy[i], nx=x+dx[i];
      if(ny<0||nx<0||h<=ny||w<=nx) continue;
      if(s[ny][nx]=='.') dfs(ny, nx, cnt, c);
    }
  }else{
    for(int i=-1;i<=1;i++){
      for(int j=-1;j<=1;j++){
	if(i==0&&j==0) continue;
	int ny=y+i, nx=x+j;
	if(ny<0||nx<0||h<=ny||w<=nx) continue;
	if(s[ny][nx]=='#') dfs(ny, nx, cnt, c);
      }
    }
  }
  
}

string get_tree(int x, int px, int id){
  
  vector<string> S;

  int flag=0;
  
  for(int i=0;i<G[id][x].size();i++){

    int nx=G[id][x][i];

    if(nx==px) continue;
    
    S.push_back(get_tree(nx, x, id));
    
    flag=1;
  }

  if(!flag) return "10";
  
  sort(S.begin(),S.end());
  
  string res;

  for(int i=0;i<S.size();i++) res+=S[i];
  
  return "1"+res+"0";
}

void solve(){

  if(get_tree(0,-1,0)==get_tree(0,-1,1)) cout<<"yes"<<endl;
  else cout<<"no"<<endl;
  
}

string tmp[N];

int main(){
  
  while(1){
    
    cin>>h>>w;
    if(!h&&!w) break;
    
    for(int i=0;i<h+2;i++)
      for(int j=0;j<w+2;j++) s[i]+='.';
    
    for(int i=1;i<=h;i++) cin>>tmp[i], tmp[i]="x"+tmp[i];
    
    for(int i=1;i<=h;i++)
      for(int j=1;j<=w;j++) s[i][j]=tmp[i][j];

    memset(num,-1,sizeof(num));
    
    h+=2; w+=2;
    
    int cnt=0;
    
    idx=0;
    
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	if(num[i][j]!=-1) continue;
	if(s[i][j]=='.') dfs(i,j,cnt++,0);
	else dfs(i,j,cnt++,1);
      }
    }
    
    make_graph();
    
    for(int i=0;i<N;i++) s[i]="";
    
    cin>>h>>w;
    
    for(int i=0;i<h+2;i++) 
      for(int j=0;j<w+2;j++) s[i]+='.';
    
    for(int i=1;i<=h;i++) cin>>tmp[i], tmp[i]="x"+tmp[i];
    
    for(int i=1;i<=h;i++)
      for(int j=1;j<=w;j++) s[i][j]=tmp[i][j];
    
    memset(num,-1,sizeof(num));
    
    h+=2; w+=2;
    
    cnt=0;
    
    idx=1;
    
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	if(num[i][j]!=-1) continue;
	if(s[i][j]=='.') dfs(i,j,cnt++,0);
	else dfs(i,j,cnt++,1);
      }
    }
    
    make_graph();

    solve();
    
    for(int i=0;i<2;i++)
      for(int j=0;j<N*N;j++) G[i][j].clear();
    
    for(int i=0;i<N;i++) s[i]="";
  }
  
  return 0;
}

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

const int INF = 2e9;

int main(){
    string s;
    cin >> s;
    if(s == "Sunny")cout << "Cloudy" << endl;
    if(s == "Cloudy")cout << "Rainy" << endl;
    if(s == "Rainy")cout << "Sunny" << endl;
}

Measured memory_bytes: 256
<?php
  $n = trim(fgets(STDIN));
  $l = explode(" ", trim(fgets(STDIN)));
  sort($l);
  $ans = 0;
  for($i=0; $i<$n; $i++){
      for($j=$i+1; $j<$n; $j++){
          for($k=$j+1; $k<$n; $k++){
              if($l[$i] != $l[$j] && $l[$j] != $l[$k] &&
                 $l[$i] + $l[$j] > $l[$k]){
                     $ans++;
                 }
          }
      }
  }
  echo $ans;

Measured memory_bytes: 16252
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <cmath>
#include <algorithm>
#include <set>
#define ll long long
#define INF 1000000000
#define MOD 1
#define SIZE 100001
using namespace std;

int n,ta,ao,a,b;
vector<int>v[SIZE];


vector<int> d(int x){
	vector<int>distance(n,INF);
	vector<bool>visited(n);
	priority_queue<pair<int,int> >q;
	q.push(make_pair(0,x));
	distance[x]=0;
	while(!q.empty()){
		a=q.top().second;q.pop();
		if(visited[a]){continue;}
		visited[a]=1;
		for (int i=0; i<v[a].size(); i++){
			b=v[a][i];
			if(distance[a]+1<distance[b]){
				distance[b]=distance[a]+1;
				q.push(make_pair(-distance[b],b));
			}
		}
	}
	
	return distance;
	
}


int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cin>>n>>ta>>ao;ta--;ao--;
  if(n==2){cout<<0;return 0;}
  for (int i=0; i<n-1; i++){
	  cin>>a>>b;
	  a--;b--;
	  v[a].push_back(b);
	  v[b].push_back(a);
  }
  vector<int>td(n),ad(n);
  td=d(ta);
  ad=d(ao);
  int ans=0;
  for (int i=0; i<n; i++){
	  if(td[i]<ad[i]){
		  ans=max(ans,ad[i]-1);
	  }
  }
  cout<<ans;
}



Measured memory_bytes: 7896
#include <iostream>
#include <vector>
#include <cmath>

std::vector<long long> divisors(long long n) {
	std::vector<long long> ret(1, 1);
	long long m = sqrt(n);
	for (long long i = 2; i <= m; i++) {
		if (n % i == 0) ret.push_back(i);
	}
	if (m == sqrt(n)) {
		for (long long i = ret.size() - 2; i >= 0; i--) {
			ret.push_back(n / ret[i]);
		}
	} else {
		for (long long i = ret.size() - 1; i >= 0; i--) {
			ret.push_back(n / ret[i]);
		}
	}
	return ret;
}

std::vector<long long> comdiv(long long a, long long b) {
    if (a > b) std::swap(a, b);
    std::vector<long long> v = divisors(a);
    std::vector<long long> ret(1, 1);
    for (long long i = 1; i < v.size(); i++) {
        if (b % v[i] == 0) ret.push_back(v[i]);
    }
    return ret;
}

bool is_prime(long long n) {
    if (n == 1) return false;
    if (n == 2) return true;
    if (n % 2 == 0) return false;
    for (long long i = 3; i <= sqrt(n); i += 2) {
        if (n % i == 0) return false;
    }
    return true;
}

int main() {
    long long a, b;
    std::cin >> a >> b;
    std::vector<long long> v = comdiv(a, b);
    long long ans = 1;
    for (auto i : v) {
        if (is_prime(i)) ans++;
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 3700
#include<iostream>
using namespace std;
int main(){
	int c,sum=0;
	int koka[]={1,5,10,50,100,500};
	for(int i=0;i<6;i++){
		cin>>c;
		sum+=c*koka[i];
	}
	cout<<(sum>=1000?"1":"0")<<endl;
	return 0;
}

Measured memory_bytes: 1160
#include <algorithm>
#include <iostream>
#include <numeric>
#include <set>
#include <vector>
using namespace std;

static int solve(const int *const begin, const int *const end, const int k) {
    int res = 0;

    auto max_extract = min((int)(end - begin), k);

    for (int n_ab = 1; n_ab <= max_extract; n_ab++) {
        for (int n_a = 0; n_a <= n_ab; n_a++) {
            auto neg_values = multiset<int>();
            auto n_b = n_ab - n_a;
            auto n_cd = k - n_ab;
            auto left_value = 0;
            for (int i = 0; i < n_a; i++) {
                left_value += begin[i];
                if (begin[i] < 0)
                    neg_values.insert(begin[i]);
            }
            auto right_value = 0;
            for (int i = 0; i < n_b; i++) {
                right_value += end[-1 - i];
                if (end[-1 - i] < 0)
                    neg_values.insert(end[-1 - i]);
            }

            auto sum = left_value + right_value;
            auto n_back = min((int)neg_values.size(), n_cd);
            auto itr = neg_values.begin();
            for (int i = 0; i < n_back && itr != neg_values.end(); i++) {
                sum -= *itr;
                ++itr;
            }

            res = max(res, sum);
        }
    }

    return res;
}

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

    constexpr int big_enough = 1'000;
    auto v = vector<int>(big_enough);
    auto left = big_enough / 2;
    auto right = left;
    for (int i = 1; i <= n; i++) {
        int v_i;
        cin >> v_i;
        v[right++] = v_i;
    }

    cout << solve(v.data() + left, v.data() + right, k);
    return 0;
}


Measured memory_bytes: 256
_, s = input(), input()
cnt = 0
for i in range(1000):
    t = "{:0>3}".format(i)
    ss = s
    if t[0] not in ss:
        continue
    ss = ss[ss.index(t[0]) + 1:]
    if t[1] not in ss:
        continue
    ss = ss[ss.index(t[1]) + 1:]
    if t[2] not in ss:
        continue
    cnt += 1
print(cnt)

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

int main(int argc, char const *argv[])
{
    string s;
    cin >> s;
    int b=0;
    int r=0;
    for(int i=0;i<s.length();++i){
        if(s[i]=='1')++b;
    }
    r=s.length()-b;
    r >= b ? cout << b*2 << endl : cout << r*2;
    return 0;
}


Measured memory_bytes: 512
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		double [] in = new double [a];
        for(int i=0;i<a;i++){in[i] = sc.nextDouble();
                             String s = sc.next();
                             if(s.equals("BTC")){in[i]*=380000;}
                            }
        double ans = 0;
		
        for(int i=0;i<a;i++){ans+=in[i];
                            }
        
		System.out.println(ans);
	}
}


Measured memory_bytes: 24660
s = input().rstrip().split(' ')
N = int(s[0])
K= int(s[1])
Hs = list(map(int, input().rstrip().split(' ')))

Hs = sorted(Hs, reverse=True)
count = 0

for h in Hs:
    if K == 0:
        count = count + h
    else:
        K = K - 1
print(count)


Measured memory_bytes: 26360
#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(),(a).end()
#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 ntuples(type1,type2,type3,v,n) vector<tuple<type1,type2,type3>> v(n);for(size_t i=0;i<(n);i++){cin>>get<0>(v[i])>>get<1>(v[i])>>get<2>(v[i]);}

#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) acm(all(v),0l)

int main() {
  int n;
  cin>>n;
  nvec(long,a,n);
  int count=0;
  for(int i=0;i<n;i++){
    while(a[i]%2==0){
      a[i]/=2;
      count++;
    }
  }
  cout<<count;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main()
  {int N; cin >> N;
  vector<int> As(N), Bs(N);
  for (int i = 0; i < N; ++i) cin >> As[i] >> Bs[i];
  sort(As.begin(), As.end()); sort(Bs.begin(), Bs.end());
  int m = (N - 1) / 2, L = As[m], R = Bs[m];
  if (N % 2 == 0)
    {L += As[m + 1]; R += Bs[m + 1];}
  cout << R - L + 1 << endl;}

Measured memory_bytes: 4836
#include <stdio.h>
#include <stdlib.h>
typedef long long ll;

ll LCM(ll a, ll b)
{
    ll x = a * b, r = a % b;
    while (r != 0)
    {
        a = b;
        b = r;
        r = a % b;
    }
    return (x / b);
}

ll solve(ll num, ll c, ll d)
{
    return (num / LCM(c, d) - num / c - num / d);
}

int main(void)
{
    ll a, b, c, d;

    scanf("%lld%lld%lld%lld", &a, &b, &c, &d);

    printf("%lld\n", b - (a - 1) + (solve(b, c, d)) - (solve(a - 1, c, d)));

    return 0;
}

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

string to_string(const string& s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename T> string to_string(T v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; }
template <typename T, typename U> string to_string(pair<T, U> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
void print_debug() { cerr << endl; }
template <typename T, typename... U> void print_debug(T t, U... u) { cerr << " " << to_string(t); print_debug(u...); }
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", print_debug(__VA_ARGS__)
#else
#define debug(...)
#endif

typedef long long ll;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  
  int a[3][3];
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> a[i][j];
    }
  }
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        if (a[i][j] == x) {
          a[i][j] = 0;
        }
      }
    }
  }
  for (int i = 0; i < 3; i++) {
    int row = 0, col = 0, diag1 = 0, diag2 = 0;
    for (int j = 0; j < 3; j++) {
      if (a[i][j] == 0) {
        row++;
      }
      if (a[j][i] == 0) {
        col++;
      }
      if (a[j][j] == 0) {
        diag1++;
      }
      if (a[j][3-j-1] == 0) {
        diag2++;
      }
    }
    debug(row, col, diag1, diag2);
    if (row == 3 || col == 3 || diag1 == 3 || diag2 == 3) {
      cout << "Yes";
      return 0;
    }
  }
  cout << "No";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
int A,B,C;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>A>>B>>C;
    cout << min(B/A,C)<<"\n";
}

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

ab = []
for i in range(N):
    array = list(map(int, input().strip().split()))
    ab.append(array)
cd=[]
for i in range(M):
    array = list(map(int, input().strip().split()))
    cd.append(array)

for i in range(N):
    dic = [100000000000, 0]
    a,b = ab[i][0],ab[i][1]
    for j in range(M):
        cj, dj = cd[j][0], cd[j][1]
        dist = abs(a-cj)+abs(b-dj)
        if dist < dic[0]:
            dic[0] = dist
            dic[1] = j+1
    print(dic[1])

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n;
    cin >> n;
    vector<int32> cnt(n);
    FOR(i,1,n){
        int32 a;
        cin >> a;
        --a;
        cnt[a]++;
    }
    REP(i,n)ANS(cnt[i]);
    return 0;
}

Measured memory_bytes: 4784
#include<iostream>
#include<string>
using namespace std;
int main()
{

    int n, count, i, end;
    cin >> n;

    int* a = new int[n];

    for (i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    count = 0;
    end = 1;
    while(end == 1){
        for (i = 0; i < n; i++){
            if (a[i] % 2 ==1){
                end = 0;
                break;
            }
            else{
                a[i] /= 2;
            }
        }
        count ++;
    }

    cout << count-1;

    return 0;

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
  int N, M, C;
  cin >> N >> M >> C;

  int B[21];
  for (int i = 0; i < M; i++)
    cin >> B[i];

  int ans = 0;
  for (int i = 0; i < N; i++) {
    int s = C;
    for (int j = 0; j < M; j++) {
      int a;
      cin >> a;
      s += a * B[j];
    }
    if (s > 0)
      ans += 1;
  }

  cout << ans << endl;

  return 0;
}

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

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  ll n;
  cin >> n;
  if (n%7 == 0) cout << "thu" << endl;
  if (n%7 == 1) cout << "fri" << endl;
  if (n%7 == 2) cout << "sat" << endl;
  if (n%7 == 3) cout << "sun" << endl;
  if (n%7 == 4) cout << "mon" << endl;
  if (n%7 == 5) cout << "tue" << endl;
  if (n%7 == 6) cout << "wed" << endl;
}


Measured memory_bytes: 3112
N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())
L = [A,B,C,D,E]
L.sort()
if N%L[0] == 0:
  print(4+N//L[0])
else:
  print(5+N//L[0])

Measured memory_bytes: 3064
n=int(input())
lstw=[input() for _ in range(n)]
string=[]
flag=False
cnt=0

if len(lstw)==1:
    flag=True
elif len(lstw)==len(set(lstw)):
    for i in range(n):
        string.append(lstw[i][:1])
        string.append(lstw[i][-1:])
    for i in range(1,n):
        if string[2*i-1]==string[2*i]:
            cnt+=1
    if cnt==(n-1):
        flag=True

if flag:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
s = input()
temp = 10**9
x = []
y = []
for i in range(len(s)):
	if s[i] =="A":
		x.append(i)
	elif s[i]=="Z":
		y.append(i)

mx = min(x)
mz = max(y)


print((mz-mx)+1)

Measured memory_bytes: 16884
import Control.Applicative ((<$>), (<*>))
import Data.List(sort, intercalate)
import Text.Printf

main :: IO ()
main = solve <$> f <*> f >>= putStrLn
  where f = map read <$> words <$> getLine

solve :: [Int] -> [Int] -> String
solve (_:as) (_:bs) = intercalate " " . map h . g . sort $ f (f [] as) bs
  where f ls (h:m:hm) = f ((h,m):ls) hm
        f ls [] = ls
        g (x:y:ys) | x == y = g (y:ys)
                   | otherwise = x : g (y:ys)
        g [x] = [x]
        h :: (Int, Int) -> String
        h (h, m) = printf "%d:%02d" h m



Measured memory_bytes: 4252
#include<bits/stdc++.h>
using namespace std;
int n, m, pp[100007][2], h[1000007], svh[1000007], to[3000007], nxt[3000007], pos[200007], cnt;
int dfn[1000007], low[1000007], col[1000007], tot, st[1000007], tp;
bool vis[1000007];
pair<int, int>p[200007];
int read()
{
	int num = 0;
	char c = getchar();
	while (c < '0' || c>'9')c = getchar();
	while (c >= '0' && c <= '9')num = num * 10 + c - '0', c = getchar();
	return num;
}
int add(int a, int b)
{
	cnt++;
	to[cnt] = b;
	nxt[cnt] = h[a];
	h[a] = cnt;
	return 0;
}
int mtree(int w, int l, int r)
{
	if (l == r)
	{
		add(w + 20000, pp[p[l].second][pp[p[l].second][0] == l]);
		return 0;
	}
	int mid = (l + r) / 2;
	mtree(2 * w, l, mid);
	mtree(2 * w + 1, mid + 1, r);
	add(w + 20000, 2 * w + 20000);
	add(w + 20000, 2 * w + 20001);
	return 0;
}
int tadd(int w, int l, int r, int x, int y, int v)
{
	if (x <= l && r <= y)
	{
		add(v, w + 20000);
		return 0;
	}
	int mid = (l + r) / 2;
	if (x <= mid)tadd(2 * w, l, mid, x, y, v);
	if (y > mid)tadd(2 * w + 1, mid + 1, r, x, y, v);
	return 0;
}
int dfs(int w)
{
	dfn[w] = low[w] = ++tot;
	st[++tp] = w;
	vis[w] = 1;
	for (int i = h[w]; i; i = nxt[i])
		if (!dfn[to[i]])
			dfs(to[i]), low[w] = min(low[w], low[to[i]]);
		else if(vis[to[i]])low[w] = min(low[w], dfn[to[i]]);
	if (low[w] == dfn[w])
	{
		while (st[tp] != w)
		{
			vis[st[tp]] = 0;
			col[st[tp]] = w;
			tp--;
		}
		vis[w] = 0;
		col[w] = w;
		tp--;
	}
	return 0;
}
int check(int mid)
{
	int sv = cnt;
	memcpy(h, svh, sizeof h);
	for (int i = 1; i <= m; i++)
	{
		int l = upper_bound(pos + 1, pos + m + 1, p[i].first - mid) - pos;
		int r = lower_bound(pos + 1, pos + m + 1, p[i].first + mid) - pos - 1;
		if (l != i)tadd(1, 1, m, l, i - 1, i);
		if (r != i)tadd(1, 1, m, i + 1, r, i);
	}
	memset(dfn, 0, sizeof dfn);
	memset(low, 0, sizeof low);
	for (int i = 1; i <= 100000; i++)
		if (!dfn[i])
			dfs(i);
	cnt = sv;
	for (int i = 1; i <= n; i++)
		if (col[pp[i][0]] == col[pp[i][1]])
			return 0;
	return 1;
}
int main()
{
	n = read();
	for (int i = 1; i <= n; i++)
	{
		p[++m].first = read();
		p[++m].first = read();
		p[m - 1].second = p[m].second = i;
	}
	sort(p + 1, p + m + 1);
	for (int i = 1; i <= m; i++)
		if (pp[p[i].second][0])
			pp[p[i].second][1] = i;
		else pp[p[i].second][0] = i;
	mtree(1, 1, m);
	memcpy(svh, h, sizeof svh);
	for (int i = 1; i <= m; i++)
		pos[i] = p[i].first;
	int l = 0, r = 1e9;
	while (l != r)
	{
		int mid = (l + r + 1) / 2;
		if (check(mid))l = mid;
		else r = mid - 1;
	}
	cout << l << endl;
	return 0;
}

Measured memory_bytes: 35200
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;

#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  multiset<int> mst;
  mst.insert(A[0]);
  for(int i = 1; i < N; i++) {
    if(A[i] > *(mst.begin())) {
      auto it = mst.lower_bound(A[i]);
      it--;
      mst.erase(it);
    }
    mst.insert(A[i]);
  }
  cout << mst.size() << endl;
  return 0;
}

Measured memory_bytes: 5376
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
	int a, b, ans;
	scanf("%d%d", &a, &b);
	ans = a*b;
	if(ans%2 == 0) printf("Even\n");
	else printf("Odd\n");
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include <iostream>
#include<algorithm>
int g[101][101],a[1000],b[1000],c[1000];
int const infty=10000000;

int main(){
  int n,m,answer=0;
  scanf("%d%d",&n,&m);
  for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
      g[i][j]=infty;
    }
  }
  for(int i=0;i<m;i++){
  std::cin >> a[i] >> b[i] >> c[i];
    g[a[i]][b[i]]=g[b[i]][a[i]]=c[i];
  }
  for(int k=1;k<=n;k++){
    for(int i=1;i<=n;i++){
      for(int j=1;j<=n;j++){
        g[i][j]=std::min(g[i][k]+g[k][j],g[i][j]);
      }
    }
  }
  for(int i=0;i<m;i++){
    bool use=false;
    for(int j=1;j<=n;j++){
      if(j==a[i]||j==b[i]){
        if(c[i]==g[a[i]][b[i]])use=true;
      // }else if(g[a[i]][j]==c[i]+g[b[i]][j])use=true;
      }
    }
    if(!use)answer++;
  }
  printf("%d",answer);
  return 0;
}

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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

class modint {
  private:
    ll m_val;
    ll m_mod;
  public:
    constexpr modint() : m_val(0), m_mod() { m_mod = MOD; }
    constexpr modint(const ll x) : m_val(0), m_mod(0) { m_mod = MOD; m_val = x % m_mod; }
    constexpr modint(const ll x, const ll mod) : m_val(0), m_mod(0) { m_mod = mod; m_val = x % m_mod; }
    constexpr ll val() const { return m_val; }
    constexpr modint operator+(const modint &rhs) const { return modint(*this) += rhs; }
    constexpr modint operator-(const modint &rhs) const { return modint(*this) -= rhs; }
    constexpr modint operator*(const modint &rhs) const { return modint(*this) *= rhs; }
    constexpr modint operator/(const modint &rhs) const { return modint(*this) /= rhs; }
    constexpr modint &operator+=(const modint &rhs) {
      m_val += rhs.m_val;
      if (m_val >= m_mod) m_val -= m_mod;
      return *this;
    }
    constexpr modint &operator-=(const modint &rhs) {
      if (m_val < rhs.m_val) m_val += m_mod;
      m_val -= rhs.m_val;
      return *this;
    }
    constexpr modint &operator*=(const modint &rhs) {
      m_val = m_val * rhs.m_val % m_mod;
      return *this;
    }
    constexpr modint &operator/=(const modint &rhs) {
      *this *= rhs.inv();
      return *this;
    }
    constexpr modint pow(ll n) const {
      if (n == 0) return 1;
      modint o = pow(n >> 1);
      o *= o;
      if (n & 1) o *= *this;
      return o;
    }
    constexpr modint inv() const {
      return pow(m_mod - 2);
    }
    friend ostream& operator<<(ostream& os, const modint &a) { os << a.val(); return os; }
};

class combination {
  private:
    vector<modint> m_fact, m_ifact;
  public:
    combination(ll n): m_fact(n+1), m_ifact(n+1) {
      m_fact[0] = 1;
      for (ll i = 1; i <= n; ++i) m_fact[i] = m_fact[i-1]*i;
      m_ifact[n] = m_fact[n].inv();
      for (ll i = n; i >= 1; --i) m_ifact[i-1] = m_ifact[i]*i;
    }
    modint operator()(ll n, ll k) {
      if (k < 0 || k > n) return 0;
      return m_fact[n] * m_ifact[k] * m_ifact[n-k];
    }
};

int main() {
  ll x, y;
  cin >> x >> y;

  ll n = 0, m = 0;
  n = (2*x-y)/3;
  m = (2*y-x)/3;

  if (n < 0 || m < 0 || (x+y)%3 != 0) {
    cout << 0 << endl;
    return 0;
  }

  combination comb(n+m);
  cout << comb(n+m, n) << endl;

  return 0;
}


Measured memory_bytes: 21120
#include "bits/stdc++.h"
using namespace std;

int main(){
    
    int N;
    cin >> N;
    string s;
    cin >> s;
    int l = 0, r = N - 1;
    for(;l < N && s[l] == '<'; l++);
    for(;r >= 0 && s[r] == '>'; r--);
    r = N - 1 - r;
    cout << N - l - r + max(l, r) << endl;
    
    return 0;
}



Measured memory_bytes: 3312
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
//constexpr int MOD=1000000007;
constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;

bool ex[1100000]={};

int main(void){
    int N;
    cin >> N;
    lint A[N];
    lint ans=0;
    map<lint,lint> cnt;
    rep(i,N){
        cin >> A[i];
        cnt[A[i]]++;
    }
    sort(A,A+N);
    rep(i,N){
        ex[A[i]]=true;
    }
    for(int i=1;i<=1000000;i++){
        if(ex[i] && cnt[i]==1) ans++;
        if(ex[i]) for(int j=i;j<=1000000;j+=i) ex[j]=false;
    }
    cout << ans << endl;
}


Measured memory_bytes: 18656
def main():
    S = list(input())
    
    A = []
    for s in S:
        if s == "B":
            if len(A) == 0:
                pass
            else:
                A.pop()
        elif s == "0":
            A.append("0")
        elif s == "1":
            A.append("1")
    
    if len(A) == 0:
        print("")
    else:
        for x in range(len(A)):
            if x != len(A) - 1:
                print(A[x], end = "")
            else:
                print(A[x])


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064