akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define rep(i, init, n) for(int i = init; i <(int)(n); i++)

int N, M , Q;
vector<int> a, b, c, d;
int num;
ll dfs(vector<int>& v, ll m){
    ll ans = 0;
    //REP(i, v.size()) cout << v[i]<< " ";
        //cout << endl;
    if (v.size() < N){
        for(int i = m; i <= M; i++){
            v.push_back(i);
            ll tmp = dfs(v, i);
            ans = max(ans, tmp);
            v.pop_back();
        }
    }
    else{
        num++;
        //REP(i, N) cout << v[i]<< " ";
        //cout << endl;
        //cout << num << endl;
        REP(i, Q){
            if (v[b[i] - 1] - v[a[i] - 1] == c[i]) ans += d[i];
        }
    }
    return ans;
    
}

int main() {
    cin >> N >> M >> Q;
    a.resize(Q);
    b.resize(Q);
    c.resize(Q);
    d.resize(Q);
    REP(i, Q) cin >> a[i] >> b[i] >> c[i] >> d[i];
    vector<int> v;
    num = 0;
    cout << dfs(v, 1) << endl;
    //cout << num << endl;
    return 0;
}

Measured memory_bytes: 3628
def main
  all_staff_manage = []

  loop do
    staff_num = gets.chomp.to_i
    break if staff_num == 0
    all_staff_manage << StaffManage.new.make_staffs(staff_num)
  end

  all_staff_manage.each do |staff_manage|
    staff_manage.output()
  end
end

class StaffManage
  def initialize()
    @staffs = Hash.new(0)
    @result = []
  end

  def make_staffs staff_num
    staff_num.times do
      id,rate,number = gets.chomp.split(' ').map{|x| x.to_i}
      @staffs[id] += rate * number
    end
    self
  end

  def output()
    check()
    if @result.empty?
      puts 'NA'
    else
      @result.each{|id| puts id}
    end
  end

  private
  def check()
    @staffs.each do |key, value|
      @result << key if value >= 1000000
    end
  end
end

main

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

using namespace std;

int main() {
	int N, M;
    cin >> N >> M;
	int D = 1;
	for(int i=1; i<=sqrt(M); i++) {
		if(M % i == 0) {
			if (M / i >= N) {
				D = max(i, D);
			}
			if (i >= N) {
				D = max(M/i, D);
			}

		}
	}
	cout << D << endl;
}


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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, c;
    cin >> a >> b >> c;
    cout << max(c - (a - b), 0) << endl;

    return 0;
}


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

void unrestorable()
{
    cout << "UNRESTORABLE\n";
}

