akhauriyash/Code-Regression huggingface dataset:
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)
# pragma warning(disable:4996)


struct BIT {
	vector<LL> bit;
	BIT(int n) {
		bit.resize(n+10);
		for (int i = 0; i < n; i++)bit[i] = 0;
	}
	int sum(int i) {
		LL s = 0;
		while (i>0) {
			s += bit[i];
			i -= i& -i;
		}
		return s;
	}
	void add(int i, LL x) {
		while (i <= bit.size()-1) {
			bit[i] += x;
			i += i& -i;
		}
	}
};

int main() {
	int n, q;
	cin >> n >> q;
	BIT bit(101010);
	int k, s, t, x, i;
	REP(qqq, q) {
		cin >> k;
		if (k == 0) {
			cin >> s >> t >> x;
			bit.add(s, x);
			bit.add(t + 1, -x);
		}
		else {
			cin >> i;
			cout << bit.sum(i) << endl;
		}
	}
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<int ,P> P3;
typedef pair<P ,P> PP;
const ll MOD = ll(1e9+7);
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int n;

int main() {
    cin >> n;
    if(n%2==0){
        cout << n*(n-2)/2 << endl;
        for(int i = 1; i <= n; i++){
            for(int j = i+1; j <= n; j++){
                if(i+j==n+1)continue;
                cout << i << " " << j << endl;
            }
        }
    }
    else{
        cout << n*(n-2)/2+1 << endl;
        for(int i = 1; i <= n; i++){
            for(int j = i+1; j <= n; j++){
                if(i+j==n)continue;
                cout << i << " " << j << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 998244353
#define endl "\n"
#define F first
#define S second
#define pb push_back
#define loop(n) for(int i=0; i<n; i++)
void solve()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int i=0;
	bool ok=true;
	while(ok)
	{
	     if(i%2==0)
	     {
	          c=c-b;
	          if(c<=0){ok=false;break;}
	          i++;
	          
	     }
	     else 
	     {
	          a=a-d;
	          if(a<=0){ok=false;break;}
	          i++;
	     }
	}
	if(i%2==0)cout<<"Yes\n";
	else cout<<"No\n";
	return;
}




int32_t main() 
{ 
	fast;
	int t=1;//cin>>t;
	while(t--){solve();}
	return 0; 
}

Measured memory_bytes: 3652
input = raw_input
n, k = map(int, input().split(" "))

a_list = [int(a)-1 for a in  input().split(" ")]
uses = [-1] * n
path = [-1] * n
path[0] = 0
uses[0] = 0

count = 0
cur = 0
end = False
for i in range(n):
    count += 1
    cur = a_list[cur]
    if k == count:
        end = True
        break

    if uses[cur] != -1:
        break
    uses[cur] = count
    path[count] = cur

if end:
    out = cur+1
else:
    shuuki = count - uses[cur]

    shift = uses[cur]
    k1 = (k - shift) % shuuki + shift
    out = path[k1] + 1

print(out)

Measured memory_bytes: 91892
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define MAXINF 1000000005
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define repc(it, x) for(auto it = (x).begin(); it != (x).end(); ++it)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rrepc(it, x) for(auto it = (x).rbegin(); it != (x).rend(); ++it)
#define all(x) (x).begin(), (x).end()
#define P pair<int, int>

const int MX = 2005;
bool d[3][3][MX];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<string> s(3);
    rep(i, 3) cin >> s[i];
    int ans = MX*3;
    sort(all(s));
    do {
        rep(i,3)rep(j,3)rep(k,s[i].size()) {
            if(i > j) continue;
            bool isOk = true;
            for(int ni = k; ni < s[i].size(); ni++) {
                int nj = ni-k;
                if(nj >= s[j].size()) break;
                if(s[i][ni]=='?' || s[j][nj]=='?') continue;
                if(s[i][ni]!=s[j][nj]) isOk = false;
            }
            d[i][j][k] = isOk;
        }
        auto f = [&](int i, int j, int k) {
            if(k >= s[i].size()) return true;
            return d[i][j][k];
        };
        rep(x, MX) rep(y, MX) {
            if(!f(0,1,x)) continue;
            if(!f(1,2,y)) continue;
            if(!f(0,2,x+y)) continue;
            int now = 0;
            now = max<int>(now, s[0].size());
            now = max<int>(now, x+s[1].size());
            now = max<int>(now, x+y+s[2].size());
            ans = min(ans, now);
        }
    } while (next_permutation(s.begin(), s.end()));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int h, w; cin >> h >> w;
	vector<string> a(h);
	rep(i, 0, h - 1)cin >> a[i];
	queue<pair<int, int>> q;
	vector<vector<int>> step(h, vector<int>(w, 10010010));
	rep(i, 0, h - 1)rep(j, 0, w - 1)
	{
		if (a[i][j] == '#')
		{
			q.push({ i,j });
			step[i][j] = 0;
		}
	}
	int d[4] = { 1,0,-1,0 };
	while (!q.empty())
	{
		int x = q.front().first;
		int y = q.front().second;
		q.pop();
		rep(i, 0, 3)
		{
			int nx = x + d[i];
			int ny = y + d[i ^ 1];
			if (0 <= nx && nx < h && 0 <= ny && ny < w&&step[nx][ny] == 10010010)
			{
				step[nx][ny] = step[x][y] + 1;
				q.push({ nx,ny });
			}
		}
	}
	int ans = 0;
	rep(i, 0, h - 1)rep(j, 0, w - 1)
	{
		ans = max(ans, step[i][j]);
	}
	cout << ans << endl;
}


Measured memory_bytes: 13456
using System;

public class Hello
{
    public static void Main()
    {
        var N = int.Parse(Console.ReadLine().Trim());

        var yomi = new [] {"hon", "pon", "bon"};
        var table = new []{ 1, 1, 0, 2, 0, 0, 1, 0, 1, 0 };

        var ans  = yomi[table[N % 10]];
        Console.WriteLine(ans);
   }
}

Measured memory_bytes: 27556
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

int main()
{
	int a, b;
	scanf("%d%d", &a, &b);
	
	if ((1 <= a) && (a <= 9) && (1 <= b) && (b <= 9))
	{
		int ans = a * b;
		printf("%d\n", ans);
	}
	else
	{
		printf("-1\n");
	}
	
		
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
using namespace std;
int main() {
	string s, t;
	cin >> s >> t;
	int a, b;
	cin >> a >> b;
	string u;
	cin >> u;
	if (s == u) {
		cout << a - 1 << " " <<  b << endl;
	}
	else {
		cout << a << " " << b - 1 << endl;
	}
	return 0;
}

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

int main() {
    int K;
    string S;
    cin >> K >> S;
    int l = S.size();
    if (l <= K) {
        cout << S << endl;
    } else {
        string res = "";
        for (int i = 0; i < K; i++) {
            res += S.at(i);
        }
        cout << res << "..." << endl;
    }
    return 0;
}

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

string s, t; // 3000 max
int m, n;

int memo[3001][3001];

int dp (int i, int j) {
	if (i < 0 or j < 0)
		return 0;
	if (memo[i][j] != -1)
		return memo[i][j];
	if (s[i] == t[j]) {
		memo[i][j] = 1 + dp(i - 1, j - 1);
	}
	else {
		int t1 = dp(i - 1, j);
		int t2 = dp(i, j - 1);
		memo[i][j] = max(t1, t2);
	}
	return memo[i][j];
}

int main () {
	cin >> s >> t;
	m = s.length();
	n = t.length();
	for (int i = 0; i < m; i++)
		for (int j = 0; j < n; j++)
			memo[i][j] = -1;
	dp(m - 1, n - 1);
	int si = m - 1, ti = n - 1;
	vector <char> stck;
	while (si >= 0 and ti >= 0) {
		if (s[si] == t[ti]) {
			stck.push_back(s[si]);
			si--, ti--;
		}
		else {
			if (dp(si - 1, ti) > dp(si, ti - 1))
				si--;
			else
				ti--;
		}
	}
	reverse(stck.begin(), stck.end());
	for (char c : stck)
		cout << c;
	cout << "\n";
	return 0;
}

Measured memory_bytes: 35712
from itertools import accumulate
from math import ceil

class BIT():
    def __init__(self,n):
        self.size=n
        self.bit=[0]*(n+1)
    def add(self,i,x):
        while i<=self.size:
            self.bit[i]+=x
            i+=i&-i
    def sum(self,i):
        s=0
        while i>0:
            s+=self.bit[i]
            i-=i&-i
        return s
    def reset(self):
        self.bit=[0]*(self.size+1)

n=int(input())
A=list(map(int,input().split()))
bit=BIT(n+1)
l,r=0,10**9+1
while r-l>1:
    mid=(l+r)//2
    B=[(1 if a>=mid else -1) for a in A]
    B=[0]+list(accumulate(B))
    cnt=0
    B_sorted={b: i for i,b in enumerate(sorted(B),start=1)}
    bit.reset()
    for b in B:
        cnt+=bit.sum(B_sorted[b])
        bit.add(B_sorted[b],1)
    if cnt>=ceil((n*(n+1)//2)/2):
        l=mid
    else:
        r=mid
print(l)

Measured memory_bytes: 144264
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>	
#include <cmath>
#include <string>
#include<math.h>
#include<sstream>//���炵���̂Œ���
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define Cout(s) cout<<s<<endl
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
string Yes(bool b) { if (b) { return "Yes"; } else { return "No"; } }
string YES(bool b) { if (b) { return "YES"; } else { return "NO"; } }
//================================================
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

ll a = 1, b = 0, c, d, n, k = 0, ans = 0;
string s, t;
int mod = 1000000007;


int main()
{
	int n; cin >> n; vector<ll> a(n);cin>> a[0];
	rep(i, n - 1) { cin >> b; a[i + 1] = a[i] + b; }
	ll sum = a[n - 1]; ll  flag = 2000000000000;
	for(int i=0;i<n;i++) {
		if (flag > abs(sum - 2 * a[i]))
			flag = abs(sum - 2 * a[i]);
	}
	cout << flag << endl;

	return 0;
}


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

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
template <typename T> constexpr T inf = numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity() : numeric_limits<T>::max() / 4;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (int i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (int i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define COMP(key) [](const auto& a, const auto& b) { return a.key < b.key; }

template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& a) { return is >> a.first >> a.second; }
template<typename T> istream& operator>>(istream& is, vector<T>& a) { for (T& x : a) is >> x; return is; }

void LOG(const int& x) { cerr << x << "\n"; }
template<typename T> void LOG(const vector<T>& a) { for (const T& x : a) cerr << x << " "; cerr << "\n"; }
template<typename T, std::size_t S> void LOG(const T (&a)[S]) { REP(i, S) cerr << a[i] << " "; cerr << "\n"; }
template<typename T, std::size_t S, std::size_t R> void LOG(const T (&a)[S][R]) { REP(i, S) { REP(j, R) cerr << a[i][j] << " "; cerr << "\n"; } }

i64 ceil(i64 a, i64 b) { return (a - 1) / b + 1; }
i64 gcd(i64 a, i64 b) { while (b != 0) { i64 t = b; b = a % b; a = t; } return a; }
i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
i64 gcd(const vector<i64>& v) { return accumulate(ALL(v), 1LL, static_cast<i64(*)(i64, i64)>(gcd)); }
i64 lcm(const vector<i64>& v) { return v.empty() ? 0LL : accumulate(v.begin() + 1, v.end(), v[0], static_cast<i64(*)(i64, i64)>(lcm)); }
i64 pow(i64 x, i64 y, i64 z) { i64 a = 1; while (y > 0) { if (y & 1) a = a * x % z; x = x * x % z; y /= 2; } return a; }
i64 inv(i64 x, i64 m) { return pow(x, m - 2, m); }

struct InitCpp { InitCpp() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } initCpp;

const i64 M = 1000000007;
signed main() {
  i64 N;
  cin >> N;
  string S;
  cin >> S;
  i64 ans = 0;
  for (i64 d = 1; d <= N - 1; ++d) {
    i64 c = 0;
    i64 m = 0;
    for (i64 i = 0; i + d < N; ++i) {
      if (S[i] == S[i + d]) {
        c += 1;
        if (c > m) m = c;
      } else {
        c = 0;
      }
    }
    ans = max(ans, min(m, d));
  }
  cout << ans << endl;
}


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    string s;
    cin >> s;
    sort(all(s));
    if(s=="abc") cout <<"Yes"<<endl;
    else cout << "No"<<endl;
 
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>

using namespace std;

int main(void) {
	
	int n,m,i,j;
	cin >>n >>m;
	
	long long int a[n],b[n];
	vector<pair< long long int , long long int> > aa(n);
	for (i=0 ; i<n ; i++) {
		cin >>a[i] >>b[i];
		aa[i]=make_pair(a[i],b[i]);
	}
	
	sort(aa.begin(),aa.end());
	
	long long int ans=0;
	i=0;
	while (m>0) {
		if (m>=aa[i].second) {
			ans+=aa[i].first*aa[i].second;
			m-=aa[i].second;
		} else {
			ans+=aa[i].first*m;
			break;
		}
		i++;
	}
	
	cout <<ans <<endl;
	
	return 0;
}

Measured memory_bytes: 3328
n,a,b = map(int,input().split())
x = input()
c = 0
bc = 0
for i in range(n):
    if x[i] == 'a':
        if c < a + b:
            print('Yes')
            c = c + 1
        else:
            print("No")
    if x[i] == 'b':
        bc = bc + 1
        if c < a + b:
            if bc <= b:
                print('Yes')
                c  = c + 1
            else:
                print("No")
        else:
            print("No")
    if x[i] == 'c':
        print('No')

Measured memory_bytes: 4016
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>
#include <set>
#include <cstdlib>
#include <queue>
#include <map>

using namespace std;

typedef long long llint;
typedef long double ld;
#define inf 1e18
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint>> que;
//priority_queue<llint> q;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

llint n;

void solve(){
  cin >> n;
  vector<llint> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  llint m1=0,m2=0;
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  llint tmp=0;
  for(int i=0;i<n;i++){
    if(a[i]==tmp){
      if(m1!=0){
        m2=a[i];
        break;
      }
      else{
        m1=a[i];
        tmp=0;
        continue;
      }
    }
    tmp=a[i];
  }
  cout << m2*m1 << endl;
}

int main() {
  solve();
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main(){
    int i,n,ans=0,m,k,sum,rem,c;
    cin>>n>>m>>k;
    int a[n+1],b[m+1];
    for(i=1;i<=n;i++)cin>>a[i];
    for(i=1;i<=m;i++)cin>>b[i];
    vector<int>v1,v2;
    sum=0;
  v1.push_back(sum);
  v2.push_back(sum);
  for(i=1;i<=n;i++){
      sum+=a[i];
      v1.push_back(sum);
  }sum=0;
  for(i=1;i<=m;i++){
      sum+=b[i];
      v2.push_back(sum);
  }
  for(i=0;i<=n;i++){
      if(v1[i]>k)break;
      rem=k-v1[i];
      auto it=upper_bound(v2.begin(),v2.end(),rem);
      c=(int)(it-v2.begin());
      c--;
      ans=max(ans,c+i);
  }
  cout<<ans;
    return 0;
}

Measured memory_bytes: 11060
#include <iostream>

using namespace std;

int main()
{
    int n, count=0, tens[4] = {1, 100, 10000};
    cin >> n;
    for(int i=0;i<3;i++){
        if(n / tens[i] > 0){
            // そこまでのを足す
            if(n / tens[i] < 10) count += n - tens[i] + 1;
            // 99...9を足す
            else count+= (tens[i]*10) - tens[i];
        }
        else break;
    }
    cout << count << endl;
}

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

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

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts> auto make_v(size_t a,Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }

template<typename T> void fill_all(T& arr, const T& v) { arr = v; }
template<typename T, typename U> void fill_all(T& arr, const U& v) { for (auto& i : arr) fill_all(i, v); }

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}
#define DUMP(x) cout<<#x<<" = "<<(x)<<endl

struct edge { int to, cost; };

const LL LINF = 1LL<<60;
const int IINF = 1<<30;
const LL MOD = 1e9+7;

int n;
vector<int> a;

bool check(int k) {
   // whether you can reach goal with k-faced dice
   vector<bool> dp(n+1, false);
   dp[0] = true;
   for (int i = 0; i <= n; ++i) if (dp[i]) {
      for (int j = 1; j <= k; ++j) {
         if (i+j > n) return true;

         if (a[i+j-1] == 0) dp[i+j] = true;
      }
   }
   return false;
}

int binary_search(int MIN, int MAX)
{
   int l = MIN-1, r = MAX;
   while (r - l > 1) {
      int m = (l + r) / 2;
      if (check(m)) {
         r = m;
      } else {
         l = m;
      }
   }
   return r;
}

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

   cout << binary_search(1, n+1) << endl;

   return 0;
}



Measured memory_bytes: 3120
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        ab: i64,
        bc: i64,
        ca: i64,
    }

    let ans = ab * bc / 2;

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


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define turbo cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define inf 99999999

using namespace std;

const int gr = 100005;

vector <int> graph[gr];
int moc[gr];
int dp[gr];

queue <int> Q;

int main(){
    turbo
    int n,m,x,y;
    cin >> n >> m;
    for(int i=0;i<m;i++){
      cin >> x >> y;
      graph[x].pb(y);
      moc[y]++;
    }
    for(int i=1;i<=n;i++){
      dp[i]=inf;
      if(moc[i]==0){
        dp[i]=0;
        Q.push(i);
      }
    }
    while(!Q.empty()){
      int u = Q.front();
      Q.pop();
      for(int i=0;i<graph[u].size();i++){
        int v = graph[u][i];
        if(dp[v]==inf)
          dp[v] = dp[u]+1;
        dp[v]=max(dp[v],dp[u]+1);
        moc[v]--;
        if(moc[v]==0){
          Q.push(v);
        }
      }
    }
    int maxi = 0;
    for(int i=1;i<=n;i++){
      maxi = max(maxi,dp[i]);
    }
    cout << maxi << "\n";

    return 0;
}


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

int32_t main() {
    string s; cin >> s;
    if (s.size() == 6 && s[2] == s[3] && s[4] == s[5]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

int main() {
	int N; cin >> N;
	vi p(N), same(N);
	vi dif;

	rep(i, N) {
		cin >> p[i];
		--p[i];
		if (p[i] != i) {
			dif.pb(i);
		}
	}

	for (int i = 0; i < (int)dif.size(); ) {
		int j = i;
		while (j+1 < dif.size() && dif[j+1] == dif[j] + 2) {
			++j;
		}
		vi vl, vr;
		for (int k = i; k <= j; ++k) {
			int pos = dif[k];
			if (p[pos] < dif[i] || p[pos] > dif[j]) {
				puts("No");
				return 0;
			}
			if (p[pos] > pos) {
				vl.pb(p[pos]);
			} else if (p[pos] < pos) {
				vr.pb(p[pos]);
			}
		}
		bool ok = true;
		rep(t, (int)vl.size()-1) {
			if (vl[t] > vl[t+1]) {
				ok = false;
			}
		}
		rep(t, (int)vr.size()-1) {
			if (vr[t] > vr[t+1]) {
				ok = false;
			}
		}
		if (!ok) {
			puts("No");
			return 0;
		}		
		i = j + 1;
	}


	puts("Yes");
	return 0;
}

Measured memory_bytes: 4724
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define debug(x) cout<<#x<<": "<<x<<" "
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
using namespace std;
const int N=200010;
int a[N];
int main()
{
    IO;
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=k+1;i<=n;i++)
    {
        if(a[i]>a[i-k]) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    
    return 0;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i=0; i<n; ++i) cin >> a.at(i);

    auto check = [n, &a]() -> int {
        ll maxi = -1;
        int ind = -1;
        for (int i=0; i<n; ++i) if (chmax(maxi, a.at(i))) ind = i;
        return ind;
    };

    ll res = 0;
    while (true) {
        int ind = check();
        if (a.at(ind) < n) break;
        ll tmp = a.at(ind) / n;
        res += tmp;
        for (int i=0; i<n; ++i) {
            if (i == ind) a.at(i) = a.at(i) % n;
            else a.at(i) += tmp;
        }
    }
    cout << res << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


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

using namespace std;

int main()
{
  int n;
  while(cin >> n, n) {
    int a[1001];
    int dif = 1<<25;
    for(int i = 0; i < n; i++) {
      cin >> a[i];
      for(int j = 0; j < i; j++) dif = min(dif, abs(a[i] - a[j]));
    }
    cout << dif << endl;
  }
  return 0;
}

Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define fi first
#define se second
#define pii pair<int, int>

signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a + 3);
    cout << a[0] + a[1] << "\n";

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

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

	vi r(3);
	rep(i,3){cin >> r.at(i);}
	if(r.at(0)==r.at(1) && r.at(0)!=r.at(2)){Yes}
  if(r.at(1)==r.at(2) && r.at(0)!=r.at(1)){Yes}
  if(r.at(0)==r.at(2) && r.at(0)!=r.at(1)){Yes}
	No
}

Measured memory_bytes: 256
n = int(input())
a = [int(input()) for i in range(n)]
a.sort()
ress = []
for i in range(2):
    if i == 0:
        res = 0
        b = a[n//2:]
        c = a[:n//2]
        res += 2*sum(b)
        res -= 2*sum(c)
        res -= b[0]
        if n%2 == 1:
            res -= b[1]
        else:
            res += c[-1]
        ress.append(res)
    if i==1 and n%2==1:
        res = 0
        b = a[n//2+1:]
        c = a[:n//2+1]
        res += 2*sum(b)
        res -= 2*sum(c)
        res += c[-1]+c[-2]
        ress.append(res)
print(max(ress))

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

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

  ld a,b;
  cin >> a >> b;

  ld one = ceil(a / 0.08);
  ld two = ceil(b / 0.1);
  ld cand = max(one,two);

  if(floor(cand * 0.08) == a && floor(cand * 0.1) == b) {
    cout << cand << endl;
  } else {
    cout << -1 << endl;
  }
}


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

#define ll long long
#define ld long long
#define M 1000000007
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

int main() {
    fast;
	string s;
    cin >> s;
    ll ans = 0;
    for (ll i = 0; i < s.size(); i++) {
        ll c = 0;
        ll j = i;
        while (j < s.size() && (s[j] == 'A' || s[j] == 'C' || s[j] == 'T' || s[j] == 'G')) {
            c++;
            j++;
        }
        ans = max(ans, c);
        i = j;
    }
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
     
    int main()
    {
      long int n, m, sum = 0;
      cin>>n>>m;
      long int arr[m];
      for(int i = 0; i < m; i++)
      {
        cin>>arr[i];
      	sum += arr[i];
      }
      if(sum <= n)
      {
        cout<<n-sum<<"\n";
      }
      else
      {
         cout<<"-1"<<"\n";
      }
      return 0;
    }

Measured memory_bytes: 3648
import math
N, K = map(int, input().split())
S = list(input())
ans = [0]*(N-1)

for i in range(N-1):
    if S[i] != S[i+1]:
        ans[i] = 1
total = sum(ans)
if K >= math.ceil(total/2):
    print(N-1)
else:
    print(N-1-(total-2*K))

Measured memory_bytes: 4664
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#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;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const ll INFLL = 100100100100100100;
const int MOD = (int)1e9 + 7;
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;
 
int main () {
    
    int n; cin >>n;
    vector<int> a(n); REP(i,n) cin >> a[i];

    bool flag = true;
    int ans = 0;
    while (flag) {
        flag = true;
        for (int in = 0; in < n; in++) {
            if (a[in] % 2 != 0) {
                flag = false;
            } else {
                a[in] /= 2;
            } 
        }
        if (flag) {
            ans++;
        } 
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
/*************************************************************************
  >         File: D.cc
  >       Author: lyyllyyl
  >         Mail: riho.yoshioka@yandex.com
  > Created Time: Sun 04 Sep 2016 08:35:41 PM CST
*************************************************************************/
#include <bits/stdc++.h>

const int N = 1e5 + 5;
int next[N];
int n, k;
std::vector<int> edges[N];

int Dfs(int x, int &answer) {
  int mx = -1;
  for (auto &y: edges[x]) if (y != 1) {
    int dep = Dfs(y, answer);
    if (dep == k - 1 && x != 1) answer++;
    else mx = std::max(mx, dep);
  }
  return mx + 1;
}

int main() {
  std::ios::sync_with_stdio(0);
  std::cin >> n >> k;
  for (int i = 1; i <= n; i++) std::cin >> next[i], edges[next[i]].push_back(i);
  int answer = 0;
  if (next[1] != 1) {
    answer++;
    edges[next[1]].erase(std::find(edges[next[1]].begin(), edges[next[1]].end(), 1));
    next[1] = 1;
  }
  Dfs(1, answer);
  std::cout << answer << std::endl;
  return 0;
}


Measured memory_bytes: 10752
// abc147_a
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(int argc, char *argv[])
{
  int a1,a2,a3;
  cin>>a1>>a2>>a3;
  if(a1+a2+a3>21) {
    cout<<"bust"<<endl;
  } else {
    cout<<"win"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
/*
AizuOnline A0206
Title Next Trip
*/
#include <stdio.h>
// Select Below
//#include <stdlib.h>
//#include <string.h>
//#include <float.h>
//#include <math.h>
//#include <limits.h>
//Global data section
int L,M,N;
//
main()
{
  int i,month;

  while(EOF != scanf("%d",&L) && L)
    {
      month=0;

      for(i=1;i<=12;i++)
	{
	  scanf("%d %d",&M,&N);

	  L -= (M-N);
	  //printf("S:%d\n",L);
	  if(month==0 && L <=0)
	    month = i;
	}
      if(month>0)
	printf("%d\n",month);
      else
	printf("NA\n");
    }

return(0);
}

Measured memory_bytes: 612
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    REP(i, 5) {
        int a; cin >> a;
        if (a == 0) {
            print(i + 1);
            return 0;
        }
    }
    
}


Measured memory_bytes: 3580
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;

void max_self(ll& a, ll b) {
    a = max(a, b);
}
void min_self(ll& a, ll b) {
    a = min(a, b);
}

const ll INF = 1e18L + 5;

int main() {
    int n, W;
    scanf("%d%d", &n, &W);
    vector<int> weight(n), value(n);
    int sum_value = 0;
    for(int i = 0; i < n; ++i) {
            cin>>weight[i]>>value[i];
    }
    for(auto x:value)
        sum_value+=x;

    vector<ll> dp(sum_value + 1, INF); // 0 ... W
    dp[0] = 0;
    // dp[i] - the minimum total weight of items with total value exactly i
    for(int item = 0; item < n; ++item) {
        for(int value_already = sum_value - value[item]; value_already >= 0; --value_already) {
        //~ for(int weight_already = 0; weight_already <= W - weight; ++weight_already) {
            min_self(dp[value_already+value[item]], dp[value_already] + weight[item]);
        }
    }
    ll answer = 0;
    for(int i = 0; i <= sum_value; ++i) {
        if(dp[i] <= W) {
            answer = max(answer, (ll) i);
        }
        //~ min_self(answer, dp[i]);
    }
    printf("%lld\n", answer);
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int acs(const void *a, const void *b) { 
  return *(int*)a - *(int*)b;
} /* 1,2,3,4.. */
int des(const void *a, const void *b) {
  return *(int*)b - *(int*)a;
} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { 
  return *(char*)a - *(char*)b;
} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) {
  return strcmp(*(const char **)a, *(const char **)b);
} /* aaa,aab.. */
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007
#define INF 1000000009
typedef long long int lli;

int main(void) {
  int a, b;
  scanf("%d %d", &a, &b);

  rep(i, 1, 1300) {
    if ( (int)((double)i * 0.08) == a &&  (int)((double)i * 0.1) == b ) {
      printf("%d\n", i);
      return 0;
    } 
  }
  printf("-1\n");
  return 0;
}


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

int main(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    int sum = 0;
    for(int i=0;i<n-1;i++)
        sum += a[i];
    if(sum>a[n-1])
        cout<<"Yes\n";
    else
        cout<<"No\n";
    return 0;
}


Measured memory_bytes: 256
// Marcin Knapik
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

using namespace std;

// #include <ext/pb_ds/assoc_container.hpp> // order_of_key
// #include <ext/pb_ds/tree_policy.hpp> // find by order
// using namespace __gnu_pbds; 
// #define ordered_set tree< int , null_type,less< int >, rb_tree_tag,tree_order_statistics_node_update>  

// const ll MAX_LL = 0xFFFFFFFFFFFFFFFF;
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define losuj(a, b) uniform_int_distribution<ll>(a, b)(rng)

#define int ll
typedef long double             ld;
typedef long long               ll;
typedef pair<int, int>          ii;
typedef vector<int>             vi;
typedef vector<ll>              vll;
typedef vector<vll>             vvll;
typedef vector<ii>              vii;
typedef vector<vi>              vvi;
typedef vector<vii>             vvii;
#define pll pair<long long, long long>
#define ull unsigned long long

#define sz(a)                   (int)(a).size()
#define pb                      push_back
#define all(c)                  (c).begin(), (c).end()
#define rall(c)                 (c).rbegin(), (c).rend()
#define FOR(i, a)               for (int i = 0; i < (a); i++)
#define f                       first
#define s                       second

template <class T> inline bool setmin(T &a, T b){if (a > b)return a = b, 1;return 0;}
template <class T> inline bool setmax(T &a, T b){if (a < b)return a = b, 1;return 0;}

template<class T> inline T fast(T a,T b,T mod) {ll res = 1; while(b){if(b&1) res = (res*a)%mod;a = (a*a)%mod;b >>= 1;}return res;}
template<class T> istream &operator>>(istream &os, vector<T> &container){for (auto &u : container)os >> u;return os;}
template<class T> ostream &operator<<(ostream &os, const vector<T> &container){for (auto &u : container)os << u << " ";return os;}
template<class T> inline T gcd(T a, T b) { while (b)swap(a %= b, b); return abs(a); }

const ll INF = 1e9 + 7;
const ll mod = 998244353;
const ll BIG_INF = 1e18 + 7;
const ll N = 1e6+7;
const ll T = 1<<20;
const ld inf = 1e18;
ll m, n, k, q;

vector<ull> baza;

bool check(ull val){
	for(int i = 63; i >= 0; i--)
		if(baza[i] and val & (1ULL << i))
			val ^= baza[i];
	return val == 0;
}

void add(ull val){
	for(int i = 63; i >= 0; i--)
		if(val & (1ULL << i)){
			if(baza[i])
				val ^= baza[i];
			else{
				baza[i] = val;
				return;
			}
		}
}

void solve(){
	cin >> n;
	vector<ull> tab(n);
	baza = vector<ull>(64);
	cin >> tab;

	string s;
	cin >> s;

	for(int i = n - 1; i >= 0; i--){
		if(s[i] == '0')
			add(tab[i]);
		else
			if(!check(tab[i])){
				cout << 1 << '\n';
				return;
			}
	}
	cout << 0 << '\n';
}

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

	cin >> q;
	while(q--)
		solve();
}

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

int fun(int n, int a){
	int ans=0;
	while(n>0){
		ans+=n%a;
		n/=a;
	}
	return ans;
}

int main(){
	int n;
	cin>>n;
	int ans=n;
	for(int i=0; i<=n; i++){
		int check=fun(i,6)+fun(n-i,9);
		ans=min(ans,check);
	}
	cout<<ans<<endl;
}


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

using namespace std;


#ifdef zxc

#include <sys/resource.h>
#include "debug.h"
#include "profile.h"

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define profile(X) LOG_DURATION(X)
#else
#define debug(...) 42
#define profile(...) 42
#endif

using ll = int64_t;
using ld = double;
const ld EPS = 1e-9;
const int MOD = 1e9 + 7;
const ld PI = 3.141592653589793;
const int maxn = 600001;
using cd = complex<double>;

void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}

struct fenwick {
    fenwick(int size) : data(size) {

    }

    void add(int pos, int val) {
        for (; pos < data.size(); pos |= pos + 1) {
            data[pos] += val;
        }
    }

    ll get(int pos) {
        ll res = 0;
        for (; pos >= 0; pos = (pos & (pos + 1)) - 1) {
            res += data[pos];
        }
        return res;
    }

    vector<int> data;

};

signed main() {
#ifdef zxc
    struct rlimit rl;
    const rlim_t kStackSize = 512L * 1024L * 1024L;
    assert(!getrlimit(RLIMIT_STACK, &rl));
    rl.rlim_cur = kStackSize;
    assert(!setrlimit(RLIMIT_STACK, &rl));
    freopen("../input.txt", "r", stdin);
//    freopen("../kolya_output.txt", "w", stdout);
#else
    //    mt19937 mt(std::chrono::high_resolution_clock::now().time_since_epoch().count());
    //            freopen("", "r", stdin);
    //        freopen("hack.out", "w", stdout);
#endif
    profile("all");
    auto solve = [](int _) {
        int n;
        cin >> n;
        int k;
        cin >> k;
        vector<int> a(n + 1);
        vector<ll> pref(n + 1);
        for (int i = 1; i <= n; ++i) {
            cin >> a[i];
            a[i] -= k;
            pref[i] = pref[i - 1] + a[i];
        }
        vector<int> p(n + 1);
        iota(p.begin(), p.end(), 0);
        sort(p.begin(), p.end(), [&](int i, int j) {
            return tie(pref[i], i) < tie(pref[j], j);
        });
        ll ans = 0;
        fenwick fwt(n + 1);
        for (int i:p) {
            ans += fwt.get(i - 1);
            fwt.add(i, 1);
        }
        cout << ans;
    };


    fast_io();

    cout.precision(9);
    cout <<
         fixed;
    for (int i = 1; i <= 1; ++i)
        solve(1);


}


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

int main() {
  int n;
  cin >> n;
  int x = (n+1000-1)/1000;
  int ans = x*1000 - n;
  cout << ans << endl;
  return 0;
}

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

using namespace std;

#define int long long

const int N=2001;

struct kid{
	int val;
	int pos;
	bool operator<(const kid &a) const{
		return val>a.val;
	}
};

kid a[N];
int dp[N][N];

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i].val;
		a[i].pos=i;
	}
	sort(a,a+n);
	for(int i=0;i<n;i++){
		for(int l=0;l<=i;l++){
			int r=n-(i-l)-1;
			dp[i+1][l+1]=max(dp[i+1][l+1],dp[i][l]+a[i].val*abs(l-a[i].pos));
			dp[i+1][l]=max(dp[i+1][l],dp[i][l]+a[i].val*abs(r-a[i].pos));
		}
	}
	int ans=0;
	for(int i=0;i<=n;i++)
		ans=max(ans,dp[n][i]);
	cout<<ans<<"\n";
}

Measured memory_bytes: 26260
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, K, *D = map(int, read().split())

    ng = [False] * 10
    for d in D:
        ng[d] = True

    for n in range(N, 10 ** 5):
        n = str(n)
        ok = True
        for d in n:
            if ng[int(d)]:
                ok = False
                break
        if ok:
            ans = n
            break

    print(ans)
    return


if __name__ == '__main__':
    main()


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

typedef long long ll;
typedef long double ld;
//#define int ll
//#define endl '\n'

// use unique(x) - removec consecutive items, returns vec.begin() + number of items
// for vector: sort(all(vec)); vec.erase(unique(all(vec)), vec.end());
// use iota(all(vec), 0) for filling a vector with 0,1,2...
// use fill(all(vec), 1) for filling a vector with 1,1,1...
// use rotate(vec.begin(), vec.begin() + 1, vec.end()) to rotate a vector | middle arg becomes first
// print number in binary -> cout << bitset<20>(n);

const int N=100010,M=3,inf=1e9;
int n;
int a[N][M],dp[N][M];

main(){
	cin.tie(0);cin.sync_with_stdio(0);
	cin>>n;
	for(int i=0;i<n;++i)cin>>a[i][0]>>a[i][1]>>a[i][2];
	dp[0][0]=dp[0][1]=dp[0][2]=0;
	for(int i=0;i<n;++i)
		for(int j=0;j<M;++j)
			for(int k=0;k<M;++k)
				if(j!=k)
					dp[i+1][k]=max(dp[i+1][k],dp[i][j]+a[i][j]);
	cout<<max({dp[n][0],dp[n][1],dp[n][2]})<<endl;
}


Measured memory_bytes: 5972
#include<bits/stdc++.h>
#define ll long long int
#define endl "\n"
#define mod 1000000007
#define ff first
#define ss second
#define pb push_back
using namespace std;

void solve(int test){
	int n;
	cin>>n;
	ll a[n];
	ll cnt = 0;
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
		if (i != 0)
		{
			if(a[i] < a[i - 1]){
				cnt += a[i - 1] - a[i];
				a[i] = a[i - 1];
			}
		}
	}
	cout<<cnt;
}
  
int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	ll t=1,k;
	//cin>>t;
	k = t;
	while(t--){
		solve(k - t);
	}
	cerr<<"Timpe elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " mps\n" ;
	return 0;
}

Measured memory_bytes: 5368