akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define siz(v) (ll)(v).size()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repn(i, n) for (ll i = 0; i <= (ll)(n); i++)
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
vector<ll> dx = {-1, 1, 0, 0}, dy = {0, 0, -1, 1};
//cin.tie(0);
//ios::sync_with_stdio(false);

signed main()
{
    ll n, x, ans = INF*INF;

    cin >> n >> x;
    vector<ll> v(2010, INF);

    vector<ll> mncost(n, INF * INF);

    rep(i, n)
    {
        cin >> v[i];
    }


    for (int i = 0; i < n; i++)//使用回数
    {
        ll res=0;
        for(int j=0;j < n;j++)//スライム
        {
            if(i){
                mncost[j]=min(mncost[j],v[(j-i+n)%n]);
            }else{
                mncost[j]=v[j];
            }
            res+=mncost[j];
        }
        ans=min(ans,res+x*i);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
def solve():
    class UnionFind:
        def __init__(self, n):
            self.par = [i for i in range(n)]
            self.rank = [0] * n
            self.size = [1] * n

        # 検索
        def find(self, x):
            if self.par[x] == x:
                return x
            else:
                self.par[x] = self.find(self.par[x])
                return self.par[x]

        # 併合
        def unite(self, x, y):
            x = self.find(x)
            y = self.find(y)

            if x == y:
                return

            if self.rank[x] < self.rank[y]:
                self.par[x] = y
                self.size[y] += self.size[x]
                self.size[x] = 0
            else:
                self.par[y] = x
                self.size[x] += self.size[y]
                self.size[y] = 0
                if self.rank[x] == self.rank[y]:
                    self.rank[x] += 1

        # 同じ集合に属するか判定
        def same(self, x, y):
            return self.find(x) == self.find(y)

        # すべての頂点に対して親を検索する
        def all_find(self):
            for n in range(len(self.par)):
                self.find(n)


    N, M = map(int, input().split())
    ab = [list(map(int, input().split())) for _ in range(M)]
    uf = UnionFind(N)
    ans = []
    score = N * (N - 1) // 2
    for i in range(M - 1, -1, -1):
        ans.append(score)
        a, b = ab.pop()
        a -= 1
        b -= 1
        pa, pb = uf.find(a), uf.find(b)
        if not uf.same(pa, pb):
            score -= uf.size[pa] * uf.size[pb]
        uf.unite(a, b)
    ans.reverse()
    [print(ans[i]) for i in range(M)]
if __name__ == '__main__' :
    solve()

Measured memory_bytes: 33448
#include<stdio.h>
#include<string.h>
int main (){
  char s[100], p[100], s2[201];
  scanf ("%s", s);
  scanf ("%s", p);
  strcat (s2, s);
  strcat (s2, s);
  if ( strstr(s2, p) == '\0')
    printf ("No\n");
  else
    printf ("Yes\n");
  return 0;
}


Measured memory_bytes: 2104
/**< 🤣🤣🤣 */
#include<bits/stdc++.h>
using namespace  std ;
typedef long long  ll;
typedef pair<ll, ll> Pll;
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define deb(X) cout << (X) << endl
#define ASH(X) cout << (X) << " "
#define debug(x) cout << #x << " " << x << endl;
#define debug2(x,y) cout << #x << " " << x << " " << #y << " " << y << endl;
#define FOR(I,A,B) for(ll I = (A); I <= (B); I++)
#define RFOR(I,B,A) for(ll I = (B); I >=(A); I--)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define SORT(c) (sort(c.begin(),c.end()))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASES int ___T; cin >> ___T; for(int cs=1;cs<=___T;cs++)
#define FAST()  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
//template<typename T>T gcd(T x, T y){if(y==0)return x;else return gcd(y,x%y);}
ll fx[] = {1, 1, 0, -1, -1, -1, 0, 1};
ll fy[] = {0, 1, 1, 1, 0, -1, -1, -1};
vector<ll>a1,b1,c1;


/************************************************/

void Execute()
{   ll n, x, y = 0, a, b;
     cin >> x >> n;
     ll mn = INT_MAX;
     map<ll,ll>m1;
     FOR(i,1,n)
     {
         cin >> a;
         m1[a]=-1;
         //mn  = min(mn,a);
         //mx  = max(mx,a);
     }

     FOR(i,0,105)
     {
         if(m1[i]!=-1)
         {
             b = abs(x-i);
             if(b<mn){
                mn = b;
                y =i;}
         }
     }
     deb(y);

}

int32_t main()
{   //  #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    //#endif

    FAST();
    //CASES
   // {
     Execute();
        //cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "sec \n";
    //}
}
/**< 🤣🤣🤣 */


Measured memory_bytes: 3664
#include <cstdio>
#include <iostream>
using namespace std;
int n;
int a[55];
int b[55];
int main()
{
	while(cin>>n){
		for(int i=0;i<n;i++) cin>>a[i];
		for(int i=0;i<n;i++) cin>>b[i];
		int sum=0;
		for(int i=0;i<n;i++){
			if(a[i]>b[i]) sum+=a[i]-b[i];
		}
		cout<<sum<<endl;
	}
	return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define forn(i, a, n) for (int i = a; i < n; ++i)
#define ford(i, a, n) for (int i = n - 1; i >= a; --i)
#define fore(i, a, n) for (int i = a; i <= n; ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
    for (auto i : a) cerr << i << ' ';\
    cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> t(n), a(n);
    forn(i, 0, n) cin >> t[i];
    forn(i, 0, n) cin >> a[i];
    vector<int> mn(n, 1), mx(n, INF);
    mn[0] = max(mn[0], t[0]);
    mx[0] = min(mx[0], t[0]);
    forn(i, 1, n) {
        mx[i] = min(mx[i], t[i]);
        if (t[i] != t[i - 1]) {
            mn[i] = max(mn[i], t[i]);
        }
    }
    mn[n - 1] = max(mn[n - 1], a[n - 1]);
    mx[n - 1] = min(mx[n - 1], a[n - 1]);
    ford(i, 0, n - 1) {
        mx[i] = min(mx[i], a[i]);
        if (a[i] != a[i + 1]) {
            mn[i] = max(mn[i], a[i]);
        }
    }
    ll ans = 1;
    forn(i, 0, n) {
        if (mn[i] > mx[i]) {
            cout << "0\n";
            return 0;
        }
        ans *= (mx[i] - mn[i] + 1);
        ans %= MOD;
    }
    forn(i, 0, n) {
        //cerr << mn[i] << ' ' << mx[i] << '\n';
    }
    cout << ans <<'\n';
}


Measured memory_bytes: 1920
#include "bits/stdc++.h"
// #include <boost/multi_array.hpp>
// #include <boost/optional.hpp>
// #include <boost/range/irange.hpp>
// #include <boost/range/algorithm.hpp>
// #include <boost/range/adaptors.hpp>

// namespace adaptor = boost::adaptors;

using ll = long long;
using i64 = int64_t;

void Main()
{
   int N, K;
   std::cin >> N >> K;
   std::cout << N - K + 1 << "\n";
}

int main()
{
   std::cin.tie(nullptr);
   std::ios_base::sync_with_stdio(false);
   std::cout << std::fixed << std::setprecision(15);
   Main();
   return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>



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

using namespace std;
long long int a,b,x;
int main(){
  cin >> a >> b >> x;
  a = ((a+x-1)/x) *x;
  b = b/x *x;
  cout << (b-a)/x + 1 <<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int x, y, b, p;

int solve(){
  if(b>=5 && p>=2) return 0.8*(x*b + y*p);
  int i = b>5? b:5;
  int j = p>2? p:2;
  int k = 0.8*(x*i + y*j);
  int l = x*b + y*p;
  return l<k ? l:k;
}

int main(){
  int n;
  cin >> n;
  for(int i=0; i<n; ++i){
    cin >> x >> y >> b >> p;
    cout << solve() << endl;
  }
  return 0;
}

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

const int maxn = 1e5+5;
char s[maxn];
int t[3];

int main()
{
    scanf("%s",s);
    for(int i = 0; i < strlen(s); i++)
    {
        if(s[i] == 'a')
            t[0]++;
        if(s[i] == 'b')
            t[1]++;
        if(s[i] == 'c')
            t[2]++;
    }
    sort(t,t+3);
    if(t[2]-t[0] >= 2)
        printf("NO\n");
    else
        printf("YES\n");
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string str,bstr;
    cin>>str>>bstr;
    int count=0,mxi=0;;
    for(int i=0;i<bstr.size();i++)
    {
        count=0;
        for(int j=i;j<=str.size()-bstr.size()+i;j++)
        {
            count=0;
           if(str[j]==bstr[i])
           {
               //cout<<i<<" "<<j<<endl;
               for(int x=0;x<bstr.size()-i;x++)
               {
                   if(str[x+j]==bstr[x+i])
                   count++;
               }
               mxi=max(count,mxi);
           }
           
        }
        
    }
    cout<<bstr.size()-mxi;
   
}

Measured memory_bytes: 3620
import java.util.*;
import java.io.*;
import java.math.*;
public class Main{
	static int mod = (int)1e9+7;
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	public static void main(String sp[])throws IOException{
		FastReader sc = new FastReader();
		String st = sc.next();
		int v=0;
		boolean b=true;
		for(int i=0;i<st.length();i+=2){
			if(st.charAt(i)=='R' || st.charAt(i)=='U' || st.charAt(i)=='D')
				v=0;
			else b=false;
		}
		for(int i=1;i<st.length();i+=2){
			if(st.charAt(i)=='L' || st.charAt(i)=='U' || st.charAt(i)=='D')
				v=0;
			else b=false;
		}
		if(b==true)
			System.out.println("Yes");
		else System.out.println("No");

	}
	
	public static class pair{
		int pos;
		int bomb;
	}
	
	
	public static int partition(int [] arr, int s, int e){
		
		int index=s;
		int pivot = arr[e];
		for(int i=s;i<=e-1;i++){
			if(arr[i]<=pivot){
				arr = swap(arr, index, i);
				index++;
			}
		}
		swap(arr,index,e);
		print(arr);
		return index;
	}
	
	public static int[] swap(int[] arr, int low, int high){
		int temp = arr[low];
		arr[low]=arr[high];
		arr[high]=temp;
		return arr;
	}
	
	
	public static long gcd(long a, long b){
		if(a==0)
			return b;
		
		return gcd(b%a,a);
	}
	
	public static void print(int[] arr){
		for(int i=0;i<arr.length;i++)
			System.out.print(arr[i]+" ");
		System.out.println();
	}
	

	public static class comp implements Comparator<pair>{
		public int compare(pair o1, pair o2){
			return o1.bomb-o2.bomb;
		}
	}
	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;
	
 
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
 
		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return st.nextToken();
		}
 
		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}
 
		double nextDouble() {
			return Double.parseDouble(next());
		}
 
		long nextLong() {
			return Long.parseLong(next());
		}
 
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
	
}

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

#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define uniq(x) ((x).erase(unique(all(x)),(x).end()))
#define sz(x) ((int)(x).size())

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

#ifdef LOCAL//compile with -DLOCAL
#define debug(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<(x)<<endl
#define debug_vec(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = ";\
  rep(i,sz(x)){cerr<<x[i]<<" ";}cerr<<endl
#define debug_mat(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<endl;\
  rep(i,sz(x)){rep(j,sz(x[i])){cerr<<x[i][j]<<" ";}cerr<<endl;}cerr<<endl
#else
#define debug(x) void(0)
#define debug_vec(x) void(0)
#define debug_mat(x) void(0)
#endif

template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}


int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  ll N,M;
  cin >> N >> M;

  ll ans=0;
  for(ll i=1;i*i<=M;i++){
    if(M%i!=0)  continue;
    if(M/i>=N)  chmax(ans,i);
    ll a=M/i;
    if(M/a>=N)  chmax(ans,a);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3648
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  int n = sc.nextInt();
  int sum = 0;
  int[] w = new int[n]; 
  for(int i = 0; i < n;i++){
    w[i] = sc.nextInt();
    sum += w[i];
  }
  int sf = 0;
  int ss = w[0];
  for(int i = 0;;i++){
    sf += w[i];
    ss += w[i+1];
    if(ss > ((sum+1)/2)+1){
      break;
    }
  }
  int ansf = Math.abs(sum - sf*2);
  int anss = Math.abs(sum - ss*2);
  System.out.println(ansf <= anss ? ansf : anss);
}}


