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

struct edge{int s,t,n;}e[200010];
int n,p[200010],h[200010],f[200010],vis[200010],c[200010],tim;
vector <int> V;

int go(int x)
{
	if (vis[x])  return x;
	vis[x]=1;
	return go(p[x]);
}

void dfs(int x)
{
	for (int i=h[x],y; y=e[i].t,i; i=e[i].n)
		if (!vis[y])  dfs(y);
	tim++;
	for (int i=h[x],y; y=e[i].t,i; i=e[i].n)
		if (!vis[y])  c[f[y]]=tim;
	for (f[x]=0; c[f[x]]==tim; f[x]++);
}

void work()
{
	scanf("%d",&n);
	for (int i=1; i<=n; i++)
		scanf("%d",&p[i]),e[i]=(edge){p[i],i,h[p[i]]},h[p[i]]=i;
	int x=go(1);
	memset(vis,0,sizeof(vis));
	do  V.push_back(x),vis[x]=1,x=p[x];  while (x!=V[0]);
	if (!(V.size()&1))  {puts("POSSIBLE");  return;}
	for (int i=0; i<V.size(); i++)  dfs(V[i]);
	V.push_back(x);
	for (int i=0; i<V.size()-1; i++)
		if (f[V[i]]!=f[V[i+1]])
			{puts("POSSIBLE");  return;}
	puts("IMPOSSIBLE");
}

int main()
{
	work();
	return 0;
}


Measured memory_bytes: 6392
# coding: utf-8
# Your code here!

import sys

# while : 0
# black : 1
H, W = map(int, input().rstrip().split(' '))
field = [[0] * W for _ in range(H)]

for i in range(H):
    for j, c in enumerate(input()):
        if c == '#':
            field[i][j] = 1
       
for h in range(H):
    for w in range(W):
        if field[h][w] == 1:
            if h + 1 < H:
                if field[h + 1][w] == 1:
                    continue
            if h - 1 >= 0:
                if field[h - 1][w] == 1:
                    continue
            if w + 1 < W:
                if field[h][w + 1] == 1:
                    continue
            if w - 1 >= 0:
                if field[h][w - 1] == 1:
                    continue
                    
            print('No')
            sys.exit()
            
print('Yes')


Measured memory_bytes: 3064
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    h,n=MI()
    aa=LI()
    if sum(aa)>=h:print("Yes")
    else:print("No")

main()

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

typedef ostringstream OSS; typedef istringstream ISS;
typedef long long LL;
typedef pair<int, int> PII;  typedef pair<LL, LL> PLL;
typedef vector<int>    VI;   typedef vector<VI>   VVI;   typedef vector<VVI>   VVVI;
typedef vector<LL>     VLL;  typedef vector<VLL>  VVLL;  typedef vector<VVLL>  VVVLL;
typedef vector<double> VD;   typedef vector<VD>   VVD;   typedef vector<VVD>   VVVD;
typedef vector<string> VS;   typedef vector<VS>   VVS;   typedef vector<VVS>   VVVS;
typedef vector<bool>   VB;   typedef vector<VB>   VVB;   typedef vector<VVB>   VVVB;
typedef vector<PII>    VPII; typedef vector<VPII> VVPII; typedef vector<VVPII> VVVPII;
typedef vector<PLL>    VPLL; typedef vector<VPLL> VVPLL; typedef vector<VVPLL> VVVPLL;

#define fst first
#define snd second
// #define Y first
// #define X second
#define MP make_pair
#define PB push_back
#define EB emplace_back 
#define ALL(x)  (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define RANGEBOX(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define RANGE(x, l, r) ((l) <= (x) && (x) <= (r))
#define rep(i, N)  for (int i = 0; i < (int)(N); i++)
#define rrep(i, N) for (int i = N - 1; i >= 0; i--)
#define REP(i, init, N)  for (int i = (init); i < (int)(N); i++)
#define RREP(i, N, last) for (int i = (init - 1); i >= last; i--)
#define MAXUD(orig, target) orig = max(orig, target)
#define MINUD(orig, target) orig = min(orig, target)
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

template < typename T > inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; };
template < typename T > inline string toString(const T &a)   { OSS oss; oss << a; return oss.str(); };

const int    INF  = 0x3f3f3f3f;
const LL     INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;
const int    DX[] = {1,  0, -1, 0};
const int    DY[] = {0, -1,  0, 1};
const double EPS  = 1e-12;
// const double PI   = acos(-1.0);
// lambda: [](T1 x)->T2{return y;}
// simple lambda: [](T x){return x;}

bool solve(VI &xs, int K, int T) {
    rep(t, T) {
        int num = xs[t];
        REP(k, 1, K) {
            if (xs[T * k + t] != num) return false;
        }
    }

    return true;
}

int main(void) {
    int N;
    cin >> N;
    VI xs(N);
    rep(i, N) cin >> xs[i];

    VPII kts;
    REP(i, 1, N) {
        if (!(N % i)) {
            kts.EB(N / i, i);
        }
    }

    
    for (auto kt : kts) {
        if (solve(xs, kt.fst, kt.snd)) {
            cout << kt.fst << endl;
            return 0;
        }
    }
    
    cout << 1 << endl;

	return 0;
}

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

