akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

fn main() {
    input! {
        a: i32, b: i32, c: i32, d: i32,
    }
    let ans = if (a - c).abs() <= d || ((a - b).abs() <= d && (b - c).abs() <= d) {
                "Yes"
              } else {
                "No"
              };
    

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





Measured memory_bytes: 4352
#include<iostream>
using namespace std;
int main(){
 int h,n,s;
   int w=0;
  cin>>h>>n;
  for(int i{};i<n;i++){
    cin>>s; 
  w+=s;  
  }
  if(w>=h)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	int n, m;
	LinkedList<Integer>[] es;

	@SuppressWarnings("unchecked")
	void run(){
		for(;;){
			n=sc.nextInt();
			m=sc.nextInt();
			if((n|m)==0){
				break;
			}
			es=new LinkedList[n];
			for(int i=0; i<n; i++){
				es[i]=new LinkedList<Integer>();
			}
			for(int i=0; i<m; i++){
				int u=sc.nextInt()-1;
				int v=sc.nextInt()-1;
				es[u].add(v);
				es[v].add(u);
			}
			solve();
		}
	}

	void solve(){
		LinkedList<Integer> que=new LinkedList<Integer>();
		boolean[] visited=new boolean[n];
		int[] len=new int[n];
		que.offer(0);
		visited[0]=true;
		len[0]=0;
		int ans=-1;
		for(; !que.isEmpty();){
			int u=que.poll();
			if(len[u]>2){
				break;
			}
			ans++;
			for(int v : es[u]){
				if(!visited[v]){
					que.offer(v);
					visited[v]=true;
					len[v]=len[u]+1;
				}
			}
		}
		println(ans+"");
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 13000
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <array>
#include <random>
#include <complex>
#include <regex>
#include <iomanip>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define fcout cout << fixed << setprecision(10)
#define rep(i,n)    for(int i=0; i<(int)n; i++)
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define all(x) x.begin(), x.end()
#define F first
#define S second
const ll inf = 1e18;
const ll mod = 1e9 + 7;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

// mod. m での a の逆元 a^(-1) を計算する。
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll modpow(ll a, ll n){
    ll res = 1;
    while(n>0){
        if(n&1){
            res = res * a % mod;
        }
        a = a * a % mod;
        n >>=1;
    }
    return res;
}


int main(){
    ll a, b;
    cin >> a >> b;
    cout << a*b << endl;

}



Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <assert.h>
//#include <bits/stdc++.h>

#define ll long long

using namespace std;


int main(){
    cin.sync_with_stdio(false);
    int r, g, b, n;
    ll ret = 0;
    cin >> r >> g >> b >> n;
    for(ll i = 0; i * r <= n; ++i){
        for(ll j = 0; i * r + j * g <= n; ++j){
            ll left = n - (i * r + j * g);
            if(left % b == 0) ++ret;
        }
    }
    
    cout << ret;
}


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

int main() {
    string s;
    getline(cin, s);

    for (int i = 0; i < s.size(); i++) {
        char c = s.at(i);
        if ('A' <= c && c <= 'Z') {
            cout << (char)tolower(c);
        } else if ('a' <= c && c <= 'z') {
            cout << (char)toupper(c);
        } else {
            cout << c;
        }
    }
    cout << endl;
}


Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=2e3+5;
const int mod=1e9+7;
bitset<maxn*maxn>dp;
int n,a,s;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    dp[0]=1;
    for(int i=1;i<=n;i++){
        cin>>a;
        dp|=dp<<a;
        s+=a;
    }
    for(int i=(s+1)/2;i<=s;i++) 
        if(dp[i]){
            cout<<i<<endl;
            break;
        }
    return 0;
}

Measured memory_bytes: 1792
n = int(input())
li = list(map(int,input().split()))

dp = [0]*n
dp[1] = abs(li[1]-li[0])
for i in range(2,n):
  dp[i] = min(dp[i-1] + abs(li[i]-li[i-1]),dp[i-2] + abs(li[i]-li[i-2]))
print(dp[n-1])

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

int main(){
 int A,B,C;
 long long K;
 cin >> A >> B >> C >> K;
 if(A>=K) cout << K << endl;
 else if(A+B >=K) cout << A << endl;
 else cout << A-K+(A+B) << endl;
}


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

#ifdef on_linux
	#include <sys/resource.h>
#endif

#ifdef dobby_is_a_free_elf
	#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
	#define trace(...) 0;
#endif

using namespace std;
using namespace __gnu_pbds;


#define all(x)                  (x).begin(), (x).end()
#define between(i,x,y)          ((i) >= (x) && (i) <= (y))
#define DECIMAL(n)              cout << fixed << setprecision(n)
#define fi                      first
#define lbd                     lower_bound
#define mem0(x)                 memset(x, 0, sizeof (x))
#define mem1(x)                 memset(x, -1, sizeof (x))
#define mp                      make_pair
#define pb                      push_back
#define pf                      push_front
#define ppb                     pop_back
#define ppf                     pop_front
#define sc                      second
#define sqr(a)                  ((a) * (a))
#define sz(x)                   (int)((x).size())
#define ubd                     upper_bound

#define int                     long long

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template <typename T>
using ordered_set = tree<T, null_type,
      less<T>,
      rb_tree_tag,
      tree_order_statistics_node_update>;
// find_by_order(k)  returns iterator to kth element starting from 0
// order_of_key(k) returns count of elements strictly smaller than k


const long double PI = 3.14159265358979323846264338;
const double eps = 1e-10;
#ifdef int
	const long long INF = 1e18;
#else
	const long long INF = 1e9;
#endif
const int32_t fftmod = 998244353;
const int32_t MOD = 1000000007;
const int32_t N = 1e5 + 10;
const int32_t NN = 1e6 + 10;



inline void elf_magic(int testcase)
{
	int s;
	cin >> s;

	int dp[s + 10] = {};
	dp[0] = 1;
	for (int i = 1; i <= s; ++i) {
		for (int j = 3; j <= i; ++j) {
			dp[i] = (dp[i] + dp[i - j]) % MOD;
		}
	}
	cout << dp[s];
	return;
}

int32_t main()
{
	#ifdef on_linux
	rlimit cpu_time {.rlim_cur = 2, .rlim_max = RLIM_INFINITY};
	setrlimit(RLIMIT_CPU, &cpu_time);
	#endif

	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	int TESTS = 1;
	//cin >> TESTS;
	for (int i = 1; i <= TESTS; ++i) {
		// cout << "Case #" << i << ": ";
		elf_magic(i);
		if (i != TESTS)	{ cout << '\n'; }
	}
	return 0;
}

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

int main() {
    string s;
    cin>>s;
    long a=0;
    int n=std::count(s.begin(),s.end(),'1');
    a=a+n;
    n=std::count(s.begin(),s.end(),'2');
    a=a+n*2;
    n=std::count(s.begin(),s.end(),'3');
    a=a+n*3;
    n=std::count(s.begin(),s.end(),'4');
    a=a+n*4;
    n=std::count(s.begin(),s.end(),'5');
    a=a+n*5;
    n=std::count(s.begin(),s.end(),'6');
    a=a+n*6;
    n=std::count(s.begin(),s.end(),'7');
    a=a+n*7;
    n=std::count(s.begin(),s.end(),'8');
    a=a+n*8;
    if(a%9==0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3720
from functools import reduce
from fractions import gcd
from collections import defaultdict
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def prime_decomposition(n):
    i = 2
    ans = 0
    while i * i <= n:
        cnt = 1
        tmp = 0
        while n % i == 0:
            n = n // i
            tmp += 1
            if cnt == tmp:
                ans += 1
                cnt += 1
                tmp = 0
        i += 1
    if n > 1:
        ans += 1
    return ans


# 処理内容
def main():
    N = int(input())
    print(prime_decomposition(N))


if __name__ == '__main__':
    main()

Measured memory_bytes: 77568
n=int(input())
a=[*map(int,input().split())]
from math import *
l,r=[0]*n,[0]*n
for i in range(1,n):
  l[i]=gcd(l[i-1],a[i-1])
  r[~i]=gcd(r[-i],a[-i])
m=0
for i in range(n):
  m=max(m,gcd(l[i],r[i]))
print(m)

Measured memory_bytes: 20656
#include<stdio.h>

int main(int argc, char** argv){
  int r,g,b;
  int sum;
  
  scanf("%d %d %d", &r, &g, &b);
  
  sum = r * 100 + g * 10 + b;
  
  if(sum % 4 == 0)
    printf("YES\n");
  else
    printf("NO\n");
  
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1000000+10,P=1000000007;
ll f[N*2];
int main(){
	ll n,sum=0,ans=0;
	cin>>n;
    f[1]=1;
	for(ll i=1;i<=n;i++){
        f[i]=(f[i]+f[i-1])%P;
        if(i>=3) f[i]=((f[i]+sum-f[i-1]-f[i-2])%P+P)%P;
		if(i<n) ans=(ans+f[i]*(n-1)%P*(n-1)%P)%P;
		if(i<n-1) ans=(ans+f[i]*(i+1)%P)%P;
		else ans=(ans+f[i]*i%P)%P;
		sum=(sum+f[i])%P;
    }
	cout<<ans<<endl;
}



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

int main()
{
  string left="qwertasdfgzxcvb";
  string right="yuiophjklnm";
  string s;
  int i,f,cnt;
  while(cin>>s,s!="#"){
    cnt=0;
    f=(left.find(s[0],0)!=string::npos)-(right.find(s[0],0)!=string::npos);
    for(i=0;i<s.size();i++){
      if(f!=((left.find(s[i],0)!=string::npos)-(right.find(s[i],0)!=string::npos))){
	f*=-1;
	cnt++;
      }
    }
    cout<<cnt<<endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
 
//LIFE IS NOT A PROBLEM TO BE SOLVED
 
#define rep(i, a, b) for( int i = (int) a; i < (int) b; i++ )
#define F first
#define S second
#define pb push_back
 
using namespace std;
 
const int mod = 1000000007;
const int INF = 0x3f3f3f3f;
const long long int LINF = 1LL<<56;

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



int main(){
	
		
	int N, K; cin >> N >> K;
	
	int h[N];
	rep(i, 0, N) cin >> h[i];
	
	int dp[N]; dp[0] = 0;
	rep(i, 1, N){
		dp[i] = 0x3f3f3f3f;
		rep(j, 1, K+1){
			if(i-j < 0) break;
			dp[i] = min(dp[i], dp[i-j]+abs(h[i]-h[i-j]));
		}
		
	}
	
	cout << dp[N-1] << '\n';
	
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<algorithm>
#include<string>
#include <stdlib.h>
using namespace std;
#define         rep(i, n)       for (int i = 0; i < (int)(n); i++)
#define         pi              3.14159265359
#define         nl              printf("\n")
#define         gcd(a,b)        __gcd(a,b)
#define         yes             cout<<"Yes"<<"\n"
#define         no              cout<<"No"<<"\n"
#define         pf              printf
#define         sf              scanf
const int N = 2e5+5;
typedef long long int ll;
int i,j,temp,f=0;
int main()
{
   int n;cin>>n;
  int a[10002],o=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
    while(a[i]%2==0){
      o++;
      a[i]/=2;
    }
  }
  cout<<o<<endl;
  return 0;
}


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

using namespace std;

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

const double pi = 3.14159265358979323846;

#define MOD 1000000007LL
#define PS(p) cout << setprecision(15) << fixed << p << endl;
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
#define ALL(c) c.begin(), c.end()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define TG0 get< 0 >
#define TG1 get< 1 >
#define TG2 get< 2 >
#define F first
#define S second
#define VL vector< ll >

// to_string(123)
// atoi("123"); atoi(s.c_str());
// "abc".size()
// s.find('+') == string::npos
// 1e18

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

  ll N;
  cin >> N;

  ll A[N];
  for (ll i = 0; i < N; i++) {
    cin >> A[i];
  }

  for (ll i = 0; i < N; i++) {
    if (A[i] % 2 == 0) {
      if (A[i] % 3 == 0 || A[i] % 5 == 0) {

      } else {
        cout << "DENIED" << endl;
        return 0;
      }
    }
  }

  cout << "APPROVED" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N;
    int A[3];
    cin >> N >> A[0] >> A[1] >> A[2];
    vector<int> l(N);
    for (int i=0; i<N; i++) {
        cin >> l[i];
    }

    int c_min=10000;
    int k_end = 1 << 16;
    for(int k=0;k<k_end;k++) {
        vector<int> b(4),mp(4);
        for (int n=0;n<N;n++) {
            int g = (k>>(2*n)) % 4;
            if(b[g]>0) mp[g]+= 10;
            b[g] += l[n];
        }
        bool zero=false;
        for (int g=0;g<3;g++) {
            if (b[g]==0) zero=true;
        }
        if (zero) {
            continue;
        }
        int c=0;
        for (int g=0;g<3;g++) {
            c += abs(b[g]-A[g]) + mp[g];        
        }
        if (c_min>c) {
            c_min = c;
            //cout << b[0] << " " << b[1] << " " << b[2] << " " << mp[0] << " " << mp[1] << " " << mp[2] << '\n';
        }
    }

    cout << c_min << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef pair <int,int> pr;
#define fr(i, n) for(int i = 0; i < n; i++)
#define sz(a) int((a).size())
#define pb push_back
#define all(c)(c).begin(), (c).end()
#define tr(c, i) for (typeof ((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c, x)((c).find(x) != (c).end())
#define cpresent(c, x)(find(all(c), x) != (c).end())
// for mod power a^b%m use power<lli> (a,b,m)
template < class mytype >
mytype power(mytype a, mytype b, mytype m){if (b == 1) return a % m;if (b == 0) return 1;
mytype root = power < lli > (a, b / 2, m);mytype ans = (root * root) % m;if (b % 2) ans = (ans * a) % m;
return ans;
}
// for gcd use gcd<int> (a,b)
template < class type >type gcd(type a, type b){if (a == 0) return b;else return gcd(b % a, a);}
template < class type >type mod_inv(type a, type p) {return power(a, p - 2, p);}
const lli MOD = 1e9 + 7;

int main()
{
   int n;
   cin >> n;
   vector<int> v(n);
   for(int i = 0 ; i < n ; i++) cin >> v[i];
   vector<lli> prefix(n+1);
   prefix[0] = 0 ;
   for(int i = 1 ; i <= n ; i ++) prefix[i] = prefix[i-1] + v[i-1];
   lli dp[n][n];
   for(int i = 0 ; i < n ; i++) dp[0][i] = 0;
   for(int len = 1 ; len < n ; len++){
    for(int i = 0 ; i+len < n ; i++){
            lli ans = LONG_LONG_MAX;
        for(int j = i ; j < i+len ; j++){
            ans = min(ans , dp[j-i][i] + dp[i+len-j-1][j+1] + prefix[i+len+1] - prefix[i]);
        }
        dp[len][i] = ans;
    }
   }
    cout << dp[n-1][0] << endl;
    return 0;
}











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

/*
vector.push_back()
vector<int> hoge(3,-1); {-1,-1,-1}
vector<vector<int>> hogehoge(2,vector<int>(2,-1)); {{-1,-1},{-1,-1}} 
cin >>temp;
scanf("%d %d %d",&A,&B,&Q);
sort(a.begin(),a.end());
a.push_back(4000000000000);
a.insert(a.begin(),-1000000000000);
upper_bound(a.begin(),a.end(),x); // list[i] > x のイテレータ取得. *itrで数値化 
*/
template <typename T> void debug(T arr);
template <typename T> void debug (T arr, int dim);



int main(void){
    std::cout<<std::fixed<<std::setprecision(10);
    int h,w;
    cin >> h >> w;
    vector<vector<int>> ans(h+2,vector<int>(w+2,0));
    set<string> boms;
    for (int i = 0; i < h; ++i){
        string raw;
        cin >> raw;
        for (int j = 0; j < w; ++ j){
            auto c = raw[j];
            if (c == '#'){
                boms.insert(to_string(i)+","+to_string(j));
                ans[i+2][j] += 1;
                ans[i+2][j+1] += 1;
                ans[i+2][j+2] += 1;
                ans[i+1][j] += 1;
                ans[i+1][j+2] += 1;
                ans[i][j] += 1;
                ans[i][j+1] += 1;
                ans[i][j+2] += 1;
            }
        }
    }
    for (int i = 0; i <h ; ++ i){
        for (int j = 0; j < w; ++ j){
            if (boms.count(to_string(i)+","+to_string(j)) == 0){
                cout << ans[i+1][j+1];
            }else{
                cout << "#";
            }
        }
        cout << endl;
    }
};


template <typename T> void debug(T arr){
    for (auto col:arr){
        cout << col << " ";
    }
    cout <<endl;
};

template <typename T> void debug (T arr, int dim){
    for (auto raw:arr){
        for(auto col:raw){
            cout << col << " ";
        }
        cout << endl;
    }
};

Measured memory_bytes: 512
# F - Strivore

K = int(input())
S = list(str(input()))
N = len(S)
MOD = 10**9+7

fac = [1, 1]
inv = [0, 1]
finv = [1, 1]

for i in range(2, N+K+1):
    fac.append(fac[-1] * i % MOD)
    inv.append(MOD - inv[MOD%i] * (MOD//i) % MOD)
    finv.append(finv[-1] * inv[-1] % MOD)

def comb_mod(n, r, m):
    if (n<0 or r<0 or n<r): return 0
    r = min(r, n-r)
    return fac[n] * finv[n-r] * finv[r] % m

ans = 0
for i in range(K+1):
    tmp = pow(25, i, MOD)
    tmp *= comb_mod(i+N-1, N-1, MOD)
    tmp *= pow(26, K-i, MOD)
    ans += tmp
    ans %= MOD
print(ans)



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

ans = 10**10
for i in range(N+1):
    cc = 0

    t = i
    while t > 0:
        cc += t % 6
        t //= 6

    t = N-i
    while t > 0:
        cc += t % 9
        t //= 9

    if ans > cc:
        ans = cc
print(ans)


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

int main() {
    int n,d,x,ans = 0;

    cin >> n >> d >> x;
    int a[n];

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

    
    for(int i = 0; i < n; ++i){
        if(d % a[i] == 0) ans = ans + d / a[i];
        else ans = ans + d / a[i] + 1;
    }

    cout << ans + x << endl;

    return 0;
 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<set>
#define ll long long 
#include <string>
#define pb push_back
#define mp make_pair
# define pi 3.14159265358979323846
using namespace std;
int main()
{
	ll int n;
	cin>>n;
	ll int a[n],s=0,i;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		s=s^a[i];
	}
	for(i=0;i<n;i++)
	{
		ll int ans=a[i]^s;
		cout<<ans<<" ";
	}
	cout<<endl;
	
	
}
	
		
	
	
	
	




Measured memory_bytes: 5104
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep1(i, n) for(int i=1; i<(int)(n); i++)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> wi;

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

  int s;
  cin >> s;
  int a=s/100, b=s%100;
  if(1<=a&&a<=12){
    if(1<=b&&b<=12)cout << "AMBIGUOUS" << endl;
    else cout << "MMYY" << endl;
  }
  else{
    if(1<=b&&b<=12)cout << "YYMM" << endl;
    else cout << "NA" << endl;
  }

  return 0;
}

Measured memory_bytes: 3632
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n,q;
    cin>>n>>q;
    string s;
    cin>>s;
    vi a(n+1);
    rep(i,n){
        if(i&&s[i-1]=='A'&&s[i]=='C')a[i+1]++;
    }
    REP(i,1,n)a[i]+=a[i-1];
    while(q--){
        int l,r;
        cin>>l>>r;
        cout<<a[r]-a[l]<<endl;
    }
}

Measured memory_bytes: 1872
#include<iostream>
using namespace std;
int main(){
  int h1,m1,s1,h2,m2,s2,x,y,z,x1,y1,z1;


  for(int i=0;i<3;i++){
    
    cin >> h1 >> m1 >> s1 >> h2 >> m2 >> s2;

    x=h1*3600+m1*60+s1;
    y=h2*3600+m2*60+s2;
    z=y-x;
    x1=z/3600;
    z-=x1*3600;
    y1=z/60;
    z-=y1*60;
    cout << x1 <<" "<< y1<<" "<< z <<endl;

  }
  


  return 0;
}

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

int find_sum(int N) {
  int sum = 0;
  while(N>0) {
    sum += N % 10;
    N /= 10;
  }
  return sum;
}

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  

  int total = 0;
  for(int i=1; i<=N; i++) {
    int sum = find_sum(i);
    if(sum >=A && sum <=B) {
      total +=i;
    }
  }
  cout << total << endl;
}

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <queue>
#include <utility>
#include <cmath>
#include <iomanip>
#include <map>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

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

const long long int mod=1e9+7;



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

	lint H[100010];
	REP(i,N) cin >> H[i];

	int num=0;
	REP(i,N-1){
		if(H[i+1]<H[i]){
			++H[i+1];
		}
		if(H[i+1]<H[i]){
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
	return 0;

}


Measured memory_bytes: 1024
N, K = map(int, input().split())
sum = 0
for i in range(1, N+1):
    if i >= K:
        sum += 1
    else:
        cnt = 0
        new_i = i
        while(new_i < K):
            new_i *= 2
            cnt += 1
        sum += 1/(2**cnt)
print(sum/N)

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

int main() {
	int N, M;
	cin >> N >> M;
	vector<vector<char>>A(N, vector<char>(N));
	vector<vector<char>>B(M, vector<char>(M));
	for (int i = 0; i < N; i++)for (int j = 0; j < N; j++)cin >> A[i][j];
	for (int i = 0; i < M; i++)for (int j = 0; j < M; j++)cin >> B[i][j];

	bool findAns = true;
	for (int i = 0; i < N - M + 1; i++) {
		for (int j = 0; j < N - M + 1; j++) {
			findAns = true;
			for (int k = 0; k < M; k++) {
				for (int l = 0; l < M; l++) {
					if (A[i + k][j + l] != B[k][l]) {
						findAns = false;
						break;
					}
				}
				if (!findAns) break;
			}
			if (findAns) break;
		}
		if (findAns) break;
	}
	cout << (findAns ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cctype>
using namespace std;
typedef long long lint;
#define cout cerr
#define ni (next_num<int>())
template<class T>inline T next_num(){
	T i=0;char c;
	while(!isdigit(c=getchar())&&c!='-');
	bool flag=c=='-';
	flag?c=getchar():0;
	while(i=i*10-'0'+c,isdigit(c=getchar()));
	return flag?-i:i;
}
template<class T1,class T2>inline void apmax(T1 &a,const T2 &b){if(a<b)a=b;}
template<class T1,class T2>inline void apmin(T1 &a,const T2 &b){if(b<a)a=b;}
const int N=500010;
char s[N];
int num[N];
int main(){
	scanf("%s",s);
	int n=strlen(s);
	int r=0,cur=0;
	memset(num,0,sizeof(num));
	for(int i=0;i<n;i++){
		num[i]=(s[n-i-1]-'0')*9+r;
		r=num[i]/10;
		cur+=num[i]%=10;
	}
	for(;r;n++){
		cur+=num[n]=r%10;
		r/=10;
	}
	int ans=0;
	for(;cur>ans*9;ans++){
		num[0]+=9,cur+=9;
		for(int i=0,r=0;num[i]>9||r;i++){
			cur-=num[i];
			num[i]+=r;
			r=num[i]/10;
			cur+=num[i]%=10;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 2688
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    ll sum=0;
    if(k<=a)
    {
        cout<<k;
    }
    else if(k<=a+b)
    {
        cout<<a;
    }
    else
    {
        cout<<a-(k-a-b);
    }
    return 0;
}

Measured memory_bytes: 3632
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <list>
#include <stack>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  int N;
  ll x;
  cin >> N >> x;

  vector<ll> v;
  rep(i,N){
    ll a;
    cin >> a;
    v.push_back(a);
  }

  ll ret = 0;
  rep(i,v.size()-1){
    if(v[i]+v[i+1] > x){
      ll rem = v[i]+v[i+1]-x;
      ret += rem;
      v[i+1] = max(0LL, v[i+1]-rem);
    }
  }

  cout << ret << endl;
  
  return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <cmath>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

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

int main(){
    string s;
    cin >> s;
    int numA,numZ;
    for(int i=0;i<s.size();i++){
        if(s[i]=='A'){
            numA=i;
            break;
        }
    }
    for(int i=s.size()-1;i>=0;i--){
        if(s[i]=='Z'){
            numZ=i;
            break;
        }
    }
    cout << numZ-numA+1 << endl;
}

Measured memory_bytes: 640
n,t = map(int,input().split())
a = list(map(int,input().split()))

res = 0
left = 0
right = 0
for i in a:
    if i-right<=t:
        right = i
    else:
        res += right - left + t
        left = i
        right = i
    #print(left,right,res)
else:
    res += right - left + t

print(res)


Measured memory_bytes: 25200
#include"bits/stdc++.h"
using namespace std;
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for (int i = (b - 1); i >= a; i--)
#define RREP(i, n) RFOR(i, 0, n)
#define rep(i, a, b) for (auto i = a; i < b; i++)
#define rrep(i, a, b) for (auto i = a; i > b; i--)
#define fs first
#define sc second
typedef pair<int, int> P;
 
const int N = 1111*1111;
vector<int> flag(N, 0), prime(N,0);
int n, m;
int a[1111][1111];
int ans[1111][1111];
int visit[1111][1111];
int sx, sy, cnt;
 
void check(int cur, int x, int y) {
    if (cur == n) sx = x, sy = y;
}
 
void bfs() {
    queue<P> que;
    que.push(P(sx, sy));
 
    int dy[] = { -1,0,1 };
    while (que.size()) {
        P p = que.front(); que.pop();
        if (p.fs + 1 == cnt) break;
        REP(i, 3) {
            int Y = p.sc + dy[i];
            if (0 <= Y && Y < cnt && a[p.fs + 1][Y] <= m) {
                ans[p.fs + 1][Y] = max(ans[p.fs + 1][Y],ans[p.fs][p.sc] + (prime[a[p.fs + 1][Y]] == 1));
                if(visit[p.fs + 1][Y] == 0) que.push(P(p.fs + 1, Y)), visit[p.fs+1][Y]++;
            }
        }
    }
}
 
void solve() {
    cin >> m >> n;
    if (n == 0) exit(0);
    cnt = 1;
    while (cnt*cnt < m) cnt += 2;
 
    int cur = 2, id = 1, x = cnt / 2, y = cnt / 2;
    a[x][y] = 1;
 
    if (n == 1) sx = x, sy = y;
     
    while (cur <= cnt * cnt) {
        REP(_, id) y++, a[x][y] = cur, check(cur,x,y),cur++;
        REP(_, id) { x--, a[x][y] = cur, check(cur, x, y), cur++; if (cur > cnt*cnt) goto out; }
        REP(_, id + 1) y--, a[x][y] = cur, check(cur, x, y),cur++;
        REP(_, id + 1) x++, a[x][y] = cur, check(cur, x, y),cur++;
        id += 2;
    }
    out:;
 
    //cout << sx << " " << sy;
    REP(i, cnt) REP(j, cnt) ans[i][j] = 0, visit[i][j] = 0;
    if (prime[a[sx][sy]]) ans[sx][sy] = 1;
    bfs();
 
    //cout << sx << " " << sy << endl;
 
    int res = 0 ,num = 0;
    REP(i, cnt) REP(j, cnt) {
        if (prime[a[i][j]] == 0) continue;
        if (ans[i][j] > res) res = ans[i][j], num = a[i][j];
        else if (ans[i][j] == res) num = max(num, a[i][j]);
    }
 
    if (res == 0) cout << "0 0" << endl;
    else cout << res << " " << num << endl;
 
}
 
 
int main() {
    FOR(i, 2, N) {
        if (flag[i] == 0) {
            prime[i]++;
            FOR(j, 1, N) {
                if (i*j >= N) break;
                flag[i*j]++;
            }
        }
    }
 
    while (1) solve();
}


Measured memory_bytes: 25588
#include <stack>
#include <queue>
#include <cstdio>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
 
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n0,n) for(int i=n0;i<n;i++)
#define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<n;j++)
#define INF (1<<29)
#define test cout << "test" << endl;


int main (){
	int NNN;
	cin >> NNN;
	vector <int> XX;
	int temp;
	rep(i,NNN){
		cin >>temp;
		XX.push_back(temp);
	}
	vector <int> sortedXX = XX;
	sort(sortedXX.begin(),sortedXX.end());
	int s = sortedXX[sortedXX.size()/2-1];
	int u = sortedXX[sortedXX.size()/2];
	rep(i,NNN){
		if(XX[i]>s){
			cout << s << endl;
		}
		else {
			cout << u << endl;
		}
	}	


	return 0;
}


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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int m, n;
  while (cin >> m >> n, m) {
    vector<vector<int>> a(n, vector<int>(721));
    int r;
    cin >> r;
    while (r--) {
      int t, j, i, s;
      cin >> t >> j >> i >> s;
      t -= 540;
      --j, --i;
      if (s) {
        a[i][t] += 1;
      } else {
        a[i][t] -= 1;
      }
    }
    for (int i = 0; i < n; ++i) {
      for (int t = 0; t < 720; ++t) {
        a[i][t + 1] += a[i][t];
      }
    }
    int q;
    cin >> q;
    while (q--) {
      int l, r, i;
      cin >> l >> r >> i;
      l -= 540, r -= 540;
      --i;
      int res = 0;
      for (int t = l; t < r; ++t) {
        res += !!a[i][t];
      }
      cout << res << '\n';
    }
  }
}



Measured memory_bytes: 30484
#include <iostream>
#include <cmath>

using namespace std;

long long n, a, b;

void citire()
{
    cin >> n >> a >> b;
}

int main()
{
    citire();

    if (a > b) swap(a, b);

    if ( (a & 1) == (b & 1))
    {
        cout << ((b - a) >> 1 ) << endl;
        return 0;
    }

    long long ans = n;
    ans = min(ans, a - 1 + (b - a + 1) / 2);
    ans = min(ans, n - b + (b - a + 1) / 2);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define _for(i,a,b) for(int i = (a);i<(b);i++)
#define endl  '\n'
#define inf 0x3f3f3f3f
#define ull unsigned long long  
using namespace std;
const int mod=1e9+7;
const int MAX=1e5+7;
//ll a[MAX];
int main()
{
 	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 	ll n,k,ans=0;
 	cin>>n>>k;
 	for(ll i=k;i<=n+1;i++)
 	{
 		ans=ans+(n-i+1+n)*i/2-(i-1)*i/2+1;
 		ans%=mod;
	 }
	 cout<<ans<<endl;
 	
}

Measured memory_bytes: 3652
#include<iostream>
#include<stdio.h>
#include<math.h>

using namespace std;

#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b))<EPS)

class Point {
public:
	double x, y;


	Point(double x = 0, double y = 0) :x(x), y(y) {}

	Point operator + (Point p) { return Point(x + p.x, y + p.y); }
	Point operator - (Point p) { return Point(x - p.x, y - p.y); }
	Point operator * (double a) { return Point(a * x,  a * y); }
	Point operator / (double a) { return Point(x / a, y / a); }

	double abs() { return sqrt(norm()); }
	double norm() { return x * x + y * y; };

	bool operator < (const Point& p)const {
		return x != p.x ? x < p.x : y < p.y;
	}

	bool operator ==(const Point& p)const {
		return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
	}

};

typedef Point Vector;

double dot(Vector a, Vector b) {
	return a.x * b.x + a.y * b.y;
}

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

bool isOrthogonal(Vector a, Vector b) {
	return equals(dot(a, b), 0.0);
}

bool isParallel(Vector a, Vector b) {
	return equals(cross(a, b), 0.0);
}
struct Segment {
	Point p1, p2;
	Segment(){}
	Segment(Point p1,Point p2):p1(p1),p2(p2){}
};
typedef Segment  Line;

double norm(Vector a) {
	return a.x * a.x + a.y * a.y;
}

Point project(Segment s, Point p) {
	Vector base = s.p2 - s.p1;
	double r = dot(p - s.p1, base) /norm(base);
	return s.p1 + base * r;
}

int main() {
	double x1, y1, x2, y2,x0,y0;
	cin >> x1 >> y1 >> x2 >> y2;
	int q;
	Line s = Line(Point(x1, y1), Point(x2, y2));

	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> x0 >> y0;
		Point ans = project(s, Point(x0, y0));

		//cout << ans.x << " " << ans.y << endl;
		printf("%.8lf %.8lf\n", ans.x,ans.y);
	}

	return 0;
}


Measured memory_bytes: 3296
n = int(input())
si = [input() for i in range(n)]
m = int(input())
ti = [input() for i in range(m)]
sik = set(si) # 固有の値のみを抽出
tik =set(ti)
s=0
ma = 0
for i in sik:
    if si.count(i) - ti.count(i) > ma:  #もしもsにある数の方が多ければ特するのでgo!!
        ma = si.count(i) -ti.count(i)
print(ma)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		int X = stdIn.nextInt();
		int Y = stdIn.nextInt();
		int ans = 0;
		ans = X * Y;
		System.out.println(ans);
		stdIn.close();
	}
}

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

ll solve(vector<int>& dq,int st, int end, vector<vector<ll>>& dp){
	if(st > end)
		return 0;
	if(dp[st][end] != -1)
		return dp[st][end];

	//dp[st][end] = max(max(solve(dq, st+1, end-1, dp), solve(dq, st+2, end, dp)) + dq[st], max(solve(dq, st+1, end-1, dp), solve(dq, st, end-2, dp)) + dq[end]);
	dp[st][end] = max(dq[st] - solve(dq, st+1, end, dp), dq[end] - solve(dq, st, end-1, dp));
	
	return dp[st][end];
}

int main(){
	int n;cin>>n;
	vector<int> dq;
	for(int i = 0; i < n; i++){
		int t;cin>>t;
		dq.push_back(t);
	}
	vector<vector<ll> > dp(n, vector<ll>(n,-1));
	//dp[0][n-1] = solve(dq, 0, n-1, dp);
	for(int i = 0; i < n; i++){
		dp[i][i] = dq[i];
	}

	for(int i = n-1; i >= 0; i--){
		for(int j = i; j < n; j++){
			if(i==j)
				dp[i][j] = dq[j];
			else
				dp[i][j] = max(dq[i] - dp[i+1][j], dq[j] - dp[i][j-1]);
		}
	}
	
	cout<<dp[0][n-1]<<endl;
	return 0;
}

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

public class Main {


	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str1=br.readLine();

		String str2=str1.replace(',', ' ');

		System.out.println(str2);

	}

}

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

typedef unsigned long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

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

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

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

    char c = S[0];
    ll count = 0;
    for(int i = 1; i < N; i++ ){
        if( c != S[i] ){
           count++;
           c = S[i];
        }
    }

    count++;
    cout << count << endl;
}


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

int main() {
  long long N, K;
  cin >> N >> K;
  long long x[N];
  for (int i = 0; i < N; i++) cin >> x[i];
  
  long long min_ = 100000000000;
  for (int i = 0; i < N - K + 1; i++){
    min_ = min(min_, abs(x[i]) + abs(x[i + K - 1] - x[i]));
    min_ = min(min_, abs(x[i + K - 1]) + abs(x[i + K - 1] - x[i]));
  }
  
  cout << min_ << endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007


int main(void){

    int n;
    cin >> n;

    ll a[n], b[n], c[n];
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    rep(i, n) cin >> c[i];

    //昇順にソート
    sort(a, a+n);
    sort(c,c+n);

    ll ans = 0;
    //配列bを基準に、bより小さい&&bより大きい個数を掛け算で加算
    rep(i,n){
        //b[i]よりも小さい数を求める
        ll temp_l = lower_bound(a, a + n, b[i]) - a;

        //b[i]よりも大きい数を求める
        ll temp_r = upper_bound(c, c + n, b[i]) - c;
        ans += temp_l * (n - temp_r);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const double PI = 3.14159265358979323846;

int main() {
  string s;
  cin >> s;
  string tmp = s;
  reverse(s.begin(), s.end());
  int cnt = 0;
  rep(i, s.size()) {
    if(tmp.at(i) != s.at(i)) cnt++;
  }
  cout << cnt/2 << endl;
  return 0;
}

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

using namespace std;

int main(void){

    int n, t, a;
    int min = 1000000007, index = 0;

    cin >> n >> t >> a;

    t *= 1000;
    a *= 1000;

    vector<int> h(n), sub(n);

    for(int i = 0;i < n;i++){
        cin >> h[i];
    }

    for(int i = 0;i < n;i++){
        sub[i] = t - h[i] * 6;
        if(min > abs(sub[i] - a)){
            min = abs(sub[i] - a);
            index = i+1;
        }
    }

    cout << index << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

const int INF = INT_MAX / 4;

class Edge
{
public:
    int to, cost;
    Edge(){};
    Edge(int to0, int cost0){to = to0; cost = cost0;}
};

void shortestPath(const vector<vector<Edge> >& edges, int start, vector<int>& dist)
{
    dist.assign(edges.size(), INF);
    dist[start] = 0;
    priority_queue<pair<int,int> ,vector<pair<int,int> >, greater<pair<int,int> > > q;
    q.push(make_pair(0, start));

    while(!q.empty()){
        pair<int, int> p = q.top();
        q.pop();
        int v = p.second;
        if(dist[v] < p.first)
            continue;
        for(unsigned i=0; i<edges[v].size(); ++i){
            Edge e = edges[v][i];
            if(dist[v] + e.cost < dist[e.to]){
                dist[e.to] = dist[v] + e.cost;
                q.push(make_pair(dist[e.to], e.to));
            }
        }
    }

}

void shortestPath(const vector<vector<Edge> >& edges, vector<vector<int> >& dist)
{
    dist.resize(edges.size());
    for(unsigned i=0; i<edges.size(); ++i)
        shortestPath(edges, i, dist[i]);
}

int main()
{
    for(;;){
        int n, m, s, g1, g2;
        cin >> n >> m >> s >> g1 >> g2;
        if(n == 0)
            return 0;

        vector<vector<Edge> > edges(n+1);
        for(int i=0; i<m; ++i){
            int b1, b2, c;
            cin >> b1 >> b2 >> c;
            edges[b1].push_back(Edge(b2, c));
        }

        vector<vector<int> > dist;
        shortestPath(edges, dist);

        int ret = INF;
        for(int i=1; i<=n; ++i)
            ret = min(ret, dist[s][i] + dist[i][g1] + dist[i][g2]);
        cout << ret << endl;
    }
}

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

typedef long long ll;
const int N = 1e5+3;
struct Node{
	double x,y;
	Node(double x0=0,double y0=0): x(x0),y(y0) {}
	Node operator + (const Node &n) const{
		return Node(x+n.x,y+n.y);
	}
	Node operator - (const Node &n) const{
		return Node(x-n.x,y-n.y);
	}
	Node operator * (const double &t) const{
		return Node(x*t,y*t);
	}
	Node operator / (const double &t) const{
		return Node(x/t,y/t);
	}
	double square(){
		return x*x+y*y;
	}
	Node rotate(){
		return Node(y,-x);
	}
}point[N];
double cross(Node a,Node b){
	return a.x*b.y-a.y*b.x;
}
Node cal(Node a,Node b,Node c){
	Node p1=(a+b)/2,p2=(a+c)/2;
	Node v1=(b-a).rotate(),v2=(c-a).rotate();
	double t=cross(p2-p1,v2)/cross(v1,v2);
	return p1+v1*t;
}
int main(){
	int n;
	scanf("%d", &n);
	for(int i=1;i<=n;i++){
		scanf("%lf %lf", &point[i].x, &point[i].y);
	}
	random_shuffle(point+1,point+1+n);
	Node ans;
	double ansr=0;
	for(int i=1;i<=n;i++){
		if((point[i]-ans).square()>ansr){
			ans=point[i];
			ansr=0;
			for(int j=1;j<i;j++){
				if((point[j]-ans).square()>ansr){
					ans=(point[i]+point[j])/2;
					ansr=(point[j]-ans).square();
					for(int k=1;k<j;k++){
						if((point[k]-ans).square()>ansr){
							ans=cal(point[i],point[j],point[k]);
							ansr=(point[k]-ans).square();
						}
					}
				}
			}
		}
	}
	printf("%.10lf\n", sqrt(ansr));
	return 0;
}


Measured memory_bytes: 1792
N, M = map(int, input().split())
AC = [0] * N
WA = [0] * N

for i in range(M):
    p, S = input().split()
    p = int(p) - 1
    if S == 'AC':
        AC[p] = 1
    elif AC[p] == 0:
        WA[p] += 1

print(sum(AC), sum( [AC[i] * WA[i] for i in range(N)] ) )

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

/* constant */

#define MAX_K   (5000)
#define MAX_N   (1000)

/* typedef */

/* global variables */

static int ais[MAX_K], bis[MAX_K];

/* subroutines */

int get_len(int an, int bn, int *ais, int *bis, int k0) {
  int ai, aj, bi, b;

  ai = 0;
  for (bi = k0; bi < bn; bi++) {
    if (ai >= an) return bi - k0;
    b = bis[bi];
    aj = ai;
    while (aj < an && ais[aj] != b) aj++;
    if (aj >= an) return bi - k0;
    ai = aj + 1;
  }

  return bn - k0;
}

/* main */

int main(int argc, char **argv) {
  int an, bn, i, k0, len, max_len;

  scanf("%d", &an);
  scanf("%d", &bn);

  for (i = 0; i < an; i++) scanf("%d", ais + i);
  for (i = 0; i < bn; i++) scanf("%d", bis + i);

  max_len = 0;

  for (k0 = 0; k0 < bn; k0++) {
    if (k0 + max_len > bn) break;

    len = get_len(an, bn, ais, bis, k0);
    if (max_len < len) max_len = len;
  }

  printf("%d\n", max_len);

  return 0;
}

Measured memory_bytes: 632
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
	int n, x, y;
	scanf("%d %d %d", &n, &x, &y);
	x--, y--;
	int c[n];
	fill(c, c + n, 0);
	for (int i = 0; i <= x; i++){
		for (int j = i + 1; j <= x; j++) c[j - i]++;
		for (int j = x + 1; j < y; j++) c[min(j - i, x - i + y - j + 1)]++;
		for (int j = y; j < n; j++) c[j - i - (y - x) + 1]++;
	}
	for (int i = x + 1; i <= y; i++){
		for (int j = i + 1; j <= y; j++) c[min(i - x + 1 + y - j, j - i)]++;
		for (int j = y + 1; j < n; j++) c[min(i - x + 1 + j - y, j - i)]++;
	}
	for (int i = y + 1; i < n; i++){
		for (int j = i + 1; j < n; j++) c[j - i]++;
	}
	for (int i = 1; i < n; i++) printf("%d\n", c[i]);
}

Measured memory_bytes: 128
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N, M = LI()

total = int(N*(N-1)/2) + int(M*(M-1)/2)
print(total)

Measured memory_bytes: 9156
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

const int N=1000005;
const int P=998244353;

int n,Index;
double f[N],cur=P;
int Q[N];

void init(){
	/*
	#define n 100000
	for(int i=1;i<=n;i++){
		int res=0,tmp=i;
		while(tmp){
			res+=(tmp%10);
			tmp/=10;
		}
		f[i]=(double)i/res;
	}
	for(int i=n;i>=1;i--){
		if(f[i]<=cur){
			cur=f[i];
			Q[++Index]=i;
		}
	}
	for(int i=Index;i>=1;i--){
		if(Q[i])printf("%d\n",Q[i]);
	}
	#undef n
	printf("\n");
	*/
	cin>>n;
	if(n<=9){
		for(int i=1;i<=n;i++){
			printf("%d\n",i);
		}
		return ;
	}
	int cur=1;
	n-=9;
	for(int i=1;i<=9;i++) printf("%d\n",i);
	while(n){
		for(int i=cur-1;i<10*cur;i++){
			if(i==0) continue;
			printf("%d",i);
			for(int j=1;j<=cur;j++) printf("9");// printf(" %d\n",n);
			n--;
			if(n==0) break;
		}
		cur++;
	}
}

inline double s(long long x){
	long long res=0,tmp=x;
	while(tmp){
			res+=(tmp%10);
			tmp/=10;
	}
	return (double)x/res;
}

inline void init_oscar(){
	scanf("%d",&n);
	long long B=1,cur=0;
	for(int i=1;i<=n;i++){
		if(s(cur+10*B)<s(cur+B)) B*=10;
		cur+=B;
		printf("%lld\n",cur);
	}
}

int main(){
	//init();
	init_oscar();
	return 0;
}

Measured memory_bytes: 256
import scala.io.StdIn.readInt
import scala.collection.mutable.ArrayBuffer

object Main {
  def main(args:Array[String]) = {
    val b = new ArrayBuffer[String]
    var n = 0
    while({n=readInt;n} != 0) {
      val s = (1 to Math.sqrt(n).toInt).filter(n%_==0).map{i=>
        if(i!=n/i) i+n/i
        else i
      }
      if(n==s.sum-n) b+="perfect number"
      else if(n>s.sum-n) b+="deficient number"
      else b+="abundant number"
    }
    println(b.mkString("\n"))
  }

}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  while (true) {
    int x, y;
    cin >> x >> y;
    if (x + y == 0) return 0;
    if (x > y) swap(x, y);
    cout << x << " " << y << '\n';
  }
}


Measured memory_bytes: 3224
#include<bits/stdc++.h>
#define ll long long 
#define mp make_pair 
#define f(i,n) for(int i=0;i<n;i++) 
#define F first 
#define S second 
#define pb push_back 

using namespace std;

void test(){
	ll x,k,d;
	cin>>x>>k>>d;
	ll dis = abs(x);
	ll min_t = dis/d;
	
	if(k<min_t){
		dis = dis - (k*d);
	}else{
		dis = dis - (min_t*d);
		if(k>min_t){
			k = k - min_t;
			if(k%2==1)dis  = d - dis;
		}
	}
	cout<<dis<<"\n";
	
}

int main(){
	int tests=1;
	// cin>>tests;
	while(tests--){
		test();
	}
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;

int main (){

  int A,B;
  cin >>A>>B;
  int C,D;
  for(int i=1;i<1500;i++){
    C = i*0.08;
    D=i*0.1;
    if(C==A){
      if(D==B){
	cout<<i;
	return 0;
      }
    }
  }
  cout <<"-1";





  return 0;
}


Measured memory_bytes: 256
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size,n=1,init=nil) #nに配列の次元数、sizeに配列の大きさ、initに初期値を投げることでその配列を返す
  if n==1
    return Array.new(size){init}
  else
    return Array.new(n).map{Array.new(size){init}}
  end
end
s=gets.to_i
h=s/3600
m=((s-h*3600)/60)%60
s=s%60
puts [h,m,s].join(":")


Measured memory_bytes: 6880