akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define pb push_back
#define pi pair<int, int>
#define l first
#define r second
#define all(x) x.begin(), x.end()
#define fori(a, b, step) for (int i = a; i < b; i += step)
#define forj(a, b, step) for (int j = a; j < b; j += step)
#define int long long

const int maxn = 5e5 + 1, CC = 10001;

using namespace std;

string s, t;
int n, m;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n >> m >> s >> t;
    int lc = n * m / __gcd(n, m);
    map<int, int> mp;
    for (int i = 0; i < n; i++) {
        mp[i * m] = i;
    }
    for (int i = 0; i < m; i++) {
        if (mp.find(i * n) != mp.end()) {
            if (t[i] != s[mp[i * n]]) {
                cout << -1;
                return 0;
            }
        }
    }
    cout << lc;
    return 0;
}


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

int main() {
	string S;
	int K, count = 1;
	map<string, int> mp;
	cin >> S >> K;
	for (int i = 0; i < S.size(); i++) {
		for (int j = 1; j <= S.size() - i && j <= K; j++) {
			string x = S.substr(i, j);
			mp[x]++;
		}
	}
	map<string, int>::iterator it;
	for (it = mp.begin(); it != mp.end(); it++) {
		if (count == K) {
			cout << it->first;
			break;
		}
		count++;
	}
}

Measured memory_bytes: 1920
# -*- coding: utf-8 -*-
import math

def main():
    """Function."""
    n, p = map(int, input().split())
    a = list(map(int, input().split()))

    e_count, o_count = 0, 0
    for dum in a:
        if dum % 2 == 0:
            e_count += 1
        else:
            o_count += 1

    total = 0
    if p == 0:
        dum = 1
        for i in range(o_count // 2):
            n = (i + 1) * 2
            dum += (math.factorial(o_count) // (math.factorial(o_count - n) * math.factorial(n)))
        total += (2 ** e_count) * dum

    elif p == 1:
        if o_count == 0:
            pass
        else:
            dum = 0
            for i in range((o_count + 1) // 2):
                n = (i * 2) + 1
                dum += (math.factorial(o_count) // (math.factorial(o_count - n) * math.factorial(n)))
            total += (2 ** e_count) * dum

    print(total)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#063_C
n = int(input())
s = []
min_not_10 = 10 ** 10
for _ in range(n):
    i = int(input())
    s.append(i)
    if i % 10 != 0 and min_not_10 > i:
        min_not_10 = i
        
if sum(s) % 10 != 0:
    print(sum(s))
else:
    if min_not_10 == 10 ** 10:
        print(0)
    else:
        print(sum(s) - min_not_10)

Measured memory_bytes: 3060
#include<stdio.h>
int gcd(int x, int y){
    int tmp;
    tmp = x % y;
    if (tmp == 0)
        return y;
    else
        return gcd(y, tmp);
}
int main(){
    int x, y, tmp;
    scanf("%d %d", &x, &y);
    if (y > x){
        tmp = x;
        x = y;
        y = tmp;
    }
    printf("%d\n", gcd(x, y));
    return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a;
  cin >> a;
  while(a > 0)
  {
    if(a % 10 == 7)
    {
      cout << "Yes" << endl;
      return 0;
    }
    a /= 10;
  }
  cout << "No" << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
  int n, a, b, c, d; cin >> n >> a >> b >> c >> d;
  string s; cin >> s;
  --a; --b; --c; --d;

  // snuke
  bool snuke = true, snukew = false;
  FOR(i, a, c-1){
    if(s[i] == '#' && s[i+1] == '#' || s[i+1] == '#' && s[i+2] == '#') snuke = false;
  }

  if(c > d){
    FOR(i, b-1, d){
      if(s[i] == '.' && s[i+1] == '.' && s[i+2] == '.') snukew = true;
    }
  }

  // hunuke
  bool hunuke = true;
  FOR(i, b, d-1){
    if(s[i] == '#' && s[i+1] == '#' || s[i+1] == '#' && s[i+2] == '#') hunuke = false;
  }
  
  if(!snuke || (!snukew && c > d) || !hunuke)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
    
  return 0;
}


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

using namespace std;

#define ll long long
#define pb push_back
//#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a; i<n; i++)
#define INF (int)1e15
#define MOD 1000000007
//#define N 12
#define sz 1000*1000

 vector<int>v[200005];
 bool vis[200005];

 int bfs(int x){

   queue<int>Q;
   Q.push(x);
   int cnt=0;

   while(!Q.empty()){
       int first = Q.front();
       Q.pop();

       if(vis[first]) continue;
       vis[first] = true , cnt++;

       for(int u:v[first])
            Q.push(u);

      }

      return cnt;
 }

 int main(){

 ll n,m; cin>>n>>m;

 memset(vis,false,sizeof(vis));

 for(int i=0;i<m;i++){
      int a,b;
      cin>>a>>b;
      a; b;
      a--; b--;

 v[a].push_back(b);
 v[b].push_back(a);
 }

//  vector<int>::iterator it = v.begin();

/*
  for(int i=0;i<n;i++){
      cout<<i<<"->";
      for(int j=0;j<v[i].size();j++)
      {
            if(j == v[i].size() - 1)
                    cout << v[i][j] << endl;
            else
                cout << v[i][j] << " --> ";
      }
      cout<<endl;
   }

   */

  int ans = bfs(0);

  // cout<<"ecnerwala "<<ans<<endl;

  for(int i=0;i<n;i++){
     if(!vis[i]){
      int cnt = bfs(i);

        if(cnt > ans)
            ans = cnt;

     }
  }

  cout<<ans<<endl;

 return 0;
 }

Measured memory_bytes: 15128
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int result = 0;
        for(int i=0;i<N;i++){
            String cur = sc.next();
            if(cur.equals("Y")) {
                result =1;
                break;
            }
        }
        String ans;
        if(result==0) ans = "Three";
        else ans = "Four";
        System.out.println(ans);

    }
}

Measured memory_bytes: 20688
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int h,w,ans=0;
    cin>>h>>w;
    int dp[h+1][w+1];
    memset(dp,0,sizeof(dp));
    int a[h][w];
    for(int i=0;i<h;i++)for(int j=0;j<w;j++)cin>>a[i][j];
    for(int i=0;i<h;i++){
    	for(int j=0;j<w;j++){
    		if(a[i][j]){
    			dp[i+1][j+1]=0;
    		}else{
    			dp[i+1][j+1]=min(dp[i][j+1],min(dp[i+1][j],dp[i][j]))+1;
    			ans=max(ans,dp[i+1][j+1]);
    		}
    	}
    }
    cout << ans*ans<<endl;
    return 0;
}




Measured memory_bytes: 18456
#include <bits/stdc++.h>
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
using namespace std;
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
string to_string(char c) { return "'" + string(1, c) + "'";}
string to_string(string s) { return '"' + s + '"';}
string to_string(const char* s) { return to_string((string) s);}
template<typename A> string to_string(A);
template<typename A, typename B> string to_string(pair<A, B> p){
  return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";}
template<typename A> string to_string(A v) {bool f = false; string r = "{"; 
  for (auto x: v) {if (f) r += ", "; r += to_string(x); f = true;} return r += "}";}
template<typename A> string to_string(vector<vector<A>> v) {string r; 
  for (auto x: v) r += "\n" + to_string(x); return r;}
void err(istream_iterator<string>) { cerr << endl; }
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << to_string(a) << "; "; err(++it, args...); }
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
int const MOD = 1e9 + 7;
long long const INF = 1e18 + 42;
/*************************************/

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int n;
  cin >> n;
  vector<int> p(n), q(n), a(n);
  iota(ALL(a), 1);
  for (int &x : p) cin >> x;
  for (int &x : q) cin >> x;
  int u = -1, v = -1;
  int i = 0;
  do {
    if (a == p) u = i;
    if (a == q) v = i;
    ++i;
  } while (next_permutation(ALL(a)));
  kek(abs(u - v));
}


