akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>

int main()
{
	int n;
	std::cin >> n;
	int taro_count = 0, hanako_count = 0;
	while (n--) {
		std::string taro_animal, hanako_animal;
		std::cin >> taro_animal >> hanako_animal;
		if (taro_animal == hanako_animal) {
			taro_count++;
			hanako_count++;
		} else if (taro_animal > hanako_animal) {
			taro_count += 3;
		} else {
			hanako_count += 3;
		}
	}
	std::cout << taro_count << " " << hanako_count << std::endl;

	return 0;
}


Measured memory_bytes: 3128
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int func1(int N, vector<int> h) {
		int active = 0;
		int ans = 0;

		for ( int i = 0; i < N; i++ ) {
				if ( active >= h[i] ) {
						active = min(active , h[i]);
				} else if ( active < h[i] ) {
						ans += h[i] - active;
						active = h[i];
				}
		}

		return ans;
}

int main() {
		int N;
		vector<int> h;

		scanf("%d", &N);
		for ( int i = 0; i < N; i++ ) {
				int x;
				scanf("%d", &x);
				h.push_back(x);
		}

		printf("%d\n", func1(N, h));

		return 0;
}


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


int main() {

	int64_t a, b, x;
	cin >> a >> b >> x;

	int64_t ans = b / x - (a - 1) / x;

	if (a == 0)
		cout << b/x + 1;

	else
		cout << ans;
}


Measured memory_bytes: 256
#include<stdio.h>

int ans;

void swap_(int *f, int *b) {
    int temp;
    temp = *f;
    *f = *b;
    *b = temp;
}

void selectionSort(int arr[], int n) {
    int minIndex;
    bool flag = false;
    for(int i =0; i < n-1; i++) {
        minIndex = i;
        for(int j = i+1; j < n; j++) {
            if (arr[minIndex] > arr[j]) {
                minIndex = j;
                flag = true;
            }
        }
        if(flag) {
            ans++;
            flag = !flag;
        }
        swap_(&arr[minIndex], &arr[i]);
    }

}


int main() {

    int n;
    int arr[100+5];
    scanf("%d", &n);
    for(int i = 0; i < n; i++) scanf("%d", &arr[i]);
    selectionSort(arr, n);
    for(int i = 0; i < n ; i++) {
        if( i > 0 ) printf(" ");
        printf("%d", arr[i]);
    }
    printf("\n%d\n", ans);
    return 0;
}



Measured memory_bytes: 2728
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
typedef long long ll;
typedef double dd;
#define For(i,j,k) for (int i=(int)j;i<=(int)k;++i)
#define Forr(i,j,k) for (int i=(int)j;i>=(int)k;--i)
#define Set(a,p) memset(a,p,sizeof(a))
using namespace std;

template<typename T>bool chkmax(T &a,T b) { return a<b?a=b,1:0; }
template<typename T>bool chkmin(T &a,T b) { return a>b?a=b,1:0; }

const int maxn=1e5+1e2;
const ll inf=1e15;
struct node {
	int a,b;
	bool operator < (const node &aa) const {
		return a-b<aa.a-aa.b;
	}
}s[maxn];
int n,x,y,z;
ll sum,Ans=-inf;
ll pre[maxn],suf[maxn];
priority_queue<int,vector<int>,greater<int> >q;

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

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

int main() {
//	file();
	x=read(); y=read(); z=read(); n=x+y+z;
	For (i,1,n) {
		s[i].a=read(); s[i].b=read();
		int c=read(); sum+=1ll*c;
		s[i].a-=c; s[i].b-=c;
	}
	sort(s+1,s+n+1);
	For (i,1,y) q.push(s[i].b),pre[y]+=s[i].b;
	For (i,y+1,n-x) {
		pre[i]=pre[i-1]+1ll*s[i].b; q.push(s[i].b);
		int u=q.top(); q.pop(); pre[i]-=u;
	}
	while (!q.empty()) q.pop();
	For (i,n-x+1,n) q.push(s[i].a),suf[n-x+1]+=s[i].a;
	Forr (i,n-x,y+1) {
		suf[i]=suf[i+1]+1ll*s[i].a; q.push(s[i].a);
		int u=q.top(); q.pop(); suf[i]-=u;
	}
	For (i,y,n-x) chkmax(Ans,pre[i]+suf[i+1]);
	printf("%lld",Ans+sum);
	return 0;
}

Measured memory_bytes: 2304
#include<iostream>
#include<algorithm>
using namespace std;
int n;
int letu(int a,int b){
  if(a<b){
    return n-(b-a);
  }
  else return a-b;
}
int ritu(int a,int b){
  if(a>b){
    return n-a+b;
  }
  else{
    return b-a;
  }
}
int main(){
  int  m, p, a1, a2, a3, a4;
  int d[10005];

  cin>>n>>m>>p;
  for(int i=0;i<m;i++) cin>>d[i];
  
  sort(d,d+m);
  d[m]=d[0];
  int le=lower_bound(d,d+m,p)-d-1;
  int ri=le+1;
  if(le==-1){
    le=m-1;
  }
  if(ri==m)ri=0;
  //cout << d[le] << endl;
  //cout << d[ri] << endl;
  //cout  << endl;
  //ans1
  a1=ritu(p,d[le]);
  //ans2
  a2=letu(p,d[ri]);
  //ans3
  a3=1234567890;  
  for(int i=0;i<m;i++){
    int x=ritu(p,d[i]);
    int y=letu(d[i],d[i+1]);
    a3=min(a3,x+y);  
  }
  
  //ans4
  a4=1234567890;
  
  for(int i=0;i<m;i++){
    int x=letu(p,d[i]);
    int y;
    if(i==0){
      y=ritu(d[i],d[m-1]);
    }
    else{
      y=ritu(d[i],d[i-1]);
    }
    a4=min(a4,x+y);
  }
  // cout << a1 << endl;
  // cout << a2 << endl;
  //cout << a3 << endl;
  //cout << a4 << endl;
  int ans=a1;
  ans=min(ans,a2);
  ans=min(ans,a3);
  ans=min(ans,a4);
  cout << ans*100 << endl;
  return 0;
}

Measured memory_bytes: 3152
#include <iostream>
#include <string>
#include <cmath>
#include <stdio.h>
using namespace std;
 

