akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
    int data[][], k2;

    private class Point {
        int x, y;

        public Point(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }

    public void main(Scanner sc) {
        int n = sc.nextInt();
        int k = sc.nextInt();
        k2 = 2 * k;
        Point p[] = new Point[n];
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt() % k2;
            int y = sc.nextInt() % k2;
            if (!sc.next().equals("B")) {
                y = (y + k) % k2;
            }
            p[i] = new Point(x, y);
        }

        data = new int[k2][k2];
        for (int i = 0; i < n; i++) {
            add(-p[i].x, -p[i].y, 1);
            add(k - p[i].x, k - p[i].y, 1);
            add(-p[i].x, k - p[i].y, -1);
            add(k - p[i].x, -p[i].y, -1);
            add(k - p[i].x, k - p[i].y, 1);
            add(k2 - p[i].x, k2 - p[i].y, 1);
            add(k - p[i].x, k2 - p[i].y, -1);
            add(k2 - p[i].x, k - p[i].y, -1);
        }

        for (int i = 0; i < k2; i++) {
            for (int j = 1; j < k2; j++) {
                data[i][j] += data[i][j - 1];
            }
        }
        for (int i = 0; i < k2; i++) {
            for (int j = 1; j < k2; j++) {
                data[j][i] += data[j - 1][i];
            }
        }

        int ans = 0;
        for (int i = 0; i < k2; i++) {
            for (int j = 0; j < k2; j++) {
                ans = Math.max(ans, data[i][j]);
            }
        }
        System.out.println(ans);
    }

    private void add(int x, int y, int n) {
        if (x >= 0 && x < k2) {
            if (y >= 0 && y < k2) {
                data[y][x] += n;
            } else if (y < 0) {
                data[0][x] += n;
                data[k2 + y][x] += n;
            }
        } else if (x < 0) {
            if (y >= 0 && y < k2) {
                data[y][0] += n;
                data[y][k2 + x] += n;
            } else if (y < 0) {
                data[0][0] += n;
                data[0][k2 + x] += n;
                data[k2 + y][0] += n;
                data[k2 + y][k2 + x] += n;
            }
        }
    }

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


Measured memory_bytes: 106744
n = gets.chomp.to_i
a = gets.chomp.split(" ")
a.map! { |item| item.to_i }

## n = 2
## a = [10, 30]
a.map! { |item| 1.0 / item.to_i }

### p a
### p a.inject(:+)
p 1.0 / a.inject(:+)

Measured memory_bytes: 1788
#include<deque>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<numeric>
#include<cmath>
#include<cstdio>
#include<cstring>
using namespace std;
bool pr(const pair<int,int>& p,const pair<int,int>& q){
  if(p.second==q.second)
    return p.first<q.first;
  else
    return p.second>q.second;
}
int main(){
  int i;
  int n;
  cin>>n;
  pair<int,int> a[20];
  for(i=0;i<n;++i)
    cin>>a[i].first>>a[i].second;
  sort(a,a+n,pr);
  cout<<a[0].first<<' '<<a[0].second<<endl;
  return 0;
}

Measured memory_bytes: 1164
import sys
input = sys.stdin.buffer.readline

import heapq

#点の数が10**5のオーダー以下で使える
#頂点sからの各頂点への最短距離を出力
def dijkstra(s, n, edge): #s:始点、n:頂点の数、edge:重み付き辺の配列（edge[i]:iから出る[重み、行き先]の配列)
    INF = 10**20
    d = [INF]*n # d[i]: sと点iとの距離
    used = [True]*n #Trueは未確定
    d[s] = 0 #初期条件
    used[s] = False # 初期条件
    edge_list = []
    for a, b in edge[s]:
        heapq.heappush(edge_list, a*(10**6)+b) #heapqの中に重みと辺の抱き合わせた情報を入れる
    while len(edge_list):
        min_edge = heapq.heappop(edge_list) #まだ使われていない頂点の中から最小の重みのものを取りだす
        if not used[min_edge%(10**6)]: # 確定していたらcontinue、確定していない時のみ以下の処理を行う
            continue
        v = min_edge%(10**6) #行き先の情報を復元
        d[v] = min_edge // (10**6) #重みの情報を復元し、sとvの最短距離d[v]を更新する
        used[v] = False
        for e in edge[v]:
            if used[e[1]]: #その行き先がまだ未確定の場合
                heapq.heappush(edge_list, (e[0]+d[v])*(10**6) + e[1])
        
    return d


n = int(input())

edge = [[] for _ in range(n)] # edge:重み付き辺の配列（edge[i]:iから出るtuple(重み、行き先)の配列)
for _ in range(n):
    x, y, *li = list(map(int, input().split()))
    for i in range(y):
        edge[x].append((li[2*i+1], li[2*i]))
        #edge[li[2*i]].append([li[2*i+1], x]) # 無向グラフのとき

d = dijkstra(0, n, edge)

for i in range(n):
    print(i, d[i])


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

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

using namespace std;