int main() {
  char a,b,c,d;
  cin >>a>>b>>c>>d;
  string ans="No";
  if(a=='Y'&&b=='A'&&c=='K'&&d=='I') ans="Yes";
  cout << ans << endl;
  return 0;
}     
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20);
#define int long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) _overload(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload(__VA_ARGS__, revi, _rev)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
void in(){}
template<typename F, typename... R>
bool in(F& f, R&... r){
    if(cin >> f){in(r...);return true;}
    else return false;
}
#define out(x) cout << (x)
#define space() cout << " "
#define indent() cout << '\n'
void print(){}
template<typename F, typename... R>
void print(F f, R... r){out(f), indent(), print(r...);}
#define debughead(x) cerr << "Line " << __LINE__ << ": " << #x << ": "
#define debugout(x) cerr << (x) << " "
#define debugindent() cerr << '\n'
#define debug(x) debughead(x), debugout(x), debugindent()
const int INF = 1e18, MOD = 1e9 + 7;
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}

main(){
    INCANT;
    int n, p, res = 0;
    string s;
    in(n);
    vector<pair<string, int>> v, v2;
    rep(i, n){
        in(s, p);
        v.pb(mp(s, -p));
        v2.pb(mp(s, -p));
    }
    sort(all(v));
    /*
    rep(i, n){
        debug(v[i].first);
        debug(v[i].second);
    }
    */
    rep(i, n){
        rep(j, n){
            if(v[i] == v2[j]){
                print(j + 1);
            }
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define _upgrade ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

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

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

const ll mod = 1e9 + 7;
const ll IMF = 1e18;
const double PI = 3.14159265358979323846;


// ****************************************CODE***************************************//



ll n,W;
ll w[110],v[110];
ll dp[100100];

int main(){
        cin >> n >> W;
        for(int i = 1; i <= n; i++) cin >> w[i] >> v[i];

        for(int i = 0; i <= 100100; i++) dp[i] = IMF;

        dp[0] = 0;
        for(int i = 1; i <= n; i++){
                for(int j = 100000; j >= v[i]; j--){
                        dp[j] = min(dp[j], dp[j-v[i]]+w[i]);
                }
        }

        ll ans = 0;
        for(int i = 100000; i >= 0; i--){
                if(dp[i] <= W) ans = max(ans, 1LL*i);
        }

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





















































Measured memory_bytes: 1024
N, T = map(int, input().split())
cost = []
time = []
for i in range(N):
    c, t = map(int, input().split())
    if t <= T:
        cost.append(c)
        time.append(t)
if len(time) == 0:
    print("TLE")
else:
    #min_time_index = time.index(min(time))
    #print(cost[min_time_index])
    print(min(cost))

Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <vector>

int main() {
  int N, M, X, Y;
  std::cin >> N >> M >> X >> Y;
  std::vector<int> x(N);
  std::vector<int> y(M);
  for (int i = 0; i < N; ++i) std::cin >> x[i];
  for (int i = 0; i < M; ++i) std::cin >> y[i];

  int xmax = *std::max_element(x.begin(), x.end());
  int ymin = *std::min_element(y.begin(), y.end());

  for (int i = xmax+1; i <= ymin; ++i) {
    if ( X < i && i <= Y ) {
      std::cout << "No War" << std::endl;
      return 0;
    }
  }
  std::cout << "War" << std::endl;

  return 0;
}

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

int main()
{
    int N, K, R, S, P;
    string T;
    cin >> N >> K >> R >> S >> P >> T;

    int r_count = 0;
    int s_count = 0;
    int p_count = 0;


    for (int i = 0; i < N; i++)
    {
        if(T.at(i)=='r')
            r_count++;
        if (T.at(i) == 's')
            s_count++;
        if (T.at(i) == 'p')
            p_count++;
    }

    for (int i = 0; i + K < N; i++)
    {
        if (T.at(i) == T.at(i + K))
        {
            if (T.at(i) == 'r')
                r_count--;
            if (T.at(i) == 's')
                s_count--;
            if (T.at(i) == 'p')
                p_count--;

            T.at(i + K) = 'L';//Lose
        }
    }

    int64_t sum = r_count * P + s_count * R + p_count * S;

    cout << sum;
}

Measured memory_bytes: 512
package main

import (
	"fmt"
)

func main() {
	var (
		n, m int
	)
	x, y, z := -1, -1, -1
	fmt.Scan(&n, &m)

Label1000:
	// 10000 loop
	for i := 0; i <= n; i++ {
		// 5000 loop
		for j := 0; j <= n-i; j++ {
			// 1000 loop
			for k := n - j - i; i+j+k == n; k-- {
				if m-1000*k < 0 {
					continue
				}
				if m == 1000*k+5000*j+10000*i {
					x, y, z = i, j, k
					break Label1000
				}

			}
		}
	}
	fmt.Println(x, y, z)

}


Measured memory_bytes: 512
from collections import deque

N, M = map(int, input().split())
A = list(map(int, input().split()))

BC = []
for _ in range(M):
    BC.append(tuple(map(int, input().split())))

A.sort()

BC.sort(key=lambda x:x[1], reverse=True)

D = deque([])
for bc in BC:
    b = bc[0]
    c = bc[1]

    for _ in range(b):
        D.append(c)

    if len(D) >= N: 
        break

for i in range(N):
    if A[i] < D[0]:
        A[i] = D[0]
        D.popleft()
        if not D:
            break

print(sum(A))

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

# 1 "<stdin>"
# 1 "<built-in>"
# 1 "<command-line>"
# 31 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 32 "<command-line>" 2
# 1 "<stdin>"

using namespace std;

# 1 "../Algo/NumberTheory/modulo.h" 1
class ModuloOps {
public:
    ModuloOps(long long mod): MOD(mod) {
    }

    long long binPow(long long a, long long b) {
        if (b < 0) {
            throw "invalid op";
        }
        if (b == 0) {
            return 1;
        }
        auto prev = binPow(a, b/2);
        return mul(mul(prev, prev), b % 2 == 1 ? normalize(a) : 1);
    }

    long long inv(long long a) {
        return binPow(a, MOD - 2);
    }

    inline long long add(long long a, long long b) {
        return normalize(a + b);
    }

    inline long long sub(long long a, long long b) {
        return normalize(a - b);
    }

    inline void inc(long long &a, long long b) {
        a = add(a, b);
    }

    inline long long mul(long long a, long long b) {
        return normalize(normalize(a) * normalize(b));
    }

    inline long long div(long long a, long long b) {
        return mul(a, inv(b));
    }

private:
    long long MOD;

    inline long long normalize(long long a) {
        return (a%MOD + MOD) % MOD;
    }
};
# 5 "<stdin>" 2

ModuloOps MOD(1e9 + 7);

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    vector<long long> fact(n+1, 1);
    for (int i = 1; i <= n; i++) {
        fact[i] = MOD.mul(fact[i-1], i);
    }
    auto C = [&] (int n, int k) {
        if (k > n) {
            return 0ll;
        }
        return MOD.div(fact[n], MOD.mul(fact[k], fact[n-k]));
    };
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        auto pos = MOD.mul(C(i, k-1), a[i]);
        auto neg = MOD.mul(C(n-1-i, k-1), a[i]);
        MOD.inc(ans, MOD.sub(pos, neg));
    }
    cout << ans << endl;
}


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

int MaxValue(int x, int y, int z){
  if(x >= y)
    if(x >= z)
      return x;
  return y > z ? y : z;
}

int main(){
  int A, B;cin >> A >> B;
  cout << MaxValue(A+B,A-B,A*B);
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    /* チェックリスト
     * 結果はintの範囲を超えていませんか？(必要な時以外はlongを使いましょう)
     * TLEしそうな処理はありませんか？
     */
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        String dance = sc.nextLine();
        boolean good = true;
        int i = 1;
        for(char c : dance.toCharArray()){
            if(c == 'R'){
                if(i % 2 == 0){
                    good = false;
                }
            }else if(c == 'L'){
                if(i % 2 != 0){
                    good = false;
                }
            }
            i++;
        }
        System.out.println(good ? "Yes" : "No");
    }
}

Measured memory_bytes: 22996
#include <stdio.h>
int main(void){
    int a,b,c,temp=0;
    scanf("%d %d %d",&a,&b,&c);
    
    if(a>b){
        temp=a;
        a=b;
        b=temp;
    }
    if(b>c){
        temp=b;
        b=c;
        c=temp;
    }
    if(a>b){
        temp=a;
        a=b;
        b=temp;
    }
    
  printf("%d %d %d\n",a,b,c);
    return 0;
}


Measured memory_bytes: 2040
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		String s = scn.next();
      	int check = 0;
      	String[] list = s.split("");
      	String[] list1 = new String[s.length()];
      	for(int i=0; i<s.length(); ++i){
          list1[s.length()-(1+i)] = list[i];
        }
      	int check1 = 0;
      	for(int i=0; i<s.length(); ++i){
          if(!(list[i].equals(list1[i]))){
            check1 = 1;
          }
        }
      	if(check1==0){
          check = check + 1;
        }
      	int num2 = (s.length()-1)/2;
      	String[] list2 = new String[num2];
      	for(int i=0; i<num2; ++i){
          list2[i] = list[i];
        }
      	String[] list2a = new String[num2];
      	for(int i=0; i<num2; ++i){
          list2a[num2-(1+i)] = list2[i];
        }
      	int check2 = 0;
      	for(int i=0; i<num2; ++i){
          if(!(list2[i].equals(list2a[i]))){
            check2 = 1;
          }
        }
      	if(check2==0){
          check = check + 1;
        }
      	int num3 = 1+s.length()-(s.length()+3)/2;
      	String[] list3 = new String[num3];
      	for(int i=0; i<num3; ++i){
          list3[i] = list[((s.length()+3)/2-1)+i];
        }
      	String[] list3a = new String[num3];
      	for(int i=0; i<num3; ++i){
          list3a[num3-(1+i)] = list3[i];
        }
      	int check3 = 0;
      	for(int i=0; i<num2; ++i){
          if(!(list3[i].equals(list3a[i]))){
            check3 = 1;
          }
        }
      	if(check3==0){
          check = check + 1;
        }
      	if(check==3){
          System.out.println("Yes");
        }else{
          System.out.println("No");
        }
	}
}


