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

bool IsTriangle(int a, int b, int c)
{
    if(a+b>c && a+c>b && c+b>a)
        return true;
    
    return false;
}

bool CheckDuplicate(int a, int b, int c){
    if(a == b || a==c || b==c)
        return true;

    return false;
}

int main()
{
    int N=0;
    std::cin >> N;
    std::vector<int> L(N);
    for (int i = 0; i < N; i++) {
        std::cin >> L.at(i);
    }

    int count=0;
    for(int i=0; i<N; i++){
        for(int j=i+1; j<N; j++){
            for (int k=j+1; k<N; k++){
                
                if(!CheckDuplicate(L[i], L[j], L[k])){
                    if(IsTriangle(L[i], L[j], L[k]))
                        count++;
                }


            }
        }
    }
    std::cout << count << std::endl;
    // for (int i = 0; i < N; i++) {
    //     std::cout << L.at(i);
    // }
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
    int N;
    double T,A;
    cin >>N>>T>>A;
    double H[N];
    double ans  = 123456789;
    int ans2 = 0;
    for(int i = 0;i < N;i++) cin >> H[i];
    
    for(int i = 0;i < N;i++){
        if(ans > min(ans,abs(A-(T-0.006*H[i])))){
            ans = min(ans,abs(A-(T-0.006*H[i])));
            ans2 = i + 1;
        } 
    }
    cout << ans2 << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    rep(i, S.length()) {
        if (i % 2 == 0) cout << S[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 592
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<list>
#include<map>
#include<iomanip>
#include<iostream>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
long long ans=0,n,a[100005];
int main(){
	memset(a,0,sizeof(a));
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(a[i]==i)ans++;
	}
	if(ans==0){
		cout<<0<<endl;
		return 0;
	}
	ans=0;
	for(int i=1;i<=n;i++){
		if(a[i]==i){
			ans++;
			swap(a[i],a[i+1]);
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define ss second

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

ll modpow(ll a, ll b){

    ll ans=1;
    while(b){
        if(b&1){
            ans=(ans*a)%mod;
        }
        a=(a*a)%mod;
        b=b/2;
    }
    return ans;
}
map<pair<int,int>,int>  mp;
map<pair<int,int>,int> ::iterator it;
int main(){

    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        if(!mp[mk(min(i,x),max(i,x))])
        mp[mk(min(i,x),max(i,x))]=1;
        else mp[mk(min(i,x),max(i,x))]++;
    }
    int ans = 0;
    for(it=mp.begin();it!=mp.end();it++){
        if((*it).ss==2) ans++;
    }
    cout<<ans<<endl;

}



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

def can_make(t, d):
    if t==0:
        return True
    elif t<0 or t>sum(a[d:]):
        return False
    elif d==n:
        return False
    elif can_make(t-a[d], d+1) or can_make(t, d+1):
        return True
    else:
        return False
        
for i in range(q):
    if can_make(m[i], 0):
        print('yes')
    else:
        print('no')
    


Measured memory_bytes: 5624
import numpy as np

S = list(map(int,input()))
S = np.array(S)
l = len(S)
ptnA = np.tile((1,0), l)
ptnA = ptnA[0:l]
ptnB = np.tile((0,1),l)
ptnB = ptnB[0:l]

xorsumA = sum(np.logical_xor(S, ptnA))
xorsumB = sum(np.logical_xor(S, ptnB))

print(min((xorsumA,xorsumB)))


Measured memory_bytes: 16468
#include <stdio.h>
#include <algorithm>
using namespace std;
using ll = long long;

int main() {
	ll n, p, r = 1;
	scanf("%lld %lld", &n, &p);
	for (ll x = 2; x * x <= p; x++) {
		int count = 0;
		for (; p % x == 0; count++)
			p /= x;
		for (int i = 0; i + n <= count; i += n)
			r *= x;
	}
	if (n == 1)
		r *= p;
	printf("%lld\n", r);
}

Measured memory_bytes: 128
def calc(n)
  e=["0", "1", "2", "3", "5", "7", "8", "9"]
  sprintf("%o",n).split(//).map{|x| e[x.to_i]}.join
end

if true then
  fh=STDIN
else
  fh=open("in0208.txt")
end
n=-999
while fh.gets do
  n=$_.chomp.to_i
  break if n==0
  puts calc(n)
end
abort ("data strange") if n!=0

Measured memory_bytes: 8912
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		int companion = a.length() - b.length();
		int idx = 0;
		if(companion == 0) companion = a.compareTo(b);
		if(companion > 0) System.out.println("GREATER");
		else if(companion < 0) System.out.println("LESS");
		else System.out.println("EQUAL");
	}
}


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

using namespace std;

#define REP(i,m) for(int i=0; i<m; i++)
#define FOR(i,n,m) for(int i=n; i<m; i++)
#define INF 1000000007
#define INFL (1LL << 60)
#define MOD 998244353
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>

int main(){
	int n, a, b;
	cin >> n >> a >> b;
	cout << min(a, b) << " " << max(0, a+b-n) << endl;
} 

Measured memory_bytes: 764
n = int(input())
a = [int(i) for i in input().split()]

a = sorted(a)
r = a[0]
diff = abs(a[-1] - a[0] * 2)
for num in a:
    diff2 = abs(a[-1] - num * 2)
    if diff2 < diff:
        diff = diff2
        r = num

print("{} {}".format(a[-1], r))

Measured memory_bytes: 14052
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
using vs = vector<string>; using tll = tuple<ll, ll, ll>; using vtll = vector<tll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define rep1(n) for(ll i=0;i<n;++i)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop, bitSearch, bitList, nod//
//gcdlcm, isPrime, eratos, primeFactorize, Npow, combination, divisor, modinv,  digitDP//
//dfs, bfs, dijkstra, WarshallFloyd, BellmanFord, UnionFind, Kruskal ,RMQ, LCA//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007; ll INF = 1LL << 60; ll ans = 0; ll z = 0, o = 1;
vl flag; vll path; vl D;
//***********//
int main() {
	cin >> N >> M >> L;
	vector<vll> dp(N+1,vll(401, vl(401, INF)));
	dp[0][0][0] = 0;
	for (k = 0; k < N; k++) {
		ll a, b, c;
		cin >> a >> b >> c;
		for (i = 0; i <= 400; i++) {
			for (j = 0; j <= 400; j++) {
				dp[k + 1][i][j] = min(dp[k + 1][i][j], dp[k][i][j]);
				if (i + a <= 400 && j + b <= 400) {
					dp[k+1][i + a][j + b] = min(dp[k+1][i + a][j + b], dp[k][i][j] + c);
				}
			}
		}
	}
	ans = INF;
	for (i = 1; i <= 400; i++) {
		if (M * i > 400 || L * i > 400) break;
		//debug(M * i, L * i, dp[N][M * i][L * i]);
		ans = min(ans, dp[N][M * i][L * i]);
	}
	if (ans == INF) cout << -1;
	else cout << ans;
}


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


int main(){
    string ymd;
    cin >> ymd;
    string YYYY,MM;
    YYYY=ymd.substr(0,4);
    MM= ymd.substr(5,2);
    if(atoi(YYYY.c_str())>=2019 && atoi(MM.c_str())>=05){
        cout << "TBD" <<endl;
    }else{
        cout << "Heisei" <<endl;
    }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);

#define endl '\n'
#define D(x) cout << #x << " = " << (x) << endl;

const int maxn = 20;
int dp[maxn][2];

int f(string &s, int index, bool equal) {
  int n = s.size();
  if (index == s.size()) return 0;

  if (dp[index][equal] == -1) {
    int mx = 0;
    for (int d = 0; d <= 9; ++d) {
      if (equal and d > (s[index] - '0')) continue;
      int sum = d + f(s, index + 1, equal and d == (s[index] - '0'));
      mx = max(mx, sum);
    }

    dp[index][equal] = mx;
  }

  return dp[index][equal];
}

int main() { IO;
  string s;
  cin >> s;

  memset(dp, -1, sizeof dp);

  int ans = f(s, 0, true);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
from collections import deque
import sys
input = sys.stdin.readline
import bisect as bi
from operator import mul
from functools import reduce
import math

def main():
    n = int(input())
    n += 1 if n > 0 else -1
    
    s = ""
    while abs(n) > 1:
        c = "1" if n % 2 == 0 else "0"
        s = c+s 
        n = n // -2 + (0 if n > 0 else 1)

    print(0 if not s else s)
main()


Measured memory_bytes: 3572
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();		//N
		int m = sc.nextInt();		//M
		long[] x = new long[n];		//値を保管する
		long[] y = new long[m];		//値を保管する
		for(int i=0;i<n;i++) {
			x[i] = sc.nextLong();
		}
		for(int i=0;i<m;i++) {
			y[i] = sc.nextLong();
		}
		long div =1_000_000_007;		//場合の数
		long xsum = 0;	//Xの合計
		for(int i=0;i<n;i++){
			xsum += (2*i-n+1)*x[i];
		}
		xsum %= div;
		long ysum = 0;
		for(int i=0;i<m;i++){
			ysum += (2*i-m+1)*y[i];
		}
		ysum %= div;
		long sum = xsum*ysum;
		System.out.println(sum%div);
	}
}

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

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

int main(){
	int a, b;
	cin>>a>>b;
	if(a - b * 2 <= 0){
		cout<<0<<endl;
	}
	else{
		cout<<a - b * 2<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vi vector<int>
using namespace std;
constexpr int MOD=1e9+7;



int main() {
    int x ;
    cin >> x ;
    int gcd = __gcd(x,360) ; 
    if(360%x==0)
    cout << 360 / x ;
    else
    cout << 360 / gcd ;  


    
    
    
    return 0 ; 
}

Measured memory_bytes: 3620
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int n,k[101],v[101][100];
int a[101][101];
int main(void)
{
	int i,u,j;
	scanf("%d",&n);
	for(i=1;i<=n;i++)	{
		for(j=1;j<=n;j++)	{
			a[i][j]=0;
		}
	}
	for(i=1;i<=n;i++)	{
		scanf("%d %d",&u,&k[i]);
		for(j=0;j<k[i];j++)	{
			scanf("%d",&v[i][j]);
			a[u][v[u][j]]=1;
		}
	}
	for(i=1;i<=n;i++)	{
		printf("%d",a[i][1]);
		for(j=2;j<=n;j++)	{
			printf(" %d",a[i][j]);
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2788
#include <bits/stdc++.h>
#define rep(i,n) for(ll i = 0; i < (ll)(n); ++i)
#define MOD 1000000007

using namespace std;
using ll = long long;

int main() {
	int ans = 0;
	string s;
	cin >> s;
	reverse(s.begin(), s.end());
	vector<int> m(2019);
	int p = 1, n = 0;
	for(char c : s) {
		int x = c - '0';
		x = (x * p) % 2019;
		x = (x + n) % 2019;
		n = x;
		p = (p * 10) % 2019;
		if (x == 0) ans++;
		ans += m[x];
		m[x]++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3756
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
#define sz size()

const double EPS = 1e-10;
const int INF = 100000000;


int main(){
    int n;
    while(cin>>n){
        int c=0;
        bool now=false;
        bool l=false;
        bool r=false;
        if(n==0)break;
        
        rep(i,n){
            string tm;
            cin>>tm;
            if(tm=="lu")l=true;
            if(tm=="ru")r=true;
            if(tm=="ld")l=false;
            if(tm=="rd")r=false;
            if(l!=now && r!=now){
                c++;
                now=!now;
            }
        }
        cout<<c<<endl;
    }
    return 0;
}

Measured memory_bytes: 1208
n = gets.to_i
s = gets.chomp

result = s.count("R") * s.count("G") * s.count("B")

n.times do |i|
  j = i + 1
  while j < n
    k = 2 * j - i
    if j < k && k < n && s[i] != s[j] && s[j] != s[k] && s[k] != s[i]
      result -= 1
    end
    j += 1
  end
  i += 1
end

puts result

Measured memory_bytes: 14380
import math

def is_prime(n):
    for i in range(2, int(math.sqrt(n)) + 1):
        if n % i == 0:
            return False
    return True

primes = [i for i in range(2, 10**3 + 1) if is_prime(i)]
end = len(primes)
def pfac(n):
    i = 0
    pfacts = []
    while i < end:
        if n % primes[i] == 0:
            n //= primes[i]
            pfacts.append(primes[i])
        else:
            i += 1
    return pfacts

n = int(input())
counts = {}
for i in range(2, n + 1):
    for p in pfac(i):
        counts[p] = counts.get(p, 0) + 1

result = 1
for v in counts.values():
    result *= v + 1
print(result % (10**9 + 7))


Measured memory_bytes: 3064
// AtCoder Grand Contest 016
// B - Colorful Hats

#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;

const int MAX_N = 100000;

int N;
int a[MAX_N];


bool can(int min_a, int max_a, int k) {
    if (max_a - min_a > 1) {
        return false;
    }

    bool res = (max_a > k) && ((max_a - k) * 2 <= N - k);
    res = res || (min_a == max_a && k == 0 && (min_a + 1) == N);
    return res;
}

int main() {

    int min_a, max_a;
    int cnt;

    cin >> N;
    min_a = N;
    max_a = 0;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        if (a[i] > max_a) {
            cnt = 1;
            max_a = a[i];
        } else if (a[i] == max_a) {
            cnt++;
        }
        min_a = min(min_a, a[i]);
    }

    cout << (can(min_a, max_a, N - cnt) ? "Yes" : "No") << endl;

    return 0;

}





Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<n; i++)
#define REP(i,x,n) for (int i=x; i<n; i++)
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;

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

  vi x(n), y(n);
  rep(i,n) cin >> x.at(i) >> y.at(i);
  auto dist = [&](int a, int b){
    int dx = x.at(b) - x.at(a);
    int dy = y.at(b) - y.at(a);
    return sqrt(dx*dx+dy*dy);
  };

  vi p(n);
  rep(i,n) p.at(i) = i;
  double len = 0;
  int cnt = 0;
  do {
    rep(i,n-1){
      len += dist(p.at(i), p.at(i+1));
    }
    cnt++;
  } while(next_permutation(p.begin(), p.end()));

  double ans = len / cnt;
  printf("%.10f\n", ans);
  return 0;
}


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

int main()
{
  string str;
  int ct = 0;

  while (cin >> str){
    string tmp = str;
    reverse(tmp.begin(), tmp.end());
    if (str == tmp) ct++;
  }
  cout << ct << endl;
  return (0);
}

Measured memory_bytes: 1192
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(all(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define PII         pair<int, int>
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int h, w;
    cin >> h >> w;
    char g[h + 1][w + 1];
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            cin >> g[i][j];
        }
    }
    for(int i = 1; i <= 2 * h; i++){
        for(int j = 1; j <= w; j++){
            cout << g[(i + 1) / 2][j];
        }
        cout << nl;
    }
    return 0;
}


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

#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;

const int N = (int) 1e6 + 10;

int a[N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  for (int i = 1; i < N; i++) {
    for (int j = i; j < N; j += i) {
      ++a[j];
    }
  }
  int n;
  cin >> n;
  ll ans = 0;
  for (int i = 1; i < n; i++) {
    ans += a[i];
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 7556
# AtCoder
N, K = map(int, input().split())
p = list(map(int, input().split()))

S = [0]*(N+1)
for i in range(N):
    S[i+1] = S[i] + (p[i] + 1)/2

ans = 0
for i in range(N-K+1):
    rng = S[i+K]-S[i]
    ans = max(ans, rng)
print(ans)


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

AB.sort()

money = 0

m = 0
for ab in AB:
    a = ab[0]
    b = ab[1]

    if m + b <= M:
        money += a * b
        m += b
    
    else:
        money += min(b, (M - m)) * a
        m += min(b, (M - m))

    if m == M:
        break

print(money)

Measured memory_bytes: 27352
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

S = input()

a = 0  # 先頭 MM
b = 0  # うしろ MM
c = 0  # 先頭 YY
d = 0  # うしろ YY

if 1 <= int(S[0:2]) <= 12:
	a = 1
if 1 <= int(S[2:4]) <= 12:
	b = 1
if a and b:
	print("AMBIGUOUS")
elif a == 1 and b == 0:
	print("MMYY")
elif a == 0 and b == 1:
	print("YYMM")
else:
	print("NA")

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

typedef long long ll;

#define REP(i, N) for (int i = 0; i < (int)(N); i++)

// chmax, chmin
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; }

const int MAX_N = 1e+5 + 10;

int par[MAX_N]; // 親
int Rank[MAX_N]; // 木の深さ

// n要素で初期化
void init(int n) {
    for (int i = 0; i < n; i++) {
        par[i] = i;
        Rank[i] = 0;
    }
}
// 木の根を求める
int find(int x) {
    if (par[x] == x) {
    return x;
    } else {
    return par[x] = find(par[x]);
    }
}
// xとyの属する集合を併合
void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (Rank[x] < Rank[y]) {
        par[x] = y;
    } else {
        par[y] = x;
    if (Rank[x] == Rank[y]) Rank[x]++;
    }
}
// xとyが同じ集合に属するか否か
bool same(int x, int y) {
    return find(x) == find(y);
}

int main() {
    int N,M;
    cin >> N >> M;
    vector<int> p(N),x(M),y(M);
    REP(i,N) {
        int c;
        cin >> c;
        --c;
        p[i] = c;
    }
    REP(i,M) {
        int a,b;
        cin >> a >> b;
        --a; --b;
        x[i] = a;
        y[i] = b;
    }
    
    init(N);
    REP(i,M){
        unite(p[x[i]],p[y[i]]);
    }
    
    int ans = 0;
    REP(i,N){
        if ( same(i,p[i]) ) ++ans;
    }
    
    cout << ans << endl;
    
    
    return 0;
}

Measured memory_bytes: 5040
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    while (true) {
        int N, M;
        scan(N, M);

        if (N == 0 && M == 0) return;

        auto c = iota(M).map!(i => readln.chomp.to!int).array;
        auto x = iota(N).map!(i => readln.chomp.to!int).array;

        auto ans = solve(N, M, c, x);
        writeln(ans);
    }

}


int solve(int N, int M, int[] c, int[] x) {
    auto dp = new int[][](N + 1, 256);
    fillAll(dp, inf);
    dp[0][128] = 0;

    foreach (i ; 0 .. N) {
        foreach (j ; 0 .. 256) {
            foreach (k ; 0 .. M) {
                int y = clamp(j + c[k], 0, 255);
                chmin(dp[i + 1][y], dp[i][j] + (y - x[i])^^2);
            }
        }
    }

    debug {
        //writefln("%(%s\n%)", dp);
    }

    int ans = int.max;
    foreach (j ; 0 .. 256) {
        chmin(ans, dp[N][j]);
    }
    return ans;
}













void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}



Measured memory_bytes: 72884
import java.util.*;
import java.math.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    String s = sc.next();
    int[] data = new int[4];

    for (int i = 0; i < data.length; i++) {
      data[i] = Integer.valueOf(s.substring(i,i+1));
    }

    String[] op = new String[3];

    int ans = 0;

    for (int i = 0; i < Math.pow(2,data.length-1); i++) {
      ans = data[0];
      for (int j = 0; j < op.length; j++) {
        if ((1&i >> j) == 1) {
          ans += data[j+1];
          op[j] = "+";
        } else {
          ans -= data[j+1];
          op[j] = "-";
        }
      }
      if (ans == 7) break;
    }

    System.out.println(data[0]+op[0]+data[1]+op[1]+data[2]+op[2]+data[3]+"="+ans);

  }

}


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

vector<int> adj[200005];
int mark[200005], cnt[200005];

void solve(int u, int p, int delta){
    delta += mark[u];
    cnt[u] = delta;
    for(int v : adj[u])
        if(v != p)
            solve(v, u, delta);
}


int main(){
	int n, q; cin >> n >> q;
    for(int i = 0; i < n-1; i++){
        int u, v; cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for(int i = 0; i < q; i++){
        int u, x; cin >> u >> x;
        mark[u] += x;
    }
    solve(1, -1, 0);
    for(int i = 1; i <= n; i++)
        cout << cnt[i] << " ";
    cout << endl;
	return 0;
}


Measured memory_bytes: 24064
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(1000000)

def get_root(start, parents):
    if parents[start] == -1:
        return start
    else:
        return get_root(parents[start], parents)

def main():
    n, m = list(map(int, input().split()))
    parents = [-1] * (n + 1)
    for _ in range(m):
        x, y, z = list(map(int, input().split()))
        if parents[x] == -1 and parents[y] == -1:
            parents[y] = x
        elif parents[x] == -1:
            root_y = get_root(y, parents)
            if root_y != x:
                parents[x] = y
        elif parents[y] == -1:
            root_x = get_root(x, parents)
            if root_x != y:
                parents[y] = x
        else:
            root_x = get_root(x, parents)
            root_y = get_root(y, parents)
            if root_x != root_y:
                parents[root_y] = root_x
    print(len([0 for p in parents[1:] if p == -1]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 7756
#include <bits/stdc++.h>
#define FOR(I,X,Y) for(int I=X;I<Y;I++)
#define REP(I,X,Y) for(int I=Y-1;I>=X;I--)
#define INF 1000000007
using namespace std;

int main(){
  int a,b,c;
  int ans1=0,ans2=0,ans3=0,ans4=0;
  while(1){
    cin >> a >> b >> c;
    if(b < a)swap(a,b);
    if(c < b)swap(b,c);
    if(c >= a+b)break;
    ans1++;
    if(a*a+b*b==c*c)ans2++;
    if(a*a+b*b>c*c)ans3++;
    if(a*a+b*b<c*c)ans4++;
  }
  cout << ans1 << " " << ans2 << " " << ans3 << " " << ans4 << endl;
}



Measured memory_bytes: 3100
n = int(input())
print(0)
left = input()[0]
if left == 'V':exit()
print(n-1)
right = input()[0]
if right == 'V':exit()

ok = 0
ng = n-1
while ng-ok > 1:
    mid = (ng+ok)//2
    print(mid)
    s = input()[0]
    if s == 'V':exit()
    if mid%2 == 0:
        if s == left:
            ok = mid
        else:
            ng = mid
    else:
        if s != left:
            ok = mid
        else:
            ng = mid

Measured memory_bytes: 38852
h=int(input())

def bupdp(l,h):
    dp=[0]*(h+1)
    dp[0] = 0
    for i in range(0,h):
        if i>1:
            dp[i] = min(dp[i-1]+abs(l[i]-l[i-1]),dp[i-2]+abs(l[i]-l[i-2]))
        if i==1:
            dp[i] = abs(l[i]-l[i-1])
        if i<1:
            dp[i] = 0   
    # print(dp)
    return dp[-2]

l = list(map(int,input().split()))
print(bupdp(l,h))


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

void solve(long long N, long long A, std::vector<long long> x){
    ll s_max = A * N;
    vector<vector<vector<ll>>> dp(N,vector<vector<ll>>(N+1,vector<ll>(s_max+1,0)));
    dp[0][0][0] = 1;
    dp[0][1][x[0]] = 1;
    for (int j=0;j<x.size();j++){
        dp[j][0][0] = 1;
    }
    for (int j=1;j<x.size();j++){
        for(int k=1;k<=x.size();k++){
            for (int s=0;s<=s_max;s++){
                if (s<x[j]){
                    dp[j][k][s] = dp[j-1][k][s];
                }else{
                    dp[j][k][s] = dp[j-1][k-1][s-x[j]] + dp[j-1][k][s];
                }
            }
        }
    }
    ll count = 0;
    for (int i=1;i<=N;i++){
        count+=dp[N-1][i][A*i];
    }
    printf("%lld\n",count);

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long A;
    scanf("%lld",&A);
    std::vector<long long> x(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&x[i]);
    }
    solve(N, A, std::move(x));
    return 0;
}


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

using namespace std;

#define INF 1e9
#define MAXN 100005
#define MAXM 100005
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

int N;
string S, T, ans = "";

void solve(){
    
    rep(i, N){
        ans += S[i];
        ans += T[i];
    }

    cout << ans << endl;
}

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

    solve();
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		solver();
	}

	public static void solver() {
		FS r = new FS();
		String s = r.next();
		int state = 0;
		for(int i=0; i<s.length(); i++) {
			if(s.charAt(i)=='C'&&state==0 || s.charAt(i)=='F'&&state==1) state++;
		}
		if(state==2) System.out.println("Yes");
		else System.out.println("No");
	}

	// Read Class
	static class FS {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;
		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}

		private int readByte() { return hasNextByte() ? buffer[ptr++] : -1;}
		private boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}
		private void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}

		public boolean hasNext() { skipUnprintable(); return hasNextByte();}
		public String next() {
			if (!hasNext()) throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while(isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}
		public int nextInt() {
			return (int)nextLong();
		}
		public long nextLong() {
			if (!hasNext()) throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while(true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if(b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}
	}
}

Measured memory_bytes: 7892
s = list(map(str, input()))
n = len(s)
res = True
for i in range(n//2):
    if (s[i] != s[n-1-i]):
        res = False
        break
i = 0
while res and i < n//4:
    if (s[i] != s[(n-1)//2-1-i]):
        res = False
        break
    i += 1
print("Yes" if res else "No")

Measured memory_bytes: 3064
#include <stdio.h>

int main(void)
{
    int a[101]={0}, d[101]={0}, N, i, num=0;

    scanf("%d" ,&N);

    for(i=1; i<=N; i++)
        scanf("%d" ,&d[i]);

    for(i=1; i<=N; i++)
        if(a[d[i]]==0)
        {
            num++;
            a[d[i]]=1;
        }

    printf("%d" ,num);
    return 0;
}

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

typedef int_fast32_t int32;
typedef int_fast64_t int64;

const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;

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;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 n;
  cin >> n;
  int64 ans = 0;
  FOR(i,1,n+1){
    auto sum = [](int64 a, int64 d, int64 m){
      int64 res = (2 * a + d * (m-1)) * m / 2;
      return res;
    };
    ans += sum(i,i,n/i);
  }
  ANS(ans);
  return 0;
}

Measured memory_bytes: 3648
N,K= gets.split.map(&:to_i)
A = gets.split.map(&:to_i).sort
F = gets.split.map(&:to_i).sort.reverse
max_time = A.map.with_index{|a,i| a * F[i]}.max

puts (0...(max_time+1)).bsearch{|x|
  k = K
  N.times do |i|
    next if A[i] * F[i] <= x
    k -= A[i] - (x / F[i])
    break if k < 0
  end
  k >= 0
}

Measured memory_bytes: 35804
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
 
#define rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int N, C; std::cin >> N >> C;
  std::vector<std::vector<int>> D(C,std::vector<int>(C));
  rep(i,C) rep(j,C) std::cin >> D[i][j];

  std::vector<std::vector<int>> c(3, std::vector<int>(C));
  rep(i,N) rep(j,N) {
    int color; std::cin >> color; color--;
    int mod = (i+j+2)%3;
    c[mod][color]++;
  }

  // for each mod group ; color should be same
  auto f = [&](int mod, int color) -> ll {
    ll Dsum = 0;
    rep(k,C) Dsum += (D[k][color]*c[mod][k]);
    return Dsum;
  };

  ll ans = 1e9;
  rep(i, C) {
    ll D0 = f(0,i);
    rep(j,C) {
      if ( i == j ) continue;
      ll D1 = f(1,j);
      rep(k,C) {
        if ( i == j || j == k || k == i ) continue;
        ll D2 = f(2,k);
        ans = std::min(ans, D0+D1+D2);
      }
    }
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 256
/*
    This is the solution from syr.
    OJ:Atcoder
    ProblemID:AGC021A
    Date:2018/2/24
    Status:Unknown
*/
#include<algorithm>
#include<bitset>
#include<cctype>
#include<cstring>
#include<cstdlib>
#include<deque>
#include<fstream>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<sstream>
#include<string>
#include<time.h>
#include<utility>
#include<vector>

using namespace std;

const int debug=0;
const int INF=1e9+7;

int ans=0;
string s;

int FindSum(string str){
	int ret=0;
	for(int i=0;i<str.size();i++) ret+=str[i]-'0';
	return ret;
}

int main(){
	cin>>s;
	ans=FindSum(s);
	for(int i=0;i<s.size();i++){
		string str=s;
		str[i]=s[i]-1;
		for(int j=i+1;j<str.size();j++) str[j]='9';
		ans=max(ans,FindSum(str));
	}
	ans=max(ans,9*(int)(s.size()-1));
	cout<<ans<<endl;
	return 0;
}
/*
Sample Input
*/


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n;
	ll d, a; cin >> n >> d >> a;
	d *= 2;
	vector<ll> ps;
	vector<pair<ll, ll>> in;
	rep(i, n){
		ll x, h; cin >> x >> h; x *= 2;
		in.emplace_back(x, h);
		ps.pb(x - d); ps.pb(x); ps.pb(x + d + 1);
	}
	sort(all(ps));
	ps.erase(unique(all(ps)), ps.end());
	
	vector<vector<ll>> ev(ps.size());
	rep(i, n){
		ll x = in[i].first;
		x = lower_bound(all(ps), x - d) - ps.begin();
		ev[x].pb(i);
	}
	
	ll bomb = 0, ans = 0;
	rep(i, ev.size()) for(ll j : ev[i]){
		if(j < 0) bomb += j;
		else{
			ll x = in[j].first, h = in[j].second;
			x = lower_bound(all(ps), x + d + 1) - ps.begin();
			if(h > bomb * a){
				ll k = (h - bomb * a + a - 1) / a;
				ans += k;
				bomb += k;
				ev[x].pb(-k);
			}
		}
	}
	cout << ans << endl;
	
	return 0;
}

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

int main(){
  int n;
  vector<int> p;
  bool pt[300001];
  pt[0] = pt[1] = false;
  for(int i=2;i<=300000;i++)pt[i] = true;

  for(int i=2;i<=300000;i++){
    if(!pt[i])continue;
    if(i%7 == 1 || i%7 == 6){
      p.push_back(i);
      for(int j=2*i;j<=300000;j+=i)pt[j] = false;
    }
  }
  
  while(cin >> n,n!=1){
    cout << n << ":";
    for(int i=0;i<p.size();i++){
      if(n%p[i] == 0)cout << " " << p[i];
    }
    cout << endl;
  }
}

Measured memory_bytes: 1640
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
#include <map>
#include <queue>
#include <list>
#include <set>
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
using namespace std;
using ll = long long;
const int INF = 1e9 + 1;
ll MOD = 1e9+7;
ll dx[9] = {-1, -1, -1, 0, 0, 0, 1, 1, 1};
ll dy[9] = {-1,  0,  1,-1, 0, 1,-1, 0, 1};

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

    int N;
    cin >> N;
    vector<ll> A(N), left(N+1,0), right(N+1,0);
    REP(i, N){
        cin >> A[i];
    }
    REP(i, N){
        left[i+1] = __gcd(left[i], A[i]);
    }
    RREP(i, N){
        right[i] = __gcd(right[i+1], A[i]);
    }
    ll ans = 0;
    REP(i, N){
        ans = max(ans, __gcd(left[i], right[i+1]));
    }
    cout << ans << endl;
}


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

int main(){
	int N, K, M, i, j;
	scanf("%d%d", &N, &K);
	if(K > ((N - 1) * (N - 2)) / 2){
		printf("-1\n");
		return 0;
	}
	K = ((N - 1) * (N - 2)) / 2 - K;
	printf("%d\n", N - 1 + K);
	for(i = 1; i < N; i++){
		printf("%d %d\n", 0 + 1, i + 1);
	}
	for(i = 1; i < N && K > 0; i++){
		for(j = i + 1; j < N && K > 0; j++){
			printf("%d %d\n", i + 1, j + 1);
			K--;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <cmath>
#include <cstring>
#include <assert.h>
#include <utility>
#include <tuple>
#include <array>
#include <bitset>
#include <cstdlib>

using int64 = long long;

using namespace std;

constexpr int MAX_N = 3000,
              MAX_S = 3000;
int64 dp[MAX_N + 1][MAX_S + 1];

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

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

    memset(dp, 0, sizeof(dp));
    for (int i = 0; i <= N; i++) {
        dp[i][0] = 1;
    }

    constexpr int64 MOD = 998244353;

    int64 ans = 0;
    for (int i = 1; i <= N; i++) {
        for (int j = 0; j <= S; j++) {
            if (j != S) {
                (dp[i][j] += dp[i - 1][j]) %= MOD;
            }
            if (j - A[i - 1] >= 0) {
                (dp[i][j] += dp[i - 1][j - A[i - 1]]) %= MOD;
            }
            if (j == S) {
                (ans += dp[i][j] * (N + 1 - i)) %= MOD;
            }
        }
    }

    /*
    for (int j = S; j >= 0; j--) {
        for (int i = 0; i <= N; i++) {
            cerr << dp[i][j] << " ";
        }
        cerr << endl;
    }
    */

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 70656
//#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>

using namespace std;

typedef pair<long long, long long> pl;

long long N, M, K,a,b,c,d,e,H,W;
long long A[2000] = {};
//long long t[200001] = {};
bool f[1000][1000] = {};
bool ff;
string S,SS;
set <long long>sll;
pl buf;
vector <pl>vpl;


int main() {
	cin >> S;

	ff = false;

	if (S[0] != 'A') {
		ff = true;
	}
	a = 0;
	for (int i = 2; i < S.size() - 1; i++) {
		if (S[i] == 'C') {
			a++;
		}

		

	}

	if (a != 1) {
		ff = true;
	}

	a = 0;
	SS = 'A';
	for (int i = 1; i < S.size(); i++) {

		if (S[i] == 'C') {
			a++;
		}

		if (S[i] != 'C' && S[i] - S[0]<=25 && S[i] - S[0]>=0) {
			ff = true;
		}

	}

	if (a >=2) {
		ff = true;
	}



	if (ff) {
		cout << "WA" << endl;
	}
	else {
		cout << "AC" << endl;
	}

	return 0;
}

Measured memory_bytes: 888
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int N, K; std::cin >> N >> K;
  std::vector<int> p(N);
  for(auto& pi: p) std::cin >> pi;
  std::sort(p.begin(), p.end());
  int ans = 0;
  for(int i = 0; i < K; ++i) ans += p[i];
  fin(ans);
  return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
int main(){
    int r;
    cin>>r;
    cout<<r*r<<endl;
}

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

int main(){
  P player[24];
  P race[3][8];
  map<int,int> used;
  for(int i=0;i<3;i++){
    for(int j=0;j<8;j++){
      cin >> player[i*8+j].second >> player[i*8+j].first;
      race[i][j] = player[i*8+j];
    }
  }
  for(int i=0;i<3;i++){
    sort(race[i],race[i]+8);
    for(int j=0;j<2;j++){
      cout << race[i][j].second << " " << race[i][j].first << endl;;
      used[race[i][j].second] = 1;
    }
  }
  sort(player,player+24);
  int cnt=0,idx=0;
  while(cnt != 2){
    if(used[player[idx].second] == 0){
      cout << player[idx].second << " " <<  player[idx].first << endl;
      cnt++;
    }
    idx++;
  }
}

Measured memory_bytes: 1300
mod = 1e9+7
def add(a, b):
    c = a + b
    if c >= mod:
        c -= mod
    return c

def main():
    N, R = [int(x) for x in raw_input().split()]
    
    if N >= 10:
      print(R)
    else:
      print(R + ((10 - N) * 100))
    
    

main()

Measured memory_bytes: 85040
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define N ((1<<17)+1)
int a[9][N];
int b[8] = {0, 1, 3, 2, 2, 3, 1, 0};
int c[4] = {2, 0, 1, 3};
int d[N] = {};

int x[N];
int y[20];

int main(){
	a[0][0]=0;
	a[0][1]=1;
	FOR(i, 1, 9){
		int n = 1<<(i*2+1);
		REP(j, n){
			a[i][j]=a[i-1][j/4]*4;
			if(j < n-4){
				a[i][j] += b[j%8];
			}else{
				a[i][j] += c[j%4];
			}
		}
	}
	REP(i, 17){
		int k = 1<<i;
		REP(j, N) {
			int t = (j>>i)&3;
			if(t==1 || t==2){
				d[j]|=k;
			}
		}
	}

	int n, p, q; scanf("%d%d%d", &n, &p, &q);
	q^=p;
	int s=0, t=n;
	REP(i, n){
		if(q&(1<<i)){
			y[s++]=i;
		} else {
			y[--t]=i;
		}
	}
	t = n-s;
	if(s%2==0){
		printf("NO\n");
		return 0;
	}
	int m = (1<<t)-1;
	REP(i, 1<<n){
		x[i] = a[s/2][i>>t];
		int j = i&m;
		if((i>>t)&1){
			j = m^j;
		}
		x[i]|= (d[j]&m)<<s;
	}
	printf("YES\n");
	REP(i, 1<<n){
		int ans = 0;
		REP(j, n){
			if(x[i]&(1<<j)){
				ans |= 1<<y[j];
			}
		}
		ans ^= p;
		printf("%d ", ans);
	}
	printf("\n");
}






Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
#define Mod(n) n % 1000000007
const int dx[8] = {1, 0, -1, 0, -1, 1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};

int main()
{
    int N;
    cin >> N;
    long long sum = 1;
    for(int i = 1;i <= N;i++)
    {
        sum = Mod(sum * i);
    }
    cout << sum << '\n';
}


Measured memory_bytes: 256
N, K = map(int, input().split())
D = [int(i) for i in input().split()]

dec = []
for i in range(10) :
    if not i in D :
        dec.append(str(i))

i = N
while True :
    for j in str(i) :
        if not j in dec :
            break
    else :
        print(i)
        break
        
    i += 1

Measured memory_bytes: 40540
N = int(input())
s=1
while pow(26,s)<N:
    N-=pow(26,s)
    s+=1


N-=1
ans=["a"]*s
for i in range(s):
    r = N%26
    ans[i] = chr(ord(ans[i])+r)
    N//=26

#if ans[0]=="a":
#    ans[0]="z"
#else:
#    ans[0] = chr(ord(ans[0])+1)
print("".join(reversed(ans)))


Measured memory_bytes: 61812
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

int main()
{
    string a;
    int num[30] = {0};
    cin >> a;
    for(int i = 0; i < a.size(); ++i)
    {
        ++num[a[i] - 'a'];
    }
    bool flag = 1;
    for(int i = 0; i < 26; ++i)
    {
        if(num[i] > 1)
        {
            flag = 0;
            break;
        }
    }
    if(flag)
        cout << "yes" << endl;
    else cout << "no" << endl;
    return 0;
}


Measured memory_bytes: 256