string func(string S, string &T, int indx)
{
    for(int i=0; i<T.size(); i++)
    {
        if(S[indx + i] == '?')
            S[indx + i] = T[i];
        
        if(S[indx + i] != T[i])
            return "*";
    }

    for(int i=0; i<S.size(); i++)
        if(S[i] == '?')
            S[i] = 'a';
    
    return S;
}

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

    string S, T, R;
    cin >> S >> T;
    R = "*";

    if(T.size() > S.size())
    {
        unrestorable();
        return 0;
    }

    for(int i=T.size()-1; i<S.size(); i++)
    {
        string X = func(S, T, i + 1 - T.size());

        if((R == "*" || R > X) && X != "*")
            R = X;
    }

    if(R == "*")
        unrestorable();
    else
        cout << R << "\n";
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
#define SortAsc(c) std::sort(c.begin(), c.end())
#define SortDesc(c) std::sort(c.rbegin(), c.rend())
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> g(H);
  for (int i = 0; i < H; i++) {
    cin >> g.at(i);
  }

  for (int y = 0; y < H; y++) {
    for (int x = 0; x < W; x++) {
      if (g.at(y).at(x) != '#') continue;

      // 4方向探索して# (またはOKマスのx)が見つからなかったらNo
      bool found = false;
      for (int i = 0; i < 4; i++) {
        int ty = y + dy[i], tx = x + dx[i];
        if (ty < 0 || ty > H - 1 || tx < 0 || tx > W - 1) continue;
        if (g.at(ty).at(tx) != '.') {
          found = true;
          g.at(ty).at(tx) = 'x';  // もう探索不要としてマーク
          break;
        }
      }
      if (!found) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
import math

d, g = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(d)]
ans = float('inf')

for i in range(2 ** d):
    sum = 0
    count = 0
    s = set(_ for _ in range(1, d + 1))
    for j in range(d):
        if (i >> j) & 1 == 1:
            sum += l[j][0] * (j + 1) * 100 + l[j][1]
            count += l[j][0]
            s.discard(j + 1)
    if sum < g:
        t = max(s)
        n = min(l[t - 1][0], math.ceil((g - sum) / (t * 100)))
        count += n
        sum += n * t * 100
    if sum >= g:
        ans = min(ans, count)
print(ans)


Measured memory_bytes: 44400
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <numeric>
#include <bitset>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
typedef pair< ll, ll >   cp2;
typedef pair< ll, cp2 >   cp3;
#define fi first
#define se second
#define sec  se.fi
#define thr  se.se
const ll mod = 1000000007;
//              123456789

 
///////////////////////////////////////////////
//
//
///////////////////////////////////////////////

////////////////////////////////////////////////
////////////////////////////////////////////////

bool ans = true;
bool check;
int H, W;
string S[100];
int dx[4] = { 0, 1, 0, -1 };
int dy[4] = { 1, 0, -1, 0 };
int x, y;

int main(){
	cin>>H>>W;
	REP( i, H ){
		cin>>S[i];
	}
	
	REP( i, H ){
		REP( j, W ){	
			if( S[i][j] == '#' ){
				check = false;
				REP( k, 4 ){
					x = j + dx[k];
					y = i + dy[k];
					if( 0 <= x && x < W && 0 <= y && y < H ){
						if( S[y][x] == '#' ) check = true;
					}
				}
				if( !check ) ans = false;
			}
		}
	}
	
	
	if( ans ) cout<<"Yes"<<endl;
	else{	cout<<"No"<<endl;}
}



Measured memory_bytes: 256
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    A,B,K=MI()
    A_=max(0,A-K)
    K=K-A
    if K>0:
        B=max(0,B-K)
    print(A_,B)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 3572
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    A,B,T= map(int, sys.stdin.readline().split())
    c=0
    i=1
    while True:
        if i*A < T+0.5:
            c +=1
            i +=1
        else:
            break
    print(B*c)


Measured memory_bytes: 5072
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

template<typename T>
T gcd(T a, T b) {
	if( a < b ) swap(a, b);
	
	T r;
	while( r = a % b ) {
		a = b;
		b = r;
	}
	
	return b;
}

template<typename T>
map<T, T> prime_factorize(T n) {
	map<T, T> ret;
	for(T i = 2; i * i <= n; ++i) {
		while( n % i == 0 ) {
			ret[i]++;
			n /= i;
		}
	}
	
	if( n != 1 ) ret[n] = 1;
	
	return ret;
}

int main(void) {
	int n;
	cin >> n;
	
	vector<int> a(n);
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	
	int g = a[0];
	for(int i = 1; i < n; ++i) {
		g = gcd(g, a[i]);
	}
	
	if( g > 1 ) {
		cout << "not coprime" << endl;
		return 0;
	}
	
	int maxa = *max_element(a.begin(), a.end());
	vector<int> sieve(maxa + 1);
	
	iota(sieve.begin(), sieve.end(), 0);
	
	for(int i = 2; i <= maxa; ++i) {
		if( sieve[i] == i ) {
			for(int j = 2 * i; j <= maxa; j += i) {
				if( sieve[j] == j ) {
					sieve[j] = i;
				}
			}
		}
	}
	
	vector<int> cnt(maxa + 1, 0);
	for(int i = 0; i < n; ++i) {
		map<int, int> mp;
		int t = a[i];
		
		while( t > 1 ) {
			mp[sieve[t]]++;
			t /= sieve[t];
		}
		
		mp[t]++;
		
		for(auto& v : mp) {
			cnt[v.first]++;
		}
	}
	
	for(int i = 2; i <= maxa; ++i) {
		if( cnt[i] > 1 ) {
			cout << "setwise coprime" << endl;
			return 0;
		}
	}
	
	cout << "pairwise coprime" << endl;
	
	return 0;
}


Measured memory_bytes: 14776
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cstdlib>
#define rep(i,x) for(int i=0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 10010010010;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
ll gcd(ll a, ll b) {//a>b
    if (a < b)swap(a, b);
    if (a % b == 0) return b;
    else return gcd(b, a % b);
}
int main() {
    ll N;
    cin >> N;
    ll m = 0;
    ll a = 0;
    ll r = 0;
    ll c = 0;
    ll h = 0;
    string s;
    rep(i, N) {
        cin >> s;
        if (s[0] == 'M')m++;
        if (s[0] == 'A')a++;
        if (s[0] == 'R')r++;
        if (s[0] == 'C')c++;
        if (s[0] == 'H')h++;
    }
    ll ans = m * a * r + m * a * c + m * a * h + m * r * c + m * r * h +
        m * c * h + a * r * c + a * r * h + a * c * h + r * c * h;
    cout << ans << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
map<string, int> mmap;
int main(){
    int n;
    scanf("%d",&n);
    while(n--){
        int typ;
        scanf("%d",&typ);
        if(typ==0){
            char key[21];int val;
            scanf("%s %d",key,&val);
            map<string,int>::iterator it;
            it = mmap.find(key);
            if (it != mmap.end())
                it->second=val;
            else
                mmap.insert(make_pair(key,val));

        }
        else if(typ==1){
            char key[21];
            scanf("%s",key);

            map<string,int>::iterator it;
            it = mmap.find(key);
            if (it != mmap.end())
                cout<<it->second<<endl;
            else
                cout<<"0"<<endl;
        }
        else if(typ==2){
            char key[21];
            scanf("%s",key);
            map<string,int>::iterator it;
            it = mmap.find(key);
            if (it != mmap.end())
                mmap.erase(it);
        }
        else if(typ==3){
            char lc[24],rc[24];
            int cnt=1;
            //cin>>l>>r;
            scanf("%s %s",lc,rc);
            string l(lc),r(rc);
            map<string,int>::iterator itr;
            map<string,int>::iterator itlow,itup;
            itlow=mmap.lower_bound(l);
            itup=mmap.upper_bound(r);

            for(itr=itlow;itr!=itup;++itr){
                // if(r.compare(itr->first)<0)
                //    break;
                //if(l.compare(itr->first) <= 0 && r.compare(itr->first)>=0){
                    //cout<<itr->first<<" "<<itr->second<<endl;
                printf("%s %d\n",itr->first.c_str(),itr->second);

                cnt++;
                    if(cnt==1000000)
                        break;
                }


            }
        }
    }




Measured memory_bytes: 26040
#include<iostream>
#include<set>
#include<vector>
#include<string.h>
#include<map>
using namespace std;
long long a[3001];
int main(){
  string s,t;
  cin>>s>>t;
  if(s.size()!=t.size()){
    cout<<"No"<<endl;
    return 0;
  }
  for(int i=0;i<s.size();i++){
    char c=s[s.size()-1];
    s.erase(s.end()-1);
    s.insert(s.begin(),c);
    if(s==t){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
const ll M=1e9+7;
char ch[100];
ll power(ll x,ll y){
    ll res=1;
    x=x;
    if(x==0)
        return 0;
    while(y>0){
        if(y&1)
            res=(res*x);
        y=y>>1;
        x=(x*x);
    }
    return res;
}

int main(){
  ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m;
    cin>>n>>m;
    ll a[n];
    ll i;
    for(i=0;i<n;i++)
        cin>>a[i];
    vector<ll>v[n];
    for(i=0;i<m;i++){
        ll x,y;
        cin>>x>>y;
        v[x-1].push_back(y-1);
        v[y-1].push_back(x-1);
    }
    ll count=0;
    ll check[n]={0};


    for(i=0;i<n;i++){
        ll max1=INT_MIN;
        for(ll j=0;j<v[i].size();j++)
            max1=max(max1,a[v[i][j]]);
        check[i]=max1;
    }

    // for(auto x:check)
    //     cout<<x<<" ";
    // cout<<"\n";
    for(i=0;i<n;i++){
        if(check[i]==INT_MIN)
            count++;
        else if(a[i]>check[i])
            count++;
    }


    cout<<count<<"\n";
}

Measured memory_bytes: 11064
n,m,l=list(map(int,input().split()))
A=[list(map(int,input().split())) for i in range(n)]
B=[list(map(int,input().split())) for i in range(m)]
C=[]
for i in range(n):
    row=[]
    for j in range(l):
        ele=0
        for k in range(m):
            ele+=A[i][k]*B[k][j]
        row.append(ele)
    C.append(row)
for i in C:
    print(*i)
            


Measured memory_bytes: 7060
#include<bits/stdc++.h>
using namespace std;
typedef long long int  ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define txt freopen("ip.txt", "r", stdin); freopen("op.txt", "w", stdout)
#define a3 INT_MAX
#define i3 INT_MIN
#define a6 INT64_MAX
#define i6 INT64_MIN
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define quickie ios_base::sync_with_stdio(false); cin.tie(NULL);
#define div2(a) (!(a&1))
#define deb(x) cout<<(#x)<<" "<<(x)<<"\n";
#define newl cout<<"\n" 
#define pi 3.14159265358979323846
#define mod 1000000007
#define all(s) s.begin(),s.end()
#define fp(x) fixed<<setprecision(x)<<
#define split(x) while ((cout<<s[i],i+=1) && (i<n-1) && (cout<<x));
int digit(ll a)
{
    vector<long long> dig = {
        0,
        9,
        99,
        999,
        9999,
        99999,
        999999,
        9999999,
        99999999,
        999999999,
        9999999999,
        99999999999,
        999999999999,
        9999999999999,
        99999999999999,
        999999999999999,
        9999999999999999,
        99999999999999999,
        999999999999999999,
        INT64_MAX};
    auto it = lower_bound(dig.begin(), dig.end(), a);
    int idx = (it - dig.begin());
    return idx;
}
int digit(int a)
{
int r;
r = (a >= 1000000000) ? 9 : (a >= 100000000) ? 8 : (a >= 10000000) ? 7 : (a >= 1000000) ? 6 : (a >= 100000) ? 5 : (a >= 10000) ? 4 : (a >= 1000) ? 3 : (a >= 100) ? 2 : (a >= 10) ? 1 : 0;
return r + 1;
}

bool ithBitIsSet(int mask, int bit){
    int maskformask = 1<<bit;
    return (maskformask)&(mask); 
}


int main(){
    quickie;
    //txt;
    int m,n,k;
    cin>>m>>n>>k;
    char mat[m][n];
    for (int i = 0; i < m; i++)
    {
        for (int j = 0; j < n; j++)
        {
            cin>>mat[i][j];
        }
        
    }
    int ans = 0;
    
    for (int i = 0; i < 1<<m; i++)
    {
        for (int j = 0; j < 1<<n; j++)
        {
            int count = 0;
            for (int h = 0; h < m; h++)
            {
                for (int v = 0; v < n; v++)
                {
                    if(!ithBitIsSet(i,h) && !ithBitIsSet(j,v) && mat[h][v]=='#'){
                        count++;
                    }
                }
                
            }
            if(count == k ){
                ans++;
            }
            
        }
        
    }
    cout<<ans;
    return 0;
}

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

#define pb push_back
#define mk make_pair
#define sc second
#define fr first

using namespace std;

typedef long long ll;

const int N = (int) 1e6 + 5;
const int mod = (int) 1e9 + 7;

int n,last,a[N],cnt,sz[N];
vector<int> v;

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

        cin >> n;

        for (int i = 1; i <= n; i ++) {
                cin >> a[i];
                if(a[i] != a[i - 1])
                        v.pb(a[i]);
        }
        for(int i = 0; i < v.size(); i ++)
                sz[i] = 1;

        for (int i = 1; i < v.size(); i ++){
                if (v[i] >= v[i - 1]) {
                        if (last == 2 && sz[i - 1] > 1) cnt ++;
                        else{
                                sz[i] = sz[i - 1] + 1;
                                last = 1;
                        }
                }
                else {
                        if (last == 1 && sz[i - 1] > 1) cnt ++;
                        else {
                                sz[i] = sz[i - 1] + 1;
                                last = 2;
                        }
                }
        }
        cout << cnt + 1 << endl;
        return 0;
}


Measured memory_bytes: 5240
#include<stdio.h>
int main(){
  int m,f,r;
  while(1){
    scanf("%d%d%d",&m,&f,&r);
    if(m==-1 && f==-1 && r==-1){break;}
    if(m==-1 || f==-1){
      printf("F\n");
    }
    else if(m+f>=80){
      printf("A\n");
    }
    else if(m+f>=65 && m+f<80){
      printf("B\n");
    }
    else if(m+f>=50 && m+f<65){
      printf("C\n");
    }
    else if(m+f>=30 && m+f<50){
      if(r>=50){
	printf("C\n");
      }
      else{
	printf("D\n");
      }
    }
    else if(m+f<30){
      printf("F\n");
    }
  }
  return 0;
}
  



Measured memory_bytes: 2680
import java.util.*;
import java.io.*;

class Main {

	void solve() {

		char[] a = incharar();
		int ans = 700;
		for (int i=0; i<a.length; i++) {
			if (a[i] == 'o') ans += 100;
		}
		out.println(ans);

	}

	public static Scanner in = new Scanner(System.in);
	public static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) {
		new Main().solve();
		out.flush();
	}

	public int inint() {
		return in.nextInt();
	}

	public String instr() {
		return in.next();
	}

	public int[] inintar(int num) {
		int[] a = new int[num];
		for (int i=0; i<num; i++) {
			a[i] = in.nextInt();
		}
		return a;
	}

	public char[] incharar() {
		return in.next().toCharArray();
	}

}

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll n=2;
ll T[2],A[2],B[2];

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

  rep(i,n)cin>>T[i];
  rep(i,n)cin>>A[i];
  rep(i,n)cin>>B[i];

  ll ta=T[0]*A[0]+T[1]*A[1];
  ll tb=T[0]*B[0]+T[1]*B[1];
  ll ma=T[0]*A[0];
  ll mb=T[0]*B[0];

  if(ta==tb){
    cout<<"infinity"<<endl;
    return 0;
  }else if(ta<tb){
    ll D=tb-ta;
    ll dist=ma-mb;
    if(dist<0){
      cout<<0<<endl;
    }else{
      if(dist%D==0) cout<<((dist-1)/D)*2+2<<endl;
      else cout<<(dist/D)*2+1<<endl;
    }
  }else{
    ll D=ta-tb;
    ll dist=mb-ma;
    if(dist<0){
      cout<<0<<endl;
    }else{
      if(dist%D==0) cout<<((dist-1)/D)*2+2<<endl;
      else cout<<(dist/D)*2+1<<endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
int main(void){
   int A,B,C,X;
   cin>>A>>B>>C>>X;
   
   int cnt=0;
   rep(i,A+1){
       int rest=X-500*i;
       rep(j,B+1){
           int rest2=rest-100*j;
           rep(k,C+1){
               int rest3=rest2-50*k;
               if(rest3==0){
                   cnt++;
               }
           }
       }
   }
   
   cout<<cnt<<endl;
  
}

Measured memory_bytes: 3620
H, W = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(H)]

# 左上からコインの枚数が奇数であるマスのコインを右または下に移す
b = [[t for t in x] for x in a]
moves = []
for i in range(1, H + 1):
    for j in range(1, W + 1):
        if b[i - 1][j - 1] % 2 == 1:
            if j < W:
                b[i - 1][j] += 1
                moves.append((i, j, i, j + 1))
            elif i < H:
                b[i][j - 1] += 1
                moves.append((i, j, i + 1, j))
ans = (
    '{}\n{}'.format(
        len(moves),
        '\n'.join(
            ' '.join([str(y1), str(x1), str(y2), str(x2)])
            for (y1, x1, y2, x2) in moves
        )
    ) if moves else
    '0'
)

print(ans)


Measured memory_bytes: 33356
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[MAXN];
char S[MAXN];

int main()
{
    int n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n;

    double res = (double)n*acos(-1);

    res*=2.0;

    cout<<fixed;
    cout.precision(9);
    cout<<res<<"\n";

    return 0;
}


Measured memory_bytes: 3852
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x;
    int cont=0;
    cin>>x;
    int a,b;

    for(int i=0;i<x;i++)
    {
        cin>>a>>b;
        for(int j=a;j<=b;j++)
        {
            cont++;
        }
    }
    cout<<cont<<endl;












    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MAX 1001
int dp[MAX][MAX];
int lcs(string& s,string& t,int si,int ti){
	int ret = 0;
	if(si < 0 || ti < 0)return 0;
	if(dp[si][ti] != -1)return dp[si][ti];
	if( s[si] == t[ti] ){
		ret = max(ret, lcs(s,t,si-1,ti-1) + 1);
	}else{
		if(si > 0)ret = max(ret, lcs(s,t,si-1,ti));
		if(ti > 0)ret = max(ret, lcs(s,t,si,ti-1));
	}
	return dp[si][ti] = ret;
}

int main(void){
	int T;
	cin >> T;
	for(int k=0;k<T;k++){
		string s,t;
		cin >> s >> t;
		// memset(dp,0,sizeof(dp));
		for(int i=0;i<MAX;i++)for(int j=0;j<MAX;j++)
			dp[i][j] = -1;
		cout << lcs(s,t,s.size()-1,t.size()-1) << endl;;
	}
	return 0;
}

Measured memory_bytes: 7180
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define s second
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
using namespace std;

ll arr[100005];

int main(){
    faster
    int T = 1;
    while(T--){
        ll n,l;
        cin>>n>>l;
        
        rep(i,0,n-1) {
            cin>>arr[i];
        }
        
        int ind;
        
        int f = 0;
        rep(i,0,n-2){
            if(arr[i]+arr[i+1] >= l){
                f = 1;
                ind = i;
                break;
            }
        }
        
        
        if(!f){
            cout<<"Impossible";
        } else{
            cout<<"Possible\n";
            for(int i=0; i<ind; i++){
                cout<<i+1<<" ";
            }
            for(int i=n-2; i>ind; i--){
                cout<<i+1<<" ";
            }
            cout<<ind+1;
        }
        
        
    }
    return 0;
}








Measured memory_bytes: 1664
#include <bits/stdc++.h>
//#pragma once
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////


signed main(){
  int n;string s;cin>>n>>s;
  int cnt = 0;
  rep(i,n-2){
    if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C')cnt++;
  }
  cout << cnt << endl;
}


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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	if (n==3)
	{
		cout<<"2\n1 3\n2 3\n";
	}
	else if (n==4)
	{
		cout<<"4\n1 2\n1 3\n2 4\n3 4\n";
	}
	else if (n%2==1)
	{
		cout<<(n/2-1)*4+4<<endl<<n<<" "<<1<<endl<<n<<" "<<n-1<<endl<<n<<" "<<n/2<<endl<<n<<" "<<n/2+1<<endl;
		int l=2,r=n-2;
		while (l<r)
		{
			cout<<l-1<<" "<<l<<endl;
			cout<<l-1<<" "<<r<<endl;
			cout<<r+1<<" "<<l<<endl;
			cout<<r+1<<" "<<r<<endl;
			++l;--r;
		}
	}
	else
	{
		cout<<(n/2)*4<<endl<<1<<" "<<n/2<<endl<<1<<" "<<n/2+1<<endl<<n<<" "<<n/2<<endl<<n<<" "<<n/2+1<<endl;
		{
			
		};
		int l=2,r=n-1;
		while (l<r)
		{
			cout<<l-1<<" "<<l<<endl;
			cout<<l-1<<" "<<r<<endl;
			cout<<r+1<<" "<<l<<endl;
			cout<<r+1<<" "<<r<<endl;
			++l;--r;
		}
	}
	return 0;
}


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

typedef long long ll;
typedef pair<ll, ll> P;

const int mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 11


int main()
{
    int n; cin >> n;
    int ans = 0;
    for(int i = 0; i < 100; i++){
        if(ans >= n){
            cout << ans - n << endl;
            break;
        }
        ans += 1000;
    }
}

Measured memory_bytes: 3640
import java.util.*;
public class Main {
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      double W = sc.nextDouble();
      double H = sc.nextDouble();
      double x = sc.nextDouble();
      double y = sc.nextDouble();
      double ans = W*H/2.0;
      String met = "0";
      if(W/2.0==x && H/2.0==y){
        met = "1";
      }
      System.out.println(ans+" "+met);
    }
}

Measured memory_bytes: 39496
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c =(a+b)/2;
    if(((float)a+(float)b)/2-c<0.5){
      System.out.println(c);
    }else{
      System.out.println(c+1);
    }
  }
}