Measured memory_bytes: 23764
def change_str(moto_str):
    global Nnew
    global str_list
    global change_list

    for i in range(len(change_list)):
       if change_list[i] == moto_str:
            num = i+Nnew
            if num > 25:
                num = num - 26
    return change_list[num]

Nnew = int(input())
str = input()
str_list = list(str)
change_list = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]

for i in range(len(str_list)):
    str_list[i] = change_str(str_list[i])


print(*str_list,sep='')



Measured memory_bytes: 4852
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>

// Remove GCC optimizer for codechef
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

using namespace std;
using namespace __gnu_pbds;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define endl "\n"
#define int long long
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

const int INF = 1e16;
const double PI = acos(-1);
const int N = 1e6 + 7;
int mod = 1e9 + 7;

const int maxn = 102;
char mat[maxn][maxn];
int dp[maxn][maxn];
int n, m;

int32_t main()
{
    IOS;
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    
    
    cin >> n >> m;
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= m; j++)
        {
            cin >> mat[i][j];
        }
    }
    for(int i = 0; i <= n; i++)
        for(int j = 0; j <= m; j++)
            dp[i][j] = INF;
    dp[0][1] = 0;
    dp[1][0] = 0;
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= m; j++)
        {
            if(mat[i][j] == '.')
                dp[i][j] = min(dp[i-1][j], dp[i][j-1]);
            else
            {
                int mn = min(dp[i-1][j], dp[i][j-1]) + 1;
                if(mat[i-1][j] == '#')
                    mn = min(dp[i-1][j], mn);
                if(mat[i][j-1] == '#')
                    mn = min(dp[i][j-1], mn);
                dp[i][j] = mn;
            }
            // cout << dp[i][j] << " ";
        }
        // cout << endl;
    }
    cout << dp[n][m] << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int n,a,c[100009];
