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

const int N = 1e5 + 10;
int n , a[N];

int main()
{
	cin >> n;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	
	bool change;
	int ans = 0;
	while(1)
	{
		change = false;
		for(int i=0;i<n;i++)
		{
			if(a[i] == i + 1)
			{
				swap(a[i] , a[i+1]);
				ans++;
				change = true;
			}
		}
		if(!change) break;
	}
	cout << ans;
}

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

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

    int n, x, t;
    std::cin >> n >> x >> t;

    int turn = n / x + (n % x != 0);
    std::cout << turn * t;

    return 0;
}



Measured memory_bytes: 3636
function Main(input) {
  const inputs = input.split(" ");
  const x = parseInt(inputs[0], 10);
  const a = parseInt(inputs[1], 10);
  const b = parseInt(inputs[2], 10);
  
  const distA = Math.abs(x - a);
  const distB = Math.abs(x - b);
  if (distA < distB) {
    console.log('A');
  } else {
    console.log('B');
  }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21192
N = int(input())
A = list(map(int, input().split()))
A.insert(0, 0)
A.append(0)
B = []
for i in range(1, len(A)):
    B.append(abs(A[i-1] - A[i]))
gokei = sum(B)
for i in range(N):
    print(gokei - (B[i]+B[i+1]) + abs(A[i] - A[i+2]))





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

int main() {
	// your code goes here
	int n;
	cin>>n;
	
	int dp[n];
	int arr[n];
	for(int i=0;i<n;i++)
	{
	    cin>>arr[i];
	}
	//dp[i] minimum cost to reach nth stode
	dp[0] = 0;
	dp[1] = abs(arr[1] - arr[0]);
	
	for(int i=2;i<n;i++)
	{
	    dp[i] = min(abs(arr[i]-arr[i-1])+dp[i-1],abs(arr[i]-arr[i-2])+dp[i-2]);
	    //cout<<dp[i]<<" "<<abs(arr[i]-arr[i-1])+dp[i-1]<<" "<<abs(arr[i]-arr[i-2])+dp[i-2]<<endl;
	}
	
	cout<<dp[n-1]<<endl;
	return 0;
}


Measured memory_bytes: 1024
mod = 10 ** 9 + 7

def mod_combination(n, k, mod = 10 ** 9 + 7):
    def extended_gcd(a, b):
        if b == 0:
            return (a, 1, 0)
        d, x, y = extended_gcd(b, a % b)
        return (d, y, x - (a // b) * y)
    p, q = 1, 1
    for i in range(n - k + 1, n + 1):
        p = (p * i) % mod
    for i in range(2, k + 1):
        q = (q * i) % mod
    return p * (extended_gcd(q, mod)[1] % mod) % mod

n, a, b = map(int, input().split())

ans = pow(2, n, mod) - 1 - mod_combination(n, a) - mod_combination(n, b)

print(ans % mod)

Measured memory_bytes: 38880
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <numeric>

int main() {
	std::vector<int> v(3);

	std::cin >> v[0] >> v[1] >> v[2];

	std::sort(v.begin(), v.end());

	std::cout << v[0] + v[1] << std::endl;
	return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    char X, Y; cin >> X >> Y;
    if (X > Y) cout << ">" << endl;
    else if (X == Y) cout << "=" << endl;
    else cout << "<" << endl;
}


Measured memory_bytes: 256
#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 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

ll N, K;
vector< pair<ll, ll> > TD;  // t が first

vector<bool> isNew;     // 新しい種類の寿司がきたら true
vector< pair<ll, ll> > dt_sort;      // 昇順ソート済み dt, d が first

ll solve() {
    // dt_sort の作成
    REP(i, N) { dt_sort.push_back(make_pair(TD[i].second, TD[i].first)); }
    sort(dt_sort.begin(), dt_sort.end(), greater< pair<ll, ll> >());
    // isNew の作成
    vector<bool> isUsed(MAX_N, false);
    isNew.assign(N, false);
    REP(i, N) {
        ll t = dt_sort[i].second;
        if(!isUsed[t]) {
            isUsed[t] = true;
            isNew[i] = true;
        }
    }

    // まずは K 個取った仮の値を作成
    ll d = 0, x = 0;
    REP(i, K) {
        if(isNew[i]) { x++; }
        d += dt_sort[i].first;
    }
    ll ret = d + x * x;
    // l が左向きに、ダブりを消していく
    // r が右向きに、新たな種類を足していく
    ll l = K-1;
    ll r = K;
    while(l >= 0 && r < N) {
        // l をダブりまで進める
        while(l >= 0 && isNew[l]) { --l; }
        if(l < 0) { break; }
        // r を新しい種類のネタまで進める
        while(r < N && !isNew[r]) { ++r; }
        if(r >= N) { break; }
        d -= dt_sort[l].first;
        d += dt_sort[r].first;
        x++;
        ret = max(ret, d + x * x);
        --l; ++r;
    }
    return ret;
}

signed main()
{
    cin >> N >> K;
    TD.assign(N, make_pair(0, 0));
    REP(i, N) {
        cin >> TD[i].first >> TD[i].second;
    }
    ll ans = solve();
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 3956
#include<stdio.h>

int main(){
  int j,k,N,flag,count=0;
  int eg;
  int A[100];

  scanf("%d",&N);
  if((N>100)&&(N<0)){
    printf("error\n");
  }
  for(j=0;j<N;j++){
    scanf("%d",&A[j]);
  }

  flag=1;
  while(flag){
    flag=0;
    for(j=N-1;j>0;j--){
      if(A[j]<A[j-1]){
	eg=A[j];
	A[j]=A[j-1];
	A[j-1]=eg;
	flag=1;
	count++;
	
      }
    }
  }

  for(k=0;k<N;k++){
    if(k>0){
      printf(" ");
    }
    printf("%d",A[k]);
  }
  printf("\n");
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 2144
from sys import stdin
graph = [{"J":1,"O":0,"I":4},
         {"J":1,"O":2,"I":4},
         {"J":1,"O":0,"I":3},
         {"J":1,"O":5,"I":4},
         {"J":1,"O":5,"I":4},
         {"J":1,"O":0,"I":6},
         {"J":1,"O":5,"I":4}]
for line in stdin.readlines():
    cur,JOI,IOI = 0,0,0
    for c in line.strip():
        if not c in "JOI":
            cur = 0
        else:
            cur = graph[cur][c]
            if cur == 3:
                JOI += 1
            if cur == 6:
                IOI += 1
    print JOI
    print IOI

Measured memory_bytes: 4260
#include <stdio.h>

int main(void)
{
    long long int N, M, answer = 0;
    long long int A[10000] = {0};


    scanf("%lld %lld", &N, &M);
    for (int i = 0; i < M; i++)
    {
        scanf("%lld", &A[i]);
    }

    answer = N;

    for (int j = 0; j < M; j++)
    {
        answer -= A[j];
    }

    if (answer < 0)
    {
        printf("-1");
    }

    else if (answer >= 0)
    {
        printf("%lld", answer);
    }
    
    
    
    
    return 0;
}

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

#define ll long long int
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define sep(i,b,a) for(ll i=b-1;i>=a;i--)
#define vi vector <ll>
#define hell 1000000007
#define pii pair <ll,ll>
#define inf (ll)(1e16)
#define pb push_back
#define p 31

using namespace std;

ll helper(vi &w,vi &v,ll s,ll W,vector < vi > &dp)
{
    if(W<0)
        return -inf;
    if(s>=w.size())
        return 0;
    if(dp[s][W]!=-1)
        return dp[s][W];
    return dp[s][W]=max(v[s]+helper(w,v,s+1,W-w[s],dp),helper(w,v,s+1,W,dp));
}

void solve()
{
    ll n,W;
    cin>>n>>W;
    vi v,w;
    rep(i,0,n)
    {
        ll x,y;
        cin>>x>>y;
        w.pb(x);
        v.pb(y);
    }
    vector <vi> dp(n+1,vi(W+1,-1));
    cout<<helper(w,v,0,W,dp);
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll t;
    //cin>>t;
    t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 80372
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 20;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int n, m, x, c[MAXN], a[MAXN][MAXN], cnt[MAXN];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> m >> x;
    FOR(i,1,n) {
        cin >> c[i];
        FOR(j,1,m) cin >> a[i][j];
    }
    int res = 1000000000;
    FOR(mask,1,(1<<n)-1) {
        FOR(j,1,m) cnt[j] = 0;
        int money = 0;
        FOR(i,1,n)
            if (mask & (1<<(i-1))) {
                money += c[i];
                FOR(j,1,m) cnt[j] += a[i][j];
            }
        bool co = true;
        FOR(j,1,m)
            if (cnt[j] < x) {
                co = false;
                break;
            }
        if (co) res = min(res, money);
    }
    if (res == 1000000000) res = -1;
    cout << res;
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;

template <typename T>
bool chmax(T& a, const T& b) {
	if (a < b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}

template <typename T>
bool chmin(T& a, const T& b) {
	if (a > b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}


int main() {
	int N, M, A,B;
	ll HH;
	int ans = 0;
	cin >> N >> M;
	vector<ll>H(N);
	vector<vector<int>>tenbou(N,vector<int>());
	rep(i, N) {
		cin >> HH;
		H[i] = HH;
	}
	rep(i, M) {
		cin >> A >> B;
		A--; B--;
		tenbou[A].push_back(B);
		tenbou[B].push_back(A);
	}

	rep(i, N) {
		ll n = H[i];
		bool takai = true;
		for (int rin : tenbou[i]) {
			if (H[rin] >= n) takai = false;
		}
		if (takai)ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 9064
use proconio::input;

fn main() {
    input! {
        x: i64
    };
    // 5 -> 6 -> 5 -> 6 ...
    // 1 2 3 4 5 6 7 8 9 10 11 12
    let a = x / (5 + 6);
    let b = x % (5 + 6);
    let ans = a * 2
        + if b == 0 {
            0
        } else if b <= 6 {
            1
        } else {
            2
        };
    println!("{}", ans);
}


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

int main(){
  ll h,w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i,h) cin >> s[i];
  vector<vector<ll>> dist(h,vector<ll>(w,INF));
  ll b = 0;
  rep(i,h){
    rep(j,w){
      if( s[i][j] == '#' ){
        dist[i][j] = -1;
        b++;
      }
    }
  }
  queue<pair<ll,ll>> q;
  auto push = [&]( pair<ll,ll> v,ll d ){
    if( dist[v.first][v.second] != INF ) return;
    dist[v.first][v.second] = d;
    q.push(v);
  };
  push(make_pair(0,0),0);
  while(!q.empty()){
    pair<ll,ll> v = q.front();q.pop();
    ll vf = v.first;
    ll vs = v.second;
    ll d = dist[vf][vs];
    if( vf-1 >= 0 ) push(make_pair(vf-1,vs),d+1);
    if( vf+1 <= h-1 ) push(make_pair(vf+1,vs),d+1);
    if( vs-1 >= 0 ) push(make_pair(vf,vs-1),d+1);
    if( vs+1 <= w-1 ) push(make_pair(vf,vs+1),d+1);
  }
  if( dist[h-1][w-1] == INF ){
    cout << -1 << "\n";
  }else{
  	cout << h*w - (dist[h-1][w-1]+1+b) << "\n";
  }
  return 0;
}

Measured memory_bytes: 256
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n, i, max, min, sum, a;

    for(;;){
      n = sc.nextInt();
      if(n == 0)break;
      sum = 0;max = 0;min = 1000;
      for(i = 0;i < n;i++){
        a = sc.nextInt();
        if(min > a)min = a;
        if(max < a)max = a;
        sum += a;
      }
      out.println((sum - max - min) / (n - 2));
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 20920
/* 
 * File:   main.cpp
 * Author: freebsd
 *
 * Created on 2014/08/28, 10:07
 */

#include <cstdio>

using namespace std;

int main() {
    int Al = 0, Bl = 0, Cl = 0, Dl = 0;
    int Ar = 0, Br = 0, Cr = 0, Dr = 0;
    double templ = 0.0, tempr = 0.0;
    
    int i = 0;
    
    while (i != 40) {
        scanf("%lf %lf", &templ, &tempr);
    
        if(templ >= 1.1) {
            Al++;
        }else if (templ >= 0.6 && templ < 1.1) {
            Bl++;
        }else if (templ >= 0.2 && templ < 0.6) {
            Cl++;
        }else {
            Dl++;
        }
    
        if(tempr >= 1.1) {
            Ar++;
        }else if (tempr >= 0.6 && tempr < 1.1) {
            Br++;
        }else if (tempr >= 0.2 && tempr < 0.6) {
            Cr++;
        }else {
            Dr++;
        }
        
        i++; 
    }
    
    printf("%d %d\n", Al, Ar);
    printf("%d %d\n", Bl, Br);
    printf("%d %d\n", Cl, Cr);
    printf("%d %d\n", Dl, Dr);
    
    return 0;
}

Measured memory_bytes: 1052
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

void rsortr_u32(void *base, const int count){
	uint32_t *a=base;
	uint32_t *b=malloc(count*sizeof(uint32_t));
	int c[0x100];
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(0<<3))&0xFF]++; } for(int i=0xFE; i>=0; i--) c[i]+=c[i+1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(0<<3))&0xFF]]=a[i]; }{void *t=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(1<<3))&0xFF]++; } for(int i=0xFE; i>=0; i--) c[i]+=c[i+1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(1<<3))&0xFF]]=a[i]; }{void *t=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(2<<3))&0xFF]++; } for(int i=0xFE; i>=0; i--) c[i]+=c[i+1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(2<<3))&0xFF]]=a[i]; }{void *t=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(3<<3))&0xFF]++; } for(int i=0xFE; i>=0; i--) c[i]+=c[i+1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(3<<3))&0xFF]]=a[i]; }{void *t=a; a=b; b=t;}
	free(b);
}
int32_t nextint(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); int s=0; if(c=='-'){s=1;c=getchar_unlocked();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }

