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

int main(){
  string s;
  string t="ATGC";
  int nm=0,ki=0;
  cin>>s;
  for(int i=0;i<s.size();i++){
    bool at=false;
    for(int j=0;j<t.size();j++){
      if(s[i]==t[j]){
        at=true;
      }
    }
    if(!at){
      ki=0;
    }
    else {
      ki++;
      nm=max(nm,ki);
    }
  }
  cout<<nm<<endl;
  
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    vector<char> s(4);
    scanf("%s", s.begin());
    sort(s.begin(), s.end());
    printf("%s\n", s.at(0) == s.at(1) && s.at(1) != s.at(2) && s.at(2) == s.at(3) ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main() {
	int n;
	string s;
	cin >> n >> s;
	int ans = 0;
	for (int i = 1; i < n; ++i) {
		string s1 = s.substr(0, i), s2 = s.substr(i, n - i);
		int cnt = 0;
		for (int j = 0; j < 26; ++j) {
			int flag = 0;
			for (int k = 0; k < s1.size(); ++k)
				if (s1[k] == 'a' + j) flag = 1;
			for (int k = 0; k < s2.size(); ++k)
				if (s2[k] == 'a' + j && flag) flag = 2;
			if (flag == 2) cnt++;
		}
		ans = max(ans, cnt);
	}
	cout << ans << endl;

	return 0;
}

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

al = [a[i]-1 for i in range(n-1) if (a[i+1] - a[i]) == 1]
cl = [c[i] for i in al]


print(sum(b) + sum(cl))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
typedef long long int64;

int N;
int node[1000], option[1000];
vector< int > graph[1000];
int dp[1000];

int rec(int idx)
{
  if(~dp[idx]) return(dp[idx]);
  int64 ret;
  if(node[idx] == 0) {
    ret = 1;
    for(int i = 0; i < graph[idx].size(); i++) {
      (ret *= rec(graph[idx][i])) %= MOD;
    }
    (ret += option[idx]) %= MOD;
  } else if(node[idx] == 1) {
    ret = option[idx];
    for(int i = 0; i < graph[idx].size(); i++) {
      (ret += rec(graph[idx][i])) %= MOD;
    }
  } else {
    ret = 1;
    for(int i = 0; i < graph[idx].size(); i++) {
      (ret *= rec(graph[idx][i]) + 1) %= MOD;
    }
    if(!option[idx]) --ret;
  }
  return(dp[idx] = ret);
}

int main()
{
  cin >> N;
  for(int i = 0; i < N; i++) {
    string s;
    cin >> s;
    if(s[0] == 'E')      node[i] = 0;
    else if(s[0] == 'A') node[i] = 1;
    else                 node[i] = 2;
    option[i] = s.size() == 2;
  }
  for(int i = 0; i < N - 1; i++) {
    int s, t;
    cin >> s >> t;
    graph[--s].push_back(--t);
  }
  memset(dp, -1, sizeof(dp));
  cout << rec(0) << endl;
}

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

int main()
{
  int N, C, K; 
  cin >> N >> C >> K;
  int T[N]; rep(i,N) cin >> T[i];
  
  sort(T, T+N);

  int bus = 1;
  int person = 0;
  int time = 0;
  
  for(int i = 1; i < N; i++)
  {
    if(i >= person + C || T[i] > time + K)
    {
      bus++;
      time = T[i];
      person = i;
    }
  }
  cout << bus << endl;
}

Measured memory_bytes: 640
def main():
    n=int(input())
    a=[int(input()) for _ in [0]*n]
    ans=a[n-1]
    if ans>n-1:
        print(-1)
        return 0
    for i in range(n-2,-1,-1):
        if a[i]>i:
            print(-1)
            return 0
        elif a[i]+1==a[i+1]:
            continue
        elif a[i]+1<a[i+1]:
            print(-1)
            return 0
        else:
            ans+=a[i]
    print(ans)
main()

Measured memory_bytes: 12588
#include<bits/stdc++.h>
namespace my_std{
	using namespace std;
	#define reg register
	#define Rint register int
	#define FOR(i,a,b) for(register int i=(a),ed_##i=(b);i<=ed_##i;++i)
	#define ROF(i,a,b) for(register int i=(a),ed_##i=(b);i>=ed_##i;--i)
	#define FORit(templ,arr,i,a,b) for(register templ *i=(arr)+(a),*ed_##i=(arr)+(b)+1;i!=ed_##i;++i)
	#define ROFit(templ,arr,i,a,b) for(register templ *i=(arr)+(a),*ed_##i=(arr)+(b)-1;i!=ed_##i;--i)
	#define GO(x,p,e,i,v) for(register int i=p[x].head,v;i;i=e[i].link)
	#define MEM(x,v) memset(x,v,sizeof(x))
	#define fir first
	#define sec second
	#define pq priority_queue
	#define MP make_pair
	typedef long long LL;
	typedef double DB;
	typedef pair<int,int> PII;
	#define Templ(T) template<typename T>
	inline int read(){
		reg int ans=0,f=1; reg char c=getchar();
		while(!isdigit(c)) f^=(c=='-'), c=getchar();
		for(;isdigit(c);c=getchar()) ans=(ans<<1)+(ans<<3)+(c^48);
		return f?ans:-ans;
	}
	Templ(_Tp) inline int chkmin(_Tp &x,_Tp y){ return x>y?x=y,1:0; }
	Templ(_Tp) inline int chkmax(_Tp &x,_Tp y){ return x<y?x=y,1:0; }
	#define using_mod
	const int mod = 1000000007;
	#ifdef using_mod
	inline void inc(int &x, const int &y){ x += y; if(x >= mod) x -= mod; }
	inline void dec(int &x, const int &y){ x -= y; if(x < 0) x += mod; }
	inline int ksm(int x,LL y){ int res=1; for(;y;y>>=1,x=1ll*x*x%mod) if(y&1) res=1ll*res*x%mod; return res;}
	#endif
	Templ(_Tp) inline _Tp gcd(_Tp x,_Tp y){ return y?gcd(y,x%y):x; }
	inline int VSC_Local(){
		#ifdef VSC_Compile
		while(getchar() != '\n');
		#endif
		return 0;
	}
	#define FILE(s) freopen(s ".in", "r", stdin), freopen(s ".out", "w", stdout)
	#define PBTXDY
}
using namespace my_std;

/*
 * null + '0' -> "0", null + '1' -> "1"
 * "0" + '0' -> "00", "0" + '1' -> "01"
 * "1" + '0' -> "10", "1" + '1' -> "11"
 * "00" + '0' -> "0", "00" + '1' -> "0"
 * "01" + '0' -> "0", "01" + '1' -> "1"
 * "10" + '0' -> "100", "10" + '1' -> "1"
 * "11" + '0' -> "11", "11" + '1' -> "11"
 * "100" + '0' -> "10", "100" + '1' -> "10"
*/
const int N = 300010, trans[8][2] = {{1, 2}, {3, 4}, {5, 6}, {1, 1}, {1, 2}, {7, 2}, {6, 6}, {5, 5}};
int n, dp[N][8];
char sc[N];

int main(){
	scanf("%s", sc);
	n = strlen(sc);
	dp[n][2] = dp[n][6] = 1;
	ROF(i, n - 1, 0){
		FOR(t, 0, 7){
			if(sc[i] != '0') inc(dp[i][t], dp[i + 1][trans[t][1]]);
			if(sc[i] != '1') inc(dp[i][t], dp[i + 1][trans[t][0]]);
		}
	}
	printf("%d\n", dp[0][0]);
	return VSC_Local();
}

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

int main(){
  unordered_map<int, pair<vector<int>, vector<int>>> m;
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
    m[i + arr[i]].first.push_back(i + 1);
    if (i - arr[i] > 0) m[i - arr[i]].second.push_back(i + 1);
  }
  
  long long c(0);
  for (const auto& [k, v]: m) {
    for (const int& i: v.first) {
      c += distance(lower_bound(v.second.begin(), v.second.end(), i + 1), v.second.end());
    }
  }
  cout << c << endl;
  return 0;
}

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

using namespace std;

long long gcd(long long a, long long b){
	return b?(gcd(b,a%b)):a;
}

long long lcm(long long a, long long b)  {  
    return (a*b)/gcd(a, b);  
}  


int main(){

	long long a,b,c,d;
	cin>>a>>b>>c>>d;

	
	long long sum(0);
	sum += (b/c);
	sum += (b/d);
	sum -= (a-1)/c;
	sum -= (a-1)/d;
	
	long long p = lcm(c,d);
	sum -= (b/p);
	sum += (a-1)/p;


	cout<<b-a-sum+1<<endl;
    return 0;
}

Measured memory_bytes: 256
# A, B = [i for i in input().split()]
#
# A = int(A)
# B = float(B)
# B100 = int(B*100)
#
# print((B100*A)//100)

import decimal
A, B = [decimal.Decimal(i) for i in input().split()]

C =A*B

ans = int(C)
print(ans)



Measured memory_bytes: 71316
#include"bits/stdc++.h"

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7



//メイン関数
int main()
{
	ll H, W;
	cin >> H >> W;
	vector<vector<bool>> a(H, vector<bool>(W));
	vector<vector<ll>> dp(H, vector<ll>(W));
	REP(i, H)
	{
		string s;
		cin >> s;
		REP(j, W)a[i][j] = (s[j] == '.');
	}
	dp[0][0] = 1;
	REP(i, H)REP(j, W)if(a[i][j])
	{
		if(i + 1 != H)dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % MOD;
		if(j + 1 != W)dp[i][j + 1] = (dp[i][j + 1] + dp[i][j]) % MOD;
	}
	cout << dp.back().back() << endl;
	cin >> H;

	return 0;
}


Measured memory_bytes: 8320
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
MOD = 10**9 + 7
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    n, k = LI()

    ans = pow(k, n, MOD)

    print(ans)

if __name__ == '__main__':
    resolve()



Measured memory_bytes: 6808
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		String[] s = br.readLine().split(" ");

		int[] numbers = new int[n];

		for(int i=0; i<n; i++){
			numbers[i] = Integer.parseInt(s[i]);
		}



		int count = 0;

		count = sellectesort(numbers, n, count);
		StringBuilder sb = new StringBuilder();
		for(int i=0; i<n; i++){
			sb.append(numbers[i]);
			sb.append(" ");
		}

		System.out.println(sb.toString().trim());
		System.out.println(count);
	}

	static int  sellectesort(int[] nums , int n, int count){

		int min;

		int counts = count;

		Boolean judge = false;

		for(int i=0; i<n-1; i++){
			min =i;

			for(int k=i+1; k<n; k++){
				if(nums[k]<nums[min]){
					min =k;
					judge =true;
				}
			}
			if(judge) counts++;

			int num = nums[i];

			nums[i] = nums[min];

			nums[min] = num;

			judge = false;

		}

		return counts;

	}


}