Measured memory_bytes: 35664
#include <iostream>
#include <string>
int main() {
    int n;
    std::cin >> n;
    double y = 0;
    for (int i = 0; i < n; i++) {
        double x;
        std::string u;
        std::cin >> x >> u;
        y += x * (u == "JPY" ? 1 : 380000.0);
    }
    std::cout << y;
}

Measured memory_bytes: 256
use std::cmp::*;
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();

    // n / m == n % m
    // n / m * m + n % m == n
    // (m + 1) * n % m == n
    let mut ans = 0;
    let mut i = 1;
    while i * i <= n {
        if n % i == 0 {
            let d = n / i;
            if i > 1 && d == n % (i - 1) {
                ans += i - 1;
            }

            if n / i != i {
                let d = i;
                if n / i > 1 && d == n % (n / i - 1) {
                    ans += n / i - 1;
                }
            }
        }
        i += 1;
    }

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


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}
void OUT(bool b){cout<<(b?"YES":"NO")<<endl;}
void Out(bool b){cout<<(b?"Yes":"No")<<endl;}
void out(bool b){cout<<(b?"yes":"no")<<endl;}
int popcnt(int x){return __builtin_popcount(x);}
int popcnt(ll x){return __builtin_popcountll(x);}
int bsr(int x){return 31 - __builtin_clz(x);}
int bsr(ll x){return 63 - __builtin_clzll(x);}
int bsf(int x){return __builtin_ctz(x);}
int bsf(ll x){return __builtin_ctzll(x);}

