akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int N, Q;
vector< int > g[100000];
vector< int > query[100001];
int sz[100000];

int lca[100000];
bool buf[100000];

int sub(int idx)
{
  sz[idx] = query[idx].size();
  for(auto &to : g[idx]) sz[idx] += sub(to);
  return (sz[idx]);
}

void dfs(int idx, bool keep)
{
  if(g[idx].empty()) {
    if(keep) for(int &v : query[idx]) buf[v] = true;
    return;
  }

  int heavy = g[idx][0];
  for(auto &to : g[idx]) if(sz[to] > sz[heavy]) heavy = to;
  for(auto &to : g[idx]) if(heavy != to) dfs(to, false);
  dfs(heavy, true);
  query[idx].swap(query[heavy]);

  for(auto &to : g[idx]) {
    for(int &v : query[to]) {
      if(buf[v]++) lca[v] = idx;
      if(~lca[v]) continue;
      query[idx].push_back(v);
    }
  }

  if(!keep) {
    for(auto &v : query[idx]) buf[v] = false;
  }
}

int main()
{
  scanf("%d", &N);
  for(int i = 0; i < N; i++) {
    int K;
    scanf("%d", &K);
    while(K--) {
      int U;
      scanf("%d", &U);
      g[i].push_back(U);
    }
  }
  scanf("%d", &Q);

  memset(lca, -1, sizeof(lca));

  for(int i = 0; i < Q; i++) {
    int U, V;
    scanf("%d %d", &U, &V);
    if(U == V) {
      lca[i] = V;
    } else {
      query[U].push_back(i);
      query[V].push_back(i);
    }
  }

  sub(0);
  dfs(0, false);
  for(int i = 0; i < Q; i++) {
    printf("%d\n", lca[i]);
  }
}

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

int main(){
    string s;
    cin >> s;
    int ans1 = 0,ans2 = 0;
    for(int i = 0; i < s.size(); i++){
        if(i%2 == 0){
            if(s[i] != '1'){
                ans1++;
            }else{
                ans2++;
            }
        }else{
            if(s[i] != '0'){
                ans1++;
            }else{
                ans2++;
            }
        }
    }
    cout << min(ans1,ans2) << endl;
}


Measured memory_bytes: 512
#include <stdio.h>

int main(void){

    int N,M,i,a,b,c;
    scanf("%d %d",&N,&M);
    int Lmax=0,Rmin=N;
    for(i=0;i<M;i++){
        scanf("%d %d",&a,&b);
        if(Lmax<a) Lmax=a;
        if(Rmin>b) Rmin=b;
    }
    c=Rmin-Lmax+1;
    if(c<0) c=0;
    printf("%d\n",c);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pii;
typedef long long ll;
const long long MOD=1000000007;
#define rep(i,n) for(long long i=0;i<(n);i++)
#define rep2(i,m,n) for(long long i=(m);i<(n);i++)
#define ALL(v) v.begin(), v.end()
#define pb push_back







int main(){


    ll k;

    cin>>k;

    ll answer=-1;

    ll tmp=0;

    rep(i,k){
        tmp*=10;
        tmp+=7;
        tmp%=k;
        if (tmp==0){
            answer=i+1;
            break;

        }

    }

    cout<<answer<<endl;






}








            






Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include <algorithm>
#include <cassert>
#include <limits>
#include <numeric>
#include <type_traits>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <complex>
#include <climits>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll, ll> P;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)

ll gcd(ll a, ll b) {
  while (a && b) {
    if (a >= b) a %= b;
    else b %= a;
  }
  return a + b;
}
ll ketasum(ll n) { //桁の数字全ての和を返す 例: 112 -> 4
	ll sum=0;
	if (n<0) return 0;
	while (n>0) {
		sum += n%10;
		n /= 10;
	}
	return sum;
}

typedef pair<ll, ll> pair_t;

bool comp(const pair_t &a, const pair_t &b) {
        return a.first < b.first;
}

void sort2vectors(vector<ll> &av, vector<ll> &bv)
{ // ふたつの配列をまとめてそーと A[2,1] B[3,4] -> 1,4 2,3
        ll n = av.size();
        vector<pair_t> p(n);
        vector<ll> av2(n), bv2(n);
        for (ll i = 0; i < n; i++)
                p[i] = make_pair(av[i], bv[i]);
        sort(p.begin(), p.end(), comp);
        for (ll i = 0; i < n; i++) {
                av2[i] = p[i].first;
                bv2[i] = p[i].second;
        }
        av = av2;
        bv = bv2;
}
ll facctorialMethod(ll k){ //階乗
	ll s;
	if(k > 1){
		s = k*facctorialMethod(k-1);
	} else {
		s = 1;
	}
	return s;
}
vl primes(ll n){
	vl x(n);
	REP(i, n){
		x[i] = 0;
	}
	for(ll i = 2; i < sqrt(n) + 2; i++){
		while(n % i == 0){
			n /= i;
			x[i-1] += 1;
		}
	}
	if(n > 1){
		x[n-1] += 1;
	}
	return x;
}


void solve(){
	ll N;
	cin >> N;
	cout << pow(N, 3) << endl;
}


const ll mod = 1000000007;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
}


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

using namespace std;

int main() {
	int a, b, c, x, y, m;
	cin >> a >> b >> c >> x >> y;

	m = x>y ? (x-y)*a + 2*y*c : (y-x)*b + 2*x*c;
	if (m > x*a + y*b) m = x*a + y*b;
	if (m > 2*max(x, y)*c) m = 2 * max(x, y)*c;

	cout << m;
	char v;
	cin >> v;
	return 0;
}

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

typedef signed long long ll;
const int MX = 1e5 + 5;
const ll INF = 1e12 + 7;
ll dp[105][MX];
int w, n, W[MX], V[MX]; 

