akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <climits>
#include <cmath>
#include <functional>
#include <map>
#include <queue>
#include <set>

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define size_t unsigned long long
#define ll long long
#define REP(i,a) for(int i=0;i<(a);i++)
#define REPR(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
// using ll = long long;
// using vi = vector<int>;
// using vvi = vector<vi>;
// using vl = vector<long long>;
// using vvl = vector<vl>;
// using vs = vector<string>;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const int MOD = 1e9 + 7;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

int kaijo (int a, int result) {
  if (a == 0) {
    return result;
  } else {
    return kaijo(a-1, result * a);
  }
}

int kaijo(int a) {
  return kaijo(a,1);
}

ll kaijo_ll (ll a, ll result) {
  if (a == 0) {
    return result;
  } else {
    return kaijo_ll(a-1, result * a);
  }
}

ll kaijo_ll(ll a) {
  return kaijo_ll(a,1);
}

int main () {
  ll count;
  cin >> count;
  std::vector<int> v(10);
  std::vector<string> s(count);
  for (ll i = 0; i < count; i++) {
    cin >> s[i];
    for (ll j = 0; j < 10; j++) {
      v[j] = s[i][j];
    }
    VSORT(v);
    for (ll j = 0; j < 10; j++) {
      s[i][j] = v[j];
    }
  }
  VSORT(s);
  ll c = 0, result = 0;
  for (ll i = 0; i < count-1; i++) {
    if(s[i] == s[i+1]) {
      c++;
    } else {
      result += (c+1)*c/2;
      c = 0;
    }
  }
  result += (c+1)*c/2;
  cout << result << endl;
}


Measured memory_bytes: 9344
n = int(input())
lists = [[] for _ in range(n)]
for i in range(n):
    a = int(input())
    for j in range(a):
        x, y = map(int, input().split())
        lists[i].append((x-1, y))
ans = 0
for i in range(1, 2**n):
    status = True
    for j in range(n):
        if (i >> j) & 1 == 0:
            continue
        for x, y in lists[j]:
            if (i >> x) & 1 != y:
                status = False
                break
        if status == False:
            break
    if status == True:
        ans = max(ans, bin(i).count('1'))
print(ans)

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

int main(){
  int A, B, K;
  cin >> A >> B >> K;
  vector<int> a;
  int b = min(A, B);
  for(int i = 1; i <= b; i++){
    if(A % i == 0 && B % i == 0) a.push_back(i);
  }
  reverse(a.begin(), a.end());
  cout << a.at(K-1) << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
#define NUM 1000000007
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n;
    string s;
    cin>>n>>s;
    map<char,int> a;
    rep(i,n) a[s[i]]++;
    ll ans=1;
    for(auto &b:a){
        ans*=b.second+1;
        ans%=NUM;
    }
    cout<<ans-1;
}

Measured memory_bytes: 3760
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void calc(int k, string s) {
    bool[string] d;
    // 長さ i の部分文字列を求める
    // K 番目の文字列の長さは高々 K
    for (int i = 1; i <= k; i++) {
        for (int j = 0; j < s.length; j++) { // s[j] からの部分文字列
            if (j + i > s.length) break;

            string t = s[j..j+i];
            d[t] = true;
        }
    }

    auto t = d.keys;
    t.partialSort(k);
    writeln(t[k-1]);
}

void main() {
    string s = readln.chomp;
    int k = readint;

    calc(k, s);
}


Measured memory_bytes: 3324
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stack>
#include <stdio.h>
#include <string>
using namespace std;

int main()
{
	int x, y;
	stack<int> s;
	string st;

	while (cin >> st) {
		if (st[0] == '+') {
			x = s.top(); s.pop();
			y = s.top(); s.pop();
			s.push(x + y);
		}
		else if (st[0] == '-') {
			x = s.top(); s.pop();
			y = s.top(); s.pop();
			s.push(y - x);
		}
		else if (st[0] == '*') {
			x = s.top(); s.pop();
			y = s.top(); s.pop();
			s.push(x * y);
		}
		else {
			s.push(atoi(st.c_str()));
		}
	}

	cout << s.top() << "\n";
}



Measured memory_bytes: 3224
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
 vector<char>s,t;
 char sa[110],ta[110];
 sc(sa);sc(ta);
 ll slen=strlen(sa),tlen=strlen(ta);
 rep(i,0,slen)push(s,sa[i]);
 rep(i,0,tlen)push(t,ta[i]);
 ll flag=0;
 sort(s);sort(t);
 ll start=0;
 rep(i,0,slen){
  rep(j,start,tlen){
   //cout<<s[i]<<" "<<t[j]<<endl;
   if(s[i]<t[j]){
    py;return 0;
   }
   if(sa[i]==ta[j]){
    flag++;start=j+1;break;
   }
  }
 }
 if(slen<tlen&&flag==min(slen,tlen)){py;return 0;}
 pn;
  
return 0;}

Measured memory_bytes: 3644
import Data.List
import Data.Traversable
main = do
  n <- (read :: String -> Int) <$> getLine
  ps <- for [1..n] $ \x ->
    (\xs -> (xs!!0 , xs!!1)) . map read . words <$> getLine
  putStrLn . show $ solve ps
