akhauriyash/Code-Regression huggingface dataset:
N, A, B = map(int, input().split())

if (B - A) % 2 == 0:
    # 間で合う
    c1 = (B - A) // 2
    # AもBも1まで行く
    # c2 = max((A - 1), (B - 1))
    # AもBもNまで行く
    # c3 = max((N - A), (N - B))
    # c = min(c1, c2, c3)
    c = c1
else:
    # AもBも1まで行く
    # c2 = max((A - 1), (B - 1))
    # # AもBもNまで行く
    # c3 = max((N - A), (N - B))
    # c = min(c2, c3)
    c = min(A - 1, N - B) + 1 + (B - A - 1) // 2
print(c)

Measured memory_bytes: 38256
N = input()
dp = [0] + [float("inf")] * N
for i in xrange(N + 1):
    power = 1
    while power <= N:
        dp[i] = min(1 + dp[i - power], dp[i])
        power *= 6
    power = 1
    while power <= N:
        dp[i] = min(1 + dp[i - power], dp[i])
        power *= 9
print dp[N]



Measured memory_bytes: 7036
// Try AtCoder
// author: Leonardone @ NEETSDKASU

fn main() {
	let mut stdin = String::new();
    std::io::Read::read_to_string(
    	&mut std::io::stdin(),
        &mut stdin).unwrap();
	let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
    	($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let a = get!();
    let b = get!();
    let q = get!();
    let mut xs = vec![];
    let mut ys = vec![];
    for _ in 0..a {
    	xs.push(get!());
    }
    for _ in 0..b {
    	ys.push(get!());
    }
    fn foo(x: i64, ys: &[i64]) -> i64 {
    	use std::cmp::min;
        let res = ys.binary_search(&x);
        match res {
        Ok(i) => 0,
        Err(0) => (x - ys[0]).abs(),
        Err(i) if i < ys.len() => {
        	min(
            	(x - ys[i-1]).abs(),
                (x - ys[i]).abs()
			)
		},
        Err(i) => (x - ys[i-1]).abs(),
		}
	}
    
	fn bar(x: i64, xs: &[i64], ys: &[i64]) -> i64 {
        let res = xs.binary_search(&x);
        match res {
        Ok(i) => foo(x, ys),
        Err(0) => {
        	let c = (x - xs[0]).abs();
            c + foo(xs[0], ys)
        },
        Err(i) if i < xs.len() => {
        	let c1 = (x - xs[i-1]).abs();
            let c1 = c1 + foo(xs[i-1], ys);
            let c2 = (x - xs[i]).abs();
            let c2 = c2 + foo(xs[i], ys);
            std::cmp::min(c1, c2)
        },
        Err(i) => {
        	let c = (x - xs[i-1]).abs();
            c + foo(xs[i-1], ys)
        },
        }
	}
    
    for _ in 0..q {
    	let x = get!();
        let c1 = bar(x, &xs, &ys);
        let c2 = bar(x, &ys, &xs);
        let ans = std::cmp::min(c1, c2);
        println!("{}", ans);
    }
}

Measured memory_bytes: 11256
N = int(input())
a = list(map(int,input().split()))


a_sort = sorted(a, reverse=True)

a_sum = a_sort[0]

if (N-2) % 2 == 0:
    for i in range(int((N-2)/2)):
        a_sum += 2*a_sort[i+1]
    print(a_sum)
else:
    for i in range((N-2)//2):
        a_sum += 2*a_sort[i+1]
    print(a_sum+a_sort[(N-2)//2 + 1])

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

int main()
{
    int x = 0;
    cin >> x;

    int count500 = x / 500;
    int count5 = (x - (count500 * 500)) / 5;

    cout << (count500 * 1000 + count5 * 5);

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<ll> VLL;
typedef vector<PLL> VP;
const static int INF = 1000000000;
const static int MOD = 1000000007;
const int dx[4]={1, 0, -1, 0};
const int dy[4]={0, 1, 0, -1};
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; }
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<double> a, vector<double> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//最小公倍数
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}
//素数判定
bool is_prime(long long n) {
    if (n <= 1) return false;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p == 0) return false;
    }
    return true;
}
int getdigit(ll num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision

int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0);
    unsigned long long N;
    cin >> N;
    vector<unsigned long long> A(N);
    rep(i,N){
        cin >> A[i];
        if(A[i]==0){
            cout << 0 << endl;
            return 0;
        }
    }
    unsigned long long ans=1;
    rep(i,N){
        unsigned long long tmp=0;
        tmp=ans*A[i];
        if(tmp/ans==A[i]){
            ans*=A[i];
            if(ans>1000000000000000000){
                cout << -1 << endl;
                return 0;
            }
        }
        else{
            cout << -1 << endl;
            return 0;
        }
    }
    if(ans>1000000000000000000){
        cout << -1 << endl;
        return 0;
    }
    cout << ans << endl;

}

Measured memory_bytes: 3992
a = int(input())
for n in list(range(a+1)):
  if n == 1:
    b,c,d = map(int, input().split())
    if c + d > b or (c + d - b) % 2 != 0:
      print('No')
      break
  if n >= 2:
    b1 = b
    c1 = c
    d1 = d
    b,c,d = map(int, input().split())
    if abs(c-c1) + abs(d-d1) > b-b1 or (abs(c-c1) + abs(d-d1) - (b-b1)) % 2 != 0:
      print('No')
      break
else:
  print('Yes')


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

set<char> l, r;