ll solve(int pos, int sum) {
	if(sum > w) return -INF;
	if(pos >= n) return 0;
	if(dp[pos][sum] != -1) return dp[pos][sum];
	return dp[pos][sum] = max(solve(pos + 1, sum), V[pos] + solve(pos + 1, sum + W[pos]));
}

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

	scanf("%d %d", &n, &w);
	for(int i = 0; i < n; scanf("%d %d", &W[i], &V[i]), i++);
	memset(dp, -1, sizeof(dp));
    printf("%lld\n", solve(0, 0));
    return 0;
}

Measured memory_bytes: 82304
#include<iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	for(int z=0;z<n;z++){
		int n2;
		cin>>n2;
		int a[200];
		for(int i=0;i<n2;i++){
			cin>>a[i];
		}
		int u=0,d=0;
		for(int i=0;i<n2-1;i++){
			if(u<a[i+1]-a[i])u=a[i+1]-a[i];
		}
		for(int i=1;i<n2;i++){
			if(d<a[i-1]-a[i])d=a[i-1]-a[i];
		}
		cout<<u<<" "<<d<<endl;
	}
}

Measured memory_bytes: 3064
//============================================================================
// Name        : d.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include<vector>
using namespace std;

int main() {
	int n;cin>>n;
	vector<int> a(n),b(n);
	vector<vector<pair<int,int>>> e(n);
	for(int i=0;i<n-1;i++){
		cin>>a[i]>>b[i];
		a[i]--;b[i]--;
		e[a[i]].push_back(make_pair(b[i],i));
		e[b[i]].push_back(make_pair(a[i],i));
	}
	int ansnum=0;
	for(int i=0;i<n;i++){
		ansnum=max(ansnum,int(e[i].size()));
	}
	vector<int> anse(n-1,-1);
	vector<int> c(n);

	vector<int> stack;
	stack.push_back(0);
	while(stack.size()){
		int tempnode=stack.back();
		stack.pop_back();
		int color=1;
		for(int i=0;i<e[tempnode].size();i++){
			int tempe=e[tempnode][i].second;
			if(anse[tempe]==-1){
				if(color==c[tempnode])color++;
				anse[tempe]=color;
				c[e[tempnode][i].first]=color;
				stack.push_back(e[tempnode][i].first);
				color++;
			}
		}
	}
	cout<<ansnum<<endl;
	for(int i=0;i<n-1;i++){
		cout<<anse[i]<<endl;
	}


	return 0;
}


Measured memory_bytes: 8064
#include <stdio.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    long sum=0;
    int a, n, i, min=0, max=0;
    scanf("%d", &n);
    for(i=0; i<n; i++){
        scanf("%d", &a);
        sum += a;
        if(i == 0){
            min = a;
            max = a;
        }
        
        if(min > a){
            min = a;
        }
        if(max < a){
            max = a;
        }
    }
    printf("%d %d %ld\n", min, max, sum);
    return 0;
}

Measured memory_bytes: 600
n = int(input())
a = list(map(int, input().split()))

def bubbleSort(A, N):
    cnt = 0
    flag = True
    while flag:
        flag = False
        for j in range(N-1, 0, -1):
            if a[j] < a[j-1]:
                a[j], a[j-1] = a[j-1], a[j]
                flag = True
                cnt += 1

    return cnt

res = bubbleSort(a, n)

print(' '.join(map(str, a)))
print(res)



Measured memory_bytes: 5600
#include <stdio.h>
int main (){
  int n,x[100],i,j,flag=0,tmp,cnt=0,min;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&x[i]);
  }
  for(i=0;i<n;i++){
    min=i;
    for(j=i;j<n;j++){
      if(x[j]<x[min]){
	min=j;
      }
    }
    if(i!=min){
      cnt++;
    }
    tmp=x[i];
    x[i]=x[min];
    x[min]=tmp;
  }
  for(i=0;i<n;i++){
    if(i){
      printf(" ");
    }
    printf("%d",x[i]);
  }
  printf("\n%d\n",cnt);
  return 0;
}



Measured memory_bytes: 2104
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

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

#define io ios_base::sync_with_stdio(false)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vll vector<long long>
#define pb push_back
#define mod 100000007
#define pii pair<int, int>
#define PI 2*acos(0.0)

int main()
{
    io;
    string s;
    cin>>s;
    int l = s.size()-1;
    if(s[l] == '2' || s[l] == '4' || s[l] == '5' || s[l] == '7' || s[l] == '9')
        cout<<"hon";
    else if(s[l] == '3')
        cout << "bon";
    else
        cout<<"pon";
    return 0;
}


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

using P = pair<long long, int>;

int main() {
    int n, k;
    cin >> n >> k;
    vector<vector<int>> a(n);
    for (int i = 0; i < n; i++) {
        int t, d;
        cin >> t >> d;
        a.at(t - 1).push_back(d);
    }
    for (int i = 0; i < n; i++) {
        sort(a.at(i).rbegin(), a.at(i).rend());
    }

    vector<long long> top_d, other;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < (int)a.at(i).size(); j++) {
            if (j == 0) top_d.push_back(a.at(i).at(j));
            else other.push_back(a.at(i).at(j));
        }
    }
    
    sort(top_d.rbegin(), top_d.rend());
    sort(other.rbegin(), other.rend());

    long long ans = 0;
    for (long long x = 0; x <= min(k, (int)top_d.size()); x++) {
        if ((int)other.size() < k - x) continue;
        
        long long sum = 0;
        for (int i = 0; i < x; i++) {
            sum += top_d.at(i);
        }
        for (int i = 0; i < k - x; i++) {
            sum += other.at(i);
        }

        ans = max(ans, sum + x * x);
    }
    cout << ans << endl;
}  

Measured memory_bytes: 6904
#include <stdio.h>
#define ll long long
ll gcd(ll x,ll y) {
    while(y) {
        ll t=x%y;
        x=y;
        y=t;
    }
    return x;
}

int main()
{
    ll a,b;
    scanf("%lld%lld",&a,&b);
    ll num = gcd(a,b);
    int count=1;
    for (ll i=2;i*i<=num;i++) {
        if (num%i==0) {
            count++;
            while(num%i==0) {
                num/=i;
            }
        }
    }
    printf("%d",count+(num!=1));
    return 0;
}

