akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;
static const int MAX_N = 1 << 17;
int bit[MAX_N + 1];
int n;


int sum(int i)
{
	int s = 0;
	while (i > 0)
	{
		s += bit[i];
		i -= i & -i;
	}
	return(s);
}

void add(int i, int x)
{
	while (i <= n)
	{
		bit[i] += x;
		i += i & -i;
	}
}

void solve()
{
	int q;
	cin >> n >> q;
	for (int i = 0; i < q; ++i)
	{
		int com, x, y;
		cin >> com >> x >> y;
		if (com == 0)
		{
			add(x, y);
		}
		else
		{
			cout << sum(y) - sum(x - 1) << endl;
		}
	}
}

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

Measured memory_bytes: 1548
#include <stdio.h>

#define N 10

int main()
{
  int i,x,top=0;
  int stack[N];
  for (i=0;i<N;i++)
    stack[i]=0;

  while (scanf("%d",&x)!=EOF){
    if (x!=0){
      stack[top]=x;
      top++;
    }else{
      top--;
      printf("%d\n",stack[top]);
    }
  }

  return 0;
}

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

int main() {
    int n;
    scanf("%d", &n);
    vector<int> h(n);
    for (int &i: h) scanf("%d", &i);
    vector<int> dp(n);
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for (int i=2; i<n; i++) {
        dp[i] = min(abs(h[i]-h[i-1])+dp[i-1], abs(h[i]-h[i-2])+dp[i-2]);
    }
    printf("%d\n", dp[n-1]);
}

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

using namespace std;

int main()
{
  int e1, e2, c;
  int a = 0, b = 0;
  while(scanf("%d,%d,%d", &e1, &e2, &c) != EOF){
    if(e1*e1 + e2*e2 == c*c) a++;
    else if(e1 == e2) b++;
  }
  cout << a << endl << b << endl;
  return 0;
}

Measured memory_bytes: 1208
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vl=vector<ll>;
#define MOD 1000000007

int main() {
    ll S;
    cin>>S;
    vl wakekata(S+1,0);
    for (int i = 3; i <= S; i++){
        for (int j = 3; j <= i-3; j++){
            wakekata[i]+=wakekata[i-j];
            wakekata[i]%=MOD;
        }
        wakekata[i]++;
    }
    wakekata[S]%=MOD;
    cout<<wakekata[S]<<endl;
}

Measured memory_bytes: 3640
from collections import defaultdict
n,m=map(int,input().split())
d=defaultdict(int)
d[0]=0
for _ in range(n):
       w,u=map(int,input().split())
       for i,j in d.copy().items():
              if i+w<=m:d[i+w]=max(d[i+w],j+u)
print(max(d.values()))

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

int main()
{
	string s;
	cin >> s;
	int ans = (1<<30)-1;
	int na = 0;
	int nb = 0;
	for (int i = 0; i < s.size(); i += 2)
	{
		na += (s[i] == '1');
		nb += (s[i] == '0');
	}
	for (int i = 1; i < s.size(); i += 2)
	{
		na += (s[i] == '0');
		nb += (s[i] == '1');
	}
	cout << min(na, nb) << endl;
	return 0;
}

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