Measured memory_bytes: 24360
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    
    # divisors.sort()
    return divisors

N = int(input())

ans = 0
for i in range(1, N+1):
    if i % 2 == 1 and len(make_divisors(i)) == 8:
        ans += 1

print(ans)

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

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll ;
typedef unsigned long long ull ;
typedef long double ld ;

const ll MOD = 1E9 + 7, INF = 2E18 + 5 ;
const double PI = 2 * acos(0.0) ;
const long double EPS = 1.0E-14 ;

map <ll, ll> mpRow, mpCol ;
map <pair<ll, ll>, ll> mp ;
pair <ll, ll> pt[300005] ;
vector <ll> vecA, vecB ;

int main()
{
    ll r, c, m, ans = 0, rowVal = 0, colVal = 0, check = 0 ;
    cin >> r >> c >> m ;
    for (int i = 0; i < m; i++) {
        scanf("%lld %lld", &pt[i].first, &pt[i].second) ;
        mpRow[pt[i].first]++, mpCol[pt[i].second]++ ;
        mp[pt[i]]++ ;
    }

    for (auto it = mpRow.begin(); it != mpRow.end(); it++) {
        rowVal = max(rowVal, it->second) ;
    }

    for (auto it = mpCol.begin(); it != mpCol.end(); it++) {
        colVal = max(colVal, it->second) ;
    }
    for (auto it = mpRow.begin(); it != mpRow.end(); it++) {
        if (it->second == rowVal) {
            vecA.push_back(it->first) ;
        }
    }
    for (auto it = mpCol.begin(); it != mpCol.end(); it++) {
        if (it->second == colVal) {
            vecB.push_back(it->first) ;
        }
    }

    ans = rowVal + colVal - 1 ;

    for (int i = 0; i < vecA.size(); i++) {
        check = 0 ;
        for (int j = 0; j < vecB.size(); j++) {
            if (mp[{vecA[i], vecB[j]}] == 0) {
                check = 1 ;
                break ;
            }
        }
        if (check) {
            ans++ ;
            break ;
        }
    }

    cout << ans ;

    return 0 ;
}


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