Measured memory_bytes: 1700
A, B, C, D = map(int, list(input()))

for i in range(1 << 3):
    op = [None] * 3
    a = A
    b = B if (i >> 0) & 1 else -B
    op[0] = '+' if (i >> 0) & 1 else '-'

    c = C if (i >> 1) & 1 else -C
    op[1] = '+' if (i >> 1) & 1 else '-'

    d = D if (i >> 2) & 1 else -D
    op[2] = '+' if (i >> 2) & 1 else '-'

    if sum([a, b, c, d]) == 7:
        break

print('{}{}{}{}{}{}{}=7'.format(A, op[0], B, op[1], C, op[2], D))


Measured memory_bytes: 3064
def op(sign, n, a):
    if sign * a[0] <= 0:
        count = abs(a[0]) + 1
        S = sign
    else:
        count = 0
        S = a[0]

    for i in a[1:]:
        if S * (S + i) > 0:
            count += abs(S + i) + 1
            S = -1 if S > 0 else 1
        elif S + i == 0:
            count += 1
            S = -1 if S > 0 else 1
        else:
            S += i

    return count


def main():
    n = int(input())
    a = list(map(int, input().split()))
    c1 = op(1, n, a)
    c2 = op(-1, n, a)
    print(min(c1, c2))


if __name__ == "__main__":
    main()


Measured memory_bytes: 14468
#include<stdio.h>
#include<string.h>
int main(void)
{
	int x[26]={0},i,j;
	char s[26];
	char al[26]={"abcdefghijklmnopqrstuvwxyz"};
	scanf("%s", s);
	for(i=0; i<strlen(s); i++)
	{
		for(j=0; j<26; j++)
		{
			if(s[i]==al[j])
			{
				x[j]++;
				break;
			}
		}
		if(x[j]>1)
		{
			printf("no\n");
			break;
		}
		if(i==strlen(s)-1)
		printf("yes\n");
	}
	
	return 0;
}

Measured memory_bytes: 128
n, m = map(int, input().split())


left = 0
right = float('inf')
for _ in range(m):
    l, r = map(int, input().split())
    left = max(left, l)
    right = min(right, r)

ans = 0
for i in range(1, n + 1):
    if left <= i <= right:
        ans += 1
print(ans)

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

