akhauriyash/Code-Regression huggingface dataset:
s=input()

if len(s)==1:
    print(int(s))
else:
    def count(num):
        # basecase
        if len(num)==1:
            return 0
        else:
            a=0
            for j in range(1,len(num)):
                a+=int(num[:j])*2**(len(num[j:])-1)+int(num[j:])+count(num[j:])
            return a
    ans=int(s)+count(s)
    print(ans)


Measured memory_bytes: 38256
#include <iostream>
#include <algorithm>
#include <math.h> 
#include <string>
#include <iomanip>
#include <vector>
#include <chrono>
#include <cstdlib>
#include <bitset>
using namespace std;
int main(){
    int n, m, x;
    int c[12];
    int a[12][12];
    cin >> n >> m >> x;
    for(int i = 0; i < n; i++){
        cin >> c[i];
        for(int j = 0; j < m; j++){
            cin >> a[i][j];
        }
    }

    int ans = 1001001001;
    for(int bit = 0; bit < (1<<n); bit++){
        int skill[12] = {0};
        int cost = 0;
        for(int i = 0; i < n; i++){
            if(bit & (1<<i)){
                cost += c[i];
                for(int j = 0; j < m; j++) skill[j] += a[i][j];
            }
        }
        bool ok = true;
        for(int i = 0; i < m; i++) if(skill[i] < x) ok = false;

        if(ok) ans = min(ans, cost) ;
    }
    if(ans != 1001001001) cout << ans << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 3588
from itertools import accumulate
N=int(input())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
AS=sum(A)
BS=sum(B)
if BS>AS:
    print(-1)
elif all(a>=b for a,b in zip(A,B)):
    print(0)
else:
    cap=sum(max(0,b-a) for a,b in zip(A,B))
    M=sum(b-a>0 for a,b in zip(A,B))
    C=sorted((a-b for a,b in zip(A,B)),reverse=True)
    D=list(accumulate(C))
    for i, d in enumerate(D,1):
        if cap<=d:
            print(i+M)
            break

Measured memory_bytes: 20220
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <float.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <deque>
#include <locale>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <wchar.h>
#include <wctype.h>
#include <algorithm>
#include <bitset>
#include <map>
#include <iomanip>
#include <ios>
#include <iostream>
#include <vector>
#include <cwchar>
#include <cwctype>
#define mp make_pair
#define fs first
#define se second
#define memset(a,t) memset(a,t,sizeof(a))
#define all(v) v.begin(),v.end()
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
using namespace std;
int has[26];
inline bool ok(string s){
	for(int i=0;i<s.size();i++) if(s[i]!=s[0]) return 0;
	return 1;
}
inline int change(string s,char c){
	int res=0,i;
	while(1){
		if(ok(s)) return res;
//		cout<<s<<endl;
		bool has=0;
		string t="";
		for(i=0;i<s.size()-1;i++){
			if(s[i]==c) t+=c;
			else if(s[i+1]==c) t+=c;
			else t+=s[i];
		}
		res++;
		s=t;
	}
}
int main(){
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false);
	string s;
	int i,j,mn,wz;
	cin>>s;
	for(i=0;i<26;i++){
		mn=min(change(s,(char)(i+'a')),mn);
//		cout<<i<<endl;
	}
	cout<<mn<<endl;
	return 0;
	#ifdef home
        eprintf("time = %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
    #endif
}

Measured memory_bytes: 256
INF = 10 ** 20
def main():
  d, n = map(int,input().split())
  temp = [int(input()) for i in range(d)]
  temp.insert(0,0)
  alst = []
  blst = []
  clst = []
  for i in range(n):
    a,b,c = map(int,input().split())
    alst.append(a)
    blst.append(b)
    clst.append(c)
  
  dp = [[0] * n for i in range(d + 1)]
  
  t1 = temp[1]
  for i in range(n):
    if not (alst[i] <= t1 <= blst[i]):
      dp[1][i] = -INF
  
  for i in range(2, d + 1):
    t = temp[i]
    predp = dp[i - 1]
    for j in range(n):
      cj = clst[j]
      if alst[j] <= t <= blst[j]:
        dp[i][j] = max(predp[x] + (cj - clst[x] if cj >= clst[x] else clst[x] - cj) for x in range(n))
  
  print(max(dp[d]))

main()


Measured memory_bytes: 6168
#include <bits/stdc++.h>
using namespace std;
long long s;
int main () {
    long long n , m , ans = 0;
    cin >> n >> m;
    for (int i = 0; i < m; i++)
        cin >> s , ans += s;
    if (ans >= n)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}


Measured memory_bytes: 256
N = gets
points = [1, 1]
while line = gets
  ratios = line.split.map(&:to_i)
  times = [ (points[0] + ratios[0] - 1) / ratios[0],
            (points[1] + ratios[1] - 1) / ratios[1] ].max
  points = ratios.map {|i| i * times }
end
p (points[0] + points[1])

Measured memory_bytes: 1788
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

ll dp[100009][3];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N, x;
    string s;
    cin>>N>>x;
    mem(dp,0xcf);
    dp[0][0] = x;
    rep(i,N-1){
        cin>>s>>x;
        ll T[3];
        if(s=="+"){
            T[0]=dp[i][0];
            T[1]=dp[i][1];
            T[2]=dp[i][2];
        }else{
            T[0]=T[2]=dp[i][1];
            T[1]=max(dp[i][0],dp[i][2]);
        }
        dp[i+1][2]=T[2]+x;
        dp[i+1][1]=max(dp[i+1][2],T[1]-x);
        dp[i+1][0]=max(dp[i+1][1],T[0]+x);
    }
    cout1(*max_element(dp[N-1],dp[N-1]+3));
}