solve :: [(Integer,Integer)] -> Integer
solve ps =
  let sorted = reverse . (sortBy (\(a1,a2) (b1,b2) -> compare (a1+a2) (b1+b2) )) $ ps
  in addEveryOther sorted



addEveryOther :: [(Integer,Integer)] -> Integer
addEveryOther [] = 0
addEveryOther ((a1,a2):[]) = a1
addEveryOther ((a1,a2):(b1,b2):xs) = a1 - b2 + (addEveryOther xs)


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

using namespace std;
typedef long long llong;
int main()
{
    int a,b,c,d,e,f;
    while(cin>>a>>b>>c>>d>>e>>f){
        a=a*100;b=b*100;
        int cnta=f/a,cntb=f/b;
        set<int>water,sugar;
        for(int i=0;i<=cnta;++i){
            for(int j=0;j<=cntb;++j){
                if(i==0&&j==0)continue;
                int tmp=i*a+j*b;
                if(tmp<=f){water.insert(tmp);}

            }
        }
        int cntc=f/c,cntd=f/d;
        for(int i=0;i<=cntc;++i){
            for(int j=0;j<=cntd;++j){
                if(i==0&&j==0)continue;
                int tmp=i*c+j*d;
                if(tmp<=f)sugar.insert(tmp);
//                cout<<tmp<<endl;
            }
        }
        double per=0;int answater=0,anssugar=0;
        double rr=(double)e/(double)(e+100);
        for(set<int>::iterator it=water.begin();it!=water.end();++it){
            for(set<int>::iterator to=sugar.begin();to!=sugar.end();++to){
                int dw=(*it),ds=(*to);
                double tmpper=(double)ds/(double)(ds+dw);
                if((dw+ds)<=f&&tmpper<=rr&&tmpper>per){
                    per=(double)ds/(double)(ds+dw);answater=dw;anssugar=ds;
                }
            }
        }
        if(answater==0)answater=*water.begin();
        printf("%d %d\n",anssugar+answater,anssugar);
    }
    return 0;
}

Measured memory_bytes: 384
import sys
from heapq import heappop, heappush

def main():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    V = list(map(int, input().split()))

    ans = 0
    for left in range(min(N, K) + 1):
        for right in range(min(N, K) - left + 1):
            heap = []
            for v in V[:left]:
                heappush(heap, v)

            for v in V[N - right:]:
                heappush(heap, v)

            cnt = left + right
            while cnt < K and len(heap) > 0:
                v = heappop(heap)
                if v >= 0:
                    heappush(heap, v)
                    break

                cnt += 1

            ans = max(ans, sum(heap))

    return ans


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <cmath>
#include <iomanip>
using namespace std; 
typedef long long ll; typedef string str;

int main ()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
	
	char a;
	cin >> a;
	
	if(a >= 65 && a <= 90)
		cout << "A";
	else cout << "a";
}


Measured memory_bytes: 3032
//Relive your past life.
//Face your demons.
//The past is never dead,it is not even past.
//The memories are not only the key to the past but...also to the future.
//coded in Rusty Lake
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
using namespace std;
int n,cnt[100005],f[100005];
priority_queue<int> q[100005];
vector<int> v[100005];
int main(){
    scanf("%d",&n);
    for(int i=2;i<=n;++i){
        int x;
        scanf("%d",&x);
        ++cnt[x],v[i].pb(x);
    }
    queue<int> Q;
    for(int i=1;i<=n;++i)if(!cnt[i])Q.push(i);
    while(!Q.empty()){
        int x=Q.front(),k=0;
        Q.pop();
        while(!q[x].empty()){
            ++k;
            f[x]=max(f[x],k+q[x].top());
            q[x].pop();
        }
        for(int i=0;i<v[x].size();++i){
            q[v[x][i]].push(f[x]);
            if(!--cnt[v[x][i]])Q.push(v[x][i]);
        }
    }
    printf("%d\n",f[1]);       
    //system("pause");
    return 0;
}


Measured memory_bytes: 12800
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;