Measured memory_bytes: 23508
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)
        {
            // 解答はココに書く
            var a = cin.ReadInt;
            var b = cin.ReadInt;

            if ((a*b)%2 == 0) {
                WriteLine("Even");
            } else {
                WriteLine("Odd");
            }

        }
    }

    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: 11348
#include <stdio.h>

int main(void)
{
  int N;
  double A;
  double sum=0.0;
  int i;

  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%lf",&A);
    sum+=1.0/A;
  }

  sum = 1.0 / sum;
  printf("%lf\n",sum);

  return 0;
}




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

int main()
{
    char c;
    cin >> c;

    if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')
        cout << "vowel" << endl;
    else
        cout << "consonant" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int n, x, flag;
	int i, j, k;
	
	while (1){
		scanf("%d %d", &n, &x);
		
		if (n == 0 && x == 0){
			break;
		}
		
		flag = 0;
	
		for (i = 1; i <= n; i++){
			for (j = i + 1; j <= n; j++){
				for (k = j + 1; k <= n; k++){
					if (i + j + k == x){
						flag++;
					}
				}
			}
		}
		printf("%d\n", flag);
	}
	
	return 0;
}



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

using namespace std;
using ll = long long;

struct UF {
  vector<int> par, rank;

  UF() {}

  UF(int n) : par(n), rank(n, 1) {
    iota(par.begin(), par.end(), 0);
  }