int main()
{
	ll n; cin>>n;
	map<ll, ll> m;
	rep(i, n){
		ll a; cin>>a;
		ll ao = a;
		for(int j=2; j*j<=a; j++){
			if (a%j==0){
				m[j] += ao;
				while(a%j==0) a/=j;
			}
		}
		if (a!=1) m[a]+=ao;
	}
	ll ans=0;
	for(auto it=m.begin(); it!=m.end(); it++){
		ans = max(ans, it->second);
	}
	cout << ans << "\n";
	return 0;
}


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

typedef long long ll;
typedef pair<int, int> P;

const int INF = 1000000007;

int main(void){
	string S,T;
	cin>>S>>T;

	string s,t;
	sort(S.begin(), S.end());
	sort(T.begin(), T.end(), greater<int>());
	
	if(S < T) printf("Yes\n");
	else printf("No\n");

	return 0;
}

Measured memory_bytes: 256
fn main() {
    let mut sc = Scanner::new();
    let n = sc.usize_read();
    let m = sc.read();
    let mut from = vec![n; n];
    for _ in 0..m {
        let a = sc.usize_read() - 1;
        let b = sc.usize_read() - 1;
        if from[b] == n || from[b] < a {
            from[b] = a;
        }
    }

    let mut ans = 0;
    let mut last = 0;
    for i in 0..n {
        if from[i] == n {
            continue;
        }
        if last <= from[i] {
            last = i;
            ans += 1;
        }
    }
    println!("{}", ans);
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        Scanner {
            ptr: 0,
            length: 0,
            buf: vec![0; 1024],
            small_cache: vec![0; 1024],
        }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool {
        b == b'\n' || b == b'\r' || b == b'\t' || b == b' '
    }

    fn read_vec<T>(&mut self, n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        (0..n).map(|_| self.read()).collect()
    }

    fn usize_read(&mut self) -> usize {
        self.read()
    }

    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)])
                    .parse()
                    .unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}


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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
template <typename T>
using mat = vector<vector<T>>;

// clang-format off
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) { return stream << p.first << "," << p.second; }
template <typename T>
void print(const vector<T> vec) { rep (i, vec.size() - 1) cout << vec[i] << ' '; cout << vec[vec.size() - 1] << '\n'; }
template <typename Arg>
void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) { cout << head << " "; print(args...); }
template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) { rep (i, v.size()) cin >> v[i] >> w[i]; }
template <typename T>
void init(vector<T>& v) { rep (i, v.size()) cin >> v[i]; }
template <typename T>
T sum_(vector<T> vec, T init = 0) { return std::accumulate(all(vec), T(init)); }
template<typename T>
bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
template <typename T = int>
mat<T> mmat(int n, int m=0) { return mat<T>(n, vector<T>(m)); }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    yn(n == m);

    return 0;
}


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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

struct Data {
    ll a, b, c, d;
};

ll N, M, Q;
Data D[55];

ll dfs(vector<ll> v, ll s = 1) {
    if (v.size() == N) {
        ll sum = 0;
        REP(i, Q) {
            if (v[D[i].b - 1] - v[D[i].a - 1] == D[i].c)
                sum += D[i].d;
        }
        return sum;
    }

    ll ret = 0;
    for (ll i = s; i <= M; ++i) {
        v.push_back(i);
        ret = std::max(ret, dfs(v, i));
        v.pop_back();
    }
    return ret;
}

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

    cin >> N >> M >> Q;
    REP(i, Q) {
        cin >> D[i].a >> D[i].b >> D[i].c >> D[i].d;
    }

    cout << dfs(vector<ll>()) << endl;
    return 0;
}

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

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

	vector<int> a(N);
	REP(i, N){
		cin >> a[i];
	}

	int flashed = 1;
	int num = 0;

	REP(i, N){
		flashed = a[flashed - 1];
		num++;
		if(flashed == 2){
			cout << num << endl;
			return 0;
		}
	}

	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 3772
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int N, C[3]; bool see[100100][7][7][7];
char S[100100][4];
vector<char> R; bool E;

void go(int i, vector<int> c)
{
	if (i == N){
		E = 1;
		return;
	}
	if (see[i][c[0]][c[1]][c[2]]) return;

	int x = S[i][0] - 'A', y = S[i][1] - 'A';
	if (c[x] > 0){
		c[x]--; c[y]++;
		R[i] = y + 'A';
		go(i + 1, c);
		if (E) return;
		c[x]++; c[y]--;
	}
	if (c[y] > 0){
		c[y]--; c[x]++;
		R[i] = x + 'A';
		go(i + 1, c);
		if (E) return;
		c[y]++; c[x]--;
	}
}

int main()
{
	scanf ("%d %d %d %d", &N, C, C + 1, C + 2);

	for (int i = 0; i < N; i++) scanf ("%s", S[i]);
	for (int i = 0; i < N; i++){
		int x = S[i][0] - 'A', y = S[i][1] - 'A';

		if (C[x] == 0 && C[y] == 0){
			puts("No");
			return 0;
		}
		if (C[x] == 0 || C[y] == 0){
			if (C[x]) R.push_back(y + 'A'), C[x]--, C[y]++;
			else R.push_back(x + 'A'), C[y]--, C[x]++;
			continue;
		}
		break;
	}

	if (R.size() < N){
		int k = R.size();
		R.resize(N);
		C[0] = min(C[0], 2);
		C[1] = min(C[1], 2);
		C[2] = min(C[2], 2);
		go(k, { C[0], C[1], C[2] });
		if (!E){
			puts("No");
			return 0;
		}
	}

	puts("Yes");
	for (auto &c : R) printf ("%c\n", c);
	return 0;
}

