akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace mondai0056
{
	class Program
	{
		static void Main(string[] args)
		{
			var	prime	= new List<int>();
			for( int i = 2; i <= 50000; i++ ) {
				if( is_prime( i ) ) {
					prime.Add( i );
				}
			}

			var	cnt_tbl	= new int[ 50001 ];
			for( int i = 0; i < prime.Count; i++ ) {
				for( int j = i; j < prime.Count; j++ ) {
					var	idx	= prime[ i ] + prime[ j ];
					if( idx <= 50000 ) {
						cnt_tbl[ idx ]++;
					}
				}
			}

			int	n	= 0;
			while( (n = int.Parse( Console.ReadLine() )) != 0 ) {
				Console.WriteLine( cnt_tbl[ n ] );
			}
		}

		
		// 素数判定
		static bool is_prime( int n )
		{
			if( n <= 1 ) {
				return( false );
			} else if( n <= 3 ) {
				return( true );
			} else if( (n % 2) == 0 ) {
				return( false );
			} else {
				for( int i = 3; i <= (int)Math.Sqrt( n ); i += 2 ) {
					if( (n % i) == 0 ) {
						return( false );
					}
				}
			}
			return( true );
		}
	}
}

Measured memory_bytes: 6172
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

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

#define INF 1000000000

int main(){
  int n;
  while(cin>>n, n){
    vector<bitset<100> > mt(n);
    // mt[i][j] i is known by j
    // bitset is initialized by 0:false

    // input
    rep(i,n){
      int m;
      scanf("%d", &m);
      rep(j,m){
	int p;
	scanf("%d",&p);
	p--;
	mt[p][i] = true;
      }
    }

    // leak calculation
    bitset<100> ans;
    int k;
    scanf("%d", &k);
    rep(i,k){
      int l;
      scanf("%d", &l);
      l--;
      if(i==0) ans = mt[l];
      else ans &= mt[l];
    }

    //detect
    int res=0;
    rep(i,n){
      if(ans[i]){
	if(res==0) res=i+1;
	else res=-1;
      }
    }

    // out
    if(res>0) cout<<res<<endl;
    else cout<<-1<<endl;

  }
  return 0;
}

Measured memory_bytes: 1244
//57
#include<iostream>
#include<cstdlib>

using namespace std;