class Dice{
public:
    int labels[6];

    Dice(int *s){
        for(int i=0;i<6;i++){
            labels[i] = s[i];
        }        
    }
    
    void update_state(char c){
        int tmp;
        switch(c){
            case 'N':
                tmp = labels[0];
                labels[0] = labels[1];
                labels[1] = labels[5];
                labels[5] = labels[4];
                labels[4] = tmp;
                break;
            case 'S':
                tmp = labels[0];
                labels[0] = labels[4];
                labels[4] = labels[5];
                labels[5] = labels[1];
                labels[1] = tmp;
                break;
            case 'W':
                tmp = labels[0];
                labels[0] = labels[2];
                labels[2] = labels[5];
                labels[5] = labels[3];
                labels[3] = tmp;
                break;
            case 'E':
                tmp = labels[0];
                labels[0] = labels[3];
                labels[3] = labels[5];
                labels[5] = labels[2];
                labels[2] = tmp;
                break;
        }
    }
};


int main(){
    int labels[6];
    for(int i=0;i<6;i++){
        cin >> labels[i];
    }
    // cout << labels[0] << endl;
    Dice dice(labels);
    // char c;
    // while(true){
    //     cin >> c;
    //     if(c=='') break;
    //     dice.update_state(c);
    // }
    string s;
    getline(cin, s);
    getline(cin, s);
    // cout << s << endl;
    for(int i=0;i<s.size();i++){
        dice.update_state(s[i]);
    }
    cout << dice.labels[0] << endl;
}


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

typedef long long ll;
typedef pair<ll, ll> Pll;

constexpr ll INF = 1e16;

int main() {
    int n, m, s, t; cin >> n >> m >> s >> t;
    vector<vector<Pll>> grapha(n+1);
    vector<vector<Pll>> graphb(n+1);
    for (int i = 0; i < m; i++) {
        int u, v, a, b; cin >> u >> v >> a >> b;
        grapha[u].push_back(Pll(v, a));
        grapha[v].push_back(Pll(u, a));
        graphb[u].push_back(Pll(v, b));
        graphb[v].push_back(Pll(u, b));
    }
    vector<bool> fixed(n+1, false);
    vector<ll> costa(n+1, INF);
    priority_queue<Pll, vector<Pll>, greater<Pll>> pq;
    pq.push(Pll(0, s)); costa[s] = 0;
    while (!pq.empty()) {
        Pll x = pq.top(); pq.pop();
        ll c = x.first, f = x.second;
        if (fixed[f]) continue;
        fixed[f] = true;
        for (Pll y : grapha[f]) {
            ll cst = y.second + c;
            if (cst < costa[y.first]) {
                pq.push(Pll(cst, y.first));
                costa[y.first] = cst;
            }
        }
    }

    fill(fixed.begin(), fixed.end(), false);
    vector<ll> costb(n+1, INF);
    pq.push(Pll(0, t)); costb[t] = 0;
    while (!pq.empty()) {
        Pll x = pq.top(); pq.pop();
        ll c = x.first, f = x.second;
        if (fixed[f]) continue;
        fixed[f] = true;
        for (Pll y : graphb[f]) {
            ll cst = y.second + c;
            if (cst < costb[y.first]) {
                pq.push(Pll(cst, y.first));
                costb[y.first] = cst;
            }
        }
    }
    vector<ll> ans(n+1);
    ans[n] = (ll)1e15 - costa[n] - costb[n];
    for (int i = n-1; 1 <= i; i--) {
        ans[i] = max(ans[i+1], (ll)1e15 - costa[i] - costb[i]);
    }
    for (int i = 1; i <= n; i++) {
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 19576
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;

# define mp make_pair
# define pb push_back
# define PI acos(-1)
# define ff first 
# define ss second 
# define endl '\n'
# define vt vector
# define all(c) (c).begin(), (c).end()
# define rep(i,a,b) for(int i = a ; i < b ; ++i)

typedef long long ll ; 
typedef long double ld ; 
typedef pair<int,int> pii ; 
typedef pair<ll,ll> pll ;

template<class T> bool umin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool umax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

const int MOD = 1e9+9 ;
const ll inf = 1e18 ;  
const ll mod = 1e9+7 ;  

ll nCr(ll n,ll r){ll t=1;if(r>n)return 0;if(r>n-r)r=n-r;for(ll i=0;i<r;i++){t*=(n-i);t/=(i+1);}return t;}
ll power(ll a, ll n) { ll r=1;while(n){if(n&1)r=(r*a)%MOD;n>>=1;a=(a*a)%MOD;}return r%MOD;}
ll sq(int x) { ll ans = x*x ; return ans ; }

void read(vt<int> &a) {
	rep(i,0,a.size()) 
	cin >> a[i] ; 
}

// ==========Start Here==============

// 138 - 142
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL) ; 
 	
 	int n ; 
 	cin >> n ; 
 	vt<int> a(n) ; 
 	read(a) ; 
 	vt<int> ans(n) ; 
 	rep(i,0,n) {
 		ans[a[i]-1] = i + 1 ; 
 	}
 	rep(i,0,n) {
 		cout << ans[i] << " " ; 
 	}
	return 0 ; 
 	
}

Measured memory_bytes: 3976
#include <stdio.h>
#define N 252

struct node{
  int key;
  int parent;
  int left;
  int right;
} typedef Node;

int main(){
  Node heap[N];
  int h, i, j;

  scanf("%d", &h);
  for(i = 1; i < h + 1; i++){
    scanf("%d", &heap[i].key);
    heap[i].parent = 0;
    heap[i].left = 0;
    heap[i].right = 0;
  }

  for(i = 1; i < h + 1; i++){
    if(i < 125) heap[i].left = heap[i * 2].key;
    if(i < 124) heap[i].right = heap[i * 2 + 1].key;
    if(i != 1) heap[i].parent = heap[i / 2].key;
  }

  for(i = 1; i < h + 1; i++){
    printf("node %d: key = %d, ", i, heap[i].key);
    if(heap[i].parent != 0) printf("parent key = %d, ", heap[i].parent);
    if(heap[i].left != 0) printf("left key = %d, ", heap[i].left);
    if(heap[i].right != 0) printf("right key = %d, ", heap[i].right);
    printf("\n");
  }

    return 0;
}