int main()
{
	cin >>n;
	for (int i=0;i<n;i++)
	{
		cin >>a;
		c[a]++;
	}
	int ret=0;
	for (int i=0;i<=100000;i++)
	ret=max(ret,c[i]+c[i+1]+c[i+2]);
	cout <<ret<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(){
	int s1,s2,s3;
	cin>>s1>>s2>>s3;
	cout<<s1<<" "<<s2<<" "<<3*s3-s1-s2<<endl;
	cout<<4*s3-2*s1-s2<<" "<<s3<<" "<<2*s1+s2-2*s3<<endl;
	cout<<s1+s2-s3<<" "<<2*s3-s2<<" "<<2*s3-s1<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define pa pair<int,int>
#define ld long double
#define BOOST ios_base::sync_with_stdio(false)
#define pb push_back
#define st first
#define nd second
using namespace std;
char tab[1005][1005];
int dp[1005][1005];
const int mod=1e9+7;
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;i++)
    {
        for (int j=1;j<=m;j++)
        {
            scanf(" %c",&tab[i][j]);
        }
    }
dp[1][1]=1;
    for (int i=1;i<=n;i++)
    {
        for (int j=1;j<=m;j++)
        {
          if (tab[i][j]!='#' && dp[i][j]==0)dp[i][j]=(dp[i][j-1]+dp[i-1][j])%mod;
        }
    }
    printf("%d",dp[n][m]);
    return 0;
}




Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
int main(){
  int num;
  float ans;
  float *box;
  cin >> num;
  cin.ignore();
  box = new float[num];
  for(int i=0;i<num;i++){
    cin >> box[i];
  }
  for(int i=0;i<num;i++){
    ans += (1/box[i]);
  }
  cout << 1/ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
scanf("%d",&n);
string s1;
cin>>s1;
int x=0,Max=0;
for(int i=0;i<n;i++){
if(s1[i]=='I')
x++;
Max=max(x,Max)	;
if(s1[i]=='D')
x--;
}
printf("%d",Max);
	
	
	
	
	
	
	
	
	
	
}

Measured memory_bytes: 256
//自称高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    int ans = 0;
    int tmp;
    int n, a;
    cin >> n >> a;
    cout << n*n -a << endl;
}

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

