akhauriyash/Code-Regression huggingface dataset:
import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = readLn >>= flip replicateM getLine >>= print . solve . map convf
    where
        convf s = (x, u)
            where
                x = read xs
                [xs, u] = words s

solve :: [(Double, String)] -> Double
solve = sum . map convf
    where
        convf (x, "BTC") = x * 380000
        convf (x, _) = x 

readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
long long n, i, res=0, a[300010];
int main(){
	cin>>n;
	for(i=0; i<3*n; i++)
		cin>>a[i];
	sort(a, a+3*n, greater<int>());
	for(i=1; i<2*n+1; i+=2)
		res+=a[i];
	cout<<res;
	return 0;
}

Measured memory_bytes: 2560
# -*- coding: utf-8 -*-
x, y = map(int, input().split())
ans = 0
if x == y:
    print(ans)

elif x > 0 and y > 0:
    if x < y:
        ans = y - x
        print(ans)
    
    else:
        ans = x - y + 2
        print(ans)
    
elif x < 0 and y < 0:
    if x <= y:
        ans = abs(x) - abs(y)
        print(ans)
    
    else:
        ans = abs(y) - abs(x) + 2
        print(ans)

elif x > 0 and y < 0:
    if x <= abs(y):
        ans = abs(y) - x + 1
        print(ans)
    else:
        ans = x - abs(y) + 1
        print(ans)
    
elif x < 0 and y > 0:
    if abs(x) <= y:
        ans = y - abs(x) + 1
        print(ans)
    else:
        ans = abs(x) - y + 1
        print(ans)
    
elif x == 0 and y != 0:
    if y > 0:
        ans = y
        print(ans)
    else:
        ans = abs(y) + 1
        print(ans)
    
elif x != 0 and y == 0:
    if x > 0:
        ans = x + 1
        print(ans)
    else:
        ans = abs(x)
        print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include <algorithm>
#include <string>
using namespace std;
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(int)(n); i++)
typedef long long ll;
const int INF = numeric_limits<int>::max();
const int MOD = (1e9 + 7);

int main(){
  int N, M, a, p=0, ans=0;
  cin >> N >> M;
  int S[N] = {0};
  rep(i, M){
    int k;
    cin >> k;
    rep(j, k){
      cin >> a;
      S[a-1] |= 1<<i;
    }
  }
  rep(i, M){
    int x;
    cin >> x;
    p |= (x<<i);
  }
  rep(i, 1<<N){
    int t=0;
    rep(j, N){
      if(i>>j&1){
        t ^= S[j];
      }
    }
    if(t == p){
      ans++;
    }
  }
  cout << ans << endl;
}
    

Measured memory_bytes: 256
def main():
    see_sea = 1
    n = int(input())
    h = list(map(int, input().split()))
    mountain = h[0]
    for i in range(1, n):
        if mountain <= h[i]:
            see_sea += 1
            mountain = h[i]
    print(see_sea)


if __name__ == '__main__':
    main()


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

using namespace std;

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

    int N;
    cin >> N;
    vector<pair<int, int>> xy(N);
    for (int i = 0; i < N; ++i) {
        cin >> xy[i].first >> xy[i].second;
    }
    sort(begin(xy), end(xy));
    reverse(begin(xy), end(xy));
    int mn_cost = N + 1;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            int p = xy[i].first - xy[j].first;
            int q = xy[i].second - xy[j].second;
            int lastx = -1, lasty = -1;
            vector<int> taken(N, 0);
            int cost = 0;
            for (int i1 = 0; i1 < N; ++i1) {
                if (!taken[i1]) {
                    ++cost;
                    taken[i1] = 1;
                    lastx = xy[i1].first;
                    lasty = xy[i1].second;
                    for (int i2 = 0; i2 < N; ++i2) {
                        if (!taken[i2] && lastx + p == xy[i2].first
                            && lasty + q == xy[i2].second) {
                            taken[i2] = 1;
                            lastx = xy[i2].first;
                            lasty = xy[i2].second;
                        }
                    }
                }
            }
            mn_cost = min(mn_cost, cost);
        }
    }
    cout << mn_cost << "\n";

    return 0;
}

Measured memory_bytes: 256
///HELLO THERE~!
///CREATED BY MD SADMAN MEHEDI SIVAN(IUT CSE[SWE'19])

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

#define FASTIO          ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define READ            freopen("input.txt","r",stdin);
#define WRITE           freopen("red.txt","w",stdout);

using ll=long long;
using ull=unsigned long long;
const double pi = 2*acos(0.0);
const long long MX = 2e5+7;
int main()
{

    ll n;
    cin>>n;

    map<ll,ll>mp;

    ll count=0;

    ll a[n+1];

    for(ll i=0; i<n; i++)
    {
        cin>>a[i];
        if(mp[a[i]]==0)
        {
            mp[a[i]]++;
            count++;
        }
        else
        {
            mp[a[i]]=0;
            count--;
        }
    }

    cout<<count;
}


Measured memory_bytes: 10540
a = []
for i in range(5):
    b = int(input())
    a.append([(b+9) % 10, b])
a = sorted(a, reverse=True)
c = 0
for i in range(4):
    c += (a[i][1] + 9) // 10 * 10
print(c + a[4][1])


Measured memory_bytes: 2940
/*
    問題をよく読もう！
    論理的に考えよう！
    サンプルを確認しよう!
    絶対に諦めるな！
    工夫をしろ！

    Twitterは終わるまでログアウト！
    （間違えて解法をツイートしてはいけないから）

*/
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cctype>
using namespace std;
#define rep(i, n) for(int i=0; i<n; ++i)
typedef long long ll;
//必要な宣言