Measured memory_bytes: 20892
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
struct Info
{
public:
    int from;
    int to;
    ll dist;
};
map<int, deque<Info>> infos;
array<ll, 100005> x;
//------------------------------------------------------------------------------
void _main()
{
    int N, M;
    cin >> N >> M;
    int L, R;
    ll D;
    rep(i, 0, M)
    {
        cin >> L >> R >> D;
        --L; --R;
        infos[L].push_back({L, R, D});
        infos[R].push_back({R, L, -D});
    }

    x.fill(infl);

    int num = 0;

    while (true)
    {
        queue<Info> q;
        for (auto& it : infos)
        {
            if (!it.second.empty())
            {
                while (!it.second.empty())
                {
                    q.push(it.second.front());
                    it.second.pop_front();
                    ++num;
                }
                break;
            }
        }

        while (!q.empty())
        {
            const auto info = q.front();
            q.pop();

            if (x[info.from] == infl)
            {
                x[info.from] = 0;
            }

            if (x[info.to] == infl)
            {
                x[info.to] = x[info.from] + info.dist;
            }
            else if (x[info.to] != x[info.from] + info.dist)
            {
                cout << "No" << endl;
                return;
            }

            while (!infos[info.to].empty())
            {
                q.push(infos[info.to].front());
                infos[info.to].pop_front();
                ++num;
            }
        }

        if (num == M * 2)
        {
            break;
        }
    }

    cout << "Yes" << endl;
}


Measured memory_bytes: 77824
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

// North, west, south, east
int dh[] = {-1, 0, 1, 0};
int dw[] = {0, -1, 0, 1};

int main(){
    int h, w; cin >> h >> w;
    vector<vector<char>> g(h, vector<char> (w));
    ll blk = 0;
    rep(i,h){
        rep(j,w){
            cin >> g[i][j];
            if(g[i][j] == '#') blk++;
        }
    }

    queue<P> q;
    Graph dist(h, vector<int> (w,1002003004));
    auto push = [&](int vh,int vw, int d){
        if(dist[vh][vw] != 1002003004) return;
        dist[vh][vw] = d;
        q.push({vh,vw});
    };

    push(0,0,0);
    while(!q.empty()){
        P p = q.front(); q.pop();
        int d = dist[p.first][p.second];

        rep(i,4){
            int vh = p.first + dh[i], vw = p.second + dw[i];
            if(vh <= -1 || vh >= h || vw <= -1 || vw >= w) continue;
            if(g[vh][vw] == '#') continue;
            push(vh, vw, d+1);
        }
    }

    if(dist[h-1][w-1] == 1002003004){
        cout << -1 << endl;
        return 0;
    }

    cout << h*w - blk - (dist[h-1][w-1] +1) << endl;
}

Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))
#define iter(v,ite) for(auto ite=(v).begin();ite!=(v).end();ite++)
#define mimunum(v,x) distance((v).begin(),lower_bound((v).begin(),(v).end(),x))


int n;

int X[105],Y[105];



int used[205]={};
int match[205];
vector<int> vs[205];

bool dfs(int v){
  used[v]=true;
  for(int i=0;i<vs[v].size();i++){
    int u=vs[v][i],w=match[u];
    if(w<0||!used[w]&&dfs(w)){
      match[v]=u;
      match[u]=v;
      return true;
    }
  }
  return false;
}
 
int bipartite_matching(){
  int res=0;
  memset(match,-1,sizeof(match));
  for(int v=0;v<n*2;v++){
    if(match[v]<0){
      memset(used,0,sizeof(used));
      if(dfs(v)){
    res++;
      }
    }
  }
  return res;
}
	
	

int main(void){
	scanf("%d",&n);
	rep(i,n){
		scanf("%d%d",&Y[i],&X[i]);
	}
	rep(i,n){
		int y,x;
		scanf("%d%d",&y,&x);
		rep(j,n){
			if(x>X[j] && y>Y[j]){
				int p=i+n,q=j;
				vs[p].push_back(q);
				vs[q].push_back(p);
				//printf("e %d %d\n",p,q);
			}
		}
	}
	
	
	printf("%d\n",bipartite_matching());
		
	return 0;
}






Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
U = [0]*(10**6+1)
for e in A:
    U[e] += 1
ans = 0
for k in range(1,10**6+1):
    if U[k] == 1:
        ans += 1
    if U[k] > 0:
        for l in range(2*k,10**6+1,k):
            if U[l] > 0:
                U[l] += 1
print(ans)


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

int main()
{
  int A,B;
  int sum;
  int count=0;

  cin >> A >> B;
  sum=1;
  while (sum<B)
  {
    sum = sum -1 + A;
    count++;
  }
  

  cout << count << endl;
  
  return 0;
}

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  string s ; 
  cin >> s ; 
  int sum = 0 ; 
  
  rep(i,s.size()){
    int now = (int)s.at(i) - 48  ;
    sum += now ;
  }
  
  if(sum%9 == 0 ) cout << "Yes" ;
  else           cout << "No"  ;
  


}


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