void init() {
  string ls = "qwertasdfgzxcvb";
  string rs = "yuiophjklnm";
  for (auto c : ls) l.insert(c);
  for (auto c : rs) r.insert(c);
}
int solve(const string& s) {
  auto iter = s.begin();
  bool left;
  if (l.find(*iter) != l.end()) left = true;
  else                          left = false;

  int cnt = 0;
  iter++;
  while(iter != s.end()) {
    if (left & (r.find(*iter) != r.end())) {
      left = false;
      cnt++;
    }
    else if (!left & (l.find(*iter) != l.end())) {
      left = true;
      cnt++;
    }
    iter++;
  }
  return cnt;
}

int main() {
  init();
  
  string s;
  while(cin >> s, s != "#") {
    cout << solve(s) << endl;
  }
  return 0;
}


Measured memory_bytes: 3204
#include<bits/stdc++.h>
using namespace std;
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s; 
	int ans=0;
	cin>>s;
	for(int i=0;i<s.size();i++)
	if(s[i]=='+')ans++;
	else ans--;
	cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
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; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int a,b;

int main(){
    cin >> a >> b;
    int c = a + b;
    if(c >= 10){
        cout << "error" << endl;
    }else{
        cout << c << endl;
    }
}


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

int main() {
	int n,l;
    scanf("%d%d",&n,&l);
    int a,b;
    scanf("%d",&a);
    for(int i=1;i<n;i++){
        scanf("%d",&b);
        if(a+b>=l){
            printf("Possible\n");
            for(int j=1;j<i;j++){
                printf("%d\n", j);
            }
            for(int j=n-1;j>=i;j--){
                printf("%d\n", j);
            }
            return 0;
        }
        a=b;
    }
    printf("Impossible\n");

	return 0;
}

Measured memory_bytes: 768
//mangesh2102000

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define int long long int 
#define ld long double
#define pb push_back
#define tr(c,it) for(auto it = (c).begin(); it != (c).end(); ++it)
#define F first
#define S second
#define mod 1000000007  

string k;
int d;

int dp[10005][105][2];

int call(int pos,int rem_sum,int f)
{

	//cout << pos << " " << rem_sum << " " << f << " \n";

	if(dp[pos][rem_sum][f] != -1)
		return dp[pos][rem_sum][f];

	if(pos == k.length())
	{
		if(rem_sum == 0)
		{
			return dp[pos][rem_sum][f] = 1;
		}

		return dp[pos][rem_sum][f] = 0;	
	}


	int limit;

	if(f==0)
	{
		limit = k[pos] - '0';
	}
	else
	{
		limit = 9;
	}

	int ans = 0;

	for(int dig=0;dig<=limit;dig++)
	{
		int nf=f,nrem_sum=rem_sum;
		if(f==0 and dig < (k[pos]-'0'))
			nf = 1;

		nrem_sum -= (dig+d);
		nrem_sum %= d;

		ans += call(pos+1,nrem_sum,nf);
		ans %= mod;
	}

	return dp[pos][rem_sum][f] = ans;

}


int func()
{
	memset(dp,-1,sizeof(dp));
	//cout << k << " ";
	int ans = call(0,d,0);
	return ans;
}

void solve(int t)
{
    cin >> k >> d;
    int ans = func();
    ans--;
    ans += mod;
    ans %= mod;
    cout << ans;
    //cout << "Case #" << t << ": ";    
}   


int32_t main()
{
    IOS;
    int t;
    t=1;
    for(int i=1;i<=t;i++)
    {
        solve(i);
    }


    return 0;
}

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

int main(){
	ll n;
	cin >> n;
	ll sum = 0;
	for(ll i = 1; i <= n; i++){
		sum += (i)*((n/i)*(n/i+1)/2);
	}
	cout << sum << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm> 
#define max_n 1000000

using namespace std;

int main(){
  int n;
  long long int attendants[max_n];
  long long int sum = 0;
  int i;
  cin >> n;

  int j;
  j= 3*n;

  for (i=0;i<j;i++){
    cin >> attendants[i];
  }
  sort(attendants, attendants+j);

  for (i=n;i<j-1;i+=2){
    sum += attendants[i];
  }
  cout << sum << endl;
}


Measured memory_bytes: 4608
#include <bits/stdc++.h>
typedef long long ll;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,a,b,c,d,e,f,tmp,tmpp,m,h,w,x,y,sum,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s[ohara],co;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>n>>m;
    rep(i,m)ans+=1900;
    rep(i,n-m)ans+=100;
    cnt=1;
    rep(i,m)cnt*=2;
    Cout(ans*cnt);
    return 0;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    vector<pair<ll,int>> v(n);
    for(auto& i : v){
        cin >> i.first >> i.second;
    }
    sort(all(v));
    ll ans = 0;
    REP(i, n){
        if(v[i].second >= m){
            ans += v[i].first * m;
            break;
        }else{
            ans += v[i].first * v[i].second;
            m -= v[i].second;
        }
    }
    cout << ans << endl;
    return 0;
}

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


int main() {
  int N;
  cin >> N;
  
  //vector<char> l(N), r(N);
  int l, r;
  int num = 0;
  for (int i=0; i<N; i++) {
    cin >> l >> r;
    //cin >> l.at(i) >> r.at(i);
    num += (r - l + 1);
    //num += (r.at(i) - l.at(i) + 1);
  }
  
  cout << num << endl;

  return 0;
}


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

int n;
int l = 0, r = -1;
set < int > s;

