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

typedef long long int ll;
typedef vector<int> vi;     typedef vector<ll> vl;
typedef vector<vi> vvi;     typedef vector<vl> vvl;
typedef pair<int, int>  pii;  typedef pair<ll, ll> pll;
typedef vector<pii> vii;    typedef vector<pll> vll;
typedef map<int,int> mii;
typedef vector<char> vc;
typedef vector<bool> vb;
#define endl '\n'
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define trav(a,x) for(auto &a:x)
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define pf push_front
#define rb pop_back
#define rf pop_front
#define in insert
#define mp make_pair
#define fill(a,x) memset(a,x,sizeof a);
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
const ll INFL = 1e18;
const int INFI = 1e9;
#ifdef EVIL
	#include "../../trace.h"
#else
	#define trace(args...)
#endif

ll div_floor(const ll &a,const ll &b) { return a / b - (((a ^ b) < 0) and a % b);}
ll div_ceil(const ll &a,const ll &b) { return a / b + (((a ^ b) >= 0) and a % b);}
ll modpow(ll a, ll b, ll m = MOD){a %= m; ll res = 1; 
	while (b) {if (b & 1)res = (res * a) % m; a = (a * a) % m; b >>= 1;} return res;}
ll bpow(ll a, ll b){ll res = 1; while (b) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}
ll modinv(ll a, ll m = MOD) {return modpow(a, m - 2, m);}
// void graph(vvi &adj, int m) {int x, y; forn(i, m){cin>>x>>y; adj[--x].pb(--y); adj[y].pb(x);}}

list<pair<ll,int>> l1;
void primeFactors(ll n);

void solve(){
	ll n;
	cin>>n;
	primeFactors(n);
	ll ctr=0;
	for(auto&ele:l1){
		int a=ele.S;
		long double b = sqrtl(1+8*a);
		long double c=(-1+b)/2;
		ll d=c;
		ctr+=d;
	}
	cout<<ctr;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	#ifdef EVIL
		freopen("inp.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
		freopen("err.txt", "w", stderr);
	#endif
	int t=1;
	// cin>>t;
	rep(q,0,t-1){
		solve();
	}
}


// A function to print all prime 
// factors of a given number n 
void primeFactors(ll n) 
{ 
	// Print the number of 2s that divide n 
	int ctr=0;
	while (n % 2 == 0) 
	{ 
		++ctr;
		// cout << 2 << " ";
		n = n/2; 
	} 
	l1.push_back(mp(2,ctr));
	ctr=0;

	// n must be odd at this point. So we can skip 
	// one element (Note i = i +2) 
	for (int i = 3; i <= sqrt(n); i = i + 2) 
	{ 
		// While i divides n, print i and divide n 
		while (n % i == 0) 
		{ 
			++ctr;
			// cout << i << " "; 
			n = n/i; 
		} 
		l1.push_back(mp(i,ctr));
		ctr=0;
	} 

	// This condition is to handle the case when n 
	// is a prime number greater than 2 
	if (n > 2) {
		l1.push_back(mp(n,1));
		ctr=0;
		// cout << n << " "; 
	}
} 


Measured memory_bytes: 27112
n = int(input())
a = []
xy = []

for _ in range(n):
    i = int(input())
    a.append(i)
    ls = []
    for _ in range(i):
        ls.append(list(map(int, input().split())))
    xy.append(ls)

ans = 0
for i in range(2**n):
    # 正直者リスト
    _true = [0]*n
    bl = True
    for j in range(n):
        if (i >> j) & 1:
            _true[j] = 1
    for j in range(n):
        # 正直者の話だけ聞く
        if _true[j] == 1:
            # 証言を１つずつ確認して矛盾があったら終わり
            for x, y in xy[j]:
                if _true[x-1] != y:
                    bl = False
                    break
    if bl:
        ans = max(ans, sum(_true))

print(ans)


Measured memory_bytes: 3064
use std::io::*;
use std::str::FromStr;
use std::cmp;

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

fn main() {
    let a = read::<i64>();
    let b = read::<i64>();
    println!("{}", (a-1) * (b-1));
}


Measured memory_bytes: 4352
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(X, Y) for (int(X) = 0; (X) < (Y); ++(X))
#define rrep(X, Y) for (int(X) = (Y)-1; (X) >= 0; --(X))
#define itrep(X, Y) for (auto(X) = (Y).begin(); (X) != (Y).end(); (X)++)
#define all(X) (X).begin(), (X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define print(x) cout << x << endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const string YES = "Yes";
const string NO = "No";

void solve(long long N, std::vector<long long> a) {
  ll maxA = -1;
  ll minA = 1e6;
  ll maxCnt = 0;
  ll minCnt = 0;
  rep(i, N) {
    if (maxA < a[i]) {
      maxA = a[i];
      maxCnt = 1;
    } else if (maxA == a[i]) {
      maxCnt++;
    }

    if (minA > a[i]) {
      minA = a[i];
      minCnt = 1;
    } else if (minA == a[i]) {
      minCnt++;
    }
  }

  if (maxA == minA) {
    bool ok = true;
    // 全員がalone
    rep(i, N) {
      if (a[i] != N - 1) {
        ok = false;
        break;
      }
    }

    if (ok) {
      print(YES);
      return;
    }

    // 全員がnot alone
    if (2 * maxA <= N) {
      print(YES);
      return;
    }
  } else if (maxA - minA == 1) {
    if (minCnt < maxA && 2 * (maxA - minCnt) <= maxCnt) {
      print(YES);
      return;
    }
  }

  print(NO);
}

int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> a(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &a[i]);
  }
  solve(N, std::move(a));
  return 0;
}


Measured memory_bytes: 1024
<?php
// Computation - Simple Calculator
while(true){
    $data = explode(" ",trim(fgets(STDIN)));
    $a = $data[0];
    $op = $data[1];
    $b = $data[2];
    if($op === "?"){
        break;          // ??\?????????
    }
    switch ($op) {
        case "+":
            echo ($a + $b)."\n";
            break;
        case "-":
            echo ($a - $b)."\n";
            break;
        case "*":
            echo ($a * $b)."\n";
            break;
        case "/":
            echo floor($a / $b)."\n";
            break;
    }
}

