akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
//-std=c++11
#define print(x) printf("%.12f",x);
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for(int i =0 ; i < n; ++i)
#define repr(i, n) for(int i=n-1;i>=0;i--)
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define Repr(i,a,b) for(int i=a;i>=b;i--)
#define pii pair < int, int >
#define iter ::iterator
#define forit(a) for(it=a.begin();it!=a.end();it++)
typedef vector<int> vi;
typedef  long long ll;
const int inf = int(1e9);
const int mod = inf + 7;
const int N = (int)2e5 + 5;

int toInt(string s){
	return (int)(s[0]-'0')*100+(int)(s[1]-'0')*10+(int)(s[2]-'0');
}

bool ok(int i){
	if(i%10==i/10%10 && i%10==i/10/10%10)return 1;
	return 0;
}

void solve(){
	string s;
	cin>>s;
	int n=toInt(s);
	for(int i=n;i<=999;i++){
		if(ok(i)){
			cout<<i;
			return;
		}
	}


}


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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;

ll adj[310][310];
ll adjtmp[310][310];

void solve(){

    ll n;
    cin >> n;
    ll sum=0;
    rep(i,n){
        rep(j,n){
            cin >> adj[i][j];
            adjtmp[i][j]=adj[i][j];
            sum += adj[i][j];
        }
    }

    sum = sum/2;

    for (ll k = 0; k < n; k++){       // 経由する頂点
        for (ll i = 0; i < n; i++) {    // 始点
            for (ll j = 0; j < n; j++) {  // 終点
                adj[i][j] = min(adj[i][j], adj[i][k] + adj[k][j]);
            }
        }
    }

    bool ans = true;
    rep(i,n){
        rep(j,n){
            if(adj[i][j]!=adjtmp[i][j]) ans = false;
        }
    }

    if(!ans){
        cout << -1 << endl;
        return;
    }

    rep(i,n){
        rep(j,n){//iとjの経路について考える
            bool b = true;
            rep(k,n){
                if(i>=j || i==k || j==k) continue;
                if(adj[i][j]==adj[i][k]+adj[j][k]){
                    sum -= adj[i][j];
                    //cout << i << " " << j << " " << adj[i][j] << endl;
                    b=false;
                    break;
                }
            }
            //if(!b) break;
        }
    }

    cout << sum << endl;

    

    /*
    rep(i,v){
        rep(j,v){
            cout << adj[i][j] << " ";
        }
        cout << endl;
    }
    */
    

}


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


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

int main() {
  int x, a, b; 
  cin >> x >> a >> b;
    
  if ((x-a) * (x-a) <= (x-b) * (x-b)) 
    cout << "A" << endl;
  else
    cout << "B" << endl;
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
T=sum(B)-sum(A)
ca=0
cb=0
for a,b in zip(A,B):
    if a>b:
        cb+=a-b
    elif b>a:
        ca+=(b-a+1)//2
        cb+=(b-a)&1
print("YNeos"[ca<cb::2])

Measured memory_bytes: 4596
#include <iostream>
#include <vector>
using namespace std;
vector<int> aa;
vector<int> bb;
int main() {
    int N;
    cin >> N;
    if (N % 2 == 0) {
        for (int i=1; i<=N/2; i++) {
            for (int j=i+1; j<=N-i; j++) {
                aa.push_back(i);
                bb.push_back(j);
                aa.push_back(N+1-i);
                bb.push_back(j);
            }
        }
    } else {
        for (int i=1; i<=(N-1)/2; i++) {
            for (int j=i+1; j<=N-1-i; j++) {
                aa.push_back(i);
                bb.push_back(j);
                aa.push_back(N-i);
                bb.push_back(j);
            }
        }
        for (int i=1; i<N; i++) {
            aa.push_back(i);
            bb.push_back(N);
        }
    }
    cout << aa.size() << endl;
    for (int i=0; i<aa.size(); i++) {
        cout << aa[i] << " " << bb[i] << endl;
    }
    return 0;
}
 

Measured memory_bytes: 384
import itertools
 
N, M, Q = map(int, input().split())
 
int_tuple_list = list()
for i in range(Q):
    int_tuple_list.append(tuple(map(int, input().split())))
 
m_list = [i for i in range(1, M + 1)]
# print(m_list)
all_sequence_list = list()
score_list = list()
for sequence in itertools.combinations_with_replacement(m_list, N):
    # print(sequence)
    score_tmp = 0
    for ai, bi, ci, di in int_tuple_list:
        if ci == sequence[bi - 1] - sequence[ai - 1]:
            score_tmp += di
 
    # print(score_tmp)
    score_list.append(score_tmp)
 
print(max(score_list))

Measured memory_bytes: 74092
# 二つの長方形があります。 一つ目の長方形は、縦の辺の長さが A 、横の辺の長さが B です。
# 二つ目の長方形は、縦の辺の長さが C 、横の辺の長さが D です。 この二つの長方形のうち、面積の大きい方の面積を出力してください。
# なお、二つの長方形の面積が等しい時は、その面積を出力してください。

A,B,C,D = map(int,input().split())

x = A * B
y = C * D
if x > y:
    print(x)
elif x < y:
    print(y)
elif x == y:
    print(x)

Measured memory_bytes: 9116
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b)
{
   return a%b ==0 ? b : gcd(b,a%b);
}
int cnt[20];
int b[20];
int n,g;
int vis[200];
int dfs(int num)
{
    int ans=1e9;
    for(int i=1;i<=n;i++)
    {
       if(vis[i])continue;
        if(cnt[i]*i*100+b[i]<num)
        {
            vis[i]=1;
            //cout<<ans<<" "<<i<<" "<<num<<endl;
            ans=min(ans,dfs(num-(cnt[i]*i*100+b[i]))+cnt[i]);
            vis[i]=0;
        }
        else
        {
            if(cnt[i]*i*100<num)
            {
                ans=min(cnt[i],ans);
                //cout<<1<<" "<<ans<<" "<<i<<" "<<num<<endl;
            }
            else
            {
               ans=min(ans,num/(i*100)+(int)(num%(i*100)!=0));
               //cout<<0<<" "<<ans<<" "<<i<<" "<<num<<endl;
            }
        }
    }
    return ans;
}
int main()
{
   cin>>n>>g;
   for(int i=1;i<=n;i++)
   {
      vis[i]=0;
      cin>>cnt[i]>>b[i];
   }

   cout<<dfs(g)<<endl;

    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

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

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

const DIV uint = 1e9 + 7

func main() {
	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)

	S := nextInt()

	if S <= 2 {
		fmt.Println(0)
		return
	}
	maxN := S - 3
	maxK := S/3 - 1
	C := make([][]uint, maxN+1)

	for n := 0; n <= maxN; n++ {
		C[n] = make([]uint, maxK+1)
	}
	C[0][0] = 1
	for n := 1; n <= maxN; n++ {
		for k := 0; k <= maxK; k++ {
			if k > n {
				break
			} else if k == 0 {
				C[n][k] = 1
			} else if k == 1 {
				C[n][k] = uint(n)
			} else if k == n {
				C[n][k] = 1
			} else {
				C[n][k] = (C[n-1][k-1] + C[n-1][k]) % DIV
			}
		}
	}

	var t uint = 0
	for k := 1; 3*k <= S; k++ {
		t = (t + C[S-3*k+k-1][k-1]) % DIV
	}

	fmt.Println(t)
}