  int find(int x) {
    if (x == par[x]) return x;
    return par[x] = find(par[x]);
  }

  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (rank[x] < rank[y]) swap(x, y);
    rank[x] += rank[y];
    par[y] = x;
  }

  bool same(int x, int y) {
    return find(x) == find(y);
  }
};


int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> A(M), B(M);
  for (int i = 0; i < M; ++i) {
    cin >> A[i] >> B[i];
    A[i]--;
    B[i]--;
  }

  vector<ll> ans(M);
  ans[M - 1] = N * (N - 1) / 2;

  UF uf(N);
  for (int i = M - 1; i > 0; --i) {
    if (uf.same(A[i], B[i]))
      ans[i - 1] = ans[i];
    else {
      ll a = uf.rank[uf.find(A[i])];
      ll b = uf.rank[uf.find(B[i])];
      uf.unite(A[i], B[i]);
      ans[i - 1] = ans[i] - a * b;
    }
  }
  for (auto s: ans) {
    cout << s << endl;
  }
}


Measured memory_bytes: 4480
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

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

  std::vector<std::string> names(n);
  std::vector<int> scores(n);
  std::vector<int> ids(n);

  for (int i = 0; i < n; ++i) std::cin >> names[i] >> scores[i];
  for (int i = 0; i < n; ++i) ids[i] = i;

  std::sort(ids.begin(), ids.end(), [&names, &scores](const auto& i,
                                                      const auto& j) {
    return names[i] == names[j] ? scores[i] > scores[j] : names[i] < names[j];
  });

  for (auto&& id : ids) std::cout << id + 1 << '\n';
  std::cout << std::flush;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int i, ans=0;
  string S, T;
  cin >> S;
  cin >> T;
  for(i=0; i<3; i++){
    if(S.at(i) == T.at(i)) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>  
#include<algorithm>  
#include<queue>  
#include<map>  
#include<cmath>  
#include<cstdio>  
using namespace std;  
  
typedef pair < int , int > Pi;  
typedef long long ll;  
#define INF ( 1ll << 61 )  
#define fr first  
#define sc second  
//Pi data[100000];  
int x[100000], y[100000];  
int xx[100000], yy[1000000];  
  
ll dis( Pi a, Pi b) {  
  return llabs(a.fr - b.fr) + llabs(a.sc - b.sc);  
}  
int main(){  
  int w,h,n;  
  cin >> w >> h;  
  cin >> n;  
  
  for(int i = 0 ; i < n ; i++ ){  
    int a, b;  
    scanf("%d %d",x + i, y + i);  
    xx[i] = x[i], yy[i] = y[i];  
  }  
  sort( x, x + n);  
  sort( y, y + n);  
  
  int center = ( n - 1 ) / 2;  
  ll ret = INF;  
  int mx, my;  
  
  for(int i = center ; i < center + 2 ; i++ ){  
    for(int j = center ; j < center + 2 ; j++ ){  
      ll res = 0LL;  
      ll most = 0;  
      for(int k = 0 ; k < n ; k++ ){  
        most = max( most, dis( Pi( x[i], y[j]), Pi( xx[k], yy[k])));  
        res += dis( Pi( x[i], y[j]), Pi( xx[k], yy[k])) * 2;  
      }  
      if(ret > res - most){  
        ret = res - most;  
        mx = x[i];  
        my = y[j];  
      }  
    }  
  }  
  cout << ret << endl;  
  cout << mx << " " << my << endl;  
}  

Measured memory_bytes: 4696
/// --- In the name of ALLAH --- ///


#include <cmath>
#include<bits/stdc++.h>
using namespace std;


typedef long long              ll;
typedef vector<int>            vi;
typedef vector<ll>             vl;
typedef vector<vi>             vvi;
typedef vector<vl>             vvl;
typedef pair<int,int>          pii;
typedef pair<double, double>   pdd;
typedef pair<ll, ll>           pll;
typedef vector<pii>            vii;
typedef vector<pll>            vll;
typedef double                 dl;

#define endl                   '\n'
#define PB                     push_back
#define F                      first
#define S                      second
#define all(a)                 (a).begin(),(a).end()
#define rall(a)                (a).rbegin(),(a).rend()
#define sz(x)                  (ll)x.size()
#define wt                     ll t; cin>>t; while(t--)
#define input(a,n)             for(int i=0;i<n;i++) cin>>a[i];

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;


#define mem(a,b) memset(a, b, sizeof(a) )
#define sqr(a) ((a) * (a))
#define mod 10000007
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}