int main() {
    string s,t;
    cin >> s >> t;
    vector<string> ans;
    auto judge = [&](int n) {
        string ns = s.substr(n,t.size());
        bool ok = true;
        rep(i,ns.size()) {
            char sc = ns[i];
            char tc = t[i];
            if(sc == '?' || sc == tc) continue;
            ok = false;
        }
        return ok;
    };
    if(s.size() < t.size()) {
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    rep(i,s.size()-t.size()+1) {
        if(judge(i)) {
            string ns;
            if(i < s.size()-t.size()+1) ns = s.substr(0,i)+t+s.substr(i+t.size());
            else ns = s.substr(0,i)+t;
            rep(j,ns.size()) if(ns[j] == '?') ns[j] = 'a';
            ans.pb(ns);
        }
    }
    sort(all(ans));
    if(ans.empty()) cout << "UNRESTORABLE" << endl;
    else cout << ans[0] << endl;
}

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

using namespace std;

int main()
{
	int n;
	int a, b;
	int max = 0;
	int count;

	cin >> n;

	count = 0;
	for (int i = 0; i < n; i++) {
		cin >> a >> b;

		if (a == b)
			count++;
		else {
			if (a != b && count > max)
				max = count;
			count = 0;
		}
	}

	if (count > max)
		max = count;

	if (max >= 3)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

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

using namespace std;

int main()
{
    int c,h;
    cin>>c;
    long long sum=0;
    vector<long long >v;
    bool  f=false;
    int mn=INT_MAX;
    for(int i=0; i<c; i++){
        cin>>h;
        if(h%10!=0){mn=min(mn,h);
            f=true;}
        sum+=h;
        v.push_back(h);

    }
    if(sum%10!=0)
        cout<<sum<<endl;
    else
    if(!f)
        cout<<0<<endl;
    else
        cout<<sum-mn<<endl;
    return 0;
}


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

int main(void) {
    int i, len;
    char s[4096], p[4096], s2[4096];  
    scanf("%s", s);
    scanf("%s", p);

    sprintf(s2, "%s%s", s, s);
   


    if(strstr(s2, p) == NULL) {
    printf("No\n");
    }
    else{
    printf("Yes\n");
    }

    return 0;
}


Measured memory_bytes: 2108
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<string.h>
#include <algorithm>
#include<time.h>
#include <numeric>
#include <vector> 
#include <functional>
#include <list>
#include <ctype.h>
#include<map>
#include <set>
#define N 10050
using namespace std;
int main(){
	int n,a[N]={0};
	scanf("%d",&n);
	int v;
//	printf("%d",m);
    
         for(int x=1;x<105;x++)
         for(int y=1;y<105;y++)
         for(int z=1;z<105;z++){
         	v=pow(x,2)+pow(y,2)+pow(z,2)+x*y+y*z+z*x;
			 if(v<10050) a[v]++;
		 }
	
	
	for(int i=1;i<=n;i++)
	printf("%d\n",a[i]);
}

Measured memory_bytes: 3860
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<iostream>
using namespace std;
#define ll long long
#define N 200005
int n;
ll k;
ll a[N],f[N];
bool check(ll x)
{
	ll js=0;
	for(int i=1;i<=n;i++)
	{
		int xz=n-i+1;
		if(a[i]*f[xz]>x)
		{
			ll g=x/f[xz];
			js+=a[i]-g;
		}
	}
	return js<=k;
}
int main()
{
	scanf("%d%lld",&n,&k);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
		scanf("%d",&f[i]);
	sort(a+1,a+n+1);
	sort(f+1,f+n+1);
	ll l=0,r=a[n]*f[n];
	while(l<r)
	{
		//printf("%lld %lld\n",l,r);
		ll mid=(l+r)>>1;
		if(check(mid))r=mid;
		else l=mid+1;
	}
	printf("%lld",l);
}

Measured memory_bytes: 3328
import Control.Monad
import Control.Applicative
import System.IO
import Data.List

main :: IO ()
main = do
  x <- map length . group <$> getLine
  case x of
    [3,1] -> putStrLn "Yes"
    [1,3] -> putStrLn "Yes"
    [4] -> putStrLn "Yes"
    otherwise -> putStrLn "No"

Measured memory_bytes: 380
#include <stdio.h>

int main(){

  int i,j,n,arr[100],minj,tmp,count = 0;;

  //in
  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&arr[i]);
  }
  
  //sort
  for(i=0;i<n-1;i++){
    minj = i;
    
    for(j=i;j<n;j++){
      if(arr[j]<arr[minj]) minj=j;
    }
    //swap
    if(i!=minj){
      tmp = arr[i];
      arr[i] = arr[minj];
      arr[minj] = tmp;
      count++;
    }
  }
  
  //out
  for(i=0;i<n;i++){
    if(i!=0) printf(" ");
    printf("%d",arr[i]);
  }
  printf("\n%d\n",count);
  
  
  return 0;

}

Measured memory_bytes: 604
N=int(input())
A=list(map(int,input().split()))


cnt=0
minimum=10**10
tot=0
for i in range(N):
    if A[i]<0:
        cnt+=1
        A[i]=-A[i]
    minimum=min(minimum,A[i])
    tot+=A[i]

if 0 in A or cnt%2==0:
    print(tot)
else:
    print(tot-2*minimum)

Measured memory_bytes: 64752
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long int ll;

int main(){
	ll n,a,b; cin >> n >> a >> b;
	vector<ll> h(n);
	for(int i=0;i<n;i++){
		cin >> h[i];
	}
	ll l=-1; ll r=1e9;
	while(l+1<r){
		ll mid=(r+l)/2;
		ll cnt=0;
		for(int i=0;i<n;i++){
			if(h[i]>mid*b){
				cnt+=((h[i]-mid*b+(a-b-1))/(a-b));
			}
		}
		if(cnt<=mid){
			r=mid;
		}
		else{
			l=mid;
		}
	}
	cout << r << endl;
}