Measured memory_bytes: 604
class Array
	def accum
		inject([0]){|a, x| a + [a[-1] + x]}[1..-1]
	end
end

m, n = gets.split.map &:to_i
k = gets.to_i

a = (1..m).map{ gets.chomp.split("") }

d = m*n+1

orig = a.map{|r| r.map{|c|
	case c
		when ?J; 1
		when ?O; d
		when ?I; d * d
	end
}}

accum = orig.map{|r| [0] + r.accum}
accum_2d = accum.transpose.map{|r| [0] + r.accum}.transpose

k.times{
	y1, x1, y2, x2 = gets.split.map &:to_i
	x = accum_2d[y2][x2] - accum_2d[y1-1][x2] - accum_2d[y2][x1-1] + accum_2d[y1-1][x1-1]
	j = x % d
	x /= d
	o = x % d
	i = x / d
	puts "#{j} #{o} #{i}"
}

Measured memory_bytes: 211420
#include <stdio.h>
#include <string.h>

int main(void)
{
char s[200000];
int len;
int i;
char c;
int cnt;

scanf("%s", s);
len = strlen(s);

cnt = 0;
c = s[0];
for (i = 1; s[i] != '\0'; i++){
if (s[i] != c){
cnt++;
c = s[i];
}
}
printf("%d\n", cnt);

return 0;
}


Measured memory_bytes: 256
from operator import mul
from functools import reduce
from functools import lru_cache