ll gcd ( ll a, ll b ) { return __gcd ( a, b ); }
ll lcm ( ll a, ll b ) { return a * ( b / gcd ( a, b ) ); }


const ll mx=1e9;



//q=51;

//ll b[q+1][q+1];


 main()
{
    optimize();
   ll t,n,a,i,in;
   cin>>n>>t>>a;
   ll h[n+1];
   double b[n+1],j,mi;
   for(i=1;i<=n;i++)
   {
       cin>>h[i];
       b[i]=t-(h[i]*(0.006));
       //cout<<b[i]<<endl;
   }
   for(i=1;i<=n;i++)
   {
       if(b[i]>a)
       {
           j=b[i]-a;
           if(i==1){
            mi=j;
            in=1;}
           else if(j<mi)
           {
               mi=j;
               in=i;
           }


       }
       else
       {
           j=a-b[i];
           if(i==1){
            mi=j;
            in=1;}
           else if(j<mi)
           {
               mi=j;
               in=i;
           }


       }

   }
   cout<<in<<endl;



    return 0;
}






























































































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

int H,W,N;
vector<int> V;
int ans[110][110] = {0};

int main()
{
    scanf("%d%d%d",&H,&W,&N);
    for(int i = 0; i < N; i++)
    {
        int a;
        scanf("%d",&a);
        for(int j = 0; j < a; j++)V.push_back(i + 1);
    }
    int now = 0;
    for(int i = 0; i < H; i++)
    {
        if(i % 2)
        {
            for(int j = 0; j < W; j++)
            {
                ans[i][j] = V[now];
                now++;
            }
        }
        else
        {
            for(int j = W - 1; j >= 0; j--)
            {
                ans[i][j] = V[now];
                now++;
            }
        }
    }
    for(int i = 0; i < H; i++)
    {
        for(int j = 0; j < W; j++)
        {
            printf("%d",ans[i][j]);
            if(j != W - 1)printf(" ");
        }printf("\n");
    }
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<math.h>
#include<algorithm>
#include<tuple>
using namespace std;
#define fr(i,n) for(int i=0;i<n;i++)
typedef double db;
typedef tuple<bool,db> bod;
db Pi = 3.14159265358979;

db st(db t){
  t+=4*Pi;
  while(t>=0) t-=2*Pi;
  t+=2*Pi;
  return t;
}

bod J(db a,db b){
  if(a<=Pi){
    return make_tuple(!(a<=b && b<a+Pi),a+Pi-b);
  }
  else{
    return make_tuple(!(a<=b || b<a-Pi),st(a+Pi-b));
  }
}

int main(){
  int n,q,r;
  bool f;
  db x[100],y[100],m[100][100],M;
  cin >> n;
  if(n==2){
    cout<<0.5<<endl<<0.5<<endl;
    return 0;
  }
  fr(i,n) cin>>x[i]>>y[i];
  fr(i,n){
    fr(j,n){
      if(i != j){
        m[i][j]=st(atan2(x[j]-x[i],y[j]-y[i]));
      }
    }
    fr(j,n){
      if(i==j) continue;
      f=0;
      M=2*Pi;
      fr(k,n){
        if(k==i || k==j) continue;
//        cout<<i<<" "<<j<<" "<<k<<" "<<m[i][j]<<" "<<m[i][k]<<endl;
        bod G=J(m[i][j],m[i][k]);
        if(M>get<1>(G)){
          r=k;
          M=get<1>(G);
        }
        if(get<0>(G)){
          f=1;
          break;
        }
      }
      if(!f){
        q=j;
        break;
      }
    }
    if(f) cout<<0.0<<endl;
    else cout<<M/(2*Pi)<<endl;
  }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;


template <typename T>
struct SegTree{
    vector<T> dat;
    int n;
    const T Default;
    SegTree(int n_, const T& def) : Default(def){init(n_);}
    void init(int n_){
        n = 1;
        while(n < n_) n *= 2;
        dat = vector<T>(2*n-1, Default);
    }
    T f(const T& a, const T& b) {
        return max(a, b);
    }
    void update(int k, const T& a){
        k += n-1;
        dat[k] = a;
        while(k > 0){
            k = (k - 1) / 2;
            dat[k] = f(dat[k * 2 + 1], dat[k * 2 + 2]);
        }
    }
    T query(int a, int b, int k, int l, int r ){
        if(r <= a || b <= l) return Default;
        if(a <= l && r <= b) return dat[k];
        T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
        T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
        return f(vl, vr);
    }
    T query(int a, int b) {
        return query(a, b, 0, 0, n);
    }
};
int main(){
    int n;
    cin >> n;
    vi h(n), a(n);
    rep(i, n) cin >> h[i];
    rep(i, n) cin >> a[i];

    SegTree<ll> st(n+10, 0);
    rep(i, n) {
        ll m = st.query(0, h[i]);
        st.update(h[i], m + a[i]);
    }
    cout << st.query(0, n+1) << endl;
    return 0;
}

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

using namespace std;

int zet(int x){
  if(x<0) return -x;
  else return x;}

int main(){
 int n,t,mokuhyo;
  cin>>n>>t>>mokuhyo;
 
  int ondo[n];
  for(int i=0;i<n;i++){
cin>>ondo[i];
  ondo[i]=zet(t*1000-6*ondo[i]-mokuhyo*1000);}

  
  int kotae=1;
  int saitei=0;
  for(int i=0;i<n-1;i++){
    if(ondo[i+1]<=ondo[saitei]){
      saitei=i+1;
      kotae=i+2;}
  }
  
  cout<<kotae<<endl;
  
  
}


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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

struct Vertex {
    vector<ll> node;
};

Vertex V[100005];
bool U[100005];

int main() {
    ll N, K;
    cin >> N >> K;
    REP(i, N - 1) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        V[a].node.push_back(b);
        V[b].node.push_back(a);
    }

    ll ans = 1;
    memset(U, 0, sizeof(U));
    queue<pll> q;
    q.push(pll(0, K));
    while (!q.empty()) {
        pll t = q.front();
        q.pop();

        if (K - t.second < 0)
            ans = 0;
        ans = (ans * (t.second)) % MOD;
        U[t.first] = true;
        ll s = 1;
        if (t.first != 0)
            s++;
        REP(i, V[t.first].node.size()) {
            ll n = V[t.first].node[i];
            if (U[n])
                continue;

            q.push(pll(n, K - s));
            s++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8180
#include <stdio.h>

int main(void)
{
	int a, b, c, x;
	scanf("%d%*c%d%*c%d%*c%d%*c", &a, &b, &c, &x);
	int cnt = 0;
	for(int i=0;i<=a;i++) {
		for(int j=0;j<=b;j++) {
			for(int k=0;k<=c;k++) {
				if(i*500+j*100+k*50 == x) cnt++;
			}
		}
	}
	printf("%d", cnt);

	return 0;
}

Measured memory_bytes: 128
import sys
import numpy as np

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	N = II()
	H = LI()
	H = np.array(H)
	H = H[:-1] >= H[1:]
	ans = 0
	cnt = 0
	for i in range(N-1):
		if H[i]:
			cnt+=1
			ans = max(ans,cnt)
		else:
			cnt=0
	print(ans)

if __name__ == '__main__':
	main()

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

using namespace std;

int main()
{
	vector<int> vec;

	int q;
	cin >> q;

	int comand1, comand2;
	for (int i = 1; i <= q; i++) {
		cin >> comand1;
		
		switch (comand1)
		{
		case 0:cin >> comand2;
			vec.push_back(comand2);
			break;
		case 1:cin >> comand2;
			cout << vec[comand2] << endl;;
			break;
		case 2:vec.pop_back();
			break;
		}

	}

	return 0;
}


Measured memory_bytes: 3856
#include <iostream>
#include <queue>
#include <map>
using namespace std;

bool is_goal( string s )
{
	bool ok = true;
	for ( int i = 0; i + 1 < s.size(); i++ ) if ( s[i] != s[i+1] ) ok = false;
	return ok;
}

char change_color( char a, char b )
{
	if ( a == 'r' )
		return ( b == 'g' ) ? 'b' : 'g';

	else if ( a == 'g' )
		return ( b == 'b' ) ? 'r' : 'b';

	else if ( a == 'b' )
		return ( b == 'r' ) ? 'g' : 'r';

	return ' ';
}

int main( void )
{
	string in;
	while ( cin >> in )
	{
		if ( in == "0" )
			break;

		map <string, int>	V;
		queue <string>		Q;

		V[in] = 0;
		Q.push( in );

		int kotae = -1;
		while ( Q.empty() == false )
		{
			string now = Q.front();
			Q.pop();

			if ( is_goal( now ) )
			{
				kotae = V[now];
				break;
			}

			for ( int i = 0; i + 1 < now.size(); i++ )
			{
				string tmp = now;
				if ( tmp[i] != tmp[i+1] )
				{
					tmp[i] = tmp[i+1] = change_color( tmp[i], tmp[i+1] );
				}

				if ( V.find( tmp ) == V.end() )
				{
					V[tmp] = V[now] + 1;
					Q.push( tmp );
				}

			}

		}

		if ( kotae == -1 )
			cout << "NA" << endl;
		else
			cout << kotae << endl;

	}
	return 0;
}

Measured memory_bytes: 1868
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = list(map(int, input()))
ans = sum(n)
s = 0
for i,num in enumerate(n):
    if num>=1:
        ans = max(ans, s + (num-1) + 9*(len(n)-i-1))
    s += num
print(ans)

Measured memory_bytes: 61724
import copy

def culc(array):
    summy = 0
    indexes = [i for i, x in enumerate(array) if x == '+']
    ff = 0
    for i in indexes:
        summy += int("".join(array[ff:i]))
        ff = i+1
    summy += int("".join(array[ff:]))
    return summy

nums = list(input())
ans = 0

for i in range(2**(len(nums)-1)):
    bit = bin(i)
    obj = copy.deepcopy(nums)
    k = 0
    for j in range(len(nums)-1):
        if ( i >> j) & 1:
            obj.insert(j+1+k,'+')
            k += 1
    ans += culc(obj)

print(ans)

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

int hour, m, s;

int main(void) {
	cin >> s;
	m = s / 60;
	s = s - m * 60;
	hour = m / 60;
	m = m - hour * 60;
	cout << hour << ':' << m << ':' << s << endl;
	return 0;
}

Measured memory_bytes: 1164
#include <vector>
#include <map>
#include <set>
#include <sstream>
#include <algorithm>
#include <bitset>
#include <utility>
#include <iostream>
#include <cmath>
#include <deque>
#include <string>
#include <time.h>

#define pii pair<ll,ll>
#define X first
#define Y second
#define mp make_pair

typedef long long ll;
using namespace std;
#define MAXN 228228
#define MOD 1000000007
ll n, x, k, z, m, a[200500], b[200500], ra[200500], rb[200500], pa, pb;
int main() {
    cin >> n;
    cout << n * (n - 1) / 2 << endl;
    return 0;
}

Measured memory_bytes: 256