Measured memory_bytes: 1024
fn main() {
	let mut s = String::new();
	std::io::stdin().read_line(&mut s).unwrap();
	let s = s.trim();
	let a = s.bytes().enumerate().fold(0, |r, (i, c)| (if i & 1 == 0 { 1 } else { 0 } ^ if c == b'0' { 1 } else { 0 }) + r);
	let b = s.bytes().enumerate().fold(0, |r, (i, c)| (if i & 1 != 0 { 1 } else { 0 } ^ if c == b'0' { 1 } else { 0 }) + r);
	println!("{}", std::cmp::min(a, b));
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String S = sc.next();
		String s0 = S.substring(0, 1);
		String s1 = S.substring(1, 4);
		char[] c = S.toCharArray();
		boolean b = false;

		int pos = s1.indexOf(s0);

		switch (pos) {
			case 0:
				b = (c[2] == c[3]) && (c[0] != c[2]);
				break;
			case 1:
				b = (c[1] == c[3]) && (c[0] != c[1]);
				break;
			case 2:
				b = (c[1] == c[2]) && (c[0] != c[1]);
				break;
			default:
				break;
		}

		if (b) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}

}


Measured memory_bytes: 21844
find'::Eq a=>a->[] a->Int
find' x [] = 0
find' x (y:ys) =
  if y == x
    then 0
    else 1 + find' x ys
split::Char->String->[] String
split x [] = []
split x ys = take n ys : (split x (drop (n+1) ys))
  where
    n = find' x ys
format::[String]->String
format [x] = ""
format (x:xs) = x ++ "\n" ++ format xs
solve::[String]->String
solve [] = ""
solve (x:xs) = show (length x) ++ solve xs
main::IO ()
main = do
  getContents >>=
    putStr.format.(map solve).(map (split ' ')).(split '\n')


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

int main(){

    char s[101];
    int x=0;
    scanf("%s",&s);
    int len=strlen(s);

    for(int i=0;i<len/2;i++){
        if(s[i]!=s[len-1-i]){
            x++;
        }
    }
    printf("%d",x);
   
    return 0;
}


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

#define fi first
#define se second
#define forn(i,n) for(int i=0; i< (int)n; ++i)
#define for1(i,n) for(int i=1; i<= (int)n; ++i)
#define fore(i,l,r) for(int i=(int)l; i<= (int)r; ++i)
#define ford(i,n) for(int i=(int)(n) - 1; i>= 0; --i)
#define fored(i,l,r) for(int i=(int)r; i>= (int)l; --i)
#define pb push_back
#define el '\n'
#define d(x) cout<< #x<< " " << x<<el

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<char,int> pci;
typedef tuple<int, int, int> tiii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;

const ll INF = LONG_LONG_MAX;
const double PI = atan(1)*4;
const int MAXN = 2e5+20;
const double EPS= 1e-10;



struct FenwickTree { // index-1
    vector<ll> ft;
    FenwickTree(int n){
        ft.assign(n + 1, 0);
    } // init n + 1 zeroes

    ll rsq(int b) { // returns RSQ(1, b)
        ll maxi = 0; for (; b; b -= (b&(-b)) ) maxi = max(maxi,ft[b]);
        return maxi;
    }

//    int rsq(int a, int b) { // returns RSQ(a, b)
//        return rsq(b) - (a == 1 ? 0 : rsq(a - 1));
//    }

    // adjusts value of the k-th element by v (v can be +ve/inc or -ve/dec)
    void adjust(int k, ll v) { // note: n = ft.size() - 1
        for (; k < (int)ft.size(); k += (k&(-k))) ft[k] = max(v,ft[k]);
    }
};

int h[MAXN];
ll a[MAXN];

