akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define vll vector<ll>
#define vi vector<int>
#define vvll vector<vll>
#define wh(t) while(t--)
#define fi(n) for(ll i = 0; i < n; i++)
#define fj(n) for(ll j = 0; j < n; j++)
#define fu(i,s,e) for(ll i = s; i <=e; i++)
#define fd(i,s,e) for(ll i = s; i >=e; i--)
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define fr first
#define se second
#define sll stack<ll>
#define qll queue<ll>
using namespace std;
const ll M = 1e9+7;
//const ll M = 998244353;

ll pmp(ll x,ll n){ll a = 1;while(n > 0){if(n & 1) a = (a * x)%M;x = (x * x)%M;n = n>>1;}return a;}

void solve(){
	char a;
	cin >> a;
	if(a>='a'&&a<='z') cout << 'a' << endl;
	else cout << 'A' << endl;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// #endif
	ll t;
	t = 1;
	// cin >> t;
	wh(t){
		solve();
	}
	cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
	return 0;
}

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

int main()
{
    ll N; cin>>N;
    vector<ll> p(N);
    rep(i,0,N)cin>>p[i];
    sort(p.begin(),p.end());

    ll sum=p[p.size()-1]/2;
    rep(i,0,N-1)sum+=p[i];
    
    cout<<sum<<endl;    
    return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

const DXY: [(i64, i64); 8] = [(1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)];

use std::io::{stdout, Write, BufWriter};

fn main() {
    input! {
        h: i64,
        w: i64,
        map: [String; h as usize],
    }
    let out = stdout();
    let mut out = BufWriter::new(out.lock());

    let mut map = map.iter().map(|s| s.bytes().map(|b| if b == b'.' { b'0' } else { b } ).collect::<Vec<u8>>()).collect::<Vec<_>>();
    for i in 0..h {
        for j in 0..w {
            if map[i as usize][j as usize] == b'#' { continue; }
            for &(dx, dy) in DXY.iter() {
                let (y, x) = (i + dy, j + dx);
                if 0 <= x && x < w && 0<= y && y < h && map[y as usize][x as usize] == b'#' { map[i as usize][j as usize] += 1; }
            }
        } 
    }

    for r in map { writeln!(out, "{}", String::from_utf8(r).unwrap()).unwrap(); }
}


Measured memory_bytes: 4352
package main
import "fmt"

func main() {
  var(
    status string
    out = []string{"Sunny", "Cloudy", "Rainy"}
  )
  fmt.Scan(&status)
  
  switch status {
    case out[0]:
        fmt.Println(out[1])
    case out[1]:
        fmt.Println(out[2])
    case out[2]:
        fmt.Println(out[0])
  }
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back

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

const ll MOD = 1e9 + 7;
int n, x, y;
vector<int> G[100009];
ll dp[100009][2];  // 0 - white, 1 - black
int vis[100009];

void solve(int v)
{
    vis[v] = 1;

    dp[v][0] = 1;
    dp[v][1] = 1;

    for (int i = 0; i < G[v].size(); i++)
    {
        int w = G[v][i];

        if (vis[w] == 0)
        {
            solve(w);
            dp[v][0] *= (dp[w][0] + dp[w][1]);
            dp[v][1] *= (dp[w][0]);

            dp[v][0] %= MOD;
            dp[v][0] += MOD;
            dp[v][0] %= MOD;

            dp[v][1] %= MOD;
            dp[v][1] += MOD;
            dp[v][1] %= MOD;
        }
    }

    return;
}

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

    cin >> n;
    for (int i = 1; i <= n - 1; i++)
    {
        cin >> x >> y;

        G[x].pb(y);
        G[y].pb(x);
    }

    solve(1);

    ll ans = dp[1][0] + dp[1][1];
    ans += MOD;
    ans %= MOD;

    cout << ans << "\n";
}

Measured memory_bytes: 18004
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  int i=1;
  if(i==a){
    i=2;
    if(i==b){
      i=3;
    }
  }
  if(i==b){
    i=2;
    if(i==a){
      i=3;
    }
  }
  cout << i;
}


Measured memory_bytes: 256
n=int(input())
a=[]
b=[]
for i in range(n):
    c,d=map(int,input().split())
    a.append(c)
    b.append(d)
a.sort()
b.sort()