Measured memory_bytes: 2560
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define PI 3.14159265358979323846264338327950L

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back

template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

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

bool isPalindrome(string s){
    REP(i, s.length() / 2){
        if(s[i] != s[(s.length() - 1) - i]){
            return false;
        }
    }
    return true;
}

//scanf("%lld", &);
//cin >> ;
//cout << ans << endl;

 ll N, M, K, Q, i, j, k, l, tmp, ans, H, W;

int main(){

    cin >> H >> W >> K;
    vector<vector<bool>> board;
    vector<vector<bool>> clone_board;
    
    REP(i, H){
        vector<bool> tmp(3, false);
        board.push_back(tmp);
        REP(j, W){
            char c;
            cin >> c;
            if(c == '#'){
                board[i][j] = true;
            }
        }
    }

    REP(maskR, (1 << H)){
        REP(maskC, (1 << W)){
            tmp = 0;
            // maskR = 選択するビットマスク, maskC = 選択するビットマスク
            REP(i, H){
                REP(j, W){
                    if (((maskR >> i) & 1) == 0 && ((maskC >> j) & 1) == 0){
                        if(board[i][j]){
                            tmp++;
                        }
                    }
                }
            }
            if(tmp == K){
                ans++;
            }
        }
    }

    cout << ans << endl;





    return 0;
}

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


typedef long long int ll;

int main(){
  ll a,b,c,k;
  cin>>a>>b>>c>>k;
  ll sum=0;
  sum+=min(k,a);
  k-=a;
  if(k>=b){
    k-=b;
  }
  else{
    k=0;
  }
  if(k>=c){
    sum-=c;
  }
  else{
    sum-=k;
  }
  cout<<sum<<endl;
  return 0;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  priority_queue<double> que;
  rep(i, n) {
    double a;
    cin >> a;
    que.push(a);
  }
  rep(i, m) {
    double tmp = que.top();
    que.pop();
    que.push(tmp / 2.0);
  }
  
  ll ans = 0;
  while (!que.empty()) {
    ans += (ll)que.top();
    que.pop();
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1400
"
ABC162C
https://atcoder.jp/contests/abc162/tasks/abc162_c
"

K = gets.to_i
ans = 0
1.upto(K) do |a|
  1.upto(K) do |b|
    1.upto(K) do |c|
      ans = ans + a.gcd(b.gcd(c))
    end
  end
end
puts ans

Measured memory_bytes: 14340
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  ll q;
  cin >> q;

  multiset<ll> s;
  ll y = 0, t, a, b;
  cin >> t >> a >> b;
  s.insert(a);
  y += b;
  auto it = s.begin();
  rep(i, q - 1) {
    cin >> t;
    if (t == 1) {
      cin >> a >> b;
      s.insert(a);
      if (s.size() % 2 == 0) {
        y += abs(a - *it) + b;
        if (a < *it) it--;
      }
      else {
        if (a >= *it) it++;
        y += abs(a - *it) + b;
      }
    }
    else {
      cout << *it << " " << y << endl;
    }
  }



  



  
  return 0;
}


Measured memory_bytes: 9600
def p_num():
    global num
    ans = 0
    for i in range(12):
        ans += num[i] * (10 ** i)
    print(ans)


def fun(i, f):
    global k, num, n
    p = num[i + 1]
    for j in range(max(0, p - 1), ((f == 1) * 10) + ((f != 1) * min(10, p + 2))):
        num[i] = j
        if (i == 0):
            # p_num()
            n += 1
            if (k == n):
                p_num()
                exit()
        else:
            fun(i - 1, f and j == 0)


k = int(input())
num = [0] * 15
n = -1

fun(11, 1)


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

typedef double                      ld;
typedef long long                   ll;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<string , string>       pss;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define F                           first
#define S                           second
#define sep                         ' '
#define endl                        '\n'
#define file_io                     freopen("input.txt" , "r+" , stdin) ; freopen("output.txt" , "w+" , stdout);
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define error(x)                    cerr << "$$$ " << x << '\n';
#define error2(x,y)                 cerr << "#F : " << x << "      #S : " << y << '\n';
#define kill(x)                     return cout << x << endl , 0;
#define pb                          push_back

const ll MXN = 1e3 + 10;
const ll MXM = 50 + 10;
const ll MX5 = 2e5 + 10;
const ll MX6 = 1e6 + 10;
const ll LOG = 20;
const ll INF = 8e18;
const ld eps = 1e-9;
const ll MOD = 1e9 + 7; //998244353;

ll power(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md));
}
ll bmm(ll a,ll b){
    return (a%b==0 ? b : bmm(b,a%b));
}
string base2(ll n){
    string a="";while(n>=2){a+=(char)(n%2+'0');n/=2;}a+=(char)(n+'0');reverse(all(a));return a;
}

ll n, m;

int main(){
    fast_io
    //file_io
    string s, t;
    cin >> n >> t >> s;
    for(int i = 0; i < 2 * n; i ++){
        if(i % 2){
            cout << s[i / 2];
        }
        else{
            cout << t[i / 2];
        }
    }




    return 0;
}

//! N.N


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MM 1000000000
#define MOD MM+7
#define MAX 10000
#define MAP 110
#define Pair pair<int,int>