def cmb(n, r):
    # combination
    if n < 1 or r < 0:
        return 0
    if n < r:
        return 0
    r = min(n - r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


@lru_cache(maxsize=None)
def solve(N, k):
    if len(N) > 1 and N[0] == "0":
        return solve(N[1:], k)
    n = int(N)
    if k < 0:
        return 0
    elif len(N) < k:
        return 0
    elif n == 0:
        if k == 0:
            return 1
        elif k > 0:
            return 0
    elif n < 10:
        if k == 1:
            return n
        elif k == 0:
            return 1

    a = solve(N[1:], k - 1)
    b = (int(N[0]) - 1) * cmb(len(N) - 1, k - 1) * int(9**(k - 1))
    c = cmb(len(N) - 1, k) * int(9**k)
    # print(N, k, a, b, c)
    return a + b + c


N = int(input())
K = int(input())

L = len(str(N))

# print(ans)
print(solve(str(N), K))


Measured memory_bytes: 3572
#include<cstdio>
#include<string>
#include<vector>
#include<fstream>
#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<cwctype>
#include<algorithm>
#include<math.h>

using namespace std;

int main(){
	for(int i=0;i<3;i++){
		int h,m,s;
		cin>>h>>m>>s;

		int dh,dm,ds;
		cin>>dh>>dm>>ds;
		if(ds-s<0)ds-=s-60,dm--;
		else ds-=s;
		if(dm-m<0)dm-=m-60,dh--;
		else dm-=m;
		dh-=h;
		cout<<dh<<" "<<dm<<" "<<ds<<endl;
	}
		return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define mod 1000000007
#define int long long
#define ll long long
#define EPS 0.00000000000001
#define ld long double
#define inf 200000000
#define N 51




int32_t main()
{
    IOS;

    int n;
    cin >> n;
    vector<int> a(n+1),b(n+1),c(n+1);
    for(int i = 0;i < n;i++)
        cin >> a[i];
    for(int i = 1;i <= n;i++)
        cin >> b[i];
    for(int i = 1;i < n;i++)
        cin >> c[i];
    int ans = 0;
    for(int i = 0;i < n;i++)
    {
        ans += b[a[i]];

        if(i > 0  and a[i] == a[i-1] + 1)
            ans += c[a[i-1]];
    }
    cout << ans;
    
}   
 
 


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

int main() {
  int A,B;
  cin >> A >>B;
  int ans =0;

  for (int i = A; i <= B; i++) {
    int s = i;

    if(s/10000 == (((s%10000)%1000)%100)%10  &&  (s%10000)/1000 == (((s%10000)%1000)%100)/10){
      ans++;
  }
   
 }
 cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#define lli long long int
#define uli unsigned long long int
#define inf 999999999999999999
#define rep(i,n,m) for(lli i=(lli)(n);i<(lli)(m);++i)
#define reep(i,n,m) for(int i=(int)(n);i<=(int)(m);++i)
#define per(i,m,n) for(lli i=(int)(m)-1;i>=(int)(n);--i)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
using namespace std;
int main(){
  int a,b,x;
  cin>>a>>b>>x;
  if(a+b>=x&&a<=x)ou("YES");
  else ou("NO");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define fori(i, m, n) for(int i = m; i < (int)n; i++)
#define forl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define all(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string btos(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  ll n,a,b;cin>>n>>a>>b;
  ll c=n/(a+b)*a;
  ll d=min(n%(a+b),a);
  ll ans=c+d;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int INF = pow(2,30);
const int MOD = 1000000007;

int main() {
  int H, W; cin >> H >> W;
  bool s[H][W];
  rep(i,H) {
    string row; cin >> row;
    rep(j,W) s[i][j]=(row[j]=='.');
  }

  int white=0; rep(i,H) rep(j,W) if(s[i][j]) white++;
  queue<vector<int>> q; q.push({0,0});
  int d[H][W]; rep(i,H) rep(j,W) d[i][j]=INF; d[0][0]=1;
  while (d[H-1][W-1]==INF && !q.empty()) {
    int h = q.front()[0], w = q.front()[1]; q.pop();
    if (h!=0&&s[h-1][w]) { d[h-1][w] = min(d[h-1][w], d[h][w]+1); q.push({h-1,w}); s[h-1][w] = false;}
    if (h!=H-1&&s[h+1][w]) { d[h+1][w] = min(d[h+1][w], d[h][w]+1); q.push({h+1,w}); s[h+1][w] = false;}
    if (w!=0&&s[h][w-1]) { d[h][w-1] = min(d[h][w-1], d[h][w]+1); q.push({h,w-1}); s[h][w-1] = false;}
    if (w!=W-1&&s[h][w+1]) { d[h][w+1] = min(d[h][w+1], d[h][w]+1); q.push({h,w+1}); s[h][w+1] = false;}
    s[h][w] = false;
  }

  int result;
  if (d[H-1][W-1] == INF) result = -1;
  else result = white - d[H-1][W-1];
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
package main
 
import (
    "bufio"
    "fmt"
    "os"
    "strconv"
)

func main(){
    
    w := nextString()
    
    d := make([]int, 26)
    // アルファベットそれぞれの出現回数を格納
	for _, v := range w {
		d[v - 'a']++
	}
    // 出現回数が奇数のアルファベットがあったらNoを出力
	for i := 0; i < 26; i++ {
		if d[i] % 2 == 1 {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
 

     
    
}
 
/* templates */


func Max(a []int) int {
    r := a[0]
    for i := 0; i < len(a); i++ {
        if r < a[i] {
            r = a[i]
        }
    }
    return r
}
 
func Min(a []int) int {
    r := a[0]
    for i := 0; i < len(a); i++ {
        if r > a[i] {
            r = a[i]
        }
    }
    return r
}
 
func Sum(a []int) (r int) {
    for i := range a {
        r += a[i]
    }
    return r
}
 
func Abs(a float64) float64 {
    if a < 0 {
        return -a
    }
    return a
}
 
type Pair struct {
    a, b int
}
 
type Pairs []Pair
 
func (p Pairs) Len() int {
    return len(p)
}
 
func (p Pairs) Swap(i, j int) {
    p[i], p[j] = p[j], p[i]
}
 
func (p Pairs) Less(i, j int) bool {
    return p[i].b < p[j].b
}
 
var nextReader func() string
 
func init() {
    nextReader = NewScanner()
}
 
func NewScanner() func() string {
    r := bufio.NewScanner(os.Stdin)
    r.Buffer(make([]byte, 1024), int(1e+11))
    r.Split(bufio.ScanWords)
    return func() string {
        r.Scan()
        return r.Text()
    }
}

func nextString() string {
    return nextReader()
}
 
func nextInt64() int64 {
    v, _ := strconv.ParseInt(nextReader(), 10, 64)
    return v
}
 
func nextInt() int {
    v, _ := strconv.Atoi(nextReader())
    return v
}
 
func nextInts(n int) []int {
    r := make([]int, n)
    for i := 0; i < n; i++ {
        r[i] = nextInt()
    }
    return r
}

func nextStrings(n int) []string {
    r := make([]string, n)
    for i := 0; i < n; i++ {
        r[i] = nextString()
    }
    return r
}

func nextFloat64() float64 {
    f, _ := strconv.ParseFloat(nextReader(), 64)
    return f
}


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

int main()
{
  long long N;

  cin >> N;
  vector<long long> v(N, 0);
  vector<long long> ans(N, 0);



  for (int i = 0; i < N; i++)
  {
    cin >> v[i];
  }

  for(int i = 0; i < N; i++)
  {
    if( i % 2 == 0)
    {
      ans[0] += v[i];
    }
    else
    {
      ans[0] -= v[i];
    }
  } 

  for(int i = 1; i < N; i++)
  {
    ans[i] = ( v[i-1] - ans[i-1] / 2 ) * 2;
  }

  for(int i = 0; i < N; i++)
  {
    cout << ans[i] << ' ';
  }
  cout << endl;

  return 0;
  
}

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

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; i++) cin >> a.at(i);

	sort(a.begin(), a.end());
	reverse(a.begin(), a.end());

	int alice = 0;
	int bob = 0;
	for(int i = 0; i < n; i++) {
		if(i % 2 == 0) alice += a.at(i);
		else bob += a.at(i);
	}

	cout << alice - bob << endl;

 	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <random>
#include <chrono>
#include <algorithm>
#include <cstring>

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
using namespace std;
typedef long long ll;
const ll MOD = (ll)1e9 + 7;
const int N = 3000+5, inf = 1e9+5;
ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; }
ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; }
ll mult(ll x, ll y) { return (x * y) % MOD; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll a[N], dp[N][N][2];

ll f(int l, int r, bool maxi) {
    if (l > r) return 0;
    if (dp[l][r][maxi] != -1) return dp[l][r][maxi];
    ll L = f(l + 1, r, !maxi);
    ll R = f(l, r - 1, !maxi);
    if (maxi)
        return dp[l][r][maxi] = max(a[l] + L, a[r] + R);
    else
        return dp[l][r][maxi] = min(L - a[l], R - a[r]);
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n; cin >> n;
    rep (i, 0, n) cin >> a[i];
    memset(dp, -1, sizeof(dp));
    cout << f(0, n-1, true) << endl;
    return 0;
}

Measured memory_bytes: 141568
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>
#include <ctype.h>
#include <algorithm>
#include <math.h>

using namespace std;

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

  int sum = 0;
  for(int i = 0; i < n.size(); i++)
    sum += (n[i]-'0');

  if(stoi(n)%sum == 0)
    cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3592
#include<stdio.h>
#define MAX 50

int main()
{
        char str[MAX];
        int i;
        int cnt;

        scanf("%s", str);

        for(cnt=0; str[cnt]!='\0'; cnt++);

        for(i=0; i<cnt-8; i++)printf("%c", str[i]);
        printf("\n");

        return 0;
}




Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
typedef long long ll;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int main () {

    ll n,m; cin >>n>>m;

    ll res = 0;
    if(n >= 2 && m >= 2) {
        res = n*m - (n*m - (n-2)*(m-2));
    } else if (n == 1 && m >= 2) {
        res = m - 2;
    } else if (m == 1 && n >= 2) {
        res = n - 2;
    } else if (n == 1 && m == 1){
        res = 1;
    }

    cout << res << endl;
    return 0;
}



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

using namespace std;

typedef pair<char, int> ci;

map<char, int> RGB = {{'R', 0}, {'G', 1}, {'B', 2}};
map<int, char> MAP = {{0, 'L'}, {1, 'C'}, {2, 'R'}};

typedef long long int lli;

const lli MOD = 998244353;

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

    string s;
    cin >> s;

    vector<ci> data = vector<ci>(3*N);
    vector<short> pos = vector<short>(3*N); 

    int count[3];
    count[0] = count[1] = count[2] = 1;

    for(int i = 0; i < 3*N; i++) {
        data[i] = {s[i], count[RGB[s[i]]]++};
    }

    for(int i = 0; i < 3*N; i++) {
        data[i].first = MAP[pos[data[i].second]++];
    }

    /*
    for(int i = 0; i < 3*N; i++) {
        cout << data[i].first << " " << data[i].second << endl;
    }
    */

    int current, extra;
    lli result = 1;
    
    extra = current = 0;
    for(int i = 0; i < 3*N; i++) {
        if(data[i].first == 'L') {
            extra++;
        }
        if(data[i].first == 'C') {
            current = current + extra - 1;
            result *= current + 1;
            result %= MOD;
            extra = 0;
        }
    }

    extra = current = 0;
    for(int i = 3*N-1; i >= 0; i--) {
        if(data[i].first == 'R') {
            extra++;
        }
        if(data[i].first == 'C') {
            current = current + extra - 1;
            result *= current + 1;
            result %= MOD;
            extra = 0;
        }
    }

    for(int i = 1; i <= N ; i++) {
        result *= i;
        result %= MOD;
    }

    cout << result << endl;

    return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <complex>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <iomanip>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define put(x) cout << x;
#define putsp(x) cout << x << ' ';
#define putbd cout << "---------------------------------------------" << endl;
#define putln(x) cout << x << endl;
#define debug(x) cerr << #x << "=" << x << endl;
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef complex<double> comp;
typedef vector <int> vec;
typedef vector <ll> vecll;
typedef vector <double> vecd;
typedef vector <vec> mat;
typedef vector <vecll> matll;
typedef vector <vecd> matd;

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

const int MAX = 200020;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const ll INFL = 1e18;
const ll MOD = 1e9+7;

const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
//const int dx[]={-1,-1,-1,0,1,1,1,0},dy[]={-1,0,1,1,1,0,-1,-1};

//********************************template END****************************************//

void solve(void){

	string S[2];
	cin >> S[0] >> S[1];

	map<char, int> m[2];

	rep(2, i)
	{
		for (char c : S[i])
		{
			m[i][c]++;
		}
	}

	mat m2(2);

	rep(2, i)
	{
		for (char c : S[i])
		{
			m2[i].pb(m[i][c]);
		}
		sort(all(m2[i]));
	}

	if ((int)m2[0].size() != (int)m2[1].size())
	{
		cout << "No" << endl;
		return;
	}

	rep((int)m2[0].size(), i)
	{
		if (m2[0][i] != m2[1][i])
		{
			cout << "No" << endl;
			return;
		}
	}

	cout << "Yes" << endl;

}

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


Measured memory_bytes: 2944
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int h, w;
		String c[];
		char ans[][];
		
		h = sc.nextInt();
		w = sc.nextInt();
		
		c = new String[h];
		ans = new char[2 * h][w];
		
		for(int i = 0; i < h; ++i) c[i] = sc.next();
		
		for(int i = 0; i < 2 * h; ++i) {
			for(int j = 0; j < w; ++j) {
				ans[i][j] = c[i / 2].charAt(j);
			}
		}
		
		
		for(int i = 0; i < 2 * h; ++i) {
			for(char a : ans[i])System.out.print(a);
			System.out.println();
		}
		
		sc.close();
	}

}


Measured memory_bytes: 31168
S = gets.chomp
s1 = S[0, 2].to_i
s2 = S[2, 2].to_i

yymm = s2.between?(1, 12)
mmyy = s1.between?(1, 12)
ans = if yymm && mmyy
    "AMBIGUOUS"
elsif yymm
    "YYMM"
elsif mmyy
    "MMYY"
else
    "NA"
end
puts ans

Measured memory_bytes: 1788
#include<bits/stdc++.h>
 
#define pb push_back
// #define mp make_pair
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define hell1 1000000007
#define hell2 1000000009
#define pi 3.1415926535
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed<<setprecision(n)
#define eps 0.000001
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define ll unsigned long long
#define ld long double 
#define no_of_digits(n) floor(log10(n)) + 1
#define see(x) cerr << (#x) << " is " << (x) << endl
#define INF 1e13
#define LL_MAX 1e18
// memset(array, -1, sizeof(array[0][0]) * row * count)
using namespace std;
 
ll mult(ll a,ll b, ll p=hell1){   return ((a%p)*(b%p))%p; }
ll multbig(ll a,ll b,ll mod=hell1){   if(a==0 or b==0) return 0;if(a==1 or b==1) return (a*b)%mod;ll cur=multbig(a,b/2,mod);cur=(2*cur)%mod;if(b%2) cur=(cur+a)%mod;return cur;}
ll add(ll a, ll b, ll p=hell1){ if(a>=p) a%=p; if(b>=p) b%=p; if(a+b>p) return (a + b)%p; else return a+b;}
ll sub(ll a, ll b, ll p=hell1){return (a%p - b%p + p)%p;}
ll fpow(ll n, ll k, ll p = hell1) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = mult(r,n,p); n = mult(n,n,p);} return r;}
ll inv(ll a, ll p = hell1) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = hell1){ll m0 = m;ll y = 0, x = 1;if (m == 1)return 0;while (a > 1){ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}
int isPowerof2(ll x) { return (x && !(x & x-1)); } 
ll log2(ll x) { ll res = 0; while (x >>= 1) res++; return res; } 
bool isPerfectSquare(long double x) {long double sr = sqrt(x); return ((sr - floor(sr)) == 0); }
bool check(ll i,ll j,ll n){return (i>=0 && i<n && j>=0 &&  j<n);} //matrix boundary checking
 
 
ll ceil(const ll &a, const ll &b){return (a - 1)/b + 1;}
 
// max({a, b, c, d})
// cout << fixed for removing e notation
 
bool comp(pair<ll, ll>a, pair<ll, ll>b)
{
    if(a.se*b.fi + b.se > b.se*a.fi + a.se) return true;
    else return false;
}
 
void convert(int arr[], int n) 
{ 
    int temp[n+1];
    for(int i=1;i<=n;i++)
        temp[i] = arr[i]; 
    // memcpy(temp, arr, n*sizeof(int)); 
  
    sort(temp+1, temp+n+1);   
    unordered_map<int, int> umap;
    int val = 1; 
    for (int i = 1; i <= n; i++) 
        umap[temp[i]] = val++;
    for (int i = 1; i <= n; i++) 
        arr[i] = umap[arr[i]]; 
}
 
bool prime[10000005];
void SieveOfEratosthenes(int n) 
{
    memset(prime, true, sizeof(prime)); 
    prime[0] = prime[1] = 0;
    for (int p=2; p*p<=n; p++) 
    {
        if (prime[p] == true) 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
    }
}

int foo(int a, int b, int c)
{
    return (abs(a-b) + abs(b-c) + abs(a-c));
}


ll getFirstSetBitPos(ll n) 
{ 
    return log2(n & -n) + 1; 
} 

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

    ll a[n-1];

    for(int i=0;i<n-1;i++)
        cin >> a[i];

    ll b[n];

    b[n-1] = a[n-2];
    for(int i=n-2;i>0;i--)
    {
        b[i] = min(a[i], a[i-1]);
    }

    b[0] = a[0];

    ll ans = 0;
    for(int i=0;i<n;i++) ans += b[i];

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


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;



Node treeMinimum(Node x){

  while(x->left!=NIL){
    x=x->left;
  }
  return x;

}

Node treeMaximum(Node x){

  while(x->right!=NIL){
    x=x->right;
  }
  return x;

}

Node treeSearch(Node u, int k){
  if(u==NIL || k==u->key) return u;
  if(k<u->key){
    return treeSearch(u->left,k);
  }
  else return treeSearch(u->right,k);

}

Node treeSuccessor(Node x){
  Node y;
  if(x->right!=NIL)
    return treeSuccessor(x->right);
  y=x->parent;
  while(y!=NIL && x==y->right){
    x=y;
    y=y->parent;
  }
  return y;

}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left==NIL || z->right==NIL)
    y=z;
  else y=treeSuccessor(z);

  if(y->left!=NIL) x=y->left;
  else x=y->right;

  if(x!=NIL) x->parent=y->parent;
  if(y->parent==NIL) root=x;
  else if(y==y->parent->left) y->parent->left=x;
  else y->parent->right=x;

  if(y!=z) z->key=y->key;
  free(y);
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key<x->key){
      x=x->left;
    }else{
      x=x->right;
    }
  }

  z->parent=y;
  if(y==NIL){
    root=z;
  }else{
    if(z->key<y->key){
      y->left=z;
    }else{
      y->right=z;
    }
  }


}