int main(){
	
	scanf("%d",&n);
	for ( int i = 0; i < n; i++ ){
		int x;
		scanf("%d",&x);
		s.insert(x);
	}
	cout << s.size() << endl;
	return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
use  std::collections::BTreeSet;
use std::cmp::min;

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

fn main(){
    if is_seven(read()) {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn is_seven(a: u64) -> bool {
    if a % 10 == 7 {
        true
    } else if a == 0 {
        false
    } else {
        is_seven(a / 10)
    }
}


Measured memory_bytes: 2136
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <stack>
#include <vector>
#include <math.h>

using namespace std;

#define BIG_NUM 500000000

void func(int n,int k){

	int distance[n+1][n+1];

	for(int i=1;i<=n;i++){
		for(int k=1;k<=n;k++){
			if(i != k){
				distance[i][k]= BIG_NUM;
			}else{
				distance[i][k]= 0;
			}
		}
	}
	int type,from,to,cost;
	for(int loop = 0; loop < k; loop++){
		scanf("%d",&type);

		if(type == 1){
			scanf("%d %d %d",&from,&to,&cost);
			if(cost < distance[from][to]){
				distance[from][to] = cost;
				distance[to][from] = cost;

				for(int i = 1; i <= n; i++){
					if(distance[to][i] == BIG_NUM)continue;
					distance[from][i] = min(distance[from][i],distance[from][to]+distance[to][i]);
				}

				for(int i = 1; i <= n; i++){
					if(distance[from][i] == BIG_NUM)continue;
					distance[to][i] = min(distance[to][i],distance[to][from]+distance[from][i]);
				}

				for(int i = 1; i <= n; i++){
					for(int k = 1; k <= n; k++){
						if(distance[i][from] == BIG_NUM || distance[from][k] == BIG_NUM)continue;
						distance[i][k] = min(distance[i][k],distance[i][from]+distance[from][k]);
					}
					for(int k = 1; k <= n; k++){
						if(distance[i][to] == BIG_NUM || distance[to][k] == BIG_NUM)continue;
						distance[i][k] = min(distance[i][k],distance[i][to]+distance[to][k]);
					}
				}
			}
		}else{
			scanf("%d %d",&from,&to);

			if(distance[from][to] == BIG_NUM)printf("-1\n");
			else{
				printf("%d\n",distance[from][to]);
			}
		}
	}
}


int main(){

	int n,k;

	while(true){
		scanf("%d %d",&n,&k);
		if(n == 0 && k == 0)break;

		func(n,k);
	}


    return 0;
}

Measured memory_bytes: 3236
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
  int h,w;
  cin >> h >> w;
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n){
    cin >> a.at(i);
  }
  int ans[h][w];
  int i,j;
  int h_1=0,w_1=0;
  for(i=0;i<n;i++){
    for(j=1;j<=a.at(i);j++){
      ans[h_1][w_1]=i+1;
      w_1++;
      if(w_1==w){
        w_1=0;
        h_1++;
      }
    }
  }
  for(i=0;i<h;i++){
    if(i%2==1){
      for(j=0;j<w/2;j++){
        int cp=ans[i][j];
        ans[i][j]=ans[i][w-1-j];
        ans[i][w-1-j]=cp;
      }
    }
  }
  rep(i,h){
    rep(j,w){
      cout << ans[i][j] << " ";
    }
    cout << endl;
  }
}
      
               

Measured memory_bytes: 3652
n = int(input())

for i in range(n):
    Rt = int(input())
    if i == 0:
        min_Rt = Rt
    elif i == 1:
        max_p = Rt - min_Rt
        min_Rt = min(min_Rt, Rt)
    else:
        max_p = max(max_p, Rt - min_Rt)
        min_Rt = min(min_Rt, Rt)


print(max_p)



Measured memory_bytes: 5612
a,b=map(int,input().split())
while a!=0 or b!=0:
    c=0
    for i in range(1,a+1):
        for j in range(i+1,a+1):
            for k in range(j+1,a+1):
                if i+j+k==b:
                    c=c+1
                
    a,b=map(int,input().split())
    print(c)



Measured memory_bytes: 5592
import sys
def main():
    input = sys.stdin.readline
    N,M=map(int, input().split())
    #LRD=[tuple(map(int, input().split())) for _ in range(M)]
    G = [[] for _ in range(N)]
    ny = [0]*N #入次数
    for _ in range(M):
        l,r,d=map(int, input().split())
        l,r=l-1,r-1
        G[l].append((r,d))
        ny[r]+=1

    S=[(i,0) for i in range(N) if ny[i]==0]
    D=[-1]*N
    while S:
        v,dv = S.pop()
        if D[v] >= 0:
            if D[v] != dv:
                print('No')
                exit()
            continue
        D[v] = dv
        for to,d in G[v]:
            S.append((to,dv+d))
    if D.count(-1) > 0:
        print('No')
    else:
        print('Yes')

if __name__ == '__main__':
    main()

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

const ll MOD = 1e9 + 7;
const int MAX_N = 1005;
int A[MAX_N];
int B[MAX_N];

int main2() {
  int N = nextInt();
  int M = nextInt();
  REP(i, N) A[i] = nextInt();
  A[N] = -99999;
  REP(j, M) B[j] = nextInt();
  B[M] = -99999;

  sort(A, A+N);
  reverse(A, A+N);
  sort(B, B+M);
  reverse(B, B+M);

  // pv(A, A+N);
  // pv(B, B+M);

  ll ans = 1;
  ll room = 0;
  int l = N*M;
  int a = 0, b = 0;
  for (;l > 0; l--) {
    if (A[a] == l && B[b] == l) {
      room += a + b;
      a++;
      b++;
    } else if (A[a] == l) {
      ans = (ans * b) % MOD;
      room += min(b, M);
      room--;
      a++;
    } else if (B[b] == l) {
      ans = (ans * a) % MOD;
      room += min(a, N);
      room--;
      b++;
    } else {
      ans = (ans * room) % MOD;
      room--;
    }
    // cout << l << " " << a << " " << b << " " << room << " " << ans << endl;
  }
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 256
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
using namespace std;
#define ll           long long
#define all(v)       (v).begin() , (v).end()
#define vi           vector <ll>
#define vii          vector <pair<ll,ll>>
#define ii           pair<ll,ll>
#define sz(v)	     ((int)((v).size()))
#define lp(i,a,b)    for(int i=a;i<b;i++)
#define pb           push_back
#define pf           push_front
#define F            first
#define S            second
#define endl         "\n"
#define IOS          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const double PI = 3.14159265358979323846;
const ll inf=2e9,MOD=1e18,MAX=1e5+1;

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    IOS;
    ll n,idx,cnt=0;
    string res="";
    cin>>n;
    n--;
    while(n>=26){
        ll y=n%26;
        res+=char(y+'a');
        n/=26;
        n--;
    }
    res+=char(n+'a');
    reverse(all(res));
    cout<<res;
}

Measured memory_bytes: 3592
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize, m: usize,
    }
    puts!("{}\n", if n == m { "Yes" } else { "No" });
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(c) (c).begin(),(c).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)