/*他のライブラリを入れる場所*/

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	n*=3;
	vl a(n),x(n,0),y(n,0);
	rep(i,n)cin>>a[i];
	priority_queue<ll,vector<ll>,greater<ll>> pq;
	ll sum=0;
	rep(i,n){
		pq.push(a[i]);
		sum+=a[i];
		if(pq.size()>n/3){
			sum-=pq.top();
			pq.pop();
		}
		x[i]=sum;
	}
	priority_queue<ll> pq2;
	sum=0;
	rep(i,n){
		pq2.push(a[n-1-i]);
		sum+=a[n-1-i];
		if(pq2.size()>n/3){
			sum-=pq2.top();
			pq2.pop();
		}
		y[n-1-i]=sum;
	}
	ll ans=-LINF;
	range(i,n/3-1,n/3*2){
		ans=max(ans,x[i]-y[i+1]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 9588
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <math.h>
using namespace std;

int main() {

	int N;
	cin >> N;

	vector<string> s(N);
	vector<int> t(N);

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

	string X;
	cin >> X;

	int loc = distance(s.begin(), find(s.begin(), s.end(), X));
	int ans = 0;
	for (int i = loc + 1; i < N; i++) {
		ans += t[i];
	}

	cout << ans << endl;

	return 0;
}

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

num_base = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
num_set = set([0])
for i in range(m):
    num_set.add(num_base[a[i]])


def f(x):
    """数xを作るために必要なマッチ棒の本数を返す関数

    :type x: str
    :param x: マッチ棒で作る数
    :rtype: int
    :return: xを作るために必要なマッチ棒の本数
    """

    num_base = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
    ret = 0
    for i in range(len(x)):
        ret += num_base[int(x[i])]

    return ret


def max_num(x, y):
    """xとyの大きいほうを返す関数。
    1.文字列の長さが長い方が大きい
    2.文字列の長さが等しいとき、文字列として比較して大きい方が大きい

    :type x: str
    :param x: マッチ棒で作る数
    :type y: str
    :param y: マッチ棒で作る数
    :rtype: str
    :return: 大きい方の数
    """

    if len(x) > len(y):
        return x
    elif len(y) > len(x):
        return y
    else:
        if x > y:
            return x
        else:
            return y


dp = [""] * (n + 1)
for j in range(2, n + 1):
    for i in range(m):
        match = f(str(a[i]))

        if j == match:
            dp[j] = max_num(dp[j], dp[j - match] + str(a[i]))
            dp[j] = max_num(dp[j], str(a[i]) + dp[j - match])

        elif j > match:
            if dp[j - match] != "":
                dp[j] = max_num(dp[j], dp[j - match] + str(a[i]))
                dp[j] = max_num(dp[j], str(a[i]) + dp[j - match])

print(dp[n])

Measured memory_bytes: 28916
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long 
int ctoi(char c) {return c-'0';}/*char to int*/
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}/*MAX*/
int lcm(ll a,ll b){return a*b/gcd(a,b);}/*MIN*/
bool primecheck(ll n){/*sosuu*/if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
int  main(){
ll a,b,x;
cin >> a >> b >> x;
ll che = b/x;
ll ans = che- a/x;
if(a%x==0)ans++;
cout << ans << endl;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}
constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll k,ans=0;
	cin>>k;
	range(i,1,k+1)range(j,1,k+1)range(l,1,k+1){
		ans+=gcd(i,gcd(j,l));
	}
	puta(ans);
}


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

int main() {
    int n;
    cin >> n;
    int cnt = 0;
    for (int i=0; i<n; i++) {
        int num;
        cin >> num;
        if (num == cnt+1) {
            cnt++;
        }
    }
    int ans = cnt!=0 ? n-cnt : -1;
    cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var s = Console.ReadLine().Trim();

        var easy = true;
        for (int i = 0; i < s.Length; ++i)
        {
            easy = easy && (i % 2 == 0 && s[i] != 'L' || i % 2 != 0 && s[i] != 'R');
        }
        Console.WriteLine(easy ? "Yes" : "No");
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    int N, M; cin >> N >> M;
    vector<int> A(N), B(M); unordered_map<int, int> a, b; bool ok = true;
    REP(i, 0, N) {
        cin >> A[i];
        if(a[A[i]]) ok = false;
        a[A[i]] = i + 1;
    }
    REP(i, 0, M) {
        cin >> B[i];
        if(b[B[i]]) ok = false;
        b[B[i]] = i + 1;
    }
    if (!ok) {
        cout << 0 << endl;
        return 0;
    }

    int count[N * M + 1] = {};
    REP(i, 0, N) {
        REP(j, 0, M) {
            count[min(A[i], B[j])]++;
        }
    }

    vector<int> acnt(N, 0), bcnt(M, 0);
    REP(i, 0, N) {
        REP(j, 0, M) {
            if (A[i] <= B[j]) acnt[i]++;
        }
    }
    REP(j, 0, M) {
        REP(i, 0, N) {
            if (A[i] >= B[j]) bcnt[j]++;
        }
    }

    ll ans = 1; int cnt = 0;
    for (int i = N * M; i > 0; i--) {
        cnt += count[i];
        if (a[i] && b[i]) {
            continue;
        } else if (a[i]) {
            ans = (ans * acnt[a[i] - 1]) % MOD;
        } else if (b[i]) {
            ans = (ans * bcnt[b[i] - 1]) % MOD;
        } else {
            ans = (ans * (cnt - (N * M - i))) % MOD;
        }
    }
    cout << ans << endl;

    return 0;
}

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

#define fi first
#define se second
#define pb push_back
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define FOR(i, a, b) for (int i = a; i <= (b); i++)
#define ROF(i, a, b) for (int i = a; i >= (b); i--)

using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long;
using pll = pair<ll, ll>; using vpll = vector<pll>;
using vll = vector<ll>; using vvll = vector<vll>;

const int MOD = 1e9 + 7;

int main() { 
    int n, k; cin >> n >> k;
    ll ans = 0;
    vll cnt(n + 1);
    FOR(i, 1, n + 1)
        cnt[i] = (cnt[i - 1] + i) % MOD;
    FOR(i, k, n + 1) {
        // cout << cnt[n + 1] << ' ' << cnt[n - i + 1] << ' ' << cnt[i] << endl;
        ans = (ans + (cnt[n + 1] - cnt[n - i + 1]) - cnt[i] + 1 + MOD) % MOD;
    }
    cout << ans << endl;
}

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

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

int f(int n) {
  int ans = 0;
  while(n != 0) {
    ans += n % 10;
    n /= 10;
  }
  return ans;
}

int main() {
  int N;
  cin>>N;
  int ans = 1<<29;
  for(int a = 1; a < N; a++) {
    int b = N-a;
    if(a>b)break;
    int tmp = f(a) + f(b);
    ans = min(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >>s;
  long long cnt=0;
  long long kotae=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='B')cnt++;
    else kotae+=cnt;
  }    
  cout<<kotae<<endl;
  return 0;
}
    

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

template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define fi first
#define se second
#define pb push_back
#define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,a,b) for(int i = a; i < b; i++)
#define forr(i,a,b) for(int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int maxn = 1e7+10;
ll cnt[maxn];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	for(int i = 1; i <= maxn; i++){
		for(int j = i; j <= maxn; j += i){
			cnt[j]++;
		}
	}
	int N; cin >> N;
	ll res = 0;
	for(ll i = 1; i <= N; i++){
		res += i*cnt[i];
	}
	cout << res << '\n';
	return 0;
}
/*
__builtin_mul_overflow(x,y,&x)
-fsplit-stack
*/


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