char a[100000];
char b[100000];
int main(void){
	int n=nextint();
	for(int i=0; i<n; i++){
		a[i]=getchar_unlocked()&1^1;
	}
	for(int k=0; k<4; k++){
		b[0]=k&1; b[1]=k>>1;
		for(int i=2; i<n; i++){
			b[i]=b[i-2]^b[i-1]^a[i-1];
		}
		if((b[n-2]^b[n-1]^b[0])==a[n-1] && (b[n-1]^b[0]^b[1])==a[0]){
			for(int i=0; i<n; i++){
				putchar_unlocked(b[i]==0?'S':'W');
			}
			putchar_unlocked(10);
			return 0;
		}
	}
	puts("-1");
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		if(!n)break;
		int max=0,min=500;
		while(n--){
			int s=0,p;
			for(int i=0;i<5;++i){
				cin>>p;
				s+=p;
			}
			if(s>max)max=s;
			if(s<min)min=s;
		}
		cout<<max<<" "<<min<<"\n";
	}
	return 0;
}

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

int main(){
  int N;
  string s, t, temp;

  cin>>N>>s>>t;


  for(int i = 0; i <= N; i++){
    temp = s;
    temp.insert(i,t);
    bool flag  = true;
    for(int j = 0; j < N; j++){
      if(temp[j] != s[j]){
	flag = false;
      }
    }
      if(flag){
	//	cout<<temp<<endl;
	cout<<i+N<<endl;
	return 0;
      }
    
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <queue>
#define rep(i,n) for (int i=0;i<(n);++i)
#define REP(i,n) for (int i=0;i<=(n);++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int INF = 10000000;

int main(){
    int k;
    string s;
    cin >> k >> s;

    int num = s.size();
    if(k < num){
        for(int i = 0; i < k; ++i){
            cout << s[i];
        }
        cout << "..." << endl;
        return 0;
    }
    else{
        cout << s << endl;
    }
    return 0;
}

Measured memory_bytes: 3628
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
ans = B[A[0]-1]
for i in range(1,N):
  ans += B[A[i]-1]
  if A[i]==A[i-1]+1:
    ans += C[A[i-1]-1]
print(ans)

Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N;
  while (cin >> N) {
    vector<ll> A(N);
    for (auto& x : A) cin >> x;
    ll X = A[0], Y = A[1], Z = 0;
    for (int i = 2; i < N; i++) Z ^= A[i];
    ll S = X + Y;
    auto f = [&]() {
      if (S - Z < 0 || (S - Z) % 2 == 1) return -1ll;
      ll D = (S - Z) / 2;
      vector<int> bit(60, -1);
      int change = -1, last = -1;
      for (int i = bit.size() - 1; i >= 0; i--) {
        int x = (X >> i) & 1, z = (Z >> i) & 1, d = (D >> i) & 1;
        int c = 0;
        for (int a = 0; a < 2; a++) {
          if ((a & (z ^ a)) == d) {
            ++c;
            bit[i] = a;
          }
        }
        if (c == 0) return -1ll;
        if (c >= 2) bit[i] = -1;
        if (change < 0 && bit[i] < 0 && x == 1) {
          last = i;
        }
        if (change < 0 && bit[i] >= 0 && x != bit[i]) {
          change = i;
        }
      }
      if (change >= 0) {
        int x = (X >> change) & 1;
        if (x > bit[change]) {
          for (int i = bit.size() - 1; i > change; i--) if (bit[i] < 0) bit[i] = (X >> i) & 1;
          for (int i = change; i >= 0; i--) if (bit[i] < 0) bit[i] = 1;
        }
        if (x < bit[change]) {
          if (last < 0) return -1ll;
          for (int i = bit.size() - 1; i > last; i--) if (bit[i] < 0) bit[i] = (X >> i) & 1;
          bit[last] = 0;
          for (int i = last - 1; i >= 0; i--) if (bit[i] < 0) bit[i] = 1;
        }
      }
      for (int i = 0; i < bit.size(); i++) if (bit[i] < 0) bit[i] = (X >> i) & 1;
      ll res = 0;
      for (int i = bit.size() - 1; i >= 0; i--) res = res * 2 + bit[i];
      return res ? X - res : -1;
    };
    cout << f() << endl;
  }
  return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;

#define MAX_M 10000+1
#define MAX_N 1000

int N, M;
int r, q;

vector< pair<int, int> > ts[MAX_M];
int cnt[MAX_M];
int from[MAX_M];
int main() {
    while (cin >> N >> M) {
        if (N == 0 && M == 0) break;
        for (int i = 0; i < MAX_M; i++) ts[i].clear();
        memset(cnt, 0, sizeof(cnt));
        memset(from, 0, sizeof(from));
        cin >> r;
        for (int i = 0; i < r; i++) {
            int t, n, m, s;
            cin >> t >> n >> m >> s;
            if (s == 1) {
                if (cnt[m] == 0) from[m] = t;
                cnt[m]++;
            } else {
                cnt[m]--;
                if (cnt[m] == 0) 
                    ts[m].push_back(make_pair(from[m], t));
            }
        }
        cin >> q;
        for (int i = 0; i < q; i++) {
            int s, e, m;
            cin >> s >> e >> m;
            int total = 0;
            for (int j = 0; j < ts[m].size(); j++) {
                if (s < ts[m][j].first) {
                    if (e < ts[m][j].first) continue;
                    if (e <= ts[m][j].second) {
                        total += (e - ts[m][j].first);
                    } else {
                        total += (ts[m][j].second - ts[m][j].first);
                    }
                } else {
                    if (s < ts[m][j].second) {
                        if (e <= ts[m][j].second) {
                            total += (e - s);
                        } else {
                            total += (ts[m][j].second - s);
                        }
                    }
                }
                //cout << ts[m][j].first << ' ' << ts[m][j].second << endl;
            }
            cout << total << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1556
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {//234
	int a,b,c,x,y;
	cin>>a>>b>>c>>x>>y;
	int nv = 2*min(x,y)*c;
	if(x>y) {
		nv+=(x-y)*a;
	}else{
		nv+=(y-x)*b;
	}
	cout<<min(a*x+b*y, min(2*max(x,y)*c,nv));
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int main()
{
    //ifstream cin("input.in");
   // ofstream cout("output2.out");
    ios::sync_with_stdio(0);cin.tie(0);
    long N,A[100009];
    cin>>N;
    for(long i=1;i<=N;i++)
        cin>>A[i];
    long i=1,C=0;
    while(i!=2 && C<=N)
    {
        i=A[i];
        C++;
    }
    if(i!=2)
        cout<<-1;
    else
        cout<<C;
}

Measured memory_bytes: 1024
fun main(args: Array<String>) {
    var X = readLine()!!.split(" ").map(String::toInt).toMutableList()
    var cnt = 0

    while(true){
        var max = X.max()!!
        var min = X.min()!!
        var one2 = X.filter{it<max}
        if(X.toSet().size == 1) break
        else if(X.toSet().size == 3 || (max- min == 1 && one2.size==2)){
            X[X.indexOf(one2[0])]++
            X[X.indexOf(one2[1])]++
            cnt++
        }
        else{
            X[X.indexOf(min)] += 2
            cnt++
        }

    }
    println(cnt)

}


Measured memory_bytes: 36036
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;
const int MAX = 1e4;
const ll mod = 1e9+7;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i-1] * (ll)i % mod;
    inv[i] = mod - inv[mod%i] * (mod/(ll)i) % mod;
    finv[i] = finv[i-1] * inv[i] % mod;
  }
}

ll COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}

void extgcd(ll a, ll b, ll &x, ll &y) {
  if(b == 0) {
    x = 1;
    y = 0;
    return;
  }
  extgcd(b, a % b, y, x);
  y -= a/b*x;
  return; 
}

ll mod_inverse(ll a, ll m = mod) {
  ll x, y;
  extgcd(a,m,x,y);
  return (m + x % m) % m;
}

int main(){
  COMinit();
  int n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  vector<vector<ll>> dp(b+1,vector<ll>(n+1,0));
  dp[a-1][0] = 1;
  for(int i = a; i <= b; i++) {
    for(int j = 0; j <= n; j++) {
      (dp[i][j] += dp[i-1][j]) %= mod;
      if(j + i*c <= n) {
        ll r = COM(n-j,i*c);
        for(int l = 1; l <= c; l++) {
          (r *= COM(i*l,i)) %= mod;
          (r *= mod_inverse(l)) %= mod;
        }
        for(int k = c; k <= min(d,(n-j)/i); k++) {
          (dp[i][j+k*i] += dp[i-1][j] * r % mod) %= mod;
          (r *= COM(n-j-i*k,i)) %= mod;
          (r *= mod_inverse(k+1)) %= mod;
        }
      }
    }
  }
  cout << dp[b][n] << endl;
  return 0;
}

Measured memory_bytes: 8320
using System;
using System.Linq;

public class Test
{
	public static void Main()
	{
		int[] h = Console.ReadLine().Split().Select(int.Parse).ToArray();
		int[] k = Console.ReadLine().Split().Select(int.Parse).ToArray();
		int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
		int a=h[0]*x[0]+h[0]/10*x[2]+h[1]*x[1]+h[1]/20*x[3];
		int b=k[0]*x[0]+k[0]/10*x[2]+k[1]*x[1]+k[1]/20*x[3];
		if(a==b)Console.WriteLine("even");
		else Console.WriteLine(a>b?"hiroshi":"kenjiro");
	}
}


Measured memory_bytes: 8272
#include <iostream>
#include <limits.h>
#include <queue>
#include <algorithm>
#include <string>
#include <map>

using namespace std;

typedef pair<int,int> P;
typedef map<int,int> MP;

const int INF=INT_MAX/3;
//const int V_MAX=10000,E_MAX=10000;
//int V,E;
const int N=1000000;
int A[N];

void solve(int n){

  //fill(num,num+n,0);
  MP num;
 
  for(int i=0;i<n;i++){ 
    if(num[A[i]]==0) num[A[i]]=1;
    else num[A[i]]++;
  }
  
  for(MP::iterator itr=num.begin();itr!=num.end();itr++)
    if(itr->second>(n/2)){
      cout<<itr->first<<endl;
      return;
    }
  
  cout<<"NO COLOR\n";
}
  



int main(){

  int n=0;
  cin>>n;
  while(n!=0){
    for(int i=0;i<n;i++)
      cin>>A[i];
    solve(n);
    cin>>n;
  }

  return 0;
}

Measured memory_bytes: 8536
#include <stdio.h>
#include <stdlib.h>
int compare(const void *a,const void *b){
    if(*(int *)a>*(int *)b)return 1;
    return -1;
}
int main()
{   int n;
    scanf("%d",&n);
    int p[n];
    for(int i=0;i<n;i++){
        scanf("%d",&p[i]);
    }int ans=0;
    for(int i=1;i<n-1;i++){
        if((p[i-1]<p[i]&&p[i]<p[i+1])||(p[i-1]>p[i]&&p[i]>p[i+1]))ans++;
    }
    printf("%d",ans);

    return 0;
}


Measured memory_bytes: 128
package main

import (
    "fmt"
)

func visit(x int) int {
    if x == 0 {
        return 0
    }
    return visit(x/10) + x%10
}

func main() {
    var n, a, b int
    fmt.Scan(&n, &a, &b)
    res := 0
    for i := 1; i <= n; i++ {
        sum := visit(i)
        if a <= sum && sum <= b {
            res += i
        }
    }
    fmt.Println(res)
}

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

int main()
{
	long long int i, n, x, count=0;
	cin >> n;
	int a[n+1];
	for(i=0; i<=n; i+=1)
		cin >> a[i];
	for(i=0; i<n; i+=1)
	{
		cin >> x;
		if(x>=a[i])
		{
			x-=a[i];
			count+=a[i];
			//a[i]=0;
			if(x>=a[i+1])
			{
				count+=a[i+1];
				a[i+1]=0;
			}
			else
			{
				a[i+1]-=x;
				count+=x;
			}
		}
		else
		{
			//a[i]-=x;
			count+=x;
		}
	}
	cout << count << endl;
}

Measured memory_bytes: 640
from collections import Counter
n = int(input())
A = list(map(int, input().split()))
ac = sorted([(i, v) for i, v in Counter(A).items() if v >= 2], reverse=True)
s = []
for k, v in ac:
  for _ in range(v//2):
    s.append(k)
  if len(s) >= 2:
    break
if len(s) >= 2:
  print(s[0]*s[1])
else:
  print(0)

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

int main(){
  int N, l, r, count=0;
  cin >> N;
  rep(i, N){
    cin >> l >> r;
    count += r-l+1;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <vector>

static const int IINF = 1 << 30;
static const long long LINF = 1LL << 60;
static const long long MOD = 1.0e+9 + 7;

template <typename T> std::vector<T> vectors(std::size_t n, T val) {
  return std::vector<T>(n, val);
}

template <typename T, typename... Args>
auto vectors(std::size_t n, Args... args) {
  return std::vector<decltype(vectors<T>(args...))>(n, vectors<T>(args...));
}

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

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

template <class T> inline void chadd(T &a, const T &b) {
  a += b, a %= MOD;
  // TODO minus case
}

template <class T>
std::ostream &operator<<(std::ostream &s, const std::vector<T> &v) {
  if (v.empty())
    return s;
  s << *v.begin();
  for (auto iter = v.begin() + 1; iter != v.end(); ++iter)
    if (std::is_fundamental<T>::value)
      s << " " << *iter;
    else
      s << std::endl << *iter;
  return s;
}

int main() {
  // Input
  long long N, M;
  std::cin >> N >> M;
  if (N == 1 and M == 1) {
    std::cout << 1 << std::endl;
  } else if (N == 1) {
    std::cout << M - 2 << std::endl;
  } else if (M == 1) {
    std::cout << N - 2 << std::endl;
  } else {
    std::cout << (M - 2) * (N - 2) << std::endl;
  }

  return 0;
}


Measured memory_bytes: 256
n=int(input())
l=list(map(int,input().split()))
ans=0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if l[i]!=l[j] and l[j]!=l[k] and l[k]!=l[i]:
                xyz=[l[i],l[j],l[k]]
                xyz.sort()
                if xyz[0]+xyz[1]>xyz[2]:
                    ans+=1
print(ans)

Measured memory_bytes: 68412
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))

typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

int main() {
	int N,a,ans;
	cin>>N;
	rep(i,10){
		a=1;
		rep(j,i){
			a*=2;
		}
		if(a<=N)ans=a;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;
const int MAXN = 16;
const int mod = 1e9 + 7;
#define sz(v) ((int)v.size())

lint ipow(int x, int p){
	lint ret = 1, piv = x;
	while(p){
		if(p & 1) ret = ret * piv % mod;
		piv = piv * piv % mod;
		p >>= 1;
	}
	return ret;
}

int n, m, a[MAXN];
int dp[MAXN][1<<MAXN];
int prec[1<<MAXN];
lint fact[100000], invf[100000];

lint bino(int x, int y){
	if(x < y) return 0;
	return fact[x] * (invf[y] * invf[x-y] % mod) % mod;
}

int f(int cur, int stk){ // how much is already bad
	if(cur == m) return prec[(1 << n) - 1 - stk]; // how to dist others
	if(~dp[cur][stk]) return dp[cur][stk];
	lint ret = f(cur + 1, stk);
	for(int i=0; i<n; i++){
		if((stk >> i) & 1) continue;
		ret += mod - f(cur + 1, stk | (1<<i)) * bino((1<<n) - a[cur] - stk, (1<<i) - 1) % mod;
	}
	return dp[cur][stk] = ret % mod;
}

int main(){
	cin >> n >> m;
	for(int i=0; i<m; i++) cin >> a[i];
	reverse(a, a + m);
	fact[0] = invf[0] = 1;
	for(int i=1; i<100000; i++){
		fact[i] = fact[i-1] * i % mod;
		invf[i] = ipow(fact[i], mod - 2);
	}
	for(int i=0; i<(1<<n); i++){
		lint ret = 1;
		int cur = 0;
		for(int j=0; j<n; j++){
			if((i >> j) & 1){
				ret *= bino(cur + (1<<j), (1<<j));
				ret %= mod;
				cur += (1<<j);
			}
			ret *= fact[(1<<j)];
			ret %= mod;
		}
		prec[i] = ret;
	}
	memset(dp, -1, sizeof(dp));
	cout << ((1ll * f(0, 0)) << n) % mod << endl;
}


Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   

typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> isPair;
using vvll = vector< vector<ll> >;
using vll = vector<ll> ;
#define Pll pair<ll,ll>
#define vpll vector<pll>
#define sll set<ll>
#define mll map<ll,ll>

const ll inf=(ll)1e18;
const ll maxs = (ll)3000+5;
const ll mod = (ll)1e9+7;
const ll oo = (ll) 1e18;

#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define LB lower_bound
#define UB upper_bound
#define line cout<<endl;
#define fr(i,a,b) for(int i=a;i<=b;++i)
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end()) 
#define cpresent(s,x) (find(all(s),x) != s.end()) 
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++) 
#define fastio(); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mst(x,a) memset(x,a,sizeof(x))

ll n;
string s;
ll dp[maxs][maxs];
bitset<3005> b;
ll go(ll pos,ll below ,ll above)
{
    if(below<0||above<0)
        return 0;
    if(pos==n)return 1;    
    if(dp[pos][below]!=-1)
        return dp[pos][below];
    ll op = s[pos-1];
    ll ans=0;
    if(op=='<')
    {
        ans += go(pos+1,below,above-1);
        ans += go(pos,below+1,above-1);
        ans %= mod;
    }
    else
    {
        ans += go(pos+1,below-1,above);
        ans += go(pos,below-1,above+1);
        ans %= mod;
    }
    return dp[pos][below]=ans;
    
}

void solve()
{
    ll ans=0;
    memset(dp,-1,sizeof dp);
    for(ll i=1;i<=n;i++)
    {
        ll below = i-1;
        ll above = n-i;
        ans += go(1,below,above);
        ans %= mod;
    }    
    cout<<ans;    
}

int main() {
    fastio();
	cin>>n>>s;
	solve();
	return 0;
}

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

ll dfs(ll d,ll h,ll n,ll a,ll b,string& ans){
  
  if(d==n){
    return b;
  }
  

  ll H=(1LL<<(n-1-d));
  ll W=(1LL<<d);
  
  if(h<H){
    ll f=dfs(d+1,H-1-h,n,a,b,ans);
    if( f < W ){
      ans+='L';
      return W-1-f;
    }else{
      ans+='R';
      return W+W-f-1;
    }
    
  }else{
    ll f=dfs(d+1,h-H,n,a,b,ans);
    if( f < W ){
      ans+='R';
      return f;
    }else{
      ans+='L';
      return f-W;
    }
  }
}

int main(){
  while(1){
    ll n,a,b;
    cin>>n>>a>>b;
    if(n==0&&a==0&&b==0)break;
    a--;
    b--;
    string ans="";
    dfs(0,a,n,a,b,ans);
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const ll INF = 1LL<<60;

vector<vector<int>> g;
vector<int> ans;

int main(){
  int m,k; cin >> m >> k;
  int ul = pow(2, m);
  if(ul <= k) cout << -1 << endl;
  else if(m == 0){
    if(k == 0) cout << "0 0" << endl;
    else cout << -1 << endl;
  }else if(m == 1){
    if(k == 0) cout << "0 0 1 1" << endl;
    else cout << -1 << endl;
  }else{
    vector<int> arr;
    for(int i = 0; i < ul; i++){
      if(i == k) continue;
      cout << i << " ";
      arr.push_back(i);
    }
    reverse(arr.begin(), arr.end());
    cout << k;
    for(int v: arr){
      cout << " " << v;
    }
    cout << " " << k << endl;
  }
  return 0;
}


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

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define tll tuple<ll, ll, ll>
#define all(c) c.begin(),c.end()

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
 
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;

//command
//c++ atcoder.cpp -std=c++14
//./a.out

//fill(score, score+202020, 0);
#define NN 2020202

ll f[NN], rf[NN];
ll inv(ll x) {
    ll res = 1;
    ll k = MOD - 2;
    ll y = x;
    while (k) {
        if (k & 1) res = (res * y) % MOD;
        y = (y * y) % MOD;
        k /= 2;
    }
    return res;
}
void init() {
    f[0] = 1;
    rf[0] = inv(f[0]);
    for(ll i=1;i<NN;i++){
      f[i] = (f[i - 1] * i) % MOD;
      rf[i] = inv(f[i]);
    }
}
 
ll C(int n, int k) {
    ll a = f[n]; // = n!
    ll b = rf[n-k]; // = (n-k)!
    ll c = rf[k]; // = k!
 
    ll bc = (b * c) % MOD;
 
    return (a * bc) % MOD;
}

int main(){
  init();
  ll x, y;
  cin >> x >> y;
  if ((x+y)%3 != 0){
    cout << 0 << endl;
    exit(0);
  }
  if (y > 2*x){
    cout << 0 << endl;
    exit(0);
  }
  if (2*y < x){
    cout << 0 << endl;
    exit(0);
  }

  ll n = (x+y)/3;
  ll sx = 2*(x+y)/3;
  ll sy = (x+y)/3;

  ll dif = y - sy;
  //cout << n << " " << dif << endl;
  ll ans = C(n, dif); 
  
  cout << ans << endl;
}


Measured memory_bytes: 31872
S = input()
list1 = list(map(int,S))
#例えば4つ
a = list1[0]
b = list1[1]
c = list1[2]
d = list1[3]

if a == b:
    print("Bad")
elif b == c:
    print("Bad")
elif c == d:
    print("Bad")
else:
   print("Good")

Measured memory_bytes: 3060
num = int(input())

lst = [int(x) for x in input().split()]

def show():
    for i in range(len(lst)):
        print(lst[i], end="")
        if i < len(lst)-1:
            print(" ", end="")
        else:
            print()

f = True
count = 0
while f:
    f = False
    for j in reversed(range(1,len(lst))):
        if lst[j] < lst[j-1]:
            tmp = lst[j]
            lst[j] = lst[j-1]
            lst[j-1] = tmp
            count += 1
            f = True
show()
print(count)



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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int INF=1001001001;
const int INFLL=1001001001001001001ll;
const int mod=1000000007;
inline void add(int &a,int b){
    a+=b;
    if(a>=mod)a-=mod;
}

int N,X,Y;

int par[1111];
int cntx[1111],cnty[1111];

void init(){
    for(int i=0;i<2*(X+Y);i++){
        par[i]=i;
        cntx[i]=i%2==0;
        cnty[i]=i%2==1;
    }
}
int find(int x){
    return x==par[x]?x:par[x]=find(par[x]);
}
void unite(int x,int y){
    x=find(x);y=find(y);
    if(x==y)return;
    cntx[x]+=cntx[y];
    cnty[x]+=cnty[y];

    par[y]=x;
}

int dp[1111][1111];
void solve(){
    int M=X+Y;

    init();
    rep(i,N){
        int a,b;
        string s;
        cin>>a>>b>>s;
        a--;b--;

        a*=2;b*=2;
        if(s=="no")b++;
        unite(a,b);
        unite(a^1,b^1);
    }

    set<int>rs;

    vpint lis;

    rep(i,M){
        int r1=find(i*2);
        int r2=find(i*2+1);
        if(rs.find(r1)!=rs.end())continue;
        lis.pb({r1,r2});
        rs.insert(r1);rs.insert(r2);
    }

    memset(dp,0,sizeof(dp));
    dp[0][0]=1;

    for(int k=0;k<lis.size();k++){
        auto &p=lis[k];
        for(int i=0;i<=M;i++){
            if(i-cntx[p.fi]>=0)add(dp[k+1][i],dp[k][i-cntx[p.fi]]);
            if(i-cntx[p.se]>=0)add(dp[k+1][i],dp[k][i-cntx[p.se]]);
        }
    }

    if(dp[lis.size()][X]!=1){
        puts("no");
        return;
    }

    set<int>crs;

    for(int k=lis.size()-1;k>=0;k--){
        auto &p=lis[k];
        if(X-cntx[p.fi]>=0&&dp[k][X-cntx[p.fi]]){
            crs.insert(p.fi);
            X-=cntx[p.fi];
        }
        else{
            crs.insert(p.se);
            X-=cntx[p.se];
        }
    }

    rep(i,M){
        if(crs.find(find(i*2))!=crs.end())printf("%lld\n",i+1);
    }
    puts("end");
}

signed main(){
    while(cin>>N>>X>>Y,N||X||Y)solve();
    return 0;
}

Measured memory_bytes: 13024
N = int(input())
A = []
sA = []
for i in range(N):
    a = int(input())
    A.append(a)
    sA.append(a)

sA.sort(reverse=True)

f = sA[0]
s = sA[1]

for i in range(N):
    if A[i] == f:
        print(s)
    else:
        print(f)


Measured memory_bytes: 81880
from operator import itemgetter

def main():
    N,M = map(int, input().split())
    A = [[1,int(x)] for x in input().split()]
    for _ in range(M):
        b,c = map(int, input().split())
        A.append([b,c])
    A.sort(key=itemgetter(1))
    A.reverse()
    n=0
    s=0
    for a in A:
        n+=a[0]
        if n<=N:
            s+=a[1]*a[0]
        elif n>N:
            d=a[0]
            e=a[1]
            break
    s+=(N-n+d)*e
    print(s)
    
main()

Measured memory_bytes: 36940
#include <stdio.h>
#include <math.h>

int main(void){
  int n;
  long long int a[100002], p=1;
  long double p2=1.0;
  int i;
  
  scanf("%d", &n);
  
  for(i=1;i<=n;i++){
    scanf("%lld", &a[i]);
    if(a[i]==0){printf("%d",0); goto flag;}
  }
  
  for(i=1;i<=n;i++){
    p*=a[i];
    p2*=(long double)a[i];
    if(p2>(long double)pow(10,18)){printf("%d",-1); goto flag;}
  }
  
//  p*=10;
  printf("%lld", p);

  flag:
  return 0;
}



Measured memory_bytes: 2512
w,h,n=map(int,input().split())

x_mx=w
x_mn=0
y_mx=h
y_mn=0
for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        x_mn=max(x_mn,x)
    elif a==2:
        x_mx=min(x_mx,x)
    elif a==3:
        y_mn=max(y_mn,y)
    else:
        y_mx=min(y_mx,y)

ans=(x_mx-x_mn)*(y_mx-y_mn)
if x_mx-x_mn<=0 or y_mx-y_mn<=0:
    ans=0
print(max(ans,0))

Measured memory_bytes: 9108
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,a[100010],ans=0,left;
    deque<ll> deq;
    map<ll,ll> mp;
    cin>>n;
    rep(i,n){
        cin>>a[i];
        mp[a[i]]++;
    }
    sort(a,a+n);
    rep(i,n-1){
        if(i%4==0){
            deq.push_back(a[n-(i/2+1)]);
            mp[a[n-(i/2+1)]]--;
        }
        else if(i%4==1){
            deq.push_front(a[i/2]);
            mp[a[i/2]]--;
        }
        else if(i%4==2){
            deq.push_back(a[i/2]);
            mp[a[i/2]]--;
        }
        else{
            deq.push_front(a[n-(i/2+1)]);
            mp[a[n-(i/2+1)]]--;
        }
    }
    for(auto i:mp){
        if(i.second>0) left=i.first;
    }
    rep(i,n-2){
        ans+=abs(deq.at(i)-deq.at(i+1));
    }
    ans+=max(abs(deq.at(0)-left),abs(deq.at(n-2)-left));
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 8064
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
using namespace std;

#define rep(i, s) for (int i = 0; i < s; ++i)
#define all(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

int main() {
    int n;
    ll MOD=1000000007;
    cin>>n;
    string s1,s2;
    cin>>s1;
    cin>>s2;
    ll ans=1;
    int state=0;//state=0は何をおいてもいい。state=1は横に２つ。state=2は縦に１つ。

    for(int i=0;i<n;i++){
        if(i<n-1 and s1.at(i)==s1.at(i+1)){
            if(state==0){
                ans=ans*6%MOD;
            }
            else if(state==1){
                ans=ans*3%MOD;
            }
            else{
                ans=ans*2%MOD;
            }
            state=1;
            i++;
        }
        else if(s1.at(i)==s2.at(i)){
            if(state==0){
                ans=ans*3%MOD;
            }
            else if(state==1){
                ans=ans*1%MOD;
            }
            else{
                ans=ans*2%MOD;
            }
            state=2;
        }
    }
    cout<<ans<<endl;






    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int a,b;
    char op;
    cin>>a>>op>>b;
    while(op !='?'){
        switch(op){
            case'+':
            cout<<a+b<<endl;
            break;
            case'-':
            cout<<a-b<<endl;
            break;
            case'*':
            cout<<a*b<<endl;
            break;
            case'/':
            cout<<a/b<<endl;
            break;
        }
        cin>>a>>op>>b;
    }
    return 0;
}



Measured memory_bytes: 3056
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------

int main(void){
    int h, w, n;
    cin >> h >> w >> n;

    int ma = max(h , w);

    int ans = 0;
    int now = 0;
    while(now < n){
        now += ma;
        ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

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

  sort(ALL(p));
  int sum = 0;
  REP(i, k) sum += p[i];

  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 3600
package main

import (
	"fmt"
)

func isACGT(b byte) bool {
	if b == 'A' {
		return true
	}
	if b == 'C' {
		return true
	}
	if b == 'G' {
		return true
	}
	if b == 'T' {
		return true
	}
	return false
}
func main() {
	var s string
	fmt.Scanln(&s)
	ans := 0
	consec := 0
	for i := 0; i < len(s); i++ {
		if isACGT(s[i]) {
			consec += 1
			if ans < consec {
				ans = consec
			}
		} else {
			consec = 0
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
import java.util.*;
import java.io.*;
public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		long a = Integer.parseInt(st.nextToken());
		long b = Integer.parseInt(st.nextToken());
		long c = Integer.parseInt(st.nextToken());
		long d = Integer.parseInt(st.nextToken());
		System.out.println(a*b*1.0/2+" "+(c*1.0 == a*1.0/2 && d*1.0 == b*1.0/2? 1:0));
	}

}


Measured memory_bytes: 21204