#define pb push_back
#define ll long long int
#define mpi map<int, int>
#define vi vector<int>
#define qi queue<int>
#define si set<int>
#define pii pair<int, int>
#define vpi vector<pii>
#define vs vector<string>
#define pri priority_queue<int>
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define For(i, n) for (int i = 0; i < n; i++)
#define Ford(i, a, b) for (int i = a; i >= b; i--)
#define Rep(i, x, y) for (int i = x; i <= y; i++)
#define mem(a, b) memset(a, b, sizeof(a))
#define fastio                    \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)

double tick()
{
    static clock_t oldt, newt = clock();
    double diff = 1.0 * (newt - oldt) / CLOCKS_PER_SEC;
    oldt = newt;
    return diff;
}

ll fastExpo(ll a, ll n)
{
    ll res = 1;
    while (n)
    {
        if (n % 2)
            res = res * a;
        n /= 2;
        a = a * a;
    }
    return res;
}

int main()
{
    size_t n;
    cin >> n;
    intmax_t res = 1;
    vector<intmax_t> v(n);

    for (auto &i : v)
        cin >> i;
    sort(v.begin(), v.end());

    for (auto i : v)
        if (__builtin_mul_overflow(res, i, &res))
        {
            cout << -1 << endl;
            return 0;
        }

    intmax_t inf = 1e18;
    if (res > inf)
    {
        cout << -1 << endl;
        return 0;
    }
    cout << res << endl;

    cerr << "execution time is: " << tick() << "\n";
}


Measured memory_bytes: 3964
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

#define sqr(x) (x)*(x)

int main(){
  int n;
  double x,y,r;
  double x1,x2,x3,y1,y2,y3;
  double a1,a2,b1,b2,c1,c2;

  scanf("%d",&n);
  while(n--){
    scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3);
    a1 = 2.0 * (x2 - x1);
    b1 = 2.0 * (y2 - y1);
    c1 = sqr(x1) - sqr(x2) + sqr(y1) - sqr(y2);
    a2 = 2.0 * (x3 - x1);
    b2 = 2.0 * (y3 - y1);
    c2 = sqr(x1) - sqr(x3) + sqr(y1) - sqr(y3);

    x = (b1*c2 - b2*c1) / (a1*b2 - a2*b1);
    y = (c1*a2 - c2*a1) / (a1*b2 - a2*b1);

    r = sqrt(sqr((x-x1))+sqr((y-y1)));

    printf("%.3lf %.3lf %.3lf\n",x,y,r);
  }

  return 0;
}

Measured memory_bytes: 0
import sys
import copy

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

def dfs(node, count):

    if seen[node]==True:
        return
    seen[node]=True

    if node==(N-1) and count==2:
        print("POSSIBLE")
        sys.exit()
    elif count==2:
        return
    count = count + 1
    seen[node]=True

    for next_node in V[node]:
        dfs(next_node, count)

    return