int main ()
{
    int n;
    string a, b, c;
    int one_matched = 0;
    int two_matched = 0;
    cin >> n >> a >> b >> c;
    for (int i = 0; i < n; ++i) {
        if (a[i] != b[i] && a[i] != c[i] && b[i] != c[i]) {
            continue;
        }
        else if (a[i] == b[i] && b[i] == c[i]) {
            ++two_matched;
            continue;
        }
        else {
            ++one_matched;
            continue;
        }
        
    }
    cout << (n * 2 - (one_matched + two_matched * 2));

}

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

#define int				long long
#define	ll				long long

#define	mod 			1000000007
#define	inf 			1000000000000000
#define infty			1000000000000000000LL
#define	md				998244353
#define	PI				acos(-1.0)
#define	endl 			"\n"
#define	rr				return
#define	br				cout<<"\n";
long long prime[1000000];

void sieve()
{
	prime[0]=0;
	prime[1]=0;
	for(int i=2;i<1000000;i++)
		prime[i]=1;

	for(int i=2;i*i<1000000;i++)
		if(prime[i]==1)
			for(int j=i*i;j<1000000;j+=i)
				prime[j]=0;
}

bool isPrime(int n)
{
    if (n <= 1)
        return false;
    for (ll i = 2; i <= floor(sqrt(n)); i++)
        if (n % i == 0)
            return false;

    return true;
}

int factorial(int n)
{
    int f=1;
    for(int i = 1;i<=n ; i++)
        f = (f*i)%mod;
    return f;
}

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

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

int fastExponentiation(int n, int x, int modulo)
{
	int res = 1;
	while(x > 0)
       {
          if(x & 1)
          res = (res*n) % modulo;
          x = x >> 1;
          n = (n * n) % modulo;
       }
       return res;
}

int power(int n , int p )
{
	if(p==0)
	   return 1;

	 int res = power((n*n)%mod,p/2);
	 if(p%2==1)
	   res = (n*res)%mod;

	   	 return res;
}

bool isPowerOfTwo(int n)
{
   	return n && (!(n&(n-1)));
}

bool isSet(int n,int i)
{
	// To check if ith bit is set or not in binary representation of n
   	return n & (1 << i);
}

bool valid_coordinate(ll x,ll y,ll n,ll m)
{
    if(x<0 || y<0)
       return false;

   	else if(x>=n || y>=m)
       return false;

   	else
   		return true;
}

int sod(int n)
{
	int sum=0;
	while(n)
	{
		sum+=(n%10);
		n/=10;
	}
	return sum;
}



void solve()
{
	int a,b;
	cin>>a>>b;
	a%=b;
	cout<<min(a,abs(a-b));
}

int32_t main()
{

	//int t; cin>>t; while(t--)
	solve();

	return 0;
}


Measured memory_bytes: 3568
#include <stdio.h>
#include <stdlib.h>
#define int long long

int min(int a, int b){
	return a <= b ? a : b;
}

signed main(){
	int N, Q, K, i, j, q, ans;
	scanf("%lld", &N);
	char *S = (char *)malloc(sizeof(char) * (N + 2));
	scanf("%s", &S[1]);
	int *M_sum = (int *)malloc(sizeof(int) * (N + 1));
	int *C_sum = (int *)malloc(sizeof(int) * (N + 1));
	int *MC_sum = (int *)malloc(sizeof(int) * (N + 1));
	M_sum[0] = 0;
	C_sum[0] = 0;
	MC_sum[0] = 0;
	for(i = 1; i <= N; i++){
		M_sum[i] = M_sum[i - 1] + (S[i] == 'M' ? 1 : 0);
		C_sum[i] = C_sum[i - 1] + (S[i] == 'C' ? 1 : 0);
		MC_sum[i] = MC_sum[i - 1] + (S[i] == 'C' ? M_sum[i] : 0);
	}
/*	printf("M_sum:");
	for(i = 0; i <= N; i++){
		printf("%lld ", M_sum[i]);
	}
	printf("\n");
	printf("C_sum:");
	for(i = 0; i <= N; i++){
		printf("%lld ", C_sum[i]);
	}
	printf("\n");
	printf("MC_sum:\n");
	for(i = 0; i <= N; i++){
		printf("%lld ", MC_sum[i]);
	}
	printf("\n");
*/	scanf("%lld", &Q);
	for(q = 0; q < Q; q++){
		scanf("%lld", &K);
		for(i = 1, ans = 0; i <= N; i++){
			if(S[i] == 'D'){
				j = min(N, i + K - 1);
				ans += (MC_sum[j] - MC_sum[i - 1]) - (C_sum[j] - C_sum[i - 1]) * M_sum[i - 1];
			}
		}
		printf("%lld\n", ans);
	}
	return 0;
}

Measured memory_bytes: 24576
#include<iostream>

using namespace std;

int main(){
  int K,A,B;
  cin >> K >> A >> B;
  int i=0;
  while(++i*K<A){}
  
  if(i*K > B){
    cout << "NG";
  }else{
    cout << "OK";
  }
  return 0;
}