void inorder(Node u){
  if(u==NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u==NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);
  

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

 
  return 0;
}



Measured memory_bytes: 20448
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef pair<int, int> P;
typedef vector<P> VP;
#define X first
#define Y second
const int inf = 1e9;

int main(){
    bool first = true;
    while(1){
        int n;
        cin >> n;
        if(n==0) break;

        if(first){
            first = false;
        }else{
            cout << endl;
        }

        vector<VP> p(n, VP(2));
        for(int i=0; i<n; i++){
            cin >> p[i][0].X >> p[i][0].Y >> p[i][1].X >> p[i][1].Y;
            if(p[i][1] < p[i][0]) swap(p[i][0], p[i][1]);
            if(p[i][1].Y < p[i][0].Y) swap(p[i][0].Y, p[i][1].Y);
        }

        vector<int> ans(n, -1);
        int count = 1;
        vector<vector<int> > st(1);
        st[0] = vector<int>(n);
        for(int i=0; i<n; i++) st[0][i] = i;

        while(!st.empty()){
            vector<int> &now = st.back();
            if(now.empty()){
                st.pop_back();
                continue;
            }
            //手順1
            for(int &i: now){
                if(p[i][0] < p[now[0]][0]){
                    swap(i, now[0]);
                }
            }
            int minidx = now[0];
            now.erase(now.begin());
            ans[minidx] = count++;
            //手順2
            int h = p[minidx][1].Y;
            int xmin = p[minidx][0].X;
            int xmax = inf; //どこまで伸ばせるか
            for(int i: now){
                if(p[i][0].Y < h && h < p[i][1].Y){
                    xmax = min(xmax, p[i][0].X);
                }
            }
            //手順3
            vector<int> next;
            for(int i=now.size()-1; i>=0; i--){
                if(p[now[i]][0].X >= xmin && p[now[i]][1].X <= xmax && p[now[i]][1].Y <= h){
                    next.push_back(now[i]);
                    now.erase(now.begin() +i);
                }
            }
            st.push_back(next);
        }
        for(int i=0; i<n; i++){
            cout << ans[i] << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3112
#include <iostream>

using namespace std;

int main(void)
{
  string S, T="CODEFESTIVAL2016";
  int i, ans=0;
  
  cin >> S;
  
  for(i=0; i<16; i++){
    if(S[i] != T[i]){
      ans++;
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

struct fraction{
  int p, q;
};

int unit_fraction_partition(struct fraction f1, int a, int n, int multiple, int denominator);
struct fraction difference(struct fraction f1, struct fraction f2);
struct fraction reduction(struct fraction f);
struct fraction times(struct fraction f, int n);
int numerator(struct fraction f);
int gcd(int m, int n);

int main(void){
  struct fraction f;
  int a, n, total;
  do{
    scanf("%d%d%d%d", &(f.p), &(f.q), &a, &n);
    if(f.p!=0 || f.q!=0 || a!=0 || n!=0)
      printf("%d\n", unit_fraction_partition(f, a, n, 1, 1));
  }while(f.p!=0 || f.q!=0 || a!=0 || n!=0);
  
  return 0;
}

int unit_fraction_partition(struct fraction f1, int a, int n, int multiple, int denominator){
  int total=0;
  struct fraction f2;
  f2.p = 1;
  for(f2.q=denominator; f2.q*multiple<=a && numerator(difference(f1, times(f2, n)))<=0; f2.q++)
    if(numerator(difference(f1, f2)) == 0) total++;
    else if(numerator(difference(f1, f2)) > 0)
      total += unit_fraction_partition(difference(f1, f2), a, n-1, f2.q*multiple, f2.q);
  return total;
}

struct fraction difference(struct fraction f1, struct fraction f2){
  struct fraction f3;
  int tmp;
  f3.p = f1.p * f2.q - f2.p * f1.q;
  f3.q = f1.q * f2.q;
  if(f3.p > 0) f3 = reduction(f3);
  return f3;
}
  
struct fraction reduction(struct fraction f){
  int tmp = gcd(f.p, f.q);
  f.p /= tmp;
  f.q /= tmp;
  return f;
}
 
struct fraction times(struct fraction f, int n){
  f.p *= n;
  return reduction(f);
}
   
int numerator(struct fraction f){
  return f.p;
}

int gcd(int m, int n){
  int tmp;
  if(m < n){
    tmp = m;
    m = n;
    n = tmp;
  }
  while(n != 0){
    tmp = n;
    n = m % n;
    m = tmp;
  }
  return m;
}

Measured memory_bytes: 404
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n;
  cin >> n;
  vi dp(n + 1);
  dp[0] = dp[1] = 1;
  rep2(i, 2, n + 1) dp[i] = dp[i - 1] + dp[i - 2];
  cout << dp[n] << endl;
}


Measured memory_bytes: 3112
def factor(n):
    table = []
    i = 2
    while i * i <= n:
        if n % i == 0:
            cnt = 0
            while n % i == 0:
                n //= i
                cnt += 1
            table.append((i, cnt))
        i += 1
    if n > 1:
        table.append((n, 1))
    return table

N = int(input())

F = factor(N)

ans = 0
for _, e in F:
    x = 1
    while not (x * (x + 1) <= 2 * e < (x + 1) * (x + 2)):
        x += 1
    ans += x

print(ans)

Measured memory_bytes: 9220
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>
#include <math.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_sz_desc(const void* a, const void* b) {
    return *((size_t*)a) > * ((size_t*)b) ? -1 : 1;
}

int compare_f(const void* a, const void* b) {
    return *((int64_t*)a) < *((int64_t*)b) ? -1 : 1;
}

int compare_f2(const void* a, const void* b) {
    return *((uint64_t*)a) > * ((uint64_t*)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
    size_t result = 1;

    for (size_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static uint64_t combU64(const uint64_t n, const uint64_t r) {
    uint64_t result = 1;

    for (uint64_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static uint64_t gcd(uint64_t m, uint64_t n)
{
    uint64_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

static size_t gcdZu(size_t m, size_t n) {
    size_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

int main(void) {
    char S[5];

    scanf("%s", S);

    size_t val[2];

    val[0] = (S[0] - '0') * 10 + (S[1] - '0');
    val[1] = (S[2] - '0') * 10 + (S[3] - '0');

    if (0 < val[0] && val[0] <= 12 && 0 < val[1] && val[1] <= 12) {
        puts("AMBIGUOUS");
    }
    else if (0 < val[0] && val[0] <= 12 && (12 < val[1] || val[1] == 0)) {
        puts("MMYY");
    }
    else if ((12 < val[0] || val[0] == 0) && 0 < val[1] && val[1] <= 12) {
        puts("YYMM");
    }
    else {
        puts("NA");
    }

    return 0;
}


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

#define M 1000000007
#define FOR(i, s, n) for (ll i = (s); i < (n); ++i)
#define FORALL(i, n) for (ll i = 0; i < (n); ++i)
#define MOD 1000000007
#define ff first
#define ss second
#define pll pair<long long, long long>
#define pii pair<int,int>
#define fast ios_base::sync_with_stdio(false)
#define countbits(x) __builtin_popcount(x)
#define pb(x) push_back((x))
#define vll vector<ll>
#define all(x) x.begin(),x.end()
#define print(x) cout << x << endl
#define debug print("reaching\n")
#define mll map<ll,ll>
#define lsb(i) i&(-i)
#define printv(x) \
	FORALL(i, x.size()) \
	{ \
		cout << x[i] << ' '; \
	} \
	cout << endl \
;
#define printm(m) \
	for(auto i: m){\
		cout<<i.ff<<' '<<i.ss<<endl; \
	}\
;
// vector<map<ll,ll>> m(2);
long long binpow(long long a, long long b) {
	if(b<=0) return 1;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}



template <typename T>
T extGcd(T a, T b, T &x, T &y)
{
	if (b == 0)
	{
		x = 1;
		y = 0;
		return a;
	}
	else
	{
		int g = extGcd(b, a % b, y, x);
		y -= a / b * x;
		return g;
	}
}

template <typename T>
T modInv(T a, T m)
{
	T x, y;
	extGcd(a, m, x, y);
	return (x % m + m) % m;
}


int main()
{
	fast;
	// cin.tie(0);
	// cout.tie(0);
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif

	int t=1;
	// cin>>t;
	ll tot=t;
	while(t--){
		ll a,b,c,d;
		cin>>a>>b>>c>>d;
		ll ans = max(a*c, a*d);
		ans = max(ans, b * c);
		ans = max(ans, b * d);
		if(ans < 0){
			if(a<= 0 and b>=0) ans = 0;
			if(c<=0 and d>=0) ans= 0;
		}
		print(ans);
	}
	return 0;
}

Measured memory_bytes: 3688
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a,b,ans;
  a=0,b=0;
  string s;
  cin>>n;
  cin>>s;
  vector<char> c(n);
  vector<int> e(n);
  vector<int> w(n);
  for(int i=0;i<n;i++){
    c[i]=s.at(i);
    if(c[i]=='W'){a++;}
    w[i]=a;
  }
  reverse(c.begin(),c.end());
  for(int i=0;i<n;i++){
    if(c[i]=='E'){b++;}
    e[i]=b;
  }
  ans=min(e[n-1],w[n-1]);
  for(int i=1;i<n-1;i++){
    ans=min(ans,w[i-1]+e[n-i-1]);
  }
  cout<<ans;
}

Measured memory_bytes: 3332
import itertools
import sys

N = 999999
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41] 
primeb = [0 for i in range(N+1)]
 
for i in primes:
  primeb[i] = 1
 
def isprime(n):
  for p in primes:
    if (n % p == 0):
      return True
    if (n < p*p):
      return False 
S = primes[-1]
for i in range(S, N):
  if isprime(i):
    pass 
  else: 
    primes.append(i)
    primeb[i] = 1

for line in sys.stdin:
  n = int(line)
  print sum(primeb[:n+1])

Measured memory_bytes: 52244
import java.util.*;

class Main {
	
	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		for(;;){
			int n = in.nextInt();
			if(n==0) return ;
			int cont = 0, best = 0, ma=-(1<<29);
			for(int i=0; i<n; i++){
				int x = in.nextInt();
				cont = Math.max(0, cont+x);
				best = Math.max(best, cont);
				ma = Math.max(ma, x);
			}
			System.out.println((ma<0)?ma:best);
		}
	}

}

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

l2 = l[1]
l[1] = l[0]
l[0] = l2

l3 = l[2]
l[2] = l[0]
l[0] = l3

L=[str(a) for a in l]
L=" ".join(L)
print(L)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; ll k; cin >> n >> k;
  vector<ll> A(n); rep(i, n) cin >> A[i];
  rep(i, n) A.push_back(A[i]);
  int logK = log2(n*k);
  vector<vector<ll>> next(logK+1, vector<ll>(n));
  map<ll, vector<int>> pos;
  rep(i, 2*n) pos[A[i]].push_back(i);
  for(auto ele: pos) {
    int prev = -1;
    for(int p: ele.second) {
      if(prev >= n) break;
      if(prev != -1) next[0][prev] = (p+1)-prev;
      prev = p;
    }
  }
  rep(k, logK) rep(i, n) {
    if(LONG_LONG_MAX-next[k][(i+next[k][i])%n] > next[k][i]) {
      next[k+1][i] = next[k][i] + next[k][(i+next[k][i])%n];
    } else {
      next[k+1][i] = longinf;
    }
  }
  ll p = 0;
  while(1) {
    bool updated = false;
    rrep(i, logK) {
      if(p+next[i][p%n] < n*k) {
        p = p+next[i][p%n];
        updated = true;
        break;
      }
    }
    if(!updated) break;
  }
  vector<ll> ans;
  set<ll> se;
  for(ll i=p; i<n*k; i++) {
    if(se.count(A[i%n])) {
      while(se.count(A[i%n])) {
        se.erase(ans.back());
        ans.pop_back();
      }
    } else {
      ans.push_back(A[i%n]);
      se.insert(A[i%n]);
    }
  }
  for(ll a: ans) cout << a << ' ';
  cout << "\n";
  return 0;
}


Measured memory_bytes: 127196
#include <iostream>
#include <vector>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <sstream>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
	int H = 0, W = 0;
	int N = 0;

	cin >> H >> W;
	cin >> N;

	vector<int> vctNum(N);
	for (auto& elem : vctNum) {
		cin >> elem;
	}

	//vector<stringstream> str(H);
	vector<vector<int>> table(H, vector<int>(W, 0));
	vector<bool> dirPosi(N, true);
	int numRoomInLine = W;
	int count = 0;
	int lineIndex = 0;
	bool dirPosiFlg = true;
	for (int k = 0; k < N; ++k) { // color のループ
		int curNum = vctNum[k];

		if (numRoomInLine >= curNum) {
			// 最初の行内に収まる。
			for (int i = 0; i < curNum; ++i) {
				table[lineIndex][W - numRoomInLine + i]  = k + 1;
			}
			count += curNum;
			numRoomInLine -= curNum;
			if ((count % W) == 0) {
				dirPosi[lineIndex] = dirPosiFlg;
				++lineIndex;
				dirPosiFlg = !dirPosiFlg;
			}
		}
		else {
			// 最初の行に収まらない。

			for (int i = 0; i < numRoomInLine; ++i) {
				table[lineIndex][W - numRoomInLine + i] = k + 1;
				//cout << k + 1;
			}
			if (numRoomInLine != 0) {
				dirPosi[lineIndex] = dirPosiFlg;
				++lineIndex;
				dirPosiFlg = !dirPosiFlg;
			}
			count += numRoomInLine;
			curNum -= numRoomInLine;
			numRoomInLine = W;
			int numLines = curNum / W;
			int numRestCol2 = curNum % W;

			for (int j = 0; j < numLines; ++j) {
				for (int i = 0; i < W; ++i) {
					table[lineIndex][i] = k + 1;
					//cout << k + 1;
				}
				dirPosi[lineIndex] = dirPosiFlg;
				++lineIndex;
				// dirPosiFlg = !dirPosiFlg;
			}

			for (int i = 0; i < numRestCol2; ++i) {
				table[lineIndex][W - numRoomInLine + i] = k + 1;
				// cout << k + 1;
			}
			numRoomInLine = W - numRestCol2;
			count += curNum;
		}
	}
	
	for (int i = 0; i < H; ++i) {
		if (dirPosi[i] ) {
			for (const auto& elem : table[i]) {
				cout << " " << elem;
			}
			cout << endl;
		}
		else {
			for (auto elem = table[i].rbegin(); elem != table[i].rend(); ++elem) {
				cout << " " << *elem;
			}
			cout << endl;
		}
	}

	return 0;
}

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

#define int long long


int get(int a, int b){
    return (a / b);
}

signed main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    a--;

    int ans1 = b-get(b, c) - get(b, d) + get(b, c/__gcd(c, d)*d);
    int ans2 = a-get(a, c) - get(a, d) + get(a, c/__gcd(c, d)*d);

    cout << ans1 - ans2 << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		double[] arr = new double[n + 1];
		for (int i = 1; i <= n; i++)
			arr[i] = s.nextDouble();
		double res = 0.0;
		double[][] dp=new double[n+1][n+1];
		boolean[][] vis=new boolean[n+1][n+1];
		for (int head = 0; head <= n; head++) {
			int tail = n - head;
			if (head > tail)
				res += solve(arr, n, head,dp,vis);
		}
		System.out.println(res);
	}

	public static double solve(double[] arr, int n, int k,double[][] dp, boolean[][] vis) {
		if (k < 0)
			return 0.0;
		if (n == 0)
			return (k == 0) ? 1.0 : 0.0;
		if(vis[n][k])
			return dp[n][k];
		else {
			vis[n][k]=true;
			dp[n][k]=arr[n] * solve(arr, n - 1, k - 1,dp,vis) + (1.0 - arr[n]) * solve(arr, n - 1, k,dp,vis);
		return dp[n][k];
		}
	}

}

Measured memory_bytes: 125432
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; 
int main(){
    ll h,n;
    cin>>h>>n;
    for(int i=0; i<n; i++){
        int a;
        cin>>a;
        h-=a;
    }
    if(h<=0){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 256