Measured memory_bytes: 256
# coding: utf-8


def solve(*args: str) -> str:
    n = int(args[0])
    s = args[1]

    c = ''
    q = 0
    for i in range(n):
        if c != s[i]:
            q += 1
        c = s[i]

    return str(q)


if __name__ == "__main__":
    print(solve(*[input() for _ in range(2)]))


Measured memory_bytes: 39408
use std::io::stdin;
use std::str::FromStr;

fn read_line<T>() -> Vec<T>
where
    T: FromStr,
    <T as std::str::FromStr>::Err: std::fmt::Debug,
{
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect()
}

fn gcd(a: usize, b: usize) -> usize {
    if a % b == 0 {
        b
    } else {
        gcd(b, a % b)
    }
}

fn gcd_three(a: usize, b: usize, c: usize) -> usize {
    let tmp = gcd(a, b);
    gcd(tmp, c)
}

fn main() {
    let in_vec: Vec<usize> = read_line();
    let k = in_vec[0];

    let mut res: i64 = 0;
    for a in 1..k+1 {
        for b in 1..k+1 {
            for c in 1..k+1 {
                res += gcd_three(a, b, c) as i64;
            }
        }
    }

    println!("{}", res);
}


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

void dfs(llong cur, llong & maxN, int use, llong & counter) {
	if (cur > maxN) return; // 終端条件
	if (use == 0b111) counter++;

	dfs(cur * 10 + 3, maxN, use | 0b001, counter);
	dfs(cur * 10 + 5, maxN, use | 0b010, counter);
	dfs(cur * 10 + 7, maxN, use | 0b100, counter);
}