int main() {
  int A, B, M;
  cin >> A >> B >> M;
  
  int i = 0;
  vector<int> a(A), b(B), x(M), y(M), c(M);
  rep(i, A) cin >> a[i];
  rep(i, B) cin >> b[i];
  rep(i, M) {
    cin >> x[i] >> y[i] >> c[i];
  }
  
  int mina = a[0], minb = b[0];
  rep(i, A) {
    if(a[i] < mina) mina = a[i];
  }
  rep(i, B) {
    if(b[i] < minb) minb = b[i];
  }
  
  int ans = mina + minb;
  
  rep(i, M) {
    if(a[x[i]-1] + b[y[i]-1] - c[i] < ans) ans = a[x[i]-1] + b[y[i]-1] - c[i];
  }
  
  
  
  cout << ans << endl;
  
}


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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int n;
  while (cin >> n, n) {
    vector<int> a;
    for (int i = 1; i < n; i++) {
      a.emplace_back(i * i % n);
    }
    sort(a.begin(), a.end());
    a.erase(unique(a.begin(), a.end()), a.end());
    vector<int> ans((n - 1) / 2 + 1);
    for (int i = 0; i < int(a.size()); i++) {
      for (int j = 0; j < int(a.size()); j++) {
        int tmp = a[j] - a[i];
        if (tmp == 0) continue;
        if (tmp < 0) tmp += n;
        if (tmp > (n - 1) / 2) tmp = n - tmp;
        ans[tmp]++;
      }
    }
    for (int i = 1; i <= (n - 1) / 2; i++) {
      cout << ans[i] << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 3188
n=gets.to_i
T=gets.split.map &:to_i
A=gets.split.map &:to_i
X=[0]*n
c=0
a=1
n.times{|i|
  if T[i]!=c
    X[i] = 1
    a=0 if T[i]>A[i]
  end
  c=T[i]
}
Y=[0]*n
c=0
(n-1).downto(0){|i|
  if A[i]!=c
    Y[i] = 1
    a=0 if T[i]<A[i]
  end
  c=A[i]
}
n.times{|i|
  if X[i]+Y[i]<1
    a *= [T[i],A[i]].min
    a %= 10**9+7
  end
}
p a

Measured memory_bytes: 21012
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;cin >> s;
	string ans = "";
	rep(i,s.size()){
		if(s.at(i) == '0') ans += '0';
		else if(s.at(i) == '1') ans += '1';
		else{
			if(ans != "") ans = ans.substr(0,ans.size() - 1);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,u) for(int i=start[u];i;i=e[i].next)
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
#define SZ(A) ((int)A.size())
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
inline int read()
{
	int s=0,f=1;char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')ch=getchar(),f=-1;
	while(isdigit(ch))s=s*10+ch-'0',ch=getchar();
	return ~f?s:-s;
}

const int maxn=3e5+20;

int n,L;
int x[maxn],t[maxn];
int a[maxn],b[maxn],vis[maxn];
ll ans;

inline void init()
{
	n=read();L=read();
	REP(i,1,n)x[i]=read();
	REP(i,1,n)
	{
		t[i]=read();
		ans+=t[i]/(L<<1);
		t[i]%=L<<1;
		if(!t[i]){ vis[i]=1; continue;}
		if(t[i]<=2*(L-x[i]))a[i]=1;//右进左出
		if(t[i]<=2*x[i])b[i]=1;//左进右出
		if(a[i]+b[i]==0){ vis[i]=1; ans++; continue;}
	}
	vector<int>t01;
	queue<int>t11;
	
	REP(i,1,n-1)
	{
		if(a[i] || b[i])
		{
			if(b[i])
			{
				if(a[i])t11.push(i);
				else t01.push_back(i);
			}else
			{
				if(!t01.empty())vis[t01.back()]=1,vis[i]=1,t01.pop_back(),ans++;
				else if(!t11.empty())vis[t11.front()]=1,vis[i]=1,t11.pop(),ans++;
				//else;
			}
		}
	}
	t01.clear(); while(!t11.empty())t11.pop();
	REP(i,1,n-1)if(!vis[i])
	{
		if(b[i])
		{
			if(a[i])
			{
			 	if(!t01.empty())vis[t01.back()]=1,vis[i]=1,t01.pop_back(),ans++;
			 	else t11.push(i);
			}else t01.push_back(i);
		}//else if(!t11.empty())vis[t11.front()]=1,vis[i]=1,t11.pop(),ans++;
	}
	while(SZ(t11)>=2)
	{
		int x=t11.front(); t11.pop();
		int y=t11.front(); t11.pop();
		vis[x]=1; vis[y]=1; ans++;
	}
	if(vis[n]==0 && a[n])
	{
		REP(i,1,n-1)if(vis[i]==0 && b[i])
		{
			vis[i]=vis[n]=1;
			ans++;
			break;
		}
	}
	REP(i,1,n)
	{
		if(!vis[i])
		{
			ans++;
		}
	}
	ans+=(vis[n] || !a[n]);
	printf("%lld\n",ans*(L<<1));
}

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


Measured memory_bytes: 7116
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
  int a, b;
  cin >> a >> b;
  int ans = 6-a-b;
  cout << ans << endl;
  return 0;
}

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

#define int long long 
#define double long double

typedef pair<int,int> pi;

typedef vector<int> vi;
typedef vector<pi> vpi;

#define f first
#define s second
#define mp make_pair
#define pb push_back

#define gcd __gcd

const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int fast_ex(int a,int n,int m){
  if(n == 0)return 1;
  if(n == 1)return a;
  int x = 1;
    x *= fast_ex(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}

signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  int n,k,gc,i,j;
  cin >> n >> k;
  cin >> gc;
  int mx = gc;
  for(i = 0;i < n-1;i++){
  	cin >> j;
  	mx = max(mx,j);
  	gc = gcd(gc,j);
  }
  if( (k%gc) == 0 && mx >= k)cout << "POSSIBLE";
  else cout << "IMPOSSIBLE";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; ++i)
#define reps(i,s,n) for(int i = (s); i < (n); ++i)
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 (b<a) { a=b; return 1; } return 0; }
long long gcd(long long x, long long y) {
    return y ? gcd(y, x%y) : x;
}
int main(){

  string s; cin >> s;
  int n = s.size(), cnt=0;
  rep(i,n/2){
    if(s[i]!=s[n-1-i]) cnt++;
  }
  cout << cnt;

  return 0;
 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lp(i, x, n) for (int i = x; i < (int)n; ++i)
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()
#define ll unsigned long long
#define N 100001
#define mod 1000000007
int main() {
        string s;
        cin >> s;
        s[3]++;
        cout << s;
        return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>//
#include <vector>//
#include <map>
#include <cstdlib>
#include <numeric>
#include <algorithm>//ソート等に使用
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <thread>///////////////////
#include <queue>//幅優先等のキュー
#include <stack>

#define rep(i,m,n) for(int i=(m);i<(n);i++)
#define mer(i,m,n) for(int i=(m);i>(n);--i)

#define MOD 1000000007
//#define MOD 998244353
#define MAX 

using namespace std;

using ll = long long int;
using ld = long double;
using std::swap;

vector<int> v;
vector<int> w;
vector<long long int> vll;
vector<long long int> wll;
//vector<vector<int>> vec(50, vector<int>(4, 0));
vector<vector<int>> vv;
vector<vector<int>> ww;
//vector<char> vc;



int main() {
	int N,Q;
	cin >> N;
	v.resize(100001,0);
	rep(i, 0, N) {
		int x;
		cin >> x;
		++v[x];
	}
	cin >> Q;
	vll.resize(Q + 1, 0);
	rep(i, 1, 100001) {
		vll[0] += v[i] * i;
	}
	rep(i, 0, Q) {
		int x, y;
		cin >> x >> y;
		vll[i+1] = vll[i] + v[x] * (y - x);
		v[y] += v[x];
		v[x] = 0;
	}
	rep(i, 1, Q + 1) {
		cout << vll[i] << '\n';
	}

	return 0;
}

Measured memory_bytes: 4552
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		int a;

		Scanner sc = new Scanner(System.in);

		a = sc.nextInt();
		Long[] aArray = new Long[a];

		for (int i = 0; i < a; i++) {
			aArray[i] = sc.nextLong();
		}

		List<Long> list = new ArrayList<Long>(Arrays.asList(aArray));
		Collections.sort(list,Comparator.reverseOrder());

		long max = list.get(0);
		long maxNext = list.get(1);

		for (int i = 0; i < a; i++) {
			if (max == aArray[i]) {
				System.out.println(maxNext);
			} else {
				System.out.println(max);
			}
		}
	}
}


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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL<<60;
const ll mod =1000000009;

const int max_V = 100005;
vector<int> G[max_V];
vector<int> color(max_V);
int n;

bool dfs(int v, int c) {
	color[v] = c;
	for (int i : G[v]) {
		if (color[i] == c)return false;
		if (color[i] == 0 && !dfs(i, -c))return false;
	}
	return true;
}

bool is_bipartite() {
	REP(i, n) {
		if (color[i] == 0) {
			if (!dfs(i, 1))return false;
		}
	}
	return true;
}

int main() {
	

	int m;
	cin >> n >> m;

	REP(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	if (is_bipartite()) {
		ll a = count(ALL(color), 1);
		ll b = count(ALL(color), -1);

		cout << a * b - m << endl;
	}
	else {
		ll v = n;
		cout << v * (v - 1) / 2 - m << endl;
	}


}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main()
{
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i, n) cin >> p[i];

    sort(all(p));
    int su = 0;
    rep(i, n) su += p[i];

    cout << su - p[n - 1] / 2 << '\n';
    return 0;
}


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

ll solve() {
    ll N, A, B;
    cin >> N >> A >> B;
    vector<ll> V(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> V[i];
    }
    sort(V.begin(), V.end(),greater<>());
    ll s = 0;
    for ( int i = 0; i < A; i++ ) {
        s += V[i];
    }
    double m = s/(double)A;
    ll l = lower_bound(V.begin(), V.end(), V[A-1], greater<>()) - V.begin();
    ll r = upper_bound(V.begin(), V.end(), V[A-1], greater<>()) - V.begin();
    ll cr = r - l;
    ll cb = B - l;
    ll ca = A - l;
    ll d = 1;
    ll ans = 0;
    for ( ll i = 0; i < cb; i++ ) {
        d *= cr - i;
        d /= (i+1);
        if ( i+1 >= ca ) ans += d;
        if ( l != 0 && i+1 >= ca ) break;
    }

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

int main() {
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

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

int main() {
  int n,m;
  cin >> n >> m;
  int shukudai = 0;
  for(int i=0; i<m; i++){
    int a;
    cin >> a;
    shukudai += a;
  }
  
  int ans = n - shukudai;
  if(ans < 0) ans = -1;
  cout << ans << endl;
}
  

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


typedef pair<int,int> pii;

int dx[] = {-1,0,1,0};
int dy[] = {0,1,0,-1};
int main (){

  int n;
  while(1){
    cin >> n;
    if(!n) break;

    int m[1000][1000] = {};
    m[500][500] = 1;
    vector<pair<int,int> > xy(n+1,pii(500,500));    

    for(int i=1; i<n; i++){
      int p,d;
      cin >> p >> d;

      int nx = xy[p].first + dx[d];
      int ny = xy[p].second + dy[d];
     
      m[ny][nx] = 1;

      xy[i] = pii(nx,ny);
    }

    int minx=1000,maxx=-1,miny=1000,maxy=-1;
    for(int i=0; i<1000; i++){
      for(int j=0; j<1000; j++){
	if(m[i][j] == 1){
	  minx = min(minx,j);
	  miny = min(miny,i);
	  maxx = max(maxx,j);
	  maxy = max(maxy,i);
	}
      }
    }
    cout << (maxx - minx) +1<< " " << (maxy - miny)+1 << endl;
    
  }
}

Measured memory_bytes: 5108
from operator import add

pre = [
    ((0, 1, 2), (1, 0, 1), (2, 1, 0)),
    ((3, 2, 2), (2, 1, 1), (2, 1, 1)),
    ((1, 1, 2), (1, 1, 2), (2, 2, 3)),
    ((3, 2, 2), (2, 2, 2), (2, 2, 3)),
]

q = int(input())
for _ in range(q):
    n = int(input())
    books = [c == 'Y' for c in input()]
    books = [(0, 0)] + list(zip(books[:2 * n], books[2 * n:])) + [(0, 0)]
    shelves = [(u1 | u2) * 2 + (l1 | l2) for (u1, l1), (u2, l2) in zip(*[iter(books)] * 2)]
    ans = [0, 1, 2]
    for key in shelves:
        new_ans = [min(map(add, ans, costs)) for costs in pre[key]]
        ans = new_ans
    print(ans[0] + n)

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

using ll = long long;

ll N, T;
ll t[222222];

int main() {
   cin >> N >> T;
   for (int i = 0; i < N; i++) {
      cin >> t[i];
   }
   
   ll ans = 0;
   for (int i = 0; i < N-1; i++) {
      ans += min(t[i+1] - t[i], T);
   }
   ans += T;

   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 1792
import sys
input=sys.stdin.readline
from collections import defaultdict
from heapq import heappush, heappop,heappushpop,heapify
n,m = map(int, input().split())
link = defaultdict(list)
chg=10**8
for _ in range(m):
    p,q,c=map(int, input().split())
    link[p].append([p+chg*c,1])
    link[p+chg*c].append([p,1])

    link[q+chg*c].append([p+chg*c,0])
    link[p+chg*c].append([q+chg*c,0])

    link[q+chg*c].append([q,1])
    link[q].append([q+chg*c,1])

def dks(g,start):
    INF=float('inf')
    visited = set()
    hq = []
    heappush(hq, (0,start))
    while hq:
        shortest, i = heappop(hq)
        if i in visited:
            continue
        visited.add(i)
        for j, t in g[i]:
            if j in visited:
                continue
            if j==n:
                return (shortest+t)//2
            heappush(hq, (shortest + t, j))
    return -1
ans=dks(link,1)
print(ans)

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

int main() {
  int N;
  cin >> N;
  vector<psii> p(N);
  rep(i,N) {
    cin >> p[i].first.first >> p[i].first.second;
    p[i].first.second *= -1;
    p[i].second = i+1;
  }
  sort(p.begin(), p.end());
  rep(i,N) {
    cout << p[i].second << endl;
  }
}

Measured memory_bytes: 3596
from collections import Counter
n = int(input())
x = {i: 10000 for i in "abcdefghijklmnopqrstuvwxyz"}
for _ in range(n):
    s = Counter(input())
    for i in "abcdefghijklmnopqrstuvwxyz":
        x[i] = min(x[i], s[i])
ans = ""
for i, v in sorted(x.items()):
    ans += i * v
print(ans)

Measured memory_bytes: 3436
import itertools
n,a,b,c=map(int,input().split())
ans=float("inf")
l=[]
for i in range(n):l.append(int(input()))
for i in itertools.product([1,2,3,0],repeat=n):
    if i.count(1) and i.count(2) and i.count(3):
        m=[0,0,0,0]
        for j in range(n):
            m[i[j]]+=l[j]
        ans=min(ans,abs(m[1]-a)+abs(m[2]-b)+abs(m[3]-c)+(n-i.count(0)-3)*10)
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>

int main(void)
{
  int len, q;
  scanf("%d%d", &len, &q);

  char str[len + 1];
  scanf("%s", str);

  int i, j, k;
  int table[len];

  table[0] = 0;
  for(i = 1; i < len; i++)
    {
      if(str[i - 1] == 'A' && str[i] == 'C') {
        table[i] = table[i - 1] + 1;
      }
      else {
        table[i] = table[i - 1];
      }
    }

  int answers[len];
  for(i = 0; i < q; i++) {
    scanf("%d%d", &j, &k);
    answers[i] = table[k - 1] - table[j - 1];
  }
  for(i = 0; i < q; i++) {
    printf("%d\n", answers[i]);
  }
  return 0;
}


Measured memory_bytes: 1664
//
// じょえチャンネル
// https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
//
// Created by yamunaku on 2020/02/22.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

ll modpow(ll x, ll a){
    ll ans = 1;
    while(a){
        if(a & 1) ans = ans * x % MOD;
        a >>= 1;
        x = x * x % MOD;
    }
    return ans;
}

ll inv(ll x){
    return modpow(x, MOD - 2);
}

vector<ll> fact, invfact;

void buildFact(int n){
    fact = vector<ll>(n + 1, 1);
    invfact = vector<ll>(n + 1, 1);
    for(int i = 1; i <= n; i++){
        fact[i] = fact[i - 1] * i % MOD;
    }
    invfact[n] = inv(fact[n]);
    for(int i = n - 1; i >= 1; i--){
        invfact[i] = invfact[i + 1] * (i + 1) % MOD;
    }
}

ll bcomb(int n, int k){
    return fact[n] * invfact[k] % MOD * invfact[n - k] % MOD;
}


int main(){
    //CFS;
    ll n, a, b;
    cin >> n >> a >> b;
    buildFact(200000);
    ll ans = modpow(2, n) - 1;
    ll tmp = invfact[a];
    rep(i, a){
        tmp = tmp * (n - i)  % MOD;
    }
    ans += -tmp + MOD;
    tmp = invfact[b];
    rep(i, b){
        tmp = tmp * (n - i) % MOD;
    }
    ans += -tmp + MOD;
    ans %= MOD;
    cout << ans << endl;
    return 0;
}

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

using namespace std;
#define ll long long
#define ull unsigned long long
#define all(x) x.begin(), x.end()
typedef vector<ll> vll;
typedef vector<int> vi;
const ll N = 2e6 + 10;
const int M = 1e9 + 7;
const double eps = 1e-9;

int main() {
    ll n;
    cin >> n;
    vll v(n);
    ll x = 0;
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
        x ^= v[i];
    }
    for (int j = 0; j < n; ++j) {
        cout << (x ^ v[j]) << " ";
    }
}



Measured memory_bytes: 4708
package main
import (
        "bufio"
        "fmt"
        "os"
        "strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
    sc.Scan()
    return sc.Text()
}

func main() {
    input, _ := strconv.Atoi( nextLine())
    fmt.Println(input*input*input)
}


Measured memory_bytes: 1116
import java.util.Scanner;

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

        if (Math.abs(x - a) < Math.abs(x - b)) {
            System.out.println("A");
        } else {
            System.out.println("B");
        }
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,a[100001];
    long long ans=0;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=1;i<=n;i++){
        int b;
        ans+=a[i]/2;
        b=a[i]%2;
        if(i<n&&b&&a[i+1]){
            ans++;
            a[i+1]--;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 640
a,b=map(int, input().split())

ans =[]
for x in range(10*b+10):
	if a<=x*0.08<a+1 and b<=x*0.1<b+1:
		ans.append(x)
if len(ans) != 0:
	print(min(ans))
else:
	print(-1)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end() 
#define rep(i, K, N)  for(long long int i = K; i < N; i++)
#define ll long long int
using namespace std;

int main() {
ll N;cin >> N;
map<ll, ll> P;
  
rep(x, 1, N){
if(x*x >= N)break;
rep(y, 1, N){
if(y*y >= N)break;
rep(z, 1, N){
if(z*z >= N)break;
P[x*x + y*y + z*z + x*y + y*z + x*z]++;
}
}
}

rep(i, 1, N + 1)cout << P[i] << endl;
}

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

using namespace std;

#define F first
#define S second
#define modulo ll (1e9 + 7)

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

void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}

const int N = 1e5 + 9, M = 2e3 + 9, OO = 0x3f3f3f3f;
const ll llOO = 0x3f3f3f3f3f3f3f3f;


int main(){
    init();

    ll x;   cin >> x;
    if(x < 7)   return cout << 1, 0;
    if(x < 12)  return cout << 2, 0;

    ll op = x / 11, a = 0, b = 0, p = 0;
    while((op + a) * 5 + (op + b) * 6 < x){
        if(p)   a++;
        else b++;
    }
    cout << op * 2 + a + b;
}

Measured memory_bytes: 256
MOD = 10 ** 9 + 7

N, M = map(int, input().split())
a = {int(input()) for i in range(M)}

dp = [0 for _ in range(N+1)]
dp[0] = 1
for i in range(1, N+1):
    if i in a:
        dp[i] = 0
    else:
        dp[i] = (dp[i-1]+dp[i-2]) % MOD

print(dp[N])

Measured memory_bytes: 11884
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll   long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f3f
#define pi 3.1415926535898
using namespace std;
const int N=3e5+10;
const int mod=1e9+7;
char mp[2020][2020];
int dis[2020][2020];
int vis[2020][2020];
int h,w,x11,y11,x2,y2;
int sum=inf;
int dx[4]= {0,0,1,-1};
int dy[4]= {1,-1,0,0};
struct A
{
    int x,y,v;
    A(int x=0,int y=0,int v=0):x(x),y(y),v(v) {}
    bool operator<(const A&o)const
    {
        return v>o.v;
    }
};
int main()
{
    cin>>h>>w;
    cin>>x11>>y11;
    cin>>x2>>y2;
    for(int i=1; i<=h; i++)
    {
        for(int j=1; j<=w; j++)
        {
            cin>>mp[i][j];
        }
    }
    memset(dis,inf,sizeof(dis));
    priority_queue<A>q;
    q.push(A(x11,y11,dis[x11][y11]));
    dis[x11][y11]=0;
    while(!q.empty())
    {

        int x=q.top().x;
        int y=q.top().y;
        q.pop();
        if(vis[x][y])
        {
            continue;
        }
        vis[x][y]=1;
        for(int i=0; i<4; i++)
        {
            int xx=x+dx[i];
            int yy=y+dy[i];
            if(xx>=1&&xx<=h&&yy>=1&&yy<=w&&mp[xx][yy]!='#')
            {
                if(dis[xx][yy]>dis[x][y])
                {
                    dis[xx][yy]=dis[x][y];
                    q.push(A(xx,yy,dis[xx][yy]));
                }
            }
        }
        for(int i=-2; i<=2; i++)
        {
            for(int j=-2; j<=2; j++)
            {
                int xx=x+i;
                int yy=y+j;
                if(xx>=1&&xx<=h&&yy>=1&&yy<=w&&mp[xx][yy]!='#')
                {
                    if(dis[xx][yy]>dis[x][y]+1)
                    {
                        dis[xx][yy]=dis[x][y]+1;
                        q.push(A(xx,yy,dis[xx][yy]));
                    }
                }
            }
        }
    }
    if(dis[x2][y2]==inf)
    {
        cout<<-1<<endl;
    }
    else
    {
        cout<<dis[x2][y2]<<endl;
    }
    return 0;
}


Measured memory_bytes: 29396
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int len;
string s;
int gx,gy;
int sx=0,sy=0;

string change(string s){
  int len=s.size();
  string res="";
  for(int i=0;i<len;i++){
    if(s[i]=='F'){
      int cnt=1;
      while(i+1<len && s[i+1]=='F'){
        i++;
        cnt++;
      }
      if(cnt%2==0)res+='f';
      else res+='F';
      
    }else{
      res+=s[i];
    }
  }
  return res;
}

int main(){
  cin>>s>>gx>>gy;

  int len=s.size();
  int p=0;
  int cc=0;
  int dir=0;
  vector<int> v,w;
  
  while(p<len){
    
    if(s[p]=='F'){
      cc++;
      p++;
    }else if(s[p]=='T'){
      if(dir==0)v.push_back(cc);
      if(dir==1)w.push_back(cc);
      dir=(dir+1)%2;
      p++;
      cc=0;
    }
  }
      if(dir==0)v.push_back(cc);
      if(dir==1)w.push_back(cc);
      /*
  for(int x:v)cout<<x<<' ';
  cout<<endl;
    for(int x:w)cout<<x<<' ';
  cout<<endl;
      */
  unordered_set<int> st;
  st.insert(0);
  for(int i=0;i<(int)v.size();i++){
    unordered_set<int> nst;
    for(int x:st){
      nst.insert( x+v[i] );
      if(i){
        nst.insert( x-v[i] );
      }
    }
    st=nst;
  }

  if(st.count(gx)==0){
    cout<<"No"<<endl;
    return 0;
  }

  st.clear();
  st.insert(0);
  for(int i=0;i<(int)w.size();i++){
    unordered_set<int> nst;
    for(int x:st){
      nst.insert( x+w[i] );
      nst.insert( x-w[i] );
    }
    st=nst;
  }

  if(st.count(gy)==0){
    cout<<"No"<<endl;
    return 0;
  }

  cout<<"Yes"<<endl;
  return 0;
}


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

using ll = long long;

ll ans(string s){
	if(s.size() <= 1) return 0;
	if(s[0] == s[1]) return 1 + ans(s.substr(2));
	return ans(s.substr(1));
}

ll solve(ll k, string s){
	string t;
	for(int i = 0; i < k; i++) t += s;
	return ans(t);
}

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	string s;
	cin >> s;
	ll k;
	cin >> k;
	ll v = (k % 2) + 4;
	ll diff = solve(v+2, s) - solve(v, s);
	cout << solve(v, s) + diff * ((k - v) / 2) << '\n';
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int ban;
double a, x, y;
 
int main(){
	scanf("%d %lf", &ban, &a);
	int jum = 0;
	for(int k = 1; k<= ban ; k++){
		scanf("%lf %lf", &x, &y);
		double jaw = sqrt(x*x + y*y);
		if(jaw<= a){
			jum++;
		}
	}
	printf("%d", jum);
}


Measured memory_bytes: 3836
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
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 (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll MOD = 1000000007;

int main() {
    vi a(3);
    rep(i,3) cin >> a[i];
    sort(all(a));
    int aa = a[0];
    int bb = a[1];
    int cc = a[2];
    cout << aa << " " << bb << " " << cc << "\n";
}



Measured memory_bytes: 3164
#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> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#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 pub push_back
#define pob 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)
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 main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

    int H, W; cin >> H >> W;
    ve_vei a(H, vei(W)); rep(i,H) rep(j,W) cin >> a[i][j];
    ve_vei copy = a;
    int cnt = 0;
    for(int x = 0; x <= W-1; x++ ) {
        if(x % 2 == 0){
            for(int y = 0; y <= H-1;y++) {
                if( y != H-1 and copy[y][x] % 2 == 1 ) { copy[y+1][x] += 1; cnt++; }
                if( y == H-1 and x != W-1 and copy[y][x] % 2 == 1 ) { copy[y][x+1] += 1;cnt++; }
            }
        }
        else {
            for(int y = H-1; y>= 0; y--){
                if( y != 0 and copy[y][x] % 2 == 1) { copy[y-1][x] += 1; cnt++; }
                if( y == 0 and x != W-1 and copy[y][x] % 2 == 1) { copy[y][x+1] += 1; cnt++; }
            }
        }
    }
    cout << cnt << endl;

    for(int x = 0; x <= W-1; x++ ) {
        if(x % 2 == 0){
            for(int y = 0; y <= H-1;y++) {
                if( y != H-1 and a[y][x] % 2 == 1 ) { a[y+1][x] += 1; cout << y+1 << " " << x+1 << " " << y+2 << " " << x+1 << endl; }
                if( y == H-1 and x != W-1 and a[y][x] % 2 == 1) { a[y][x+1] += 1; cout << y+1 << " " << x+1 << " " << y+1 << " " << x+2 << endl; }
            }
        }
        else {
            for(int y = H-1; y>= 0; y--){
                if( y != 0 and a[y][x] % 2 == 1) { a[y-1][x] += 1; cout << y+1 << " " << x+1 << " " << y << " " <<  x+1 << endl; }
                if( y == 0 and x != W-1 and a[y][x] % 2 == 1) { a[y][x+1] += 1; cout << y+1 << " " << x+1 << " " << y+1 << " " << x+2 << endl; }
            }
        }
    }
}



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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

class Prints {
private:
    class __Prints {
    public:
        __Prints(const char* sep, const char* term) : sep(sep), term(term) {}
        template <class... Args>
        void operator()(Args&&... args) const { print(std::forward<Args>(args)...); }

    private:
        const char *sep, *term;
        void print() const { std::cout << term; }
        void print_rest() const { std::cout << term; }
        template <class T, class... Tail>
        void print(T&& head, Tail&&... tail) const { std::cout << head, print_rest(std::forward<Tail>(tail)...); }
        template <class T, class... Tail>
        void print_rest(T&& head, Tail&&... tail) const { std::cout << sep << head, print_rest(std::forward<Tail>(tail)...); }
    };

public:
    Prints() {}
    __Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); }
    template <class T>
    void print_vec(const std::vector<T>& vec, const char* sep = " ", const char* term = "\n") const {
        const size_t sz = vec.size();
        for (size_t i = 0; i < sz; i++) std::cout << vec[i] << (i == sz - 1 ? term : sep);
    }
};

Prints prints;

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll K;
    cin >> K;
    bool ok = true;
    ll cur = 7 % K;
    ll base = 1;
    ll ans = 1;
    set<ll> st;
    while (true) {
        if (cur == 0) {
            break;
        }
        if (st.find(cur) != st.end()) {
            ok = false;
            break;
        }
        st.emplace(cur);
        base *= 10;
        base %= K;
        cur = (cur + 7 * base) % K;
        ++ans;
    }
    if (ok) {
        prints()(ans);
    }
    else {
        prints()(-1);
    }
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    cout << setprecision(18) << fixed;
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 50488
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    string s, t;
    cin >> s >> t;
    int n = s.length(), ans = 0;
    for(int i=0;i<n;i++){
        if(s[i] != t[i]) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
#include <boost/range.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/algorithm_ext.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>
using namespace std;
constexpr char nl = '\n';
using ll = long long;
using boost::irange;
namespace rng { using namespace boost; using namespace boost::range; }
namespace adp { using namespace boost::adaptors; }

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

template<class C> auto operator>>(istream& in, C& c) -> typename enable_if<!is_void<decltype(c.begin())>::value && !is_same<C, string>::value, istream&>::type {
    for (auto& v : c) { in >> v; } return in; }
template<class C> auto operator<<(ostream& out, const C& c) -> typename enable_if<!is_void<decltype(c.begin())>::value && !is_same<C, string>::value, ostream&>::type {
    int i = 0; for (const auto& v : c) { if (i++) { out << ' '; } out << v; } return out; }
template<size_t N, class T, class R> using when_last = typename enable_if<N == tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N, class T, class R> using when_init = typename enable_if<N != tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_last<N, T, istream&> { return in >> get<N>(t); }
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_init<N, T, istream&> { return operator>><N + 1>(in >> get<N>(t), forward<T>(t)); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_last<N, T, ostream&> { return out << get<N>(t); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_init<N, T, ostream&> { return operator<<<N + 1>(out << get<N>(t) << ' ', t); }

#ifdef LOCAL
constexpr auto color_s_ = "\033[2m\033[33m", color_e_ = "\033[0m";
template<class T> void trace_(const T& v) { cerr << v; }
template<class T> void trace_(const vector<vector<T>>& m) { cerr << "\n"; for (const auto& v : m) { trace_(v); cerr << "\n"; } }
template<class T> void trace_(const char* s, const T& v) { cerr << color_s_ << s << "="; trace_(v); cerr << color_e_ << "\n"; cerr.flush(); }
template<class T, class... Ts> void trace_(const char* s, const T& v, const Ts&... vs) { cerr << color_s_; for (; *s != ','; ++s) { cerr << *s; } cerr << "="; trace_(v); cerr << ","; trace_(++s, vs...); }
#define TRACE(...) trace_(#__VA_ARGS__, __VA_ARGS__)
#else
#define TRACE(...)
#endif

int main() {
    int n, m;
    cin >> n >> m;
    map<int, ll, greater<int>> as;
    for (int i : irange(0, n)) {
        int a;
        cin >> a;
        as[a] += 1;
    }
    for (int i : irange(0, m)) {
        int b, c;
        cin >> b >> c;
        as[c] += b;
    }
    ll ans = 0;
    int rem = n;
    for (const auto& p : as) {
        ll a, k;
        tie(a, k) = p;
        if (rem > k) {
            rem -= k;
            ans += a * k;
        } else {
            ans += a * rem;
            break;
        }
    }
    cout << ans << nl;
}


Measured memory_bytes: 12800
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <deque>
#include <valarray>
#include <unordered_map>
#include <unordered_set>
#include <array>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <chrono>
#include <random>
#include <numeric>
using namespace std;
using ll = long long;
using ld = long double;
using str = string;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vs> vvs;
typedef vector<vc> vvc;
typedef vector<vb> vvb;
using P = pair<ll,ll>;
#define REP(i, n) for (ll i = 0; i < (int)(n); i++)
#define RREP(i, n) for (ll i = (int)(n)-1; i > -1 ; i--)
#define IN(T, x) T x;cin >> x;
#define AIN(T, a, n) vector<T> a(n);REP(i, n){cin >> a[i];}
#define A2IN(T1, a, T2, b, n) vector<T1> a(n);vector<T2> b(n);REP(i, n){cin >> a[i] >> b[i];}
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) SORT(a);reverse(ALL(a))
#define pb push_back
#define mp make_pair
#define PF first
#define PS second
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(b<a){a=b;return 1;}return 0;}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
#define OUT(x) cout << x << endl;
#define OUTD(x) cout << fixed << x << endl;
#define BOUT(b) if(b){OUT("Yes");}else{OUT("No");}
const ll MOD = 1000000007;
const ll INF = 10e9;
#define PI 3.14159265369;
ll dx[4] = {1,-1,0,0};
ll dy[4] = {0,0,1,-1};
ll ddx[8] = {1,1,1,-1,-1,-1,0,0};
ll ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll ans = INF;
  IN(ll,N);
  IN(ll,M);
  IN(ll,X);
  vll C(N);
  vvll A(N,vll(M));
  REP(i,N){
    cin >> C.at(i);
    REP(j,M){
      cin >> A.at(i).at(j);
    }
  }
  REP(i,1<<N){
    ll money = 0;
    vll skill(M,0);
    REP(j,N){
      if(i>>j&1){
        bool isOK = true;
        money += C.at(j);
        REP(k,M){
          skill.at(k) += A.at(j).at(k);
          if(skill.at(k) < X){
            isOK = false;
          }
        }
          if(isOK){
            chmin(ans,money);
            break;
          }
      }
    }
  }
  if(ans == INF){
    OUT(-1);
  }else{
    OUT(ans);
  }
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=1<<20,INF=1<<30;

int bit[MAX+1],M;

//1-indexed

int sum(int i){
    int s=0;
    while(i>0){
        s+=bit[i];
        i-=i&-i;
    }
    return s;
}

//sからtの和=sum(t)-sum(s-1)

void add(int i,int x){
    while(i<=M){
        bit[i]+=x;
        i+=i&-i;
    }
}

int par[MAX];

void init(int n){
    for(int i=0;i<n;i++){
        par[i]=i;
    }
}

int root(int a){
    if(par[a]==a) return a;
    else return par[a]=root(par[a]);
}

void unite(int a,int b){
    if(root(a)!=root(b)) par[root(b)]=root(a);
}

bool check(int a,int b){
    return root(a)==root(b);
}

int main(){
    
    int N,K;cin>>N>>K;
    M=N*2;
    vector<pair<int,int>> P(N);
    vector<int> A(M,0),B(M,0),C(M,0),done(M,0);
    for(int i=0;i<N;i++){
        cin>>P[i].first;
        P[i].second=i;
    }
    
    for(int i=0;i<N;i++){
        if(P[i]>P[i+1]) C[i]=1;
        else C[i]=0;
    }
    C[N]=0;
    
    sort(all(P));
    
    for(int i=0;i<N;i++){
        int a=P[i].first,b=P[i].second;
        int s=sum(b+K)-sum(b);
        if(s>0) A[b]=1;
        add(b+1,1);
    }
    
    for(int i=0;i<=MAX;i++){
        bit[i]=0;
    }
    
    reverse(all(P));
    
    
    
    for(int i=0;i<N;i++){
        int a=P[i].first,b=P[i].second;
        //cout<<a<<" "<<b<<endl;
        int s=sum(b+N+1)-sum(b+N-(K-1));
        if(s>0) B[b]=1;
        add(b+N+1,1);
    }
    
    int sum=1;
    
    init(N-K+1);
    
    set<int> SE;
    
    for(int i=0;i<N-K;i++){
        if(!(A[i]||B[i+(K)])){
            unite(i,i+1);
        }
        //cout<<sum<<endl;
    }
    
    vector<int> S(N+1,0);
    
    for(int i=0;i<N;i++){
        S[i+1]=S[i]+C[i];
        //cout<<S[i+1]<<endl;
    }
    
    int cnt=0;
    
    int was=-1;
    
    for(int i=0;i<=N-K;i++){
        if(S[i+K-1]-S[i]==0){
            if(was==-1) was=i;
            else unite(i,was);
        }
    }
    
    for(int i=0;i<=N-K;i++){
        SE.insert(root(i));
    }
    
    //cout<<sum<<" "<<cnt<<endl;
    
    if(cnt>=2) sum-=(cnt-1);
    
    if(sum==0) sum++;
    //cout<<sum<<endl;
    
    cout<<SE.size()<<endl;
    
}



Measured memory_bytes: 23168
#include <stdio.h>

main(){
  int a, d = 0, s = 1, n, dta[251];
  
  scanf("%d", &n);
  for(a=1;a<=n;a++) scanf("%d", &dta[a]);
  for(a=1;a<=n;a++){
    printf("node %d: key = %d, ", a, dta[a]);
    
    if(a/2) printf("parent key = %d, ", dta[a/2]);
    if(2*a<=n) printf("left key = %d, ", dta[2*a]);
    if(2*a+1<=n) printf("right key = %d, ", dta[2*a+1]);
    
    printf("\n");
  }
  
  return 0;
}



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

int main() {
  int h, w, n;
  cin >> h >> w >> n;
  int big = h < w ? w : h;
  int ans = n%big == 0 ? n/big : n/big + 1;
  cout << ans << endl;
  return 0;
}

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

int main() {
    int a, b; cin >> a >> b;
    if (a == 1) a += 13;
    if (b == 1) b+= 13;

    if (a > b) cout << "Alice" << endl;
    else if (a == b) cout << "Draw" << endl;
    else cout << "Bob" << endl;
}


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

using namespace std;

using ll = long long;

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

int main() {
    ll a, b;
    cin >> a >> b;
    ll c = gcd(a, b);
    cout << a * b / c << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
R = [int(i) for i in input().split()]
S = set()
f = 0
for i in R:
    if i//400 < 8:
        S.add(i//400)
    else:
        f += 1

t = max(1,len(S)) 
mx = len(S)+f
print(t,mx)


Measured memory_bytes: 3060
#include <stdio.h>

int main(void){
  int H,W;
  int counter = 0;
  scanf("%d%d",&H,&W);
  int ans[4][H*W];

  int data[H][W];
  for(int i = 0;i < H;i++){
    for(int j = 0;j < W;j++){
      scanf("%d",&data[i][j]);
    }
  }


  for(int i = 0;i < H;i++){
    if(i%2 == 0){
      for(int j = 0;j < W;j++){
        if(i == H-1 && j == W-1){
          break;
        }
        if(data[i][j]%2 != 0){
          if(j == W-1){
            ans[0][counter] = i+1;
            ans[1][counter] = j+1;
            ans[2][counter] = i+2;
            ans[3][counter] = j+1;
            data[i+1][j]++;
            counter++;
          }else{
            ans[0][counter] = i+1;
            ans[1][counter] = j+1;
            ans[2][counter] = i+1;
            ans[3][counter] = j+2;
            data[i][j+1]++;
            counter++;
          }
        }
      }
    }else{
      for(int j = W-1;j >= 0;j--){
        if(i == H-1 && j==0){
          break;
        }
        if(data[i][j]%2 != 0){
          if(j == 0){
            ans[0][counter] = i+1;
            ans[1][counter] = j+1;
            ans[2][counter] = i+2;
            ans[3][counter] = j+1;
            data[i+1][j]++;
            counter++;
          }else{
            ans[0][counter] = i+1;
            ans[1][counter] = j+1;
            ans[2][counter] = i+1;
            ans[3][counter] = j+0;
            data[i][j-1]++;
            counter++;
          }
        }
      }
    }
  }

  printf("%d\n",counter);
  for(int i = 0;i < counter;i++){
    printf("%d %d %d %d\n",ans[0][i],ans[1][i],ans[2][i],ans[3][i]);
  }
  return 0;
}

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

int n;
ll k;
int a[200001];
int f[200001];

bool solve(ll x) {
  ll tmp = 0;
  for ( int i = 0; i < n; i++ ) {
    ll res = a[i] - x / f[i];
    if ( res < 0 ) { continue; }
    tmp += res;
  }
  if ( tmp <= k ) { return true; } else { return false; }
}

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

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

  sort(a, a+n);
  sort(f, f+n, greater<int>());

  ll l = 0;
  ll r = 1e18;

  for ( int i = 0; i < 150; i++ ) {
    ll m = (r + l) / 2;
    if ( solve(m) ) {
      r = m;
    } else {
      l = m;
    }
  }

  cout << r << endl;
  return 0;
}

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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)        //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++)   //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)      //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define RANGE(i,v) for(auto &(i):v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

template<typename T> using V = vector< T >;
using Vi = V<int>;
using Vll = V<LL>;
using Vs = V<string>;

int main(){
    int N;
    Vi b;
    cin>>N;
    if(N==0) cout<<0<<endl;

    while(N!=0){
        b.pb(((N%(-2))?1:0));
        if(N%(-2)!=0) N--;
        N/=(-2);
    }

    REP(i,b.size()){
        cout<<b[b.size()-i-1];
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
int main()
{
   int r, g, b;
   cin >> r >> g >> b;

   int num = 100 * r + 10 * g + b;
   if (num % 4 == 0)
   {
      cout << "YES" << endl;
   }
   else
   {
      cout << "NO" << endl;
   }
   return 0;
}


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

int main() {
    int W,H,x,y,r;
    cin>>W>>H>>x>>y>>r;
    if(r<=x && x<=W-r && r<=y && y<=H-r){
    cout<<"Yes"<<endl;	
    }else{
    cout<<"No"<<endl;	
    }
}

Measured memory_bytes: 3096