V = []
seen = [False]*N

for i in range(N):
    V.append(set())

for i in range(M):
    *l, = map(int, input().split())
    V[l[0]-1].add(l[1]-1)
    V[l[1]-1].add(l[0]-1)


dfs(0, 0)

print("IMPOSSIBLE")

Measured memory_bytes: 69828
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		@SuppressWarnings("resource")
		Scanner scanner = new Scanner(System.in);

		long a = scanner.nextLong();
		long b = scanner.nextLong();

		System.out.println(a * b / gcs(a, b));

	}

	static long gcs(long a, long b) {

		long tmp;
		while ((tmp = a % b) != 0) {
			a = b;
			b = tmp;
		}
		return b;

	}

}

Measured memory_bytes: 21844
#include <stdio.h>
int main() {
  char S[1000];
  scanf("%s", S);
  int i;
  int ans = 0;
  for(i == 0; i < 200; ++i) {
    if (S[i] == NULL) {
      break;
    }
    if (i % 2 == 0 && S[i] == 'L') {
      ++ans;
      break;
    }
    if (i % 2 != 0 && S[i] == 'R') {
      ++ans;
      break;
    }
  }
  if (ans == 0) {
    printf("Yes");
  }
  else if (ans != 0) {
    printf("No");
  }
  return 0;
}

Measured memory_bytes: 256
from itertools import combinations
from heapq import heappop, heappush
import sys
sys.setrecursionlimit(1000000)
INF = 10 ** 20

def convert(s, m, n):
  if s == "H":
    return 0
  if s == "D":
    return 1
  if s[0] == "C":
    return int(s[1:]) + 1
  if s[0] == "L":
    return int(s[1:]) + m + 1

def get_cost(start, m, n, edges):
  cost = [INF] * (m + n + 2)
  cost[start] = 0
  que = []
  heappush(que, (0, start))
  while que:
    total, node = heappop(que)
    for dist, to in edges[node]:
      if cost[to] > total + dist:
        cost[to] = total + dist
        if not (2 <= to <= m + 1):
          heappush(que, (total + dist, to))
  return cost


def shortest_path(start, goal, rest, cakes_dist, dic):
  if not rest:
    return cakes_dist[start][goal]
  if (start, rest) in dic:
    return dic[(start, rest)]
  
  ret = INF
  for to in rest:
    ret = min(ret, shortest_path(to, goal, tuple((i for i in rest if i != to)), cakes_dist, dic) + cakes_dist[start][to])
  dic[(start, rest)] = ret
  return ret

while True:
  m, n, k, d = map(int, input().split())
  if m == 0:
    break
  clst = list(map(int, input().split()))
  """
  Home ... 0
  D ... 1
  Cake ... 2, 3, ... m + 1
  Land ... m + 2, m + 3, ... m + n + 1
  """
  edges = [[] for _ in range(m + n + 2)]
  for _ in range(d):
    s, t, e = input().split()
    e = int(e)
    s = convert(s, m, n)
    t = convert(t, m, n)
    edges[s].append((e, t))
    edges[t].append((e, s))
  
  cakes_dist = [[INF] * (m + 2) for _ in range(m + 2)]
  for start in range(m + 2):
    cost = get_cost(start, m, n, edges)
    for to in range(m + 2):
      if to != start:
        cakes_dist[start][to] = cost[to]
  
  """
  now ... 現在いる点
  rest ... 残りのめぐる点
  dic[(now, rest)] ... 現在いる点、残りの点をまわる時の最小距離
  dic[(now, rest)] = min(cakes_dist[now][to] + dic[(to, rest - to)] for to in rest)
  """
  dic = {}
  ans = INF
  cakes = [i for i in range(2, m + 2)]
  for num in range(m + 1):
    for rest in combinations(cakes, num):
      cal = sum([clst[i - 2] for i in rest])
      ans = min(ans, shortest_path(0, 1, rest, cakes_dist, dic) * k - cal)
  print(ans)


Measured memory_bytes: 6236
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdlib>
#include<utility>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#define int long long
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pi acos(-1)
#define pb push_back
#define all(v) v.begin(),v.end()
using namespace std;
typedef pair<int,int> p;
typedef long long ll;

signed main(){
	int n;
	cin>>n;
	int dt[n];
	dt[0]=2;dt[1]=1;
	loop(i,2,n+1)dt[i]=dt[i-1]+dt[i-2];
	cout<<dt[n]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  int H,W,k,i,j;
  for(k=0;;k++){
  scanf("%d %d",&H,&W);
    if(H==0 && W==0){break;}
  for(i=0;i<H ;i++ )
    {
      if(i%2==0)
	{
	  for(j=0;j<W;j++)
	    {
	      if(j%2==0){printf("#");}
	      else{printf(".");}
	    }
	}
      else
	{
	  for(j=0;j<W;j++)
	    {
	      if(j%2==0){printf(".");}
	      else{printf("#");}
	    }
	}
      printf("\n");
    }
  printf("\n");
  }
  return 0;
}

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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;

constexpr int MOD = 1000000007;