Measured memory_bytes: 15368
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define rrep(i,n) for(int i=n-1; i>=0; i--)

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef long double lb;

const int INF=1<<27;
const int MOD=(int)1e9+7;

int main(void)
{
    int a, b;
    cin >> a >> b;
    if((a%2)*(b%2)){
        cout << "Odd" << endl;
    }else{
        cout << "Even" << endl;
    }
    return 0;
}



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

const int MAX = 2005;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  long long n,k;
  cin >> n >> k;
  COMinit();
  for(int i=1;i<=k;i++){
    cout << COM(n-k+1,i)*COM(k-1,i-1)%MOD << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<functional>
#include<algorithm>
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define pf push_front
#define pb push_back
#define int long long
using namespace std;
const int INF=1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const int N=101;

int net[N][N];

int bfs(int n,int s,int d){
  vector<int> time(n);
  queue<int> que;
  rep(i,n)time[i]=INF;
  time[s]=0;
  que.push(s);
  int u;
  while(!que.empty()){
    u=que.front(),que.pop();
    rep(i,n){
      if(time[i]>time[u]+net[u][i]){
        time[i]=time[u]+net[u][i];
        que.push(i);
      }
    }
  }
  return time[d];
}

signed main(){
  int n;
  cin>>n;
  rep(i,n)rep(j,n)net[i][j]=INF;
  rep(i,n){
    int r,k;
    cin>>r>>k;
    r--;
    rep(i,k){
      int t;
      cin>>t;
      t--;
      net[r][t]=1;
    }
  }

  int p;
  cin>>p;
  rep(i,p){
    int s,d,v;
    cin>>s>>d>>v;
    s--;d--;
    int ans=bfs(n,s,d)+1;

    if(ans<=v)cout<<ans<<endl;
    else cout<<"NA"<<endl;
  }
 return 0;
}

Measured memory_bytes: 3100
#include <iostream>

using namespace std;

void solve()
{
	double height;
	double Max = 0;
	double Min = 99999999;
	while(cin >> height)
	{
		Max = max(Max, height);
		Min = min(Min, height);
	}
	cout << Max - Min << endl;
}

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

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

using namespace std;

template<typename C>
class seg_tree {
  vector<C> tree;
  function<C(C, C)> key;
  C def;
  int p = 1;
public:
  seg_tree(int n, function<C(C, C)> _key, C _def) : key(_key), def(_def) {
    while (p < n) {
      p <<= 1;
    }
    tree.resize(p << 1, def);
  }

  seg_tree(const vector<C>& a, function<C(C, C)> _key, C _def) : key(_key), def(_def) {
    while (p < a.size()) {
      p <<= 1;
    }
    tree.resize(p << 1, def);
    for (int i = 0; i < a.size(); ++i) {
      tree[i ^ p] = a[i];
    }
    for (int i = p - 1; i; --i) {
      tree[i] = key(tree[i << 1], tree[i << 1 | 1]);
    }
  }

  C get(int l, int r) {
    C res = def;
    for (l ^= p, r ^= p; l <= r; l >>= 1, r >>= 1) {
      if (l & 1) {
        res = key(res, tree[l++]);
      }
      if ((r & 1) == 0) {
        res = key(res, tree[r--]);
      }
    }
    return res;
  }

  void update(int k, C x) {
    k ^= p;
    tree[k] += x;
    for (k >>= 1; k; k >>= 1) {
      tree[k] = key(tree[k << 1], tree[k << 1 | 1]);
    }
  }
};

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

  int n;
  cin >> n;
  vector<int> h(n);
  seg_tree<long long> t(n + 1, [](auto a, auto b) { return max(a, b); }, 0);
  for (int i = 0; i < n; ++i) {
    cin >> h[i];
  }
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    long long x = t.get(0, h[i]);
    t.update(h[i], a + x);
  }
  cout << t.get(0, n);

  return 0;
}

Measured memory_bytes: 5120
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <set>
#include <ctime>
using namespace std;
typedef long long ll;
const int maxn=100050;
const int inf=0x3f3f3f3f;
const ll N=1e9+7;
struct Edge{
    int v,nxt,c;
}e[maxn*4];
int h[maxn],tot;
void addEdge(int x,int y,int c){
    e[++tot]=(Edge){y,h[x],c};
    h[x]=tot;
}
struct node{
    int x,d;
    node(int x,int d):x(x),d(d){}
    bool operator < (const node&y)const{
        // return d>y.d;
        if(d!=y.d) return d>y.d;
        return x<y.x;
    }
};
int n,m;
bool vis[maxn];
int dis[maxn];
int pre[maxn];
set<int> s[maxn];
int dijkstra(){
    priority_queue<node> q;
    memset(dis,0x3f,sizeof dis);
    q.push(node(1,0));
    dis[1]=0;
    while(!q.empty()){
        node u=q.top();
        q.pop();
        if(u.d>dis[u.x]) continue;
        for (int i = h[u.x]; i ; i=e[i].nxt)
        {
            int v=e[i].v;
            int w=(s[u.x].count(e[i].c)?0:1)+u.d;
            if(dis[v]>w){
                dis[v]=w;
                q.push(node(v,dis[v]));
                s[v].clear();
                s[v].insert(e[i].c);
            }
            else if(dis[v]==w) s[v].insert(e[i].c);
        }
    }
    return dis[n]>=inf?-1:dis[n];
}
int main(int argc, char const *argv[])
{
    scanf("%d%d", &n,&m);
    for(int i = 0; i < m; ++i){
        int x,y,c;
        scanf("%d%d%d", &x,&y,&c);
        addEdge(x,y,c);
        addEdge(y,x,c);
    }
    cout << dijkstra() << endl;
    return 0;
}