int main(){
  int n,m;
  cin>>n>>m;
  int d[100000]={};
  for(int i=1;i<n;i++){
    cin>>d[i];
    d[i]+=d[i-1];
  }
  int p=0;
  int s=0;
  while(m--){
    int a;
    cin>>a;
    s=(s+abs(d[p]-d[p+a]))%100000;
    p+=a;
  }
  cout<<s<<endl;
  return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair <ll,ll> P;
#define REP(i, n) for(ll i = 0LL; i < (ll)(n); i++)
#define REPR(i, n) for(ll i = n-1; i > 0LL; i--)
#define FOR(i, n, m) for(ll i = n; i < (ll)(m); i++)
#define PRINT(x) cout << x << endl
#define ALL(v) v.begin(), v.end()
#define INF (ll)1e18
#define PI 3.14159265358979

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

ll MOD = 1000000007;


const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main()
{
    ll R;
    cin >> R;
    PRINT(setprecision(20) << 2*R*PI);
    return 0;
}


Measured memory_bytes: 3816
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <cassert>
#include <bitset>

using namespace std;

using int64 = long long;

/////////////////////
// Code starts here//
/////////////////////


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

    int A, B;
    cin >> A >> B;

    for (int i = 1; i <= 2000; i++) {
        if (i * 8 / 100 == A && i / 10 == B) {
            cout << i << "\n";
            return 0;
        }
    }

    cout << -1 << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
 
using namespace std;
 
 
struct AB {
    int a;
    int b;
    
    bool operator<( const AB& right ) const {
        return a == right.a ? a < right.a : b < right.b;
    }
};
 
 
int main()
{
    int N, M;
    cin >> N >> M;
    
    vector<AB> ab(M);
    for( int i = 0; i < M; ++i ){
        int tmpa, tmpb;
        cin >> tmpa >> tmpb;
        ab[i].a = tmpa;
        ab[i].b = tmpb;;
        if( ab[i].b < ab[i].a )
            swap(ab[i].a, ab[i].b);
    }
    
    sort(ab.begin(), ab.end());
    
    /*
    for( auto itr = ab.begin(); itr != ab.end()-1; ++itr ){
        if( itr->a == (itr+1)->a && itr->b == (itr+1)->b ){
            ab.erase(itr+1);
            --itr;
        }
    }
    */
    
    
    vector<int> ans(N, 0);
    for( auto itr = ab.begin(); itr != ab.end(); ++itr ){
        ++ans[itr->a-1];
        ++ans[itr->b-1];
    }
    
    
    for( int i = 0; i < N; ++i ){
        cout << ans[i] << endl;
    }
    
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _LIBCPP_DEBUG 0
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;
int INF = 1 << 30;
    
int main(void){

    int N,M; cin>>N>>M;
    vector<int> A(M,0);
    ll sum=0;
    for (int i = 0; i < M; ++i) {
        cin>>A[i];
        sum+=A[i];
    }
    if(sum > N){
        cout<<-1<<endl;
    }else{
        cout<<N-sum<<endl;
    }

}

Measured memory_bytes: 3672
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>

int test(std::size_t p, std::size_t k, const std::vector<std::size_t>& nums)
{
    std::size_t buf = p;
    std::size_t cnt = 1;
    for (std::size_t i = 0; i < nums.size(); ++i) {
        if (nums[i] <= buf) {
            buf -= nums[i];
        } else {
            buf = p;
            buf -= nums[i];
            cnt++;
        }
    }

    return (k - cnt);
}

int main()
{
    std::size_t n, k;
    std::cin >> n >> k;

    std::size_t pmin = 0;
    std::vector<std::size_t> nums;
    std::size_t maxPair = std::ceil((double)n/k);

    nums.reserve(n);
    for (std::size_t i = 0; i < n; ++i) {
        std::size_t w;
        std::cin >> w;
        if (pmin < w) {
            pmin = w;
        }
        nums.push_back(w);
    }

    std::size_t pmax = 0;
    for (std::size_t i = 0; i <= n - maxPair; ++i) {
        std::size_t sum = 0;
        for (std::size_t j = i; j < i + maxPair; ++j) {
            sum += nums[j];
        }
        if (pmax < sum) {
            pmax = sum;
        }
    }

    while (true) {
        if (pmin == pmax) {
            std::cout << pmin << std::endl;
            break;
        } else if ((pmin + 1) == pmax) {
            int ret = test(pmin, k, nums);
            if (ret >= 0) {
                std::cout << pmin << std::endl;
                break;
            } else {
                std::cout << pmax << std::endl;
                break;
            }
        }
        std::size_t ptest = (pmin + pmax) / 2;
        int ret = test(ptest, k, nums);
        if (ret < 0) {
            pmin = ptest;
        } else {
            pmax = ptest;
        }
    }

    return 0;
}


Measured memory_bytes: 3640
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int dig(LL a){
	int c=0;
	while(a>0){
		c++;
		a/=10;
	}
	return c;
}

int main(){
	LL digit=0,nw=1;
	FOR(i,0,11){
		cout<<"? "<<nw<<endl;
		string s;
		cin>>s;
		if(s=="N"){
			digit=i;
			break;
		}
		nw*=10;
	}
	if(digit==0){
		nw=2;
		FOR(i,0,11){
			cout<<"? "<<nw<<endl;
			string s;
			cin>>s;
			if(s=="Y"){
				digit=i+1;
				nw/=2;
				cout<<"! "<<nw<<endl;
				return 0;
			}
			nw*=10;
		}
	}

	LL l=1,r=10,m=(l+r)/2;
	FOR(i,1,digit){
		l*=10;r*=10;
	}
	m=(l+r)/2;
	FOR(i,0,64){
		if(l==m){
			cout<<"! "<<m+1<<endl;
			return 0;
		}
		string q=to_string(m)+"0";
		cout<<"? "<<q<<endl;
		string s;
		cin>>s;
		if(s=="N"){
			l=m;
		}else{
			r=m;
		}
		m=(r+l)/2;
	}
	cout<<"! "<<m<<endl;

    return 0;
}


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

typedef long long ll;

int main() {
  ll n,p,q;
  cin >> n >> p >> q;
  ll c[n],x=0,y=0;
  for(ll i=0; i<n; i++) {
    cin >> c[i];
    c[i]+=i*p;
    x+=c[i];
    y+=i*p;
  }
  sort(c,c+n);
  ll ans=x-y;
  for(ll i=0; i<n; i++) {
    x-=c[i];
    x+=(i*2LL+q)*p;
    ans=max(ans,x-y);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5076
N=int(input())
p=10**9+7

def primeryNum(n):
    n_=int(n**0.5)
    ary=list(range(n+1))
    ary[1]=0 
    for a in ary:
        if a>n_: break
        elif a==0: continue
        
        for i in range(a*2,n+1,a):
            ary[i]=0           
    return ary

primeryN=primeryNum(N)

divN=[0]*(N+1)
for pn in primeryN:
    if pn==0:
        continue
    # print(pn)
    i=1
    cnt=0
    while (pn**i<=N):
        cnt+=(N//pn**i)
        i+=1
    divN[pn]=cnt

# print(divN)
ans=1
for d in divN:
    if d==0:
        continue
    ans=(ans*(d+1))%p
print(ans)

Measured memory_bytes: 9428
<?php
  list($x,$k,$d) = explode(" ", trim(fgets(STDIN)));

  if($x >= 0 && $k*$d <= $x){
    echo $x - $k*$d;
  }else if($x >= 0 && $k*$d > $x){
    $p = intdiv($x+$d-1,$d);
    $r=$k-$p;
    if($r%2==0){
      echo abs($x-$d*$p);
    }else{
      echo abs($x-$d*$p+$d);
    }
  }else if($x < 0 && $k*$d <= abs($x)){
    echo abs($x+$k*$d);
  }else{
    $p = intdiv(abs($x)+$d-1,$d);
    $r=$k-$p;
    if($r%2==0){
      echo abs($x+$d*$p);
    }else{
      echo abs($x+$d*$p-$d);
    }
  }

Measured memory_bytes: 16176
f::Integer->Integer->Integer->Integer->Integer
f _ _ 0 ans=ans
f _ 0 _ ans=ans
f 1 w h ans
    |h<w=f 2 w h ans
    |h `mod` w==0 =let d=(h `div` w)*w*2
                   in f 0 0 0 (ans+d-w)
    |otherwise=let d=(h `div` w)
               in f 1 w (h-d*w) (ans+d*w+(d-1)*w+w)
f 2 w h ans
   |w<h=f 1 w h ans
   |w `mod` h==0=let d=(w `div` h)*h*2
                 in f 0 0 0 (ans+d-h)
   |otherwise=let d=(w `div` h)
              in f 2 (w-d*h) h (ans+d*h+(d-1)*h+h)

main = do
       e1<-getLine
       let (n:x:[])=map read (words e1)::[Integer]
       print $ f 1 x (n-x) n

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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    vector<pair<uint64_t, int64_t>> nums(n);
    int64_t ans = 0;
    for (auto i : irange(0L, n)) {
        cin >> nums[i].first >> nums[i].second;

        if ((nums[i].first & k) == nums[i].first) {
            ans += nums[i].second;
        }
    }

    for (auto i : irange(0L, 30L)) {
        if ((k & (1uL << i)) == 0) {
            continue;
        }
        auto l = ((k & ~(1uL << i)) | ((1uL << i) - 1));

        int64_t t = 0;
        for (auto j : irange(0L, n)) {
            if ((nums[j].first & l) == nums[j].first) {
                t += nums[j].second;
            }
        }

        ans = max(ans, t);
    }

    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n) for(ll i=0;i<(n);++i)
#define REPR(i,n) for(ll i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    ll n; cin>>n;
    ll cnt[10][10];
    memset(cnt,0,sizeof(cnt));

    for (int i = 1; i <= n; ++i) {
        string s = to_string(i);
        cnt[s.front()-'0'][s.back()-'0']++;
    }

    ll ans = 0;
    for (int i = 1; i <= n; ++i) {
        string s = to_string(i);
        ans += cnt[s.back()-'0'][s.front()-'0'];
    }

    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    cin>>n>>k;
    int ans=1;
    rep(i,n){
        if(ans*2>ans+k){
            ans+=k;
        }
        else{
            ans*=2;
        }
    }
    cout<<ans<<"\n";
}


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

using namespace std;

const int MOD=1'000'000'007;

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(){
    long N, K;
    cin>>N>>K;
    vector<long> A(N);
    for(int i=0; i<N; ++i){
        cin>>A[i];
    }

    vector<long> xCk(N); // xCk[0] == 0C(K-1)
    long k=0;
    while(k<K-1){
        xCk[k] = 0;
        k++;
    }
    xCk[k] = 1; // k == K-1 => xCk[K-1] == (K-1)C(K-1) == 1
    /*
    long bunbo = 1;
    for(int i=1; i<=K-1; ++i){
        bunbo *= i;
        bunbo %= MOD;
    }
    */
    for(int i=K; i<N; ++i){
        // iCK-1
        /*
        xCk[i] = 1;
        for(int j=0; j<K-1; ++j){
            xCk[i] *= (i-j);
            xCk[i] %= MOD;
        }
        */
        xCk[i] = xCk[i-1] * i;
        xCk[i] %= MOD;
        xCk[i] *= modinv(i-K+1, MOD);
        xCk[i] %= MOD;
    }

    sort(A.begin(), A.end());
    long ans = 0;
    long tmp = 0;
    for(int i=0; i<N; ++i){
        //cout<<A[i]<<" "<<i<<" "<<xCk[i]<<endl;
        tmp = A[i]; // * i;
        tmp %= MOD;
        if(xCk[i] > 0){
            tmp *= xCk[i];
            tmp %= MOD;

            ans += tmp;
            ans %= MOD;
        }
        //cout<<ans<<endl;

        //cout<<A[i]<<" "<<(N-i-1)<<" "<<xCk[N-i-1]<<endl;
        tmp = A[i]; // * (N-i-1);
        tmp %= MOD;
        if(xCk[N-i-1] > 0){
            tmp *= xCk[N-i-1];
            tmp %= MOD;

            ans += MOD;
            ans -= tmp;
            ans %= MOD;
        }
        //cout<<ans<<endl;
    }
    cout<<ans<<endl;

    return 0;
}


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define ALL(name) name.begin(),name.end()
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

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

    int N;
    vector<int> V;
    cin >> N;
    V.resize(N);
    REP(i, N) {
        cin >> V[i];
    }

    // key: 数, val: 出現数
    map<int, int> even, odd;
    REP(i, N) {
        if(i % 2 == 0) {
            even[V[i]]++;
        }
        else {
            odd[V[i]]++;
        }
    }

    vector< pair<int, int> > v_even, v_odd;


    for(auto& tmp : even) {
        v_even.push_back(make_pair(tmp.second, tmp.first));
    }
    v_even.push_back(make_pair(0, -1));
    for(auto& tmp : odd) {
        v_odd.push_back(make_pair(tmp.second, tmp.first));
    }
    v_odd.push_back(make_pair(0, -1));
    SORT(v_even);
    reverse(v_even.begin(), v_even.end());
    SORT(v_odd);
    reverse(v_odd.begin(), v_odd.end());

    int ans = N;

    int i_n = v_even.size();
    if(i_n > 10) { i_n = 10;}
    int j_n = v_odd.size();
    if(j_n > 10) { j_n = 10;}
    for(int i = 0; i < i_n; ++i) {
        for(int j = 0; j < j_n; ++j) {
            if(v_even[i].second != v_odd[j].second) {
                ans = min(ans, N - v_even[i].first - v_odd[j].first);
            }
        }
    }

    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 9592
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,y,k;
    for ( ; ; )
    {
        scanf("%d %d",&x,&y);
        if (x == 0 && y == 0)
        {
            break;
        }
        if (x > y)
        {
            k = y, y = x, x = k;
        }
        printf("%d %d\n",x,y);
    }
    return 0;
}



Measured memory_bytes: 3116
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    ll t1, t2, a1, a2, b1, b2, c1 = 0, c2 = 0, z = 0;
    cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
    if (t1 * a1 + t2 * a2 == t1 * b1 + t2 * b2) {
        cout << "infinity";
        return 0;
    }
    ll x = 0, y = 0;
    bool l = 0;
    for (int i = 1; i <= 200; i++) {
        c1 += t1 * a1;
        c2 += t1 * b1;
        //cout << c1 - c2 << '\n';
        if (!x) x = c1 - c2;
        int k;
        if (c1 - c2 < 0) k = 1;
        else k = 0;
        if ((i > 1 && k != l) || c1 == c2) z++;
        l = k;
        c1 += t2 * a2;
        c2 += t2 * b2;
        //cout << c1 - c2 << '\n';
        if (!y) y = c1 - c2;
        if (c1 - c2 < 0) k = 1;
        else k = 0;
        if (k != l || c1 == c2) z++;
        l = k;
        //break;
    }
    //cout << z << '\n';
    //cout << x << ' ' << y << ' ';
    if ((x > 0 && y > 0) || (x < 0 && y < 0)) cout << 0;
    else {
        if (abs(x) % abs(y) == 0) cout << abs(x) / abs(y) * 2;
        else cout << abs(x) / abs(y) * 2 + 1;
    }
}


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

#define ll long long int

ll arr[3*111123];
int main() {
    ll n;
    scanf("%lld",&n);
    for (int i = 0; i < 3* n; i++) {
        scanf("%lld",&arr[i]);
    }
    sort(arr,arr+3*n,greater<ll>());
    ll ans = 0;
    int cnt = 0;
    for (int i = 0; i < 3* n; i++) {
        if (i % 2 != 0) {
            ans += arr[i];
          //  cout << arr[i] << " ";
            cnt++;
            if (cnt == n)break;
        }
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 2560
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n, m = map(int, input().split())
G = [[] for _ in range(n)]
for i in range(m):
  a, b = map(int, input().split())
  a -= 1
  b -= 1
  G[a].append(b)
seen = [False]*n
def dfs(v):
  seen[v] = True
  for nv in G[v]:
    nxt[v] = nv
    if seen[nv]:
      return nv
    s = dfs(nv)
    if s != -1:
      return s
  seen[v] = False
  return -1
for i in range(n):
  nxt = [-1]*n
  s = dfs(i)
  if s != -1:
    break
else:
  print(-1)
  exit()
while True:
  used = set()
  L = []
  while s not in used:
    used.add(s)
    L.append(s)
    s = nxt[s]
  L.append(s)
  for i in range(len(L)-1):
    a, b = L[i], L[i+1]
    for nv in G[a]:
      if nv != b and nv in used:
        nxt[a] = nv
        s = a
        break
    else:
      continue
    break
  else:
    print(len(used))
    for v in used:
      print(v+1)
    break

Measured memory_bytes: 9868
#include <iostream>
#include<list>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<set>
#include<map>
#include<bitset>
using namespace std;

int main()
{

    int n;
    cin>>n;
    vector<int> s[n];
    bitset<64> b(0);
    for(int i=0;i<n;i++){
        int temp,temp1;
        cin>>temp;
        while(temp--){
            cin>>temp1;
            s[i].push_back(temp1);
        }
    }
    int q;cin>>q;
    int tp1,i,ok;
    while(q--){
        cin>>tp1;
        switch(tp1){
        case 0:
            cin>>i;
            cout<<b.test(i)<<"\n";
            break;
        case 1:
            cin>>i;
            for(int j=0;j<s[i].size();j++)
            b.set(s[i][j],1);
            break;
        case 2:
            cin>>i;
            for(int j=0;j<s[i].size();j++)
            b.set(s[i][j],0);
            break;
        case 3:
            cin>>i;
            for(int j=0;j<s[i].size();j++)
            b.flip(s[i][j]);
            break;
        case 4:
            cin>>i;
             ok=1;
            for(int j=0;j<s[i].size();j++)
            if(b.test(s[i][j])==0){
                ok=0;break;
            }
            if(ok)cout<<"1\n";
            else cout<<"0\n";
            break;
        case 5:
            cin>>i;
             ok=0;
            for(int j=0;j<s[i].size();j++)
            if(b.test(s[i][j])){
                cout<<"1\n";
                ok=1;
                break;
            }
            if(ok==0)cout<<"0\n";
            break;
        case 6:
            cin>>i;
             ok=1;
            for(int j=0;j<s[i].size();j++)
            if(b.test(s[i][j])){
                ok=0;break;
            }
            if(ok)cout<<"1\n";
            else cout<<"0\n";
            break;
        case 7:
            cin>>i;
             ok=0;
            for(int j=0;j<s[i].size();j++)
            if(b.test(s[i][j])){
                ok++;
            }
            cout<<ok<<"\n";
            break;
        case 8:
            bitset<64> c(0);
            cin>>i;
            for(int j=0;j<s[i].size();j++)
            if(b.test(s[i][j])){
                c.set(s[i][j]);
            }
            cout<<c.to_ulong()<<"\n";
            break;
         }
    }
}





Measured memory_bytes: 3140
#include <iostream>
#include <string>
#include <vector>
#include <stdlib.h>

using namespace std;

bool connected(const string &s) {
	if (s.length() <= 1)
		return false;

	size_t i = 0;
	char last = s[i];
	for (i++; i < s.length(); i++) {
		char c = s[i];
		if (c != last) {
			return true;
		} else {
			last = c;
		}
	}

	return false;
}

void solve() {
	string S;
	cin	>> S;

	cout << (connected(S) ? "Yes" : "No") << endl;
}

int main() {	
	solve();
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    char S[10];
    char T[10];
    int count=0;
    int i;
    scanf("%s",S);
    scanf("%s",T);

    for(i=0; i<3; i++){
        if(S[i] == T[i]){
            count++;
        }
    }
    
    printf("%d\n",count);
}

Measured memory_bytes: 128
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-04-04 20:21:30
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 1728
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

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

  int n, m; cin >> n >> m;
  vector<int> a(n); cin >> a;

  int sum = accumulate(all(a), int());

  int ans = 0;

  for (int i = 0; i < n; ++i) {
    ans += (a[i] * 4 * m >= sum);
  }

  if (ans >= m) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int mod = 1e9+7;
LL dp[2005][2005];
int main(){
    int n, k;
    scanf("%d%d", &n, &k);
    dp[n+1][0] = 1;
    for(int i=n;i>=2;i--){
        for(int j=n;j>=0;j--){
            dp[i][j] = (dp[i][j] + dp[i+1][j])%mod;
            dp[i][j] = (dp[i][j] + dp[i][j+1])%mod;
            dp[i][j+1] = (dp[i][j+1] + dp[i+1][j])%mod;
        }
    }
    int ans = dp[2][n-k];
    for(int i=1;i<=n-k-1;i++) ans = ans*2%mod;
    printf("%d\n", ans);
}

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

#define forn(i, n) for (int i = 0; i < (int)n; ++i)
#define for1(i, n) for (int i = 1; i <= (int)n; ++i)
#define fore(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

typedef long long i64;
typedef vector<int> vi;
typedef vector<i64> vi64;
typedef vector<vi> vvi;
typedef vector<vi64> vvi64;
typedef double ld;

#define MOD 1000000007

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

    int n, m;
    cin >> n >> m;
    vi64 x(n), y(m);
    forn(i, n) cin >> x[i];
    forn(i, m) cin >> y[i];

    i64 sx = 0;
    forn(i, n) {
        sx += x[i] * (i64)(i * 2 - n + 1);
        sx %= MOD;
    }   
    i64 sy = 0;
    forn(i, m) {
        sy += y[i] * (i64)(i * 2 - m + 1);
        sy %= MOD;
    }   

    i64 ans = (sx * sy) % MOD;

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

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i = (ll)(a); i < (ll)(b); 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; }
const ll INF = 1LL << 60;
ll p[200010];
int main(){
    ll N,K; cin >> N >> K;
    rep(i,N){cin >> p[i];}

    ll tmpmax = -INF;
    ll tmp = 0;
    ll a = p[0];
    ll b = p[K-1];

    rep(i,K){
        tmp+=p[i];
    }
    tmpmax = tmp;

    for(ll i=0; i < N-K; i++){
        tmp -=a;
        a = p[i+1];
        b = p[i+K];
        tmp += b;
        if (tmp > tmpmax){
            tmpmax = tmp;
        }
    }
    
    double result = (tmpmax+K) / 2.0;


    cout << setprecision(10)<< fixed << result << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  return 0;
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
const int yuzu=1e5;
#define chu(a,b) ((a)+(b)-1)/(b)
typedef ll fuko[yuzu|10];
ll n=read(),a=read(),b=read();
fuko h;

int judge(ll times){
ll i,k=0;
for (i=1;i<=n;++i){
  if (h[i]>b*times){
    ll now=h[i]-b*times;
    k+=chu(now,a-b);
    }
  }return k<=times;
}

int main(){
int i;
for (i=1;i<=n;++i) h[i]=read();
ll l=1,r=1e9+1;
for (;l<=r;){
  ll mid=l+r>>1;
  judge(mid)?r=mid-1:l=mid+1;
  }
write(r+1);
}

Measured memory_bytes: 1024
//#pragma GCC optimize ('O3')
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mp make_pair
#define f first
#define s second
#define pb push_back

const int N = 1e5 + 5;
const int M = 1560 + 5;
const ll OO = 2e18;
const int mod = 1e9 + 7;

int n,k,ans;

int cum(int x) {

    return (1LL*x*(x+1)/2)%mod;

}

int add(int a, int b) {

    return (a+b)%mod;

}

int sub(int a, int b) {

    return (a-b+mod)%mod;

}

int mul(int a, int b) {

    return (1LL*a*b)%mod;

}

int main() {

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

    cin >> n >> k;

    for (int i = k; i <= n+1; ++i) {
        int mn = cum(i-1);
        int mx = sub(cum(n), (i==n+1 ? 0 : cum(n-i)));
        ans = add(ans, add(sub(mx,mn),1));
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define ll long long
#define clr(x,i) memset(x,i,sizeof(x))
using namespace std;
const int N=200005;
const ll mod=1e9+7;
inline int read()
{
    int x=0,f=1; char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9') {x=x*10+ch-'0',ch=getchar();}
    return x*f;
}
int main()
{
	int a=read(),b=read(),c=read();
	swap(a, b); swap(a, c);
	printf("%d %d %d",a,b,c);
}

Measured memory_bytes: 256
#include<queue>
#include<vector>
#include<cstdio>
#include<string>
#include<cstring>
#include<cstdint>
#include<iostream>
#include<algorithm>
using namespace std;
int xt[200001];
int main()
{
	int n;
	scanf("%d",&n);
	int l=0,r=n;
	string x;
	printf("0\n");
	fflush(stdout);
	cin>>x;
	if(x[0]=='M')
		xt[0]=0;
	else if(x[0]=='F')
		xt[0]=1;
	else
		xt[0]=2;
	while(xt[0]!=2)
	{
		int mid=(l+r)/2;
		printf("%d\n",mid);
		fflush(stdout);
		cin>>x;
		if(x[0]=='M')
			xt[mid]=0;
		else if(x[0]=='F')
			xt[mid]=1;
		else
			xt[mid]=2;
		if(xt[mid]==2)
			return 0;
		int len=mid-l+1;
		if(len%2)
		{
			if(xt[l%n]==xt[mid%n])
				l=mid;
			else
				r=mid;
		}
		else
		{
			if(xt[l%n]==xt[mid%n])
				r=mid;
			else
				l=mid;
		}
	}
	return 0;
}

Measured memory_bytes: 852
#include<bits/stdc++.h>
    using namespace std;
     
    int main(){
      string N;
      cin >> N;
      int L=N.size();
      int f=0;
      for(int i=0; i<L; i++){
        string A="";
        A.push_back(N.at(i));
        f+=stoi(A);
      }
      if(stoi(N)%f==0){
        cout << "Yes" << endl;
      }
      else{
        cout << "No" << endl;
      }
    }

Measured memory_bytes: 256
a,b,m = map(int,input().split())
a_li = list(map(int,input().split()))
b_li = list(map(int,input().split()))

sum_li = [list(map(int, input().split())) for _ in range(m)]

ans = min(a_li) + min(b_li)

for i in range(m):
    a_num = sum_li[i][0]
    b_num = sum_li[i][1]
    waribiki = sum_li[i][2]
    
    a_place = a_li[a_num-1]
    b_place = b_li[b_num-1]
    
    ans = min(ans, a_place + b_place - waribiki)
    
print(ans)

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

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

    int d, atmp;
    vector<int> a(n);
    for(int ik=0;ik<k;ik++) {
        cin >> d;
        for(int id=0;id<d;id++) {
            cin >> atmp; atmp--;
            a.at(atmp)++;
        }
    }

    int ans = 0;
    for(int in=0;in<n;in++) {
        if(a.at(in)==0) ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;cin>>n>>k;
    vector<int>p(n);
    for(int i=0;i<n;++i){
        cin>>p[i];
    }
    sort(p.begin(), p.end());
    int ans=0;
    for(int i=0;i<k;++i){
        ans+=p[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define fi first
#define se second
#define pb push_back
#define mp make_pair
ll power(ll x,ll y,ll p)
{
    ll res = 1;      // Initialize result

    x = x % p;  // Update x if it is more than or
                // equal to p

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}
int main(){
  ll h,w;
  cin >> h >> w;
  vector <ll> maxm ;
  vector <string> v;
  for(ll i=0;i<h;i++){
    string s;
    cin >> s;
    v.pb(s) ;
  }
  queue <pair<ll,ll>> q;
  for(ll i=0;i<h;i++){
    for(ll j=0;j<w;j++){
      if(v[i][j]=='.'){
        vector <vector<ll>> v1(h,vector <ll>(w,0)),dis(h,vector <ll>(w,0)) ;
        q.push(mp(i,j)) ;
        v1[i][j] = 1;
        dis[i][j] = 0;

        while(q.size()!=0){
          ll s = q.front().fi ,t = q.front().se;
          if((s-1>=0)){
            if((v[s-1][t]!='#')&&(v1[s-1][t]==0)){
              q.push(mp(s-1,t)) ;
              v1[s-1][t]=1;
              dis[s-1][t] = dis[s][t]+1 ;
            }
          }
          if(s+1<=h-1){
            if((v[s+1][t]!='#')&&(v1[s+1][t]==0)){
              q.push(mp(s+1,t)) ;
              v1[s+1][t]=1;
              dis[s+1][t] = dis[s][t]+1 ;
            }
          }
          if(t+1<=w-1){
            if((v[s][t+1]!='#')&&(v1[s][t+1]==0)){
              q.push(mp(s,t+1)) ;
              v1[s][t+1]=1;
              dis[s][t+1] = dis[s][t]+1 ;
            }
          }
          if(t-1>=0){
            if((v[s][t-1]!='#')&&(v1[s][t-1]==0)){
              q.push(mp(s,t-1)) ;
              v1[s][t-1]=1;
              dis[s][t-1] = dis[s][t]+1 ;
            }
          }
          q.pop() ;
        }
        ll dist=0;
        for(ll a=0;a<h;a++){
          for(ll b=0;b<w;b++){
            if(dist<dis[a][b]) dist = dis[a][b] ;
            //cout << dis[i]
          }
        }
        maxm.pb(dist) ;

      }
    }
  }
  sort(maxm.begin(),maxm.end()) ;
   cout << maxm[maxm.size()-1] << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;
int main() {
  int n, k, num, d, a, ans = 0;
  cin >> n >> k;
  vector<int> sunuke(n);
  for (int  i = 0; i < k; i++) {
    cin >> d;
    for (int j = 0; j < d; j++) {
      cin >> a;
      sunuke[a-1]++;
    }
  }
  for (int i = 0; i < n; i++) {
    if (sunuke[i]==0) ans++;
  }
  cout << ans << endl;
  
}

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

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

fn main() {
    let s: String = read();
    let arr: Vec<i32> = s.chars().map(|c| c.to_digit(10).unwrap() as i32).collect();
    for bit in 0..1 << 4 {
        let mut p_or_m = vec!["-"; 3];
        for i in 0..3 {
            if bit & (1 << i) != 0 {
                p_or_m[i] = "+"
            }
        }
        let mut sum = arr[0];
        let mut ans = String::new();
        for j in 0..3 {
            ans += &arr[j].to_string();
            ans += p_or_m[j];
            if p_or_m[j] == "+" {
                sum += arr[j + 1];
            } else {
                sum -= arr[j + 1];
            }
        }
        ans += &arr[3].to_string();

        if sum == 7 {
            println!("{}=7", ans);
            break;
        }
    }
}


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

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORTASC(c) sort((c).begin(),(c).end())
#define SORTDESC(c,t) sort((c).begin(),(c).end(), std::greater<t>());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define VMAX(a) *max_element(ALL(a))
#define VMIN(a) *min_element(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double PI  = acos(-1.0);

using ll = long long;
using namespace std;

int main() {
    ll n;
    ll a[200010];

    cin >> n;

    
    REP(i, n){
        cin >> a[i];
    }

    ll target = 1;
    ll ct = 0;
    REP(i, n){
        if(a[i] == target){
            target++;
            ct++;
        }
    }

    if(ct == 0){
        cout << -1 << endl;
    } else {
        cout << n-ct << endl;
    }
    
    return 0;
}

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

#define For(i, j, k) for (int i = j; i <= k; ++ i)
#define Forr(i, j, k) for (int i = j; i >= k; -- i)

using namespace std;

inline int read() {
	int x = 0, p = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') p = -1;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	return x * p;
}

inline void File() {
	freopen("D.in", "r", stdin);
	freopen("D.out", "w", stdout);
}

const int N = 1e2 + 10;
int a[N], sta[N], tp, n, m, lst, sum, cnt, ans[N];

int main() {

	n = read(), m = read();
	For(i, 1, m) {
		a[i] = read();
		if (a[i] & 1) sta[++ tp] = i;
	}

	if (tp > 2) return puts("Impossible"), 0;

	if (tp > 0) swap(a[1], a[sta[1]]);
	if (tp > 1) swap(a[m], a[sta[2]]);


	if (m == 1) {
		if (a[1] == 1) return printf("1\n1\n1\n"), 0;
		return printf("%d\n2\n%d %d\n", a[1], a[1] - 1, 1), 0;
	}
	For(i, 1, m) printf("%d ", a[i]); puts("");

	ans[cnt = 1] = lst = a[1] - 1; sum = 1;
	For(i, 1, m) sum += a[i], ans[++ cnt] = sum - lst, lst = sum;
	ans[cnt] -= 1;

	int tt = 0; For(i, 1, cnt) if (ans[i] == 0) ++ tt;		

	printf("%d\n", cnt - tt);
	For(i, 1, cnt) if (ans[i]) printf("%d ", ans[i]); puts("");

	return 0;
}


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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)

#define mod 1e9+7;
#define inf 1e18+7;

typedef long long ll;

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

    vector<ll>a(n),b(n),c(n);
    rep(i,n){
        cin>>a[i];
    }

    b[0]=a[0];
    c[n-1]=a[n-1];
    
    for(int i=1;i<n;i++){
        b[i]=a[i]+b[i-1];
    }
    for(int i=n-2;i>=0;i--){
        c[i]=a[i]+c[i+1];
    }

    ll ans=inf;
    rep(i,n-1){
        ans=min(ans,abs(b[i]-c[i+1]));
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
const ll inf = 1e16;
const ll md = 1000000007;

int popcount(int s) {
  int res = 0;
  rep(i, 20) res += s >> i & 1;
  return res;
}

int main() {
  int n;
  cin >> n;
  vector<vector<pii>> speak(n);
  rep(i, n) {
    int a;
    cin >> a;
    rep(j, a) {
      int x, y;
      cin >> x >> y;
      speak[i].emplace_back(x - 1, y);
    }
  }
  int ans = 0;
  for (int state = 0; state < 1 << n; state++) {
    // 証言が間違いだったときのフラグincorrect
    bool inc = false;
    // i番目が正直だったとき、証言が合っているかチェック
    rep(i, n) if (state >> i & 1) {
      for (pii p : speak[i]) {
        int j = p.first;
        if ((state >> j & 1) != p.second) {
          inc = true;
          break;
        }
      }
      if (inc) break;
    }
    if (inc) continue;
    ans = max(ans, popcount(state));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
a = []
from collections import defaultdict
for i in range(M):
    a.append(list(map(int,input().split())))
dic = defaultdict(list)
res = {}
res_set =set()
res_set.add(1)
for i in range(M):
    dic[a[i][0]].append(a[i][1])
    dic[a[i][1]].append(a[i][0])
queue = [1]
while queue:
    tmp = queue.pop(0)
    for i in range(len(dic[tmp])):
        if dic[tmp][i] not in res_set:
            res_set.add(dic[tmp][i])
            queue.append(dic[tmp][i])
            res[dic[tmp][i]] = tmp
if len(res_set) < N:
    print("No")
else:
    print("Yes")
    for i in range(2, N + 1):
        print(res[i])

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

template <typename T>
T set_oparate(T &sorted_a, T &sorted_b, char op) {
#define abc(a, b, c) begin(a), end(a), begin(b), end(b), inserter(c, end(c))
    T ret;
    switch (op) {
    case 'u':   // 和集合（A ∪ B）
        set_union(abc(sorted_a, sorted_b, ret)); break;
    case 'i':   // 積集合（A ∩ B）
        set_intersection(abc(sorted_a, sorted_b, ret)); break;
    case 'd':   // 差集合（A \ B, A ∩ B^c）
        set_difference(abc(sorted_a, sorted_b, ret)); break;
    case 's':   // 対称差（A Δ B, (A\B) ∪ (B\A)）
        set_symmetric_difference(abc(sorted_a, sorted_b, ret)); break;
    }
    return ret;
#undef abc
}

int main() {
    int n; cin >> n;
    vector<int> a(n);
    for (int &ai: a) cin >> ai;
    int m; cin >> m;
    vector<int> b(m);
    for (int &bi: b) cin >> bi;
    for (int x: set_oparate(a, b, 's')) cout << x << endl;
    return 0;
}


Measured memory_bytes: 6408
program ABC066A
    implicit none
    integer(8)::i,j
    integer(8)::result=30000
    integer(8),dimension(3)::A
    read(5,*)(A(i),i=1,3)

    do i=1,2
        do j=i+1,3
            if(A(i)+A(j)<result)then
                result=A(i)+A(j)
            end if
        end do
    end do

    print'(i0)',result
end program ABC066A

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define ff first
#define ss second
#define nl '\n'
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */

using vi = vector<int>;
using vll = vector<ll>;
#define allOf(x) (x).begin(), (x).end()

template <typename P, typename Q>
ostream&operator<<(ostream&os, const pair<P, Q>&p)
{return os << '(' << p.first << ", " << p.second << ')';}
template <typename K, typename V>
ostream&operator<<(ostream&os, const map<K, V>&v)
{os << '['; for(const auto&it:v) (os << it) << ", "; return os << ']';}
template <typename T> ostream&operator<<(ostream&os, const set<T>&v)
{os << '['; for(const auto&it:v) (os << it) << ", "; return os << ']';}
template <typename T> ostream&operator<<(ostream&os, const vector<T>&v)
{os << '['; for(const auto&it:v) os << it << ", "; return os << ']';}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */



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

  int n, m, X, Y; cin >> n >> m >> X >> Y;
  vi x(n), y(m);
  for(auto&p:x)cin>>p;
  x.emplace_back(X);
  for(auto&p:y)cin>>p;
  y.emplace_back(Y);
  sort(allOf(x)); sort(allOf(y));

  if( x.back() < y.front() ) {
    cout << "No War" << nl;
  } else {
    cout << "War" << nl;
  }

  return 0;
}

/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    public static long count;
    static void Main(string[] args)
    {
        int[] arr = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
        int n = arr[0];
        int r = arr[1];
        int rate = (n >= 10) ? r : r + 100 * (10 - n);
        Console.WriteLine(rate);
    }

  

}




Measured memory_bytes: 11220
N = int(input())
A = [int(i) for i in input().split()]

count = 0
for i in range(N):
    minj = i
    for j in range(i, N):
        if A[j] < A[minj]:
            minj = j

    if i != minj:
        A[i], A[minj] = A[minj], A[i]
        count += 1

for i in range(N):
    print(A[i], end='')
    if i != N - 1:
        print(' ', end='')
print('')

print(count)


Measured memory_bytes: 5628