vvi permuate(int n) {
    vi vec(n);
    iota(vec.begin(), vec.end(), 1);

    vvi permutations = {vec};
    while (next_permutation(vec.begin(), vec.end())) { permutations.push_back(vec); }
    return permutations;
}

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

    int n;
    cin >> n;

    vi p(n), q(n);
    rep(i, 0, n) { cin >> p[i]; }
    rep(i, 0, n) { cin >> q[i]; }

    vvi permutations = permuate(n);
    auto p_itr = lower_bound(permutations.begin(), permutations.end(), p);
    auto q_itr = lower_bound(permutations.begin(), permutations.end(), q);

    cout << abs(distance(p_itr, q_itr)) << endl;
    return 0;
}

Measured memory_bytes: 3384
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(in);
int n = Integer.parseInt(sc.next());
int k = Integer.parseInt(sc.next());
int[] l=new int[n];
    for (int i = 0; i < n; i++) {
        l[i]=Integer.parseInt(sc.next());
    }
Arrays.sort(l);
int ans=0;
for (int i = n-1; i >=n-k; i--) {
        ans+=l[i];
}
    out.println(ans);
}
}

Measured memory_bytes: 23636
//Be Name Khoda, Besmellah Rahmane Rahim, In The Name Of God;
//#include<bits/stweight++.h>
#include<iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include<bitset>
#include<list>
#include<cassert>
#include<numeric>
#include <stdio.h>
#include <string.h>
#include<iomanip>
#include<unordered_map>
#include<unordered_set>
#include <fstream>
 
using namespace std;
const int N = 1000 + 5;
int a[N];
int n,m;
vector<int> ans;
 
int main()
{
    cin >> n >> m;
    int cnt = 0;
    for(int i = 1; i <= m; ++i) 
    {
        cin >> a[i];
        cnt += a[i] % 2;
    }
    if (cnt > 2)
    {
        cout << "Impossible" << endl;
        return 0;
    }
    for(int i = 2; i < m; i++) 
    {
        if (a[i] % 2) 
        {
            if (a[1] % 2)
            {
                swap(a[i], a[m]);
            }
            else
            {
                swap(a[i], a[1]);
            }
        }
    }
    for (int i = 1; i <= m; i++) 
    {
        cout << a[i] << " ";
    }
    cout << endl;
    if (m == 1 && a[1] == 1) 
    {
        ans.push_back(1);
    }
    else 
    {
        if (m == 1)
        { 
            ans.push_back(a[1] - 1);
            ans.push_back(1);
        }
        else 
        {
            if (a[1] != 1) 
            {
                ans.push_back(a[1] - 1);
            }
            for (int i = 2; i < m; i++) 
            {
                ans.push_back(a[i]);
            }
            ans.push_back(a[m] + 1);
        }
    }
    cout << ans.size() << endl;
    for(int i = 0; i < ans.size(); i++) 
    {
        cout << ans[i] << " ";
    }
}

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

int main(){
    int x,y,z,k;
    cin>>x>>y>>z>>k;
    ll a[x],b[y],c[z];
    for(int i=0;i<x;i++)cin>>a[i];
    for(int i=0;i<y;i++)cin>>b[i];
    for(int i=0;i<z;i++)cin>>c[i];
    vector<ll> d(x*y);
    for(int i=0;i<x;i++){
        for(int j=0;j<y;j++){
            d.push_back(a[i]+b[j]);
        }
    }
    sort(d.begin(),d.end(),greater<ll>());
    vector<ll> e(k*z);
    for(int i=0;i<min(k,x*y);i++){
        for(int j=0;j<z;j++){
            e.push_back(d[i]+c[j]);
        }
    }
    sort(e.begin(),e.end(),greater<ll>());
    for(int i=0;i<k;i++)cout<<e[i]<<endl;
}


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


