akhauriyash/Code-Regression huggingface dataset:
letters = list(input())
flg = ['NOSENCE', 'NOSENCE']
if int(''.join(letters[0:2])) >= 1 and int(''.join(letters[0:2])) <= 12:
  flg[0] = 'MM'
if int(''.join(letters[2:4])) >= 1 and int(''.join(letters[2:4])) <= 12:
  flg[1] = 'MM'

if flg[0] == 'MM' and flg[1] == 'MM':
  answer = 'AMBIGUOUS'
elif flg[0] == 'MM':
  answer = 'MMYY'
elif flg[1] == 'MM':
  answer = 'YYMM'
else:
  answer = 'NA'

print(answer)


Measured memory_bytes: 38256
import sys

n,a,b = map(int, input().split())

if (b-a) < 2:
	print(1+n)
	sys.exit()
else:
	n -= (a-1)
	ans = a
	ans += (b-a)*(n//2)
	if n % 2 == 1:
		ans += 1


print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  char c;cin >> c;
  if(c == 'a' || c == 'i' || c == 'e' || c == 'u' || c == 'o')cout << "vowel" << endl;
  else cout << "consonant" << endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define forn(i, x, n) for (int i = x; i < n; i++)
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define pll pair<ll, ll>
typedef long double ld;
typedef long long ll;

char g[53][53];

int main() {
    int H, W;
    scanf("%d %d ", &H, &W);
    forn(i, 0, H) {
        forn(j, 0, W) {
            scanf(" %c", &g[i][j]);
        }
    }
    
    bool good = true;
    forn(i, 0, H) {
        forn(j, 0, W) {
            if (g[i][j] == '#' &&
                g[i - 1][j] != '#' &&
                g[i + 1][j] != '#' &&
                g[i][j - 1] != '#' &&
                g[i][j + 1] != '#') {
                good = false;
            }
        }
    }
    printf(good ? "Yes\n" : "No\n");
    return 0;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n,k;
  cin >> n >> k;
  vi x(n);
  rep(i, n) cin >> x[i];
  int ans = 1000000000;
  rep(i, n - k + 1){
    int left = x[i];
    int right = x[i + k - 1];
    if(left < 0 && right < 0){
      ans = min(ans, -left);
    }else if(left < 0){
      int dis = right - left;
      ans = min(ans, dis * 2 - max(-left, right));
    }else{
      ans = min(ans, right);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include <set>
#include <array>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <vector>
#include <tuple>
#include <string>
#include <math.h>
#include <time.h>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <limits>
#include <climits>
#include <numeric>
#include <functional>

#define lnd '\n'
// #define reverse(i, n) for(ll i = n-1; i >= 0; --i)
#define from(i, n) for (ll i = 0; i < n; ++i)
#define loop(i, n) for(ll i = 0; i < n; i++)
#define REPN(i, n) for (ll i = 1; i <= n; ++i)
#define ALL(s) (s).begin(), (s).end()
#define rALL(s) (s).rbegin(), (s).rend()
#define sz(s) (int)(s).size()
#define mk make_pair
#define pb push_back
#define sqr(s) ((s) * (s))

using namespace std;

typedef long long ll;
typedef long long int lli;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned int ui;

template <class T>
T GCD (T a, T b) {
  if(a == 0) return b;
  return GCD(b%a, a);
}

template <class T>
T LCM(T a, T b){
  return a*b/GCM(a,b);
}

template <class T>
T modpow(T x, T p){
    T res = 1;
    while(p > 0){
        if(p&1) res *= x;
        x *= x;
        p /= 2;
    }
    return res;
}

template <class T>
T modpow(T x, T p, ll mod){
    T res = 1;
    while(p > 0){
        if(p&1) res = (res*x)%mod;
        x = (x*x)%mod;
        p /= 2;
    }
    return res%mod;
}

template <class T>
void print(T a[], ll n){
    for (ll i = 0; i < n; i++) std::cout << a[i] << ' ';
    cout << endl;
}

template<class T>
void printc(T c){
    for(auto const& v: c) std::cout << v << ' ';
    cout << endl;
}

struct HASH{
  size_t operator()(const pair<long,long>&x)const{
    return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
  }
};

bool pair_sort(const pair<int, int> &p1, const pair<int,int> &p2){
    if(p1.first != p2.first) return p1.first < p2.first;
    else return p1.second < p2.second;
}

const int INF = std::numeric_limits<int>::max();
const ll M_INF = std::numeric_limits<ll>::min();
const ll LL_INF = std::numeric_limits<ll>::max();

void solution();
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solution();
    return 0;
}

ll result[200005] = {0};
void fact(ll n) {
   if (n >= 0) {
      result[0] = 1;
      for (ll i = 1; i <= n; ++i) {
         result[i] = i * result[i - 1];
      }
   }
}

void solution(){
  ll a, b, n;
  cin >> a >> b >> n;

  if(n == b){
    cout << floor((a*(n-1))/b) << endl;
  }else if(n < b){
    cout << floor(a*n/b) << endl;
  }
  else{
    ll ans = max(floor((a*(b-1))/b), floor((a*(n-1))/b)- a*(floor(n-1/b)));
    cout << ans << endl;

  }
}     



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

using namespace std;

int main(){
    int N, K;

    cin >> N >> K;


    double prob = 0;
    for(int i = 1; i <= N; i++){
        int dcount = 0;
        int score = i;
        while(score < K){
            score *= 2;
            dcount++;
        }

        prob += pow(0.5, dcount);
    }

    prob *= 1.0/N;

    printf("%.13lf\n", prob);

    return 0;
}

        



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

const long long INF = 1000000000;

typedef long long ll;

#define writeln(n) cout<<n<<"\n";

typedef pair<int, int> P;
typedef pair<string, int> Psi;


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

	ll n ;cin>>n;

	writeln( n*(n-1)/2);

}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define endl '\n'
#define pb push_back
#define mod 1000000007
#define mp make_pair
#define pi acos(-1)
#define line cout<<"----------------------------"<<endl
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define filein freopen("input.txt","r",stdin)
#define fileout freopen("output.txt","w",stdout)
using namespace std;
const ll mx=200009;	
vector<int> v[mx]; 
ll ans[mx];
int n,m; 
ll upor[mx]; 
void dfs(int s, int par)
{
	ans[s]=1;
	for(auto x: v[s])
	{
		if(x==par) continue; 
		dfs(x,s);
		ans[s]*=ans[x]+1;
		ans[s]%=m;
	}
}
void dfs1(int s, int par)
{
	vector<ll> pre((int)v[s].size()+5),suf((int)v[s].size()+5);
	pre[0]=1; 
	for(int i=1;i<=(int)v[s].size();i++)
	{
		int x=v[s][i-1] ;
		pre[i] =pre[i-1];
		if(x==par) continue; 
		pre[i]*=(ans[x]+1); 
		pre[i]%=m; 
	}
	suf[(int)v[s].size()+1]=1; 
	for(int i=(int)v[s].size();i>0;i--)
	{
		suf[i]=suf[i+1] ; 
		int x=v[s][i-1] ; 
		if(x==par) continue; 
		suf[i]*=(ans[x]+1); 
		suf[i]%=m; 
	}
	upor[1]=1; 
	for(int i=1;i<=(int)v[s].size();i++)
	{
		int x=v[s][i-1]; 
		if(x==par) continue; 
		upor[x]=1; 
		upor[x]=(upor[x]*pre[i-1])%m; 
		upor[x]=(upor[x]*suf[i+1])%m; 
		upor[x]*=upor[s];  
		upor[x]++; 
		upor[x]%=m; 
		dfs1(x,s);
	}
}
int main()
{
	
	cin>>n>>m;
	for(int i=0;i<n-1;i++)
	{
		ll a,b; 
		cin>>a>>b;
		v[a].pb(b);
		v[b].pb(a);
	}
	dfs(1,-1);
	dfs1(1,-1);
	upor[1]=1; 
	for(int i=1;i<=n;i++) 
	{
		ans[i]=(ans[i]*upor[i])%m; 
		cout<<ans[i]<<endl; 
	}
}


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

#define PI 4*atan(1)
#define INF 1e8

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)

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

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

int main(){
  string S;
  cin >> S;
  int l_index = 0, r_index = S.size() - 1;
  int ans = 0;
  while(l_index <= r_index){
    // cerr << "l: " << S[l_index] << " r: " << S[r_index] << endl;
    if(S[l_index] == 'x' && S[r_index] != 'x'){
      l_index++;
      ans++;
    }else if(S[l_index] != 'x' && S[r_index] == 'x'){
      r_index--;
      ans++;
    }else if(S[l_index] == S[r_index]){
      l_index++;
      r_index--;
    }else{
      cout << -1 << endl;
      return 0;
    }
  }
  // if(S[l_index] != S[r_index]){
  //   cout << -1 << endl;
  //   return 0;
  // }
  cout << ans << endl;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
int main() {
	ll a, b, k; cin >> a >> b >> k;
	for (ll i = 0; i <= b-a; i++)
		if (i<k||i>b-a-k)cout << i+a << endl;
	return 0;
}

Measured memory_bytes: 508
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 3
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	h := getNextInt(scanner)
	n := getNextInt(scanner)

	for i := 0; i < n; i++ {
		h -= getNextInt(scanner)
	}
	ans := "Yes"
	if h > 0 {
		ans = "No"
	}
	fmt.Fprintln(writer, ans)
}


Measured memory_bytes: 1664
N=int(input())
from collections import deque
q=deque([["a",1]])
while q:
  ch,most=q.popleft()
  if len(ch)==N:
    print(ch)
    continue
  for i in range(ord("a"),ord("a")+most):
    q.append([ch+chr(i),most])
  q.append([ch+chr(ord("a")+most),most+1])


Measured memory_bytes: 22764
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	unsigned long long p[m],y[m],x[m] ;
	for(int i=0;i<m;i++)
	{
		cin>>p[i]>>y[i];
		x[i]=(p[i]<<47)+(y[i]<<17)+i;;
	}
	sort(x,x+m);
	int c=1;
	y[(x[0]<<47)>>47]=c; 
	for(int i=1;i<m;i++){
		if(x[i]>>47==x[i-1]>>47)
		   c++;
		else
		   c=1;
		y[(x[i]<<47)>>47]=c;
	}
	for(int i=0;i<m;i++){
		x[i]=p[i]*1000000+y[i];
		printf("%012lu\n",x[i]); 
	}
	return 0;
}

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