int main(){
//    ios_base::sync_with_stdio(false);
//    cin.tie(NULL); cout.tie(NULL);
//    cout<< setprecision(2)<< fixed;
    int n;
    cin>> n;
    int m=0;
    forn(i,n){
        cin>> h[i];
        m= max(m,h[i]);
    }
    forn(i,n) cin>> a[i];
    FenwickTree f = FenwickTree(m+10);
    forn(i,n){
        ll v= f.rsq(h[i]);
        f.adjust(h[i],a[i]+v);
    }
    cout<< f.rsq(m+9)<<el;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
int main() {
   int K,S;
   cin >> K >> S;
   int cnt=0;
   
   for(int i = 0;i < K+1;i++){
       for(int j = 0;j < K+1;j++){
           if((i+j)<=S && (i+j)>=(S-K)) cnt++;
       }
   }
   
   cout << cnt << endl;
   
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(Type, ...)  Type __VA_ARGS__; input(__VA_ARGS__)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
inline i64  sigma(i64 n)            { return (n * (n + 1) >> 1); }
inline i64  updiv(i64 a, i64 b)     { return (a + b - 1) / b; }
inline i64  sqr(i64 n)              { return n * n; }
inline string to_string(char c)     { return string(1, c); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}
template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

inline void input() {}
template <class Head, class... Tail>
inline void input(Head &head, Tail&... tail) { cin >> head; input(tail...); }

inline void print() { cout << "\n"; }
template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}

template <typename Func>
struct FixPoint : Func {
    inline constexpr FixPoint(Func &&f) noexcept : Func(forward<Func>(f)) {}

    template <typename... Args>
    inline decltype(auto) operator()(Args &&... args) const {
        return Func::operator()(*this, forward<Args>(args)...);
    }
};

template< typename Func >
inline decltype(auto) makeFixPoint(Func &&f) {
    return FixPoint< Func >{forward< Func >(f)};
}
// }}} End Header

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

    var(int, a, b);
    print(max(0, a - (2 * b)));

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#if 1
#define int long long
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define stoi stoll
#else
#define MAX INT_MAX
#define MIN INT_MIN
#endif
#define ALL(obj) (obj).begin(), (obj).end()
#define fi first
#define se second
const int NIL = -1;
const int MOD = 1000000007;
#define REP(i,n) for (int i=0; i < (n); ++i)
#define FOR(i,a,b) for (int i=(a); i < (b); ++i)
using namespace std;

int pow(int x, int n) {int res=1; while(n){if(n&1)res*=x;x*=x;n>>=1;} return res;}
int get_gcd(int a, int b){while(1){if (a < b) swap(a, b); if (b == 0) return a; a %= b;}}
int get_lcm(int a, int b){return a * b / get_gcd(a, b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//-------------------------テンプレここまで-------------------------//

signed main () {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n,k,q;
  cin >> n >> k >> q;

  vector<int> v(n, k-q);
  REP(i,q) {
    int a;
    cin >> a;
    a--;
    v[a]++;
  }
  REP(i,n) {
    if (v[i] > 0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

const ll mod = 1e9 + 7;

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

    ll n;
    cin >> n;
    vll p(n), q(n);
    REP(i, n) cin >> p[i];
    REP(i, n) cin >> q[i];

    vll v(n);
    REP(i, n) v[i] = i + 1;
    ll id = 0, a, b;
    do {
        id++;
        if (p == v) a = id;
        if (q == v) b = id;
    } while(next_permutation(v.begin(), v.end()));
    
    ll res = abs(a - b);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/math/common_factor.hpp>
#include <boost/icl/interval_map.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/pending/disjoint_sets.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>
#include <boost/graph/kruskal_min_spanning_tree.hpp>
#include <boost/graph/graph_utility.hpp>
#include <boost/numeric/ublas/vector.hpp>
#include <boost/multiprecision/cpp_int.hpp>
// ↓これいる？
#include <boost/graph/strong_components.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::math;
using namespace boost::numeric;
using namespace boost::multiprecision;
using ll = long long;
namespace bst = boost;
template<class T> void fill(T& v) { for (auto&& i : v) cin >> i; }

//#include "atcoder.hpp"

int main() {
    int H,W,K;
    
    cin >> H>>W>>K;
  
  vector<string> s(H);
  fill(s);
  
  vector<vector<int>> r(H);
  REP(i,H)
    r[i].resize(W, 0);
  
  int now = 1;
  REP(i,H) {
    REP(j,W) {
      if (s[i][j] == '#') {
        int k = j;
        while (k >= 0 && r[i][k] == 0) {
          r[i][k] = now;
          k--;
        }
        j++;
        while (j < W && r[i][j] == 0 && s[i][j] == '.') {
          r[i][j] = now;
          j++;
        }
        now++;
        j--;
      }
    }
  }
    
  for (int i = 1; i < H;i++)
    if (r[i][0] == 0){
      r[i] = r[i-1];
  }
  for (int i = H-1; i >=0;i--)
    if (r[i][0] == 0){
      r[i] = r[i+1];
  }


  REP(i,H) {
    bool spe = false;
    REP(j,W) {

    cout << (spe ? " " : "") << r[i][j];
      spe = true;
    }
    cout << endl;
  }
    
    return 0;
}







Measured memory_bytes: 1280
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();

		for (int i = 0; i < n - 1; i++) {
			StringBuilder sb = new StringBuilder();
			for (int j = i + 1; j < n; j++) {
				for (int k = 0; k < 10; k++) {
					if ((i >> k & 1) != (j >> k & 1)) {
						sb.append(k + 1).append(' ');
						break;
					}
				}
			}
			sb.deleteCharAt(sb.length() - 1);
			System.out.println(sb.toString());
		}
	}
}


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

typedef long long int ll;
typedef long long unsigned int ull;
typedef long double ld;
typedef vector<int> vr;
typedef pair<int, int> pr;
#define pb push_back
#define ff first
#define ss second
#define INF 1999999999
#define MODA 1000000007
#define PI 3.1415926535897932384626433
#define endl "\n"
//cout << fixed << setprecision(2);


int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int cnt1 = 0, cnt9 = 0, cnt7 = 0, cnt4 = 0;
    for(int i = 1; i <= 4; i++){
    	char a;
    	cin >> a;
    	if(a == '1'){
    		cnt1++;
    	}
    	else if(a == '9'){
    		cnt9++;
    	}
    	else if(a == '7'){
    		cnt7++;
    	}
    	else if(a == '4'){
    		cnt4++;
    	}
    }
    if(cnt1 == 1 && cnt9 == 1 && cnt7 == 1 && cnt4 == 1){
    	cout << "YES" << endl;
    }
    else{
    	cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 3604
import sys
s=int(input())
S=list(map(int,input().split()))
t=int(input())
T=list(map(int,input().split()))
S=list(set(S))
ans=0
for i in range(len(S)):
  for j in range(t):
    if S[i]==T[j]:
      ans+=1
print(ans)


Measured memory_bytes: 6332
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define loop(x) for(int i = 0;i<(x);i++)
signed main(){
	int n,k; cin>>n>>k;vector<int>arr;
	loop(n){
			int a; cin>>a;arr.push_back(a);
		}
	for(int i = k; i<arr.size();i++){
		if(arr[i]>arr[i-k])cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
}

Measured memory_bytes: 5380
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    vector<ll> v(m);
    for(auto& i : v){
        cin >> i;
    }
    if(n >= m){
        cout << 0 << endl;
        return 0;
    }
    sort(all(v));
    ll ans = v.back() - v[0];
    vector<ll> diff(m-1);
    REP(i, m-1){
        diff[i] = v[i+1] - v[i];
    }
    sort(diff.rbegin(), diff.rend());
    ll b = 0;
    REP(i, n-1){
        ans -= diff[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
import bisect
import copy
import fractions
import itertools
import math
import queue
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))


n, m = MI()
student = [LI() for i in range(n)]
checkpoint = [LI() for i in range(m)]
for i in student:
    tmp = INF
    ans = 0
    for index, j in enumerate(checkpoint):
        if abs(i[0] - j[0]) + abs(i[1] - j[1]) < tmp:
            tmp = abs(i[0] - j[0]) + abs(i[1] - j[1])
            ans = index + 1 
    print(ans)


Measured memory_bytes: 67180
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    
    let mut s: Vec<char> = read::<String>().chars().collect();
    let mut pre = s[0];
    let mut ans = 0;

    for i in 1..s.len() {
        if s[i] == pre {
            ans += 1;
            s[i] = match s[i] {
                '0' => '1',
                '1' => '0',
                _ => 'x',
            };
        }
        pre = s[i];
    }

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

Measured memory_bytes: 4352
n = int(input())
l = list(map(int,input().split()))
ans = 0
for i in range(n):
    for j in range(i + 1,n):
        for k in range(j + 1,n):
            if l[i] == l[j] or l[k] == l[j] or l[i] == l[k]:
                continue
            elif l[i] + l[j] > l[k] and l[k] + l[j] > l[i] and l[i] + l[k] > l[j]:
                ans += 1
print(ans)

Measured memory_bytes: 9192
#include <iostream>
#include <vector>
#include <deque>
#include <utility>
#include <algorithm>

int main() {
    int n, a, b;
    long long c;
    std::cin >> n;
    std::vector<std::deque<std::pair<int, long long>>> graph(n);
    for (int i = 0; i < n - 1; i++) {
        std::cin >> a >> b >> c;
        a--; b--;
        graph[a].push_back(std::make_pair(b, c));
        graph[b].push_back(std::make_pair(a, c));
    }

    int qn, k, x, y;
    std::cin >> qn >> k;
    k--;
    std::deque<int> q;
    std::vector<long long> d(n, -1);
    d[k] = 0;
    q.push_back(k);

    while (!q.empty()) {
        auto curr = q.front();
        q.pop_front();
        for (auto el : graph[curr]) {
            if (d[el.first] != -1) continue;
            d[el.first] = d[curr] + el.second;
            q.push_back(el.first);
        }
    }

    for (int i = 0; i < qn; i++) {
        std::cin >> x >> y;
        x--; y--;
        std::cout << d[x] + d[y] << std::endl;
    }

    return 0;
}

Measured memory_bytes: 71296
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;

int INF = 1<<25;
struct Pos{int y, x;}
int[] dx = [1, 0, -1,  0, 0];
int[] dy = [0, 1,  0, -1, 0];
void main() {
    while(true) {
        int H, W;
        readf("%d %d\n", &H, &W);
        if (H==0 && W==0) break;

        Pos player;
        Pos ghost;
        bool[][] grid = H.iota.map!(i => readln.chomp.enumerate.tee!((a) {
            if (a.value=='A') player = Pos(i.to!int, a.index.to!int);
            if (a.value=='B') ghost = Pos(i.to!int, a.index.to!int);
        }).map!(a => (a.value!='#')).array).array;

        int[][] dist = new int[][](H, W);
        foreach(ref e; dist) e[] = INF;
        auto list = DList!Pos(player);
        dist[player.y][player.x] = 0;
        while (!list.empty) {
            Pos p = list.front;
            list.removeFront;
            foreach(int i; 0..4) {
                int _y = p.y+dy[i];
                int _x = p.x+dx[i];
                if (0<=_y && _y<H && 0<=_x && _x<W) {
                    if (grid[_y][_x] && dist[_y][_x]==INF) {
                        list.insert(Pos(_y, _x));
                        dist[_y][_x] = dist[p.y][p.x]+1;
                    }
                }
            }
        }

        int[] pattern = readln.chomp.map!(c => c=='6'?0:c=='2'?1:c=='4'?2:c=='8'?3:4).array;
        bool flag = false;
        int[] ans;
        int time = 0;
        for(int _=0; _<1000; _++) {
            foreach(i; pattern) {
                if (dist[ghost.y][ghost.x] <= time) {
                    ans = [time, ghost.y, ghost.x];
                    flag = true;
                    break;
                }
                ghost = Pos(min(H-1, max(0, ghost.y+dy[i])), min(W-1, max(0, ghost.x+dx[i])));
                time++;
            }
        }
        writeln(flag ? ans.to!(string[]).join(" "):"impossible");
    }
}

Measured memory_bytes: 3260
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)
#define F first
#define S second
#define ll long long;

const int INF = 1e9;

using namespace std;

long long H,W,ans = 10000000010;

int main() {
  cin>>H>>W;
  //縦に３つ
  if(3 <= H){
    ans = min(ans, (H+3-1)/3*W - H/3*W);
  }
  //横に３つ
  if(3 <= W){
    ans = min(ans, (W+3-1)/3*H - W/3*H);
  }
  //2+1パタン
  REP(i,1,W){
    vector<long long> v;
    v.push_back(i*H);
    v.push_back((H+2-1)/2*(W-i));
    v.push_back(H/2*(W-i));
    sort(v.begin(),v.end());
    ans = min(ans, v[2]-v[0]);
  }
  REP(i,1,H){
    vector<long long> v;
    v.push_back(i*W);
    v.push_back((W+2-1)/2*(H-i));
    v.push_back(W/2*(H-i));
    sort(v.begin(),v.end());
    ans = min(ans, v[2]-v[0]);
  }

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


Measured memory_bytes: 384
n, l = map(int, input().split())
s = []
for i in range(n):
    S = input()
    s.append(S)


import string
ALPHABETS = string.ascii_uppercase

def chars_to_int(chars):

    chars = chars.upper()
    size = len(chars)

    result = 0
    for pos, c in enumerate(chars):
        i = ALPHABETS.index(c) + 1
        exp = size - pos - 1
        result += i * 26 ** exp

    return result

a = []
for i in range(n):
    b = chars_to_int(s[i])
    a.append([b, s[i]])

a.sort(key=lambda x: x[0])

ans = ""
for i in range(n):
    ans += a[i][1]

print(ans)

Measured memory_bytes: 3892
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    bool first = true;

    for(;;){
        int p, s;
        cin >> p >> s;
        if(p == 0)
            return 0;
        ++ p;
        ++ s;

        vector<vector<int> > num(p, vector<int>(s, 0));
        vector<vector<bool> > missing(p, vector<bool>(s, false));
        vector<int> missingNum(p+s, 0);
        for(int i=0; i<p; ++i){
            for(int j=0; j<s; ++j){
                if(!(cin >> num[i][j])){
                    cin.clear();
                    cin.ignore();
                    missing[i][j] = true;
                    ++ missingNum[i];
                    ++ missingNum[p+j];
                }
                if((i == p-1) ^ (j == s-1))
                    num[i][j] *= -1;
            }
        }

        vector<vector<bool> > check = missing;
        queue<int> q;
        for(int i=0; i<p+s; ++i){
            if(missingNum[i] == 1)
                q.push(i);
        }
        while(!q.empty()){
            int y = q.front();
            int x = -1;
            q.pop();

            int tmp = 0;
            if(y < p){
                for(int i=0; i<s; ++i){
                    tmp -= num[y][i];
                    if(check[y][i])
                        x = i;
                }
            }else{
                x = y - p;
                y = -1;
                for(int i=0; i<p; ++i){
                    tmp -= num[i][x];
                    if(check[i][x])
                        y = i;
                }
            }
            if(y == -1 || x == -1)
                continue;

            num[y][x] = tmp;
            check[y][x] = false;
            -- missingNum[y];
            -- missingNum[p+x];
            if(missingNum[y] == 1)
                q.push(y);
            if(missingNum[p+x] == 1)
                q.push(p+x);
        }

        if(first)
            first = false;
        else
            cout << endl;

        if(*max_element(missingNum.begin(), missingNum.end()) > 0){
            cout << "NO" << endl;
        }else{
            for(int i=0; i<p; ++i){
                for(int j=0; j<s; ++j){
                    if(missing[i][j])
                        cout << num[i][j] << endl;
                }
            }
        }
    }
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll,ll> pll;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define MOD 1000000007
#define ARRAY_MAX 100005

const int INF = 1e9+7;


int main(){

    int t,b;
    b = -2;
    cin >> t;
    if(t == 0){
        cout << "0" << endl;
        return 0;
    }
    string s;
    while(t != 0){
        int mod = t%b;
        t /= b;
        if(mod < 0){
            t++;
            mod -= b;
        }
        s.push_back('0'+mod);
    }
    reverse(s.begin(),s.end());
    cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    char c[100];
    for(int i=0; i<s.size(); i++){
        c[i] = s[i];
    }
    sort(c, c+s.size());
    bool isok = true;
    for(int i=0; i<s.size()-1; i++){
        if(c[i]==c[i+1]){
            isok = false;
            break;
        }
    }
    if(isok){
        cout << "yes" << endl;
    }else{
        cout << "no" << endl;
    }
    return 0;
}

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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

int N, K;
bool enable[110];

signed main() {
    cin >> N >> K;
    //辺は最低N-1本
    if (N * (N - 1) / 2 - (N - 1) < K) {
        cout << -1 << endl;
        return 0;
    }
    int M = N * (N - 1) / 2;
    vector<pii> E;
    for (int i = 1; i <= N; ++i) {
        for (int j = i + 1; j <= N; ++j) {
            E.push_back(pii(i, j));
        }
    }
    int k = 0;
    cout << M - K << endl;
    for (pii e:E) {
        if (e.first == 1) {
            cout << e.first << " " << e.second << endl;
        } else if (k == K) {
            cout << e.first << " " << e.second << endl;
        } else {
            k++;
        }
    }
    return 0;
}


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

int main() {
  string s;
  cin >> s;
  int place = 700;
  for(int i=0;i<s.size();i++){
    if(s[i]=='o') place+= 100;
  }
  cout << place << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
input=sys.stdin.readline
#import fractions
#import math
#import collections
#from collections import deque
#from bisect import bisect_left
#N = int(input())
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = list(map(int,input().split()))
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
N,M = map(int,input().split())
KS = [list(map(int,input().split())) for _ in range(M)]
P = list(map(int,input().split()))
c = 0
from collections import deque
for i in range(2**N):
    bitlist = deque()
    for j in range(N):
        if ((i >> j) & 1): #2進数表示のj桁目(0桁目から数える)が1かどうか
            bitlist.appendleft(1)
        else:
          	bitlist.appendleft(0)
    bitlist = list(bitlist)
    e = 0
    for ii in range(M):
        d = 0
        k = KS[ii][0]
        s = KS[ii][1:]
        for l in s:
            d += bitlist[l-1]#onの数
        d = d%2
        if d != P[ii]:
            e = 1
            break
    if e == 0:
        c += 1
print(c)

Measured memory_bytes: 3316
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int K = sc.nextInt();
		 List<Integer> list = new ArrayList<>();
		for(int i =0; i < K; i++) {
			int d = sc.nextInt();
			for(int num = 0; num < d; num++ ) {
				int kos = sc.nextInt();
				if(!list.contains(kos)) {
					 list.add(kos);
				}

			}
		}
			System.out.println(N-list.size());
		}
}


Measured memory_bytes: 46108
N = int(input())
s, t = [0]*N, [0]*N
for i in range(N):
  s[i], t[i] = input().split()
X = input()

ans = 0
flag = False
for i in range(N):
  if flag:
    ans += int(t[i])
  if s[i] == X:
    flag = True

print(ans)

Measured memory_bytes: 9016
n = int(input())
list = list(map(int,input().split()))
di = {}
for i in range(n):
	k = list[i]
	if k not in di:
		di[k]=1
	else:
		di[k]+=1
"""
list_del=[]
for key in di.keys():
	if di[key]==1:
		list_del.append(key)
for i in range(len(list_del)):
	di.pop(list_del[i])
"""
	
su=0
for valu in di.values():
	su += valu*(valu-1)/2
	
for i in range(n):
	k = list[i]
	l = di[k]
	su_ch = su
	su_ch -= l*(l-1)/2
	su_ch += (l-1)*(l-2)/2
	print(int(su_ch))
	

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

bool equal(string s1, string s2) {
	if (s1.length() != s2.length())return false;
	for (int i = 0; i < s1.length(); i++) {
		if (s1[i] != s2[i])return false;
	}
	return true;
}

bool In(vector<string>s, string w) {
	for (int i = 0; i < s.size(); i++) {
		if (equal(s[i], w))return true;
	}
	return false;
}

int main() {
	int n; cin >> n;
	bool ok = true;
	vector<string>a;
	string w; cin >> w;
	char c = w.back();
	a.emplace_back(w);
	for (int i = 0; i < n - 1; i++) {
		cin >> w;
		if (c != w.front() || In(a, w)) {
			ok = false;
			break;
		}
		a.emplace_back(w);
		c = w.back();
	}
	if (ok) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
import numpy as np
n, k = map(int,input().split())
a = np.array(input().split(),dtype=int)
n1 = [0 for i in range(40)]
g0 = [0 for i in range(40)]
g1 = [0 for i in range(40)]
ss = [0 for i in range(40)]
t2 = [1 for i in range(40)]

for i in range(40):
    n1[i] = np.count_nonzero(a&1)
    a >>= 1
    if i > 0:
        t2[i] = t2[i-1]*2
    g0[i] = n1[i]*t2[i]
    g1[i] = (n-n1[i])*t2[i]
    if n1[i] < n-n1[i]:
        ss[i] = ss[i-1]+g1[i]
    else:
        ss[i] = ss[i-1]+g0[i]

def DFS(ni,ki,sm):
    if ni == 0:
        if ki == 0:
            return sm+g0[0]
        else:
            return sm+ss[0]
    else:
        if ki//t2[ni] == 0:
            return DFS(ni-1,ki,sm+g0[ni])
        elif ki//t2[ni] > 1:
            return sm+ss[ni]
        else:
            return max(sm+g0[ni]+ss[ni-1],DFS(ni-1,ki-t2[ni],sm+g1[ni]))

ma = DFS(39,k,0)
print(ma)


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

int main(){
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++){
		for(int j=i+1;j<s.size();j++){
			if(s[i]==s[j]){
				cout<<"no"<<endl;
				return 0;
			}
		}
	}
	cout<<"yes"<<endl;
	return 0;
}

Measured memory_bytes: 256