if n%2==1:
    ans=b[n//2]-a[n//2]+1
else:
    ans=(b[(n-1)//2]+b[n//2])-(a[(n-1)//2]+a[n//2])+1
    
print(ans)


Measured memory_bytes: 98996
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>


using namespace std;


int main()
{
	char v[5];
	int ans=1;
	
	for(int i=0;i<4;i++){
		cin >> v[i];
	}
	
	for(int i=0;i<3;i++){
		if(v[i] == v[i+1]) ans = 0;
	}
	
	if(ans == 0)cout << "Bad" << endl;
	else cout << "Good" << endl;
	
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lli;
typedef double lld;
#define mod 1000000007
#define mod2 998244353
#define fori(n) for (int i = 0; i < n; i++)
#define forj(n) for (int j = 0; j < n; j++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
template <typename T, typename U>ostream &operator<<(ostream &out, const pair<T, U> &p){out << "(" << p.first << ", " << p.second << ")";return out;}
template <template <typename, typename...> class ContainerType, typename ValueType, typename... Args>void print(const ContainerType<ValueType, Args...> &c){for (const auto &v : c)cout << v << ' ';cout << '\n';} void print(){cout<<'\n';}
template <typename T, typename... Args>void print(T a, Args... args){cout << a << " ";print(args...);}
lli llipower(lli x, lli y, lli p = LLONG_MAX){lli res = 1;x = x % p;while (y > 0){if (y & 1)res = (res * x) % p;y = y >> 1;x = (x * x) % p;}return res;}

//8====================================D
int main(){
    int n,x;
    cin>>n;
    vector<int> a(1e6+5,0);
    vector<int> b;
    fori(n){
     
        cin>>x;
        b.pb(x);
        a[x]++;
    }
    int ans=n;
    for(int i:b){
        bool flag=true;

        for(int j=2;j*j<=i;j++){
        
            if(i%j==0){
               
                if (a[i / j] || a[j])
                {

                    flag = false;
                    break;
                }
            }
            
          
            
        }
        if (a[1] && i!=1)
        {

            flag = false;
            
        }

        if (a[i] > 1)
        {
            flag = false;
            
        }
        if(!flag) ans--;
    }
    
    cout<<ans<<endl;


}

Measured memory_bytes: 8228
n = int(input())
s = []
for i in range(n):
  s.append(input())
s.sort()
k = 0
f = s
mk = 0
for i in range(n-1):
  if s[i] == s[i+1]:
    k = k+1
    if k == mk :
      mk = k
      f.append(s[i])
    elif k > mk :
      mk = k
      f = [s[i]]
  else:
    k = 0
for i in range(len(f)):
  print(f[i])

Measured memory_bytes: 18628
#086_C
n = int(input())
txy =[(0, 0, 0)] + [tuple(map(int, input().split())) for _ in range(n)]

flg = True
for i in range(n):
    ti, xi, yi = txy[i]
    tj, xj, yj = txy[i+1]
    if abs(xj-xi) + abs(yj-yi) > tj - ti:
        flg = False
        break
    elif (tj - ti - abs(xj-xi) - abs(yj-yi)) % 2:
        flg = False
        break
print('Yes' if flg else 'No')

Measured memory_bytes: 18160
#include <stdio.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int N, T, E, x[128];

bool ok(int t) {
    return T-E <= t && t <= T+E;
}

int solve() {
    rep (i, N) {
        int t = T/x[i]*x[i];
        if (ok(t) || ok(t+x[i])) return i+1;
    }
    return -1;
}

int main() {
    scanf("%d%d%d", &N, &T, &E);
    rep (i, N) scanf("%d", x+i);
    printf("%d\n", solve());
    return 0;
}

Measured memory_bytes: 1028
#include "bits/stdc++.h"
using namespace std;
using lint = long long;
#define low lower_bound
#define upp upper_bound
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define Rep(i, n) for (int i = int(n); i >= 0; --i)
#define all(vec) (vec).begin(), (vec).end()
#define cend printf("\n");
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define prique2(T) priority_queue<T>

struct edge { lint to, cost; };
using P = pair<lint, lint>;
using D = pair<double, double>;
//const lint mod = 998244353LL;
const lint mod = 1000000007LL;
const lint inf = 3e18;

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

lint modpow(lint x, lint n) {
	lint ans = 1;
	while (n > 0) {
		if (n & 1) {
			ans *= x;
			if (mod <= ans) ans %= mod;
		}
		x *= x;
		if (mod <= x) x %= mod;
		n >>= 1;
	}
	return ans;
}

lint fact[1000000];
void f_init(lint n) {
	if (1000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (lint i = 2; i <= n; ++i) {
		fact[i] = i * fact[i - 1];
		if (mod <= fact[i]) fact[i] %= mod;
	}
	return;
}

lint comb(lint n, lint r) {
	if (n < r) return 0;
	if (n == r) return 1;
	lint ans = fact[n] * modpow(fact[n - r], mod - 2) % mod * modpow(fact[r], mod - 2);
	if (ans < 0) return ans + mod;
	return ans;
}

lint nck[1010][1010];
void comb(lint n) {
	rep(i, n + 1) {
		rep(j, i + 1) {
			if (j == 0 || i == j) nck[i][j] = 1;
			else nck[i][j] = nck[i - 1][j - 1] + nck[i - 1][j];
		}
	}
}

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

lint lcm(lint a, lint b) { return a / gcd(a, b) * b; }

bool pri(lint p) {
	for (lint i = 2LL; i * i <= p; ++i) if (p % i == 0) return false;
	return p > 1LL;
}

map<lint, lint> factring(lint n) {
	map<lint, lint>ans;
	for (lint i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++ans[i];
		}
	}
	if (n != 1) ++ans[n];
	return ans;
}

double dis(D a, D b) { return sqrt((a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second)); }

int n,l,r,ans;
string s;
int main() {
	cin>>s;
	n=s.size();
	r=n-1;
	while(true) {
		if(s[l]==s[r]) {
			++l; --r;
		}
		else {
			if(s[l]=='x') ++l;
			else if(s[r]=='x') --r;
			else {
				printf("-1\n");
				return 0;
			}
			++ans;
		}
		if(l>r) break;
	}
	cout<<ans<<endl;
}


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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

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

    int mod = 1e9 + 7;
    vector<vector<int>> dp(N + 1, vector<int>(K + 1));
    dp[0][0] = 1;

    for(int i = 0; i < N; i++) {
        vector<int> imos(K + 2);
        for (int j = 0; j <= K; j++) {
            if (j + A[i] + 1 <= K + 1) {
                imos[j + A[i] + 1] += mod - dp[i][j];
                imos[j + A[i] + 1] %= mod;
            }
            imos[j] += dp[i][j];
            imos[j] %= mod;
        }
        int sum = 0;
        for (int j = 0; j <= K; j++) {
            sum += imos[j];
            sum %= mod;
            dp[i + 1][j] = sum;
        }
    }

    cout << dp[N][K] << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

Measured memory_bytes: 40192
#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define SREP(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)

//printf
#define PRINTD(d) printf("%d\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9

typedef long long ll;
int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int Max(int a, int b) {
	return (a) > (b) ? (a) : (b);
}

int main() {
	char s[3][4];
	REP(i, 3) {
		scanf("%s", s[i]);
	}
	printf("%c%c%c\n", s[0][0], s[1][1], s[2][2]);
}

Measured memory_bytes: 128
#include<stdio.h>

int main(){
  int n,a,b,flag=0;
  scanf("%d %d %d",&n,&a,&b);
  while(b-a!=1){
    if(flag){
      b--;
      flag=0;
    }
    else{
      a++;
      flag=1;
    }
  }
  if(flag)  printf("Alice\n");
  else printf("Borys\n");
}

Measured memory_bytes: 256
import math

N=int(input())
#print(list(N))
digits=len(str(N))
cnt=-(-digits//2)
#print(cnt)


ans=0
for i in range(cnt):
    ans+=10**(i*2+1)-10**(i*2)
print(ans if digits%2==0 else ans-(10**(digits)-N)+1)

Measured memory_bytes: 3060
<?php
list($sx,$sy,$tx,$ty) = explode(" ",trim(fgets(STDIN)));
$dx = $tx - $sx;
$dy = $ty - $sy;

$u = str_repeat("U",$dy);
$r = str_repeat("R",$dx);
echo $u;
echo $r;


$d = str_repeat("D",$dy);
$l = str_repeat("L",$dx);
echo $d;
echo $l;

echo "LU";
echo $u;
echo $r;
echo "RD";

echo "RD";
echo $d;
echo $l;
echo "LU";

?>


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

#define int long long

#define inf 1000000007LL
#define mod 1000000007LL

#define rep(i, n) for(int i = 0; i < (n); i++)
#define trep(i, n) for(int i = 0; i <= (n); i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define mfor(i, s, t) for(int i = (s); i < (t); i++)
#define tfor(i, s, t) for(int i = (s); i <= (t); i++)
#define rfor(i, s, t) for(int i = (t) - 1; i >= (s); i--)

int pre[26];
int all[26];

signed main() {
  string s;
  cin >> s;
  rep(i, 26) {
    pre[i] = -1;
    all[i] = 0;
  }
  rep(i, s.size()) {
    int x = s[i] - 'a';
    all[x] = max(all[x], i - pre[x]);
    pre[x] = i;
  }
  rep(i, 26) {
    all[i] = max(all[i], (int)s.size() - pre[i]);
  }
  int ans = inf;
  rep(i, 26) {
    ans = min(ans, all[i]);
  }
  cout << ans - 1 << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;

int main(){
    string s;
    cin >> s;
    for (int i=0; i<s.size(); i++) {
        if ((i+1)%2==1) {
            cout << s.at(i);
        }
    } 
    cout << endl;
 }

Measured memory_bytes: 888
H, W = map(int, input().split())
S = [input() for _ in range(H)]

ret = [[0] * W for _ in range(H)]
for y in range(H) :
    for x in range(W) :
        if S[y][x] == '#' :
            for yy in range(max(0, y-1), min(H, y+2)) :
                for xx in range(max(0, x-1), min(W, x+2)) :
                    if S[yy][xx] != '#' :
                        ret[yy][xx] += 1
                    else :
                        ret[yy][xx] = '#'
for i in range(H) :
    s = ''.join(map(str, ret[i]))
    print(s)

Measured memory_bytes: 42352
#include <iostream>

using namespace std;

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

	int a,resultA = 0;

	for (int i = 0; i < n; i++) {
		cin >> a;
		resultA += a;
	}

	if (resultA >= h) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rep1(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep1(i, s, n) for (int i = (s); i >= (n); i--)

int main()
{
	int N, tmp, swap = 0;


	cin >> N;
	vector<int> A(N);
	rep(i, N) cin >> A[i];

	rep(i, N) {
		rrep1(j, N - 1, i + 1) {
			if (A[j] < A[j - 1]) {
				swap++;
				tmp = A[j];
				A[j] = A[j - 1];
				A[j - 1] = tmp;
			}
		}
	}

	rep(i, N - 1) cout << A[i] << " ";
	cout << A[N - 1] << endl;
	cout << swap << endl;

	return 0;
}



Measured memory_bytes: 3116
#include<bits/stdc++.h>          
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
#define mk_p(a,b)	make_pair((a),(b))
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;

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

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,k;
	cin >> n >> k;
	cout << ((n - 1) + (k - 1) - 1)/ (k - 1) << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <array>
#include <vector>

using namespace std;

int main() {

  while ( true ) {
	int n;
	cin >> n;
	if ( n == 0 ) break;

	array<int, 10> hist;
	hist.fill( 0 );
	for ( int i = 0; i < n; i++ ) {
	  int elem;
	  cin >> elem;
	  hist[ elem ]++;
	}
	for ( const int num : hist ) {
	  if ( num > 0 ) {
		for ( int i = 0; i < num; i++ ) {
		  cout << "*";
		}
		cout << endl;
	  } else {
		cout << "-" << endl;
	  }			   
	}
  }  
}

Measured memory_bytes: 1152
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int mod = 1000000007;

int main(){
    ll w,h,x,y;
    cin>>w>>h>>x>>y;
    double ans = (w*h)/2.0;
    ll k;
    if((w/2.0==x) && (h/2.0==y)) k=1;
    else k=0;
    cout<<ans<<" "<<k<<endl;
}


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

using namespace std;

void solve(void)
{
	long n, k, s = 0;
	cin >> n >> k;
	vector<long> as(n), ps;
	for (int i = 0; i < n; i++)
	{
		cin >> as[i];
		s += as[i];
	}
	for (long f = 1; f * f <= s; f++)
	{
		if (s % f == 0)
		{
			ps.push_back(f);
			if (f * f != s) ps.push_back(s/f);
		}
	}
	sort(ps.rbegin(), ps.rend());
	int m = ps.size();
	for (int i = 0; i < m; i++)
	{
		long f = ps[i];
		if (f == 1)
		{
			cout << f << endl;
			return;
		}
		vector<pair<long, long>> xs(n);
		for (int j = 0; j < n; j++)
		{
			long x = as[j] / f * f;
			xs[j] = make_pair(as[j] - x, f - (as[j] - x));
		}
		sort(xs.begin(), xs.end());
		for (int l = 0; l < n; l++)
		{
			long cnt1 = 0, cnt2 = 0;
			for (int j = 0; j < l; j++)
			{
				cnt1 += xs[j].first;
			}
			for (int j = l; j < n; j++)
			{
				cnt2 += xs[j].second;
			}
			//cout << cnt1 << ' ' << cnt2 << endl;
			if (cnt1 == cnt2 && cnt1 <= k)
			{
				cout << f << endl;
				return;
			}
		}
	}
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


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

using namespace std;

#define all(c) ((c).begin()),((c).end())
#define debug(c) cerr<<"> "<<#c<<" = "<<(c)<<endl;
#define iter(c) __typeof((c).begin())
#define tr(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back

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

int main(){
	for(int n, r; cin >> n >> r, (n | r) != 0; ) {
		vi cards(n);
		rep(i, n) cards[i] = n - i;
		rep(i, r) {
			int p, c; cin >> p >> c;
			rotate(cards.begin(), cards.begin() + p - 1, cards.begin() + p + c - 1);
		}
		cout << cards.front() << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
 


public class Main {
	private static Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static long mod =1000000007;
	//static 	ArrayList<Integer> cc = new ArrayList<>(100);
	static int N;
	public static void main(String[] args) {
		//0 48 || 1 49 || B 66
		int N=sc.nextInt();
		int K=sc.nextInt();
		
		int a[]=new int[N];
		
		int t=-1;
		
		for(int i=0;i<N;i++) {
			a[i]=sc.nextInt();
			if(a[i]==1)t=i;
		}
		int ans=0;
		int g=0;
		while(true) {
			ans++;
			g+=K;
			if(g>=N)break;
			g--;
		}
		p(ans);
		
		
		
		
	}
	static int a,b,c;
	
	
	
	
	/*static boolean v(int i,long sum1,long sum2) {
		if(i==N) {
			long b=Math.abs(sum1-sum2);
			if(b==0) {
				if(sum1<=K) {
					return true;
				}else return false;
			}else if(b%D==0) {
				if(Math.max(sum1, sum2)<=K)return true;
				else return false;
			}
			else return false;
		}
		
		if(v(i+1,sum1,sum2+v[i]%D))return true;
		
		if(v(i+1,sum1+D-v[i]%D,sum2))return true;
		return false;
		
	}*/
	
	
	
	
	

	


	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	public static int gcd(int a, int b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


Measured memory_bytes: 52256
import java.util.*;

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

        if (a == 1) {
            if (b == 2) {
                System.out.println(3);
            } else {
                System.out.println(2);
            }
        } else if (a == 2) {
            if (b == 1) {
                System.out.println(3);
            } else {
                System.out.println(1);
            }
        } else {
            if (b == 1) {
                System.out.println(2);
            } else {
                System.out.println(1);
            }

        }

    }
}


Measured memory_bytes: 21844
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

# 各森の最小値を使う
# 後は全体から最小値を順に取ってくればよい

class UF(object):
    def __init__(self,n):
        self.par = [i for i in range(n)]
        self.rank = [0]*n
        self.size = [1]*n

    # x が属する集合の代表値を返す
    def find(self,x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # x と y の集合を結合する
    def union(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]

    # x と y が同じ集合に属するか判定する
    def is_same(self,x,y):
        return self.find(x) == self.find(y)

    # x が属する集合の要素数を返す
    def get_size(self,x):
        x = self.find(x)
        return self.size[x]

N,M = LI()
a = LI()
x,y = LIR(M,2)

uf = UF(N)
for i in range(M):
    uf.union(x[i],y[i])

d = defaultdict(list)
for i in range(N):
    d[uf.find(i)].append(a[i])

for g in d.values():
    g.sort(reverse=True)

if 2*(len(d)-1) > N:
    print('Impossible')
else:
    if len(d) == 1:
        print(0)
        exit()
    ans = 0
    num = 0
    for gr in d.values():
        ans += gr.pop()
        num += 1
    left = []
    for gr in d.values():
        left.extend(gr)
    left.sort()
    for i in range(2*(len(d)-1)-num):
        ans += left[i]
    print(ans)

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

typedef long long i64;
typedef pair<int, int> ii;
typedef pair<i64, i64> ll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<vi> vvi;

#define fastIO() ios_base::sync_with_stdio(0), cin.tie(0)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ms(a, x) memset(a, x, sizeof(a))
#define len(x) (x).size()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

const double eps = 1e-9;
const double pi = acos(-1.0);
const int inf = 1e9;
const int maxn = 2e5+5;
const int mod = 1e9+7;

int main() {
    fastIO();
    int x; cin >> x;
    cout << (x>=30?"Yes\n":"No\n");
    return 0;
}



Measured memory_bytes: 3648
from functools import reduce
import fractions
n, m = map(int, input().split())
a = [int(x)//2 for x in input().split()]

y = a[0]

for i in range(1,n):
    y = y*a[i] // fractions.gcd(y,a[i])
    if y > m:
        print(0)
        exit()

for i in range(n):
    if (y // a[i]) % 2 == 0:
        print(0)
        exit()

x = m//y

if x % 2 == 0:
    print(x//2)
else:
    print((x+1)//2)


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


Measured memory_bytes: 63600
//Created by Kira

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

#define IOS cin.sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pii pair<int,int> 
#define pb push_back
#define vi vector<int> 
using ll = long long;

const int mod = 1e9 + 7;

ll pwr(ll a, ll b);
    



int main(){
   IOS

   int n, r; cin>>n>>r;

   if(n >= 10){
       cout<<r<<"\n";
   }else{
       cout<<r + 100*(10-n)<<"\n";
   }


   














}

ll pwr(ll a, ll b){
   a %= mod;	//Remove mod if not required
   ll res = 1;
   while(b > 0){
    if(b&1)
        res = res * a % mod;
        a = a * a % mod;
    b >>= 1;
    }

    return res;
}



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

typedef long long ll;

int main() {
    vector<bool> prime(55556, true);
    prime[0] = false;
    prime[1] = false;
    for (int i = 2; i * i <= 55555; i++) {
        if (prime[i]) {
            for (int j = i * 2; j <= 55555; j += i) {
                prime[j] = false;
            }
        }
    }
    //rep(i, 55556) if (prime[i]) cout << i << " ";
    //vector<int> count(5, 0);
    //rep(i, 55556) if (prime[i]) count[i % 5]++;
    //rep(i, 5) cout << count[i] << "\n";
    vector<int> ans;
    rep(i, 55556) if (prime[i] && i % 5 == 1) ans.push_back(i);
    int N;
    cin >> N;
    rep(i, N) {
        cout << ans[i];
        if (i == N - 1) cout << "\n";
        else cout << " ";
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

int main() {
	string s;
	cin >> s;
	int mode = 0;
	REP(i,0,s.size()) {
		if (mode == 0 && s[i] == 'C') mode = 1;
		else if (mode == 1 && s[i] == 'F') mode = 2;
	}
	if (mode == 2) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
int W,H,x,y,r;
cin >> W >> H >> x >> y >>r;
if (x-r<0 || x+r>W) cout << "No" <<endl;
else if (y-r<0 || y+r>H) cout << "No" <<endl;
else cout << "Yes" <<endl;
return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <cstdio>

using namespace std;

string s;

int main()
{
    cin>>s;
    if(s == "AAA" || s == "BBB")
    {
        cout<<"No"<<endl;
    }
    else
    {
        cout<<"Yes"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdio>
#include<stdio.h>
#include<cmath>
#include<math.h>
#include<vector>
#include<set>
#include<queue>
#include<map>
#define forn(i,n) for(int (i)=0;i<(n);i++)
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int>pii;
typedef long long ll;
typedef pair<ll,ll> pll;
const int MAXN=200005;
const int INF=2147483647;
const ll LINF=9223372036854775807;
const int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
set<int>st;
int n;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	forn(i,n)
	{
		int x;
		cin>>x;
		st.insert(x);
	}
	if(st.size()==n)cout<<"YES";
	else cout<<"NO";
	return 0;
}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
int main()
{

    long long a,b,c,d,e,f,g,h,i,j,k,l;
    cin>>a>>b;
    map<long long ,long long>mp;
    while(b--)
    {
        cin>>d;
        for(i=1;i<=d;i++)
        {
            cin>>e;
            mp[e]++;
        }
    }
    k=a-mp.size();
    cout<<k<<endl;




}


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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

template<class T> T gcd(const T& a,const T& b){ return b==0?a:gcd(b,a%b); }
template<class T> T lcm(const T& a,const T& b){ return a/gcd(a,b)*b; }

int main(){
	lint n,m;
	string s,t; cin>>n>>m>>s>>t;

	if(n>m){
		swap(n,m);
		swap(s,t);
	}

	lint g=gcd(n,m);
	rep(i,g) if(s[n/g*i]!=t[m/g*i]) return puts("-1"),0;
	cout<<lcm(n,m)<<'\n';

	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <queue>

using namespace std;

int main(){
    int A[6],B[6],j=0,min=0;
    B[0]=0;
    string checker("9");
    for(int i=0;i<5;i++){
        cin>>A[i];
    }
    int time=0;
    for(int i=0;i<5;i++){
        if(A[i]%10==0){
            time+=A[i];
        }else{
            string S=to_string(A[i]);
            reverse(S.begin(),S.end());
            int check1=S[0]-48;
            int check2=stoi(checker);
            if(check2>check1){
                checker.pop_back();
                checker.push_back(S[0]);
                min=j;
            }
            B[j]=A[i];
            j++;
        }
    }
    for(int i=0;i<j;i++){
        if(i!=min){
            for(int k=0;k<=13;k++){
                if(time+k*10>time+B[i]){
                    time+=k*10;
                    break;
                }
            }
        }
    }
    time+=B[min];
    cout<<time<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

int n,k;
ll h[310],dp[310][310][310];

void solve(){
    cin >> n >> k;
    rep(i,n){
        cin >> h[i+1];
    }
    rep(i,n+1){
        rep(j,n+1){
            rep(l,k+1){
                dp[i][j][l]=INF;
            }
        }
    }
    dp[0][0][0]=0;
    rep(i,n){
        rep(l,min(i+1,k)){
            rep(j,i+1){
                dp[i+1][j][l+1]=min(dp[i+1][i+1][l+1],dp[i][j][l]);
            }
        }
        rep(l,min(i+1,k+1)){
            rep(j,i+1){
                dp[i+1][i+1][l]=min(dp[i+1][i+1][l],dp[i][j][l]+max(h[i+1]-h[j],0ll));
            }
        }
    }
    ll ans=INF;
    rep(j,n+1){
        rep(l,k+1){
            ans=min(ans,dp[n][j][l]);
        }
    }
    rep(i,n+1){
        rep(j,n+1){
            rep(l,k+1){
                if (dp[i][j][l]==INF) continue;
                //cout << i << " " << j << " " << l << " " << dp[i][j][l] << endl;
            }
        }
    }
    cout << ans << endl;
}

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

Measured memory_bytes: 227712
#include <iostream>
#include <string>
#include <algorithm>
#include  <set>
#include <cmath>
using namespace std;
typedef long long ll;
#define rep(i,k) for(i=0;i<k;i++)

int main() {
ll  a, b, c, d, e, f, g,  i, j, k, m, l;
	ll v[100],h ;
	double n, u[10],sum;
	cin >> n;
	sum = 0;
	string ss[10];

	rep(i, n) {
		cin >> u[i] >> ss[i];
		if (ss[i] == "JPY")sum += u[i];
		else sum += u[i] * 380000;
	}
		

	cout << sum;


	return 0;
}

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

using namespace std;
typedef long long ll;

int dfs(int source, vector<vector<int> >& adj, vector<int> &dp) {
  if(dp[source]!=-1)
    return dp[source];
  
  int res=0;
	for(int neighbour: adj[source]) {
    	res = max(res, 
                  1 + dfs(neighbour, adj, dp));
    }
  dp[source] = res;
  return res;
}

int main() {
  	int N, M, u, v;
	  
  	cin>>N>>M;
 
  	vector<vector<int> >  adj(N, vector<int>(0));
  	vector<int> dp(N, -1);
  
  	for(int i=0;i<M;i++) {
    	cin>>u>>v;
      	adj[u-1].push_back(v-1);
    }
  	int res=0;
  	for(int i=0;i<N;i++)
      res = max(res, dfs(i, adj, dp));
  	cout<<res;
}



Measured memory_bytes: 8832
#include <bits/stdc++.h>
using namespace std;
int main() {
  deque<int> deq;
  int n;
  cin >> n;
  string command;
  int x;
  for(int i = 0;i < n;i++){
    cin >> command;

    if(command == "insert"){
      cin >> x;
      deq.push_front(x);
    }
    if(command == "delete"){
      cin >> x;
      for(int j = 0;j < deq.size();j++){
        if(deq[j] == x){
          deq.erase(deq.begin()+j);
          break;
        }
      }
    }
    if(command == "deleteFirst"){
      deq.pop_front();
    }
    if(command == "deleteLast"){
      deq.pop_back();
    }
  }
  for(int i = 0;i < deq.size();i++){
    cout << deq[i];
    if(i != deq.size()-1)cout << " ";
  }
  cout << endl;
}



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

int main() {
    int n,m,x;
    cin>>n>>m>>x;
    
    int a[m];
    int i;
    for(i=0; i<m; i++){
        cin>>a[i];
    }
    
    int cost_0=0;
    int cost_n=0;
    
    int j=0;
    while(a[j]<x){
        cost_0++;
        j++;
    }
    cost_n = m-cost_0;
    
    if(cost_0<cost_n){
        cout<<cost_0;
    }else{
        cout<<cost_n;
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::HashSet;
use std::cmp;
use std::f64::consts;

fn main() {
    let n: i32 = read();
    let start: i32 = read();

    let vec: Vec<i32> = (0..n).map(|_| read()).collect();
    let mut diff_vec: Vec<i32> = Vec::new();

    for &i in vec.iter() {
        let diff: i32 = (start - i).abs();
        diff_vec.push(diff);
    }

    let mut ans: i32 = 0;
    for (i, &e) in diff_vec.iter().enumerate() {
        if i == 0 {
            ans = e as i32;
        } else {
            ans = gcd(ans, e);
        }
    }

    println!("{}", ans);
}

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

// 最大公約数
fn gcd(a: i32, b: i32) -> i32 {
    match b {
        0 => a,
        _ => gcd(b, a % b)
    }
}

// 最小公倍数
fn lcm(a: i32, b: i32) -> i32 {
    a * b / gcd(a, b)
}


Measured memory_bytes: 4352
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <climits>
#include <sstream>
#include <cstdio>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;


int ans;
set<string> memo;
queue<string> q;
bool na;

void bfs(){
	//cout<<ans<<endl;
	queue<string> nq;
	
	while(!q.empty()){
		string ss=q.front();q.pop();
		if(memo.count(ss)){
			//cout<<ss<<" finded"<<endl;
			continue;
		}
		//cout<<ss<<endl;
		memo.insert(ss);
		bool end=true;
		for(int i=0;i<ss.size()-1;i++)if(ss[i]!=ss[i+1])end=false;
		if(end){
			//cout<<ss<<" "<<ans<<endl;
			return ;
		}

		for(int i=0;i<ss.size()-1;i++){
			if(ss[i]!=ss[i+1]){
				string sss(ss);
				if(ss[i]!= 'r' && ss[i+1]!='r')sss[i]=sss[i+1]='r';
				if(ss[i]!= 'g' && ss[i+1]!='g')sss[i]=sss[i+1]='g';
				if(ss[i]!= 'b' && ss[i+1]!='b')sss[i]=sss[i+1]='b';
				nq.push(sss);
			}
		}
	}
	if(!nq.empty()){
		++ans;
		q=nq;
		bfs();
	}else na=true;
}


main(){
	string ss;
	while(cin>>ss){
		if(ss[0]=='0')break;
		ans=0;
		na=false;
		memo.clear();
		while(!q.empty())q.pop();
		q.push(ss);
		bfs();
		if(na)cout<<"NA"<<endl;
		else cout<<ans<<endl;
	}
}

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

using lint = long long;
int main(){
    lint H;
    lint N;
    lint sumA=0;
    lint tempA;
    cin >> H >> N;
    for(lint i=0;i<N;i++){
        cin >> tempA;
        sumA += tempA;
    }
    if(H <= sumA){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
n = int(input())
l = list(map(int,input().split()))

flag1 = True
flag2 = True
flag3 = True
flag4 = True
flag5 = True
flag6 = True
flag7 = True
flag8 = True

Max = 0
Min = 0

for value in l:
	if 1 <= value and value < 400 and flag1 == True:
		flag1 = False
		Max += 1
		Min += 1
	elif 400 <= value and value < 800 and flag2 == True:
		flag2 = False
		Max += 1
		Min += 1
	elif 800 <= value and value < 1200 and flag3 == True:
		flag3 = False
		Max += 1
		Min +=1
	elif 1200 <= value and value < 1600 and flag4 == True:
		flag4 = False
		Max += 1
		Min += 1
	elif 1600 <= value and value < 2000 and flag5 == True:
		flag5 = False
		Max += 1
		Min += 1
	elif 2000 <= value and value < 2400 and flag6 == True:
		flag6 = False
		Max += 1
		Min += 1
	elif 2400 <= value and value < 2800 and flag7 == True:
		flag7= False
		Max += 1
		Min += 1
	elif 2800 <= value and value < 3200 and flag8 == True:
		flag8 = False
		Max += 1
		Min += 1
	elif 3200 <= value and value <= 4800:
		Max += 1

if Min == 0:
	Min = 1

print(str(Min) + " " + str(Max))


Measured memory_bytes: 3064
import itertools

int1 = lambda x: int(x) - 1

H, W, N = map(int, input().split())
B = set(tuple(map(int1, input().split())) for _ in range(N))

adj = (-1, 0, 1)
visited = set()
ans = [0] * 10
for a, b in B:
    for dy, dx in itertools.product(adj, repeat=2):
        if not (1 <= a + dy < H - 1 and 1 <= b + dx < W - 1):
            continue
        elif (a + dy, b + dx) in visited:
            continue
        visited.add((a + dy, b + dx))
        c = 0
        for ddy, ddx in itertools.product(adj, repeat=2):
            if (a + dy + ddy, b + dx + ddx) in B:
                c += 1
        ans[c] += 1
ans[0] = (H - 2) * (W - 2) - sum(ans[1:])
for x in ans:
    print(x)


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

using namespace std;

int main (){
	string s;
	cin >> s;
	int n;
	cin >> n;
	string str;int ans=0;
	for (int i=0;i<n;i++){
		cin >> str;
		str+=str;
		for (int j=0;j<10;j++){
			if (str.substr(j,s.size ())==s){
				ans++;break;}
		        }
		    }
		    cout << ans<< endl;
		    return 0;
}		        		


Measured memory_bytes: 3228
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

using System.Collections;

class Program
{
    static void Main()
    {
        string S = Console.ReadLine();

        long K = long.Parse(Console.ReadLine());

        //2は、5000兆日後には2の5000兆乗の長さになる。
        //つまり、2以上も、5000兆日後にはnの5000兆乗の長さになる。

        //Kはせいぜい1以上10^18以下



        //文字列中の、最初の1が連続する部分の長さ
        var xxx = S.TakeWhile(itm => itm == '1').Count();

        //1が連続する部分の次の文字
        var yyy = S.SkipWhile(itm => itm == '1').Take(1);

        if (K <= xxx)
        {
            Console.WriteLine(1);
        }
        else
        {
            Console.WriteLine(yyy.Single());
        }
    }
}



static class MathUtil
{
    public static IEnumerable<IEnumerable<int>> GetPermutation(int n)
    {
        if (n == 0)
        {
            yield return Single(0);
            yield break;
        }

        for (int i = 0; i <= n; i++)
        {
            foreach (var x in GetPermutation(n - 1))
            {
                yield return Single(i).Concat(x.Select(itm => itm < i ? itm : itm + 1));
            }
        }
    }

    private static IEnumerable<int> Single(int x)
    {
        yield return x;
    }

    public static IEnumerable<int> EnumeratePrimeNumbers()
    {
        List<int> primes = new List<int>() { 2 };
        yield return 2;

        for (int i = 3; i < int.MaxValue; i++)
        {
            bool isPrime = true;
            int Sqrt = (int)Math.Sqrt(i) + 1;

            foreach (var prime in primes)
            {
                if (prime > Sqrt)
                {
                    break;
                }
                if (i % prime == 0)
                {
                    isPrime = false;
                    break;
                }
            }

            if (isPrime)
            {
                primes.Add(i);
                yield return i;
            }
        }
    }
}


Measured memory_bytes: 11348
#include <stdio.h>

int main(){
  int N,i,j,v;
  
  scanf("%d",&N);
  int A[N];

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

  
  for(i=1;i<N;++i){
    for(j=0;j<N-1;++j) printf("%d ",A[j]);
    printf("%d",A[N-1]);
    printf("\n");
    v=A[i];
    j = i - 1;
    while (j>= 0 && A[j] > v){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
  }

  for(j=0;j<N-1;++j) printf("%d ",A[j]);
  printf("%d",A[N-1]);

  printf("\n");
  return 0;
}



Measured memory_bytes: 2056
#include <iostream>
#include <vector>

using std::cin;
using std::cout;
using std::endl;
using std::vector;

int main(int argc, char* argv[]) {
  int n;
  cin >> n;

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

  double denom = 0;
  for (int b : a) {
    denom += 1.0 / b;
  }

  cout << (1.0 / denom) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 100003;
int n,a[MaxN];

int main() {
    scanf("%d",&n);
    for (int i=1;i<=n;++i) scanf("%d",a+i);
    int cnt=0;
    for (int i=1;i<n;++i) if (a[i]==i && a[i+1]==i+1) cnt++,swap(a[i],a[i+1]);
    for (int i=1;i<=n;++i) if (a[i]==i) cnt++;
    printf("%d\n",cnt);
    return 0;
}

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    string T = "YAKI";
    bool ok = (S.size() >= 4);
    for (int i=0; i<4; i++) {
        if (S[i] != T[i]) ok = false;
    }
    cout << (ok ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256