int main(){
    long long n,k;
    cin >> n >> k;
    long long h[n];
    for(int i=0;i<n;i++){
        cin >> h[i];
    }
    sort(h,h+n);
    long long ans=1e9;
    for(int i=0;i<n-k+1;i++){
        ans=min(ans,h[i+k-1]-h[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
/**
  *    █████╗  ██████╗       ██████╗ ██╗     ███████╗
  *   ██╔══██╗██╔════╝       ██╔══██╗██║     ╚══███╔╝
  *   ███████║██║            ██████╔╝██║       ███╔╝
  *   ██╔══██║██║            ██╔═══╝ ██║      ███╔╝
  *   ██║  ██║╚██████╗▄█╗    ██║     ███████╗███████╗
  *   ╚═╝  ╚═╝ ╚═════╝╚═╝    ╚═╝     ╚══════╝╚══════╝
  *
  *  @Author: TieWay59
  *  @Created: 2020/8/15 21:20
  *  @Link: https://atcoder.jp/contests/agc047/tasks/agc047_a
  *  @Tags:
  *
  *******************************************************/

#include <bits/stdc++.h>

#ifdef DEBUG

#   include "libs59/debugers.h"
//  #define debug(x)  cerr <<#x << " = "<<x<<endl;
#else
#   define endl '\n'
#   define debug(...)
#   define max(x,y) ((x)>(y)?(x):(y))
#   define min(x,y) ((x)>(y)?(y):(x))
#endif

#define STOPSYNC ios::sync_with_stdio(false);cin.tie(nullptr)
#define MULTIKASE int Kase=0;cin>>Kase;for(int kase=1;kase<=Kase;kase++)
typedef long long ll;
const int MAXN = 2e5 + 59;
const int MOD = 1e9 + 7;
const int INF = 0x3F3F3F3F;
const ll llINF = 0x3F3F3F3F3F3F3F3F;
using namespace std;
using pii = pair<int, int>;
using vint = vector<int>;

ll fpow(ll a, ll b, ll mod = MOD) {
    if (a % mod == 0) return 0;
    ll ret = 1;
    a %= mod;
    while (b) {
        if (b & 1)ret = ret * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ret;
}


void solve(int kaseId = -1) {
    int n;
    cin >> n;
    map<pair<int, int>, int> cnt;
    for (int i = 1; i <= n; ++i) {
        long double ai;
        cin >> ai;
        ll val = (ll) (ai * 1000000000.0 + 0.5);
        ll cnt2 = 0;
        ll cnt5 = 0;
        while (val % 2 == 0) {
            cnt2++;
            val /= 2;
        }
        while (val % 5 == 0) {
            cnt5++;
            val /= 5;
        }
        cnt[make_pair(cnt2, cnt5)]++;
    }

    ll ans = 0;
    for (const auto &pi: cnt) {
        for (const auto &pj: cnt) {
            if (pi.first.first + pj.first.first >= 18 &&
                pi.first.second + pj.first.second >= 18) {
                if (pi == pj) {
                    ans += pi.second * (pi.second - 1ll);
                } else {
                    ans += pi.second * 1ll * pj.second;
                }
            }
        }
    }
    debug(cnt);

    cout << ans / 2 << endl;
}

void solves() {
    MULTIKASE {
        solve(kase);
    }
}

int main() {
#ifdef DEBUG
    freopen("input.txt", "r+", stdin);
#endif
    STOPSYNC;
    solve();
    return 0;
}
/*

 */

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

using namespace std;

bool dp[4001][16001];
int x,y;
string s;
int ax[4001],ay[4001];
int tx,ty;

void dfsx(int t,int n){
	if (dp[t][8000+n])return ;
	if (t<tx){
		dfsx(t+1,n+ax[t]);
		dfsx(t+1,n-ax[t]);
	}
	
	dp[t][n+8000]=1;
}

void dfsy(int t,int n){
	if (dp[t][8000+n])return ;
	if (t<ty){
		dfsy(t+1,n+ay[t]);
		dfsy(t+1,n-ay[t]);
	}
	
	dp[t][n+8000]=1;
}

int main()
{
	cin>>s;
	cin>>x>>y;
	int i,j;
	bool fx=1;
	for (i=0;i<s.size();i++){
		if (s[i]=='F'){
			if (fx)ax[tx]++;
			else ay[ty]++;
		}
		else{
			if (fx)fx=0,tx++;
			else fx=1,ty++;
		}
	}
	if (s[s.size()-1]=='F'){
		if (fx)tx++;
		else ty++;
	}
	dfsx(1,ax[0]);
	bool xx=dp[tx][8000+x];
	
	memset(dp,0,sizeof(dp));
	dfsy(0,0);
	bool yy=dp[ty][8000+y];
	
	if (xx && yy){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}

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

int main() {
  int N;
  cin>>N;
  vector<int> vec(N);

  for(int i=0;i<N;i++){
  cin >> vec.at(i);
  }

  int sum=0;
  int a;
  for(int i=0;i<N-1;i++){
   a=max(vec.at(i),vec.at(i+1));
   sum+=vec.at(i)+vec.at(i+1)-a;
    vec.at(i)=a;
    vec.at(i+1)=a;
  }
  
  if(sum>a)
    cout<<"Yes";
  else
    cout<<"No";
     
  
}

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

const int maxn=105;

int n,m;
int a[maxn][maxn],b[maxn][maxn];
int ecnt,dep[1005],cur[1005],head[1005];
struct Edge{int v,next,flow;}edge[100005];
stack<int> c[maxn][maxn];

inline int get_col(int x){return (x-1)/m+1;}
inline void add_edge(int u,int v,int flow){
	edge[ecnt]=(Edge){v,head[u],flow},head[u]=ecnt++;
	edge[ecnt]=(Edge){u,head[v],0},head[v]=ecnt++;
}

bool bfs(int s,int t){
	memset(dep+1,0,4*t);
	queue<int> Q;dep[s]=1,Q.push(s);
	while(!Q.empty()){
		int u=Q.front();Q.pop();
		for(int i=head[u],v;~i;i=edge[i].next){
			v=edge[i].v;
			if(edge[i].flow&&!dep[v])
				dep[v]=dep[u]+1,Q.push(v);
		}
	}
	return dep[t];
}

int dfs(int u,int flow,const int &t){
	if(u==t)return flow;
	int used=0,rlow;
	for(int v,&i=cur[u];~i;i=edge[i].next){
		v=edge[i].v;
		if(edge[i].flow&&dep[v]==dep[u]+1){
			rlow=dfs(v,min(edge[i].flow,flow-used),t);
			if(rlow)edge[i].flow-=rlow,edge[i^1].flow+=rlow,used+=rlow;
			if(used==flow)break;
		}
	}
	if(!used)dep[u]=-1;
	return used;
}

int main(){
	scanf("%d%d",&n,&m);
	memset(head+1,0xff,4*(n*2+2));
	for(int i=1;i<=n;i++)
		for(int j=1,x;j<=m;j++){
			scanf("%d",&a[i][j]),x=get_col(a[i][j]);
			c[i][x].push(a[i][j]),add_edge(i,n+x,1);
		}
	int s=n*2+1,t=s+1;
	for(int id=1;id<=m;id++){
		for(int i=1;i<=n;i++)
			add_edge(s,i,1),add_edge(i+n,t,1);
		while(bfs(s,t)){
			memcpy(cur+1,head+1,4*t);
			dfs(s,0x3f3f3f3f,t);
		}
		for(int i=n+1;i<=2*n;i++)
			for(int j=head[i],v;~j;j=edge[j].next)
				if(edge[j].flow){
					edge[j].flow=0,v=edge[j].v;
					b[v][id]=c[v][i-n].top(),c[v][i-n].pop();
				}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++)
			cout<<b[i][j]<<' ',a[get_col(b[i][j])][j]=b[i][j];
		cout<<'\n';
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++)cout<<a[i][j]<<' ';
		cout<<'\n';
	}
	return 0;
}

Measured memory_bytes: 11880
#include<stdio.h>

#define M 2000001
#define INFTY (1<<30)

int H,A[M];

void maxHeapify(int i){
  int l,r,biggest,tmp;
  l=2*i;
  r=2*i+1;
  if(l<=H&&A[l]>A[i])
    biggest=l;
  else
    biggest=i;
  if(r<=H&&A[r]>A[biggest])
    biggest=r;
  if(biggest!=i){
    tmp=A[i];
    A[i]=A[biggest];
    A[biggest]=tmp;
    maxHeapify(biggest);
    }
}

int extract(){
  int maxv;
  if(H<1)return -INFTY;
  maxv = A[1];
  A[1] = A[H--];
  maxHeapify(1);
  return maxv;
}

void increKey(int i,int key){
  int tmp;
  if(key<A[i])return;
  A[i] = key;
  while(i>1&&A[i/2]<A[i]){
    tmp = A[i];
    A[i] = A[i/2];
    A[i/2] = tmp;
    i = i/2;
  }
}

void insert(int key){
  H++;
  A[H]=-INFTY;
  increKey(H,key);
}

int main(){
  int key;
  char com[10];
  while(1){
    scanf("%s",com);
    if(com[0]=='e'&&com[1]=='n'){
      break;
    }
    if(com[0]=='i'){
      scanf("%d",&key);
      insert(key);
    }
    else printf("%d\n",extract());
  }
  return 0;
}

Measured memory_bytes: 4696
#include <stdio.h>

#define N 100000

typedef struct {
    char s[11];
    int time;
} Process;

void enqueue(Process);
Process dequeue();
int isEmpty();
int isFull();

int head = 0;
int tail = 0;
Process p[N];

int main() {
    int i;
    int time, dtime;
    int num;
    Process ip;

    scanf("%d %d", &num, &time);

    for (i = 0; i < num; i++) {
        scanf("%s %d", ip.s, &ip.time);
        enqueue(ip);
    }

    dtime = 0;
    while (!isEmpty()) {

        ip = dequeue();
        ip.time -= time;

        if (ip.time <= 0) {
            dtime += (time + ip.time);
            printf("%s %d\n", ip.s, dtime);
        }
        else {
            dtime += time;
            enqueue(ip);
        }
    }


}

void enqueue(Process process){
    if (isFull()) {
        return;
    }
    if (tail == N) tail = 0;
    p[tail] = process;
    tail++;
}

Process dequeue() {
    Process pr;
    pr.time = -1;
    if (isEmpty()) {
        return pr;
    }
    pr = p[head];
    if (head + 1 == N) {
        head = 0;
    } else {
        head ++;
    }

    return pr;
}

int isEmpty() {
    return head == tail;
}

int isFull() {
    return head == (tail + 1) % N;
}



Measured memory_bytes: 3252
N=int(input())
string=[input() for _ in range(N)]
string.sort()
string.append("0")
max=0
cnt=1
ans=[]
for i in range(N):
    if string[i]==string[i+1]:
        cnt+=1
    elif cnt>max:
        ans=[string[i]]
        max=cnt
        cnt=1
    elif cnt==max:
        ans.append(string[i])
        cnt=1
    else:
        cnt=1
for word in ans:
    print(word)


Measured memory_bytes: 20676
fun main(args: Array<String>){

  val S = readLine()!!
  val AB = S.substring(0,2).toInt()
  val CD = S.substring(2).toInt()

  when {
    (0 < AB && AB <=12 ) && (0 < CD && CD <=12) -> println("AMBIGUOUS")
    (0 < AB && AB <=12 ) && (CD ==0 || 12 < CD) -> println("MMYY")
    (AB ==0 || 12 < AB ) && (0 < CD && CD <=12) -> println("YYMM")
    (AB ==0 || 12 < AB ) && (CD ==0 || 12 < CD) -> println("NA")
  }

}


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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
struct edge{int from, to; ll cost;};

const ll MOD = 1000000007;
const long double EPS = 1e-10;

int main(){
    std::ios::sync_with_stdio(0); cin.tie(0);
    ll a,b,c, k;
    cin >> a >> b >> c >> k;

    if(k % 2){
        cout << b-a << endl;
    }else{
        cout << a-b << endl;
    }

}

Measured memory_bytes: 764
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;
const ll mod=(ll)1e9+7;
//}}}

int main(){
  int A, B, K;
  cin >> A >> B >> K;
  if(A > B) swap(A, B);
  int num = 0;
  rrep(i, A + 1){
    if(A % i == 0 && B % i == 0){
      num++;
      if(num == K){
        cout << i << endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 256
n_vertex, n_edge = gets.split.map(&:to_i)
#puts "#{n_vertex} #{n_edge}"
edges = n_vertex.times.map { Array.new(n_vertex, -1) }
for i in 0...n_edge do
  u, v, d = gets.split.map(&:to_i)
#  puts "#{u} #{v} #{d}"
  edges[u - 1][v - 1] = d
  edges[v - 1][u - 1] = d
end
#for i in 0...n_vertex do
#  puts edges[i].join(" ")
#end

for i in 1...n_vertex do
  if edges[0][i] > 0
    targ_v = i
    targ_d = edges[0][i]
    break
  end
end
#puts "#{targ_v} #{targ_d}"

t_max = gets.to_i
#puts "#{t_max}"
count = 0
for t in 0...t_max do
  n_new = gets.to_i
#  puts "#{n_new}"
  for i in 0...n_new do
    new_id, dst = gets.split.map(&:to_i)
#    puts "#{new_id} #{dst}"
  end
  
  if t < t_max / 2
    command = -1
  else
    if count < targ_d
      command = targ_v + 1
      count += 1
    else
      command = -1
    end
  end
  puts command
end


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

int main(void){

  int x,ybas,ylim,yvol,us;
  int resx,resy;

  cin >> x >>ybas >> ylim >> yvol >> us;

  resx = us * x;
  resy = ybas;
  resy += (ylim < us)? (us - ylim) * yvol : 0;

  if(resx < resy) cout << resx << endl;
  else cout << resy << endl;
  
  return 0;
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T &a, T b) {if (a < b) {a = b;return 1;}return 0;}
template<class T> inline bool chmin(T &a, T b) {if (a > b) {a = b;return 1;}return 0;}

int main(){
	string s; cin>>s;
  if (s[0] == 'R' && s[1] == 'R' && s[2] == 'R') cout << 3 << endl;
  else if ((s[0] == 'R' && s[1] == 'R') || (s[1] == 'R' && s[2] == 'R')) cout << 2 << endl;
  else if (s[0] == s[1] && s[1] == s[2] && s[0] == 'S') cout << 0 << endl;
  else cout << 1 << endl;
}


Measured memory_bytes: 3592
s=input()
ans=[0]*len(s)
s+='R'
flg=False
cr=0
cl=0
for i in range(len(s)):
    if s[i]=='R':
        if flg:
            ans[rp]=-(-cr//2)+cl//2
            ans[lp]=cr//2+-(-cl//2)
            flg=False
            cr=0
            cl=0
        cr+=1
    else:
        if not flg:
            rp=i-1
            lp=i
            flg=True
        cl+=1
print(*ans)

Measured memory_bytes: 6400
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string a = Console.ReadLine();
            string b = Console.ReadLine();
            string c = Console.ReadLine();

            char card = a[0];
            a = a.Remove(0, 1);
            bool flag = true;
            while (flag)
            {
                switch (card)
                {
                    case 'a':
                        if (a.Length == 0)
                        {
                            Console.WriteLine("A");
                            flag = false;
                        }
                        else
                        {
                            card = a[0];
                            a = a.Remove(0, 1);
                        }
                        break;

                    case 'b':
                        if (b.Length == 0)
                        {
                            Console.WriteLine("B");
                            flag = false;
                        }
                        else
                        {
                            card = b[0];
                            b = b.Remove(0, 1);
                        }
                        break;

                    case 'c':
                        if (c.Length == 0)
                        {
                            Console.WriteLine("C");
                            flag = false;
                        }
                        else
                        {
                            card = c[0];
                            c = c.Remove(0, 1);
                        }
                        break;
                    default:
                        break;
                }
            }
        }
    }
}


Measured memory_bytes: 2900
#include <iostream>
#include <cstdlib>
#include <string>
#include <ctime>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <queue>
#include <utility>
#include <cmath>
using namespace std;

int main(){
	int n, k;
	scanf("%d%d", &n, &k);
	int ans = 0;
	for(int i = 0; i < n; i++){
		int x;
		scanf("%d", &x);
		ans += min(x*2, abs(k-x)*2);
	}
	printf("%d\n", ans);
	return 0;
}

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


int main() {
  ll n;
  cin>>n;
  ll ans=0;
  rep(i,n){
    ll temp=(i+1)*(n-i);
    ans+=temp;
  }
//  cout<<ans<<endl;
  rep(i,n-1){
    ll u1,v1;
    cin>>u1>>v1;
    u1--;v1--;
    if (u1>v1)swap(u1,v1);
    ll temp=(u1+1)*(n-v1);
    ans-=temp;
  }
  cout<<ans;
}


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

int main() {
  int N;
  string S;
  cin >> N >> S;
  vector<int> V(26);
  for (auto c : S) V.at(c - 'a')++;
  while (cin >> S) {
    vector<int> tmp(26);
    for (auto c : S) tmp.at(c - 'a')++;
    for (int i = 0; i < 26; i++) {
      V.at(i) = min(V.at(i), tmp.at(i));
    }
  }
  for (int i = 0; i < 26; i++) {
    if (V.at(i)) while (V.at(i)--) cout << char('a' + i);
  }
  cout << "\n";
}

Measured memory_bytes: 3604
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    s=input()
    k=int(input())
    for i in range(k):
        if(s[i]!='1'):
            print(int(s[i]))
            return
    print(1)
resolve()

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

signed main(){
	int N;
	cin >> N;
	int sum = 0;
	for(int i = 1; i <= N; i++){
		int a;
		cin >> a;
		if(i%2 && a%2){
			++sum;
		}
	}
	cout << sum << endl;

 
	return 0;
}

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

int main() {

	ll n; cin >> n;
	map<string,ll> mp;
	for (int i = 0; i < n; i++) {
		string tmp; cin >> tmp;
		sort(tmp.begin(), tmp.end());
		mp[tmp]++;
	}
	ll ans = 0;
	for (auto u : mp) {
		ans += u.second * (u.second - 1) / 2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 11284
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>


using namespace std;

int main() {
	int n,m;
	cin >> n >> m;
	vector<int> x;
	for(int i = 0;i < m;i++) {
		int xx;
		cin >> xx;
		x.push_back(xx);
	}
	sort(x.begin(),x.end());
	vector<int> dif;
	for(int i = 0;i < x.size() - 1;i++) {
		dif.push_back(x[i+1] - x[i]);
	}
	sort(dif.begin(),dif.end());
	int cnt = m;
	int dist = 0;
	int cur = 0;
	while(cnt > n){
		dist += dif[cur];
		cur++;
		cnt--;
	}
	cout << dist << endl;
}


Measured memory_bytes: 1400