Measured memory_bytes: 12756
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    X, Y, Z = (int(_) for _ in input().split())
    
    print((X-Z)//(Y+Z))
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main() {
    int x = 0;
    int ans = 0;
    scanf("%d", &x);
    if (x == 1) {
        printf("1\n");
        return 0;
    }
    for (int i=2; i<=sqrt(x)+1; i++) {
        int buf = 1;
        while (buf * i <= x) {
            buf = buf * i;
        }
        if (buf > ans) ans = buf;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define MOD 1000000007
#define MT make_tuple
#define PB push_back
typedef long long ll;

int N, a[220], ans;

int main () {
        scanf("%d", &N);
        fo(i, 0, 2*N) scanf("%d", &a[i]);
        sort(a, a+2*N);
        for (int i = 2*N-2; i >= 0; i -= 2) {
                ans += a[i];
        }
        printf("%d\n", ans);
        return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include  <iostream>
#include  <algorithm>
#include  <climits>
#include  <vector>
#include  <string>
#include  <cstring>
#include  <stack>
#include  <queue>
#include  <cmath>
#include  <iomanip>
#include  <set>
#include  <map>
#include  <new>
#include <cstdint>
#include <cctype>
using namespace std;
#define rep(i,n)  for(int i = 0; i < n; i++)
#define lrep(i,n,m)  for(int i = n; i < m; i++)

using ll = long long;
using Vii = vector<vector<int> >;
using Gjudge = vector<vector<bool>>;
using Vi = vector<int>;
using Vl = vector<ll>;
using Vll = vector<vector<ll> >;
using Vs = vector<string>;
using Vb = vector<bool>;
using the = pair<int, int>;
using lthe = pair<ll, ll>;

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; }

const int Mod = static_cast<int>(1e9 + 7);
const int INF = INT_MAX;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,1,0,-1 };

int main()
{
    int n;
    cin >> n;
    Vi H(n);
    rep(i, n)  cin >> H[i];

    int max = H[0];
    int ans = 1;

    for (int i = 1; i < n; i++) {
        if (H[i] >= max) {
            ans++;
            max = H[i];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
// 1_abc137_a
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

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 SZ(x) ((int)(x).size())
#define INF (1e16)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a;
    cin >> b;
    int c = a + b;
    if(a - b > c) c = a - b;
    if(a * b > c) c = a * b;
    cout << c << endl;
    return 0;
}

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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}

int main()
{
#ifdef FASTIO
  ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif

  int n,k;
  string s;

  cin >> n >> k >> s;

  if (s[k-1] == 'A')
    s[k-1] = 'a';
  else if (s[k-1] == 'B')
    s[k-1] = 'b';
  else
    s[k-1] = 'c';

  cout << s << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
	
	int N,K,h[100010],i,ans=0;
	
	scanf("%d %d",&N,&K);
	
	for(i=1;i<=N;i++){
		scanf("%d",&h[i]);
		if(h[i]>=K){
			ans++;
		}
	}
	
	printf("%d\n",ans);
	
	
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> kushi(2 * N);
  for(int i = 0; i < 2 * N; i++) cin >> kushi.at(i);
  
  sort(kushi.begin(), kushi.end());
  
  int answer = 0;
  
  for(int i = 0; i < N; i++) answer += kushi.at(i * 2);
  cout << answer << endl;
}

Measured memory_bytes: 256
k=int(input())
s=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(s[k-1])

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

int main() {
  char c;
  cin >> c;

  if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
    cout << "vowel" << endl;
  } else {
    cout << "consonant" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define rep(i,n) for(ll i=0;i<(n);i++)  
#define pii pair<int,int>
#define piii pair<int,pii>
#define mp make_pair
#define pb push_back  
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second  
const int INF = INT_MAX;
const ll LLINF = LLONG_MAX;
const double eps = 1e-5;
const double PI = M_PI;  
#define DEB cout<<"!"<<endl
#define SHOW(a,b) cout<<(a)<<" "<<(b)<<endl
#define SHOWARRAY(ar,i,j) REP(a,i)REP(b,j)cout<<ar[a][b]<<((b==j-1)?((a==i-1)?("\n\n"):("\n")):(" "))
  
#define DIV 1000000007
typedef vector<ll> Array;
typedef vector<Array> matrix;
typedef tuple<int,int,int> tiii;
#define mt make_tuple

ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if(n&1==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}

int main(){
  int n; cin >> n;
  int c = 0;
  vector<ll> v;
  for(int i = 1; i <= n; i++){
    ll in; cin >> in;
    v.pb(in);
  }
  int ans = 0;
  for(int i = 0; i < n-1; i++){
    if(i+1 == v[i])
      swap(v[i],v[i+1]),ans++;
  }
  if(v[n-1] == n) ans++;
  cout << ans << endl;
}

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

int main(){
  int i,j;
  int N;
  cin >> N;
  
  vector<int> cards(N);
  for(i = 0 ; i < N ; i++)	cin >> cards.at(i);
  
  int A = 0,B = 0,turn = 0;
  while(true){
    
    int max = 0;
    for(j = 0 ; j < N ; j++){
      if( max < cards.at(j) ){
        max = cards.at(j);
      }
    }
    for(j = 0 ; j < N ; j++){
      if( max == cards.at(j) ){
        cards.at(j) = 0;
        break;
      }
    }
    A += max;
    turn++;
    
    if( turn == N)	break;
    
    max = 0;
   	for(j = 0 ; j < N ; j++){
      if( max < cards.at(j) ){
        max = cards.at(j);
      }
    }
    for(j = 0 ; j < N ; j++){
      if( max == cards.at(j) ){
        cards.at(j) = 0;
        break;
      }
    }
    B += max;
    turn++;

    if( turn == N )	break;
  }
  cout << A - B << endl;

  
}        

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

double n,ans;

signed main()
{
	cin>>n;
	ans=(n/3.00)*(n/3.00)*(n/3.00);
	cout<<fixed<<setprecision(10)<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
N = int(input())
K = int(input())
def dp(n, k): #0以上n以下の数で０でない数字がちょうどk個あるもの。
  if k == 0:
    return 1
  elif n == 0:
    return 0
  else:
    n = int(n)
    s = str(n)
    digit = len(s)
    m, fdigit = divmod(n,10)
    if m >= 1:
        return int(dp(m, k-1) * fdigit + dp(m-1, k-1)* (9-fdigit) + dp(m, k))
    elif k == 1:
        return n
    elif k == 2 or k == 3:
        return 0
    else:
        return 1
if K == 0:
    answer = dp(N, K)-1
else:
    answer = dp(N, K)
print(int(answer))

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;

int main()
{
    int m, f, r;
    int cnt = 0;

    while(1)
    {
        cin >> m >> f >> r;
        if((m == -1) && (f == -1) && (r == -1))
        {
            break;
        }

        int sum = m + f;
        if((m == -1) || (f == -1))
        {
            cout << "F";
        }
        else if(sum >= 80)
        {
            cout << "A";
        }
        else if(sum >= 65)
        {
            cout << "B";
        }
        else if(sum >= 50)
        {
            cout << "C";
        }
        else if(sum >= 30)
        {
            if(r >= 50)
            {
                cout << "C";
            }
            else
            {
                cout << "D";
            }   
        }
        else
        {
            cout << "F";
        }

        cout << endl;

        cnt++;
        if(cnt > 50)
        {
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 3096
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;
using ll = long long;
int main(){
  int n;
  cin >> n;
  vector<int> dp(1000000, 1001001001);
  dp[0] = 0;
  for(int i = 0; i < n; i++) {
    for(int j = 0; i + pow(9, j) <= n; j++){
      dp[i + pow(9, j)] = min(dp[i + pow(9, j)], dp[i] + 1);
    }
    for(int j = 0; i + pow(6, j) <= n; j++){
      dp[i + pow(6, j)] = min(dp[i + pow(6, j)], dp[i] + 1);
    }
    for(int j = 0; j <= 6; j++){
      dp[i + 1] = min(dp[i + 1], dp[i] + 1);
    }
  }
  cout << dp[n] << "\n";
  return 0;
}

Measured memory_bytes: 4224
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int w = sc.nextInt();
        int l = s.length();
        
        for(int i=0;i<l;i+=w) System.out.print(s.charAt(i));
        System.out.println();
    }
}

Measured memory_bytes: 21844
s = gets.chomp

n = s.size
res = 0
(1 << (n - 1)).times do |b|
  ex = s[0]
  (n - 1).times do |i|
    if (b >> i) & 1 == 1
      ex += "+"
    end
    ex += s[i + 1]
  end
  res += eval(ex)
end
puts res

Measured memory_bytes: 14256
_ = gets
a, b = gets.chomp.split.map(&:to_i)
p = gets.chomp.split.map(&:to_i)
f = 0
s = 0
t = 0
p.each do |i|
  if i <= a
    f += 1
  elsif i <= b
    s += 1
  else
    t += 1
  end
end
puts [f, s, t].min

Measured memory_bytes: 1788
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX_N = 100;

int N;
double A, B, C;
double D[MAX_N];

int main(){
	cin >> N;
	cin >> A >> B >> C;
	for(int i = 0; i < N; i++) cin >> D[i];
	sort(D, D + N);
	reverse(D, D + N);
	double ans = C / A;
	double sum_p = A, sum_c = C;
	for(int i = 0; i < N; i++){
		sum_p += B;
		sum_c += D[i];
		ans = max(ans, sum_c / sum_p);
	}
	cout << (int)ans << endl;
}


Measured memory_bytes: 3224
#include <iostream>
using namespace std;
static const int MAX = 100;

struct Card
{
  char suit, value;
};

void bubleSort(Card C[], int N)
{
  bool flag = 1;
  for (int i = 0; flag; i++)
  {
    flag = 0;
    for (int j = N - 1; j > i; j--)
    {
      if (C[j].value < C[j - 1].value)
      {
        swap(C[j], C[j - 1]);
        flag = 1;
      }
    }
  }
}

void selectionSort(Card C[], int N)
{
  int minj;
  for (int i = 0; i < N; i++)
  {
    minj = i;
    for (int j = i; j < N; j++)
    {
      if (C[j].value < C[minj].value)
      {
        minj = j;
      }
    }
    if (minj != i)
    {
      swap(C[i], C[minj]);
    }
  }
}

bool isStable(Card in[], Card out[], int N)
{
  int seqIn, seqOut;
  for (int i = 0; i < N; i++)
  {
    seqIn = 0;
    for (int k = 0; k < N; k++)
    {
      if (in[i].value == in[k].value)
      {
        seqIn++;
        if (in[i].suit == in[k].suit)
        {
          break;
        }
      }
    }

    seqOut = 0;
    for (int j = 0; j < N; j++)
    {
      if (in[i].value == out[j].value)
      {
        seqOut++;
        if (in[i].suit == out[j].suit)
        {
          if (seqOut != seqIn)
          {
            return false;
          }
          break;
        }
      }
    }
  }
  return true;
}

int main()
{
  Card C1[MAX], C2[MAX];
  int N;
  char ch;

  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> C1[i].suit >> C1[i].value;

  for (int i = 0; i < N; i++)
    C2[i] = C1[i];

  bubleSort(C2, N);
  for (int i = 0; i < N; i++)
  {
    if (i > 0)
    {
      cout << " ";
    }
    cout << C2[i].suit << C2[i].value;
  }
  cout << endl;

  if (isStable(C1, C2, N))
    cout << "Stable" << endl;
  else
    cout << "Not Stable" << endl;

  for (int i = 0; i < N; i++)
    C2[i] = C1[i];

  selectionSort(C2, N);
  for (int i = 0; i < N; i++)
  {
    if (i > 0)
    {
      cout << " ";
    }
    cout << C2[i].suit << C2[i].value;
  }
  cout << endl;

  if (isStable(C1, C2, N))
    cout << "Stable" << endl;
  else
    cout << "Not stable" << endl;

  return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
int MAX;

//int memo[810][810][9];

int gcd(int a, int b){
	  return (a==0) ? b : gcd(b%a,a);
}

pii frac_minus(int p,int q, int mp, int mq){ // p/q - mp/mq
	  int nume = p*mq - q*mp;
	  int deno = q*mq;
	  int g = gcd(nume,deno);
	  return pii(nume/g, deno/g);
}

int solve(int p,int q, int prod,int n,int pre){
	  
	  if(prod > MAX or p < 0 or q < 0)
			return 0;
	  if(n<0)
			return 0;

	  int ans = 0;
	  if(p==0)
			ans++;
	  /*
	  if(p == 1 and (ll)q*(ll)prod <= MAX and pre <= q and q>0){
//			cout << "(" << p <<"/"<<q<<","<<prod<<","<<n<<") ";
			ans++;
	  }
	  */
	  
	  int high;
	  if(p!=0)
			high = min(MAX,q*n/p);
	  else 
			high = 12000;
	  for(int j=pre; j<=high; j++){
			pii tmp = frac_minus (p,q,1,j);
			int np = tmp.first;
			int nq = tmp.second;
			if(prod*j > MAX) break;
			ans += solve(np,nq,prod*j,n-1,j);
	  }

	  return ans ;
}

int main(){

	  while(1){

			int p,q,n;
			cin >> p >> q >> MAX >> n;
			if(!p) break;
			int g = gcd(p,q);
			cout << solve(p/g,q/g,1,n,1) << endl;
	  }
}

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

using namespace std;
const long long mod=1e9+7;
const long long INF=1LL<<60;

int main(){
    string s;
    cin>>s;
    int n=s.size();
    string ans;
    if(s[0]!=s[n-1]){
        if(n%2==0)ans="Second";
        else ans="First";
    }
    else {
        if(n%2==1)ans="Second";
        else ans="First";
    }
    cout<<ans<<endl;

    
}
 
   

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16

ll n;
ll a[101010],a2[101010];
ll b[101010],b2[101010];
map<ll,vector<ll> > g;
map<ll,bool> vis;

ll e,c,m;
ll sz;
void dfs(ll v){
  sz++;
  vis[v]=true;
  for(ll nv : g[v]){
    if(!vis[nv])dfs(nv);
  }
}

int main(){
	cin>>n;
  ll sum=0;
  rep(i,n){
    cin>>a[i];
    a2[i]=a[i];
    sum^=a[i];
  }
  a[n]=sum;
  a2[n]=sum;
  sum=0;
  rep(i,n){
    cin>>b[i];
    b2[i]=b[i];
    sum^=b[i];
  }
  b[n]=sum;
  b2[n]=sum;
  n++;
  sort(a2,a2+n); sort(b2,b2+n);
  {
    bool ok=true;
    rep(i,n)if(a2[i]!=b2[i])ok=false;
    if(!ok){
      cout<<-1<<endl;
      return 0;
    }
  }

  rep(i,n){
    if(a[i]!=b[i]){
      e++;
      g[a[i]].push_back(b[i]);
    }
  }
  rep(i,n){
    if(!vis[a[i]]){
      c++;
      sz=0;
      dfs(a[i]);
      if(sz==1&&a[i]!=a[n-1])m++;
    }
  }
  if(a[n-1]!=b[n-1])m++;
  cout<<e+c-1-m<<endl;
	return 0;
}


Measured memory_bytes: 29952
#include<bits/stdc++.h>
using namespace std;
#define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);
typedef long long int ll;
typedef vector<pair<ll,ll> > vpl;
typedef vector<pair<int,int> > vpi;
typedef vector<ll> vec;
typedef map<ll,ll> mp;
ll GCD(ll a,ll b)
{
    if(a == 0)
    {
        return b;
    }
    return GCD(b%a,a);
}
int main()
{
    FastIO;
    int q = 1;
    //cin >> q;
    while(q--)
    {
        int n,x,t;
        cin >> n >> x >> t;
        cout << (int)ceil(n*1.0/x)*t << endl;
    }
}



Measured memory_bytes: 3584
<?php

while (true) {
    $stdin = preg_split('/ /', trim(fgets(STDIN)));
    $h = intval($stdin[0]);
    $w = intval($stdin[1]);
    
    if ($h === 0 && $w === 0) {
        return;
    }
    
    for ($i = 0; $i < $h; $i++) {
        for ($j = 0; $j < $w; $j++) {
            print '#';
        }
        print "\n";
    }
    print "\n";
}

Measured memory_bytes: 6640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define pf push_front
#define PI acos(-1)
#define EPS 1e-5
#define sz(v) ((int)(v).size())
#define all(v) v.begin(),v.end()
#define forn(i, n) for(ll i=0;i<(ll)n;i++)
#define fi first
#define se second
 

int main() {
	int n, k, q;
	cin >> n >> k >> q;
	vector<int> a(q);
	vector<int> cnt(n);
	forn(i, q) cin >> a[i], cnt[a[i]-1]++;
	forn(i, n) {
		if(k-q+cnt[i] > 0) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	
	return 0;
}



Measured memory_bytes: 3992
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#define ll long long

using namespace std;

int main()
{
	ll n;
	cin >> n;
	bool in = false;
	for (int i=sqrt(n);i>=1;i--)
	{
		if (n % i == 0)
		{
			cout << n/i + i-2;
			break;
		}
	}
}




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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int k;
  cin >> k;
  int ans = 0;
  for (int a = 1; a <= k; a++) {
    for (int b = 1; b <= k; b++) {
      for (int c = 1; c <= k; c++) {
        ans += __gcd(a, __gcd(b, c));
      }
    }
  }
  cout << ans << '\n';
  return 0;
}

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

int main() {
	char s[200000];
	int x = 0;
	cin >> s;
	for (int i = 0; i < 200000; i++) {
		if (s[i] == 'A') {
			x = i;
			break;
		}
	}
	for (int i = 200000; i >= 0; i--) {
		if (s[i] == 'Z') {
			x = i-x+1;
			break;
		}
	}
	cout << x << endl;
}

Measured memory_bytes: 384
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
#define inf 1e9
using namespace std;

const int maxn = 2000*2000+5;
const int mod  = 1e9+7;
inline void add(int &a,const int &b){a+=b;if(a>=mod)a-=mod;}

int pw(int x,int k)
{
	int re=1;
	for(;k;k>>=1,x=(ll)x*x%mod) if(k&1)
		re=(ll)re*x%mod;
	return re;
}
int inv(int x){ return pw(x,mod-2); }

int s[maxn],invs[maxn];
void pre()
{
	s[0]=1; for(int i=1;i<maxn;i++) s[i]=(ll)s[i-1]*i%mod;
	invs[maxn-1]=inv(s[maxn-1]);
	for(int i=maxn-2;i>=0;i--) invs[i]=(ll)invs[i+1]*(i+1)%mod;
}
int C(int n,int m){return (ll)s[n]*invs[m]%mod*invs[n-m]%mod;}

int n,m;
int f[2005];

int main()
{
	pre();
	
	scanf("%d%d",&n,&m); int u=n*m;
	if(m==1) return puts("1"),0;
	
	f[0]=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<i;j++)
			add(f[j+1],(ll)f[j]*C(u-i-j*(m-1)-1,m-2)%mod);
	}
	int ans=f[n];
	ans=(ll)ans*s[n]%mod;
	printf("%d\n",ans);
	
	return 0;
}


Measured memory_bytes: 31616
from itertools import product
from collections import defaultdict as dd

class UFT(object):
  def __init__(self,n):
    self.parent={i:i for i in range(1,n+1)}
    self.height={i:0 for i in range(1,n+1)}
  def find(self,a):
    if self.parent[a]!=a:
      self.parent[a]=self.find(self.parent[a])
    return self.parent[a]
  def unite(self,a,b):
    a=self.find(a)
    b=self.find(b)
    if self.height[a]>self.height[b]:
      self.parent[b]=a
    else:
      if self.height[a]==self.height[b]:
        self.height[b]+=1
      self.parent[a]=b
  def isunited(self,a,b):
    return self.find(a)==self.find(b)


n,k,l=map(int,input().split())
uk=UFT(n)
ul=UFT(n)
dc=dd(int)
du={}

for _ in range(k):
  a,b=map(int,input().split())
  uk.unite(a,b)

for _ in range(l):
  a,b=map(int,input().split())
  ul.unite(a,b)
  
for i in range(1,n+1):
  du[i]=(uk.find(i),ul.find(i))
  dc[du[i]]+=1

print(*(dc[du[i]] for i in range(1,n+1)))


Measured memory_bytes: 139492
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
	int n,k,s,x;
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++)
		scanf("%d",&x);
	if ((n-1)%(k-1)>0) s=(n-1)/(k-1)+1;
	else s=(n-1)/(k-1);
	printf("%d\n",s);
	return 0;
}

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

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> ii;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vii;
typedef long double ld;
typedef vector<ld> vld;
typedef vector<vector<ld>> vvld;
typedef vector<bool> vbl;
typedef vector<vbl> mbl;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(s) (s).begin(), (s).end()
const ll MOD = 998244353;

ll binpow(ll x, ll y, ll mod)
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % mod;
        y >>= 1;
        x = (x * x) % mod;
    }
    return res;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll n, m, k;
    cin >> n >> m >> k;
    ll ans = 0;
    vll fact(n + 1), infact(n + 1);
    fact[0] = infact[0] = 1;
    for (int i = 1; i <= n; i++)
        fact[i] = (i * fact[i - 1] + MOD) % MOD, infact[i] = binpow(fact[i], MOD - 2, MOD);
    for (int i = 0; i <= k; i++)
    {
        ll num = (fact[n - 1] * infact[i]) % MOD;
        num = (num * infact[n - 1 - i] + MOD) % MOD;
        num= (m * num + MOD) % MOD;
        if (i != n - 1)
            num = (num * binpow(m - 1, n - 1 - i, MOD) + MOD) % MOD;
        ans += num;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6288
import sys

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


def main():
    N = int(readline())

    print(N // 3)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9088
import java.util.Scanner;

class Main{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        for(int i=0;i<n;i++) {
           String[] s=sc.next().split(":");
           int c=Math.abs(Integer.parseInt(s[0])*60-Integer.parseInt(s[1])*11);
           //double d=Math.min(c,360-c);
           //System.out.println(d<30?"alert":d<90?"warning":"safe");
           System.out.println(c<60||c>660?"alert":c<180||c>540?"warning":"safe");
        }
    }
}


Measured memory_bytes: 29040
#include<stdio.h>
int Astore(int soba_g);
int Bstore(int soba_g);
int Cstore(int soba_g);

int main(void){
  int soba;
  int price;
  int minprice;

  while(1){
    scanf("%d",&soba);
    if(soba==0) break;
    minprice=100000;

    for(int a=0;a<=soba;a+=200){
      for(int b=0;b<=soba;b+=300){
        for(int c=0;c<=soba;c+=500){
          if(a+b+c==soba){
            price = Astore(a)+Bstore(b)+Cstore(c);
            if(minprice>price) minprice = price;
          }
        }
      }
    }
    printf("%d\n",minprice);
  }

  return 0;
}

int Astore(int soba_g){
  int unit_soba = soba_g/200;
  //袋の数
  if(unit_soba<5) return 380*unit_soba;
  else{return 380*(unit_soba-unit_soba%5)*0.8+380*(unit_soba%5);}
}

int Bstore(int soba_g){
    int unit_soba = soba_g/300;
    //袋の数
    if(unit_soba<4) return 550*unit_soba;
    else{return 550*(unit_soba-unit_soba%4)*0.85+550*(unit_soba%4);}
}

int Cstore(int soba_g){
  int unit_soba = soba_g/500;
  //袋の数
  if(unit_soba<3) return 850*unit_soba;
  else{return 850*(unit_soba-unit_soba%3)*0.88+850*(unit_soba%3);}
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#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
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    ll H,N;
    cin >> H >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    ll t = 0;
    REP(i, N){
        t += A[i];
    }

    Yes(H <= t);
}

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

void solve()
{
	int x,y,z;
	cin>>x>>y>>z;
	swap(x,y);
	swap(x,z);
	cout<<x<<" "<<y<<" "<<z<<endl;
}

int main()
{
	ll t = 1;
	// cin>>t;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    string s;
    cin >> s;
    rep(i,s.size()) cout << 'x';
    cout << endl;
    return 0;
}

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

int main(int argc, char const *argv[])
{
    double r;
    cin >> r;
    double pi = 3.14159265358979323846;
    printf("%.6f %.6f", r * r * pi, 2 * r * pi);
    return 0;
}



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

int main(void){
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    
    if (e - a > k) cout << ":(" << endl;
    else cout << "Yay!" << endl;
}

Measured memory_bytes: 256
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1000000000
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};

int main (){
    int n,q;
    cin>>n>>q;
    vector<queue<int>> st(n);
    rep(i,0,q){
        int cmd;cin>>cmd;
        if(cmd==0){
            int t,x;cin>>t>>x;
            st[t].push(x);
        }else  if(cmd==1){
            int t;cin>>t;
            if(!st[t].empty())cout<<st[t].front()<<endl;
        }else {
            int t;cin>>t;
            if(!st[t].empty())st[t].pop();
        }
    }
    

}



/*

*/


Measured memory_bytes: 4244
# -*- coding: utf-8 -*-
import math
import sys


def solve(N):
  N_str = ''
  if N == 0:
    return('0')

  while(N != 0):
    r = N % 2
    if r < 0:
      r += 2
    N = (N-r)//(-2)
    N_str += str(r)
  return(N_str[::-1])


if __name__ == "__main__":
  N = int(sys.stdin.readline().rstrip())
  print(solve(N))

Measured memory_bytes: 3060
N = int(input())
X = list(map(int, input().split()))
Y = sorted(X)

smaller_index = int((N - 1) / 2)
larger_index = smaller_index + 1
avg = (Y[smaller_index] + Y[larger_index]) / 2
for i in range(N):
    if X[i] < avg:
        print(Y[larger_index])
    else:
        print(Y[smaller_index])


Measured memory_bytes: 25556
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define ll long long
#define MAX (long long )1e9+7
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define endl "\n"
#define all(A) A.begin(),A.end()





 
int32_t main(){
	ll a,b,c,k;
	cin >> a >> b >> c >> k;
	ll sum = 0;
	if(a >= k){
		sum+=(k*1);
		k = 0;
	}else if(a < k){
		sum+= (a*1);
		k = k-a;
	}
	
	if(b >= k){
		sum+= (k*0);
		k = 0;
	}else if(b < k){
		sum+= (k*0);
		k = k-b;
	}
	
	if(c>=k){
		sum+= (k*(-1));
		k = 0;
	}else if(c < k){
		sum+=(k*(-1));
		k = k-c;
	}
	
	cout << sum << endl;
	return 0;
 
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ll long long
#define maxn 200100
using namespace std;
map <ll, ll > s; //start index, stair top
ll arr[maxn];
int main()
{
	ios_base::sync_with_stdio(false);
	ll n; cin>>n;
	for (ll i = 0; i < n; ++i)
		cin>>arr[i];
	ll farthest_back_start_allowed = 0;
	for (ll i = 0; i < n; ++i)
	{
		ll start = i - arr[i];
		if(start < 0 || start < farthest_back_start_allowed){
			cout<<"-1\n";
			return 0;
		} 
		ll required_end = i;
		s[start] = required_end;
		farthest_back_start_allowed = max(farthest_back_start_allowed, (ll)i - arr[i]);
	}
	long long answer = 0;
	for(map<ll, ll> :: iterator itr = s.begin(); itr != s.end(); itr++){
		ll start = itr -> first;
		ll end = itr -> second;
		answer += (end - start);
	}
	cout<<answer<<endl;
	return 0;
}

Measured memory_bytes: 14336
#include <iostream>
#include <string>

using namespace std;

int main(){
    string S;
    cin >> S;
    if(S.size() == 2){
        cout << S << endl;
    }else if(S.size() == 3){
        for(int i = 2; i >= 0; i--){
            cout << S[i];
        }
        cout << endl;
    }

}

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

int main(){
  string s;
  cin >> s;
  int c = 0;
  for(int i = 0; i < s.size() - 1; i++){
    if(s.at(i) == 'B' && s.at(i+1) == 'W'){
      c++;
    }
    if(s.at(i) == 'W' && s.at(i+1) == 'B'){
      c++;
    }
  }
  cout << c << endl;
}

Measured memory_bytes: 512
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
from bisect import bisect_left

s = input().strip()  # e.g., "contest"
t = input().strip()  # e.g., "son"
# s = "contest"
# t = "son"
# t = "programming"
# t = "sentence"

# 文字と出現位置のマップ
charmap = [[] for _ in range(26)]
for i, ch in enumerate((s + s)):
    charmap[ord(ch) - ord('a')].append(i)

# t を舐めながら答えを探す
ans = p = 0
for ch in t:
    pos_list = charmap[ord(ch) - ord('a')]
    if len(pos_list) == 0:
        print('-1')
        exit(0)

    p = pos_list[bisect_left(pos_list, p)] + 1
    if len(s) <= p:
        ans += len(s)
        p -= len(s)

ans += p
print(ans)


Measured memory_bytes: 13744
#include<cstdio>
#include<algorithm>

using namespace std;

int main(){
	long long q, h, s, d;
	scanf("%lld%lld%lld%lld", &q, &h, &s, &d);
	long long one = min(min(q * 4, h * 2), s);
	long long N;
	scanf("%lld", &N);
	long long ans;
	if(N % 2 == 0){
		ans = min(N / 2 * d, N * one);
	}else{
		ans = min(N / 2 * d + one, N * one);
	}
	printf("%lld\n", ans);
	return 0;
}


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

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

Measured memory_bytes: 256
N = int(input())
S = input()

Rr = 0
Gr = 0
Br = 0
Rl = 0
Gl = 0
Bl = 0

for i in range(1,N):
  if S[i] == "R":
    Rr += 1
  elif S[i] == "G":
    Gr += 1
  else:
    Br += 1

ans = 0
for i in range(N-1):
  if S[i] == "R":
    ans += Gl*Br
    ans += Bl*Gr
    Rl += 1
  elif S[i] == "G":
    ans += Rl*Br
    ans += Bl*Rr
    Gl += 1
  else:
    ans += Rl*Gr
    ans += Gl*Rr
    Bl += 1
    
  if S[i+1] == "R":
    Rr -= 1
  elif S[i+1] == "G":
    Gr -= 1
  else:
    Br -= 1
  
for i in range(1, N-1):
  for k in range(1, min(i, N-1-i)+1):
    if S[i] != S[i+k] and S[i] != S[i-k] and S[i+k] != S[i-k]:
      ans -= 1
  
print(ans)
  
  

  



Measured memory_bytes: 73844
#include<bits/stdc++.h>
#include<time.h>
#include<stdlib.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define pll pair<ll,ll>
#define vll vector<ll,ll>
#define all(a) (a).begin(),(a).end()
#define ff first
#define ss second
#define sz(x) (ll)x.size()
#define hell 1000000007
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>b;i--)
#define lbnd lower_bound
#define ubnd upper_bound
#define bs binary_search
#define gcd(a,b) __gcd((a),(b))
#define EPS 1e-12
#define lcm(a,b) ((a)*(b))/__gcd((a),(b))
#define sqrt sqrtl
#define cbrt cbrtl
using namespace std;

int main()
{
  IOS
  ll n;
  cin>>n;
  ll a[n+5],i;
  for(i=1;i<=n;i++)
  	cin>>a[i];
  sort(a+1,a+n+1);
  double ans=a[1]+a[2];
  ans=ans/(double)2;
  for(i=3;i<=n;i++)
  {
  	 ans=ans+a[i];
  	 ans=ans/(double)2;
  }
  cout<<ans;
  return 0;
}                   

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;
typedef long long ll;
typedef vector<vector<bool>> Graph;

vector<bool> seen;
int n, m;

void dfs(const Graph &g, int v){
	seen[v] = true;
	rep(v2, n){
		if(g[v][v2] == false) continue;
		if(seen[v2]) continue;
		dfs(g, v2);
	}
}

int main() {
	
	
	cin >> n >> m;
	Graph g(n, vector<bool>(m));
	vector<int> a(m), b(m);
	rep(i, m){
		cin >> a[i] >> b[i];
		a[i]--;
		b[i]--;
		g[a[i]][b[i]] = g[b[i]][a[i]] = true;
	}
	int ans = 0;
	rep(i, m){
		// ひとつの辺を取る
		seen.assign(n, false);
		g[a[i]][b[i]] = g[b[i]][a[i]] = false;
		
		// dfsする
		dfs(g, 0);
		
		// 連結かどうか調べる
		bool conected = true;
		rep(j, n) if(!seen[j]) conected = false;
		if(!conected) ans++;
		g[a[i]][b[i]] = g[b[i]][a[i]] = true;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] arrA = new int[m];
		int[] arrB = new int[m];
		for (int i = 0; i < m; i++) {
		    arrA[i] = sc.nextInt() - 1;
		    arrB[i] = sc.nextInt() - 1;
		}
		int count = 0;
		for (int i = 0; i < m; i++) {
		    UnionFindTree uft = new UnionFindTree(n);
		    for (int j = 0; j < m; j++) {
		        if (i == j) {
		            continue;
		        }
		        uft.unite(arrA[j], arrB[j]);
		    }
		    if (!uft.isUnion()) {
		        count++;
		    }
		}
        System.out.println(count);
	}
	
	static class UnionFindTree {
	    int[] parents;
	    
	    public UnionFindTree(int size) {
	        parents = new int[size];
	        for (int i = 0; i < size; i++) {
	            parents[i] = i;
	        }
	    }
	    
	    public int find(int x) {
	        if (parents[x] == x) {
	            return x;
	        } else {
	            return parents[x] = find(parents[x]);
	        }
	    }
	    
	    public void unite(int x, int y) {
	        int xx = find(x);
	        int yy = find(y);
	        if (xx == yy) {
	            return;
	        }
	        parents[xx] = yy;
	    }
	    
	    public boolean isUnion() {
	        int count = 0;
	        for (int i = 0; i < parents.length; i++) {
	            if (i == parents[i]) {
	                count++;
	            }
	        }
	        return count == 1;
	    }
	}
}


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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)


int main()
{
  string sa, sb, sc;
  cin >> sa >> sb >> sc;
  deque<char> qa, qb, qc;
  forll(i, 0, sa.size())
	qa.push_back(sa[i]);
  forll(i, 0, sb.size())
	qb.push_back(sb[i]);
  forll(i, 0, sc.size())
	qc.push_back(sc[i]);

  char next;
  next = qa.front();
  qa.pop_front();
  forll(i, 0, 300){
	
	if (next == 'a'){
	  if (qa.empty()){
		cout << "A" << endl;
		return 0;
	  }
	  next = qa.front();
	  qa.pop_front();
	}else if (next == 'b'){
	  if (qb.empty()){
		cout << "B" << endl;
		return 0;
	  }
	  next = qb.front();
	  qb.pop_front();
	}else if (next == 'c'){
	  if (qc.empty()){
		cout << "C" << endl;
		return 0;
	  }
	  next = qc.front();
	  qc.pop_front();
	}
  }
}


Measured memory_bytes: 256