Measured memory_bytes: 20600
//#include "stdafx.h"
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define	BitSetV(Val,Bit)		((Val) |= (Bit))			
#define	BitTstV(Val,Bit)		((Val) & (Bit))				
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long long int	QWORD;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int main()
{
	int A, B, C;
	cin >> A >> B >> C;
	cout << A * B / 2 << endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input().rstrip())
d = {}
for _ in range(N):
    string = input().rstrip()
    if string in d.keys():
        d[string] += 1
    else:
        d[string] = 1
d = sorted(d.items(), key=lambda x: x[1], reverse=True)
# print(d)
rets = []
max = -1
for string, val in d:
    if max == -1:
        max = val
    elif max != val:
        break
    rets.append(string)

for a in sorted(rets):
    print(a)


Measured memory_bytes: 43228
Module Module1

    Sub Main()
        Dim instr() As String = Split(Console.ReadLine())
        Dim n As Integer = CInt(instr(0))
        Dim t As Integer = CInt(instr(1))
        Dim ans As Integer = 1001

        For i As Integer = 1 To n
            instr = Split(Console.ReadLine())
            Dim ci As Integer = CInt(instr(0))
            Dim ti As Integer = CInt(instr(1))
            If ti <= t And ci < ans Then
                ans = ci
            End If
        Next
        If ans <> 1001 Then
            Console.WriteLine(ans)
        Else
            Console.WriteLine("TLE")
        End If
    End Sub

End Module


Measured memory_bytes: 13532
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
const long long inf = 1000000001; // const 書き換え禁止
const double PI = 3.14159265358979323846; //M_PI はライブラリ

int main(void){
    int H,W,h,w;
    cin >> H >> W >> h >> w;
    int ans =H*W - ( W*h + (H*w) - (h*w) );
    
    cout << ans << endl;
}

Measured memory_bytes: 3592
'use script';

	{
	function Main(input) {
		const N = input;
		const b = 1000000000+7;

		let d10 = 1;
		let d9 = 1;
		let d8 = 1;
		
		for(i=0; i<N; i++){
			d10 = d10 * 10 % b;
			d9 = d9 * 9 % b;
			d8 = d8 * 8 % b;
		}
		
		let ans = d10-d9*2+d8;
		ans = (ans % b + b) % b;     
		console.log(ans);

	}
  
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
}

Measured memory_bytes: 33132
#include <iostream>

using namespace std;

int main()
{
    int w, h;
    
    do
    {
        cin  >> w >> h;
        
        if(w == 0 && h == 0)
            break;
        
        else
            for(int i = 0; i < w; i++)
            {
                if(i % 2 == 0)
                {
                    for(int c = 0; c < h; c++)
                    {
                        if(c % 2 == 0)
                            cout << '#';
                        else
                            cout << '.';
                    }
                }
                
                else
                {
                    for(int c = 0; c < h; c++)
                    {
                        if(c % 2 == 1)
                            cout << '#';
                        else
                            cout << '.';
                    }
                }
  
                cout << endl;
            }
        
        cout << endl;
    }while(true);

    return 0;
}

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