const int INF = 1e9 + 10;

int N, M, X;
int A[15][15], under[15];

int main() {
    cin >> N >> M >> X;
    vector<int> C(N);
    rep(i,N) {
        cin >> C[i];
        rep(j, M) cin >> A[i][j];
    }
    int res = INF;
    rep(c, 1 << N) {
        rep(j,M) under[j] = 0;
        int cur = 0;
        rep(i,N) {
            if( (c>>i)&1 ) {
                cur += C[i];
                rep(j,M) under[j] += A[i][j];
            } 
        }
        int count = 0;
        rep(j,M) if (under[j] >= X) count++;
        if (count == M) chmin(res, cur);
    }
    if (res == INF) cout << "-1" << endl;
    else cout << res << endl;
}


Measured memory_bytes: 3584
use std::io::Read;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let c: i64 = it.next().unwrap().parse().unwrap();
    let mut h = vec![0i64; n];
    let mut dp = vec![0i64; n];
    h[0] = it.next().unwrap().parse().unwrap();
    let mut deq = std::collections::VecDeque::new();
    deq.push_back((-2 * h[0], 0 + h[0] * h[0]));
    for i in 1..n {
        h[i] = it.next().unwrap().parse().unwrap();
        let f = |(a, b)| a * h[i] + b;
        while deq.len() >= 2 {
            let a = *deq.get(0).unwrap();
            let b = *deq.get(1).unwrap();
            if f(a) < f(b) {
                break;
            }
            deq.pop_front();
        }
        dp[i] = f(*deq.front().unwrap()) + c + h[i] * h[i];
        let p = (-2 * h[i], dp[i] + h[i] * h[i]);
        while deq.len() >= 2 {
            let k = deq.len();
            let a = *deq.get(k - 2).unwrap();
            let b = *deq.get(k - 1).unwrap();
            if (b.1 - a.1) * (b.0 - p.0) < (p.1 - b.1) * (a.0 - b.0) {
                break;
            }
            deq.pop_back();
        }
        deq.push_back(p);
    }
    println!("{}", dp[n - 1]);
}

fn main() {
    run();
}


Measured memory_bytes: 15980
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<map>
#include<numeric>
#include<queue>
#include<functional>
#include<cassert>
#include<set>
#define rep(a,b) for(int a=0;a<b;++a)
#define REP(a,b,c,d) for(int a=b;a<c;a+=d)
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define mod 1000000007
using namespace std;
using ll = long long;
using p_i = pair<int, int>;
int main() {
	string s; cin >> s;
	int K; cin >> K;
	set<string> st;
	rep(i, s.size()) REP(j, 1, K + 1, 1) st.insert(s.substr(i, j));
	vector<string> str;
	for (auto sts = st.begin(); sts != st.end(); ++sts)str.push_back(*sts);
	cout << str[K - 1] << endl;
}

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

int check(int a,int b,int c){
  if((a>b&&b>c)||(a<b&&b<c)) return 1;
  return 0;
}


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

  int ans=0;
  for(int i=1;i<n-1;i++){
    ans += check(p[i-1],p[i],p[i+1]);
  }

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


Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int n,sum=0;
	scanf("%d",&n);
	if(n<3) printf("0\n");
	else {
	while(n-6>=0){
		n-=3;
		sum++;
	}
	sum++;
	printf("%d\n",sum);
    }
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;