int main()
{
	int N, A;
	cin >> N >> A;
	int temp = N / 500;
	int ans = 500 * temp;
	int ans2 = N - ans;
	if (ans2 <= A)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
infty = 10**21
white = 0
gray = 1
black = 2
n = input()
m = [[infty for i in xrange(n)] for j in xrange(n)]
l = [[0 for i in xrange(n)] for j in xrange(n)]
d = [0 for i in xrange(n)]
color = [0 for i in xrange(n)]
def dijkstra():
    
    

    for i in xrange(n):
        d[i] = infty
        color[i] = white


    d[0] = 0
    color[0] = gray
    while True:
        minv = infty
        u = -1
        for i in xrange(n):
            if minv > d[i] and color[i] != black:
                u = i
                minv = d[i]
        if u == -1:
            break
        color[u] = black
        for v in xrange(n):
            if color[v] != black and m[u][v] != infty:
                if d[v] > d[u] + m[u][v]:
                    d[v] = d[u] + m[u][v]
                    color[v] = gray

    for i in xrange(n):
        if d[i] == infty:
            print i,-1
        else:
            print i,d[i]



for i in xrange(n):
    l[i] = map(int,raw_input().split())
    u = l[i][0]
    k = l[i][1]
    for j in xrange(2,k*2+2,2):
        v = l[i][j]
        c = l[i][j+1]
        m[u][v] = c

dijkstra()

Measured memory_bytes: 6672
#include <iostream>
#include <vector>

int main()
{
	std::string S;
	std::vector<std::string> D 
		= { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };
	int ans = 0;

	std::cin >> S;
	for (int i = 0; i < D.size(); i++)
	{
		if (S == D[i]) ans = D.size() - i;
	}

	std::cout << ans << std::endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#define N 200010
#define mem(x, a) memset(x, a, sizeof x)
#define fo(x, a, b) for (int x = (a); x <= (b); x++)
#define fd(x, a, b) for (int x = (a); x >= (b); x--)
using namespace std;
int n, a[N], b[N], z[N][2];

inline int read() {
	int x = 0, f = 0; char c = getchar();
	while (c < '0' || c > '9') f = (c == '-') ? 1 : f, c = getchar();
	while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
	return f ? -x : x;
}

void jinwei(int x, int mid) {
	while (b[x] == mid) b[x] = 1, x--;
	b[x]++;
}

bool check(int mid) {
	z[1][0] = a[1], z[1][1] = 1;
	int top = 1;
	fo(i, 2, n) {
		if (a[i] > a[i - 1]) {
			z[++top][0] = a[i], z[top][1] = 1;
			continue;
		}
		while (z[top][0] > a[i]) top--;
		if (z[top][0] == a[i] && top > 0) z[top][1]++;
		else z[++top][0] = a[i], z[top][1] = 2;
		while (z[top][1] > mid && z[top][0] != 0) {
			if (top > 1 && z[top - 1][0] == z[top][0] - 1) z[top - 1][1]++, top--;
			else z[top][0]--, z[top][1] = 2;
		}
		if (z[1][0] == 0) return 0;
	}
	return 1;
}

int main()
{
	n = read();
	fo(i, 1, n) a[i] = read();
	check(2);
	int l = 1, r = n, mid;
	while (l <= r) {
		mid = (l + r) >> 1;
		if (check(mid)) r = mid - 1;
		else l = mid + 1;
	}
	printf("%d\n", r + 1);
	return 0;
}


Measured memory_bytes: 3792
s=input()
t=int(s[0:2])
u=int(s[2:4])
if t==0:
    if u==0:
        print("NA")
    elif u<13:
        print("YYMM")
    else:
        print("NA")
elif u==0:
    if t<13:
        print("MMYY")
    else:
        print("NA")
elif t<13:
    if u<13:
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if u<13:
        print("YYMM")
    else:
        print("NA")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define inf (ll)1e9
#define mod (ll)(1e9+7)
#define d(x) cerr<<#x<<"="<<x<<endl;
#define p(x) cout<<x<<endl
#define pfix(d,x) cout << fixed << setprecision(d) << x << endl;
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define minel(v) *min_element(all(v))
#define minind(v) distance((v).begin(), min_element(all(v)))
#define maxel(v) *max_element(all(v))
#define maxind(v) distance((v).begin(), max_element(all(v)))
typedef vector<int> vi;

ll gcd(ll a, ll b)
{
    if (a < b) {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    return b ? gcd(b, a % b) : a;
}

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

ll a,b,c,d;

ll solve(ll x){
    return x-x/c-x/d+x/lcm(c,d);
}

int main(void){
    cin>>a>>b>>c>>d;
    d(solve(b))
    d(solve(a-1))
    p((solve(b)-solve(a-1)));
    return 0;
}


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

const long long mod = 1e9 + 7;

#define pb push_back

typedef pair <int,int> pii;


int main() {
    //freopen("in.txt","r",stdin);
    long long n, m, ans = 0;
	cin >> n >> m;
	ans = min(n,m/2);
	n -= ans;
	m -= ans*2;
	if (m >= 4) {
        ans += m/4;
	}
    cout << ans;
	return 0;
}


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

using namespace std;

typedef long long ll;

int main(){
  ll K;
  cin >> K;
  ll sum = 0;
  ll i,j,k;
  for(i=1;i<=K;i++)
    for(j=1;j<=K;j++)
      for(k=1;k<=K;k++)
        sum += __gcd(i,__gcd(j,k));
  cout << sum << endl;
}

Measured memory_bytes: 3640
N, M = map(int,input().split())

WA = [0] * N
AC = [0] * N
ac = 0
wa = 0

for i in range(M):
  pi, S = map(str,input().split())
  p = int(pi)
  
  if S == "AC":
    if AC[p-1] != 1:
      AC[p-1] = 1
      ac += 1
      wa += WA[p-1]
  elif S == "WA":
    if AC[p-1] == 1:
      pass
    else:
      WA[p-1] += 1
else:
  print(ac, wa)

Measured memory_bytes: 4596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll oo=1e18;
struct data{
	ll x,y;
}b[200005];
bool cmp(data a,data c) { return a.x<c.x; }//按照x排序 
ll ans=oo,n;
ll max1,max2;
ll min1=oo,min2=oo;//1为较小的，2为较大的
int main(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld%lld",&b[i].x,&b[i].y);
		if(b[i].x>b[i].y) swap(b[i].x,b[i].y);//保证x较小 
		max1=max(b[i].x,max1);	max2=max(b[i].y,max2);
		min1=min(b[i].x,min1);	min2=min(b[i].y,min2);
	}
	ans=(max1-min1)*(max2-min2);
	sort(b+1,b+n+1,cmp);
	ll big=max(b[1].y,b[n].x),sma=min(b[1].y,b[2].x);//维护另一序列中的最大最小值 
	ll tmp=big-sma;sma=b[1].y;
	for(int i=2;i<n;i++){
		big=max(big,b[i].y);
		sma=min(sma,b[i].y);
		tmp=min(tmp,big-min(sma,b[i+1].x));
	}
	ans=min(ans,tmp*(max2-min1));//已将最大值和最小值挤在一坨 
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3328
n, k = map(int, input().split())

a = list(map(int, input().split()))

dp = [''] * (k + 1)

for i in range(a[0]):
    dp[i] = 'Second'

for x in a:
    dp[x] = 'First'

for i in range(1, k + 1):
    if dp[i] != '':
        continue

    dp[i] = 'Second'
    for x in a:
        if x > i:
            continue
        if dp[i-x] == 'Second':
            dp[i] = 'First'
            break

print(dp[-1])


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

using namespace std;

vector <int> V[200000];

int c[200000],d[200000],g[200000];
int i,j,m,n,r;
long long s,t;

int main()
{
	scanf("%d%d",&n,&m);
	for (i=1;i<=n;i++)
		scanf("%d",&g[i]);
	for (i=1;i<=n;i++)
		V[g[i]].push_back(i);
	for (i=1;i<n;i++)
	{
		if (g[i]<g[i+1])
			t=t+g[i+1]-g[i];
		if (g[i]>g[i+1])
			t=t+g[i+1],r++;
	}
	s=1e15;
	for (i=1;i<=m;i++)
	{
		s=min(s,t);
		for (j=0;j<V[i].size();j++)
		{
			if (V[i][j]>1)
			{
				if (g[V[i][j]-1]<g[V[i][j]])
					t=t-g[V[i][j]]+g[V[i][j]-1];
				if (g[V[i][j]-1]>g[V[i][j]])
					t=t-g[V[i][j]]+i-1,r--;
			}
			if (V[i][j]<n)
			{
				if (g[V[i][j]]<g[V[i][j]+1])
					t=t-g[V[i][j]+1]+g[V[i][j]];
				if (g[V[i][j]]>g[V[i][j]+1])
					t=t-g[V[i][j]+1]+i-1,r--;
			}
		}
		t=t-r;
		for (j=0;j<V[i].size();j++)
			g[V[i][j]]=m+i;
		for (j=0;j<V[i].size();j++)
		{
			if (V[i][j]>1)
				if (g[V[i][j]-1]<g[V[i][j]])
					t=t+g[V[i][j]]-g[V[i][j]-1];
			if (V[i][j]<n)
				if (g[V[i][j]]>g[V[i][j]+1])
					t=t+g[V[i][j]+1]-i,r++;
		}
	}
	printf("%lld",s);
	return 0;
}

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

using namespace std;

#define ll long long
#define F first
#define S second
#define ii pair < int , int >

const int N=20;
map<string , int > mp;
int main()
{   char a[N],b[N];
string s;
    scanf("%s",a);
    scanf("%s",b);
    int x,y;
    scanf("%d%d",&x,&y);
    s=a;
    mp[s]=x;
    s=b;
    mp[s]=y;
    char z[N];
    scanf("%s",z);
    s=z;
    mp[z]--;
    s=a;
    string q=b;
    printf("%d %d",mp[s],mp[q]);
}


Measured memory_bytes: 3760
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int w,h,n,x1[1005],x2[1005],y1[1005],y2[1005],fx[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
int map[2005][2005];
struct node{
	int x,y;
	node(int xx,int yy)
	{
		x=xx,y=yy;
	}
};
queue<node>q;
void imos(){
	memset(map, 0, sizeof(map));
	for(int i=1;i<=n;i++)
	{
		map[x1[i]][y1[i]]++;
		map[x1[i]][y2[i]]--;
		map[x2[i]][y1[i]]--;
		map[x2[i]][y2[i]]++;
	}
	for(int i=0;i<w;i++)
	{
		for(int j=1;j<h;j++)
		{
			map[i][j]=map[i][j]+map[i][j-1];
			//printf("%2d",map[i][j]);
		}
		//printf("\n");
	}
	for(int j=0;j<h;j++)
	{
		//printf("%2d",map[0][j]);
		for(int i=1;i<w;i++)
		{
			map[i][j]=map[i][j]+map[i-1][j];
			//printf("%2d",map[i][j]);
		}
		//printf("\n");
	}
}
int compress(int *x,int *xx,int w){
	vector<int>v;
	for(int i=1;i<=n;i++)
	{
		for(int j=-1;j<=1;j++)
		{
			int jx1=x[i]+j,jx2=xx[i]+j;
			if(jx1>=0&&jx1<w)
			v.push_back(jx1);
			if(jx2>=0&&jx2<w)
			v.push_back(jx2);
		}
	}
	/*
	for(int i=0;i<int(v.size());i++)
		printf("*%d",v[i]);
	printf("#######\n");*/
	sort(v.begin(),v.end());
	/*for(int i=0;i<int(v.size());i++)
		printf("*%d",v[i]);
	printf("#######\n");*/
	v.erase(unique(v.begin(),v.end()),v.end());
	/*for(int i=0;i<int(v.size());i++)
		printf("*%d",v[i]);
	printf("#######\n");*/
	for(int i=1;i<=n;i++)
	{
		x[i]=find(v.begin(),v.end(),x[i])-v.begin();
		xx[i]=find(v.begin(),v.end(),xx[i])-v.begin();
	}
	return v.size();
}
int main()
{
	while(~scanf("%d %d",&w,&h)&&w&&h)
	{
		scanf("%d",&n);
		for(int i=1;i<=n;i++)
			scanf("%d %d %d %d",&x1[i],&y1[i],&x2[i],&y2[i]);
		w=compress(x1,x2,w);
		h=compress(y1,y2,h);
		imos();
		int ans=0;
		for(int i=0;i<w;i++)
		{
			for(int j=0;j<h;j++)
			{
				if(map[i][j]==0)
				{
					ans++;
					while(!q.empty())
						q.pop();
					q.push(node(i,j));
					while(!q.empty())
					{
						node k=q.front();
						q.pop();
						if(map[k.x][k.y]!=0)
							continue;
						map[k.x][k.y]=1;
						for(int o=0;o<4;o++)
						{
							int xx=fx[o][0]+k.x,yy=fx[o][1]+k.y;
							if(xx>=0&&yy>=0&&xx<w&&yy<h&&map[xx][yy]==0)
								q.push(node(xx,yy));
						}
					}
				}
			}
		}
		printf("%d\n",ans);
	}
}

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

typedef long long ll;
using namespace std;

int main(){
	
	int n,k;
	cin >> n;// >> k;
  k=3;
	vector< vector<int> > happ(n, vector<int>(k));
	int INF = 1<<30;
	
	for(int i=0;i<n;++i)
		for(int j=0;j<k;++j)
			cin >> happ[i][j];
			
	//dp[i][j] es la mayor felicidad del dia i con la actividad anterior j
	vector< vector<int> > dp(n, vector<int>(k,0));
	
	for(int i=0;i<k;++i){
		int maxi = 0;
		for(int j=0;j<k;j++){
			if(i!=j)
				maxi = max(maxi, happ[0][j]);
		}
		dp[0][i] = maxi;
	}
	



	for(int day=1;day<n;++day){
		for(int i=0;i<k;++i){
			for(int j=0;j<k;++j){
				if(i!=j){
					dp[day][j]=max(dp[day][j],dp[day-1][i]+happ[day][j] );
					//cout << "day " << day << " i " << i << " j " << j << " dp "  << dp[day][j] << endl;
				}
			}
		}
	}
	
	int maxi = -INF;
	for(int i=0;i<3;++i){
		maxi = max(maxi,dp[n-1][i]);
	}
	cout << maxi << endl;
	
	/*for(int i=0;i<n;++i){
		for(int j=0;j<k;j++){
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}*/
	
	
			
	
	
	return 0;
}


Measured memory_bytes: 11136
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a); i<(b);++i)
#define rep(i, n) FOR(i, 0, n)

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

// solve
int dp[2002][2002];
int sumw[4001][2003];
int sumb[4001][2003];
int atw[2001];
int atb[2001];

int main(int argc, char const* argv[])
{
  int n;
  cin >> n;
  vector<char> c;
  vector<int> a;
  rep(i, 2 * n){
    char cc;
    int x;
    cin >> cc >> x;
    c.pb(cc);
    a.pb(x);
    if(cc == 'B')atb[x] = i;
    else atw[x] = i;
  }
  rep(i, 2 * n){
    rep(j, n){
      if(i > 0)sumw[i][j] = sumw[i - 1][j];
      if(i > 0)sumb[i][j] = sumb[i - 1][j];
      if(c[i] == 'W' && a[i] > j)sumw[i][j]++;
      if(c[i] == 'B' && a[i] > j)sumb[i][j]++;
    }
  }
  rep(i, n + 1){
    rep(j, n + 1){
      if(i > 0 || j > 0)dp[i][j] = inf;
      if(i > 0)dp[i][j] = min(dp[i][j], dp[i-1][j] + sumw[atw[i]][i] + sumb[atw[i]][j]);
      if(j > 0)dp[i][j] = min(dp[i][j], dp[i][j-1] + sumw[atb[j]][i] + sumb[atb[j]][j]);
    }
  }
  cout << dp[n][n] << endl;
	return 0;
}


Measured memory_bytes: 78592
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"
#include "stack"
#include "queue"

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<vector<int> > mat;

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  vector<int>::iterator lb = lower_bound(a.begin(), a.end(), a[n - 1] / 2);
  vector<int>::iterator sub = lb - 1;
  cout << a[n - 1] << " ";
  cout << (abs(2 * *lb - a[n - 1]) < abs(2 * *sub - a[n - 1]) ? *lb : *sub) << "\n";
}

Measured memory_bytes: 640
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap};

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;