int main(void){
    int i, j, k, n, ans = 0; cin >> n;
    for (i=0; i<n; i++) {
        for (j=0; j<n; j++) {
            for (k=0; k<n; k++) {
                ans += gcd(gcd(i+1, j+1), k+1);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>

using namespace std;

int main(){
  int X, A, B;
  cin >> X >> A >> B;
  if( B-A <= 0){
    cout << "delicious" << endl;
    return 0;
  }
  if (B-A <= X){
    cout << "safe" << endl;
    return 0;
  }

  cout << "dangerous" << endl;
  return 0;

}

Measured memory_bytes: 256
#include <stdio.h>
struct dice{
    int d[6], tmp[6];
};
struct dice dice1;
struct dice dice2;
struct dice dice3[110];
void copy1(int a){
    int i;
    for (i=0;i<6;i++){
        dice3[a].d[i]=dice2.d[i];
        dice3[a].tmp[i]=dice2.tmp[i];
    }
}
void copy2(int a){
    int i;
    for (i=0;i<6;i++){
        dice2.d[i]=dice3[a].d[i];
        dice2.tmp[i]=dice3[a].tmp[i];
    }
}
void init1(int n[6]){
    int i;
    for (i=0;i<6;i++){
        dice1.d[i]=n[i];
    }
}
void init2(int n[6]){
    int i;
    for (i=0;i<6;i++){
        dice2.d[i]=n[i];
    }
}
void throwdice(char c){
    int i;
    for(i=0;i<6;i++){
        dice1.tmp[i]=dice1.d[i];
    }
    if(c=='N'){
        dice1.d[0]=dice1.tmp[1];
        dice1.d[1]=dice1.tmp[5];
        dice1.d[2]=dice1.tmp[2];
        dice1.d[3]=dice1.tmp[3];
        dice1.d[4]=dice1.tmp[0];
        dice1.d[5]=dice1.tmp[4];
    }
    else if(c=='E'){
        dice1.d[0]=dice1.tmp[3];
        dice1.d[1]=dice1.tmp[1];
        dice1.d[2]=dice1.tmp[0];
        dice1.d[3]=dice1.tmp[5];
        dice1.d[4]=dice1.tmp[4];
        dice1.d[5]=dice1.tmp[2];
    }
    else if(c=='W'){
        dice1.d[0]=dice1.tmp[2];
        dice1.d[1]=dice1.tmp[1];
        dice1.d[2]=dice1.tmp[5];
        dice1.d[3]=dice1.tmp[0];
        dice1.d[4]=dice1.tmp[4];
        dice1.d[5]=dice1.tmp[3];
    }
    else if(c=='S'){
        dice1.d[0]=dice1.tmp[4];
        dice1.d[1]=dice1.tmp[0];
        dice1.d[2]=dice1.tmp[2];
        dice1.d[3]=dice1.tmp[3];
        dice1.d[4]=dice1.tmp[5];
        dice1.d[5]=dice1.tmp[1];
    }
    else if(c=='R'){
        dice1.d[0]=dice1.tmp[0];
        dice1.d[1]=dice1.tmp[3];
        dice1.d[2]=dice1.tmp[1];
        dice1.d[3]=dice1.tmp[4];
        dice1.d[4]=dice1.tmp[2];
        dice1.d[5]=dice1.tmp[5];
    }
}
int compare(){
    int i;
    for(i=0;i<6;i++){
        if(dice1.d[i]!=dice2.d[i]){
            return 0;
        }
    }
    return 1;
}
int main()
{
    int n[6];
    int m;
    int i,j,k,l;
    int ok=0;
    scanf("%d",&m);
    for(i=0;i<6;i++){
        scanf("%d",&n[i]);
    }
    init2(n);
    copy1(0);
    for(i=0;i<m-1;i++){
        for(j=0;j<6;j++){
            scanf("%d",&n[j]);
        }
        init1(n);
        for(j=0;j<i+1;j++){
            copy2(j);
            for(k=0;k<4;k++){
                for(l=0;l<4;l++){
                    throwdice('N');
                    throwdice('E');
                    throwdice('S');
                    if(compare()) ok=1;
                }
                throwdice('N');    
            }
            throwdice('E');
            for(k=0;k<2;k++){
                for(l=0;l<4;l++){
                    throwdice('N');
                    throwdice('E');
                    throwdice('S');
                    if(compare()) ok=1;
                }
                throwdice('W');    
                throwdice('W');    
            }
        }
        copy1(i+1);
    }
    if(!ok) puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 2096
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int main(int argc, char *argv[]){
  int N,L;
  cin>>N>>L;
  vector<int> vec(N+1);
  for(int i=0; i<=N; i++){
    vec[i]=i;
  }
  int allsum=0;
  for(int i=1; i<=N; i++){
    vec[i]=L+i-1;
    allsum+=vec[i];
  }
  int sum=0;
  int min=10000;
  int diff=0;
  int num;
  int ans;
  for(int i=1; i<=N; i++){
    sum=0;
    for(int j=1; j<=N; j++){
      if(j==i) continue;
      sum+=vec[j];
      
    }
    diff=(allsum)-(sum);
    diff=abs(diff);
    
    if(diff<min){ min=diff; num=i; ans=sum;}
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
//template<class T>void max(T a,T b){if(a<b)return b;else return a;}
//template<class T>void min(T a,T b){if(a>b)return b;else return a;}
//template<class T>bool Max(T&a, T b){if(a < b){a = b;return 1;}return 0;}
//template<class T>bool Min(T&a, T b){if(a > b){a = b;return 1;}return 0;}

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


ll cal(ll n,ll k){
    if(k==1)return 0;
    while(n>=k){
        if(n%k==0)n/=k;
        else n%=k;
    }
    return n;
}
int main(){fastio
    ll n;cin>>n;
    set<ll>se;
    for(ll i=1;i*i<=n-1;i++){
        if((n-1)%i==0){
            if(cal(n,i)==1)se.insert(i);
            if(cal(n,(n-1)/i)==1)se.insert((n-1)/i);
        }
    }
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            if(cal(n,i)==1)se.insert(i);
            if(cal(n,n/i)==1)se.insert(n/i);
        }
    }
    //for(auto x:se)cout<<x<<" ";cout<<endl;
    cout<<se.size()<<endl;
    return 0;
}



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

int main() {
  long n,ansa=0,ansb=0,x=0,y=0;
  cin >> n;
  vector<long> a(n),wa(n);
  for(long i=0;i<n;i++) cin >> a[i];
  wa[0]=a[0];
  for(long i=1;i<n;i++) wa[i]=wa[i-1]+a[i];
  for(long i=0;i<n;i++) {
    if(i%2==0) {
      if(wa[i]+x<=0) {
        ansa+=1-wa[i]-x;
        x+=1-wa[i]-x;
      }
      if(wa[i]+y>=0) {
        ansb+=1+wa[i]+y;
        y+=-1-wa[i]-y;
      }
    } else {
      if(wa[i]+x>=0) {
        ansa+=1+wa[i]+x;
        x+=-1-wa[i]-x;
      }
      if(wa[i]+y<=0) {
        ansb+=1-wa[i]-y;
        y+=1-wa[i]-y;
      }
    }
  }
  cout << min(ansa,ansb) << endl;
}

Measured memory_bytes: 4756
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

int A[10];
int n, m, q;
vector<int> a(55);
    vector<int> b(55);
    vector<int> c(55);
    vector<int> d(55);
int ans = 0;
void dfs(int i, int v) {
    A[i] = v;
    if (i==n-1) {
        bool ok = true;
        int sum = 0;
        rep(j, q) {
            if (A[b[j]]-A[a[j]]==c[j]) sum += d[j];
        }
        ans = max(ans, sum);
    }
    else {
        while (v<=m) {
            dfs(i+1, v);
            v++;
        }
    }
}


int main(){
    
    cin >> n >> m >> q;
    
    rep(i, q) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--;
        b[i]--;
    }
    
    dfs(0, 1);
   
    
    
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <cmath>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, q; cin >> n >> q;
    int sum;
    int a[100000] = {};
    int com, s, t;

    REP(i, q) {
        cin >> com >> s >> t;
        if (com) {
            sum = 0;
            for (int i = s; i <= t; i++) {
                sum += a[i];
            }
            cout << sum << endl;
        } else {
            a[s] += t;
        }
    }

    return 0;
}


Measured memory_bytes: 3568
#include <stdio.h>
int main(void){
	int a,b,k;
	scanf("%d %d %d",&a,&b,&k);
	int i;
	if( (b-a) > (2*k)-1){
		for(i=a;i<a+k;i++){
			printf("%d\n",i);
		}
		for(i=(b-k+1);i<=b;i++){
			printf("%d\n",i);
		}
	}
	else{
		for(i=a;i<=b;i++){
			printf("%d\n",i);
		}
	}
	return 0;
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-


def main():
    x, y, z, k = map(int, input().split())
    a = sorted(list(map(int, input().split())), reverse=True)
    b = sorted(list(map(int, input().split())), reverse=True)
    c = sorted(list(map(int, input().split())), reverse=True)
    ac = list()

    for ai in a:
        for ci in c:
            ac.append(ai + ci)

    count = min(x * z, k)
    acs = sorted(ac, reverse=True)[:count]
    ans = list()

    for bi in b:
        for ac_i in acs:
            ans.append(bi + ac_i)

    for j in sorted(ans, reverse=True)[:k]:
        print(j)


if __name__ == '__main__':
    main()


Measured memory_bytes: 152252
N,M = map(int,input().split())

buff = []
for m in range(M):
    lst = list(map(int,input().split()))
    k=lst.pop(0)
    ss=[s-1 for s in lst]
    buff.append((k,ss))

ps=list(map(int, input().split()))

pats = []
for (k,ss),p in zip(buff, ps):
    pats.append((k,ss,p))


base = int('1'*N,2)

format = '{:0' + str(N) + 'b}'

cnt = 0
for i in range(base+1):
    check_tar = [int(x) for x in format.format(i)]
    ress = []
    for k,ss,p in pats:
        res = sum([check_tar[s] for s in ss])%2 == p
        ress.append(res)
    #print(ress, all(ress), format.format(i))
    if all(ress):
        cnt+=1

print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <cstdio>
#include <chrono>
#include <random>
using namespace std;

#define DRACARYS ios_base::sync_with_stdio(false);cin.tie(NULL);cin.exceptions(cin.failbit);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define what_is(x) cerr << #x << " is " << x << endl;
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define PI 3.14159265
const long long int MAXN = 1e5+10;
const long long int MINN = 1e5+10;
const long long int inf = 1e9+10;

typedef long long ll; 
typedef long double ld; 
typedef pair<int, int> pii;
typedef vector<int> vi; 
typedef stack<int> st;

int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    DRACARYS
    int a[MAXN][3],dp[MAXN][3],n;
    cin>>n;
    repA(i,1,n){
        int x,y,z;
        cin>>x>>y>>z;
        a[i][0]=x,a[i][1]=y,a[i][2]=z;
    }
    dp[1][0]=a[1][0],dp[1][1]=a[1][1],dp[1][2]=a[1][2];
    repA(i,2,n){
        dp[i][0]=a[i][0]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=a[i][1]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=a[i][2]+max(dp[i-1][0],dp[i-1][1]);
    }
    cout<<max(dp[n][0],max(dp[n][1],dp[n][2]))<<endl;
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <cassert>
#include <random>
using namespace std;
using ll = long long;


int main() {
	int r, d, x; cin >> r >> d >> x;
	for (int i = 0; i < 10; i++) {
		x = r*x - d;
		cout << x << endl;
	}
	return 0;
}


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

int main(){
  while(true){
    int n,m;
    cin >> n >> m;

    if(n==0 && m==0)
      break;

    int a[1000];
    for(int i=0; i<n; i++){
      cin >> a[i];
    }
    int sum = -1;
    for(int i=0; i<n-1; i++){
      for(int j=i+1; j<n; j++){
        int p = a[i]+a[j];

        if(p<=m && p>sum){
          sum = p;
        }
      }
    }
    if(sum!=-1){
      cout<< sum << endl;
    }
    else{
      cout << "NONE" << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3096
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "a", long, "b");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    long n, k;
    scan(n, k);
    auto a = aryread();
    auto inversion = new long[](n);
    auto lower_than = new long[](n);
    foreach(i; iota(n))
    {
        foreach (j; iota(i))
            if(a[i] > a[j])
                lower_than[i]++;
        foreach(j; iota(i + 1, n))
            if(a[i] > a[j])
                inversion[i]++, lower_than[i]++;
    }
    auto ans = k * inversion.sum() % MOD;
    foreach (e; lower_than)
    {
        auto s = (k * (k - 1) / 2) % MOD;
        ans += (e * s) % MOD;
        ans %= MOD;
    }
    writeln(ans % MOD);
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 2300
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;
int main(){
    int D;
    cin >> D;
    vector<int> c(26);
    rep(i, 26) {
        cin >> c[i];
    }
    vector<vector<int>> s(D, vector<int>(26));
    rep(i, D)rep(j, 26) {
        cin >> s[i][j];
    }
    vector<int> t(D), d(26, -1);
    int max_day;
    rep(i, D) {
        max_day = 0;
        rep(j, 26) {
            if(d[j] != -1) {
                if(c[j]*(i-d[j]) > s[i][max_day]) {
                    max_day = j;
                }
            }
            else {
                if(s[i][j] > s[i][max_day]) {
                    max_day = j;
                }
            }
        }
        d[max_day] = i;
        t[i] = max_day+1;
    }
    rep(i, D) {
        cout << t[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3684
n, k = [int(i) for i in input().split()]
s = input()

a = s[:k-1]
c = s[k-1]
b = s[k:]

if c == 'A':
    print(a + 'a' + b)
elif c == 'B':
    print(a + 'b' + b)
else:
    print(a + 'c' + b)


Measured memory_bytes: 38384
a,b,n=map(int,input().split())
if n>=b-1:
    count=0
    for i in range(a):
        count+=(((b-1)/b)+(i/a))//1
    print(int(count))
else:
    count=0
    for j in range(a):
        count+=((n/b)+(j/a))//1
    print(int(count))
    

Measured memory_bytes: 67660
from itertools import permutations
from math import factorial

n = int(input())
xy = [list(map(int, input().split())) for i in range(n)]

root = list(permutations(xy,n))

ans = 0
for r in root:
    a = 0
    for i in range(n-1):
        a += ((r[i+1][0]-r[i][0])**2 + (r[i+1][1]-r[i][1])**2)**0.5
    ans += a
print(ans/factorial(n))


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

using namespace std;

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define show(x) cerr << #x << " " << x << endl

typedef long long ll;
typedef unsigned long long ull;

constexpr const int INT_INF=0x3f3f3f3f; // 1061109567
constexpr const ll LL_INF=0x3f3f3f3f3f3f3f3f; // 4557430888798830399

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

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

// INT
#define GCD(a, b) __gcd(a, b)
template <typename T> T LCM(T a, T b) {return a / GCD(a, b) * b;}
template <typename T> T EXTGCD(T a, T b, T& x, T& y) {
    T d = a;
    if (b != 0) {d=EXTGCD(b,a%b,y,x);y-=(a/b)*x;}
    else x=1,y=0;
    return d;
}
template <typename T> bool is_prime(T a) {
    for(int i=2;i*i<=a;i++)if(a%i==0)return 1;
    return 0;
}

// MOD
const ll MOD = 1000000000 + 7;
#define add(a, b) ((a % MOD) + (b % MOD)) % MOD
#define mul(a, b) ((a % MOD) * (b % MOD)) % MOD
#define sub(a, b) ((a % MOD) + MOD - (b % MOD)) % MOD
template <typename T> T mod_inverse(T a, T mod, bool prime){ // if mod is prime, "prime" is true.
    if(prime){
        T tmp=mod-2,now=a,res=1;while(tmp){if(tmp&1)res=mul(res,now);now=mul(now,now);tmp>>=1;}
        return res;
    }else{T x,y;EXTGCD(a,mod,x,y);return (mod+x%mod)%mod;}
}
#define divide(a, b) ((a % MOD) * (mod_inverse(b, MOD, true))) % MOD

//LLの数値をつかう時は最後にLをつける癖をつけよう
//
//  　　┓　　　┏
//  　＊┗┓　┏┛
//  　　　┫　┣　＊
//  　┏┳┻━┻┳┓
//  　┗┫　　　┣┛
//  ＊　┣　　━┃　＊        Merry Christmas!!
//  　┏┛　　〃┃
//  　┃●　　　┣━┳┓
//  　┗┻┳━━┛　┣┛
//  　＊　┃┏┓┣┓┃
//WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW

int n;
vector <pair <ll, int> > v;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    FILE *stream1;
    //FILE *stream2;
    stream1 = freopen("/Users/aim_cpo/CLionProjects/competitive/in.txt", "r", stdin);
    //stream2 = freopen("out.txt", "w", stdout);
    if (stream1 == nullptr) return 0;
    //if (stream2 == NULL) return 0;
#endif
    cin >> n;
    for (int i = 0; i < n; i++) {
        ll a; cin >> a;
        v.emplace_back(a, 0);
    }
    for (int i = 0; i < n; i++) {
        ll a; cin >> a;
        v.emplace_back(a, 1);
    }
    sort(all(v));
    ll a = 0L, b = 0L;
    ll res = 1L;
    for (int i = 0; i < (int)v.size(); i++) {
        if (v[i].se == 0 && b == 0) {
            a++;
        } else if (v[i].se == 0) {
            res = mul(res, b);
            b--;
        }
        if (v[i].se == 1 && a == 0) {
            b++;
        } else if (v[i].se == 1) {
            res = mul(res, a);
            a--;
        }
    }
    cout << res << endl;
#ifdef  LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
#endif
    return 0;
}

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

int main(void){
	int S;
	cin>>S;
	double L = (double)S;
	double length = L / 3; 
    L -= length; 
    double breadth = L / 2;
    double height = L - breadth; 
    cout<<fixed<<setprecision(17)<<(length*breadth*height);
    return 0;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 9e18
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){a=b; return true;} return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){a=b; return true;} return false; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill((T*)array, (T*)(array+N), val);}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

class debug
{
public:
    template<typename T> void vdeb(T vec);
    template<typename T1, typename T2> void adeb(T1 *arr, T2 n);
    template<typename T> void mdeb(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vdeb(T vec)
{
    cout << "#vector set debug" << endl;
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T1, typename T2> void debug::adeb(T1 *arr, T2 n)
{
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T> void debug::mdeb(T mp)
{
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
debug dbg;

class BExchange {
public:
	void solve(std::istream& in, std::ostream& out)
	{
	    ll a, b;
	    int k;
	    in >> a >> b >> k;

	    int cnt = 0;
	    while(cnt < k){
	        if(cnt % 2 == 0){
	            if(a % 2 == 1) a--;
	            b += a/2;
	            a /= 2;
	        }else{
	            if(b % 2 == 1) b--;
	            a += b/2;
	            b /= 2;
	        }
	        cnt++;
	    }

	    out << a sp b << endl;
	}
};


int main() {
	BExchange solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{ char a[3],A=10,B=11,C=12,D=13,E=14,F=15; 
  int i; 
 
       gets(a);
         for(i=0;i<3;i++) 
          {if(a[i]=='A')
	        a[i]=10;
	         if(a[i]=='B')
	          a[i]=11;
	         if(a[i]=='C')
	        a[i]=12;
	         if(a[i]=='E')
	        a[i]=14;
	         if(a[i]=='F')
	        a[i]=15;
	         if(a[i]=='D')
	        a[i]=13;}
	     if(a[0]>a[2])
       {printf(">\n");}
        
        else if(a[0]==a[2])
       {printf("=\n");}
        
    	 else if(a[0]<a[2])
       {printf("<\n");}
       	
    
} 

Measured memory_bytes: 128
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    from itertools import groupby
    G=groupby(input())
    print("Good" if(len(list(G))==4) else "Bad")
resolve()

Measured memory_bytes: 38384
class Kruskal():
    def __init__(self,n):
        self.e = []
        self.par = [i for i in range(n+1)]  #親のノード番号
        self.rank = [0]*(n+1)
    def add(self,u,v,d):  #クラスカル法で考えるのは無向グラフ
        self.e.append([u,v,d])
    def find(self,x):  #xの根のノード番号
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    def same_check(self,x,y):  #x,yが同じグループか否か
        return self.find(x) == self.find(y)
    def unite(self,x,y):  #x,yの属するグループの併合
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        elif self.rank[x] > self.rank[y]:
            self.par[y] = x
        else:
            self.par[y] = x
            self.rank[x] += 1
    def Kruskal(self):
        edges = sorted(self.e,key=lambda x: x[2])  #距離でソート
        a = 0
        for e in edges:
            if not self.same_check(e[0],e[1]):
                self.unite(e[0],e[1])
                a += e[2]
        return a

N = int(input())
A = [list(map(int,input().split())) for i in range(N)]

G = Kruskal(N)

X = []
Y = []
for i in range(N):
    X.append((A[i][0], i))
    Y.append((A[i][1], i))

X = sorted(X)
Y = sorted(Y)

# 辞書順で隣り合うものだけ考えれば良い

for i in range(N - 1):
    G.add(X[i][1], X[i + 1][1], X[i + 1][0] - X[i][0])
    G.add(Y[i][1], Y[i + 1][1], Y[i + 1][0] - Y[i][0])

print(G.Kruskal())

Measured memory_bytes: 139608
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  ll n;
  cin >> n;
  vector<ll> l(n);
  REP(i, n) cin >> l[i];
  ll ans = 0;
  REP(i, n){
    FOR(j, i+1, n){
      FOR(k, j+1, n){
        if(l[i] == l[j] || l[i] == l[k] || l[j] == l[k]) continue;
        if(l[i]+l[j] > l[k] && l[i]+l[k] > l[j] && l[j]+l[k] > l[i]) ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int x, y;
  cin >> x >> y;
  if (y >= x) {
    cout << "unsafe" << '\n';
  } else {
    cout << "safe" << '\n';
  }
  return 0;
}

Measured memory_bytes: 3612
import java.util.*

class Scanner(`in`: java.io.InputStream) {
    private val reader = java.io.BufferedReader(java.io.InputStreamReader(`in`))
    private var tokenizer: StringTokenizer? = null

    fun next(): String {
        if (tokenizer?.hasMoreTokens() != true) {
            tokenizer = StringTokenizer(reader.readLine())
        }
        return tokenizer!!.nextToken()
    }

    fun nextLine(): String {
        return if (tokenizer?.hasMoreTokens() != true) {
            reader.readLine()
        } else tokenizer!!.nextToken("\n")
    }
}

fun dprint(v: Any?, indent: Int = 0) {
    val indentStr = (1..indent).joinToString("") { " " }
    when (v) {
        is Iterable<*> -> {
            System.err.println("$indentStr[")
            v.forEach { dprint(it, indent + 1) }
            System.err.println("$indentStr]")
        }
        is Array<*> -> {
            System.err.println("$indentStr[")
            v.forEach { dprint(it, indent + 1) }
            System.err.println("$indentStr]")
        }
        is IntArray -> System.err.println(indentStr + "[" + v.joinToString(",") + "]")
        is LongArray -> System.err.println(indentStr + "[" + v.joinToString(",") + "]")
        is DoubleArray -> System.err.println(indentStr + "[" + v.joinToString(",") + "]")
        else -> System.err.println(indentStr + v)
    }
}

fun <A : Comparable<A>> min(a: A, b: A) = if (a < b) a else b
fun <A : Comparable<A>> min(vararg a: A) = a.reduce { acc, x -> min(acc, x) }
fun <A : Comparable<A>> max(a: A, b: A) = if (a > b) a else b
fun <A : Comparable<A>> max(vararg a: A) = a.reduce { acc, x -> max(acc, x) }

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

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

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

object Problem {
    fun solveMulti(sc: Scanner, pw: java.io.PrintWriter) {
        for (t in 1..sc.next().toInt()) {
            solve(sc, pw)
        }
    }

    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val N = sc.next().toInt()
        val A = IntArray(N) { sc.next().toInt() }
        val B = IntArray(N)
        for (i in N downTo 1) {
            var b = A[i - 1]
            var j = 2
            while (i * j - 1 < N) {
                b += B[i * j - 1]
                j++
            }
            B[i - 1] = b % 2
        }
        val ans = mutableListOf<Int>()
        for (i in 0 until N) {
            if (B[i] == 1) ans.add(i + 1)
        }
        pw.println(ans.count())
        if (ans.count() > 0) pw.println(ans.joinToString(" "))
    }
}


Measured memory_bytes: 51020
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <queue>
#include <iomanip>

using namespace std;
int N;
int a;
int ans=0;
int P[100005];

int main() {
  cin >> N;
  for (int i=0; i<N; i++) {
    cin >> a;
    P[a]++;
  }
  for (int i=0; i<=100000; i++) {
    ans = max(ans, P[i]+P[i+1]+P[i+2]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
import numpy as np

def judge_prime(num):
    FLAG = True
    
    # for i in range(2, int(np.sqrt(num))+1):
    for i in range(2, int(num**0.5)+1):

        if (num%i == 0):
            FLAG = False
    
    if (num == 2):
        FLAG = True
    
    return(FLAG)

X = int(input())

while (True):
    flag = judge_prime(X)
    
    if (flag):
        break
    
    X += 1

print(X)

Measured memory_bytes: 12504
n, m = map(int, input().split())
mod = 10 ** 9 + 7

s = [True for _ in range(n+1)]
for _ in range(m):
    s[int(input())] = False

dp = [0] * (n+1)
dp[0] = 1

for now in range(n+1):
    for nxt in range(now+1, min(n+1, now+3)):
        if s[nxt]:
            dp[nxt] += dp[now]
            dp[nxt] %= mod

print(dp[n])

Measured memory_bytes: 7864
#pragma GCC optimize("O3")
//#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx2")
#define io_init cin.tie(0);ios::sync_with_stdio(0);cout<<setprecision(10)
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//子の数が分かるUnionFind
struct UFT {
private:
	vector<int> par, rank;
	vector<int> c_n; //子の数
	void init(int n = 1) {
		par.resize(n); rank.resize(n); c_n.resize(n);
		for (int i = 0; i < n; i++)par[i] = i, rank[i] = 0, c_n[i] = 1;
	}
	void update(int x) {
		if (par[x] == x)return;
		else {
			int r = root(par[x]);
			c_n[par[x]] += c_n[x];
			par[x] = r;
			return;
		}
	}
	int root(int x) {
		if (par[x] == x)return x;
		else {
			int r = root(par[x]);
			return par[x] = r;
		}
	}
public:
	UFT(int n = 1) {
		init(n);
	}
	int weight(int x) {
		return c_n[root(x)];
	}
	bool issame(int x, int y) {
		return root(x) == root(y);
	}
	bool merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y)false;
		if (rank[x] < rank[y])swap(x, y);
		if (rank[x] == rank[y])rank[x]++;
		par[y] = x;
		update(y);
		return true;
	}
};

int main() {
    io_init;
	int N, M;
	cin >> N >> M;
	vector<int> A(N);
	for (int i = 0; i < N; i++)cin >> A[i];
	UFT uf(N);
	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		uf.merge(a, b);
	}
	int ans = 0;
	for (int i = 0; i < N; i++) {
		if(uf.issame(A[i]-1,i)) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 4680
import sys

def draw_line(chk, W):
    print(chk * int(W / 2) +(chk[0] if W % 2 else ''))
    
def draw(H, W):
    for i in range(H):
        draw_line(['#.', '.#'][i % 2], W)
    print()
    
for line in sys.stdin:
    H, W = map(int, line.split())
    if H == W == 0:
        break
    draw(H, W)

Measured memory_bytes: 6732
#include <iostream>

int main()
{

	int x, y, z;
	std::cin >> x >> y >> z;
	
	int counter1, counter2;

	if (x == 5)
	{
		counter1++;
	}
	else if (x == 7)
	{
		counter2++;
	}
	if (y == 5)
	{
		counter1++;
	}
	else if (y == 7)
	{
		counter2++;
	}
	if (z == 5)
	{
		counter1++;
	}
	else if (z == 7)
	{
		counter2++;
	}

	if (counter1 == 2 && counter2 == 1)
	{
		std::cout << "YES" << "\n";
	}
	else
	{
		std::cout << "NO" << "\n";
	}

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pi 3.141592653897932384626
//freopen("std.in","r",stdin);freopen("std.out","w",stdout);
using namespace std;
int main()
{
    long long n,a,b,sum,x,y;
    cin>>n;
    for(long i=0;i<n;i++){
        scanf("%lld%lld",&a,&b);
        x=min(a,b);
        y=sqrt(a*b);
        if(a==b){cout<<(a-1)*2<<endl;continue;}
        sum=(y-1)<<1;
        if(y*y==a*b)sum--;
        if(y*(y+1)<a*b)sum++;
        cout<<sum<<endl;
    }
    return 0;
}


Measured memory_bytes: 384
x,y=map(int,input().split())
s1 = [1,3,5,7,8,10,12]
s2 = [4,6,9,11]
s3 = [2]
if x in s1 and y in s1:
    print('Yes')
elif x in s2 and y in s2:
    print('Yes')
elif x in s3 and y in s3:
    print('Yes')
else:
    print('No')

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

int main() {
  int N,p=0,w=0,g=0,y=0;
  string Num ="Zero";
  cin >> N;
  
  for(int i =0; i<N; i++){
    string B;
    cin >> B;
    if(B=="P"){
      p=1;
    }
    else if(B=="W"){
      w=1;
    }
    else if(B=="G"){
      g=1;
    }
    else if(B=="Y"){
      y=1;
    }
  }
  if(p+w+g+y ==3){
    Num ="Three";
  }
  else if(p+w+g+y ==4){
    Num ="Four";
  }
  cout << Num << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main() {
  int n; cin >> n;
  int arr[n][2];
  for (int i = 0; i < n; i ++) cin >> arr[i][0] >> arr[i][1];
  bool f[n];
  for (int i = 0; i < n; i ++) f[i] = arr[i][0] == arr[i][1];
  for (int i = 0; i < n - 2; i ++) if (f[i] && f[i + 1] && f[i + 2]) {
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mod 1000000007
#define rep(i,n) for(int i=0; i<n; i++)
#define repa(i,start,end) for(int i=start; i<=end; i++)
#define repd(i,start,end) for(int i=start; i>=end; i--)
#define all(x) x.begin(),x.end()
void solve() {
    float d, t, s;
    cin >> d >> t >> s;
    if ((d/s)<= t)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);      
    solve();
  
}

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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

template <typename T>
class BIT {
    int sz;
    

public:
    std::vector<T> node;
    BIT(int sz): sz(sz+1), node(std::vector<T>(sz+1, 0)) {}

    void add(int idx, T val) {
        ++idx;
        assert(0 < idx && idx < sz);
        while(idx < sz) {
            node[idx] += val;
            node[idx] %= MOD;
            idx += idx & -idx;
        }
    }

    T sum(int idx) {
        ++idx;
        assert(0 < idx && idx < sz);
        T res = 0;
        while(idx > 0) {
            res += node[idx];
            res %= MOD;
            idx -= idx & -idx;
        }
        return res;
    }
};

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

  int n, K; cin >> n >> K;
  vi a(n);
  for(int i=0;i<n;++i) {
    cin >> a[i];
  }

  BIT<ll> bit(K+1);
  bit.add(K, 1);
  //cout << sz << endl;

  for(int i=0;i<n;++i) {
    //printv(bit.node);
    for(int j=0;j<K;++j) {
      int l = j, r = j + a[i];
      l = max(0, l);
      r = min(K, r);
      ll tmp = bit.sum(r) + MOD - bit.sum(l);
      //cout << l << ":" << r << ":" << tmp << endl;
      bit.add(j, tmp % MOD);
    }
  }
  
  //printv(bit.node);

  cout << bit.sum(0) << endl;


}


Measured memory_bytes: 1024
//kruskal tree
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
#define M 9999
int parent[M],a[M],b[M];
pair<double,int>node[M];
int root(int a){return parent[a]==a?a:parent[a]=root(parent[a]);}
int unite(int a,int b){
	int x=root(a),y=root(b);
	if(x==y)return 0;
	parent[x]=y;
	return 1;
}
int main(){
	int i,j,k,m,n;
	double x,y,z,r;
	for(;cin>>n,n;){
		vector<vector<double> >v;
		for(i=0;i<n;i++)cin>>x>>y>>z>>r,v.push_back({x,y,z,r});
		for(i=0;i<n;i++)parent[i]=i;
		for(m=i=0;i<n;i++)for(j=i+1;j<n;j++){
			for(x=k=0;k<3;k++)x+=(v[i][k]-v[j][k])*(v[i][k]-v[j][k]);
			x=sqrt(x)-v[i][3]-v[j][3];
			if(x<0)x=0;
			a[m]=i,b[m]=j,node[m].first=x,node[m++].second=m;
		}
		sort(node,node+m);
		for(x=i=0;i<m;i++)if(unite(a[node[i].second],b[node[i].second]))x+=node[i].first;
		cout<<fixed<<setprecision(3)<<x<<endl;
	}
}

Measured memory_bytes: 1508