int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
int main(){
    ll N, W; cin >> N >> W;
    ll w[110], v[110];
    ll dp[110][100100];
    for(ll i = 1; i <= N; i++){
        cin >> w[i] >> v[i];
    }

    for(ll i = 0; i < N; i++){
        for(ll j = 0; j <= W; j++){
            dp[i+1][j] = dp[i][j];
            if(w[i+1] <= j){
                dp[i+1][j] = max(dp[i+1][j],
                            dp[i][j-w[i+1]] + v[i+1]);
            }
        }
    }
    cout << dp[N][W] << endl;
}


Measured memory_bytes: 80128
#include <cstdio>

using namespace std;

int main()
{
	int a[4],b[4];
	while(scanf("%d",&a[0])!=EOF){
		scanf("%d %d %d",&a[1],&a[2],&a[3]);
		scanf("%d %d %d %d",&b[0],&b[1],&b[2],&b[3]);
		int hit=0,blow=0;
		for(int i=0;i<4;i++){
			for(int j=0;j<4;j++){
				if(a[i]==b[j]){
					if(i==j)hit++;
					else blow++;
				}
			}
		}
		printf("%d %d\n",hit,blow);
	}
	return 0;
}

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

int main()
{
	int N, A, B,ans = 0;

	cin >> N >> A >> B;

	if (B - A == 1) {
		ans = 2;
	}
	else if ((B - A-1) % 2 == 0) {
		ans = 2;
	}
	else {
		ans = 1;
	}

	if (N == 2)ans = 2;

	if (ans == 1) cout << "Alice" << endl;
	else if (ans == 2) cout << "Borys" << endl;
	else  cout << "Draw" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define se second
#define mp make_pair
#define fi first
#define del(a,vec) vec.erase(std::remove(vec.begin(), vec.end(), a), vec.end());
#define search(f,l,v) binary_search(f,l,v)
#define iter(a,b) vector<int>::iterator a,b
#define lower(v,num) lower_bound (v.begin(), v.end(), num);
#define upper(v,num) upper_bound (v.begin(), v.end(), num); 
#define removecopy(a) unique(a.begin(), a.end()); 
#define ll long long int
namespace Rahul{
    bool isPrime(int n) 
    {if (n <= 1)  return false; if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
    return true; }
    ll pow (ll x, ll n,ll mod) {//calculate x^n
    if (n == 0) return 1;

    ll res = pow (x, n / 2,mod);

    res = (res * res) % mod;
    if (n % 2) res = (res * x ) % mod;

    return res;
    }
    ll _gcd(ll a,ll b)
    {
        if(a==0)
            return b;
        else    
            return _gcd(b%a,a);
    }
    //s.erase(s.find(2)) where s={1,2,3,3,2}; 
};

string find(int i)
{
     char p='0';
    //   unordered_map<char,int>cn;
      unordered_map<int,char>cp;
      for(int i=0;i<10;i++)  
         cp[i]=p++;
    string s="";
    int co=0;
    int temp=i;
    while(temp)
        {
            int k=temp%10;
            s=cp[k]+s;
            temp/=10;
        }
    while(s.size()!=3)
        s='0'+s;
        
    return s;    
        
}
using namespace Rahul;
int main()
{
     ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
     
      int n;
      cin>>n;
      string s;
      cin>>s;
      char p='0';
      unordered_map<char,int>cn;
      unordered_map<int,char>cp;
      for(int i=0;i<10;i++)  
         cp[i]=p++;
     
     int ans=0;
    //  unordered_map<
      for(int i=0;i<=999;i++)
        {
            string p="";
            // p=toSting(i);
            p=find(i);
            // cout<<p<<endl;
            int ind=0;
            for(int j=0;j<s.size();j++) 
            {
                if(ind==3)
                    break;
                    
                if(p[ind]==s[j])
                    ind++;
            }
            
            if(ind==3)
                ans++;
                // cout<<p<<endl;}
            
            
            
        }
     cout<<ans<<endl; 
     
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;

int n, ar[4][102], dp[4][102];

signed main(){
	cin >> n;
	for (int i=1; i<=2; i++){
		for (int j=1; j<=n; j++) cin >> ar[i][j];
	}
	dp[1][1] = ar[1][1];
	for (int i=1; i<=2; i++){
		for (int j=1; j<=n; j++){
			dp[i][j] = max(dp[i-1][j], dp[i][j-1])+ar[i][j];
		}
	}
	cout << dp[2][n];
}



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

int main()
{
	string s;
	cin >> s;

	if (s == "Sunny") {
		cout << "Cloudy" << endl;
	}
	else if (s=="Cloudy")
	{
		cout << "Rainy" << endl;
	}
	else
	{
		cout << "Sunny" << endl;
	}

	return 0;
}

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

#include <set>
#include <map>
#include <iomanip>

using namespace std;

#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define all(x) (x).begin(),(x).end()
#define ll long long

struct task
{
	ll len, end;
};

bool comp(const task& l, const task& r)
{
	return l.end < r.end;
}

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

	vector<task> tasks(N);
	rep(i, N)
	{
		cin >> tasks[i].len >> tasks[i].end;
	}

	sort(all(tasks), comp);
	reverse(all(tasks));

	ll idx = tasks[0].end - tasks[0].len;
	bool flag = true;
	for (ll i = 1; i < N; i++)
	{
		if (idx < 0)
		{
			flag = false;
			break;
		}

		if (idx > tasks[i].end)
		{
			idx = tasks[i].end - tasks[i].len;
			continue;
		}

		idx -= tasks[i].len;

		if (idx < 0)
		{
			flag = false;
			break;
		}
	}

	if (idx < 0)
	{
		flag = false;
	}

	if (flag)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 3328
#include <iostream>
using namespace std;
int main(){
    int a, b, ans=0;
    cin>>a>>b;
    int w[a], v[a], dp[a][a*1000+1];
    for (int i=0; i<a; i++){
        for (int j=0; j<=a*1000; j++){
            dp[i][j]=2e9;
        }
    }
    for (int i=0; i<a; i++){
        cin>>w[i]>>v[i];
        dp[i][v[i]]=w[i];
    }
    for (int i=0; i<a-1; i++){
        for (int j=1; j<=a*1000; j++){
            if (dp[i][j]==2e9) continue;
            dp[i+1][j]=min(dp[i+1][j], dp[i][j]);
            if (dp[i][j]+w[i+1]>b) continue;
            dp[i+1][j+v[i+1]]=min(dp[i+1][j+v[i+1]], dp[i][j]+w[i+1]);
        }
    }
    for (int i=1; i<=a*1000; i++){
        if (dp[a-1][i]==2e9) continue;
        ans=max(ans, i);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 39296
#include<bits/stdc++.h>
using namespace std;
int n,seg[1000001];
void update(int k,int x){
  k += n-1;
  seg[k] = x;
  while(k > 0){
    k = (k-1)/2;
    seg[k] = min(seg[2*k+1],seg[2*k+2]);
  }
}
int find(int a,int b,int node,int l,int r){
  if(a > r || b < l) return(INT_MAX);
  if(a <= l && r <= b) return(seg[node]);
  return( min(find(a,b,2*node+1,l,(l+r)/2),find(a,b,2*node+2,(l+r)/2+1,r)) );
}
int main(){
  int q,com,x,y;
  cin >> n >> q;
  int a=1;
  while(a<n) a*=2;
  n = a;
  fill(seg,seg+1000001,INT_MAX);
  for(int i=0;i<q;i++){
    cin >> com >> x >> y;
    if(com == 0) update(x,y);
    if(com == 1) cout << find(x,y,0,0,n-1) << endl;
  }

  return (0);
}

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

#define NUM_ROOM_PER_FLOOR 10
#define NUM_FLOOR 3
#define NUM_HOUSE 4

using namespace std;

int main() {
  // 入居者情報の数
  int N;

  // 入居者情報配列
  int count[NUM_HOUSE + 1][NUM_FLOOR + 1][NUM_ROOM_PER_FLOOR + 1];

  // 配列の初期化
  for (int i = 1; i <= NUM_HOUSE; i++)
    for (int j = 1; j <= NUM_FLOOR; j++)
      for (int k = 1; k <= NUM_ROOM_PER_FLOOR; k++)
        count[i][j][k] = 0;

  // 入居者情報の数の取得
  cin >> N;

  // 入居者情報の取得
  for (int n = 0; n < N; n++) {
    int b, f, r, v;
    cin >> b >> f >> r >> v;
    count[b][f][r] += v;
  }

  // 入居者数の出力
  for (int i = 1; i <= NUM_HOUSE; i++) {
    for (int j = 1; j <= NUM_FLOOR; j++) {
      for (int k = 1; k <= NUM_ROOM_PER_FLOOR; k++) {
        cout << " " << count[i][j][k];
      }
      cout << endl;
    }
    if (i < NUM_HOUSE)
      cout << "####################" << endl;
  }

  return 0;
}



Measured memory_bytes: 3080
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W, N;
    cin >> H >> W >> N;
    cout << (N+ max(H, W) - 1)/ max(H, W) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define sz(a) (int)(a).size()
 
using namespace std;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
const int INF = 1e5+2;
const long long hell = 998244353ll;

void solve(){
	int n ;
	cin >> n;
	vector<int> time_each(n);
	for( int i = 0; i < n ; i++ ) cin >> time_each[i];
	int m ;
	cin >> m ;
	vector<pair<int,int>>drink(m);
	for( int i = 0 ; i < m ; i++ ){
	 	cin >> drink[i].first >> drink[i].second ;
	}
	long long ans = 0 ;
	for( int i = 0 ; i < m ; i++ ){
	 	for( int j = 0 ; j < n ; j++ ){
	 	 	if(drink[i].first - 1 == j) ans += drink[i].second ;
	 	 	else ans += time_each[j];
	 	}
	 	cout << ans << endl;
	 	ans = 0;
	}
}
int main(){
    	
	ios_base::sync_with_stdio(0);cin.tie(0);
    	
	int q=1;
#ifdef LOCAL
  	cin>>q;
#endif
  	while(q--){
  		solve();
  	}
#ifdef LOCAL
   	cout << "Time elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms.\n";
#endif	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;

int main(){
  
  ll x,y; cin>>x>>y;
  int ans{};
  while(x<=y){
    x*=2;
    ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3616
#include <iostream>
#include <set>
#include <algorithm>
using namespace std;
int main()
{
    int a;
    cin>>a;
    set<int > s1,c;
    set<int > s2;
    while (a--)
    {
        int t;
        cin>>t;
        s1.insert(t);
    }
    cin>>a;
    while (a--)
    {
        int t;
        cin>>t;
        s2.insert(t);
    }

    set_union(s1.cbegin(),s1.end(),s2.begin(),s2.end(),inserter(c,c.begin()));

    auto it=c.begin();
    auto its=c.end();
    for (auto i = it; i !=its ; ++i)
    {
        cout<<*i<<endl;
    }

}


Measured memory_bytes: 40596
n = gets.to_i
data = []
data.push "0 0 0".split(' ').map(&:to_i)
while line = gets
  data.push line.split(' ').map(&:to_i)
end

can = true
for i in 0..n-1
  dt = data[i+1][0] - data[i][0]
  dist = (data[i+1][1] - data[i][1]).abs + (data[i+1][2] - data[i][2]).abs
  can = false if dt < dist
  can = false if (dist % 2 != dt % 2)
end

if can; then puts "Yes"
else puts "No"
end

Measured memory_bytes: 9468
N, x = map(int, input().split())
a = list(map(int, input().split()))

ans = 0
keep = a[0]
for i in range(1, N):
    if (keep + a[i]) > x:
        ans = ans + (keep + a[i] - x)
        keep = max(x - keep, 0)
    else:
        keep = a[i]


print(ans)


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

int main() {
  int N;
cin>>N;
vector<tuple<string,int,int>> v(N);
  int s[N];
 for(int i=0;i<N;i++){
  cin>>get<0>(v.at(i))>>s[i];
   get<1>(v.at(i))=100-s[i];
   get<2>(v.at(i))=i+1;
 }
  sort(v.begin(),v.end());
  for(int i=0;i<N;i++){
  cout<<get<2>(v.at(i))<<endl;
 }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long lint;
typedef vector<lint> LIV;
#define rep(i,n) for(int i=0;i<n;++i)
#define MAXN 100010
#define MAXM 1100000
#define all(v) v.begin(),v.end()
#define inf 2147483647
#define linf 1152921504606846976

int main(){
	lint a,b,k,c=0;cin>>a>>b>>k;
	for(int i=min(a,b);i>=0;--i){
		if(a%i==0&&b%i==0)++c;
		if(c==k){
			cout<<i<<endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<cctype>
#include<stack>
#define ld long double
#define ll long long int
#define ull unsigned long long int
using namespace std;
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;}
const long long INF=1LL<<60;
//set<int>::iterator it;

int main(void){
    int p,q,r;
    cin>>p>>q>>r;
    int a,b,c;
    a=p+r;
    b=p+q;
    c=q+r;
    int ans;
    ans = min(min(a,b),c);
    cout<<ans<<endl;
    return 0;
}

//a>b>c = c>b>a b>a>c = c>a>b b>c>a = a>c>b

Measured memory_bytes: 256
import numpy as np
N, M = [int(i) for i in input().split()]

INF = int(1e18)
G = np.full((N, N), INF)
for i in range(N):
    G[i][i] = 0

edge = []
for i in range(M):
    a, b, c = [int(i) for i in input().split()]
    a, b = a - 1, b - 1
    G[a][b] = G[b][a] = c
    edge.append((a, b, c))


rng = range(N)
for k in rng:
    for i in rng:
        for j in range(i + 1, N):
            x = G[i][k] + G[k][j]
            if G[i][j] > x:
                G[i][j] = G[j][i] = x;
                
ans = 0
for (a, b, c) in edge:
    ans = ans + (G[a][b] != c)
print(ans)
    
        
    



Measured memory_bytes: 21312
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
typedef long long ll;
#define vint vector<int>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000


int main(){
  string s,t;
  cin >> s >> t;
  bool ok;
  int maxi = 0;
  if(s.size() >= t.size()){
    erep(i,s.size()-t.size()){
      ok = true;
      rep(j,t.size()){
        if(s[i + j] != '?' && s[i + j] != t[j]){
          ok = false;
        }
      }
      if(ok){
        maxi = i+1;
        //cout << maxi << endl;
      }
    }
    if(maxi){
      rep(j,t.size()){
        s[maxi-1 + j] = t[j];
      }
      rep(j,s.size()){
        if(s[j] == '?') s[j] = 'a';
      }
    }
  }
  if(maxi) cout << s << endl; else cout << "UNRESTORABLE" << endl;
}

Measured memory_bytes: 256
// "for if God is with them who can be against them."
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define endl '\n'
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define all(a) a.begin(),a.end()
#define watch(x) cout << (#x) << " is " << (x) << endl
void solve() {
	ll n;
	cin >> n;
	vector<ll>a(n + 1);
	for (int i = 1; i <= n; i++) {
		for (int j = i; j <= n; j += i) {
			a[j]++;
		}
	}
	ll ans = 0;
	for (ll i = 1; i <= n; i++) {
		ans += (a[i] * i);
	}
	cout << ans;
}
int main() {
#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
	IOS;
	int t = 1;
	//cin >> t;
	while (t--) {
		solve();
	}


#ifndef ONLINE_JUDGE
	cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif
	return 0;
}

Measured memory_bytes: 81332
def main():
    n, m = map(int, input().split())
    if (n, m) == (1, 1):
        print(1)
        exit()

    if n == 1 or m == 1:
        ans = max(0, max(n, m) - 2)
        print(ans)
        return
    else:
        x = max(0, n - 2)
        y = max(0, m - 2)
        ans = x * y
        print(ans)
        return


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
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)
        {
            int N = cin.ReadInt;
            int[] A=cin.ReadIntArray(N);
            int minA = A[0];
            int count = 1;
            for(int i = 1; i < N; i++)
            {
                if (minA > A[i])
                {
                    minA = A[i];
                    count++;
                }
            }
            Console.WriteLine(count);
            
            

        }

    }

    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: 35468
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>


int main(void){
  char buf[32] = { 0 };
  int N,K;
  long ans;
  
  fgets(buf, sizeof(buf), stdin);
  sscanf(buf, "%d %d", &N, &K);
  
  ans = K * (long)pow(K-1, (N-1));
  
  printf("%ld\n", ans);
  return 0;
}


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

int main() {
  int menu[5] = {};
  for(int i = 0; i < 5; i++) cin >> menu[i];
  
  int min1 = 10;
  int sum = 0;
  int point = 6;
  bool counter = true;
  
  for(int i = 0; i < 5; i++) {
    //cout << i << ": ";
    int one = menu[i] % 10;
    if(one != 0 && one <= min1) {
      if(counter) {
        min1 = one;
        point = i;
        counter = false;
        //cout << "ugoiteru" << endl;
        continue;
      }
      sum += menu[point] + (10 - (menu[point] % 10));;
      min1 = one;
      point = i;
      //cout << "sum = " << sum << " i = " << i << endl;
      continue;
    }
    if(one == 0) {
      sum += menu[i];
      //cout << "sum = " << sum << " i = " << i << endl;
    }else {
      sum += menu[i] + (10 - (menu[i] % 10));
      //cout << "sum = " << sum << " i = " << i << endl;
    }
  }
  if(counter) cout << sum << endl;
  else {
    sum += menu[point];
    cout << sum << endl;
  }
}

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

using std::cin;
using std::cout;
using std::endl;

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

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

  int from = R[0] + 1;
  int max_prof = R[1] - R[0];
  for (int i = 0; i < n-1; i++) {
    if (R[i] >= from) {
      continue;
    }
    for (int j = i+1; j < n; j++) {
      int prof = R[j] - R[i];
      if (max_prof < prof) {
        max_prof = prof;
        from = R[i];
      }
    }
  }

  cout << max_prof << endl;

  return 0;
}



Measured memory_bytes: 3884
#Sum of 4 Integers

count = 0
while True:
    try:
        i = int(input())
        for a in range(10):
            for b in range(10):
                for c in range(10):
                    for d in range(10):
                        if a + b + c + d == i:
                            count += 1
        print(count)
        count = 0
    except:
        break

Measured memory_bytes: 7556
s = input()
packet = 'abcdefghijklmnopqrstuvwxyz'
checked = [0]*26
ans = []
for i in range(len(s)):
    checked[packet.index(s[i])] = 1
for i in range(26):
    if checked[i] != 1:
        ans.append(packet[i])
ans.sort()
if sum(checked) != 26:
    print(ans[0])
else:
    print('None')
    

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

int L, E[88];
bool dp[88][350][350];

void run() {
	cin >> L;
	for (int i=0; i<L; ++i) cin >> E[i];
	
	memset(dp, false, sizeof(dp));
	dp[0][0][0] = true;
	
	for (int i=0; i<L-1; ++i) for (int lft=0; lft<350; ++lft) for (int self=0; self<350; ++self) {
		if (!dp[i][lft][self]) continue;
		dp[i+1][self+E[i]][0] = true;
		if (self + E[i] > 0) dp[i+1][self+E[i]-1][lft] = true;
	}
	
	int max_self = 0;
	for (int lft=0; lft<350; ++lft) for (int self=0; self<350; ++self) if (dp[L-1][lft][self]) max_self = max(max_self, self);
	cout << E[L-1] + max_self << endl;
}

int main() {
	int N;
	cin >> N;
	for (int case_i=0; case_i<N; ++case_i) run();
}


Measured memory_bytes: 13624
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100000;

int main() {
	int a,b;cin>>a>>b;
	string sa,sb;
	rep(i,b) sa+='1'-1+a;
	rep(i,a) sb+='1'-1+b;
	if(sa>sb) cout<<sb<<endl;
	else cout<<sa<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
using namespace std;
typedef double  dbl;
typedef long long int lld;
#define foi(i,n) for(i = 0; i < n; i+=1)
#define fod(i,n) for(i=n-1; i >=0; i-=1)
#define MAX std::numeric_limits<lld>::max()
#define MIN std::numeric_limits<lld>::min()
#define FastIO  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main (){
    FastIO
    lld n, a;
    lld b, i;
    cin >> n;
    cin >> a;
    cin >> b;
    if (n % (a+b)< a){
    	i = n % (a+b);
    }
    else{
    	i = a;
    }
    cout << a*(n/(a+b)) + i << "\n";
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define IREP(i, v) for(auto i = (v).begin(); i != (v).end(); ++i)
#define IRREP(i, v) for(auto i = (v).rbegin(); i != (v).rend(); ++i)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define REV(x) reverse(ALL(x))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ld = long double;
using ll = long long;
using ui = unsigned int;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using Pll_ll = pair<ll, ll>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007; 
const int INF = 1000000000; //1e9
const int NIL = -1;
const ll LINF = 1000000000000000000; // 1e18
const double EPS = 1E-10;

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


int main(){
    string S; cin >> S;
    cout << (((S[2] == S[3]) && (S[4] == S[5])) ? "Yes" : "No") << endl;
    return 0;
}


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

int main() {
    int n,sum = 0;
    cin >> n;
    vector<int> ryouri(n);
    for (int i = 0; i < n; i++){
        cin >> ryouri.at(i);
        ryouri.at(i) = ryouri.at(i)-1;
    }
    vector<int> manzoku(n);
    for (int i = 0; i < n; i++){
        cin >> manzoku.at(i);
    }
    vector<int> tuika(n-1);
    for (int i = 0; i < n-1; i++){
        cin >> tuika.at(i);
    }
    //入力終わり
    for (int i = 0; i < n; i++){
        sum += manzoku.at(ryouri.at(i));
        if(i+1 != n){
            if(ryouri.at(i) == ryouri.at(i+1)-1){
                sum += tuika.at(ryouri.at(i));
            }
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        
        String S = scanner.next();
        
        if (S.equals("AAA") || S.equals(("BBB"))) {
            System.out.println("No");
        } else {
            System.out.println("Yes");
        }
    }
}


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

ll n;

vector<int> bin_ex(ll x)
{
  vector<int> v;
  for (size_t i = 0; i < n; i++)
  {
    v.push_back(x&1);
    x = x>>1;
  }
  return v;
}

/*
void print_vector(vector<vector<int> > A)
{
  for (ll i = 0; i < n; i++)
  {
    for (ll j = 0; j < n; j++)
    {
      cout << A[i][j] << " ";
    }
    cout << endl;
  }
  cout << endl;
}
*/

void print_vec(vector<int> v)
{
  for (int i = 0; i < n; i++)
  {
    cout << v[i] << " ";
  }
  cout << endl;  
}

int sum(vector<int> v)
{
  int tmp = 0;
  for (int i = 0; i < n; i++)
  {
    tmp += v[i];
  }
  return tmp;
}

int main()
{
  //input
  cin >> n;
  vector<vector<int> > A(n);
  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < n; j++)
    {
      (A[i]).push_back(-1);
    }
  }

  int Ai,x,y;

  for (int i = 0; i < n; i++)
  {
    cin >> Ai;
    for (int j = 0; j < Ai; j++)
    {
      cin >> x >> y;
      A[i][x-1] = y;
    }
  }

  ll M = 1<<n;
  int tmpmax = 0;
  int flag = 1;
  vector<int> v;

  for (ll x = 0; x < M; x++)
  {
    v = bin_ex(x);
    flag = 1;
    for (int i = 0; i < n; i++)
    {
      if(v[i]==0) continue;
      for (int j = 0; j < n; j++)
      {
        if(A[i][j]==1 && v[j]==0)
        {
          flag = 0;
          break;
        }
        if(A[i][j]==0 && v[j]==1)
        {
          flag = 0;
          break;
        }
      }
      if(flag == 0) break;
    }
    if(flag==1)
    {
      tmpmax = max(tmpmax, sum(v));
    }
  }

  cout << tmpmax << endl;  
  
  return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <fstream>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long ll;
#define REP(i, N) for (int i = 0; i < (int)N; i++)

typedef pair<int, int> edge;
const int UNVISITED = -1;
priority_queue<edge, vector<edge>, greater<edge>> bridges;
vector<int> low;
vector<int> dist;
vector<vector<int>> adjacentList;

int dfs(int i, int d, int parent) {
  low[i] = d;
  dist[i] = d;
  for(auto n: adjacentList[i]) {
    if(dist[n] == UNVISITED) {
      low[i] = min(low[i], dfs(n, d+1, i));
      if(d < low[n]) {
        bridges.push(edge(min(i,n), max(i,n)));
      }
    } else if(parent != n) {
      low[i] = min(low[i], dist[n]);
    }
  }
  return low[i];
}

int main () {
  int V, E;
  cin >> V >> E;
  low = vector<int>(V, 0);
  dist = vector<int>(V, UNVISITED);
  adjacentList = vector<vector<int>>(V);

  for(int i = 0; i < E; i++) {
    int s, t;
    cin >> s >> t;
    adjacentList[s].push_back(t);
    adjacentList[t].push_back(s);
  }

  dfs(0, 0, -1);

  while(!bridges.empty()) {
    edge e = bridges.top(); bridges.pop();
    printf("%d %d\n", e.first, e.second);
  }

  return 0;
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define X           first
#define Y           second
#define pb          push_back
#define mp          make_pair
#define SZ(X)       (X.size())
#define mst(a,b)    memset((a),(b),sizeof(a))
#define lowbit(a)   ((a)&(-a))
using namespace std;
typedef unsigned long long ull;
typedef long long LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int mod =  1e9 + 7;
const int inf = 0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int maxn = 1e5+50;
const int maxm = 3e5+50;
const int add=1e5+2;
int a[maxn],x[maxn],c[maxn];
int bits[maxm];
void update(int pos){
    for(;pos<maxm;pos+=lowbit(pos))
        ++bits[pos];
}
int get(int pos){
    int res=0;
    for(;pos;pos-=lowbit(pos))
        res+=bits[pos];
    return res;
}
ll check(int val,int n){
    mst(c,0);mst(bits,0);
    for(int i=1;i<=n;++i)
        c[i]=(a[i]<=val),c[i]+=c[i-1];
    update(0+add);
    ll all=0;
    for(int i=1;i<=n;++i){
        all+=get(2*c[i]-i-1+add);
        update(2*c[i]-i+add);
    }
    return all;
}
int main() {
#ifdef local
    freopen("inpp", "r", stdin);
//    freopen("out.txt", "w", stdout);
#endif // local
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;cin>>n;
    for(int i=1;i<=n;++i)
        cin>>a[i];
    ll ne=(ll)n*(n+1)/2/2+1;
    for(int i=1;i<=n;++i)
        x[i]=a[i];
    sort(x+1,x+1+n);
    int m=unique(x+1,x+1+n)-(x+1);
    for(int i=1;i<=n;++i)
        a[i]=lower_bound(x+1,x+1+m,a[i])-x;
    int l=1,r=m,d;
    while(l<=r){
        int mid=(l+r)>>1;
        if(check(mid,n)>=ne)
            d=mid,r=mid-1;
        else l=mid+1;
    }
    cout<<x[d];
    return 0;


}


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

using namespace std;

int m[1400][1400];
int dp[1400][1400];

int main()
{
	int a,b;
	scanf("%d%d", &a, &b);
	
	
	for(int i = 0; i < a; ++i){
		for(int j = 0; j < b; ++j){
			scanf("%d", &m[i][j]);
		}
	}
	
	for(int i = 0; i < b; ++i){
		dp[0][i] = (m[0][i] == 0)? 1 : 0;
	}
	
	for(int i = 1; i < a; ++i){
		for(int j = 0; j < b; ++j){
			dp[i][j] = (m[i][j] == 0)? 1 + dp[i-1][j] : 0;
		}
	}
	
	int resp = 0;
	
	for(int i = 0; i < a; ++i){
		
		vector<int> izq(b,0);
		izq[0] = -1;
		
		stack<pair<int,int> > el;
		el.push(make_pair(dp[i][0], 0));
		
		for(int j = 1; j < b; ++j){
			while(el.top().first >= dp[i][j]){
				el.pop();
				if(el.empty())break;
			}
			izq[j] = (el.empty())? -1 : el.top().second;
			el.push(make_pair(dp[i][j], j));
		}
		
		stack<pair<int,int> > el2;
		vector<int> der(b,0);
		der[b-1] = b;
		el2.push(make_pair(dp[i][b-1], b-1));
		
		for(int j = b-2; j >= 0; --j){
			while(el2.top().first >= dp[i][j]){
				el2.pop();
				if(el2.empty())break;
			}
			der[j] = (el2.empty())? b : el2.top().second;
			el2.push(make_pair(dp[i][j], j));
		}
		
		for(int j = 0; j < b; ++j){
			resp = max(resp, dp[i][j]*(der[j] - izq[j] - 1));
		}
		
	}
	
	printf("%d\n", resp);
	
}


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

using namespace std ;

const int MAX = 1e5 + 10 ;

int n , m , k ;

vector< vector<int> >adj(MAX) , adj2(MAX) ;
int vis[MAX] , id[MAX] , sz[MAX] ;

int cnt = 0 ;

void dfs(int node)
{
	vis[node] = 1 ;
	id[node] = cnt ;
	sz[cnt]++ ;
	for(auto &child : adj[node])
	{
		if(vis[child])
			continue ;
		dfs(child) ;
	}
	return ; 
}

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n>>m>>k ;
	for(int i = 0 ; i < m ; ++i)
	{
		int x , y ;
		cin>>x>>y ;
		adj[x].push_back(y) ;
		adj[y].push_back(x) ;
	}
	for(int i = 0 ; i < k ; ++i)
	{
		int x , y ;
		cin>>x>>y ;
		adj2[x].push_back(y) ;
		adj2[y].push_back(x) ;
	}
	for(int i = 1 ; i <= n ; ++i)
	{
		if(vis[i])
			continue ;
		cnt++ ;
		dfs(i) ;
	}
	for(int i = 1 ; i <= n ; ++i)
	{
		int ans = sz[id[i]] ;
		ans -= adj[i].size() ;
		for(auto &j : adj2[i])
		{
			if(id[j] == id[i])
				ans-- ;
		}
		cout<<ans-1<<" " ;
	}
	return 0 ;
}		

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

int main() {
  int H, W;
  int count = 0;
  string S;
  cin >> H >> W;
  
  rep(i, H) {
    string a;
    cin >> a;
    S += a;
  }
  
  rep(i, H) {
  	rep(j, W) {
      count = 0;
      if (S[i*W + j] == '#') {
        cout << '#';
        continue;
      }
      else {
        int d1 = (i-1)*W + (j-1);
        int d2 = (i-1)*W + j;
        int d3 = (i-1)*W + (j+1);
        int d4 = i*W + (j-1);
        int d5 = i*W + (j+1);
        int d6 = (i+1)*W + (j-1);
        int d7 = (i+1)*W + j;
        int d8 = (i+1)*W + (j+1);
        if (0 <= d1 && j != 0) {
          if (S[d1] == '#') count+=1;
        }
        if (0 <= d2) {
          if (S[d2] == '#') count+=1;
        }
        if (0 <= d3 && j != W-1) {
          if (S[d3] == '#') count+=1;
        }
        if (i*W <= d4 && d4 < (i+1)*W) {
          if (S[d4] == '#') count+=1;
        }
        if (i*W <= d5 && d5 < (i+1)*W) {
          if (S[d5] == '#') count+=1;
        }
        if (j != 0 && d6 < H*W) {
          if (S[d6] == '#') count+=1;
        }
        if (d7 < H*W) {
          if (S[d7] == '#') count+=1;
        }
        if (j != W-1 && d8 < H*W) {
          if (S[d8] == '#') count+=1;
        }
      }
      cout << count;
    }
    cout << endl;
  }
}


Measured memory_bytes: 3620
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, const char *argv[])
{
  int n;
  cin >> n;
  vector<int> p(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }

  int ans = 1, min_n = p[0];
  for (int i = 1; i < p.size(); i++) {
    if (p[i] <= min_n) {
      min_n = p[i];
      ans++;
    }
  }

  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 1024