fn print(table: &Vec<Vec<char>>) {
    for i in 0..table.len() {
        for j in 0..table[i].len() {
            print!("{}", table[i][j]);
        }
        println!("");
    }
}

fn main() {
    input! {
        a: usize,
        b: usize,
    }
    const H: usize = 100;
    const W: usize = 100;
    let mut table = vec![vec!['.'; W]; H];

    let mut ac = 1;
    let mut bc = 0;
    for i in 0..H / 2 {
        for j in 0..W / 2 {
            let ii = i * 2;
            let jj = j * 2;

            if ac < a {
                table[ii + 1][jj] = '#';
                table[ii + 1][jj + 1] = '#';
                table[ii][jj + 1] = '#';
                ac += 1;
                if i == 0 && j == 0 {
                    bc += 1;
                }
            } else if bc < b {
                table[ii + 1][jj + 1] = '#';
                bc += 1;
            }
        }
    }
    println!("{} {}", H, W);
    print(&table);
}


Measured memory_bytes: 4352
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<numeric>
#include<cctype>
using namespace std;

#define Yes(a) a ? "Yes" : "No";
#define YES(a) a ? "YES" : "NO";
#define rep(i,n) for(int i=0;i<n;i++)

void sout(string* a, string* b) {
	if (*a > * b) {
		string c = *a;
		*a = *b;
		*b = c;
	}
}