int main(){
int a,b,c,x,count;
cin >> a >> b >> c >> x;
count = 0;
for (int i = 0; i <= a; i++)
{
    for (int j = 0; j <= b; j++)
    {
        for (int k = 0; k <= c; k++)
        {
            if (500 * i + 100 * j + 50 * k == x)
            {
                count++;
            }
            
        }
        
    }
    
}

cout << count << endl;



}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const int INF=1e9;
int dp[15][16];
int fld[15][15];
int main(){
      int x,y;
      while(cin>>x>>y&&(x||y)){
            REP(i,y)REP(j,x)cin>>fld[j][i];
            memset(dp,0,sizeof(dp));
            REP(i,x)if(fld[i][0]==0)dp[i][0]=1;
            REP(i,y-1){
                  REP(j,x){
                        if(fld[j][i]==0){
                              for(int k=-1;k<=1;k++){
                                    if(j+k<0||j+k>=x)continue;
                                    //cout<<j+k<<" "<<i+1<<" "<<j<<" "<<i<<endl;
                                    if(fld[j+k][i+1]==0){
                                          //cout<<j+k<<" "<<i+1<<" "<<j<<" "<<i<<endl;
                                          dp[j+k][i+1]+=dp[j][i];
                                    }
                                    else if(fld[j+k][i+1]==2&&k==0)dp[j+k][i+1]+=dp[j][i];
                              }
                        }else if(fld[j][i]==2){
                              int to=min(y,i+2);
                              if(to==y||fld[j][to]!=1)dp[j][to]+=dp[j][i];
                        }
                  }
                  //REP(k,x)cout<<dp[k][i+1]<<" ";cout<<endl;
            }
            //REP(i,y+1)REP(j,x)printf("%2d%c",dp[j][i],j==x-1?'\n':' ');
            int ans=0;
            REP(i,2)REP(j,x)ans+=dp[j][y-i];
            cout<<ans<<endl;
      }
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

vector<long long> A;

long long cnt(long long key) {
    long long res = 0;
    rep(i, A.size()) {
        if (A[i] == 0) {
            if (key > 0) res += A.size() - i - 1;
        } else if (A[i] < 0) {
            int left = i;
            int right = A.size();
            while (right - left > 1) {
                int mid = (right + left) / 2;
                if (A[i] * A[mid] < key) right = mid;
                else left = mid;
            }
            res += A.size() - right;
        } else {
            int left = i;
            int right = A.size();
            while (right - left > 1) {
                int mid = (right + left) / 2;
                if (A[mid] * A[i] < key) left = mid;
                else right = mid;
            }
            res += left - i;
        }
    }
    return res;
}

int main() {
    int N;
    long long K;
    cin >> N >> K;
    A = vector<long long>(N);
    rep(i, N) cin >> A[i];
    sort(A.begin(), A.end());
    
    long long left = -1e18 - 100, right = 1e18 + 100;
    while (right - left > 1) {
        long long mid = (right + left) / 2;
        if (K - 1 < cnt(mid)) right = mid;
        else left = mid;
    }
    cout << left << endl;
    return 0;
}


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

int main(){
    string s, t;
    int i, j, s_l, t_l;
    bool ans = false;
    bool a_flag = true;
    bool a_flag_tmp = false;

    cin >> s >> t;
    s_l = s.length();
    t_l = t.length();

    for (i=0; i<s_l; i++){
        for (j=0; j<t_l; j++){
            if (s[i] < t[j]){
            ans = true;
            break;
            }
            else if (s[i] == t[j]){
            a_flag_tmp = true;
            }
        }
        a_flag = a_flag & a_flag_tmp;
        a_flag_tmp = false;
        if (ans == true)
            break;
    }

    if (a_flag == true && s_l < t_l)
        ans = true;

    if (ans == true)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


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

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  char c[2] = {'S', 'W'};
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 2; j++) {
      vector<int> T;
      T.push_back(i);
      T.push_back(j);
      for (int k = 0; k < N; k++) {
        if (S[k] == 'o') {
          if (T[k + 1] == 0)
            T.push_back(T[k]);
          else
            T.push_back(1 - T[k]);
        } else {
          if (T[k + 1] == 0) {
            T.push_back(1 - T[k]);
          } else {
            T.push_back(T[k]);
          }
        }
      }
      if (T[0] == T[N] && T[1] == T[N + 1]) {
        for (int i = 1; i < N + 1; i++) {
          cout << "SW"[T[i]];
        }
        cout << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
}

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

int main(void){
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
        cin >> v[i];
    
    ll ans = 0;
    vector<int> left_minus_list;
    ll left_plus = 0;
    for (int i = 0; i <= n; i++) {
        if (i > 0)
            if (v[i-1] < 0)
                left_minus_list.push_back(v[i-1]);
            else
                left_plus += v[i-1];
        
        int sosa_num = i;
        ll all_plus = left_plus;
        vector<int> all_minus_list;
        copy(left_minus_list.begin(), left_minus_list.end(), back_inserter(all_minus_list));
        for (int j = n+1; j > i; j--) {
            if (n + 1 != j) {
                sosa_num++;
                if (sosa_num > k)
                    break;
                if (v[j-1] < 0)
                    all_minus_list.push_back(v[j-1]);
                else
                    all_plus += v[j-1];
            }
            if (sosa_num <= k) {
                if (all_minus_list.size() <= k - (sosa_num)) {
                    ans = max(ans, all_plus);
                    //cout << "a " <<  i << " " << j << " " << all_plus << endl;
                }
                else {
                    sort(all_minus_list.begin(), all_minus_list.end());
                    ans = max(ans, all_plus + accumulate(all_minus_list.begin()+(k-sosa_num), all_minus_list.end(), 0));
                    //cout << "b " <<  i << " " << j << " " << all_plus << " " << all_minus_list.size() << " " << accumulate(all_minus_list.begin()+(k-sosa_num), all_minus_list.end(), 0) << endl;
                }
            }
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
# ワーシャルフロイド法
H, W=list(map(int, input().split()))
c=[list(map(int, input().split())) for _ in range(10)]
A=[list(map(int, input().split())) for _ in range(H)]

for k in range(10):
    for i in range(10):
        for j in range(10):
            if c[i][j]>c[i][k]+c[k][j]:
                c[i][j]=c[i][k]+c[k][j]

ans=0
for h in range(H):
    for w in range(W):
        if A[h][w]!=-1 and A[h][w]!=-1:
            ans+=c[A[h][w]][1]
print(ans)


Measured memory_bytes: 3444
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

const int maxn = 1e5+10;

char a[maxn];

int main()
{
    bool yes = true;
    scanf("%s",a);
    int len = strlen(a);
    for(int i=0;i<len;i++)
    {
        if(a[i]=='d')
        {
            if(i+4<len&&(a[i+1]=='r'&&a[i+2]=='e'&&a[i+3]=='a'&&a[i+4]=='m'))
            {
                i=i+4;
                if((a[i+1]=='e'&&a[i+2]=='r')&&((i+3==len)||((i+3<len)&&(a[i+3]=='d'||a[i+3]=='e'))))
                {
                    i=i+2;
                }
            }
            else
            {
                yes=false;
                break;
            }
        }
        else if(a[i]=='e')
        {
            if(i+4<len&&(a[i+1]=='r'&&a[i+2]=='a'&&a[i+3]=='s'&&a[i+4]=='e'))
            {
                i=i+4;
                if((a[i+1]=='r')&&((i+2==len)||((i+2<len)&&(a[i+2]=='d'||a[i+2]=='e'))))
                {
                    i++;
                }
            }
            else
            {
                yes=false;
                break;
            }
        }
        else
        {
            yes=false;
            break;
        }
    }
    if(yes)
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


string str;
int main() {
  while (cin >> str) {
	int con = 0;
	for (int i = 1; i < str.size(); ++i) {
	  if (str[i] != str[i-1]) ++con;
	}
	cout << con << endl;
  }
}
	   


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int N,i,j=-1,Y,cnt=0,f1=0,f2=0;
    int m[1000];
  cin>>N;
    int x,y;
    y=N%100;
    x=N/100;
    if(x>=1&&x<=12){f1=1;}
    if(y>=1&&y<=12){f2=1;}
    
   if(f1==1&&f2==1){cout<<"AMBIGUOUS\n";}
        else if(f1==1&&f2!=1)
       {cout<<"MMYY\n";}
        else if(f2==1&&f1!=1)
        {cout<<"YYMM\n";}
      else{cout<<"NA\n";}
     
 
    
    
    

    }

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

using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair

int main()
{
	ios::sync_with_stdio(false);
  	cin.tie(0);
	int n;
	cin >> n;
	cout << "ABC" << n << "\n";	
	return 0;
}

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

using namespace std;

#define int long long

int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int val=a[0];
    for(int i=1;i<n;i++){
        val=(val^a[i]);
    }
    vector<int>b(n);
    for(int i=0;i<n;i++){
        b[i]=(val^a[i]);
        cout<<b[i]<<' ';
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 6284
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include <unordered_map>
#define MOD (1000000007l)

using namespace std;

int main(void) {
  vector<long> original;
  long N;
  cin >> N;

  long before = 0;
  for (long i = 0; i < N; i++) {
    long tmp;
    cin >> tmp;
    if (tmp != before) {
      original.push_back(tmp);
      before = tmp;
    }
  }

/*
  for (auto v: original) cerr << v << endl;
  cerr << endl;
*/

  unordered_map<long, long> selecting;
  long ret = 1;

  for (long v: original) {
    ret = (ret + selecting[v]) % MOD;
    selecting[v] = ret;
  }

  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 10096
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

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

#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, BinaryHeap, VecDeque};
fn main() {
    input!(n:i32, k:i32, p:[i32;n]);
    let mut p:Vec<i32> = p.clone();
    p.sort();
    let mut ans = 0;
    for i in 0..k {
        ans+=p[i as usize];
    }
    println!("{}", ans);
}


Measured memory_bytes: 2172
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define int long long
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
    string S; cin >> S;
    int ans = 0;
    rep(i, (S.size() + 1) / 2) {
        if (S.at(i) != S.at(S.size() - i - 1))ans++;
    }
    cout << ans << endl;
}

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

int main()
{
	string s1, s2;
	while (cin >> s1, s1 != ".") {
		cin >> s2;
		if (s1 == s2) {
			puts("IDENTICAL");
			continue;
		}
		int n1 = s1.size(), n2 = s2.size();
		bool ok = true;
		int i1 = 0, i2 = 0, cnt = 0;
		while (i1 < n1 || i2 < n2) {
			string t1, t2;
			while (i1 < n1 && s1[i1] != '\"') t1.push_back(s1[i1++]);
			while (i2 < n2 && s2[i2] != '\"') t2.push_back(s2[i2++]);
			if (t1 != t2) {
				ok = false;
				break;
			}
			if (i1 < n1) ++i1;
			if (i2 < n2) ++i2;
			if (i1 == n1 || i2 == n2) break;
			t1.clear(), t2.clear();
			while (i1 < n1 && s1[i1] != '\"') t1.push_back(s1[i1++]);
			while (i2 < n2 && s2[i2] != '\"') t2.push_back(s2[i2++]);
			if (t1 != t2) ++cnt;
			if (i1 < n1) ++i1;
			if (i2 < n2) ++i2;
		}
		if (i1 != n1 || i2 != n2) ok = false;
		puts(ok && cnt == 1 ? "CLOSE" : "DIFFERENT");
	}
	return 0;
}



Measured memory_bytes: 3156
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n * n);

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

    for (int i = 0; i < n * n; i++) {
        if (b[i] == 0)
            continue;
        int count = b[i] - 1;
        int j = 0;
        while (count > 0 && j < i) {
            if (b[j] != 0) {
                j++;
                continue;
            }
            b[j] = b[i];
            count--;
            j++;
        }
        if (count > 0) {
            cout << "No";
            return 0;
        }
    }

    for (int i = 0; i < n; i++) {
        int count = n - i - 1;
        int j = a[i];
        while (count > 0 && j < n * n) {
            if (b[j] != 0) {
                j++;
                continue;
            }
            b[j] = i + 1;
            count--;
            j++;
        }
        if (count > 0) {
            cout << "No";
            return 0;
        }
    }

    cout << "Yes" << endl;
    for (int i = 0; i < n * n; i++)
        cout << b[i] << " ";

    return 0;
}

Measured memory_bytes: 2176
#include <iostream>

using namespace std;

int main()
{
    int H,W,h,w;
    int temp1=0;
    int temp2=0;
    cin>>H;
    cin>>W;
    cin>>h;
    cin>>w;
    temp1=(H-h);
    temp2=(W-w);
    cout<<temp1*temp2;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main(void) {
	string str;
	cin >> str;
	bool find = false;
	for (int i = 1; !find && i < str.length()-1; ++i) {
		string ss = str.substr(0,str.length()-i);
		if (ss.length()%2 == 0) {
			if (ss.substr(0,ss.length()/2) == ss.substr(ss.length()/2,ss.length()/2)) {
				cout << ss.length() << endl;
				find = true;
			}
		}
	}

	return 0;
}


Measured memory_bytes: 256
S=str(input())
s=list(S)
# print(S[0:2])
# print(S[3:4])
s1 = int(''.join(S[0:2]))
s2 = int(''.join(S[2:4]))
# print(s1)
# print(s2)

stmp1=""
if s1 <=12 and s1 > 0:
    stmp1='MM'
elif (s1 > 0):
    stmp1='YY'
else:
    stmp1='NA'

stmp2=""
if s2 <=12 and s2 > 0:
    stmp2='MM'
elif (s2 > 0):
    stmp2='YY'
else:
    stmp2='NA'

if((stmp1=='NA' and not (stmp2=='MM')) or (stmp2=='NA' and not (stmp1=='MM')))or(stmp1=='YY' and stmp2=='YY'):
    print('NA')
elif(stmp1=='MM' and stmp2=='MM'):
    print('AMBIGUOUS')
elif(stmp1=='NA'):
    print('YY'+stmp2)
elif(stmp2=='NA'):
    print(stmp1+'YY')
else:
    print(stmp1+stmp2)

Measured memory_bytes: 3316
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N = int(input())
    A = [int(x) for x in input().split()]

    if A.count(0) >= 1:
        print(0)
        return
    ans = 1
    for a in A:
        ans *= a
        if ans > 10 **18:
            print(-1)
            return

    print(ans)
    
    

if __name__ == '__main__':
    main()



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

map<ll, int> prime_factor(ll n) {
    map<ll, int> ret;
    for (ll i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

int main() {

    int N;
    cin >> N;

    map<ll, int> prime = prime_factor(N);
    cout << N << ":";

    for (auto itr = prime.begin(); itr != prime.end(); itr++) {
        rep(i, itr->second) cout << " " << itr->first;
    }

    cout << endl;

    return 0;
}


Measured memory_bytes: 3112
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,x,i;
	cin>>n>>x;
	vector<int> a(n);
	int ans=1;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	if(a[0]<=x)
	ans++;
	for(i=1;i<n;i++)
	{
		a[i]=a[i-1]+a[i];
			if(a[i]<=x)
	         ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.stream.Collectors;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int P = scanner.nextInt();
		int Q = scanner.nextInt();
		int R = scanner.nextInt();
		scanner.close();
		List<Integer>list = Arrays.asList(P, Q, R);
		list = list.stream().sorted().collect(Collectors.toList());
		System.out.println(list.get(0)+list.get(1));
	}
}

Measured memory_bytes: 27092
#include <bits/stdc++.h>
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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const int inf = (1<<29);
int N, A, B, C;
vector<int> l(10);

int dfs(int n, int a, int b, int c){
    if(n == N+1){
        if(a && b && c) return abs(a-A)+abs(b-B)+abs(c-C)-30;
        else return inf;
    }

    int resA = dfs(n+1, a+l[n], b, c)+10;
    int resB = dfs(n+1, a, b+l[n], c)+10;
    int resC = dfs(n+1, a, b, c+l[n])+10;
    int resD = dfs(n+1, a, b, c);

    return min(min(resA, resB), min(resC, resD));
}

int main(){
    cin >> N >> A >> B >> C;
    for(int i=1; i<=N; i++) cin >> l[i];

    cout << dfs(1, 0, 0, 0) << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  string s;
  cin >> s;
  int cnt = 0;
  rep(i, s.size()) if (s[i] == '1') {
    cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3592
def dist(a, b):
    return abs(a[0]-b[0]) + abs(a[1]-b[1])
n, m = map(int, input().split())
studs = [list(map(int, input().split())) for _ in range(n)]
checks = [list(map(int, input().split())) for _ in range(m)]
for s in studs:
    min_d = 4 * 10 ** 8 + 1
    min_idx = 0

    for idx, c in enumerate(checks):
        d = dist(s, c)
        if d < min_d:
            min_d = d
            min_idx = idx + 1

        elif d==min_d:
            min_idx = min(min_idx, idx+1)
    print(min_idx)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(i=0;i<n;i++)
#define test(a) cout << "*" << a << endl;
int main (){
  int N;
  cin >> N;
  if(N%10==3){
    cout << "bon";
  }
  else if(N%10==0||N%10==1||N%10==6||N%10==8){
     cout << "pon";

    
  }
  else{
      cout << "hon";

  }
}

Measured memory_bytes: 3620