int main() {
  long n, ans = 0;
  string S, T;
  cin >> S >> T;
  n = S.size();

  for (int i = 0; i < n; i++) {
    if (S[i] != T[i]) ans++;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3860
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>

using namespace std;

string s,t;
int q,sm;
bool f=false;

int main(){
    cin>>s>>t;
    q=s.length();
    for(int i=0;i<q;i++){
        sm=0;
        for(int j=0;j<q;j++){
            sm+=t[j]==s[(i+j)%q];
        }
        if(sm==q)f=true;
    }
    cout<<(f ? "Yes":"No")<<endl;
    
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(true){
            int H = sc.nextInt();
            int W = sc.nextInt();
            if(H == 0 && W == 0){
                break;
            }
            for(int i=0;i<H;i++){
                for(int j=0;j<W;j++){
                    if(i==0 || i==H-1 || j==0 || j==W-1){
                        System.out.printf("#");
                    }else{
                        System.out.printf(".");
                    }
                }
                System.out.printf("\n");
            }
            System.out.printf("\n");
        }
    }
}


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

using namespace std;

int main(void) {
  string s;
  cin >> s;

  int q;
  cin >> q;

  string que;
  string p;
  int a, b;

  for(int i=0; i < q; ++i) {
    cin >> que;
    cin >> a >> b;
    if (que == "replace") {
      cin >> p;
      s = s.substr(0,a) + p + s.substr(b+1,s.size()-b);
    } else if (que == "reverse") {
      string t = s.substr(a, b-a+1);
      string tt(t.rbegin(), t.rend());
      s = s.substr(0, a) + tt + s.substr(b+1,s.size()-b);
    } else {
      cout << s.substr(a, b-a+1) << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 3212
#include <bits/stdc++.h>
using namespace std;
void debug() {cout<<endl;}
template<typename T,typename... Args>
void debug(T x,Args... args) {cout<<x<<" ";debug(args...);}
#define forn(i,a,b) for(int i=a;i<b;++i)
#define SZ(x) int(x.size())
#define pb push_back
#define F first
#define S second
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    
    set<int> st;
    
    while (n--) {
        int a;
        cin >> a;
        st.insert(a);
    }
    
    cout << SZ(st) << endl;
}


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

using namespace std;

int main(){
    string s;
    cin >> s;
    int min = 999;


    for(int i = 0; i < s.size() -2; i++){
        string strp = s.substr(i,3);
        istringstream ss;
        ss = istringstream(strp);

        int num;
        ss >> num;

        if(abs(num - 753) < min){
            min = abs(num - 753);
        }
    }
    cout << min << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int A,B,count,k=1;
    
    cin >> A >> B;
    
    count = A;
    
    while(count < B){
        count += (A-1);
        k++;
    }
    if(B == 1) k = 0;
    cout << k << endl;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=100010;
map<string,int> mp;
int a,b;
string s,st,u;
int main()
{
	cin>>s>>st>>a>>b>>u;
	if(s==u) a--;
	else b--;
	cout<<a<<' '<<b;
	return 0;
 } 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ALL(n) begin(n),end(n)
#define IN(a, x, b) (a<=x && x<b)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
template<class T> inline T CHMAX(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T & a, const T b) { return a = (a > b) ? b : a; }

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);

int main()
{
    INIT;
    int a, b;
    cin >> a >> b;
    int ans = 1;
    int tap = a;
    while(a < b){
        a = a - 1;
        a += tap;
        ans++;
    }
    cout << (b == 1 ? 0 : ans) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long mod=1000000000+7;
const long long INF=mod;

//マクロ
//型エイリアス
using ll = long long;
using P=pair<long long,long long>;
using vl=vector<long long>;
//ショートカット
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,k,n) for(int i=k;i<n;i++) //半開区間
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define mp make_pair
//入力
#define vin(v,N) for(long long i=0;i<N;i++) cin>>v.at(i)
#define lin(n) long long n;cin>>n
#define vlin(v,N) vector<long long>v(N);for(long long i=0;i<N;i++)cin>>v.at(i)

#define max(a,b) max((ll)a,(ll)b)
#define min(a,b) min((ll)a,(ll)b)

//関数
//最大公約数
long long gcd(long long m,long long n){
  long long a=max(m,n);
  long long b=min(m,n);
  long long r=a%b;
  while(r!=0){
    a=b; b=r; r=a%b;
  }
  return b;
}
// 最小公倍数
long long lcd(long long m,long long n){
  return m*n/gcd(m,n);
}
//xのn乗
long long power(long long x,long long N){
  long long ret=1;
  for(long long i=0;i<N;i++)   
    ret*=x;
  return ret;
}
//nCr
long long C(long long n, long long r);
//nCr (mod)
long long modC(long long n, long long r) {
    vector<long long> f(n+1),inv(n+1),invf(n+1);
    f[0]=f[1]=1;
    invf[0]=invf[1]=1;
    inv[1]=1;
    for (long long i=2;i<n+1;i++) {
        f[i]=(i*f[i-1])%mod;
        inv[i]=mod-((mod/i)*inv[mod%i])%mod;
        invf[i]=(inv[i]*invf[i-1])%mod;
    }
    long long cmb=f[n]*(invf[r]*invf[n-r]%mod)%mod;
    if (n>=r) return cmb;
    else return 0;
}
//素因数分解(mapで返す)
map<long long,long long> factor(long long p){
  ll p1=p;
  map<long long,long long>ret;
  for(long long i=2;i*i<=p1;i++){
     while(p%i==0){
      ret[i]++;
      p/=i;
    }
  }
  if(p!=1)
  ret[p]++;
  return ret;
}
//素数判定
bool is_prime(long long N){
  for(long long i=2;i*i<=N;i++){
    if(N%i==0)
      return false;
  }
  return true;
}
//最大値更新
void chmax(long long &a,long long b){
  a=max(a,b);
}
//最小値更新
void chmin(long long &a,long long b){
  a=min(a,b);
}

//メイン関数
int main(){
  //doubleの桁数
  cout<<fixed<<setprecision(10);
  
  lin(H);lin(W);
  vector<vector<char>> maze(H,vector<char>(W));
  rep(i,H){
    rep(j,W){
      cin>>maze[i][j];
    }
  }
  
  vl dh={1,0,-1,0};
  vl dw={0,1,0,-1};
  
  ll res=0;
  
  rep(sh,H){
    rep(sw,W){
      if(maze[sh][sw]=='#') continue;
      ll M=0;
      
      vector<vector<bool>> undone(H,vector<bool>(W,true));
      vector<vector<ll>>d(H,vector<ll>(W,-INF));
      d[sh][sw]=0;
      undone[sh][sw]=0;
      
      queue<P>Q;
      Q.push(mp(sh,sw));
      
      
      while(Q.size()>0){
        ll h=Q.front().first, w=Q.front().second; Q.pop();
        
        rep(i,4){
          ll nh=h+dh[i], nw=w+dw[i];
          if(0<=nh && nh<H && 0<=nw && nw<W && maze[nh][nw]=='.'
               && undone[nh][nw]){
            Q.push(mp(nh,nw));
            undone[nh][nw]=false;
            chmax(d[nh][nw], d[h][w] + 1);
            //cout<<d[h][w]<<" "<<d[nh][nw]<<endl;
          }
        }
      }
      
      rep(i,H){
        rep(j,W){
          M=max(M,d[i][j]);
        }
      }
      //cout<<M<<endl;
      chmax(res,M);
    }
  }
  cout<<res;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=3030,mod=998244353;
int A,B,C,D,f[N][N],inv[N];
int main(){
    scanf("%d%d%d%d",&A,&B,&C,&D);
    inv[1]=1;
    for(int i=2;i<N;i++)inv[i]=mod-1ll*mod/i*inv[mod%i]%mod;
    f[A][B]=1;
    for(int i=B+1;i<=D;i++)
        f[A][i]=1ll*f[A][i-1]*A%mod;
    for(int i=A+1;i<=C;i++)
        f[i][B]=1ll*f[i-1][B]*B%mod;
    for(int i=A+1;i<=C;i++)
        for(int j=B+1,dat=0,t1=1,t2=1;j<=D;j++)
            dat=(dat+1ll*t1*(j-1)%mod*f[i-1][j-1])%mod,
            f[i][j]=(1ll*dat*t2+1ll*f[i-1][j]*j)%mod,
            t1=1ll*t1*inv[i]%mod,t2=1ll*t2*i%mod;
    cout<<f[C][D];
    return 0;
}

Measured memory_bytes: 39148
#include  <stdio.h>

int main(void)
{
       int hp1,at1,hp2,at2;
       int turn1=1;
       int turn2=1;
        scanf("%d  %d  %d  %d",&hp1,&at1,&hp2,&at2);

       while(hp2-at1*turn1>0)
        {
                turn1++;
        }

        while(hp1-at2*turn2>0)
        {
                turn2++;
        }

        if(turn1<=turn2){
                printf("Yes");
        }else{
                printf("No");
        }
        return 0;
}


Measured memory_bytes: 3236
#include <iostream>
#include <stdio.h>
using namespace std;
int main(void){
    // Your code here!
    long a,b,c,s,sum;
    cin >> b;
    for(int i = 0;i < b;i++){
    cin >> a;
    if(i == 0){
        c = a;
        s = a;
        sum = a;
        continue;
    }
    if(a > c) c = a;
    if(a < s) s = a;
    sum += a;
    }
    
    cout << s << " " << c << " " << sum << endl;
}


Measured memory_bytes: 3096
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Queue queue = new Queue();
		int n = sc.nextInt();
		int q = sc.nextInt();
		for (int i = 0; i < n; i++) {
			String name = sc.next();
			int cpuTime = sc.nextInt();
			Process p = new Process(name, cpuTime);
			queue.enqueue(p);
		}
		sc.close();

		int totalTime = 0;
		while (!queue.isEmpty()) {
			Process p = queue.dequeue();
			int time = Math.min(p.getCpuTime(), q);
			p.setCpuTime(p.getCpuTime() - time);
			totalTime += time;
			if (p.isFinished()) {
				System.out.println(p.getName() + " " + totalTime);
			} else {
				queue.enqueue(p);
			}
		}
	}
}

class Process {
	private String name;
	private int cpuTime;
	public Process(String name, int cpuTime) {
		this.name = name;
		this.cpuTime = cpuTime;
	}
	public String getName() {
		return name;
	}
	public int getCpuTime() {
		return cpuTime;
	}
	public void setCpuTime(int cpuTime) {
		this.cpuTime = cpuTime;
	}
	public boolean isFinished() {
		return this.cpuTime <= 0;
	}
}

class Queue {
	private LinkedList<Process> queue;
	public Queue() {
		queue = new LinkedList<Process>();
	}
	public void enqueue(Process p) {
		queue.addLast(p);
	}
	public Process dequeue() {
		Process ret = queue.getFirst();
		queue.removeFirst();
		return ret;
	}
	public boolean isEmpty() {
		return queue.size() <= 0;
	}
}

Measured memory_bytes: 75616
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)

const ll MOD = (ll)1e9 + 7;
const ll HIGHINF = (ll)1e18;

int main() {
  ll n; cin >> n;
  if (n==0) cout << 0 << endl;
  else {
    string ans;
    ll i = 1;
    while (n!=0) {
      i *= -2;
      if (n % i == 0) {
        ans += '0';
      } else {
        ans += '1';
        n -= i / (-2);
      }
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 256
a,b=map(int,input().split())
s=input()
x=[str(i) for i in range(10)]
y="-"
for i in range(a+b+1):
    if i==a:
        if s[i]!="-":
            print("No")
            break
    else:
        if s[i] not in x:
            print("No")
            break
else:
    print("Yes")


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Vec2(T, n, m, xs, x0) vector<vector<T>> xs(n, vector<T>(m, x0))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

// constexpr int MOD = 1e9+7;


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

int main(void){
    Cin(ll, n);
    string s = to_string(n);
    int d = (int)s.size();
    Cout(max(sd10(n), 9*(d-1) + (int)(s[0] - '0') - 1));
}


Measured memory_bytes: 256
import sys

n, t, *a = map(int, sys.stdin.read().split())

def main():
    r = 0
    cnt = 0
    prof = 0
    max_prof = 0
    buy_price = sell_price = a[0]
    while True:
        r += 1
        if r == n:
            if prof == max_prof:
                cnt += 1
            elif prof > max_prof:
                max_prof = prof
                cnt = 1
            break

        cur = a[r]
        if cur > sell_price:
            sell_price = cur
            prof = sell_price - buy_price
        elif cur > buy_price:
            pass
        else:
            if prof == max_prof:
                cnt += 1
            elif prof > max_prof:
                max_prof = prof
                cnt = 1
            buy_price = sell_price = cur
            prof = 0

    return cnt

if __name__ == '__main__':
    ans = main()
    print(ans)

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

def main():
    n = int(input())
    res = float('inf')

    for i in range(1, int(math.sqrt(n)) + 1):
        if n % i == 0:
            res = min(res, (i - 1) + (n // i - 1))

    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int n,m,c,s,g;
main()
{
    while(cin>>n>>m>>c>>s>>g,n)
    {
        vector<pair<int,int> >G[21][101];
        for(int i=0;i<m;i++)
        {
            int a,b,d,C;
            cin>>a>>b>>d>>C;
            G[C][a].push_back({b,d});
            G[C][b].push_back({a,d});
        }
        int dis[101][101];
        for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)dis[i][j]=i==j?0:1e9;
        int p[21];
        for(int i=1;i<=c;i++)cin>>p[i];
        for(int i=1;i<=c;i++)
        {
            int take[101][101];
            for(int k=1;k<=n;k++)for(int j=1;j<=n;j++)take[k][j]=k==j?0:1e9;
            for(int j=1;j<=n;j++)
            {
                for(int k=0;k<G[i][j].size();k++)
                {
                    take[j][G[i][j][k].first]=min(take[j][G[i][j][k].first],G[i][j][k].second);
                }
            }
            for(int k=1;k<=n;k++)for(int I=1;I<=n;I++)for(int J=1;J<=n;J++)
                take[I][J]=min(take[I][J],take[I][k]+take[k][J]);
            int q[55]={},r[55];
            for(int j=1;j<p[i];j++)cin>>q[j];
            for(int j=0;j<p[i];j++)cin>>r[j];
            q[p[i]]=1e9;
            for(int j=1;j<=n;j++)for(int k=1;k<=n;k++)
            {
            	if(take[j][k]==1e9)continue;
                int sum=0;
                int id=0;
                while(q[id+1]<take[j][k])
                {
                    sum+=(q[id+1]-q[id])*r[id];
                    id++;
                }
                sum+=(take[j][k]-q[id])*r[id];
                take[j][k]=sum;
                dis[j][k]=min(dis[j][k],take[j][k]);
            }
        }
        for(int k=1;k<=n;k++)for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)
            dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
        if(dis[s][g]<1e9)cout<<dis[s][g]<<endl;
        else cout<<-1<<endl;
    }
}


Measured memory_bytes: 3352
h,w=map(int,input().split())
ans=10**100

for i in range(1,h):
    if w%2==0:
        l=[i*w,(h-i)*(w//2),(h-i)*(w//2)]
    else:
        l=[i*w,(h-i)*(w//2),(h-i)*(w//2+1)]

    if (h-i)%2==0:
        ll=[i*w,((h-i)//2)*w,((h-i)//2)*w]
    else:
        ll=[i*w,((h-i)//2)*w,((h-i)//2+1)*w]
    p=min(max(l)-min(l),max(ll)-min(ll))
    ans=min(ans,p)
for i in range(1,w):
    if h%2==0:
        l=[i*h,(w-i)*(h//2),(w-i)*(h//2)]
    else:
        l=[i*h,(w-i)*(h//2),(w-i)*(h//2+1)]

    if (w-i)%2==0:
        ll=[i*h,((w-i)//2)*h,((w-i)//2)*h]
    else:
        ll=[i*h,((w-i)//2)*h,((w-i)//2+1)*h]
    p=min(max(l)-min(l),max(ll)-min(ll))
    ans=min(ans,p)
print(ans)







Measured memory_bytes: 3064
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    n = int(input())
    x = list(map(int, input().split()))
    sorted_x = sorted(x)

    low = sorted_x[(n // 2) - 1]
    high = sorted_x[(n // 2)]

    for i in range(n):
        if x[i] < high:
            print(high)
        else:
            print(low)


Measured memory_bytes: 25220
n=int(input())
a=[input() for i in range(n)]
a.sort()
a+="zzzzzzzzzzzzzzzzzzz"
m=[]
st=a[0];cnt=1
for i in range(1,n+1):
    if st!= a[i]:
        m.append((st,cnt))
        st=a[i]
        cnt=1
    else:
        cnt+=1
m.sort(key=lambda x:x[0])
m.sort(key=lambda x:x[1],reverse=True)
cnnnk=m[0][1]
for i in m:
    if i[1]==cnnnk:
        print(i[0])
    else:
        break

Measured memory_bytes: 34596
// C - Inserting 'x'

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int main() {
	string s;
	cin >> s;

	string t = "";
	for (int i=0; i<s.size(); i++) {
		if (s[i] != 'x') t.push_back(s[i]);
	}
	auto rev_t = t;
	reverse(rev_t.begin(), rev_t.end());
	if (t != rev_t) {
		cout << -1 << endl;
		return 0;
	}

	vector<int> cnt;

	int c = 0;
	for (int i=0; i<s.size(); i++) {
		if (s[i] == 'x') c++;
		else {
			cnt.push_back(c);
			c = 0;
		}
	}
	cnt.push_back(c);

	auto rev_cnt = cnt;
	reverse(rev_cnt.begin(), rev_cnt.end());

	int ans = 0;
	for (int i=0; i<cnt.size(); i++) {
		ans += abs(cnt[i] - rev_cnt[i]);
	}
	ans /= 2;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4296
// ------------------------------------
// Date:2018/ 2/22
// Problem:ABC 042 Iroha's Obsession c.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()

using ll = long long;

int main()
{
  int N,K;
  string t;
  cin >> N >> K;
  vector<int> L(K);
  REP(i,K) cin >> L[i];
  FOR(i,N,10*N) {
    bool flag = true;
    t = to_string(i);
    REP(j,t.size()) {
      REP(k,L.size()) {
        if (t[j]-'0' == L[k]) flag = false;
      }
    }
    if (flag) {
      cout << t << endl;
      return 0;
    }
  }
  cout << endl;
  
  return 0;
}


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

using namespace std;
     
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pf push_front         																																																										
#define ppb pop_back
#define mp make_pair
#define bpp __builtin_popcount
#define al 0x3F3F3F3F
#define sz(x) x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
#define resize(v) v.resize(unique(all(v)) - v.begin());
//#define int long long

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;                                                                          																																													
typedef pair <int, int> pii;

const int mod = (int)1e9 + 7;                                   
const int MAX_N = (int)2e5 + 123;
const int N = 1e6 + 123;                     
const int INF = al;           
const ll INFL = 3e18 + 1;
const double pi = acos(-1.0);
const double eps = 1e-9;
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, x, y, q, ans, sz[MAX_N];
bool check[MAX_N];

inline void boost () {
    ios_base :: sync_with_stdio(NULL);
    cin.tie(NULL), cout.tie(NULL);
}                                                                     
                                                                    
inline void Solve () {
   boost ();
   cin >> n >> q;
   check[1] = 1;
   for (int i = 1; i <= n; i ++) sz[i] = 1;
   while (q --) {
   	cin >> x >> y;
   	check[y] |= check[x];
   	sz[y] ++, sz[x] --;
   	if (!sz[x]) check[x] = 0; 
   }
   for (int i = 1; i <= n; i ++) ans += check[i];
   cout << ans;
}  

int main () {
//	freopen("sparse.in", "r", stdin);	
//	freopen("sparse.out", "w", stdout);
   int tt = 1;                																																																									
//	cin >> tt;
	while (tt --) {
   	Solve ();
   }
   return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define ub upper_bound
#define lb lower_bound
#define all(v) ((v).begin()),((v).end())
#define allr(v) ((v).rbegin()),((v).rend())
#define ff first
#define ss second
#define mp make_pair
#define pll pair<ll,ll> 
#define fo(i,n) for(ll i=0;i<n;i++)
#define foa(i,s,e) for(ll i=(s);i<e;i++)
#define fod(i,s,e) for(ll i= (s);i>=(e);i--)
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
#define sz(x) (ll)(x.size())
#define ANS cout<<ans<<'\n'
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define Yes cout<<"Yes\n"
#define No cout<<"No\n"
const ld pi = 3.14159265358979323846;
ll MOD = 1e9 + 7;
//ll MOD = 998244353;
const char nl = '\n';
const ll inf = 1e15;
#define fill(a,b) memset(a, b, sizeof(a))
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) fo(i, n){fo(j, m)cout<<dp[i][j]<<" ";cout<<"\n";}
ll nxt(){ll x; cin >> x; return x;}
ll mul(ll x,ll y){
    return (1ll* (x%MOD)*(y%MOD));
}
ll modpow(ll x,ll y){ll z=1;while(y>0){if(y%2)z=mul(z,x);x =mul(x,x) ;y/=2;}return z;}
ll power(ll x,ll y){ll z=1;while(y>0){if(y%2)z=z*x;x =x*x ;y/=2;}return z;}
ll gcd(ll a,ll b){if(a<b) return gcd(b,a);if(b==0) return a;return gcd(b,a%b);} 
ll min(ll a,ll b){if(a<b)return a;return b;}
ll max(ll a,ll b){if(a>b)return a;return b;}
ll sq(ll a){
    ll ans = (1ll*a*a);
    return ans;
}
void solve(){
    ll n;
    cin >> n;
    ll a[n];
    fo(i, n)cin >> a[i];
    ll b[n];
    b[n - 1] = a[n - 1];
    fod(i, n - 2, 0){
        b[i] = b[i + 1] + a[i];
    }
    ll ans = 0;
    fo(i, n - 1){
        ans = (ans + mul(a[i], b[i + 1]) % MOD) % MOD;
    }
    cout << (ans % MOD + MOD) % MOD << nl;


}
int main(){ 
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("inputf.txt" , "r" , stdin) ;
    freopen("outputf.txt" , "w" , stdout) ;
    freopen("error.txt" , "w" , stderr) ;
    #endif
    ll TC = 1;
    //cin>>TC;
    fo(TT, TC){
        // Google,FB cout << "Case #"<< TT + 1 << ": ";
        solve();
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


Measured memory_bytes: 6916
/*************************************************************************
    > File Name: aoj2249.cpp
    > Author:    WArobot 
    > Blog:      http://www.cnblogs.com/WArobot/ 
    > Created Time: 2017??´06???20??\ ????????? 15??¶23???28?§?
 ************************************************************************/

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

const int MAX_N = 12345;
const int MAX_M = 20010;
const int INF = 1e9;

struct edge{
	int to , cost , money;
	edge(int tt , int tc , int tm) : to(tt) , cost(tc) , money(tm) {} ;
};
typedef pair<int,int> P;

vector< edge > G[MAX_N];
int dis[MAX_N];
int n , m;

void Dijkstra(){
	fill(dis,dis+n+1,INF);
	dis[1] = 0;
	priority_queue< P , vector<P> , greater<P> >	que;
	que.push( P(0,1) );
	while(!que.empty()){
		P p = que.top();	que.pop();
		int v = p.second;
		if( dis[v] < p.first )	continue;
		for(int i = 0 ; i < G[v].size() ; i++){
			edge e = G[v][i];
			if( dis[e.to] > dis[v] + e.cost ){
				dis[e.to] = dis[v] + e.cost;
				que.push( P(dis[e.to] , e.to) );
			}
		}
	}
}
int main(){
	int u , v , cost , money;
	while(~scanf("%d%d",&n,&m) && (n+m)){
		for(int i = 0 ; i <= n ; i++)	G[i].clear();
		for(int i = 0 ; i < m ; i++){
			scanf("%d%d%d%d",&u,&v,&cost,&money);
			G[u].push_back( edge(v,cost,money) );
			G[v].push_back( edge(u,cost,money) );
		}
		Dijkstra();
		int ans = 0;
		for(int i = 2 ; i <= n ; i++){
			int min_money = 0x3f3f3f3f;
			// ????????????????¶???????????????¶????´???¨???????????£??????????´???¨
			for(int j = 0 ; j < G[i].size() ; j++){
				edge e = G[i][j];
				if( dis[ e.to ] + e.cost == dis[i] && min_money > e.money ){
					min_money = e.money;
				}
			}
			if( min_money != 0x3f3f3f3f )
				ans += min_money;
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 5164
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
using namespace std;
int main() {
	int N,K;
	cin>>N>>K;
	long long int ans=K;
	for(int i=0;i<N-1;i++)ans*=K-1;
	cout<<ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <map>
#include <set>
#include <cstring>
#include <climits>

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

using namespace std;

bool primearray[10000];

void erathos()
{
	int i;
	memset(primearray, 0, sizeof(primearray));

	REP( i, 2, 10000)
	{
		if( primearray[i] == 0 )
		{
			for( int j = i*2; j < 10000; j+=i)
			{
				primearray[j] = 1;
			}
		}
	}

	return;
}

int main()
{
	int in;

	erathos();

	while( cin >> in, in)
	{
		for( int i = in ; i > 0; i--)
		{
			if( primearray[i] == 0 && primearray[i-2] == 0 )
			{
				cout << i-2 << " " << i << endl;
				break;
			}
		}
	}

	return 0;

}

Measured memory_bytes: 872
#include"bits/stdc++.h"
using namespace std;
int main() {
	int N; cin >> N;
	priority_queue<int64_t> que;
	que.push(0);
	int64_t cnt = 0;
	for (int i = 0; i < N; i++)
	{
		int64_t a; cin >> a;
		if (que.top() > a) cnt += que.top() - a;
		que.push(a);
	}
	cout << cnt << endl;
}

Measured memory_bytes: 5264
#include <bits/stdc++.h>
#define va first
#define vb second
#define lb lower_bound
#define ub upper_bound
#define pp push_back
#define ep emplace_back
#define all(v) (v).begin(),(v).end()
#define szz(v) ((int)(v).size())
#define psm partial_sum
#define acm accumulate
#define fio ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
using ll = long long;
using lf = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
const lf PI = 3.14159265358979323846264338L;
string S;
int n, cnt[200005], p[200005];
int main(){
    fio;
    cin >> n >> S;
    for(int i = 1; i <= n; i++){
        cnt[i] = cnt[i-1] + (S[i-1] == '#');
    }
    int ans = min(cnt[n], n - cnt[n]);
    for(int i = 1; i <= n; i++){
        if(S[i-1] == '#'){
            //cout << i << ' ' << 2 * cnt[i-1] + n - i + 1 - cnt[n] << '\n';
            ans = min(ans, 2 * cnt[i-1] + n - i + 1 - cnt[n]);
        }
    }
    cout << ans << '\n';
}

Measured memory_bytes: 1300
import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayList;

class Main{
	public static void main(String[] args){
      	Scanner sc = new Scanner(System.in);
      	int n = sc.nextInt();
      	int a[] = new int[n];
      	
      	for(int i = 0; i < n; i++)
          a[i] = sc.nextInt();
      	Arrays.sort(a);
      
      	int bob = 0, alice = 0;
      	boolean flag = true;
      	int i = n-1;
      	while(i >= 0){
          if(flag){
            alice += a[i];
          	flag = !flag;
          }else{
            bob +=a[i];
            flag = !flag;
          }
    		i--;
    	}
      	System.out.println(alice - bob);
      	
	}
}

Measured memory_bytes: 21844
import heapq

n = int(input())

s = []
while (n != 0):

    if(n == 26):
        s.append("z")
        break

    temp = n % 26
    if(temp == 0):
        temp = 26
    s.append(chr(temp + 96))
    n = (n - temp) // 26

s.reverse()
s = "".join(s)
print(s)

Measured memory_bytes: 62280
#include<bits/stdc++.h>
#define reg(i,a,b) for(int i=a;i<=b;i++)
#define reh(i,a,b) for(int i=a;i>b;i--)
#define in(x) scanf("%d",&x)
#define fro freopen("D:\\testdata.in", "r", stdin)
#define il inline
#define lson(q) q<<1
#define rson(q) q<<1|1
using namespace std;
typedef long long ll;
const int mx=1e5+10;
int a[mx];
int b[mx];
int c[mx];
int n,m;
int t;
int res;
string str;
int main(){
	cin>>n;
	reg(i,1,n-1){
		cin>>b[i];
	}
	b[n]=b[n-1];
	a[1]=b[1];
	reg(i,2,n){
		a[i]=min(b[i-1],b[i]);
	}
	reg(i,1,n){
		res+=a[i];
	}
	cout<<res<<endl;
	return 0;
}




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

#ifdef _PRINTDEBUG
  #include "lib/printdebug.hpp"
#else
  #define printdebug(...) 1
#endif
#define MOD_1_000_000_007 (1000000007)
#define IINF (1<<28)
#define LINF (1LL<<60)
#define rep(i, n)      REP(i, 0, (n))
#define repc(i, n)     REPC(i, 0, (n))
#define REP(i, n, m)   for (int i = (int)(n); i <  (int)(m); i++)
#define REPC(i, n, m)  for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
#define yesno(cond)       YESNO((cond), "Yes", "No")
#define YESNO(cond, a, b) cout << ((cond) ? (a) : (b)) << "\n"

namespace solver {
  using namespace std;
  typedef long long ll;

  int N, xs[110];

  void init() {
    cin >> N;
    rep(i, N) {
      cin >> xs[i];
    }
  }

  void solve() {
    int minv = IINF;
    REPC(i, 1, 100) {
      int cur = 0;
      rep(j, N) cur += pow(xs[j]-i, 2);
      minv = min(minv, cur);
    }
    cout << minv << endl;
  }
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  solver::init();
  solver::solve();
  return 0;
}

Measured memory_bytes: 256
import scala.io.StdIn

/**
  * AOJ
  */
object Main {

  def main(args: Array[String]): Unit = {

    val n = StdIn.readInt()
    for(i <- 1 to n){
      if(check_num(i)){print(" %d".format(i))}
    }
    println()
  }

  def check_num(n:Int): Boolean = n match {
    case n if n % 3 == 0 => true
    case n if(n.toString.contains("3")) => true
    case _ => false
  }
}

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

int main(){
	int n,sum;
    sum =0;
	cin>>n;
	vector<int> a(n);
	vector<int> b(n);
	vector<int> c(n-1);
	for(int i=0;i<n;i++){
	cin>>a[i];
	}
  	for(int i=0;i<n;i++){
	cin>>b[i];
	}
	for(int i=0;i<n-1;i++){
	cin>>c[i];
	}
	for(int i=0;i<n;i++){
	sum+=b[a[i]-1];
      if(a[i+1]-a[i] ==1){
        sum += c[a[i]-1];
      }
	}
	cout<<sum<<endl;
}


Measured memory_bytes: 256
N,M=map(int,input().split())
A=[list(map(int,input().split())) for i in range(M)]
B=[[]for i in range(N)]
P=[0]*N
for a,b in A:
  B[a-1].append(b-1)
  B[b-1].append(a-1)

from collections import deque

def bfs(x):
  q=deque()
  q.append(x)
  while len(q):
    x=q.popleft()
    
    if P[x]==0:
      for i in B[x]:
        q.append(i)
        P[x]=1
        
ans=0
for a,b in A:
  P=[0]*N
  B[a-1].remove(b-1)
  B[b-1].remove(a-1)
  bfs(0)
  if P!=[1]*N:
    ans+=1
  B[a-1].append(b-1)
  B[b-1].append(a-1)
print(ans)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e;
string s,h;
int main(){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>s>>h;
	for(b=0; b<s.size(); b++){
		if(s[b]==h[b]) c++;
	}
	cout<<c;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <limits>
#include <numeric>

using namespace std;
typedef long long int ll;
typedef long double ld;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }                   // 最大公約数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); };                      // 最小公倍数
ll getDigit(ll num) { return log10(num) + 1; }                         // 桁数
ll digitSum(ll n) { return (n < 10) ? n : digitSum(n / 10) + n % 10; } // 各桁の和
#define MOD 1e9 + 7
#define pb push_back
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repn(i, n) for (ll i = 1; i <= n; i++)
#define repi(i, a, b) for (ll i = ll(a); i < ll(b); ++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265359

template <typename T>
void printVector(string name, vector<T> vec)
{
    cout << name << ": ";
    rep(i, vec.size())
    {
        cout << vec[i] << " ";
    }
    cout << endl;
}

void Main()
{
    char n;
    cin >> n;
    if ((int)n >= 65 && (int)n <= 90)
    {
        cout << "A" << endl;
    }
    else
    {
        cout << "a" << endl;
    }

    return;
}

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


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <cstdlib> //絶対値整数abs
#include <cmath>   //絶対値少数fbs
#include <math.h>
using namespace std;
#define rep(i, N) for (ll i = 0; i < (N); i++)
typedef long long ll;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> a(N - 1);
    vector<ll> b(N, 0);
    rep(i, N - 1) cin >> a.at(i);
    rep(i, N - 1) b.at((a.at(i) - 1))++;
    rep(i, N) cout << b.at(i) << endl;
}


Measured memory_bytes: 6368
n,m,a,b = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
x = max(x)
y = min(y)
for z in range(x+1,y+1):
    if a < z and z <= b:
        print("No War")
        quit()
print("War")

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

using namespace std;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;

const int N = 100 + 7;
const int P = 1000 + 7;
const ll OO = (ll) 1e18;
int n, wLimit;
ll mnw[N * P];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> wLimit;
  for (int i = 1; i < N * P; i++) {
    mnw[i] = OO;
  }
  for (int i = 1; i <= n; i++) {
    int w, p;
    cin >> w >> p;
    for (int j = N * P - 1; j >= p; j--) {
      mnw[j] = min(mnw[j], mnw[j - p] + w);
    }
  }
  int sol = 0;
  for (int i = 0; i < N * P; i++) {
    if (mnw[i] <= wLimit) {
      sol = i;
    }
  }
  cout << sol << "\n";
  return 0;
}


Measured memory_bytes: 1152
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
getInt = readInt <$> BS.getLine

main = do
    n <- getInt
    print $ solve n

solve :: Int -> Int
solve n = minimum [p + (n `div` p) - 2 | p <- [1..1000000], n `mod` p == 0]

Measured memory_bytes: 764