int combination(int n, int k) {
	if (n > k && k > 0) {
		return (combination(n - 1, k) + combination(n - 1, k - 1));
	}
	else
		return 1;
}

int main() {
	int n, k;
	cin >> n;
	vector<pair<int, int>> a(n);
	for (int i = 0; i < n; i++) {
		a.at(i).second = i + 1;
		cin >> a.at(i).first;
	}
	sort(a.begin(), a.end());
	for (int i = 0; i < n; i++) {
		cout << a.at(i).second << ' ';
	}
	cout << endl;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
const ll MOD=1e9+7;

bool conti(ll i){
	bool p = false;
	while(i){
		if( (i&1) and p ){
			return true;
		}else{
			p = i&1;
			i /= 2;
		}
	}
	return false;
}

int main(){
	ll H , W , K;
	cin >> H >> W >> K;
	ll dp[H+1][W+1]={};
	dp[0][1] = 1;
	FOR(h,1,H+1){
		FOR(i,0, (1 << (W-1)) ){
			if(conti(i))continue;
			FOR(j,0,W-1){
				if(i&(1<<j)){
					(dp[h][j+1] += dp[h-1][j+2]) %= MOD;
					(dp[h][j+2] += dp[h-1][j+1]) %= MOD;
					j++;
 				}else{
 					(dp[h][j+1] += dp[h-1][j+1]) %= MOD;
 				}
			}
			if((i&(1<<(W-2)))==0)(dp[h][W]+=dp[h-1][W])%=MOD;
		}
	}
	cout << dp[H][K] << endl;
}

Measured memory_bytes: 256
//Wrong answer on test inf.
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define ll long long
#define inf 1000000001
#define y1 y1___
using namespace std;
char gc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
ll read(){
	char ch=gc();ll x=0;int op=1;
	for (;!isdigit(ch);ch=gc()) if (ch=='-') op=-1;
	for (;isdigit(ch);ch=gc()) x=(x<<1)+(x<<3)+ch-'0';
	return x*op;
}
#define N 200005
int n,a[N];
int main(){
	n=read();
	rep (i,1,n) a[i]=read()-i;
	sort(&a[1],&a[n+1]);
	int x=a[(n+1)/2];
	ll ans=0;
	rep (i,1,n) ans+=abs(a[i]-x);
	printf("%lld\n",ans);
	return 0;
}

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

int facctorialMethod(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

int main(){
long long int num;
float ans=0;
 cin>>num;
 vector<int> x;
 vector<int> y;
 int num_func=facctorialMethod(num);
 int times=(num-1)*(num_func/2)/(num*(num-1)/2);  
 for(int i=0;i<num;i++){
  int tmp_x,tmp_y;
  cin>>tmp_x>>tmp_y;
  x.push_back(tmp_x);
  y.push_back(tmp_y);
 }

for(int i=0;i<num;i++){
  for(int j=i+1;j<num;j++){
    ans+=sqrt(pow(x[i]-x[j],2.0)+pow(y[i]-y[j],2.0));
  }
}

cout <<setprecision(10)<<ans*times/(num_func/2)<<endl;
//それぞれの街の間は回通る⇨それぞれの距離の総和*/(n!/2)
}



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

using namespace std;

int main()
{
    string s;
    while( cin >> s ) {
        int t[10];
        transform(
            s.begin(),
            s.end(),
            t,
            []( char const c ){ return c - '0'; }
            );

        for( int i=9; i>=0; --i ) {
            for( int j=0; j<i; ++j ) {
                t[j] = ( t[j] + t[j+1] ) % 10;
            }
        }
        cout << t[0] << endl;
    }
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define P pair<int,int>
#define pb push_back
int main(){
	string s;
	cin>>s;
	string f,l;
	f=s.substr(0,2);
	l=s.substr(2,2);
	int fo=stoi(f),la=stoi(l);
	bool a=fo>12||fo==0,b=la>12||la==0;
	if(a&&b){
		cout<<"NA"<<endl;
	}else if(a){
		cout<<"YYMM"<<endl;
	}else if(b){
		cout<<"MMYY"<<endl;
	}else{
		cout<<"AMBIGUOUS"<<endl;
	}
}


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

int main(void){
    long a, b;
    cin >> a >> b;
    if(a+b==15){
        cout << '+' << endl;
    }else if(a*b==15){
        cout << '*' << endl;
    }else{
        cout << 'x' << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import sys

for line in sys.stdin:
    n,x = map(int,line.split())
    if n==0 and x==0:
        break
    _range = list(range(1,n+1))
    conb = []
    for i in _range[::-1]:
        d = x - i
        if i - 1 <= 0:
            continue
        for j in _range[:i-1][::-1]:
            d2 = d - j
            if j - 1 <= 0:
                continue
            for k in _range[:j-1][::-1]:
                if d2 - k == 0:
                    conb.append((i,j,k))

    print(len(conb))

Measured memory_bytes: 7636
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <sstream>
#include <istream>
#include <iomanip>
#include <typeinfo>
#include <stack>
#include <map>
 
using namespace std;
typedef long long int ll;


int main(){

    ll Q, H, S, D;
    cin >> Q >> H >> S >> D;
    ll N;
    cin >> N;

    vector<ll > A(4, 0);
    A[0] = D;
    A[1] = 2 * S;
    A[2] = 4 * H;
    A[3] = 8 * Q;

    vector<ll > B(3, 0);
    B[0] = S;
    B[1] = 2 * H;
    B[2] = 4 * Q;

    sort(A.begin(), A.end());
    sort(B.begin(), B.end());

    cout << (N / 2) * A[0] + (N % 2) * B[0] << endl;


} 

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
//#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
//#include <array>
#include <valarray>
#include <stdio.h>
//#include <random>
//#include <windows.h>
//#pragma comment(lib, "winmm.lib")

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;

int main() {
	int N, K, X, Y;
	cin >> N >> K >> X >> Y;
	if (N >= K) {
		cout << K*X + (N - K)*Y << endl;
	}
	else {
		cout << N*X;
	}
}

Measured memory_bytes: 384
#include <math.h>
#include <stdio.h>
#define p2(x) ((x)*(x))
#define UPDATE_H(h,expr) if(H<h){for(m=0;m<n;m++)if((expr)>p2(L[m])+1e-9)break;if(m==n)H=h;}
double X[10],Y[10],L[10],hypot_cache[10][10],PL[10][10],PX[10][10],PY[10][10];
int main(){
	int n,i,j,k,l,m;
	double H,h,px,py,pl,vx,vy,cx,cy,cl,t,d;
	for(;scanf("%d",&n),n;printf("%.6f\n",H)){
		H=-1;
		for(i=0;i<n;i++)scanf("%lf%lf%lf",X+i,Y+i,L+i);
		for(i=0;i<n;i++)for(j=i+1;j<n;j++)hypot_cache[i][j]=hypot_cache[j][i]=hypot(X[i]-X[j],Y[i]-Y[j]);
		for(i=0;i<n;i++)UPDATE_H(L[i],p2(L[i])+p2(hypot_cache[i][m])); //1D
		for(i=0;i<n;i++)for(j=i+1;j<n;j++){ //2D
			//三角形(長さL[i],L[j],hypot)に垂線を下ろす(長さpl)
			//連立方程式L[i]**2=t**2+pl**2,L[k]**2=(hypot-t)**2+pl**2の解は
			t=( p2(L[i])-p2(L[j])+p2(hypot_cache[i][j]) )/( 2*hypot_cache[i][j] );
			PL[i][j]=sqrt(p2(L[i])-p2(t));
			//座標はベクトルを伸縮させることで求まる
			PX[i][j]=X[i]+(X[j]-X[i])*t/hypot_cache[i][j];
			PY[i][j]=Y[i]+(Y[j]-Y[i])*t/hypot_cache[i][j];
			UPDATE_H(PL[i][j],p2(PL[i][j])+p2(PX[i][j]-X[m])+p2(PY[i][j]-Y[m]));
		}
		for(i=0;i<n;i++)for(j=i+1;j<n;j++){ //3D
			//http://topcoder.g.hatena.ne.jp/Mi_Sawa/20130712 ※素直にcomplex使いましょう、はい--;
			//(vx,vy)は(X[i]-X[j],Y[i]-Y[j])に直交する
			vx=Y[j]-Y[i];
			vy=X[i]-X[j];
			for(k=j+1;k<n;k++){
				//(px,py)->(X[k],Y[k])を(vx,vy)に正射影する(cx,cy)
				t=((X[k]-PX[i][j])*vx+(Y[k]-PY[i][j])*vy)/(vx*vx+vy*vy);
				cx=PX[i][j]+t*vx;
				cy=PY[i][j]+t*vy;
				cl=sqrt(p2(L[k])-p2(cx-X[k])-p2(cy-Y[k])); //(cx,cy)から(求める点)までの長さは√(L[k]**2-hypot(cx-X[k],cy-Y[k])**2)
				//(px,py),(cx,cy),(求める点)を通る平面はxy平面に対して垂直なので垂線を下ろせば良い
				d=hypot(cx-PX[i][j],cy-PY[i][j]);
				t=( p2(PL[i][j])-p2(cl)+p2(d) )/( 2*d );
				pl=sqrt(p2(PL[i][j])-p2(t));
				px=PX[i][j]+(cx-PX[i][j])*t/d;
				py=PY[i][j]+(cy-PY[i][j])*t/d;
				UPDATE_H(pl,p2(pl)+p2(px-X[m])+p2(py-Y[m]));
			}
		}
	}
return 0;}

Measured memory_bytes: 688
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    int n;
    cin >> n;
    vector<int> l(n);
    for (int i = 0; i < n; ++i) {
        cin >> l.at(i);
    }
    sort(l.begin(), l.end());
    long long ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            int a = l.at(i), b = l.at(j);
            int it = lower_bound(l.begin(), l.end(), a + b) - l.begin();
            if (it - j - 1 > 0) ans += it - j - 1; 
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
typedef long int li;
#define MOD 1000000007
int main(){
  int n; cin >> n;
  string s; cin >> s;
  int cnt=0;
  li ans=1;
  for(int i=0;i<2*n;i++){
    if(s.at(i)=='B'){
      if(cnt%2==0) cnt++;
      else{
	ans*=cnt;
	ans%=MOD;
	cnt--;
      }
    }
    else{
      if(cnt%2==1)cnt++;
      else{
	ans*=cnt;
	ans%=MOD;
	cnt--;
      }
    }
    if(ans==0)break;
  }
  if(cnt!=0)ans=0;
  for(int i=1;i<=n;i++){
    ans*=i;
    ans%=MOD;
  }
  cout << ans;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
//NOT TO SUBMIT IN WRONG PLACE OR BY WRONG COMPILER
//ABC 177, task a, 2020/08/30
//ms,
/*
*/

int main(void){
  int N, M;
  vector<vector<int>> hole(100000);
  vector<int> ans(100000, 0);
  vector<int> depth(100000, -1);
  queue<int> found;

  cin >>N >>M;
  for(int i=0;i<M;i++){
    int a, b;
    cin >>a >>b;
    a--; b--;
    hole[a].push_back(b);
    hole[b].push_back(a);
  }

  //BFS
  depth[0]=0;
  found.push(0);
  while(found.size() != 0){
    int v = found.front();
    found.pop();
    for(size_t i=0;i<hole[v].size();i++){
      int u = hole[v][i];
      if(depth[u] != -1) continue;
      depth[u] = depth[v] + 1;
      ans[u] = v;
      found.push(u);
    }
  }

  cout <<"Yes"<<endl;
  for(int i=1;i<N;i++){
    int output = ans[i]+1;
    cout <<output <<endl;
  }
  return 0;
}
/*
重みなしの連結無効グラフを考える。最短炉木を見つければよい。
BFSで行けると思う。→正解！
始点は1の点。0-indexでコードするので0の点だな。
*/


Measured memory_bytes: 10652
#prag\
ma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;

struct node{
	int x,y,t;
}q[2501];
bool a[51][51],vis[51][51];
int d[4][2]={0,1,0,-1,1,0,-1,0};
int main()
{
	ios::sync_with_stdio(false);
	int n,m,tot=0;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++){
			char c;
			cin>>c;
			if(c=='.') a[i][j]=1,tot++;
		}
	for(int ff=1;ff<=150000;ff++) {
		int xx;
		xx++;
	}
	if(!a[1][1]||!a[n][m]){
		cout<<-1;return 0;
	}
	int t=1,w=1;
	q[1].x=1,q[1].y=1,q[1].t=1;vis[1][1]=1;
	while(t<=w){
		for(int i=0;i<4;i++){
			int x=q[t].x+d[i][0],y=q[t].y+d[i][1];
			if(x>0&&x<=n&&y>0&&y<=m&&a[x][y]&&!vis[x][y]){
				++w,q[w].x=x,q[w].y=y,q[w].t=q[t].t+1;
				if(x==n&&y==m){
					cout<<tot-q[w].t;
					return 0;
				}
				vis[x][y]=1;
			}
		}
		++t;
	}
	cout<<-1;
}

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

#define N 128
#define UL 10000
#define LL -10000
#define OF(X) \
  !!( (X).re > UL || (X).re < LL \
   || (X).im > UL || (X).im < LL )

struct Complex
{
  int re;
  int im;
  int of;
};
typedef struct Complex Complex;

static const char *e;

static Complex
add (
  Complex a,
  Complex b
  )
{
  Complex res = { 0 };

  if ( a.of ) return ( a );
  if ( b.of ) return ( b );

  res.re = a.re + b.re;
  res.im = a.im + b.im;
  res.of = OF( res );

  return ( res );
}

static Complex
subtract (
  Complex a,
  Complex b
  )
{
  Complex res = { 0 };

  if ( a.of ) return ( a );
  if ( b.of ) return ( b );

  res.re = a.re - b.re;
  res.im = a.im - b.im;
  res.of = OF( res );

  return ( res );
}

static Complex
multiply (
  Complex a,
  Complex b
  )
{
  Complex res = { 0 };

  if ( a.of ) return ( a );
  if ( b.of ) return ( b );

  res.re = a.re * b.re - a.im * b.im;
  res.im = a.re * b.im + a.im * b.re;
  res.of = OF( res );

  return ( res );
}

static Complex
expression (
  void
  );

static Complex
term (
  void
  )
{
  static const Complex ie = { 0, 1, 0 };
  Complex res = { 0, 0, 0 };

  if ( isdigit ( *e ) )
  {
    while ( isdigit ( *e ) )
    {
      res.re = res.re * 10 + ( *e - '0' );
      ++e;
      res.of = OF( res );
      if ( res.of ) break ;
    }
  }
  else if ( *e == 'i' )
  {
    ++e;
    res = ie;
  }
  else if ( *e == '-' )
  {
    ++e;
    res = term ( );
    res.re = -res.re;
    res.im = -res.im;
  }
  else if ( *e == '(' )
  {
    ++e;
    res = expression ( );
    ++e;
  }

  return ( res );
}

static Complex
factor (
  void
  )
{
  Complex res = term ( );

  for ( ; ; )
  {
    switch ( *e )
    {
      case '*':
        ++e;
        res = multiply ( res, term ( ) );
        break ;
      default:
        return ( res );
    }

    if ( res.of ) return ( res );
  }
}

static Complex
expression (
  void
  )
{
  Complex res = factor ( );

  for ( ; ; )
  {
    switch ( *e )
    {
      case '+':
        ++e;
        res = add ( res, factor ( ) );
        break ;
      case '-':
        ++e;
        res = subtract ( res, factor ( ) );
        break ;
      default:
        return ( res );
    }

    if ( res.of ) return ( res );
  }
}

/** Application main entry point. */
int
main (
  int     argc,
  char  * argv[ ]
  )
{
  char s[ N ];

  while ( fgets ( s, sizeof ( s ), stdin ) != NULL )
  {
    Complex res;

    e = s;
    res = expression ( );

    if ( res.of )
    {
      puts ( "overflow" );
    }
    else if ( res.re == 0 && res.im == 0 )
    {
      puts ( "0" );
    }
    else
    {
      if ( res.re )
      {
        printf ( "%d", res.re );
      }
      if ( res.im )
      {
        if ( res.re && res.im >= 0 ) putchar ( '+' );
        printf ( "%di", res.im );
      }
      puts ( "" );
    }

  }

  return ( 0 );
}

Measured memory_bytes: 0
H,W =map(int,input().split())
if H==1 or W==1:
  print(1)
elif H%2==0:
  print(W*H//2)
else:
  if W%2==1:
    print(W*(H//2)+W//2+1)
  else:
    print(W*(H//2)+W//2)

Measured memory_bytes: 2940