Measured memory_bytes: 3620
/*******************************
Author:galaxy yr
LANG:C++
Created Time:2019/07/23 09:40:42
*******************************/
#include<iostream>
#include<cstdio>
using namespace std;
const int maxn=2e5+10;
int n,a[maxn],l,r,mid,ans;
bool small(int i,int j,int k) { return a[i]<=k and a[j]<=k; }
bool big(int i,int j,int k) { return a[i]>k and a[j]>k; }
int check(int k)
{
    for(int i=0;i<n-1;i++)
    {
        if(big(n+i,n+i+1,k) or big(n-i,n-i-1,k))return 0;
        if(small(n+i,n+i+1,k) or small(n-i,n-i-1,k))return 1;
    }
    return small(1,1,k);
}
int main()
{
    //freopen("triangle.in","r",stdin);
    //freopen("triangle.out","w",stdout);
    cin>>n;
    for(int i=1;i<=2*n-1;i++) cin>>a[i];
    l=1,r=2*n-1;
    while(l<=r)
    {
        mid=(l+r)>>1;
        if(check(mid)) r=mid-1,ans=mid;
        else
            l=mid+1;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
import java.util.*;

class Main {
        public static void main(String args[]) {
                try (Scanner sc = new Scanner(System.in)) {
                        while (true) {
                                int x = sc.nextInt(), y = sc.nextInt();
                                if (x == 0 && y == 0) {
                                        break;
                                }
                                System.out.println(Math.min(x,y) + " " + Math.max(x,y));
                        }
                }
        }
}

Measured memory_bytes: 36892
from operator import itemgetter
from itertools import *
from bisect import *
from collections import *
from heapq import *
from fractions import Fraction
import sys

sys.setrecursionlimit(10 ** 6)

def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def SI(): return sys.stdin.readline()[:-1]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
int1 = lambda x: int(x) - 1
def MI1(): return map(int1, sys.stdin.readline().split())
def LI1(): return list(map(int1, sys.stdin.readline().split()))
p2D = lambda x: print(*x, sep="\n")
dij = [(1, 0), (0, 1), (-1, 0), (0, -1)]

n,h,w=MI()
ans=0
for _ in range(n):
    a,b=MI()
    if a>=h and b>=w:ans+=1
print(ans)

Measured memory_bytes: 10384
while True:
    N=int(input())
    
    if N==0:
        break
    
    num=0
    res=-11111111
    for i in range(N):
        a=int(input())
        num=max(num+a, a)
        #print(num)
        res=max(num, res)
        #print(res)

    print(res)



Measured memory_bytes: 5604
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> P;

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

void solve(void){
	int N;
	cin >> N;
	vector <int> ls(N+1, 0), rs(N+1, 0);
	rep(N, i) {
		cin >> ls[i] >> rs[i];
	}
	sort(all(ls));
	sort(all(rs));
	reverse(all(ls));
	ll ans = 0;
	rep(N+1, i) {
		if (ls[i] > rs[i]) {
			ans += 2 * (ls[i] - rs[i]);
		}
	}
	cout << ans << endl;
}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 1024
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.println(find(sc.nextInt()));
	}

	static String find(int n) {
		for (int i = 1; i <= 9; i++)
			for (int j = 1; j <= 9; j++)
				if (i * j == n)
					return "Yes";
		return "No";
	}
}


Measured memory_bytes: 23892
n = int(input())
L_A = list(map(int,input().split()))

L_even = []
for i in range(0,n):
    if L_A[i] % 2 == 0:
        L_even.append(L_A[i])

ans = 0
for i in range(0,len(L_even)):
    if L_even[i] % 3 == 0 or L_even[i] % 5 == 0:
        ans += 0
    else:
     ans += 1

if ans == 0:
    print('APPROVED')
else:
    print('DENIED')

Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <tuple>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <complex>
#include <bitset>
#include <numeric>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n) ;++(i))
#define REPN(i,a,n) FOR((i),(a),(a)+(n))
#define FOR(i,a,b) for(int (i)=(a); (i)<(b) ;++(i))
#define PB push_back
#define MP make_pair
#define SE second
#define FI first
#define DBG(a) cerr<<(a)<<endl;
#define ALL(v) (v).begin(),(v).end()
typedef long long LL;  typedef pair<LL, LL> PLL; typedef vector<LL> VLL;
const LL LINF=334ll<<53; const int INF=15<<26; const LL MOD=1E9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,c=0;
    string s,t;
    cin >> n;
    cin >> s;
    cin >>t;
    for(int i=n;i>=1;--i){
        if(s.substr(n-i)==t.substr(0,i)){
            c=i;
            break;
        }
    }
    
    DBG(c)
    cout << n*2-c << endl;



    return 0;
}


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

using ll = long long;

const ll INF = (1LL << 60);

ll f(ll b, ll n) {
    if (n < b) return n;
    else return f(b, n / b) + n % b;
}