int main(){


	int K,X;
	scanf("%d %d",&K,&X);

	printf("%d",X-K+1);
	for(int i = X-K+2; i <= X+K-1; i++){

		printf(" %d",i);
	}
	printf("\n");

	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

class Main {

    public static void main(String[] args) {

	final Scanner stdin = new Scanner(System.in);

	while ( stdin.hasNextInt() ) {

	    final int n = stdin.nextInt();
	    System.out.println( solve( n ) );
	    
	}
	
    }

    static long solve( final int n ) {

	long sum = 0;
	final long end = min( 2000L, n );
	final long start = max( 0, n - 2000L );
	for ( long i = start; i <= end; i++ ) {
	    final long sumAB = i;
	    final long combAB = min( sumAB, 2000L - sumAB ) + 1;
	    final long sumCD = n - i;
	    final long combCD = min( sumCD, 2000L - sumCD ) + 1;
	    sum += combAB * combCD;
	}
	return sum;
    }
    
}

Measured memory_bytes: 18820
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    A, B = LI()
    ans = A * B
    ans -= A 
    ans -= B
    ans += 1
    print(ans)

main()



Measured memory_bytes: 83552
n = int(input())
txy = [list(map(int, input().split())) for i in range(n)]

for i in range(n):
    if i == 0:
        ti, xi, yi = 0, 0, 0
    else:
        ti, xi, yi = txy[i-1]
    tf,xf,yf = txy[i]
    dt = tf - ti
    dx = abs(xi-xf)
    dy = abs(yi-yf)

    if dt < dx + dy or (dt-(dx+dy))%2 != 0:
        print("No")
        exit()
print("Yes")


Measured memory_bytes: 27324
def input_int():
    return int(input())

def input_ints():
    return list(map(int, input().split()))

A, B, C, D = input_ints()

turn = 0
while True:
    if turn == 0:
        C -= B
        if C <= 0:
            print('Yes')
            break
    else:
        A -= D
        if A <= 0:
            print('No')
            break
    turn = 1 - turn


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

int main(){
  int K;
  cin >> K;
  if((K%2==0)||(K%5==0)){
    cout << -1 << endl;
  }else{
    if(K%7==0){
      K/=7;
    }
    int mod=9*K;
    int x=1;
    for(int i=1;;i++){
      x=(x*(10%mod))%mod;
      if(x==1){
        cout << i << endl;
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 3512
#include <string>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<long long,long long> P;
typedef pair<long long,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
long long n,h[100005];
ll dp[100005];
#define ALL(v)  (v).begin(),(v).end()
std::set<long long> st;
//#define MAX(a,b) if(a>b)
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))

#define DEBUG


stack<long long> sta;   
queue<long long> que;


int main(){
	
	long long A,B,C,D,E,F,G,H,I,J,L,N,M,K,O,P,Q,R,S,T,U,V,W,X,Y,Z;
	long long ans;
	ans=0;
	string s;
	long long sum,sum1,sum2,sum3,sum4;
	sum=0;
	sum1=0;
	sum2=0;
	sum3=0;
	sum4=0;
	long long flg,flg1,cnt,cnt1;
	flg=0;
	flg1=0;
	cnt=0;
	cnt1=0;
	long long max;
	long long max1;
	max=0;
	max1=0;
	long long min;
	long long min1;
	min=INF;
	min1=INF;

	long long work,work1,work2,work3,work4;
	work=0;
	work1=0;
	work2=0;
	work3=0;
	work4=0;
    
	long long a[4];
	long long value;
	value=0;

    
	std::cin >> N;
	//std::cin >> N >> M;
	//std::cin >> N >> M >> K;
    
	std::vector<long long> v(N);
	//std::vector<long long> w(N);
	//std::vector<long long> z(N);
	//std::cin >> s;
    vector<pair<long long, long long> > w(100005);
    vector<pair<long long, long long> > z(100005);

	// 配列入力1
	
	for(long long i=0; i<N; i++){
		std::cin >> v[i];
	}
	for(long long i=0; i<N; i++){
		if(i%2==0){
			w[v[i]].first++;
			w[v[i]].second=v[i];
		}
		else{
			z[v[i]].first++;
			z[v[i]].second=v[i];

		}
	}
	//std::sort(w.begin(),w.end(),std::greater<long long>());//降順ソート
	//std::sort(z.begin(),z.end(),std::greater<long long>());//降順ソート
	sort(w.begin(), w.end(),greater<pair<long long,long long> >());
	sort(z.begin(), z.end(),greater<pair<long long,long long> >());
	//printf("%d,%d\n",z[0].first,w[0].first);
	//printf("%d,%d\n",z[0].first,w[0].first);
	//printf("%d,%d\n",z[0].first,w[0].first);
	//printf("%d,%d\n",z[0].first,w[0].first);
	
	if(z[0].second!=w[0].second){
		printf("%lld",N-z[0].first-w[0].first);
	}
	else if(N==1){
		puts("1");
	}
	else if(z[0].first+w[1].first > z[1].first+w[0].first){
		printf("%lld",N-z[0].first-w[1].first);
	}
	else{
		printf("%lld",N-z[1].first-w[0].first);
	}
	return 0;
	


}


Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
int main(){
	int x;
	cin>>x;
	int a=0;
	int b=0;
	for(int i=-500;i<=500;i++){
		for(int j=-500;j<=500;j++){
			if(abs(pow(i,5)-pow(j,5))==x){
				if(i>j){
				a=i;
				b=j;
			}else {
				b=i;
				a=j;
			}
				break;			
			}
		}
	}
	cout<<a<<" "<<b<<endl;
	return 0;
	
}

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


int main(void){
  string s,t; cin >> s >> t;
  cout << t << s << endl;
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from collections import Counter


def main():
    N = int(input())
    A = list(map(int, input().split()))

    result = 0
    for key, value in Counter(A).items():
        if value > key:
            result += (value - key)
        elif value < key:
            result += value

    print(result)


if __name__ == "__main__":
    main()


Measured memory_bytes: 18676
#include <bits/stdc++.h>
#define maxlog 60
#define mod 1000000007
using namespace std;
typedef long long LL;

struct Mat {
	vector< vector<int> > ways;
	Mat(int n, bool isI) {
		ways.resize(n, vector<int>(n,0));
		if(isI)
			for( int i = 0 ; i < n ; i++ )
				ways[i][i] = 1;
	}
};

LL m;
int n,tot;
Mat* dp[maxlog];

Mat* mult(Mat* a, Mat* b) {
	Mat* res = new Mat(n,false);
	for( int i = 0 ; i < n ; i++ )
		for( int j = 0 ; j < n ; j++ )
			for( int k = 0 ; k < n ; k++ ) {
				int v1 = a->ways[i][k];
				int v2 = b->ways[k][j];
				int add = ( (LL) v1 * v2 ) % mod;
				int curr = res->ways[i][j];
				res->ways[i][j] = ( curr + add ) % mod;
			}
	return res;
}

int main() {
	scanf("%d%lld",&n,&m);
	dp[0] = new Mat(n,false);
	for( int i = 0 ; i < n ; i++ )
		for( int j = 0 ; j < n ; j++ )
			scanf("%d",&dp[0]->ways[i][j]);
	for( int i = 1 ; (1LL<<i) <= m ; i++ )
		dp[i] = mult(dp[i-1], dp[i-1]);
	Mat* ans = new Mat(n,true);
	for( int i = 0 ; (1LL<<i) <= m ; i++ )
		if( m & (1LL<<i) )
			ans = mult(ans, dp[i]);
	for( int i = 0 ; i < n ; i++ )
		for( int j = 0 ; j < n ; j++ )
			tot = ( tot + ans->ways[i][j] ) % mod;
	printf("%d\n",tot);
	return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
int main(){
  int n,p;
  while(cin>>n>>p, n!=0 || p!=0){
    int A[n];
    memset(A, 0, sizeof(A));
    int t=0;
    while(1){
      if(p==0){
        p=A[t];
        A[t]=0;
      } else {
        p-=1;
        A[t]+=1;
      }
      int f=1;
      rep(i,n) {
        if(t!=i && A[i]!=0) f=0;
      }
      if(p==0 && f) break;
      t=(t+1)%n;
    }
    cout<<t<<endl;
  }
  return 0;
}

Measured memory_bytes: 2996
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  if(s.at(0)==s.at(1)||s.at(1)==s.at(2)||s.at(2)==s.at(3)){
    cout << "Bad" << endl;
  }
  else {
    cout << "Good" << endl;
  }
}

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

using namespace std;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define all(c) c.begin(), c.end()
#define rall(c) c.end(), c.begin()
#define INF (int)1e9
#define MOD 1000000007
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef map<int, int> MPII;
typedef set<int> SETI;

const int mxN = 2e5;
int a[mxN];

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

    int n;
    cin >> n;
    if (n % 1000 == 0)
        cout << 0;
    else
        cout << ((ceil(n / 1000) + 1) * 1000) - n;
}

Measured memory_bytes: 3804
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false


signed main(void){
    int N;
    const int MEM = 2020;
    int A[MEM];
    
    cin >> N;
    REP(i,N){
        cin >> A[i];
    }
    
    vector<pair<int,int>> P;
    vector<int> Q(N,0);
    REP(i,N){
        P.push_back({A[i],i});
    }
    
    sort(P.begin(),P.end(),greater<>());
    
    
    int dp[MEM][MEM]={};
    REP(i,MEM){
        REP(j,MEM){
            dp[i][j]=-INF;
        }
    }
    dp[0][0]=0;
    
    REP(j,N){
        REP(i,j+1){
            int k = j-i;
            //左
            dp[i+1][k] = max(dp[i+1][k],dp[i][k]+P[j].first*(abs(i-P[j].second)));
            //右
            dp[i][k+1] = max(dp[i][k+1],dp[i][k]+P[j].first*(abs(N-1-k-P[j].second)));
        }
    }
    
    int Ans=0;
    REP(i,N+1){
        Ans=max(Ans,dp[i][N-i]);
    }
    cout << Ans << endl;
    
    #if debug
    REP(i,N+1){
        REP(j,N+1){
            if(dp[i][j]<-INF/10){
                cout << "-∞" << " ";
            }else{
                cout << dp[i][j] << " ";
            }
        }
        cout << endl;
    }
    #endif
    
    return 0;
}



Measured memory_bytes: 35600
a, b, c, d = list(map(int, input().split()))

ab = [str(x) for x in range(a, b+1)]

cd = [str(x) for x in range(c, d+1)]

set_abcd = set(ab) & set(cd)

if len(set_abcd) <= 0:
	print(0)
else:
	print(len(set_abcd) - 1)


Measured memory_bytes: 3068
import scala.io.StdIn._
object Main extends App {
  var stack = List((0L, -1))
  val n = readInt()
  val height = readLine.trim.split(' ').map(_.toLong)
  var max = 0L
  for ((h, i) ← height.zipWithIndex) {
    val (greater, lesser) = stack.span(_._1 >= h)
    var last = i
    for ((g, gi) ← greater) {
      if (max < g * (i - gi)) max = g * (i - gi)
      last = gi
    }
    stack = (h, last)::lesser
  }
  if (stack.nonEmpty && max < stack.map{case (h, i) ⇒ h * (n - i)}.max) max = stack.map{case (h, i) ⇒ h * (n - i)}.max
  println(max)
}



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

using namespace std;

int main() {
  int N, K;
  char c;
  string s;
  
  cin >> N >> K;
  cin >> s;
  c = s[K-1];
  c = c + 'a' - 'A';
  string s2(1,c);
  s.replace(K-1, 1, s2);
  cout << s << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
using P = pair<int,int>;
int main()
{
    int n,m;
    cin >> n >> m;
    vector<ll> a(n);
    rep(i,n)cin >> a[i];
    ll ans = 0;
    priority_queue<pair<ll,int>> q;
    rep(i,m){
        int b;
        ll c;
        cin >> b >> c;
        q.push(pair<ll,int>(c,b));
    }
    sort(a.begin(),a.end());
    rep(i,n){
        if(q.empty()){
            ans+= a[i];
            continue;
        }
        pair<ll,int> p = q.top();q.pop();
        if (a[i] <p.first){
            ans += p.first;
            p.second--;
            if(p.second >0)q.push(pair<ll,int>(p));
            
        }
        else ans += a[i];
    }
    cout << ans << endl;

    return 0;
}

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

using namespace std;

int main() {
    int S;
    cin >> S;
    int front, back;
    bool YYMM = true, MMYY = true;
    front = S / 100;
    back = S % 100;
    
    if(front > 12 || front == 0) MMYY = false;
    if(back > 12 || back == 0) YYMM = false;
    if(front == 0 && back > 0 && back < 13) {
        cout << "YYMM" << endl;
        return 0;
    }
    if(back == 0 && front > 0 && front < 13) {
        cout << "MMYY" << endl;
        return 0;
    }
    if(front == 0 && back == 0) {
        cout << "NA" << endl;
        return 0;
    }
    

    if(YYMM && MMYY) {
        cout << "AMBIGUOUS" << endl;
    }
    else if(YYMM && !MMYY) {
        cout << "YYMM" << endl;
    }
    else if(!YYMM && MMYY) {
        cout << "MMYY" << endl;
    }
    else if(!YYMM && !MMYY) {
        cout << "NA" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int n;
  cin>>n;
  vector<vector<int>> x(n);
  vector<vector<int>> y(n);
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    for(int j=0;j<a;j++){
      int b,c;
      cin>>b>>c;
      x.at(i).push_back(b);
      y.at(i).push_back(c);
    }
  }
  int count=0;
  bool check=true;
  for(int tmp=0;tmp<1<<15;tmp++) {
    if (tmp>=(1<<n)) continue;
    bitset<15> s(tmp);
    for(int i=0;i<n;i++) {
      if (s[i]==0) continue;
      int a=x.at(i).size();
      for(int j=0;j<a;j++) {
        if (s[x.at(i).at(j)-1]!=y.at(i).at(j)) {
          check=false;
          break;
        }
      }
    }
    int count1=s.count();
    if(check)count=max(count1,count);
    check=true;
  }
  cout<<count<<endl;
  return 0;
}

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


int main(){
  int D,G;
  cin>>D>>G;
  vector<int> p(D);
  vector<int> c(D);
  for(int i=0;i<D;++i){
    cin>>p.at(i);
    cin>>c.at(i);
  }

  int ans=1000;
  for(int tmp;tmp<(1<<10);++tmp){
    bitset<10> s(tmp);
    int sum=0;
    int rep=0;
    
    for(int i=0;i<D;++i){
      if(s.test(i)){
        sum=sum+100*p.at(i)*(i+1)+c.at(i);
        rep=rep+p.at(i);
      }
    }
    
    if(sum>=G){
      if(ans>rep){
      ans=rep;
    }
    }
    
    else{
      int ind=0;
      for(int i=0;i<D;++i){
        if(s.test(i)==0){
          ind=i;
        }
      }
      int x=1;
      while(x<=p.at(ind) && sum<G){
        ++x;
        ++rep;
        sum=sum+100*(ind+1);
      }
      if(sum>=G && ans>rep){
        ans=rep;
      }
    }
    
  }
  
  cout<<ans<<endl;
  
}

Measured memory_bytes: 256
n = gets.chomp.to_i
cats = gets.chomp.split(" ").map(&:to_i)

looks = cats.uniq.sort

if looks.length > 2
  puts "No"
  exit(0)
end

if looks.length == 1
  real_colors = looks[0]
  if real_colors > n / 2 and real_colors != n - 1
    puts "No"
    exit(0)
  else
    puts "Yes"
    exit(0)
  end
else
  if looks[0] != looks[1] - 1
    puts "No"
    exit(0)
  end
  look_hash = {}
  cats.each do |c|
    look_hash[c] = (look_hash[c] || 0) + 1
  end

  unique = look_hash[looks[0]]
  real_colors = looks[0] + 1
  if (unique > looks[0])
    puts "No"
    exit(0)
  end
  if (real_colors - unique) > (n - unique) / 2
    puts "No"
    exit(0)
  else
    puts "Yes"
    exit(0)
  end
end


Measured memory_bytes: 15892
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include<cmath>
#include<algorithm>
#include<complex>
#include<cstdlib>
#include<cctype>

#define DBG cout << '!' << endl;
#define REP(i,n) for(int i = 0;i < (n);i++)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cout << v[i] << ' ';cout << endl << endl;}
#define SHOW2d(v,i,j) {for(int a = 0;a < i;a++){for(int b = 0;b < j;b++)cout << v[a][b] << ' ';cout << endl;}cout << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;


int dp[220][220];



int main()
{
	REP(i,220)REP(j,220)dp[i][j] = 1000000000;
	REP(i,220)dp[i][i] = 0;
	int n,m,r;
	
	cin >> n >> m >> r;
	
	iv mokuteki;
	
	REP(i,r)
	{
		int tmp;
		cin >> tmp;
		mokuteki.PB(tmp);
	}
	
	REP(i,m)
	{
		int a,b,c;
		cin >> a >> b >> c;
		dp[a][b] = min(c,dp[a][b]);
		dp[b][a] = min(c,dp[b][a]);
	}
	
	REP(k,n+2)REP(i,n+2)REP(j,n+2)
	dp[i][j] = min(dp[i][j] , dp[i][k] + dp[k][j]);

	//SHOW2d(dp,n+1,n+1);
	
	ll ans = 1000000000000;
	
	sort(ALL(mokuteki));
	
	do
	{
		//SHOW1d(mokuteki,r);
		ll hikaku = 0;
		REP(i,r-1)
		{
			hikaku += dp[mokuteki[i]][mokuteki[i+1]];
		}
		
	//	cout << hikaku << endl;
		ans = min(ans,hikaku);
	}while(next_permutation(ALL(mokuteki)));
		
	cout << ans << endl;
	
	return 0;
}


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

int main()
{
	int n, m, p;
	while (cin >> n >> m >> p, n + m + p)
	{
		int winner = 0;
		int total = 0;
		for (int i = 1; i <= n; i++)
		{
			int tmp;
			cin >> tmp;
			total += tmp * 100;
			if (i == m) winner = tmp;
		}
		if (winner == 0)
			cout << 0 << endl;
		else
			cout << total * (100 - p) / 100 / winner << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
#include<stdlib.h>
void Search(int **,int*,int,int);
int main(){
  int i,j,k,n,m;
  int **keep,**list,*flag,**count;

  scanf("%d %d",&n,&m);

  keep = malloc(sizeof(int *)*2);
  keep[0]=malloc(sizeof(int)*m);
  keep[1]=malloc(sizeof(int)*m);

  list = malloc(sizeof(int *)*n);

  flag = malloc(sizeof(int)*n);
  for(i=0;i<n;i++)flag[i]=-1;
  count = malloc(sizeof(int *)*2);
  count[0] = malloc(sizeof(int)*n);
  count[1] = malloc(sizeof(int)*n);
  for(i=0;i<n;i++){
    count[0][i]=0;
    count[1][i]=0;
  }

  for(i=0;i<m;i++){
    scanf("%d %d",&keep[0][i],&keep[1][i]);
    count[0][keep[0][i]]++;
    count[0][keep[1][i]]++;
  }
  
  k=0;
  for(i=0;i<n;i++){
    list[i]=malloc(sizeof(int)*(count[0][i]+1));
    list[i][count[0][i]]=-1;
  }
  for(j=0;j<m;j++){
    list[keep[0][j]][count[1][keep[0][j]]++]=keep[1][j];
    list[keep[1][j]][count[1][keep[1][j]]++]=keep[0][j];
  }
      
  free(count[0]);
  free(count[1]);
  free(count);
  free(keep[0]);
  free(keep[1]);
  free(keep);

  for(i=0;i<n;i++)if(flag[i]==-1)Search(list,flag,i,i);
  //for(k=0;k<n;k++)printf(" %d",flag[k]);

  scanf("%d",&m);
  
  while(m--){   
    scanf("%d %d",&i,&j);
    if(flag[i] == flag[j])printf("yes\n");
    else printf("no\n");
  }

  for(i=0;i<m;i++)free(list[i]);
  free(list);
  free(flag);
  return 0;
}

void Search(int **list,int *flag,int num,int s){
  int i;
  flag[num]=s;
  for(i=0;list[num][i]!=-1;i++){
    if(flag[list[num][i]] == -1){
      Search(list,flag,list[num][i],s);
    }
  }   
}
    
		    
    
    
  
  



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

using namespace std;

int par[1001];

void init(int n)
{
    memset(par, -1, sizeof(par));
}

int find(int x)
{
    if (par[x] < 0) return (x);
    return (par[x] = find(par[x]));
}

void merge(int x, int y)
{
    x = find(x);
    y = find(y);
    if (x == y) return;
    
    if (-par[x] < -par[y]) swap(x, y);
    par[x] += par[y];
    par[y] = x;
}

bool same(int x, int y)
{
    return (find(x) == find(y));
}


int main()
{
    int n, m;
    
    while (scanf("%d %d", &n, &m) && n){
        vector<pair<int, pair<int, int> > > es(m);
        
        for (int i = 0; i < m; i++){
            int a, b, c;
            scanf("%d %d %d", &a, &b, &c);
            es[i] = make_pair(c, make_pair(a, b));
        }
        
        sort(es.begin(), es.end());
        
        init(n + 1);
        int ec = 0;
        int i = 0;
        while (ec != n - 1 && i != m){
            if (!same(es[i].second.first, es[i].second.second)){
                merge(es[i].second.first, es[i].second.second);
                if (++ec == n / 2){
                    printf("%d\n", es[i].first);
                    break;
                }
            }
            i++;
        }
    }
    
    return (0);
}

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

int main(){
	ll n,q;
	cin >> n >> q;
	string a;
	cin >> a;
	vector <ll> arr(n+1,0);
	for (int z=1;z<a.size();z++){
		if (a[z-1] == 'A' && a[z] == 'C'){
			arr[z] = arr[z-1]+1;
		}
		else arr[z] = arr[z-1];
	}
	for (int z=0;z<q;z++){
		ll l,r;
		cin >> l >> r;
		cout << arr[r-1]-arr[l-1] << endl;
	}
	cin >> a;
}


Measured memory_bytes: 1792