int main() {
  int N;
  cin >> N;
  cout << "ABC" <<  to_string(N) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

const int MAX = 510000;
const int MOD = 998244353;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long FINV(int n){
    if (n < 0) return 0;
    return finv[n];
}

ll mod_pow(ll x, ll n, ll mod){ // x ^ n % mod
    ll res = 1;
    while(n > 0){
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    COMinit();
    ll n, m, k;
    cin >> n >> m >> k;
    ll MOD = 998244353;

    ll ans = 0;

    rep(i,k+1){
        ans += COM(n-1,i) * m % MOD * mod_pow(m-1,n-i-1,MOD) % MOD;
        ans %= MOD;
    }

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




Measured memory_bytes: 15592
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define ll unsigned long long
using namespace std;
int main(){
    ll N;cin>>N;
    map<ll,ll> A;
    map<ll,ll> B;
    REP(i,N){
        ll k;cin>>k;
        A[k]++;
    }
    ll ans=0;
    B=A;
    for(auto itr=A.begin();itr!=A.end();++itr) {
        ll index=itr->first;
        ans=max(ans,B[index]+B[index-1]+B[index+1]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 10112
///-----Bismillahir Rahmanir Rahim-----///

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

///---FAST I/O---///
#define Boost() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

///---DATA TYPE---///
typedef long long ll;



int main()
{
    Boost();

    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        ll n,ans=0;
        cin>>n;
        for(ll i=1;i<=n;i++)
        {
            ll cntMultipleOfiLessThanN=floor((n*1.0)/(i*1.0));
            ll tmp=(cntMultipleOfiLessThanN*(cntMultipleOfiLessThanN+1)*i);
            ans+=(tmp/2);
        }
        cout<<ans<<endl;

    }
    return 0;
}

///---hints:----///
/*
For a positive integer j, we define g(j) as the sum of multiples of j that does not exceed N.
Find sum[g(j);j=1...N],This g(X) is a sum of an arithmetic progression,and can be calculated faster than f(X).
Specifically, let Y=floor(N/X)(the maximum integer that does not exceed N/X), then g(X)=X+2X+...+YX=(1+2+...+Y)X=Y(Y+ 1)X/2,
so by using this formula, the problem can be solved in a total of O(N) time.
*/



Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    string s;
    cin >> n >> s;
    int x = 0;
    int ans = 0;
    for(int i = 0; i < n; i++){
        if(s[i]=='I')x++;
        if(s[i]=='D')x--;
        ans = max(ans,x);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <algorithm>
using i64 = long long;

int main() {
    int n, m;
    i64 k;
    std::cin >> n >> m >> k;
    std::vector<i64> a(n), b(m);
    for (auto &e : a) std::cin >> e;
    for (auto &e : b) std::cin >> e;

    for (int i = 1; i < n; i++) a[i] += a[i - 1];
    for (int i = 1; i < m; i++) b[i] += b[i - 1];

    int ret = std::upper_bound(b.begin(), b.end(), k) - b.begin();
    for (int i = 0; i < n; i++) {
        if (a[i] > k) break;
        const i64 rem = k - a[i];
        const int c = i + 1 + (std::upper_bound(b.begin(), b.end(), rem) - b.begin());
        if (ret < c) ret = c;
    }

    std::cout << ret << std::endl;

    return 0;
}


Measured memory_bytes: 6432
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define PB push_back
#define SP << " " <<

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VLL;

__attribute__((constructor))
void initial(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed <<setprecision(15);
}


int main(void){
	ll N, K, S;
    cin >> N >> K >> S;
    ll a = 1000000000;
    if(S == a){
        a = 1;
    }
    rep(i,N){
        if(i<K){
            cout << S << " ";
        }else{
            cout << a << " ";
        }
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 1280
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    long N=sc.nextLong(), D=sc.nextLong(), t=0, a,b,d;
    D*=D;
    for(int i=0; i<N; i++){
      a=sc.nextLong();
      b=sc.nextLong();
      d = a*a +b*b;
      if(d<=D) t++;
    }
    System.out.println(t);
  }
}

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

public class Main {

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

    int n = sc.nextInt();
    int m = sc.nextInt();
    int x = sc.nextInt();
    int[] c = new int[n];
    int[][] a = new int[n][m];

    for (int i = 0; i < n; i++) {
      c[i] = sc.nextInt();
      for (int j = 0; j < m; j++) {
        a[i][j] = sc.nextInt();
      }
    }

    long ans = Long.MAX_VALUE;

    for (int i = 0; i < Math.pow(2,n); i++) {
      boolean ok = true;
      long res = 0;
      for (int k = 0; k < m; k++) {
        long sum = 0;
        for (int j = 0; j < n; j++) {
          if ((1&i >> j) == 1) {
            res += c[j];
            sum += a[j][k];
          }
          // System.out.println(sum);
        }
        if (sum < x) {
          ok = false;
        }
        // System.out.println();
      }
      // System.out.println(res/m);
      if (ok) {
        ans = Math.min(ans,res/m);
      }
    }

    if (ans == Long.MAX_VALUE) {
      System.out.println(-1);
    } else {
      System.out.println(ans);
    }

  }

}


Measured memory_bytes: 36688
// E.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long LL;

int main(int argc, char* argv[]) {
	string s, t;
	cin >> s >> t;
	int n = (int)s.length();
	vector<vector<int>> next_pos(n);
	vector<int> last(26);
	for (int i = 0; i < 26; ++i) {
		last[i] = s.find('a' + i);
	}
	for (int i = n - 1; i >= 0; --i) {
		next_pos[i] = last;
		last[s[i] - 'a'] = i;
	}
	LL pos = 0;
	for (char c : t) {
		LL curr = pos % n;
		if (c != s[curr]) {
			LL next = next_pos[curr][c - 'a'];
			if (next < 0) {
				pos = -1;
				break;
			}
			pos += (next + n - curr) % n;
		}
		++pos;
	}
	cout << pos << endl;
	return 0;
}


Measured memory_bytes: 13696
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <vector>
#include <iomanip>

using namespace std;
typedef long long ll;

int main(){
    int n;
    int P, Q;
    int order = 0;
    cin >> n;
    vector<int> a(n), p(n), q(n);
    for (int i = 0; i < n; i++) {
        a[i] = i+1;
        cin >> p[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> q[i];
    }
    do {
        int pcnt = 0, qcnt = 0;
        order++;
        for (int i = 0; i < n; i++) {
            if (a[i] == p[i]) {pcnt++;}
            if (a[i] == q[i]) {qcnt++;}
        }
        if (pcnt == n) {P = order;}
        if (qcnt == n) {Q = order;}
    } while (next_permutation(a.begin(), a.end()));

    cout << abs(P - Q);

    return 0;
}

Measured memory_bytes: 384
S=input()
F = S[:2]
B = S[2:]
 
F_m = 0<int(F)<13
F_y = 0<=int(F)<100
B_m = 0<int(B)<13
B_y = 0<=int(B)<100
YM = F_y + B_m
MY = B_y + F_m
if YM==2 & MY==2:
    print("AMBIGUOUS")
elif YM==2:
    print('YYMM')
elif MY==2:
    print('MMYY')
else:
    print('NA')

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

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
const int maxn = 1e5 + 5;
bool dif[maxn];
ii a[maxn];
vector<ii> adj[maxn];
int n, m;
vector<int> res;
bool vis[maxn];
void dfs(int u){
    vis[u] = 1;
    for(auto c : adj[u]){
        if(vis[c.first] == 0){
            dfs(c.first);
            if(dif[c.first]){
                res.pb(c.second);
                dif[c.first] = 0;
                dif[u] ^= 1;
            }
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    cin >> n >> m;
    for(int i = 0 ; i < n ; ++i)cin >> a[i].first >> a[i].second;
    sort(a,a+n);
    for(int i = 1 ; i <= m ; ++i){
        int l , r;cin >> l >> r;
        l = lower_bound(a,a+n,mp(l,0))-a;
        r = lower_bound(a,a+n,mp(r+1,-1))-a;
        adj[l].pb(mp(r,i));
        adj[r].pb(mp(l,i));
    }
    for(int i = 0 ; i < n ; ++i){
        if(a[i].second)dif[i] ^= 1 , dif[i + 1] ^= 1;
    }
    for(int i = 0 ; i <= n ; ++i){
        if(vis[i] == 0){
            dfs(i);
        }
        if(dif[i]){
            return cout << -1 , 0;
        }
    }
    cout << res.size() << '\n';sort(res.begin(),res.end());
    for(int c : res)cout << c << " ";
}


Measured memory_bytes: 13820
N = int(input())

AB = []

for _ in range(N):
    AB.append(tuple(map(int, input().split())))



AB.sort(key=lambda x:x[1])

on_time = True

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

    time += a

    if time > b:
        on_time = False

if on_time:
    print('Yes')
else:
    print('No')

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

int main(){
  int N, flag=0;
  cin >> N;
  long long int a[N];
  for(int i=0; i<N; i++){
    cin >> a[i];
    if(flag == 0){
      if(a[i] % 2 == 1) flag = 1;
    }
  }
  if(flag == 1) cout << "first\n";
  else cout << "second\n" << "\n";
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
  
int main() {
  int N,M;
  cin >> N >> M;
  
  vector<long long>A(N);
  vector<long long>B(N*35);
  long long sum = 0;
  int L = 0;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    sum += A.at(i);
    for (int j = 0; j < 35; j++) {
      B.at(L) = A.at(i);
      L++;
      A.at(i) /= 2;
      if (A.at(i) == 0){
        break;
      }
    }
  }
  sort(B.begin(), B.end());
  reverse(B.begin(), B.end());
  
  long long ans = sum;
  for (int i = 0; i < min(M,(N*35)); i++) {
    ans -= (B.at(i)+1)/2;
  }
  cout << ans << endl;
}
   

Measured memory_bytes: 31404
#include<bits/stdc++.h>
#define ll long long int
#define F first
#define S second
#define pb push_back
#define sd(x) scanf("%d",&x)
#define sd2(x,y) scanf("%d%d",&x,&y);
#define sdl(x) scanf("%lld",&x)
#define sd2l(x,y) scanf("%lld%lld",&x,&y);
#define sz(x) (int)(x.size())
#define nax 200010
#define inf 1001000100
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 1000000007
#define mp make_pair
#define pc pair<char ,int>
#define pi pair<int ,int>
#define pii pair <int,pi>
using namespace std;
int bits[50];
void add(ll x)
{
   int ctr = 0;
   while(x)
   {
      bits[ctr++] += x%2;
      x/=2;
   }
}
int main(int argc, char const *argv[])
{
  //freopen("input.txt","r",stdin);
  //freopen("output.txt","w",stdout);
  ll n,k,x;
  fastio
  cin >> n >> k;
  for(int i = 1; i <= n; i++)
  {
     cin >> x;
     add(x);
  }
  ll fans =  0;
  ll cans = 0;
  for(int i = 45; i >= 0; i--)
  {
      int have = bits[i];
      int rem = n - have;
      if(have >= rem) // chill
        fans += have * 1ll * (1ll <<  i);
      else
      {
          ll add = (1ll << i);
          if(cans + add <= k)
          {
             fans += rem * 1ll * add;
             cans += add;
          }
          else
              fans += have * 1ll * add;
      }
  }
  cout << fans << '\n';
  return 0; 
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	string _; cin >> _;
	deque<char> s;
	for(char c : _) {
		s.push_back(c);
	}
	int q; cin >> q;
	bool front = true;
	while(q--) {
		int i; cin >> i;
		if(i == 1) {
			front ^= true;
		}
		if(i == 2) {
			int f;
			char c; cin >> f >> c;
			if(front) {
				if(f == 1) {
					s.push_front(c);
				} else {
					s.push_back(c);
				}
			} else {
				if(f == 1) {
					s.push_back(c);
				} else {
					s.push_front(c);
				}
			}
		}
	}
	if(front) {
		for(auto itr = s.begin(); itr != s.end(); ++itr) {
			cout << *itr;
		}
	} else {
		for(auto itr = s.rbegin(); itr != s.rend(); ++itr) {
			cout << *itr;
		}
	}
	cout << '\n';
	return 0;
}

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

class point{
public:
	double x;
	double y;
	point(double px, double py){
		x = px;
		y = py;
	}
};

double cross(point a, point b, point c, point d){
	return (b.x - a.x) * (d.y - c.y) - (b.y - a.y) * (d.x - c.x);
}

bool pn(double a){
	if (a > 0)
		return true;
	else
		return false;
}

int main()
{
	double x1, y1, x2, y2, x3, y3, xp, yp;
	while (cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp){
		point a = point(x1, y1);
		point b = point(x2, y2);
		point c = point(x3, y3);
		point p = point(xp, yp);
		if ((pn(cross(p, a, b, a)) && pn(cross(p, b, c, b)) && pn(cross(p, c, a, c))) ||
			(pn(cross(p, a, b, a) * (-1)) && pn(cross(p, b, c, b) * (-1)) && pn(cross(p, c, a, c) * (-1)))){
			cout << "YES" << endl;
		}
		else{
			cout << "NO" << endl;
		}

	}
	return 0;
}

Measured memory_bytes: 1224
#include<iostream>
#include<string>
typedef long long ll;
using namespace std;

int main(){
    string s;
    cin >> s;
    int sum=0;
    int tmp=1;
    int X=0;
    int len = s.length();
    for(int i=len-1; i>=0; i--){
        sum+=s[i]-'0';
        X += (s[i]-'0')*tmp;
        tmp=tmp*10;
    }

    if(X%sum==0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip>
#include <fstream>
#include <map>
#include <cassert>
#include <sstream>
#include <numeric>
#include <regex>
#include <cctype>
#include <utility>
#include <stdio.h>

typedef long long ll;

#define nums vector<int>
#define words vector<string>
#define letrs vector<char>
#define MOD 1000000007
#define pb push_back
#define llnums vector<ll>
#define FOR(i,n) for(int i{0}; i < n; ++i)

using namespace std;

int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int x, n;
  cin >> x >> n;
  if (n == 0) {
      cout << x << '\n';
      return 0;
  }
  vector<int> numbers;
  int z;
  FOR(i, n) {
      cin >> z;
      numbers.push_back(z);
  }
  sort(numbers.begin(), numbers.end());
  if (find(numbers.begin(), numbers.end(), x) == numbers.end()) {
      cout << x << '\n';
      return 0;
  } int ans = 0;
  for (int i{x+1}; i > x; ++i) {
      if (find(numbers.begin(), numbers.end(), i) == numbers.end()) {
          ans = i;
          break;
      }
  }
  for (int i{x-1}; i < x; --i) {
      if (find(numbers.begin(), numbers.end(), i) == numbers.end()) {
          if (abs(i-x) <= abs(ans-x)) {
              ans = i;
          }
          break;
      }
  }
  cout << ans << '\n';
  return 0;
}









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

using namespace std;
using ll = long long;

int N;
vector<vector<vector<double> > > dp;

double rec(int i, int j, int k) {
  if (dp[i][j][k] >= 0) {
    return dp[i][j][k];
  }
  if (i == 0 && j == 0 && k == 0) {
    return 0.0;
  }
  double res = 0.0;
  if (i > 0) {
    res += rec(i - 1, j, k) * i;
  }
  if (j > 0) {
    res += rec(i + 1, j - 1, k) * j;
  }
  if (k > 0) {
    res += rec(i, j + 1, k - 1) * k;
  }
  res += N;
  res *= 1.0 / (i + j + k);

  return dp[i][j][k] = res;
}

int main() {
  cin >> N;
  dp.assign(N + 1, vector<vector<double> >(N + 1, vector<double>(N + 1, -1)));
  int c1 = 0, c2 = 0, c3 = 0;
  rep(i, N) {
    int a;
    cin >> a;
    if (a == 1) {
      c1++;
    } else if (a == 2) {
      c2++;
    } else {
      c3++;
    }
  }
  printf("%.10f\n", rec(c1, c2, c3));
  return 0;
}

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

const int N = 2e5 + 9, P = 1e9 + 7;

map<int, vector<int>>T;
unordered_map<int, int>e[N];
int n, x, y, a[N], b[N], f[N], fac[N], fac_rev[N];

bool cmp1 (int x, int y) { return b[x] < b[y]; }

bool cmp2 (int x, int y) { return a[x] < a[y]; }

int find (int x) { return x == f[x] ? x : f[x] = find(f[x]); }

void Merge (int x, int y) { f[find(x)] = find(y); }

int qp (int a, int b) { int c = 1; for (; b; b >>= 1, a = 1ll * a * a % P) if (b & 1) c = 1ll * c * a % P; return c; }

int mi1, mi2;

int main () {
	scanf("%d%d%d", &n, &x, &y);
	for (int i = 1; i <= n; ++i) {
		f[i] = i;
		scanf("%d%d", &a[i], &b[i]);
		if (!mi1 || b[i] < b[mi1]) mi1 = i;
		T[a[i]].emplace_back(i);
	}
	for (int i = 1; i <= n; ++i) if (a[i] != a[mi1]) if (!mi2 || b[i] < b[mi2]) mi2 = i;
	for (auto &v : T) {
		sort(v.second.begin(), v.second.end(), cmp1);
		vector<int>&p = v.second;
		int lim = x - b[p[0]];
		for (int i = p.size() - 1; i; --i) if (b[p[i]] <= lim) Merge(p[i], p[i - 1]);
	}
	for (int i = 1; i <= n; ++i) if (a[i] != a[mi1] && b[i] + b[mi1] <= y) Merge(i, mi1);
	for (int i = 1; i <= n; ++i) if (a[i] != a[mi2] && b[i] + b[mi2] <= y) Merge(i, mi2);
	fac[0] = 1; for (int i = 1; i <= n; ++i) fac[i] = 1ll * fac[i - 1] * i % P;
	fac_rev[n] = qp(fac[n], P - 2);
	for (int i = n - 1; ~i; --i) fac_rev[i] = 1ll * fac_rev[i + 1] * (i + 1) % P;
	for (int i = 1; i <= n; ++i) ++e[find(i)][a[i]];
	int ans = 1; for (int i = 1; i <= n; ++i) if (i == find(i)) {
		int j = 0;
		for (auto v : e[i]) ans = 1ll * ans * fac_rev[v.second] % P, j += v.second;
		ans = 1ll * ans * fac[j] % P;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 41984
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();

    int min = N;
    for (int A = 0; A <= N; A++) {
      int x = 0;

      int i = A;
      int j = 6;
      while (i >= j) {
        int k = (i / j) % 6;
        i -= j * k;
        x += k;
        j *= 6;
      }

      i = (N - A) + i;
      j = 9;
      while (i >= j) {
        int k = (i / j) % 9;
        i -= j * k;
        x += k;
        j *= 9;
      }
      x += i;
      if (min > x) {
        min = x;
      }
    }
    System.out.println(min);
  }
}


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

const int block = 4;
const int floor = 3;
const int room = 10;

int main() {
  int n, m;
  cin >> n >> m;
  int A[n][m];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> A[i][j];
    }
  }
  int b[m];
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }

  for (int i = 0; i < n; i++) {
    int c = 0;
    for (int j = 0; j < m; j++) {
      c += A[i][j] * b[j];
    }
    cout << c << endl;
  }
  return 0;
}

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

int main(void){
    int n;
    cin>>n;
    bool x=false;
    rep(i,n){
        int a;
        cin>>a;
        if(a%2==0&&a%3!=0&&a%5!=0){
            cout<<"DENIED"<<endl;
            x=true;
            break;
        }
    }
    if(x==false) cout<<"APPROVED"<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  int A[100],N,i,j,minj,temp,count=0;
  scanf("%d",&N);
  for(i=0;i<N;i++){scanf("%d",&A[i]);}
   
  for(i=0;i<N;i++)
    {
      minj=i;
      for(j=i;j<N;j++){
    if(A[minj]>A[j]){minj=j;}
    }
      if(i!=minj){
      temp=A[i];
      A[i]=A[minj];
      A[minj]=temp;
      count++;
      }
    }
  for(i=0;i<N;i++){printf("%d",A[i]);
      if(i!=(N-1)){printf(" ");}
      }
  printf("\n%d\n",count);
  return 0;
}

Measured memory_bytes: 604
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (size_t i = 0; i < size_t(n); i++)
#define forn1(i,n) for (size_t i = 1; i <= size_t(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

int n, m;
vec<pii> g[50];
ll dp[1 << 20];
int co[50 - 1];

bool find_path(int u, int v, int c, int p) {
    if (u == v) {
        return true;
    }

    for (auto e : g[u]) {
        int x, i;
        tie(x, i) = e;
        if (x == p) continue;
        if (find_path(x, v, c, u)) {
            co[i] |= 1 << c;
            return true;
        }
    }

    return false;
}

int main() {
    fastio();

    cin >> n;
    forn(i, n - 1) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        g[a].emplace_back(b, i);
        g[b].emplace_back(a, i);
    }

    cin >> m;
    forn(i, m) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        find_path(u, v, i, -1);
    }

    vl dp(1 << m, 0);
    dp[0] = 1;
    for (int i = 0; i < n - 1; i++) {
        vl temp = dp;
        forn(j, 1 << m) {
            temp[j | co[i]] += dp[j];
        }
        dp = temp;
    }

    cout << dp[(1 << m) - 1] << endl;

    return 0;
}

Measured memory_bytes: 16640
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

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

    int h, w, d;
    cin >> h >> w >> d;
    map<int, P> mp;
    rep(i, h) rep(j, w) {
        int a;
        cin >> a;
        mp[a] = P(i, j);
    }
    vector<int> dist(h*w+1);
    auto f = [](P a, P b){ return abs(a.fi - b.fi) + abs(a.se - b.se);};
    for (int i = h*w; i >= 1; --i) {
        if (i + d > h * w) continue;
        dist[i] = dist[i+d] + f(mp[i], mp[i+d]);
    }
    int q;
    cin >> q;
    while (q--) {
        int a, b;
        cin >> a >> b;
        cout << dist[a] - dist[b] << endl;
    }
}


Measured memory_bytes: 7168
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
signed main(){
  int N,M; cin>>N>>M;
  vector<pii> A(N);
  rep(i,0,N) cin>>A[i].first>>A[i].second;
  int ans=0;
  sort(ALL(A));
  int memo=0;
  priq B;
  vi C(N),D(N);
  rep(i,0,N){
    C[i]=A[i].first;
    D[i]=A[i].second;
    }
  C.push_back(MOD);
  REP(i,1,M){
    rep(j,dislow(C,i),disup(C,i)){
      B.push(D[j]);
      }
    if(B.size()>0){
      ans+=B.top();
      B.pop();
      }
    }
  cout<<ans<<endl;
  }


Measured memory_bytes: 5232
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//#define int long long


int main() {
  int a,b,c,d;
  cin >> a>>b>>c>>d;

  cout << max(a*b, c*d) << endl;
      
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#define che
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define MK make_pair
#define PB push_back
#define fi first
#define se second

typedef long long LL;
typedef pair<int, int> PII;
const int N=2e5+10 ;

vector<int> g[N];
int down[N], dia=0, n;
void dfs(int u, int fa){
	for ( auto v : g[u])if ( v!=fa){
		dfs(v, u);
		dia=max(dia, down[u]+down[v]+1);
		down[u]=max(down[u], down[v]+1);
	}
}
int main(){
	#ifdef che
	freopen("input.txt","rt",stdin);
	freopen("output.txt","wt",stdout);
	#endif
	scanf("%d", &n);
	for (int i=1, u,v ;i<n; ++i){
		scanf("%d%d", &u, &v);
		g[u].PB(v); g[v].PB(u);	
	}
	dfs(1, -1);
	++dia;
	puts(dia%3==2 ? "Second":"First");
	return 0;
}

Measured memory_bytes: 23936
import java.util.*;
//mport java.io.*;


public class Main{

    static int INFTY = Integer.MAX_VALUE;
    static long num=1000000007;
    public static void main (String args[]){
        //初期処理
        Scanner sc=new Scanner(System.in);
        // BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        // try{
            // int n = Integer.parseInt(br.readLine());
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] a = new int[m];
        for (int i=0;i<m;i++){
            a[i] = sc.nextInt();
            if(i==0){continue;}
        //2連続で壊れてたら0で終了
            if(a[i]-a[i-1]==1){
                System.out.println(0);
                return;
            }
        }
        long[] f = new long[n+1];
        f[0]=1;
        f[1]=1;
        for(int i=2;i<=n;i++){
            f[i] = (f[i-1] + f[i-2]) % num;
        }
        //壊れてない場合は区間分けすると死亡
        if(m==0){
            System.out.println(f[n]);
            return;
        }
        //最初の区間は特別
        long ans = f[a[0]-1] % num;

        for(int i=1;i<m;i++){
            //ans = ( ans % num ) * (f[a[i]-a[i-1]-1] % num ) * (f[a[i+1]-a[i]-1] % num) % num;
            ans = ( ans % num ) * (f[a[i]-a[i-1]-2]) % num;
        }
        //最後の区間も特別
        ans = ( ans % num ) * (f[n-a[m-1]-1]) % num;
        System.out.println(ans);
    }
        

}

Measured memory_bytes: 47072
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  for(int i=0;i<n;i++){
    cin >> p.at(i);
  }
  int count=0;
  int min=p.at(0);
  int elem=0;
  for(int i=0;i<n;i++){
    elem = p.at(i);
    if(elem <= min){
      count += 1;
    }
    if(elem < min){
      min = elem;
    }
  }
       cout << count;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>

using namespace std;

int main() {
	string n;
	cin >> n;
	if ((n[0] == n[1] && n[1] == n[2]) || (n[1] == n[2] && n[2] == n[3]))
      cout << "Yes" << endl;
	else cout << "No"<<endl;
	return 0;
}


Measured memory_bytes: 256
void main(){
	int n = _scan();
	int[] ans_arr = [1, 2, 4, 8, 16, 32, 64];
	int ans;
	foreach(elm; ans_arr){
		if(elm>n)break;
		ans = elm;
	}
	ans.writeln();
}

import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;

// 1要素のみの入力
T _scan(T= int)(){
	return to!(T)( readln().chomp() );
}

// 1行に同一型の複数入力
T[] _scanln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split()){
		ln ~= elm.to!T();
	}
	return ln;
}


Measured memory_bytes: 2688
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 1LL << 60;

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include "unordered_map"
#include "map"
#include <cmath>
#include <climits>
#include "queue"
#include "tuple"
#include <algorithm>
#include <iomanip>
#include "sstream"
#include <math.h>

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

//const double PI = M_PI;

template <typename T>
inline void printQueue(queue<T>&oq){queue<T>q(oq);int qCount=q.size();for(int i=0;i<qCount;++i){T qe=q.front();q.pop();
        cout<<qe;if(i!=qCount-1){cout << ", ";}q.push(qe);}cout << endl;}

template<typename T>
inline void PV(vector<T> v){int vc=v.size();for(int i=0;i<vc;++i){cout << v[i];if(i!=vc-1){cout<<", ";}}cout << endl;}

inline double round( double val )
{
    if( val < 0 ) return ceil(val - 0.5);
    return floor(val + 0.5);
}

int main() {
//    freopen("../input.txt","r",stdin);
//    freopen("../output.txt","w",stdout);
//    for(int i = 1; i <= n; ++i) {
    ull C;
    cin >> C;
    vector<ll> nV;
    for(int i = 0; i < C; ++i) {
        ll n;
        cin >> n;
        nV.emplace_back(n);
    }
    ll fns = 0;
    ll bns = 0;
    unordered_map<ll, ll> fnsM;
    unordered_map<ll, ll> bnsM;
    for(int i = 0; i < C; ++i) {
        fns += nV[i];
        fnsM[i] = fns;
        ll j = C - i - 1;
        bns += nV[j];
        bnsM[j] = bns;
    }
    ull ma = ULLONG_MAX;
    for(int i = 0; i < C - 1; ++i) {
        ull a = abs(fnsM[i] - bnsM[i + 1]);
        if(a < ma) {
            ma = a;
        }
    }
    cout << ma;
}


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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

void solve()
{
  // ll x, y, z; cin >> x >> y >> z;
  string s; cin >> s;
  ll n; cin >> n;
  // vector<ll> a(n); REP(i, n) cin >> a[i];
  // ll ans = 0;
  // bool ok = false;
  for(ll i = 0; i < s.size(); i+=n) {
    cout << s[i];
  }
  cout << endl;
  // cout << ans << endl;
  // cout << (ok?"Yes":"No") << endl;}
}


int main(void)
{
  // ll t; cin >> t; REP(i, t)
  solve();
}


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

using namespace std;

const int N = 2e5 + 5;

int n, m;
long long f[N], g[N];
vector <pair <int, int> > segment[N];

struct SegmentTree {
    long long node[N << 2], lazy[N << 2];
    void init (int i, int l, int r) {
        if (l == r) {
            node[i] = lazy[i] = 0;
            return;
        }

        int mid = l + r >> 1;
        init(i << 1, l, mid); init(i << 1 | 1, mid + 1, r);
        node[i] = lazy[i] = 0;
    }

    void dolazy (int i, int l, int r) {
        if (lazy[i]) {
            node[i] += lazy[i];
            if (l != r) {
                lazy[i << 1] += lazy[i];
                lazy[i << 1 | 1] += lazy[i];
            }

            lazy[i] = 0;
        }
    }

    void update (int i, int l, int r, int a, int b, long long val) {
        dolazy(i, l, r);
        if (l > r || a > r || b < l) return;
        if (a <= l && r <= b) {
            node[i] += val;
            if (l != r) {
                lazy[i << 1] += val;
                lazy[i << 1 | 1] += val;
            }

            return;
        }

        int mid = l + r >> 1;
        update(i << 1, l, mid, a, b, val); update(i << 1 | 1, mid + 1, r, a, b, val);
        node[i] = max(node[i << 1], node[i << 1 | 1]);
    }

    long long query (int i, int l, int r, int a, int b) {
        if (l > r || a > r || b < l) return -(long long)1e18;
        dolazy(i, l, r);
        if (a <= l && r <= b) return node[i];

        int mid = l + r >> 1;
        return max(query(i << 1, l, mid, a, b), query(i << 1 | 1, mid + 1, r, a, b));
    }
} it;

int main(){
    scanf("%d %d", &n, &m); it.init(1, 1, n);
    for (int i = 1; i <= m; i++) {
        int l, r, c;
        scanf("%d %d %d", &l, &r, &c);
        segment[r].push_back({l, c});
        it.update(1, 1, n, l, r, c);
    }

    for (int i = 1; i <= n; i++) f[i] = it.query(1, 1, n, i, i);
    it.init(1, 1, n);
    for (int i = 1; i <= n; i++) {
        g[i] = max(0LL, it.query(1, 1, n, 1, i));
        it.update(1, 1, n, i, i, g[i]);
        g[i] += f[i];
        for (auto j: segment[i]) it.update(1, 1, n, j.first, i, j.second);
    }

    long long ans = 0;
    for (int i = 1; i <= n; i++) ans = max(ans, g[i]);
    printf("%lld", ans);
    return 0;
}


Measured memory_bytes: 26752
#include <stdio.h>

int main(void)
{
    int N, Q, i;
    scanf("%d%d", &N, &Q);

    char str[N + 1];
    int sum[N], l[Q], r[Q];
    scanf("%s", str);

    sum[0] = 0;
    for (i = 0; i < N - 1; i++)
    {
        sum[i + 1] = sum[i];
        if(str[i] == 'A' && str[i + 1] == 'C'){
            sum[i + 1]++;
            }
    }

    for (i = 0; i < Q; i++){
        scanf("%d %d", &l[i], &r[i]);
        printf("%d\n", sum[r[i] - 1] - sum[l[i] - 1]);
    }

    return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main(){
  
  string s;
  cin>>s;
  
  int A = ( s[0] - '0' )* 10 + ( s[1] - '0' );
  int B = ( s[2] - '0' )* 10 + ( s[3] - '0' );
  
  int flg1 = 0, flg2 = 0;
  
  if( 1 <= A && A <= 12 ) flg1 = 1;
  if( 1 <= B && B <= 12 ) flg2 = 1;
  
  if( flg1 && flg2 ) cout<<"AMBIGUOUS"<<endl;
  else if( flg1 && !flg2 ) cout<<"MMYY"<<endl;
  else if( !flg1 && flg2 ) cout<<"YYMM"<<endl;
  else cout<<"NA"<<endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  int N;
  cin >> N;
  string s, t;
  cin >> s >> t;
  int ans = 2*N;
  for (int i=N; i>=1; i--) {
    string s_sub = s.substr(N-i, i), t_sub = t.substr(0, i);
    if (s_sub==t_sub) {
      ans -= i;
      break;
    }
  }
  cout << ans << endl;
}

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

typedef long long ll;

const ll MOD = 1000000007;

int main(void) {
	int N;
	ll ans = 1;

	cin >> N;
	for (int i = N; i > 1; --i) {
		ans *= i;
		ans %= MOD;
	}
	cout << ans << '\n';

	return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<pair<string,int>> namepoint(n);
    map<pair<string,int>,int> num;
    for(int i=0; i<n; i++){
        string s;
        int a;
        cin >> s >> a;
        namepoint[i]=make_pair(s,-a);
        num[namepoint[i]]=i+1;
    }
    sort(namepoint.begin(),namepoint.end());
    for(auto p:namepoint){
        cout << num[p] << endl;
    }
}

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

using namespace std;

char s[200001];

int main() {
    int n, x = 0, i;
    long long ans = 0;
    vector <int> v;
    
    scanf("%s", s);
    
    n = strlen(s);
    
    for (i = 0; i < n; i++) {
        if (s[i] == 'A') {
            v.push_back(1);
        } else if (s[i] == 'B' && i + 1 < n && s[i + 1] == 'C') {
            v.push_back(0);
            i++;
        } else {
            v.push_back(-1);
        }
    }
    
    for (i = (int)v.size() - 1; i >= 0; i--) {
        if (v[i] == 1) {
            ans += x;
        } else if (v[i] == 0) {
            x++;
        } else {
            x = 0;
        }
    }
    
    printf("%lld\n", ans);
    
    return 0;
}


Measured memory_bytes: 1528
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll n, a[5000], dp[5000][5000], use[5000][5000];

ll fetch(ll qi, ll qj){
	if(use[qi][qj]){
		return dp[qi][qj];
	}
	use[qi][qj] = true;
	
	ll t = n-(qj-qi);
	if(t%2 == 0){
		return dp[qi][qj] = max(fetch(qi, qj-1)+a[qj-1], fetch(qi+1, qj)+a[qi]);
	}
	else{
		return dp[qi][qj] = min(fetch(qi, qj-1)-a[qj-1], fetch(qi+1, qj)-a[qi]);
	}
}

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

	cin >> n;
	rep(i, 0, n){
		cin >> a[i];
	}
	memset(use, 0, sizeof(use));
	for(ll k = 0; k <= n; k++){
		dp[k][k] = 0;
		use[k][k] = true;
	}
	
	print(fetch(0, n))
	
	return 0;
}

Measured memory_bytes: 313856
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

ll gcd(ll a,ll b){
    if(a > b) swap(a,b);
    if(b % a == 0) return a;
    return gcd(a, b%a);
}

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

int main() {
    int n,ans=1;
    cin >> n;
    int t[n],a[n];
    for(int i=0;i<n;i++) cin >> t[i] >> a[i];
    ll tmin=t[0],amin=a[0];
    for(int i=1;i<n;i++){
        ll ax=(amin+a[i]-1)/a[i],tx=(tmin+t[i]-1)/t[i];
        tmin = t[i] * max(tx,ax);
        amin = a[i] * max(tx,ax);
    }
    cout << tmin+amin << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int llint
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a+MOD)%MOD)+((b+MOD)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define PI (acos(-1))
#define EPS (1e-10)
#define INF INT_MAX
#define INFLL LLONG_MAX
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using MCI = std::map<char, int>;
using VPII = std::vector<PII>;
using Complex = std::complex<double>;
using namespace std;


int N, K;
VI v;
int c[100010];


int solve(){
	int sum = 0;
	rep(i, 0, SIZE(v)){
		sum += c[v[i]];
		if(K <= sum) return v[i];
	}
	return -1;
}


signed main(){
	cin >> N >> K;
	rep(i, 0, N){
		int a, b;
		cin >> a >> b;
		if(!c[a]) v.pb(a);
		c[a] += b;
	}

	sort(ALL(v));

	cout << solve() << endl;

	return 0;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
int main(){
	int H, W;
	cin >> H >> W;
	map<int, int64_t> mp;
	multiset<int64_t> values;
	for(int i=1; i<=W; i++){
		mp[i] = 0;
		values.insert(0);
	}
	for(int i=1; i<=H; i++){
		int l, r;
		cin >> l >> r;
		if(r != W){
			auto it = mp.upper_bound(r+1);
			if(it != mp.begin()){
				it--;
				if(it->first != r+1){
					int64_t v = it->second + (r+1-it->first);
					mp[r+1] = v;
					values.insert(v);
				}
			}
		}
		auto it = mp.lower_bound(l);
		while(it != mp.end() && it->first <= r){
			values.erase(values.find(it->second));
			it = mp.erase(it);
		}
		if(values.size())
			cout << i + *values.begin() << endl;
		else
			cout << -1 << endl;
	}
	return 0;
}

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

const int maxn = 3000;
int n, a[maxn + 3];
vector<int> G[maxn + 3];

bool dfs(int u, int pa = 0) {
	bool flag = false;
	for (int i = 0, v; i < G[u].size(); i++) {
		v = G[u][i];
		if (v == pa) continue;
		flag |= a[u] > a[v] && !dfs(v, u);
	}
	return flag;
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}
	for (int i = 1, u, v; i < n; i++) {
		scanf("%d %d", &u, &v);
		G[u].push_back(v), G[v].push_back(u);
	}
	for (int i = 1; i <= n; i++) {
		if (dfs(i)) printf("%d ", i);
	}
	puts("");
	return 0;
}

Measured memory_bytes: 384