int main(){

    ll N;
    cin >> N;
    int m = 100;
    for(ll i=1;i*i<=N;i++){
        if(N%i) continue;
        m = min(m, (int)max(to_string(i).size(), to_string(N/i).size()));
    }
    cout << m << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
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; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;
ll primenum[1001];
ll MOD = 1e9 + 7;

void sieve(ll n) {
  while(n != 1) {
    bool divflag = false;
    ll i = 2;
    // cout << "a " << n << " " << i << endl;
    while(!divflag){
      if (n % i == 0) {
        n /= i;
        primenum[i]++;
        divflag = true;;
      }
      i++;
      // cout << "b " << n << " " << i << endl;
    }
  }
}

int main() {
  ll n;
  cin >> n;
  reps1(i, n+1) {
    sieve(i);
  }

  ll ans = 1;
  reps1(i, n+1)
    if (primenum[i]) ans = (ans * (primenum[i]+1)) % MOD;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int r;
  cin>>r;
  if(r<1200)
  {
    cout<<"ABC";
  }
  else if(r>=1200 && r<2800)
  {
    cout<<"ARC";
  }
  else
  {
    cout<<"AGC";
  }
}


Measured memory_bytes: 3576
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include<vector>
#include<iostream>
#include<set>
#include<map>
#include<algorithm>
using namespace std;




int main() {
	int n,a,b;
	cin >> n >> a >> b;
	
	cout << min(n*a,b) << endl;
    return 0;
}


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

string MINF = "-";

void chmax(string &a, string b){
    
    if(a == MINF) a = b;
    else if(b.size() > a.size()) a = b;
    else if(b.size() < a.size()) return;
    else if(a < b) a = b;
}

int main(){
    int N, M; cin >> N >> M;
    vector<int> a(M);
    for(int i=0; i<M; i++) cin >> a[i];
    
    int match[10] = {0,2,5,5,4,5,6,3,7,6};

    string MINF = "-";
    vector<string> dp(N+50, MINF);
    dp[0] = "";

    for(int i=0; i<N; i++){
        if(dp[i] == MINF) continue;
        for(int j=0; j<M; j++){
            chmax(dp[i+match[a[j]]], dp[i]+(char)(a[j]+'0'));
            chmax(dp[i+match[a[j]]], (char)(a[j]+'0')+dp[i]);
        }
    }

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

Measured memory_bytes: 39936
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
#define pb(obj) push_back(obj)
#define REP(i,N) for(ll i=0;i<N;i++)
typedef long long ll;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll box,child;
    cin>>box>>child;
    vector<ll>candy(box);
    ll sum=0;
    ll A;
    for(ll i=0;i<box;i++){
        cin>>A;
        sum+=A;
        sum%=child;
        candy[i]=sum;
    }
    map<ll,ll>m;
    m[0]++;
    for(ll i=0;i<box;i++){
        m[candy[i]]++;
    }
    ll sub=0;
    for(auto& a:m){
        if(a.second>1){
            sub+=a.second*(a.second-1)/2;
        }
    }
    cout<<sub<<endl;
}

Measured memory_bytes: 4992
s=input()

a,b=int(s[0]+s[1]),int(s[2]+s[3])

if b==0:
    if 0<a<13:
        print('MMYY')
    else:
        print('NA')
elif a==0:
    if 0<b<13:
        print('YYMM')
    else:
        print('NA')
elif a>12:
    if b>12:
        print('NA')
    elif 0<b<13:
        print('YYMM')
elif 0<a<13:
    if b>12:
        print('MMYY')
    elif 0<b<13:
        print('AMBIGUOUS')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
using ll = long long;
 
int main() {
    double a,b,h,m;
    cin >> a >> b >> h >> m;
    double long_an = h*30+m*0.5;
    double short_an = m*6;
    double ang = abs(long_an-short_an);
    // if(ang>180)
    //     ang =360-ang;
    ang = ang*M_PI/180;
    // cout << ang << endl;
    // cout << cos(ang) << endl;
    double ans = a*a+b*b-2*a*b*cos(ang);
    ans = sqrt(ans);
    printf("%.14f",ans);
    return 0;
}

Measured memory_bytes: 4224
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>

#include <cstdio>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define swap(a, b, type) { type _tmp = a; a = b; b = _tmp; }
typedef long long ll;
typedef unsigned long long ull;

#define MOD (1000000007)

ll d[101][9];
int line[8];

int main()
{
	int H, W, K;
	ll left, mid, right, tmp;

	cin >> H >> W >> K;

	repc(i, 0, W - 1) {
		if (i == 0) line[i] = 1;
		else if (i == 1) line[i] = 2;
		else {
			line[i] = line[i - 1] + line[i - 2];
		}
	}

	repc(h, 1, H) {
		repc(w, 1, W) {
			if (h == 1) {
				if (w == 1) d[h][w] = line[max(0, W - 2)];
				else if (w == 2) d[h][w] = line[max(0, W - 3)];
				else d[h][w] = 0;
				continue;
			}

			if (w == 1) left = 0;
			else {
				tmp = line[max(0, w - 3)];
				tmp *= line[max(0, W - w - 1)];
				left = (d[h - 1][w - 1] * tmp) % MOD;
			}

			tmp = line[max(0, w - 2)];
			tmp *= line[max(0, W - w - 1)];
			mid = (d[h - 1][w] * tmp) % MOD;

			if (w == W) right = 0;
			else {
				tmp = line[max(0, w - 2)];
				tmp *= line[max(0, W - w - 2)];
				right = (d[h - 1][w + 1] * tmp) % MOD;
			}

			d[h][w] = (left + mid + right) % MOD;
		}
	}

	cout << d[H][K] << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) std::cout<<arg<<"\n"
#define prin2(arg1,arg2) std::cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) std::memset(arg,n,sizeof(arg))
#define mp(a,b) std::make_pair(a,b)
#define pb push_back
using std::cin;
typedef long long ll;
typedef std::pair<int,int> pi;
typedef std::vector<int> vi;
typedef std::set<int> si;
typedef std::string str;
const int INF=1e+9;
const ll INFLL=1e+17;
const ll MOD=1e+9+7;
int N,K;
int A[100010];
int gcd(int a,int b){
  if(b==0) return a;
  else return gcd(b,a%b);
}
int main(){
  cin>>N>>K;
  rep(i,N) cin>>A[i];
  int max=0;
  rep(i,N) max=std::max(max,A[i]);
  if(max<K) prin("IMPOSSIBLE");
  else{
    int g=0;
    rep(i,N){
      g=gcd(A[i],g);
    }
    if(K%g==0) prin("POSSIBLE");
    else prin("IMPOSSIBLE");
  }
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926525
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

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

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  ll n,c;cin>>n>>c;
  vector<ll> x,v,y,w;
  x.push_back(0);
  v.push_back(0);
  // y.push_back(c);
  // w.push_back(0);
  REP(i,n){
    ll xx,vv;cin>>xx>>vv;
    x.push_back(xx);
    v.push_back(vv);
    y.push_back(c-xx);
    w.push_back(vv);
  }
  // x.push_back(c);
  // v.push_back(0);
  y.push_back(0);
  w.push_back(0);
  reverse(y.begin(), y.end());
  reverse(w.begin(), w.end());
  REP(i,n)v[i+1]+=v[i];
  REP(i,n)w[i+1]+=w[i];
  ll maxn=-1;
  // for(int i=0;i<n+1;i++){
  //   for(int j=0;i+j<n+1;j++){
  //     maxn=max(maxn, max(v[i]+w[j]-2*x[i]-y[j], v[i]+w[j]-x[i]-2*y[j]));
  //   }
  // }
  vector<ll> maxns;
  for(int i=0;i<n+1;i++){
    maxns.push_back(v[i]-x[i]);
  }
  for(int i=0;i<n+1;i++){
    if(i+1<n+1 && maxns[i]>maxns[i+1])maxns[i+1]=maxns[i];
  }
  vector<ll> maxns2;
  for(int i=0;i<n+1;i++){
    maxns2.push_back(v[i]-2*x[i]);
  }
  for(int i=0;i<n+1;i++){
    if(i+1<n+1 && maxns2[i]>maxns2[i+1])maxns2[i+1]=maxns2[i];
  }
  for(int i=0;i<n+1;i++){
    maxn=max(maxn, max(maxns[n-i]+w[i]-2*y[i], maxns2[n-i]+w[i]-y[i]));
  }
  P(maxn);
  return 0;
}


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

bool dp[100001];
vector<int> v;

int main() {
	int n, k; cin >> n >> k; v.resize(n);
	for (auto &x : v) { cin >> x; }
	sort(v.begin(), v.end()); fill(dp, dp + 100001, 0);
	for(int i = 1; i <= k; i++)
		for(int j = 0; j < n && v[j] <= i; j++)
			if (!dp[i - v[j]]) { dp[i] = 1; break; }
	cout << (dp[k] ? "First" : "Second") << '\n';
	cin.ignore(2); return 0;
}

Measured memory_bytes: 3700
sx, sy, tx, ty = map(int, input().split())
for i in range(tx - sx):
    print("R", end = "")

for i in range(ty - sy):
    print("U", end = "")

print("R", end = "")

for i in range(ty - sy + 1):
    print("D", end = "")

for i in range(tx - sx + 1):
    print("L", end = "")

print("UU", end = "")

for i in range(tx - sx - 1):
    print("R", end = "")

for i in range(ty - sy - 1):
    print("U", end = "")

print("RU", end = "")

for i in range(tx - sx + 1):
    print("L", end = "")

for i in range(ty - sy + 1):
    print("D", end = "")

print("R", end = "")
print()

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

int main() {
  int A , B , C , D;
  cin >> A >> B >> C >> D;
  if(A + B == C + D) {
    cout << "Balanced" << endl;
  }
  else if(A + B > C + D) {
    cout << "Left" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int N;
    cin >> N;
    for(ll i = 1;i <= N;i++){
        if(((i*(i+1))/2 == N)){
            cout << "Yes" << endl <<  i+1 << endl;
            vector<vector<int>> S(i,vector<int>(i+1,0));
            int cnt = 1;
            for(int j = 0;j < i;j++){
                for(int k = 1+j;k <= i;k++){
                    if(S[j][k] == 0){
                    S[j][k] = cnt;
                    S[k-1][j] = cnt;
                    cnt++;
                    }
                    //cout << S[j][k] << " ";
                }
                //cout << endl;
            }
            for(int k = 0;k <= i;k++){
                cout << i << " ";
                for(int j = 0;j < i;j++){
                    cout << S[j][k] << " ";
                }
                cout << endl;
            }
            cin >> N;
            return 0;
        }
    }
    cout << "No" << endl;
    //cin >> N;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

ll X[4] = {1,0,-1,0};
ll Y[4] = {0,1,0,-1};

ll XX[4] = {1,-1,-1,1};
ll YY[4] = {1,1,-1,-1};
ll XXX[16] = {2,1,0,-1,-2,2,-2,2,-2,2,-2,2,-1,0,1,2};
ll YYY[16] = {2,2,2,2,2,1,1,0,0,-1,-1,-2,-2,-2,-2,-2};
int main(){
    ll H,W,ch,cw,dh,dw;
    cin >> H >> W >> ch >> cw >> dh >> dw;
    ch--;cw--;
    dh--;dw--;
    vector<string> S(H);
    rep(i,H){
        cin >> S[i];
    }
    priority_queue<PlP,vector<PlP>,greater<PlP>> que;
    que.push(PlP(0,Pll(ch,cw)));
    vector<vector<ll>> memo(H,vector<ll>(W,1e18));
    memo[ch][cw] = 0;
    while(!que.empty()){
        ll cost = que.top().fi;
        ll h = que.top().se.fi;
        ll w = que.top().se.se;
        que.pop();
        ll cnt = 0;
        rep(i,4){
            ll hh = h + Y[i];
            ll ww = w + X[i];
            if(!(0<= hh && hh < H)) continue;
            if(!(0<= ww && ww < W)) continue;
            if(memo[hh][ww] <= cost){
                continue;
            }
            if(S[hh][ww] == '#'){
                cnt++;
                continue;
            }
            //cout << hh <<" "<< ww <<endl;
            memo[hh][ww] = cost;
            que.push(PlP(cost,Pll(hh,ww)));
            
        }
        
        if(cnt>0){
            rep(i,4){
                ll hh = h + YY[i];
                ll ww = w + XX[i];
                if(!(0<= hh && hh < H)) continue;
                if(!(0<= ww && ww < W)) continue;
                if(memo[hh][ww] <= cost+1) continue;
                if(S[hh][ww] == '#'){
                    continue;
                }
                memo[hh][ww] = cost+1;
                que.push(PlP(cost+1,Pll(hh,ww)));
            }
            rep(i,16){
                ll hh = h + YYY[i];
                ll ww = w + XXX[i];
                if(!(0<= hh && hh < H)) continue;
                if(!(0<= ww && ww < W)) continue;
                if(memo[hh][ww] <= cost+1) continue;
                if(S[hh][ww] == '#'){
                    continue;
                }
                memo[hh][ww] = cost+1;
                que.push(PlP(cost+1,Pll(hh,ww)));
            }
        }
    }/*
    PR(memo[0],4);
    PR(memo[1],4);
    PR(memo[2],4);
    PR(memo[3],4);*/
    if(memo[dh][dw] == 1e18){
        cout << -1 << endl;
    }else{
        cout << memo[dh][dw] << endl;
    }
    //cout << ans << endl;
}

Measured memory_bytes: 13416
import sys
input = sys.stdin.readline
Q, H, S, D = map(int, input().split())
N = int(input()) * 4
res = 0

res += (N // 8) * min(Q * 8, H * 4, S * 2, D)
N %= 8
res += (N // 4) * min(Q * 4, H * 2, S)
N %= 4
res += (N // 2) * min(Q * 2, H * 1)
N %= 2
res += N * Q
print(res)

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long  A,B,C,K;
	long long  ans=0;
	cin>>A>>B>>C>>K;
	if(A>=K){
		cout<<K;
	}
	else{
	K-=A;
	ans+=A;
	if(K<=B){
		cout<<ans;
	}
	else{
		ans-=(K-B);
		cout<<ans;
	}
	}
}

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

using namespace std;

int main () {
  int NN = 100000;
  vector<int> v;
  v.push_back(1);
  for (int i = 6; i <= NN; i *= 6){
    v.push_back(i);
  }
  for (int i = 9; i <= NN; i *= 9){
    v.push_back(i);
  }
  sort(v.begin(), v.end());

  int N;
  while(cin >> N) {
    int dp[111111] = {};
    for (int i = 0; i <= N; i++) dp[i] = 1 << 25;
    dp[0] = 0;

    for (int i = 0; i <= NN; i++) {
      for (int j = 0; j < v.size(); j++) {
        int n = i + v[j];
        if (n <= NN) {
          dp[n] = min(dp[n], dp[i] + 1);
        }
      }
    }
    cout << dp[N] << endl;
  }
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);


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

  int k;
  cin >> k;
  vector<ll> a;
  for (int i = 1; i <= 9; i++) a.push_back(i);
  while (true) {
    if (k <= a.size()) {
      cout << a[k-1] << endl;
      return 0;
    }
    k -= a.size();
    vector<ll> old;
    swap(old, a);
    for (ll x : old) {
      for (int i = -1; i <= 1; i++) {
        int d = x%10 + i;
        if (d < 0 || d > 9) continue;
        ll nx = x * 10 + d;
        a.push_back(nx);
      }
    }
  }

  return 0;
}


Measured memory_bytes: 1712
N, K = map(int, input().split())
A = [int(n)-1 for n in input().split()]

pos, root, cnt, lst = 0, {}, 0, []
while True:
    if cnt == K:
        ans = pos + 1
        break
    if pos in root:
        ans = lst[root[pos] + (K-root[pos]) % (cnt-root[pos])] + 1
        break
    root[pos] = cnt
    lst.append(pos)
    cnt += 1
    pos = A[pos]

print(ans)


Measured memory_bytes: 32332
N=int(input())
X=list(map(int,input().split()))

X_sort=sorted(X)

if X_sort[N//2-1]==X_sort[N//2]:
    for n in range(N):
        print(X_sort[N//2])
else:
    if X_sort.count(X_sort[N//2-1])==1:
        for n in range(N):
            if X[n]>X_sort[N//2-1]:
                print(X_sort[N//2-1])
            else:
                print(X_sort[N//2])
    else:
        for n in range(N):
            if X[n]>X_sort[N//2-1]:
                print(X_sort[N//2-1])
            else:
                print(X_sort[N//2])


Measured memory_bytes: 26772
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
int n,x,y;
int a[2005];
int dfs(int m,int t,int h,int b,int k){
    if(m==n){
        return max(h-b,b-h);;
    }
    if(k==2){
        return max(a[n-1]-b,b-a[n-1]);
    }
    
    if(t==1){
        int s=0;
        for(int i=m;i<n;i++){
            s=max(s,dfs(i+1,0,a[i],b,k+1));
        }
        return s;
    }else{
        int s=1000000001;
        for(int i=m;i<n;i++){
            s=min(s,dfs(i+1,1,h,a[i],k+1));
        }
        return s;
    }
}
int main(void){
    cin>>n>>x>>y;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    
    cout<<dfs(0,1,x,y,0)<<endl;
}


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

using namespace std;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15);
  }
} initializer;

int main() {
  int a, b;
  cin >> a >> b;
  if (0 < a) {
    cout << "Positive" << endl;
  } else if (b < 0) {
    cout << ((a - b) % 2 ? "Positive" : "Negative") << endl;
  } else {
    cout << "Zero" << endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		int W, H;
		int x, y, r;

		Scanner stdIn = new Scanner(System.in);

		W = stdIn.nextInt();
		H = stdIn.nextInt();
		x = stdIn.nextInt();
		y = stdIn.nextInt();
		r = stdIn.nextInt();

		if (0 > (y - r)) {
			System.out.println("No");
		} else if (H < (y + r)) {
			System.out.println("No");
		} else if (0 > (x - r)) {
			System.out.println("No");
		} else if (W < (x + r)) {
			System.out.println("No");
		} else {
			System.out.println("Yes");
		}

	}
}

Measured memory_bytes: 26328
N = int(input())
T = [list(map(int, input().split())) for _ in range(N)]

x=y=0
flg = False
for t,dx,dy in T:
    if abs(x-dx) + abs(y-dy) <= t and (t-dx-dy)%2==0:
        x,y = dx,dy
    else:
        break
else:
    flg = True

print("NYoe s"[flg::2])


Measured memory_bytes: 27380
#include <stdio.h>

int main() {
char a;
char ch[120];
char c[120];
char b[120];
int i,j,k,l,m,n,o;
m = 0;
n = 0;
i=0;
l=0;

while(1) {
scanf("%c",&a);

if(a == '\n') {
 break;
}

ch[i] = a;
i=i+1;

}

j=0;
while(1) {
scanf("%c",&a);
if(a == '\n') {
break;
}
c[j] = a;
j +=1;
}
/*??????????????§??\??????*/

for(k=0;k<i;k++) {

if(c[0] == ch[k] ) {       /*???????????????????????¨?????????????????? */
 l = k;
n = 0;                         /* ??????????????´???????????????*/
for(m=0;m<i-k;m++) {         /* c[k]????????????????§????????????? */
n = n +1;
l  +=1;
b[m] = ch[l-1];
}
l=0;
for(m=n;m<n+1+k;m++) {
l +=1;
b[m] = ch[l-1];            
}
o=0;
for(n=0;n<j;n++) {
/*printf("b[%d] = %c\n c[%d] = %c\n",n,b[n],n,c[n]); */
if(b[n] == c[n]){
o +=1;
}
}
}

/* printf("i = %d\nj = %d\n",i,j); */


if(o == j) {
printf("Yes\n");
break;
} else if(k==i-1) {
printf("No\n");
}
}
 
return 0;

}


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

using namespace std;

const long long oo=1000000000000000001LL;
void add(long long &a,long long b)
{
	a+=b;
	if(a>=oo)a=oo;
}
long long mult(long long a,long long b)
{
	if(a==0||b==0)return 0;
	if(a<=oo/b)return a*b;
	return oo;
}

int n;
char a[110][220];
int len[110];

long long dp[2010];
long long f[2010];

bool can[110][220];
long long cnt[30];

int main()
{
	int m;
	long long K;
	while(~scanf("%d %d %lld",&n,&m,&K))
	{
		for(int i=1;i<=n;i++)scanf("%s",a[i]+1);
		for(int i=1;i<=n;i++)len[i]=strlen(a[i]+1);
		dp[0]=1;
		for(int i=1;i<=m;i++)
		{
			dp[i]=0;
			for(int j=1;j<=n;j++)
				if(len[j]<=i)
					add(dp[i],dp[i-len[j]]);
		}
		if(K>dp[m])
		{
			puts("-");
			continue;
		}
		memset(can,0,sizeof(can));
		for(int i=1;i<=n;i++)can[i][0]=1;
		memset(f,0,sizeof(f));
		f[0]=1;

		for(int i=1;i<=m;i++)
		{
			memset(cnt,0,sizeof(cnt));
			for(int j=1;j<=n;j++)
				for(int k=0;k<len[j];k++)
					if(can[j][k])
					{
						int ll=m-i-(len[j]-(k+1));
						if(ll<0)continue;
						long long t=mult(f[i-k-1],dp[ll]);
						add(cnt[a[j][k+1]-'a'],t);
					}
			for(int x=0;x<26;x++)
			{
				if(cnt[x]<K)
					K-=cnt[x];
				else
				{
					printf("%c",'a'+x);
					for(int j=1;j<=n;j++)
						if('a'+x==a[j][len[j]]&&can[j][len[j]-1])
							add(f[i],f[i-len[j]]);
					for(int j=1;j<=n;j++)
					{
						for(int k=len[j]-1;k>=1;k--)
							if(can[j][k-1]&&('a'+x)==a[j][k])
								can[j][k]=1;
							else can[j][k]=0;
					}
					break;
				}
			}
		}

		puts("");
	}
}

Measured memory_bytes: 1268
// https://atcoder.jp/contests/abc054/tasks/abc054_c

use itertools::Itertools as _;
use petgraph::graph::UnGraph;
use proconio::input;
use proconio::marker::Usize1;

fn main() {
    input! {
        n: usize,
        abs: [(Usize1, Usize1)],
    }

    let graph = UnGraph::<(), (), usize>::from_edges(abs);
    let ans = graph
        .node_indices()
        .permutations(n)
        .filter(|p| p[0].index() == 0 && p.windows(2).all(|w| graph.contains_edge(w[0], w[1])))
        .count();
    println!("{}", ans);
}


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

int main(){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max({a*c, a*d, b*c, b*d}) << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define MAXN	16
#define MAXM	32768
#define MAXS	14348907
#define INF	1e9
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
int mp[MAXN][MAXN], bit[MAXN];
int ups[MAXM], upt[MAXM];
int sum[MAXN][MAXM], cost[MAXS];
int dp[MAXN][MAXM];
int n, m, goal;
void init() {
	goal = (1 << n) - 1;
	bit[1] = 1;
	for (int i = 2; i <= n; i++)
		bit[i] = bit[i - 1] << 1;
	for (int i = 1; i <= n; i++)
	for (int s = 0; s <= goal; s++) {
		if (s & bit[i]) continue;
		for (int j = 1; j <= n; j++)
			if (s & bit[j]) sum[i][s] += mp[i][j];
	}
	for (int s = 0; s <= goal; s++) {
		int tmp = s, sv = 0, tv = 0, now = 1;
		while (tmp) {
			if (tmp & 1) sv += 2 * now;
			if (tmp & 1) tv += now;
			now *= 3; tmp >>= 1;
		}
		ups[s] = sv; upt[s] = tv;
	}
	for (int s = 0; s <= goal; s++)
	for (int tmp = goal ^ s, t = goal ^ s; t; t = (t - 1) & tmp)
	for (int i = 1; i <= n; i++)
		if (s & bit[i]) cost[ups[s] + upt[t]] += sum[i][t];
}
void update(int &x, int y) {
	x = min(x, y);
}
int main() {
	read(n), read(m);
	for (int i = 1; i <= m; i++) {
		int x, y, z;
		read(x), read(y), read(z);
		mp[x][y] = mp[y][x] = z;
	}
	init();
	for (int i = 1; i <= n; i++)
	for (int j = 0; j <= goal; j++)
		dp[i][j] = INF;
	dp[1][bit[1]] = 0;
	for (int s = 0; s <= goal; s++)
	for (int i = 1; i <= n; i++) {
		if ((bit[i] & s) == 0 || dp[i][s] == INF) continue;
		int ts = s ^ bit[i];
		for (int j = 1; j <= n; j++) {
			if ((bit[j] & s) || mp[i][j] == 0) continue;
			update(dp[j][s ^ bit[j]], dp[i][s] + sum[j][ts]);
		}
		for (int tmp = goal ^ s, t = goal ^ s; t; t = (t - 1) & tmp)
			update(dp[i][s ^ t], dp[i][s] + cost[ups[ts] + upt[t]]);
	}
	cout << dp[n][goal] << endl;
	return 0;
}

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

int n,k,minn=1e5+10;bool tub[10];

void dfs(int ans){
    if(ans>=n){
        minn=min(minn,ans);
        return ;
    }
    for(register int i=0;i<=9;i++){
        if(!ans&&!i) continue;
        if(tub[i]) continue;
        dfs(ans*10+i);
    }
    return ;
}

int main(){
    cin>>n>>k;
    for(register int i=1;i<=k;i++){
        int x;cin>>x;
        tub[x]=true;
    }
    dfs(0);
    printf("%d",minn);
    return 0;
}

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

using namespace std;

long solve(long N) {
  if (N <= 1) {
    return 0;
  }

  long ans = 0;

  long upper = floor(sqrt(N));

  long div = 1;

  while (div <= upper) {
    if (N % div == 0) {
      long t = N / div - 1;
      if (N % t == div && N / t == div) {
        ans += t;
      }
      div = max(N / t, div + 1);
    } else {
      div += 1;
    }
  }

  return ans;
}

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

  long ans = solve(N);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        String po[]=new String[n];
        int a=0,b=0;
        int ab=0;
        int ans=0;
        for(int i=0;i<n;i++){po[i]=sc.next();
        int leng=po[i].length();
        po[i]=po[i].replace("AB","");
        ans+=(leng-po[i].length())/2;
        leng=po[i].length();
        if(leng!=0){
            if(po[i].substring(0,1).equals("B"))b++;
            if(po[i].substring(leng-1,leng).equals("A"))a++;
            if(po[i].substring(0,1).equals("B")&&po[i].substring(leng-1,leng).equals("A"))ab++;
            //System.out.println(a+" "+b+" "+ab);
        }
        }
        //System.out.println(a+" "+b+" "+ab);
        System.out.println((a==b)&&(b==ab)?(a==0)?ans:ans+a-1:ans+Math.min(a,b));
    }
}


Measured memory_bytes: 40452
#include <iostream>
using namespace std;
 
int main(){
  string h;
  int A;

  for(;;){
    int sum = 1,top = 1,dice[4] = {2,3,4,5};
    cin >> A;
    if(A == 0) break;
    for(int i = 0 ; i < A ; i++){
      cin >> h;
      int tmp = top;
      if( i == 0 ) top = 1;
      if(h == "North"){
    top = dice[0];
    dice[0] = 7 - tmp;
    dice[3] = tmp;
      }
      else if(h == "East"){
    top = dice[2];
    dice[2] = 7 - tmp;
    dice[1] = tmp;
      }
      else if(h == "West"){
    top = dice[1];
    dice[1] = 7 - tmp;
    dice[2] = tmp; 
      }
      else if(h == "South"){
    top = dice[3];
    dice[3] = 7 - tmp;
    dice[0] = tmp;
      }
      else if(h == "Right"){
    tmp = dice[3];
    dice[3] = dice[2];
    dice[2] = dice[0];
    dice[0] = dice[1];
    dice[1] = tmp;
      }
      else{
    tmp = dice[3];
    dice[3] = dice[1];
    dice[1] = dice[0];
    dice[0] = dice[2];
    dice[2] = tmp; 
      }
      sum += top;
    }
    cout << sum << endl;
  }
 
  return 0;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
bool mmp(int a,int b)
{
return a>b;
}
int main()
{
   int n,k,ass=0;
   int a[51];
   cin>>n>>k;
   for(int i=1;i<=n;i++)
    {
   	cin>>a[i];
    }
	sort(a+1,a+n+1,mmp);
	for(int i=1;i<=k;i++)	
	{
		ass+=a[i];
	}
	cout<<ass<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int n,count=0;
  scanf("%d",&n);
  char s[n];
  scanf("%s",&s);
  for(int i=0;i<n-2;i++){
    if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C'){
      count++;
    }
  }
  printf("%d",count);
  return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>
using namespace std;
int gcd(int a,int b)
{
    return a==0?b:gcd(b%a,a);
}
int main()
{
    int x;
    scanf("%d",&x);
    printf("%d\n",360/gcd(x,360));
    return 0;
}


Measured memory_bytes: 1712
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int n;
    cin>>n;
    vector<tuple<string,int,int>> p;
    string s;
    int a;
    rep(i,n){
        cin>>s>>a;
        p.emplace_back(s,-a,i+1);
    }
    sort(btoe(p));
    for(auto v: p){
        cout<<get<2>(v)<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

infants = []
for i,a in enumerate(A):
    infants.append((a, i))
infants.sort(reverse=True)
dp = [[0 for _ in range(N+1)] for _ in range(N+1)]

for i in range(N):
    for j in range(i+1):
        dp[j+1][i-j] = max(dp[j+1][i-j], dp[j][i-j] + infants[i][0] * abs(infants[i][1] - j))
        dp[i-j][j+1] = max(dp[i-j][j+1], dp[i-j][j] + infants[i][0] * abs(infants[i][1] - (N-1 - j)))
ans = 0
for i in range(N+1):
    ans = max(ans, dp[i][N-i])
print(ans)


Measured memory_bytes: 107520
import sys
from itertools import product

s = sys.stdin.readline().rstrip()

def main():
    for ops in product('+-', repeat=3):
        res = s[0]
        for i in range(3):
            res += ops[i] + s[i+1]
        if eval(res) == 7:
            print(res + '=7')
            return 

if __name__ ==  '__main__':
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7;

pair<int, int> p[N];
pair<ll, int> pos_pos[N], pos_neg[N], neg_pos[N], neg_neg[N];

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin >> n;
    ll ans = 0;
    for(int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        p[i] = {x, y};
        pos_pos[i] = {x + y, i};
        pos_neg[i] = {x - y, i};
        neg_pos[i] = {-x + y, i};
        neg_neg[i] = {-x -y, i};
    }
    sort(pos_pos, pos_pos + n);
    sort(pos_neg, pos_neg + n);
    sort(neg_pos, neg_pos + n);
    sort(neg_neg, neg_neg + n);
    for(int i = 0; i < n; i++){
        if(neg_neg[n - 1].second == pos_pos[i].second) {
            ans = max(ans, neg_neg[n - 2].first + pos_pos[i].first);
        }
        else ans = max(ans, neg_neg[n - 1].first + pos_pos[i].first);
    }
    for(int i = 0; i < n; i++){
        if(neg_pos[n - 1].second == pos_neg[i].second) {
            ans = max(ans, neg_pos[n - 2].first + pos_neg[i].first);
        }
        else ans = max(ans, neg_pos[n - 1].first + pos_neg[i].first);
    }
    for(int i = 0; i < n; i++) {
        if(pos_pos[n - 1].second == neg_neg[i].first) {
            ans = max(ans, pos_pos[n- 2].first + neg_neg[i].first);
        }
        else ans = max(ans, pos_pos[n - 1].first + neg_neg[i].first);
    }
    for(int i = 0; i < n; i++){
        if(pos_neg[n - 1].second == neg_pos[i].second) {
            ans = max(ans, pos_neg[n - 2].first + neg_pos[i].first);
        }
        else ans = max(ans, pos_neg[n - 1].first + neg_pos[i].first);
    }
    cout << ans;

    return 0;
}


Measured memory_bytes: 17648