int main() {
    ll n, s;

    cin >> n >> s;

    if (s == n) {
        cout << n + 1 << endl; 
    } else {
        for (ll b = 2; b * b <= n; b++) {
            if (f(b, n) == s) {
                cout << b << endl;
                return 0;
            }
        }

        ll ans = INF;
        for (ll p = 1; p * p < n; p++) {
            if ((n - s) % p != 0) continue;
            ll b = (n - s) / p + 1;
            if (b >= 2 && f(b, n) == s) {
                ans = min(ans, b);
            }
        }
        if (ans >= INF) cout << -1 << endl;
        else cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair

int main()
{
	int M,D;
	scanf("%i %i",&M,&D);
	int ans=0;
	for(int i=1;i<=D;i++)
	{
		int x=i/10;
		int y=i%10;
		if(x>=2 && y>=2)
		{
			int t=x*y;
			if(M>=t) ans++;
		}
	}
	printf("%i\n",ans);
	return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
vector<int> dx = {-1, -1, -1, 0, 0, 1, 1, 1};
vector<int> dy = {-1, 0, 1, -1, 1, -1, 0, 1};

int main () {
    ll n, m, k; cin >> n >> m >> k;
    vector<ll> a(n), b(m), sa(n+1), sb(m+1);
    rep(i, n) cin >> a[i];
    rep(i, m) cin >> b[i];
    sa[0] = 0; sb[0] = 0;
    rep(i, n) sa[i+1] = sa[i] + a[i];
    rep(i, m) sb[i+1] = sb[i] + b[i];
    //rep(i, n+1) cout << sa[i] << endl;
    //rep(i, m+1) cout << sb[i] << endl;
    //ll time = 0;
    ll cnt = 0;
    ll ans = 0;
    for (int na = 0; na <= n; na++) {//Aからnaさつ
        if (sa[na] > k) break;
        cnt = na;
        //time = sa[na];
        int ok = 0; int ng = m+1;
        int cnt2 = k - sa[na];
        while (abs(ok-ng) > 1) {
            int mid = (ok+ng)/2;
            if (sb[mid] <= cnt2) {
                ok = mid;
            } else {
                ng = mid;
            }
        }
        cnt += ok;
        ans = max(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

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

  int n, m;
  bool s[200001] = {false};
  bool e[200001] = {false};
  scanf("%d %d", &n, &m);

  int cnt = 0;
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    if (a == 1) {
      s[b] = true;
      cnt++;
    }
    else if (b == n) {
      e[a] = true;
    }
  }

  for (int i = 1; i <= m; i++) {
    if (s[i] == true && e[i] == true) {
      printf("POSSIBLE\n");
      return 0;
    }
  }


  printf("IMPOSSIBLE\n");

  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
 
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint 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(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    }    

  int main(){
      lint n,m;
      cin>>n>>m;
      lint a[n];
      lint sum=0;
      rep(i,n){cin>>a[i];
    sum+=a[i];
      }
      lint ans=0;
      rep(i,n){
            if(a[i]*4*m>=sum)ans++;
      }
      if(ans>=m)cout<<"Yes";
      else cout<<"No";
  }
     
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define R register
#define mp make_pair
#define ll long long
#define pii pair<int, int>
using namespace std;
const int N = 110000, mod = 998244353;

int n, m, fa[3][N], lim[3];
ll sum[3][N], f[N], ans;
vector<int> to[N];
set<int> mex;

template <class T>
inline void read(T &x) {
	x = 0;
	char ch = getchar(), w = 0;
	while (!isdigit(ch)) w = (ch == '-'), ch = getchar();
	while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	x = w ? -x : x;
	return;
}

inline ll quickpow(ll base, ll pw) {
	ll ret = 1;
	while (pw) {
		if (pw & 1) ret = ret * base % mod;
		base = base * base % mod, pw >>= 1;
	}
	return ret;
}

int main() {
	int x, y;
	read(n);
	for (R int i = 0; i <= 2; ++i) {
		read(m);
		for (R int j = 1; j <= n; ++j) to[j].clear();
		for (R int j = 1; j <= m; ++j)
			read(x), read(y), to[min(x, y)].push_back(max(x, y));
		for (R int j = n; j; --j) {
			mex.clear();
			for (auto &v : to[j])
				mex.insert(fa[i][v]);
			while (mex.find(fa[i][j]) != mex.end())
				++fa[i][j];
			lim[i] = max(lim[i], fa[i][j]);
			sum[i][fa[i][j]] = (sum[i][fa[i][j]] + quickpow(10, 18 * j)) % mod;
		}
	}
	for (R int i = 0; i <= lim[1]; ++i)
		for (R int j = 0; j <= lim[2]; ++j)
			f[i ^ j] = (f[i ^ j] + sum[1][i] * sum[2][j]) % mod;
	for (R int i = 0; i <= lim[0]; ++i)
		ans = (ans + sum[0][i] * f[i]) % mod;
	cout << ans << endl;
	return 0;
}

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

using namespace std;

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

typedef long long ll;

void Main()
{
    int n; cin >> n;
	int a[200010];
	int f_m = 0;
	int s_m = 0;
	rep(i, n)
	{
		cin >> a[i];
		if (f_m < a[i]) {
			s_m = f_m;
			f_m = a[i];
		} else {
			if (s_m < a[i]) {
				s_m = a[i];
			}
		}
	}
	rep (i, n)
	{
		if (a[i] == f_m) {
			cout << s_m << endl;
		} else {
			cout << f_m << endl;
		}
	}

}

int main()
{
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	Main();
}


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

int main(void) {
    string S,T;
    cin >> S;
    cin >> T;
    for(int i=0; i<S.length(); ++i) {
        if(S[i]!=T[i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 3592
s_dash = input()
t = input()
answer = 'UNRESTORABLE'
if len(s_dash) < len(t):
    pass
else:
    for i in range(len(s_dash)-len(t)+1):
        for j, k in zip(s_dash[i:i+len(t)], t):
            if j != '?' and j != k:
                break
        else:
            answer = s_dash[:i] + t + s_dash[i+len(t):]
            answer = answer.replace('?', 'a')
print(answer)

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

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

    string s;
    cin >> s;

    set<char> st = {'A', 'C', 'G', 'T'};

    int n = s.size(), ans = 0, right = 0;
    for(int left = 0; left < n; left++){
        while(right < n && st.count(s[right])){
            right++;
        }
        ans = max(ans, right - left);
        if(left == right) right++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	int n,r;
	while(cin>>n>>r,r){
		int cards[60],i;
		for(i=0;i<60;i++)cards[i]=i;
		for(i=0;i<r;i++){
			int a,b;
			cin>>a>>b;
			a--;
			int j;
			int c[60];
			for(j=0;j<60;j++){
				if(j<b){
					c[j]=cards[a+j];
				}else if(j<a+b){
					c[j]=cards[j-b];
				}else{
					c[j]=cards[j];
				}
			}
			for(j=0;j<60;j++){
				cards[j]=c[j];
//cout<<cards[j]<<endl;
			}
//cout<<endl;
		}
		cout<<n-cards[0]<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
ll getPow(ll a,ll p){
  ll ret = 1,cp = a;
  while(p){
    if(p&1) ret = (ret*cp)%MOD;
    p >>= 1;
    cp = (cp*cp)%MOD;
  }
  return ret;
}
ll getInverse(ll a){
  return getPow(a,MOD-2)%MOD;
}
vector<ll> fact(200001,1),factinv(200001,1);
void init(ll l){
  for(ll i = 1; i < l; ++i){
    fact[i] = (fact[i-1]*i)%MOD;
    factinv[i] = (factinv[i-1]*getInverse(i))%MOD;
  }
}
ll C(ll a,ll b){
  ll ans = fact[a+b];
  ans = (ans*factinv[a])%MOD;
  ans = (ans*factinv[b])%MOD;
  return ans;
}
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll h,w,a,b;
  cin >> h >> w >> a >> b;
  init(h+w);
  ll ans = 0;
  for(int j = b; j < w; ++j){
    ans = (ans+C(h-a-1,j)*C(a-1,w-j-1))%MOD;
  }
  cout << ans;
  return 0;
}

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

int main() {
	int n; scanf("%d", &n);
	rep(i, n) {
		double x1, y1, x2, y2, x3, y3;
		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
		double a = -x1 + x2, b = -y1 + y2, c = (-pow(x1, 2) - pow(y1, 2) + pow(x2, 2) + pow(y2, 2)) / 2;
		double d = -x1 + x3, e = -y1 + y3, f = (-pow(x1, 2) - pow(y1, 2) + pow(x3, 2) + pow(y3, 2)) / 2;
		double y = (c*d - a*f) / (b*d - a*e);
		double x = (f - e*y) / d;
		printf("%.3lf %.3lf %.3lf\n", x, y, hypot(x1 - x, y1 - y));
	}
}

Measured memory_bytes: 3300
# C - Skill Up

import itertools
import numpy as np
N, M, X = map(int, input().split())
CA = np.zeros((N, M+1), dtype=np.int64)
for i in range(N):
    CA[i] = list(int(x) for x in input().split())

ans = 10**18
for lst in itertools.product((0,1), repeat=N):
    tmp = 0
    pnt = np.zeros(M, dtype=np.int64)
    for i in range(N):
        if lst[i] == 1:
            tmp += CA[i][0]
            pnt += CA[i][1:]
            if np.all(pnt >= X):
                ans = min(ans, tmp)

if ans == 10**18:
    print(-1)
else:
    print(ans)

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    int x = n%100;
    int y = (n-x)/100;
    if(x >= 1 && x <= 12)
    {
        if(y >= 1 && y <= 12)
            cout << "AMBIGUOUS";
        else
            cout << "YYMM";
    }

    else
    {
        if(y >= 1 && y <= 12)
            cout << "MMYY";
        else
            cout << "NA";
    }
    
}

Measured memory_bytes: 256
<?PHP
$input=explode(' ',trim(fgets(STDIN)));
$a=intval($input[0]);
$b=intval($input[1]);

if($a > 100){
  echo -1;
  return;
}
if($b > 100){
  echo -1;
  return;
}

$kotae = $a * $b;
echo $kotae;



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

int main() {
	int n, k;

	cin >>n >> k;

	vector<int> price;
	for(int i = 0; i < n; i++) {
		int p;
		cin >> p;
		price.emplace_back(p);
	}

	sort(price.begin(), price.end());

	int min_price_total = 0;
	for(int i = 0; i < k; i++) {
		min_price_total += price[i];
	}

	cout << min_price_total << endl;

	return 0;

}


Measured memory_bytes: 3640
import java.io.PrintStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main {
	final static PrintStream so = System.out;
	final static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {

		char[] chars = sc.next().toCharArray();
		Map<Character, Integer> counter = new HashMap<>();
		counter.put('E', 0);
		counter.put('W', 0);
		counter.put('N', 0);
		counter.put('S', 0);
		
		for (char ch: chars) {
			counter.put(ch, counter.get(ch) + 1);
		}
		
		int e = counter.get('E');
		int w = counter.get('W');
		int n = counter.get('N');
		int s = counter.get('S');
		boolean ew = (e == 0 && w > 0) || (w == 0 && e > 0);
		boolean ns = (n == 0 && s > 0) || (s == 0 && n > 0);
		so.println(ew || ns ? "No" : "Yes");
	}
}


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

int main(void){
   int N;
   cin >> N;
   int a[N+1];
   int count = 1;
   int ans = 0;
   for(int i = 0; i < N; i++)
    cin >> a[i];
    a[N]=0;
    sort(a, a+N);
    for(int i = 1; i <= N; i++){
        if(a[i]==a[i-1])
            count++;
        else if(a[i]!=a[i-1]&&count>=a[i-1]){
            ans+=(count-a[i-1]); count=1;}
        else if(a[i]!=a[i-1]&&count<a[i-1]){
            ans+=count; count=1;}
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
using System;

namespace contest
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] cap = { "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" };
            // 文字列の入力
            string a = Console.ReadLine();

            for(int i =0; i < 26; i++)
            {
                if (!a.Equals(cap[i]))
                {
                    continue;
                }
                else
                Console.WriteLine("A");
                return;
            }
            
            //出力
            Console.WriteLine("a");
        }

    }
}


Measured memory_bytes: 25792
N, M = map(int, input().split())
fact = [1]*(N+1)
rfact = [1]*(N+1)
for i in range(1, N+1):
    fact[i] = r = (i * fact[i-1]) % M
    rfact[i] = pow(r, M-2, M)

S = [1]

rev2 = pow(2, M-2, M)
base = pow(2, N, M)
ans = 0
S = [1]
for K in range(N+1):
    res = (fact[N] * rfact[K] * rfact[N-K]) % M
    res = (res * pow(2, pow(2, N - K, M-1), M)) % M
    b = 1
    v = 0
    T = [0]*(K+2)
    for L in range(K):
        T[L+1] = s = (S[L] + (L+1)*S[L+1]) % M
        v += s * b
        b = (b * base) % M
    v += b
    T[K+1] = 1
    S = T
    res = (res * v) % M
    if K % 2:
        ans -= res
    else:
        ans += res
    ans %= M

    base = (base * rev2) % M
print(ans)


Measured memory_bytes: 3436
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define X first
#define Y second
#define sz(v) (int)v.size()
using ord = tree<int, null_type, greater<int>, rb_tree_tag, tree_order_statistics_node_update>;

void solve();

main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
#ifdef ONPC
	freopen("in.txt", "r", stdin);
#endif
	int t = 1;
	//cin >> t;
	while (t--) solve();
	return 0;
}

const int N = 1e5 + 5;
int n, a[N], fenv[N + N];

void inic() {
	for (int i= 0; i < N + N; ++i) fenv[i] = 0;
}

void inc(int r, int add) {
	for (; r < N + N; r += r & -r) fenv[r] +=add;
}

int get(int r) {
	int res= 0;
	for (; r > 0; r -= r & -r) res += fenv[r];
	return res;
}

void solve() {
	cin >> n;
	for (int i = 1; i <= n; ++i) cin >> a[i];
	if (n == 1) {
		cout << a[1] << '\n';
		return;
	}
	ll all = (ll)n * (ll)(n) / (ll)2;
	int lef = 0, rig = 1e9 + 1;
	while (rig - lef > 1) {
		int mid = (lef + rig) / 2;
		ll cur = 0;
		inic();
		inc(N, 1);
		int bal = 0;
		for (int i = 1; i <= n; ++i) {
			int x = a[i];
			if (x >= mid) x = 1;
			else x = -1;
			bal += x;
			cur += get(N + bal);
			inc(N + bal, 1);
		}
		if (cur * 2 >= all) {
			lef = mid;
		} else {
			rig = mid;
		}
	}
	cout << lef << '\n';
}

Measured memory_bytes: 1536
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.LinkedList;


public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.lunchMinimumValueCalculation();
		return;
	}
	
	//昼食の代金の最小値を求める
	private void lunchMinimumValueCalculation() {
		
		BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); //標準入力
		
		LinkedList<Integer> pastaPriceList = new LinkedList<Integer>();
		LinkedList<Integer> juicePriceList = new LinkedList<Integer>();
		
		try {
			
			for (int i = 0; i < 3; i++) {
				String inputStr = bufferedReader.readLine();
				pastaPriceList.add(Integer.parseInt(inputStr));
			}
			
			for (int i = 0; i < 2; i++) {
				String inputStr = bufferedReader.readLine();
				juicePriceList.add(Integer.parseInt(inputStr));
			}
			
			Collections.sort(pastaPriceList);
			Collections.sort(juicePriceList);
			
			int pastaPriceNum = pastaPriceList.get(0);
			int juicePriceNum = juicePriceList.get(0);
			
			System.out.println((pastaPriceNum + juicePriceNum) - 50);
			
		} catch (IOException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		}
		
	}
}

Measured memory_bytes: 17060