int main(void) {
	llong N; cin >> N;
	llong res = 0;
	dfs(0, N, 0, res);
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7+1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

/*--------------------template--------------------*/

ll v[100];

int main()
{
	while (1) {
		cin >> n >> k;
		if (n == 0 && k == 0) {
			return 0;
		} else {
			vi v(n + 1);
			REP(i, n + 1)
				v[i] = n + 1 - i;
			REP(i, k)
			{
				ll p, c;
				cin >> p >> c;
				REP(j, c)
				{
					ll tmp = v[p + j];
					for (int l = p; l >= 1; l--) {
						v[j + l] = v[j + l - 1];
					}
					v[j + 1] = tmp;
				}
			}
			cout << v[1] << endl;
		}
	}
}

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 11451419194545;

int main(){

    ll N; 
    string S;
    cin >> N >> S;

    vector<ll > A(N, 0);

    if(S.size() % 2 != 0){
        cout << "No" << endl;
        return 0;
    }

    if(S.substr(0, S.size()/2) == S.substr(S.size()/2, S.size()/2)){
        cout << "Yes" << endl;
        return 0;
    }else{
        cout << "No" << endl;
    }


}

Measured memory_bytes: 256
import math

def is_ok(A, x, K):
  cut_count = 0
  for number in A:
    cut_count += (math.ceil(number / x)) - 1
  return cut_count <= K

A = []
[N, K] = input().split()
N = int(N)
K = int(K)
A = input().split()
ans = 0

l = 0
r = 10 ** 9

for i in range(N):
  A[i] = int(A[i])

while r - l > 1:
  x = (r + l) // 2
  if is_ok(A, x, K):
    r = x
  else:
    l = x
      
print(r)

Measured memory_bytes: 24956
n = gets.to_i
vec = Array.new(4) { Array.new(13) }
suits = %w[S H C D]

n.times do
  suit, rank = gets.split
  suit_index = suits.index(suit)
  vec[suit_index][rank.to_i - 1] = 1
end

vec.each_with_index do |v, i|
  v.each_with_index do |w, j|
    next unless w.nil?

    suit = suits[i]
    rank = j + 1
    puts "#{suit} #{rank}"
  end
end



Measured memory_bytes: 6872
gets.to_i.times{
  gets
  a=gets.split.map &:to_i
  s=gets.chop.chars
  r=0
  b=[]
  a.zip(s).reverse.map{|a,f|
    b.map{a=[a,a^_1].min}
    f[?0]?b<<a:r=1 if a!=0
  }
  p r
}

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

using namespace std;

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

int main() {
  long long a, b;
  cin >> a >> b;
  cout << a * b / gcd(a, b);
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize(3)
#include<cstdio>
#include<cstring>
#include<vector>
#include<iostream>
using namespace std;
int n,m,cnt,ans,k[11],p[11],s[11][11],l[11];
vector<int>v[11];
inline string Itoa(int x) {
	string s="";
	while(x>=2) {
		s=char(x%2+48)+s;
		x/=2;
	}
	s=char(x+48)+s;
	return s;
}
inline bool check(string x) {
	memset(l,0,sizeof(l));
	cnt=1;
	for(register int i=x.length()-1;i>=0;i--,cnt++)if(x[i]=='1')for(register int j=0;j<v[cnt].size();j++)l[v[cnt][j]]++;
	for(register int i=1;i<=m;i++)if(l[i]%2!=p[i])return false;
	return true;
}
int main() {
	scanf("%d%d",&n,&m);
	for(register int i=1; i<=m; i++) {
		scanf("%d",&k[i]);
		for(register int j=1; j<=k[i]; j++) {
			scanf("%d",&s[i][j]);
			v[s[i][j]].push_back(i);
		}
	}
	for(register int i=1; i<=m; i++)scanf("%d",&p[i]);
	for(register int i=0; i<(1<<n); i++){
		if(check(Itoa(i)))ans++;
	}
	printf("%d",ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	string s;
	cin>>s;
	vector<int> a(4);
	rep(i,4) a[i]=int(s[i]-'0');
	rep(i,1<<3){
		string ans;
		bool flag=true;
		int now=a[0];
		rep(j,3){
			if(i & (1<<j)){
				now+=a[j+1];
				ans.push_back('+');
			}else{
				now-=a[j+1];
				ans.push_back('-');
			}
		}
		if(now==7){
			cout<<a[0]<<ans[0]<<a[1]<<ans[1]<<a[2]<<ans[2]<<a[3]<<"=7"<<endl;
			return 0;
		}
	}
}

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

int main() {

	long long n;
    cin >> n;
  
  	long long sum = 0;
  	int i = 1;
  
  	while ( i <= n ){
      if ( i % 3 != 0 && i % 5 != 0 ){
        sum += i;
      }
      i++;
    }
 
	cout << sum << endl;
  
}



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

typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100003;

int main(){
    
    string S;cin>>S;
    bool check=false;
    if(S[0]==S[1]&&S[2]==S[3]&&S[0]!=S[2]) check=true;
    if(S[0]==S[2]&&S[1]==S[3]&&S[0]!=S[1]) check=true;
    if(S[0]==S[3]&&S[1]==S[2]&&S[0]!=S[1]) check=true;
    if(check) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 764
from math import factorial
from sys import exit, stdin
S = list(stdin.readline().rstrip())
N = len(S)-1
ans = 0
for i in range(1 << N):
    tmp = []
    tmp.append(S[0])
    for j in range(N):
        if ((i >> j) & 1):
            tmp.append("+")
            tmp.append(S[j+1])
        else:
            tmp.append(S[j+1])
    ans += eval("".join(tmp))
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
  int n, a[101] ;
  scanf("%d", &n) ;

  int i, j ;
  for( i = 0 ; i < n ; i++ ){
    scanf("%d", &a[i]) ;
  }

  int tmp, cnt, min_i ;
  cnt = 0 ;
  for( i = 0 ; i < n-1 ; ++i ){  // i = 未ソート部分の先頭
    min_i = i ;
    for( j = i ; j < n ; ++j ){
      if( a[min_i] > a[j] ){
        min_i = j ;
      }
    }
    if( i != min_i){
      tmp      = a[min_i] ;
      a[min_i] = a[i] ;
      a[i]     = tmp ;
      cnt++ ;
    }
  }

  for( i = 0 ; i < n-1 ; i++ ){
    printf("%d ", a[i]) ;
  }
  printf("%d\n%d\n", a[n-1], cnt) ;

  return 0 ;
}


Measured memory_bytes: 2108
#include <iostream>
using namespace std;
int main()
{
	int l, r, d, ans = 0;
	cin >> l >> r >> d;
	for (int i = l; i <= r; i++)
	{
		if (i % d == 0)
			ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
	int N;
  	cin >> N;
  	if(N % 2 == 0)cout << 0.5 << endl;
  	else cout << ((static_cast<int>(N / 2) + 1) / static_cast<double>(N)) << endl;
  	return 0;
}

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

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

    ll bottleNeck = min(a, min(b, min(c, min(d, e))));
    ll ans = (n + bottleNeck - 1) / bottleNeck + 4;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#define LONG_INF 10000000000000000
#define REP(i,N) for(int i = 0; i < (N); i++)

using namespace std;

int main() {
	string s;
	int n=0;

	cin >> s;
    for (int i = 0; i < 4; i++) {
        if(s[i]=='+')n++;
        else n--;
	}


	cout << n << endl;
}


Measured memory_bytes: 256
/*********************
*  Author: xuziyuan  * 
*********************/

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

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

Measured memory_bytes: 256
// Try AtCoder
// author: Leonardone @ NEETSDKASU

fn main() {
    let mut stdin = String::new();
    std::io::Read::read_to_string(&mut std::io::stdin(), &mut stdin).unwrap();
    let mut stdin = stdin.split_whitespace();
    macro_rules! get { () => (stdin.next().unwrap().parse().unwrap()) }
    
    let n: i32 = get!();
    let mut x = n;
    let mut f = 0;
    while x > 0 {
        f += x % 10;
        x /= 10;
    }
    let ans = if n % f == 0 { "Yes" } else { "No" };
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
long long num[1000005];
long long ans[1000005];
int prime(long long x)
{
    if(x==1||x==2|x==3)
    {
        return 1;
    }
    int s=sqrt(x);
    for(int i=2;i<=s;i++)
    {
        if(x%i==0)
        {
            return 0;
        }
    }
    return 0;
}
int main()
{
    long long a,b,cnt=0,m=0;
    scanf("%lld%lld",&a,&b);
    long long k=__gcd(a,b);
    cnt++;
    for(long long i=2;i*i<=k;i++)
    {
        if(k%i==0)
        {
            cnt++;
        }
        while(k%i==0)
        {
            k/=i;
        }
    }
    if(k>1)
    {
        cnt++;
    }
    printf("%lld\n",cnt);
    return 0;
}


Measured memory_bytes: 128
N=int(input())
B=[int(s) for s in input().split()]


count=0
n=N-1
A=[int(0) for _ in range(N)]
for i in range(0,n):
    A[i]=B[i]

for i in range(0,n):
    if A[i+1]>B[i]:
        A[i+1]=B[i]
        
for i in range(0,n):
    count+=A[i]
    
count+=B[n-1]
print(count)


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/02/15  Problem: 054_abc_d / Link: https://abc054.contest.atcoder.jp/tasks/abc054_d?lang=en  ----- */
/* ------問題------

イルカは、微量の物質Cを生成したいと考えています。
物質Cを生成するためには、タイプAの物質とタイプBの物質の混合比が Ma:Mb となる溶液を用意する必要があります。
しかし、イルカは薬品を1つも持っていないため、薬局へ薬品を買いに行くことにしました。
薬局では、N 種類の薬品を取り扱っており、各薬品 i の在庫はちょうど1つです。
各薬品 i は、タイプAの物質 ai グラム、タイプBの物質 bi グラム含んでおり、価格 ci 円で売られています。 
イルカは、いくつかの薬品を薬局で買います。買った薬品は全て使わなければなりません。
物質Cを生成するために、必要な最小予算を求めてください。 
薬局で売られている薬品の組み合わせで、物質Cを生成できない場合はそれを報告してください。

-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N,A,B;

LL ans = 0LL;

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

	cin >> N>>A>>B;
	VI a(N), b(N), c(N);
	FOR(i, 0, N) {
		cin >> a[i] >> b[i] >> c[i];
	}

	VVI dp(401, VI(401, INF));

	dp[0][0] = 0;
	FOR(i, 0, N) {
		FORR(aa, 400, 0-1) {
			FORR(bb, 400, 0-1) {
				if(aa+a[i]<=400&&bb+b[i]<=400)dp[aa+a[i]][bb+b[i]] = min(dp[aa+a[i]][bb+b[i]], dp[aa][bb] + c[i]);
			}
		}
	}
	ans = INF;
	FOR(i, 1, 401) {
		if (A*i<=400 && B*i<=400) {
			ans = min(ans, (long long )dp[A*i][B*i]);
		}
	}
	if (ans == INF)ans = -1;
	cout << ans << "\n";

	return 0;
}


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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin (),(x).end()
#define sqrt(x) sqrt(abs(x))
#define re return
#define sz(x) ((int)(x).size ())
#define prev PREV
#define next NEXT

using ll = long long;
using ii = pair<int, int>;
using ld = long double;
using D = double;
using vi = vector<int>;
using vii = vector<ii>;
using vvi = vector<vi>;
using vs = vector<string>;

template<typename T> T abs (T x) { re x < 0 ? -x : x; }
template<typename T> T sgn (T x) { re x < 0 ? -1 : (x > 0 ? 1 : 0); }
template<typename T> T sqr (T x) { re x * x; }
template<typename T> T gcd (T a, T b) { re a != 0 ? gcd (b % a, a) : b; }

const int N = 1 << 18;

int n;
int m;
int top[N];
int tin[N];
int ct;
vi v[N];
int res[N];
int ans[N];

int go (int x, int p, int up) {
	top[x] = up;
	tin[x] = ct++;
	for (int i = 0; i < sz (v[x]); i++) {
		int y = v[x][i];
		if (y == p) continue;
		go (y, x, max (up, x));
	}
	re 0;
}

int dfs (int x, int f) {
	int cur = 1;
	for (int i = 0; i < sz (v[x]); i++) {
		int y = v[x][i];
		if (tin[y] < tin[x] || y >= f) continue;
		cur += dfs (y, f);
	}
	re cur;
}

int go2 (int x, int cur) {
	cur += res[x];
	ans[x] = cur;
	for (int i = 0; i < sz (v[x]); i++)
		if (tin[v[x][i]] > tin[x])
			go2 (v[x][i], cur);
	re 0;
}

int main () {
	scanf ("%d", &n);
	for (int i = 0; i < n - 1; i++) {
		int a, b;
		scanf ("%d%d", &a, &b); a--; b--;
		v[a].pb (b);
		v[b].pb (a);
	}
	go (0, 0, 0);
	for (int i = n - 1; i >= 0; i--) {
//		printf ("%d = %d\n", i + 1, top[i] + 1);
		if (top[i] > i) continue;
		res[i] = 1;
		for (int j = 0; j < sz (v[i]); j++) {
			int x = v[i][j];
			if (tin[x] < tin[i]) continue;
			res[x] = dfs (x, i);
//			printf ("%d += %d\n", j + 1, res[j]);
			if (x > top[i]) continue;
			int tmp = dfs (x, top[i]);
//			printf ("%d %d -= %d\n", j + 1, i + 1, res[j]);
			res[x] -= tmp;
			res[i] += tmp;
		}
	}
	res[0] = 0;
//	for (int i =0 ; i < n; i++) printf ("%d = %d\n", i + 1, res[i]);
	go2 (0, 0);
	for (int i = 1; i < n; i++) printf ("%d ", ans[i]);
	printf ("\n");
	return 0;
}

Measured memory_bytes: 32512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		char c = sc.next().charAt(0);
		c++;
		System.out.println(c);
		sc.close();
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
  int n,x,q,k;
    vector<int>v;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        v.push_back(x);
    }
    cin>>q;
    for(int i=0;i<q;i++)
    {
        cin>>k;
        vector<int>::iterator s,t;
        s=lower_bound(v.begin(),v.end(),k);
        t=upper_bound(v.begin(),v.end(),k);
        cout<<s-v.begin()<<" "<<t-v.begin()<<endl;
    }
    return 0;
}



Measured memory_bytes: 3540
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std ;

const int N = 200010 ; 

int cnt ;
int res ;
int n, m ; 
int tg[N] ;
char S[N] ; 
char t[N] ;
char c[4] ; 
int main(){
	cin >> (S + 1) ; 
	int w ;
	cin >> m ; n = strlen(S + 1) ; 
	for (int i = 1 ; i <= m ; ++ i){
		cin >> w ; int k ; 
		if (w == 1) res ^= 1 ; 
		else cin >> k >> c, -- k, t[++ cnt] = c[0], tg[cnt] = res ^ k ;
	}
	if (res == 1)
		for (int i = 1 ; i <= cnt ; ++ i) tg[i] ^= 1 ; 
	for (int i = cnt ; i >= 1 ; -- i) 
		if (!tg[i]) cout << t[i] ; 
	if (!res) for (int i = 1 ; i <= n ; ++ i) cout << S[i] ; 
	else for (int i = n ; i >= 1 ; -- i) cout << S[i] ; 
	for (int i = 1 ; i <= cnt ; ++ i) 
		if (tg[i]) cout << t[i] ; 
	return 0 ; 
}

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

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i, n) {
    cin >> d.at(i);
  }
  sort(d.begin(), d.end());
  int hanbun = n / 2;
  int ans;
  ans = d[hanbun] - d[hanbun-1];
  cout << ans << endl;
}


Measured memory_bytes: 640
number=int(input())
div100=int(number//100)
get100=div100*100
diff100=number-get100
div5=int(diff100//5) #24...div5 4 mod5 4
mod5=diff100%5
if (div5*100<number and number>=100 and div100*5>=diff100)or diff100%100==0:
  print("1")
else:
  print("0")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b,x,ans=1e9;
    cin>>a>>b>>x;
    for(int i=0;i<=20000;i++){
        int c=x-(i*1000);
        if(c<=0)ans=min(a*i,ans);
        else{
            if(c%500==0)ans=min(a*i+c/(500)*b,ans);
            else ans=min(a*i+(c/(500)+1)*b,ans);
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3100
import sys
sys.setrecursionlimit(1000000)

n,m = map(int,input().split())
e = [[] for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    e[a-1].append(b-1)
def dfs(x):
    num = 0
    for nex in e[x]:
        if dis[nex] < 0:
            dfs(nex)
        num = max(num,dis[nex]+1)
    dis[x] = num
    return 
dis = [-1]*n
for i in range(n):
    if e[i] and dis[i] < 0 :
        dfs(i)
print(max(dis))

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define ALL(v) v.begin(), v.end()

int main() {
    set<int> s;
    int a;
    REP (i, 3) {
        cin >> a;
        s.insert(a);
    }

    if (s.size() == 2) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

int main() {
  string S;
  cin >> S;
  int a = 0, b = 0;
  
  for (int i = 0; i < S.size(); i++){
    if (S.at(i) == '0')
      a++;
    if (S.at(i) == '1')
      b++;
    
  }
  
  int ans = 2 * min(a,b);
  
  cout << ans << endl;
}

Measured memory_bytes: 512
def resolve():
    '''
    code here
    '''

    S = input()

    is_flag = False
    key = 'keyence'

    for i in range(8):
        if i == 0:
            if S[-7:] == key:
                is_flag = True

        elif 1 <= i < 7:
            if S[:i] == key[:i] and S[-1*(7-i):] == key[-1*(7-i):]:
                is_flag = True
        else:
            if S[:7] == key:
                is_flag = True

    print('YES') if is_flag else print('NO') 


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 3064
#include <cstdio>
#include <cctype>
template <class T>
void read(T &x)
{
	x=0;char c=getchar();
	while(!isdigit(c)) c=getchar();
	while(isdigit(c)) x=x*10+c-'0',c=getchar();
}
const int N=1e5+10;
const int mod=1e9+7;
int n,yuy[26];
char s[N];
int main()
{
	read(n);
	scanf("%s",s+1);
	for(int i=1;i<=n;i++)
		++yuy[s[i]-'a'];
	int ans=1;
	for(int i=0;i<26;i++) ans=1ll*ans*(yuy[i]+1)%mod;
	printf("%d\n",ans==0?mod-1:ans-1);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int N;
    int n[4];

    scanf("%d", &N);
    for(int i=0; i<4; i++){
      n[3-i] = N % 10;
      N /= 10;
    }

    if((n[0] == n[1] && n[1] == n[2]) || (n[1] == n[2] && n[2] == n[3])){
      printf("Yes\n");
    } else {
      printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 256
N,X = map(int,input().split())
L =[0] + list(map(int,input().split()))

D = [0 for i in range(N+2)]
cnt = 1
for i in range(2,N+2):
  D[i] = D[i-1] + L[i-1]
  if D[i] > X:
    break
  else:  
    cnt += 1
print(cnt)

Measured memory_bytes: 38384
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define mt make_tuple
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef stringstream sst;
typedef vector<ll> vi;

int n,m,r,A[55],B[55],K[66],X[66][11],Y[66];
int V;
vi x1,x2,y;
bool dp1[55][55][600],dp2[55][55][600];
bool ok[55][55][55][55];
int dp[55][55][55][55];

void f(int n,int A[],bool dp[][55][600]){
	rep(i,2*n-1){
		dp[i][i][A[i]]=1;
	}
	rep2(len,2,n+1)rep(from,2*n-len){
		int to=from+len-1;
		rep2(cut,from,to)rep(rule,sz(x1)){
			dp[from][to][y[rule]] |=
			dp[from][cut][x1[rule]] & dp[cut+1][to][x2[rule]];
		}
	}
}

void main2(){
	rep(i,n-1)A[i+n]=A[i];
	rep(i,m-1)B[i+m]=B[i];
	V=31;
	x1.clear();
	x2.clear();
	y.clear();
	rep(i,r){
		if(K[i]==2){
			x1.pb(X[i][0]);
			x2.pb(X[i][1]);
			y.pb(Y[i]);
		}
		else rep(k,K[i]-1){
			if(k==0){
				x1.pb(X[i][0]);
				x2.pb(X[i][1]);
				y.pb(V++);
			}else if(k==K[i]-2){
				x1.pb(V-1);
				x2.pb(X[i][k+1]);
				y.pb(Y[i]);
			}else{
				x1.pb(V-1);
				x2.pb(X[i][k+1]);
				y.pb(V++);
			}
		}
	}
	
	memset(dp1,0,sizeof(dp1));
	memset(dp2,0,sizeof(dp2));
	f(n,A,dp1);
	f(m,B,dp2);
	
	memset(ok,0,sizeof(ok));
	rep(from1,2*n-1)rep2(to1,from1,2*n-1){
		rep(from2,2*m-1)rep2(to2,from2,2*m-1){
			rep(var,V){
				ok[from1][to1][from2][to2] |=
				dp1[from1][to1][var] & dp2[from2][to2][var];
			}
		}
	}
	
	memset(dp,0,sizeof(dp));
	rep(from1,2*n)rep2(to1,max(0,from1-1),2*n-1){
		rep(from2,2*m)rep2(to2,max(0,from2-1),2*m-1){
			dp[from1][to1][from2][to2]=
			to1==from1-1 && to2==from2-1 ? 0 : -INF;
		}
	}
	int ans=-1;
	rep2(len1,1,n+1)rep2(len2,1,m+1){
		rep(from1,2*n-len1)rep(from2,2*m-len2){
			int to1=from1+len1-1,to2=from2+len2-1;
			rep2(cut1,from1,to1+1)rep2(cut2,from2,to2+1){
				if(ok[from1][cut1][from2][cut2]){
					dp[from1][to1][from2][to2]=
					max(dp[from1][to1][from2][to2],1+dp[cut1+1][to1][cut2+1][to2]);
				}
			}
			if(len1==n && len2==m){
				ans=max(ans,dp[from1][to1][from2][to2]);
			}
		}
	}
	cout<<ans<<endl;
}

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	while(cin>>n>>m>>r && n){
		rep(i,n)cin>>A[i];
		rep(i,m)cin>>B[i];
		rep(i,r){
			cin>>K[i];
			rep(j,K[i])cin>>X[i][j];
			cin>>Y[i];
		}
		main2();
	}
}

Measured memory_bytes: 49456
#![allow(unused_imports)]
#![allow(non_snake_case, unused)]

use std::cmp::*;
use std::collections::*;
use std::ops::*;

macro_rules! eprint {
	($($t:tt)*) => {{
		use ::std::io::Write;
		let _ = write!(::std::io::stderr(), $($t)*);
	}};
}
macro_rules! eprintln {
	() => { eprintln!(""); };
	($($t:tt)*) => {{
		use ::std::io::Write;
		let _ = writeln!(::std::io::stderr(), $($t)*);
	}};
}
macro_rules! dbg {
	($v:expr) => {{
		let val = $v;
		eprintln!("[{}:{}] {} = {:?}", file!(), line!(), stringify!($v), val);
		val
	}}
}

macro_rules! mat {
	($($e:expr),*) => { Vec::from(vec![$($e),*]) };
	($($e:expr,)*) => { Vec::from(vec![$($e),*]) };
	($e:expr; $d:expr) => { Vec::from(vec![$e; $d]) };
	($e:expr; $d:expr $(; $ds:expr)+) => { Vec::from(vec![mat![$e $(; $ds)*]; $d]) };
}

macro_rules! ok {
	($a:ident$([$i:expr])*.$f:ident()$(@$t:ident)*) => {
		$a$([$i])*.$f($($t),*)
	};
	($a:ident$([$i:expr])*.$f:ident($e:expr$(,$es:expr)*)$(@$t:ident)*) => { {
		let t = $e;
		ok!($a$([$i])*.$f($($es),*)$(@$t)*@t)
	} };
}

pub fn readln() -> String {
	let mut line = String::new();
	::std::io::stdin().read_line(&mut line).unwrap_or_else(|e| panic!("{}", e));
	line
}

macro_rules! read {
	($($t:tt),*; $n:expr) => {{
		let stdin = ::std::io::stdin();
		let ret = ::std::io::BufRead::lines(stdin.lock()).take($n).map(|line| {
			let line = line.unwrap();
			let mut it = line.split_whitespace();
			_read!(it; $($t),*)
		}).collect::<Vec<_>>();
		ret
	}};
	($($t:tt),*) => {{
		let line = readln();
		let mut it = line.split_whitespace();
		_read!(it; $($t),*)
	}};
}

macro_rules! _read {
	($it:ident; [char]) => {
		_read!($it; String).chars().collect::<Vec<_>>()
	};
	($it:ident; [u8]) => {
		Vec::from(_read!($it; String).into_bytes())
	};
	($it:ident; usize1) => {
		$it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1
	};
	($it:ident; [usize1]) => {
		$it.map(|s| s.parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1).collect::<Vec<_>>()
	};
	($it:ident; [$t:ty]) => {
		$it.map(|s| s.parse::<$t>().unwrap_or_else(|e| panic!("{}", e))).collect::<Vec<_>>()
	};
	($it:ident; $t:ty) => {
		$it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<$t>().unwrap_or_else(|e| panic!("{}", e))
	};
	($it:ident; $($t:tt),+) => {
		($(_read!($it; $t)),*)
	};
}

pub fn main() {
	let _ = ::std::thread::Builder::new().name("run".to_string()).stack_size(32 * 1024 * 1024).spawn(run).unwrap().join();
}

const MOD: i64 = 1_000_000_007;
const INF: i64 = std::i64::MAX/2;

fn solve() {
	let (n,k) = read!(i64, i64);
	let mut ans = 0;
	for i in k..(n+2) {
		let left = i*(i-1)/2;
		let right = (n+(n-i+1))*i/2;
		ans += right-left+1;
		ans %= MOD;
	}
	println!("{}", ans);
}


fn run() {
    solve();
}


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

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

  int minTimes = 1000000000;

  for (int i=0;i<n;i++) {
    int a;
    int times = 0;
    cin >> a;
    for (int j=0;a % 2 == 0;j++) {
      a /= 2;
      times += 1;
    }
    if (times < minTimes) {
      minTimes = times;
    }
  }

  cout << minTimes << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
const ll mo = 1000000007;
const ll INF = 1 << 30;
ll ans = 0;

int main()
{
ll n;
cin >> n;
ll temp=1;
while(true){
    if((n-temp)%temp==0&&(n-temp)/temp>temp){
        ans+=(n-temp)/temp;
    }
    if((n-temp)/temp<temp)break;
    
    temp++;
}

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

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();

            var aa = int.Parse(s.Substring(0, 2));
            var bb = int.Parse(s.Substring(2));

            if (aa != 0 && aa < 13)
            {
                if (bb != 0 && bb < 13)
                    Console.WriteLine("AMBIGUOUS");
                else
                    Console.WriteLine("MMYY");
            }
            else
            {
                if (bb != 0 && bb < 13)
                    Console.WriteLine("YYMM");
                else
                    Console.WriteLine("NA");
            }

        }

    }
}


Measured memory_bytes: 11092
from collections import defaultdict
import sys
input = sys.stdin.readline

class UnionFind:
    def __init__(self, N):
        self.parent = list(range(N))
        self.rank = [0] * N
        self.size = [1] * N

    def find(self, x):
        if self.parent[x] != x:
            self.parent[x] = self.find(self.parent[x])
        return self.parent[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
            self.size[y] += self.size[x]
        else:
            self.parent[y] = x
            self.size[x] += self.size[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def get_size(self, x):
        return self.size[self.find(x)]

N = int(input())
a = [-1] * (10**5+1)
uf = UnionFind(10**5+1)
xs = [set() for _ in range(10**5+1)]
for _ in range(N):
    x, y = map(int, input().split())
    if a[x] == -1:
        a[x] = y
    else:
        uf.unite(a[x], y)
    xs[y].add(x)

root = defaultdict(set)
for y in range(10**5+1):
    root[uf.find(y)] |= xs[y]
ans = 0
for y in range(10**5+1):
    ans += len(root[uf.find(y)]) - len(xs[y])
print(ans)

Measured memory_bytes: 96032
#include<iostream>
#include<cstdio>
#include<algorithm>
#define Lens 101
#define Inf 1<<22

using namespace std;
int N;
int w[Lens][Lens],p[Lens],d[Lens];
char c[Lens];

void dijkstra()
{
	d[0] = 0;
	while (true)
	{
		int u = -1;
		int minv = Inf;
		for (int i = 0; i < N; i++)
		{
			if (c[i] == 'w'&&minv > d[i])
			{
				minv = d[i];
				u = i;
			}
		}
		if (u == -1) break;
		c[u] = 'b';
		for (int v = 0; v < N; v++)
		{
			if (c[v] == 'w'&&w[u][v] != Inf)
				d[v] = min(d[v], w[u][v]+d[u]);
		}
	}
}

int main()
{
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		c[i] = 'w';
		d[i] = Inf;
		p[i] = -1;
		int u,n;
		cin >> u >> n;
		for (int j = 0; j < n; j++)
		{
			int v, tw;
			cin >> v >> tw;
			w[u][v] = tw;
		}
	}
	for(int i=0;i<N;i++)
		for (int j = 0; j < N; j++)
		{
			if (w[i][j] == 0)
				w[i][j] = Inf;
		}
	dijkstra();
	for (int i = 0; i < N; i++)
		cout << i <<' '<< d[i] << endl;
	return 0;
}


Measured memory_bytes: 3104
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	static BufferedReader in;
	static PrintWriter out;
	static StringTokenizer tok;

	private void solve() throws IOException {
		int T = 1;
		for (int t = 0; t < T; t++) {
			int n = ni();
			char[] a = ns().toCharArray();
			int cntW[] = new int[a.length];
			int cntE[] = new int[a.length];
			for (int i = 1; i < a.length; i++)
				cntE[i] = a[i - 1] == 'E' ? cntE[i - 1] + 1 : cntE[i - 1];
			for (int i = a.length - 2; i >= 0; i--)
				cntW[i] = a[i + 1] == 'W' ? cntW[i + 1] + 1 : cntW[i + 1];

			int ans = 0;
			for (int i = 0; i < a.length; i++)
				ans = Math.max(ans, cntE[i] + cntW[i]);
			out.println(n - 1 - ans);
		}

	}

	String ns() throws IOException {
		while (!tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine(), " ");
		}
		return tok.nextToken();
	}

	int ni() throws IOException {
		return Integer.parseInt(ns());
	}

	long nl() throws IOException {
		return Long.parseLong(ns());
	}

	double nd() throws IOException {
		return Double.parseDouble(ns());
	}

	String[] nsa(int n) throws IOException {
		String[] res = new String[n];
		for (int i = 0; i < n; i++) {
			res[i] = ns();
		}
		return res;
	}

	int[] nia(int n) throws IOException {
		int[] res = new int[n];
		for (int i = 0; i < n; i++) {
			res[i] = ni();
		}
		return res;
	}

	long[] nla(int n) throws IOException {
		long[] res = new long[n];
		for (int i = 0; i < n; i++) {
			res[i] = nl();
		}
		return res;
	}

	public static void main(String[] args) throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		tok = new StringTokenizer("");
		Main main = new Main();
		main.solve();
		out.close();
	}
}

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

void shuffle(void);
void cut(int k);
void copy(void);

int n,m,k;
int ans[201];
int buff[201];

int main(void){
    
    
    cin>>n>>m;
    
    for(int i=1;i<=2*n;i++){
        ans[i]=i;
    }
    
    for(int i=0;i<m;i++){
        cin>>k;
        if(k==0){shuffle();}
        else{cut(k);}
    }
    
    for(int i=1;i<=2*n;i++){
        cout<<ans[i]<<endl;
    }
}

void copy(void){
    for(int i=1;i<=2*n;i++){
        buff[i]=ans[i];
    }
}

void shuffle(void){
    copy();
    int j;
    j=1;
    for(int i=1;i<=2*n;i+=2){
        ans[i]=buff[j];
        ans[i+1]=buff[j+n];
        j++;
    }
}

void cut(int k){
    copy();
    int j;
    j=1;
    for(int i=1;i<=2*n-k;i++){
        ans[i]=buff[k+i];
    }
    for(int i=2*n-k+1;i<=2*n;i++){
        ans[i]=buff[j];
        j++;
    }
}


Measured memory_bytes: 3100
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int lcs(string s, string t) {
  int n = s.length();
  int m = t.length();
  s = " " + s;
  t = " " + t;
  // dp[i][j] := sのi文字目, tのj文字目まで見たときの LCS
  vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (s[i] == t[j]) {
        dp[i][j] = dp[i - 1][j - 1] + 1;
      } else {
        dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
      }
    }
  }
  return dp[n][m];
}

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

  while (q--) {
    string s, t;
    cin >> s >> t;
    cout << lcs(s, t) << endl;
  }
  return 0;
}


Measured memory_bytes: 6856
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ull B = 100000007;
ll mod = 1000000007;
int INF = 0x3f3f3f3f;


int main() {
    ll a, b, n;
    cin >> a >> b >> n;
    if(b == 1) {
        cout << 0 << endl;
    }
    else {
        double maxid = b - 1;
        if(n >= maxid) {
            cout << (ll)floor((double)a * (maxid) / (double)b) << endl;
        }
        else {
            cout << (ll)floor((double)a * n / (double)b) << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 3712
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

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

  std::vector<int> V(N), C(N);
  std::vector<std::pair<int, int>> A(N);

  for (int i = 0; i < N; i++) {
    std::cin >> V[i];
  }

  for (int i = 0; i < N; i++) {
    std::cin >> C[i];
  }

  for (int i = 0; i < N; i++) {
    A[i] = std::make_pair(V[i],  C[i]);
  }

  std::sort(A.begin(), A.end(), [&](const std::pair<int, int>& a, const std::pair<int, int>& b) {
    return a.first - a.second < b.first - b.second;
  });

  int best_c = 0, best_v = 0, answer = 0;

  for (int i = N - 1; i >= 0; i--) {
    best_v += A[i].first;
    best_c += A[i].second;

    answer = std::max(answer, best_v - best_c);
  }

  std::cout << answer << std::endl;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vi vector<int>
#define vll vector<ll>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pb  push_back
#define ppb pop_back
#define mp  make_pair
int main(){
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif
	ll n;
	cin>>n;
	ll A[n],B[n-1];
	for(ll i=0;i<n-1;++i){
		cin>>B[i];
	}
	for(ll i=1;i<n-1;++i){
		A[i]=min(B[i-1],B[i]);
	}
	A[0]=B[0];
	A[n-1]=B[n-2];
	ll ans=0;
	for(ll i=0;i<n;++i){
		ans+=A[i];
	}
	cout<<ans<<endl;

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int Euclid(int a, int b, int& step)
{
	if(b == 0)
	{
		return(a);
	}
	else
	{
		++step;
		return(Euclid(b, a % b, step));
	}
}

void solve()
{
	int a, b;
	while(cin >> a >> b, a || b)
	{
		if(a < b)
		{
			swap(a, b);
		}
		int step = 0;
		cout << Euclid(a, b, step);
		cout << " " << step << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 0
#include<cstdio>

using namespace std;
int d[128];
int dp[128][3][2];

int main(){
    int n,k;
    scanf("%d%d",&n,&k);

    int a,b;
    for(int i = 0;i < k; i++){
        scanf("%d%d",&a,&b);
        d[a] = b;
    }

    for(int i = 0;i < 3; i++){
        dp[1][i][0] = 1;
    }

    for(int i = 1;i <= n; i++){
        for(int j = 0;j < 3; j++){
                if(d[i] > 0 && d[i] != j+1){
                    dp[i][j][0] = 0;
                    dp[i][j][1] = 0;
                }
                else {
                    for(int x = 0;x < 3; x++){
                        if(x != j){
                            dp[i][j][0] += dp[i-1][x][0] + dp[i-1][x][1];
                        }
                    }
                    dp[i][j][1] += dp[i-1][j][0];//‘O&#8218;&#204;“&#250;&#8218;&#204;“&#252;&#8218;&#234;&#8218;&#198;&#8218;&#173;
                    dp[i][j][0] %= 10000;
                    dp[i][j][1] %= 10000;
                    }
                }
            }
        int ans=0;
        for(int i = 0;i < 3; i++){
            ans += dp[n][i][0];
            ans += dp[n][i][1];
        }
        /*for(int i = 0;i <= n; i++){
            for(int j = 0;j < 3; j++){
                printf("%5d",dp[i][j][0]);
            }
            puts("");
        }*/
        printf("%d\n",ans%10000);
    return 0;
}

Measured memory_bytes: 1032