akhauriyash/Code-Regression huggingface dataset:
#define MOD 1000000007
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

void print(auto x) {
    cout << x << endl;
}

ll sum(auto x) {
    return accumulate(x.begin(), x.end(), 0LL);
}

map<ll, int > prime_factor(ll n) {
  map<ll, int > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }

    return true;
}

int main() {
    ll A, B;
    cin >> A >> B;
    if (A > B) swap(A, B);
    map<ll, int> a = prime_factor(A);
    ll ans = 1;
    for (auto p : a) {
        if (B % p.first == 0) ans++;
    }
    print(ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_set>
#include <string>
#include <algorithm>

using namespace std;

int main() {
	int n, k, x, y;
	cin >> n >> k >> x >> y;
	cout << (min(k, n) * x + max((n-k), 0) * y) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <numeric>
#include <vector>

using namespace std;

int main(void){
    int n;
    cin >> n;
    vector<int> v;
    vector<bool> vb;
    v.reserve(n);
    vb.reserve(n - 1);
    for(int i = 0; i < n; ++ i){
        int tmp;
        cin >> tmp;
        v.push_back(tmp);
    }
    long tmpmax = 0, sum = 0;
    for(int i = 0; i < n; ++ i) sum += ((v[i] < 0)? -v[i] : v[i]);
    for(int i = 0; i < n; ++ i){
        if(i == 0) for(int j = n - 2; 0 <= j; -- j) vb[j] = ((j == n - 2)? (v[j + 1] < 0) : (vb[j + 1] != (v[j + 1] < 0)));
        else vb[i - 1] = ((i == 1)? v[0] < 0 : vb[i - 2] != v[i - 1] < 0);
        if(((i == 0)? vb[0] : ((i == n - 1)? vb[n - 2] : (vb[i - 1] != vb[i]))) == (v[i] < 0)){
            tmpmax = sum;
            break;
        }else{
            tmpmax = max(tmpmax, sum - 2 * abs(v[i]));
        }
    }
    cout << tmpmax << endl;
    
    return 0;
}


Measured memory_bytes: 640
let rec find a x n =
  if a.(n) = x then n else find a x (n+1);;

let print_array l =
  Array.fold_left (fun x y -> (if x = "" then "" else x^" ")^y) "" l |> print_endline;;

let to_array s = Str.split (Str.regexp_string " ") s |> Array.of_list;;

let bubble_sort c n =
  let b = Array.copy c in
  for i = 0 to n-1 do
    for j = n-1 downto i+1 do
      if Char.code b.(j).[1] < Char.code b.(j-1).[1] then
        let temp = b.(j) in
        b.(j) <- b.(j-1);b.(j-1) <-temp;
    done;
  done;
  b;;

let selection_sort c n =
  let b = Array.copy c in
  for i = 0 to n-1 do
    let minj = ref i in
    for j = i to n-1 do
      if Char.code b.(j).[1] < Char.code b.(!minj).[1] then
        minj := j
    done;
    let temp = b.(i) in
    b.(i) <- b.(!minj);b.(!minj) <- temp;
  done;
  b;;

let is_stable org c n =
  let rec loop = function
      i when i = n -> "Stable"
    | i ->
       if (Char.code c.(i).[1]) = (Char.code c.(i-1).[1]) then
         if find org c.(i) 0 > find org c.(i-1) 0 then loop (i+1)
         else "Not stable"
       else
         loop (i+1)
  in loop 1
;;

let () =
  let n = read_int() and
      a = read_line () |> to_array in
  let b = bubble_sort a n and
      s = selection_sort a n in
  let r1 = is_stable a b n and
      r2 = is_stable a s n in
  print_array b;
  print_endline r1;
  print_array s;
  print_endline r2
;;

Measured memory_bytes: 2096
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>

const long INF = (1l << 30);
const long LINF = (1l << 60);

std::string s, t;

int main(){
    std::cin >> s;
    std::cin >> t;
    long cnt =  0;
    for(int i = 0; i < 3; i++){
        if(s[i] ==  t[i]){
            cnt++;
        }
    }
    printf("%ld\n",cnt);
}


Measured memory_bytes: 256
#include<stdio.h>

int gcd( int a, int b )
{
 	while( a != 0 && b != 0 ){
		a %= b;
		if( a == 0 ) break;
		b %= a;
		if( b == 0 ) break;
	}
	
	return a + b;
}

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

int main()
{
	int a, b;
	while( scanf( "%d %d", &a, &b ) != EOF ){
		printf( "%d %d\n", gcd( a, b ), lcm( a, b ) );	
	}

 	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(){
    int n=0,i,cnt[100]={0},j=0,max=0,longer=0,cou[100]={0};
    char str,save[100][100];
    while(1){
        scanf("%c",&str);
        if(str=='\n') break;
        if(str!=' '){
            if(isupper(str)) {
                str = tolower(str);
            }
            save[j][n]=str;
            n++;
            cou[j]++;
        }else{
            for(i=0;i<j;i++){
                if(!strcmp(save[i],save[j])){
                    cnt[i]++;
                }
            }
            j++;
            n = 0;
        }
    }
    for(i=0;i<=j;i++){
        if(cnt[max]<=cnt[i]) max=i;
    }
    for(i=1;i<=j+1;i++){
        if(cou[longer]<=cou[i]){
            longer=i;
        }
    }
    printf("%s %s\n",save[max],save[longer]);

    return 0;
}

Measured memory_bytes: 564
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;

class Main{
    public static void main(String[] args) throws IOException{
        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        final Deque<Integer> st = new ArrayDeque<Integer>(128);
        final String[] in = br.readLine().split(" ");
        for(int i = 0; i<in.length; i++){
            if(in[i].equals("+")){
                final int b = st.poll();
                final int a = st.poll();
                st.addFirst(a+b);
            }else if(in[i].equals("-")){
                final int b = st.poll();
                final int a = st.poll();
                st.addFirst(a-b);
            }else if(in[i].equals("*")){
                final int b = st.poll();
                final int a = st.poll();
                st.addFirst(a*b);
            }else{
                st.addFirst(Integer.valueOf(in[i]));
            }
        }
        System.out.println(st.peek());
    }
}

Measured memory_bytes: 24360
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]
    MOD = 10**9+7

    H,W = LMIIS()
    S = [input() for _ in range(H)]
    # print(S)

    def tansaku(S,V,y,x,length):

        
        if  x >= 1 and S[y][x-1] == '.' and V[y][x-1] > length+1:
            V[y][x-1] = length+1
            tansaku(S,V,y,x-1,length+1)


        if x < W-1 and S[y][x+1] == '.' and V[y][x+1] > length+1:
            V[y][x+1] = length+1
            tansaku(S,V,y,x+1,length+1)


        if y >= 1 and S[y-1][x] == '.' and V[y-1][x] > length+1:
            V[y-1][x] = length+1
            tansaku(S,V,y-1,x,length+1)


        if y < H-1 and S[y+1][x] == '.' and V[y+1][x]> length+1:
            V[y+1][x] = length+1
            tansaku(S,V,y+1,x,length+1)

        return
    
    def getmax():
        max_length = 0
        for h in range(H):
            for w in range(W):
                V = [[MOD] * W for _ in range(H)]
                if S[h][w] == '.':
                    V[h][w] = 0
                    tansaku(S,V,h,w,0) 
                for v in V:
                    v = list(map(lambda x:x%MOD,v))
                    max_length = max(v+[max_length])
                    # print(V)
        return max_length
    
    print(getmax())
    






if __name__ == '__main__':
    main()

Measured memory_bytes: 112928
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb(x) push_back(x)
#define f(i,st,n) for(i=st;i<n;i++)
#define qu queue
#define ps(x) push(x)
#define vec vector
#define ft() front()
#define mst(a,b) memset(a,b,sizeof(a))
#define mod 1000000007
#define sfl(x) scanf("%lld",&x)
#define pfl(x) printf("%lld\n",x)
#define pf(x) printf("%lld",x)
#define mpr make_pair
#define fs first
#define se second
#define inf LLONG_MAX
 
 
 
ll gcd(ll a,ll b){
    if(a==0){
        return b;
    }                     
    return gcd(b%a,a);
}
ll power(ll x,ll y){            
    ll res=1;
    while(y>0){
        if(y%2==1){
            res=((res)*(x));
        }
        x=((x)*(x));
        y=y/2;
    }
    return res;
}
 
 ll n,h,l,r,a[2002],dp[2002][2002];

 ll fn(ll i,ll t){

    if(i==n)return 0;

    if(dp[i][t]!=-1)return dp[i][t];

    ll x=t+a[i];
    ll y=t+a[i]-1;
    x%=h;
    y%=h;
    dp[i][t]= max((x>=l&&x<=r)+fn(i+1,x),(y>=l&&y<=r)+fn(i+1,y));

    return dp[i][t];

 }
 
 
  
int main(){
 
  /*#ifndef ONLINE_JUDGE
    
   freopen("input.txt", "r", stdin);
   
   freopen("output.txt", "w", stdout);
   #endif*/

ll n,i;
sfl(n);
ll a[n],c[n+1];
mst(c,0);
f(i,0,n){
  sfl(a[i]);
  c[a[i]]++;

}

ll ans=0;

f(i,1,n+1){
ans+=(c[i]*(c[i]-1))/2;
}

f(i,0,n){
ll x=c[a[i]];



ll y=ans-((x*(x-1))/2)+max(0LL,((x-1)*(x-2))/2);

pfl(y);

}






 
  
 
   return 0;
 
    
 }

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

#pragma region template


// -type-
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;


// -const-
const ll MOD = 1000000007;


const ll MAX = (ll)0x3f0000003f000000;
const double EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1},
          dy[] = {1, 0, -1, 0, 1, -1, -1, 1};


// -define-
#define F first
#define S second

#define reps(i, k, n) for (int i = (k), i##_len = (n); i < i##_len; ++i)
#define rep(i, n) reps(i, 0, n)
#define all(o) begin(o), end(o)
#define sz(a) ((int)(a).size())
#define debug(x) cerr << x << " (L:" << __LINE__ << ")" << '\n';


// -functions-

inline bool in(string s, string c) {
    return (s.find(c) != string::npos);
}
inline bool in(string s, char c) {
    return (s.find(c) != string::npos);
}

template <class T>
void print(T& x) {
    cout << x << '\n';
}

struct setup_main {
    setup_main() {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(15);
    }
} setup_main_;

#pragma endregion

ll ans = 0;

void solve(long long N, long long M, std::vector<long long> A) {
    make_heap(all(A));
    rep(i, M) {
        pop_heap(all(A));
        A[N - 1] /= 2;
        push_heap(all(A));
    }
    for (auto&& i : A) {
        ans += i;
    }
    print(ans);
}
signed main() {
    long long N;
    scanf("%lld", &N);
    long long M;
    scanf("%lld", &M);
    std::vector<long long> A(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &A[i]);
    }
    solve(N, M, std::move(A));

    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
 int main(){
      int a,b;
      scanf("%d %d",&a,&b);
      if(a<b){
             printf("a < b\n");
      }
      else if(a>b){
	     printf("a > b\n");
      }
      else{
	     printf("a == b\n");
      }
      return 0;
}

Measured memory_bytes: 2532
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define RREP(i,a,b) for (int i = a; i > (b); --i)
#define all(x) (x).begin(),(x).end()
#define YY cout << "Yes" << endl
#define NN cout << "No" << endl
const int INF = 1000000007;
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
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); }
int solve(){
  ll n,m;
  cin>>n>>m;
  ll ans = 0;
  ans = min(n,m / 2);
  n -= ans;
  m -= ans * 2;
  if(n == 0){
    ans += m / 4;
  }
  cout << ans << endl;
  return 0;
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  // cout << fixed;cout << setprecision(16);
  solve();
  return 0;
}

Measured memory_bytes: 256
#pragma comment (linker, "/STACK:256000000")
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 2000000000000000000LL
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long a = 0;a < b;++a)
#define ALL(x) (x).begin(),(x).end()
void init() {
    iostream::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}
void solve() {
    int n;
    cin >> n;
    int back = 0;
    int ans = 0;
    cin >> back;
    REP(i, n-1) {
        int t;
        cin >> t;
        if (back >= t) {
            ans++;
        }
        back = t;
    }
    cout << ans+1LL << endl;
    cout << n << endl;
}
int main() {
    init();
    solve();
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
// 型エイリアス
using pii = pair<int, int>;
using tisb = tuple<int, string, bool>;
using vi = vector<int>;
using vii = vector<vi>;

void print(vi A, int N){
  for(int i=0; i<N; ++i){
    if(i>0) cout << " ";
    cout << A[i];
  }
  cout << endl;
}

int selectionSort(vi &A, int N){
  int count = 0;

  for(int i=0; i<N; ++i){
    int minj = i;

    for(int j=i; j<N; ++j){
      if(A[j] < A[minj]) minj = j;
    }
    
    swap(A[i], A[minj]);
    if(minj != i) ++count;
  }

  return count;
}

int main(){
  int N; cin >> N;
  vi A(N);
  for(int i=0; i<N; ++i) cin >> A[i];

  int count = selectionSort(A, N);
  print(A, N);
  cout << count << endl;
}


Measured memory_bytes: 3156
import java.util.*;
public class Main {
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int D = sc.nextInt();

        int i = 1;

        while(A > 0 && C >0) {
        	if(i % 2 != 0) {
        		C = C - B;
        	} else {
        		A = A - D;
        	}
        	i++;
        }

        if(C <= 0) {
        	System.out.println("Yes");
        } else {
        	System.out.println("No");
        }
    }
}

Measured memory_bytes: 26920
#pragma region macro
#include <bits/stdc++.h>
using i64 = int_fast64_t;
#define repeat(i, a, b) for(int i = (a); (i) < (b); ++(i))
#define rep(i, n) repeat(i, 0, n)

namespace std {
template <typename A, typename B>
string to_string(pair<A, B> p);

string to_string(const string &s) {
    return '"' + s + '"';
}

string to_string(const char *s) {
    return to_string((string)s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for(int i = 0; i < static_cast<int>(v.size()); i++) {
        if(!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for(size_t i = 0; i < N; i++) {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
};  // namespace std
#pragma endregion

void solve() {
    int n, m, q;
    std::cin >> n >> m >> q;
    std::vector<std::vector<int>> s(q, std::vector<int>(4));
    for(auto &e : s) {
        std::cin >> e[0] >> e[1] >> e[2] >> e[3];
        e[0]--;
        e[1]--;
    }
    std::queue<std::vector<int>> que;
    rep(i, m) {
        que.emplace(std::vector<int>{i});
    }
    while(que.front().size() <= n) {
        std::queue<std::vector<int>> qque;
        while(!que.empty()) {
            auto p = que.front();
            que.pop();
            for(auto i = *(p.end() - 1); i < m; i++) {
                p.emplace_back(i);
                qque.emplace(p);
                p.pop_back();
            }
        }
        que = qque;
    }
    i64 ans = -1;
    while(!que.empty()) {
        auto v = que.front();
        que.pop();
        i64 temp = 0;
        for(auto &e : s) {
            if(v[e[1]] - v[e[0]] == e[2]) {
                temp += e[3];
            }
        }
        ans = std::max(ans, temp);
    }
    std::cout << ans << std::endl;
}

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

Measured memory_bytes: 32564
// ----------------------------------------------------------
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <numeric>

using namespace std;


int main(int argc, const char * argv[]) {
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string S;
    int ans = 0;
    
    cin >> S;
    
    for(int i=0;i<S.length()-1;i++){
        if(S[i]==S[i+1]){
            ans = 1;
        }
    }
    
    if(ans){
        cout << "Bad" << endl;
    }else{
        cout << "Good" << endl;
    }
    
    return 0;
}


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

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

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    string S;
    ll K;
    ll count;
    char prev = '\0';
    vector<string> renzoku;
    cin >> S;
    cin >> K;
    iter(c, S) {
        if(c != prev) renzoku.push_back("");
        renzoku.back().push_back(c);
        prev = c;
    }
    if(S.size() == renzoku.front().size()) {
        count = K * S.size() / 2;
    } else {
        if(renzoku.front()[0] == renzoku.back()[0]) count = (K - 1) * ((renzoku.front().size() + renzoku.back().size()) / 2); 
        else count = (K - 1) * (renzoku.front().size() / 2 + renzoku.back().size() / 2);
        rep2(i, 1, renzoku.size() - 1) count += K * (renzoku[i].size() / 2);
        count += renzoku.front().size() / 2;
        count += renzoku.back().size() / 2;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1)
int main()
{
    int n,a;
    map<int,int>mp;

     cin>>n;
     for(int i=0;i<n-1;i++){
        cin>>a;
        mp[a]++;
     }
     for(int i=1;i<=n;i++){
        cout<<mp[i]<<endl;
     }
}


Measured memory_bytes: 13004
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
using namespace std;

int main(){
    long long n, m;
    cin >> n >> m;
    long long ans = 0;
    if(n > 2 && m > 2) ans = (n-2) * (m-2);
    else if (n == 2 || m == 2) ans = 0;
    else if ((n == 1 && m != 1) || (n != 1 && m == 1)) ans = (n==1 ? n*(m-2):(n-2)*m);
    else ans = 1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define pb          push_back
#define mp          make_pair
#define ll          long long
#define pii         pair<int, int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int, int>
#define mii         map<pii, int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rev(i,a,b)  for(int i=a;i>=b;i--)
#define lb          lower_bound
#define ub          upper_bound

#define bg(i)       i.begin()
#define fset(it,s)   for(auto it = s.begin(); it != s.end(); it++)
 
#define track(x)                 cerr<<#x<<": "<<x<<endl
#define track2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define track3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define track4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
 
#define ed(i)       i.end()
#define mem(a)	    memset(a, 0, sizeof(a))

#define MOD         1000000007
int mult(int a,int b, int p=MOD){return ((a%p)*(b%p))%p;}
int add(int a, int b, int p=MOD){return (a + b + p)%p;}
int fpow(int n, int k, int p = MOD) {int r = 1; for (; k; k >>= 1LL) {if (k & 1LL) r = mult(r,n,p); n = mult(n,n,p);} return r;}
int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
void self_max(int &a, int b) {a = max(a, b); }
void self_min(int &a, int b) {a = min(a, b); }
void self_add(int &a, int b, int p = MOD) { a += b; if(a >= p) a -= p;}
void self_sub(int &a, int b, int p = MOD) { a -= b; if(a < 0) a += p;}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
const int INF = 1e9 + 5;
#define N	    	400001

int ans[N];
void solve(){
    int n, m;
    cin>>n>>m;
    int height[n+1];
    rep(i, 1, n+1)
        cin>>height[i];
    rep(i, 0, m) {
        int a, b;
        cin>>a>>b;
        if(height[a] > height[b]) 
            ans[b] = true;
        else if(height[a] < height[b])
            ans[a] = true;
        else
            ans[a] = ans[b] = true;
    }
    int cnt = 0;
    rep(i, 1, n+1)
        if(!ans[i])
            cnt++;
    cout<<cnt<<endl;

}
int main() {
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
//	cin>>t;
	while(t--){
		solve();
	}
}


Measured memory_bytes: 4436
using System;
using System.Linq;
using System.Collections.Generic;

class Bmondai {
    static void Main()
    {
        var num = Int32.Parse(Console.ReadLine());
        var list = new List<int>();
        for (int i=0;i<num;++i)
        {
            list.Add(Int32.Parse(Console.ReadLine()));
        }
        var newList = list.OrderByDescending(x=>x);
        var isFirst = true;
        var ans = 0L;
        foreach (var l in newList)
        {
            if (isFirst)
            {
                ans += (l / 2);
                isFirst = false;
            }
            else
            {
                ans += l;
            }
        }
        Console.WriteLine(ans);
    }
}

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


int main(void) {
	int n; cin >> n;
	int ary[n];
	int Maximum = INT_MIN;
	int Minimum = INT_MAX;
	ll sum = 0;
	for(int r = 0; r < n; r++) {
		cin >> ary[r];
		if(ary[r] > Maximum)
			Maximum = ary[r];
		if(ary[r] < Minimum)
			Minimum = ary[r];
		sum += ary[r];
	}
	cout << Minimum << " " << Maximum << " " << sum << endl;
	return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N,M;
  cin >> N;
  vector<string> s(N);
  for (int i=0; i<N;i++){
  	cin >> s.at(i);
  }
  cin >> M;
  vector<string> t(M);
  for (int i=0; i<M; i++){
  	cin >> t.at(i);
  }
  
  int max1 = 0;
  
  int score = 0;
  
  string moji;
  
  for (int i=0; i<N; i++){
  	score=0;
    moji = s.at(i);
  	for (int i=0; i<N; i++){
  		if (s.at(i) == moji) score++;
  	}
   	for (int i=0; i<M; i++){
    	if (t.at(i) == moji) score--;
    }
    max1=max(max1,score);
    
  }
  
  cout << max1 << endl;
		
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#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 FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

int main(){
  int x;
  int i = 1;
  while(1){
    cin >> x;
    if(x == 0) return 0;
    else{
      cout << "Case " << i << ": " << x << endl;
    }
    i++;
  }
}



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

int main() {
  int W, H, x, y;
  cin >> W >> H >> x >> y;

  bool flag = false;
  if ((W % 2 == 0 && W / 2 == x) && (H % 2 == 0 && H / 2 == y))
    flag = true;
  double ans = (double)W * H / 2.0;
  printf("%.9f %d\n", ans, flag ? 1 : 0);
}

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

int main()
{
    long n; cin>>n;
    if (n==0) { cout<<"0"<<endl; return 0; }

    string res;
    for(long b=2; n; b*=-2) {
        auto m=abs(n)%abs(b);
        res+=char('0'+!!m);
        if (m) n-=b/2;
    }
    reverse(begin(res), end(res));
    cout<<res<<endl;
}


Measured memory_bytes: 256
n, k = map(int, input().split())

ans = 0
for b in range(1, n + 1):
    # n = pb + r
    p, r = divmod(n, b)
    ans += p * max(b - k, 0) + max(r - k + 1, 0)
    if k == 0:
        ans -= 1

print(ans)

Measured memory_bytes: 3060
#include<stdio.h>
int main()
{
  int i,j,k,l,m,n;

  scanf("%d",&n);
  int a[n][n];

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      a[i][j]=0;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&k,&l);
    for(j=0;j<l;j++){
      scanf("%d",&m);
      a[k-1][m-1]=1;
    }
  }
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(j!=0){
	printf(" ");
      }
      printf("%d",a[i][j]);
    }
    printf("\n");
  }
  
  return 0;
}

Measured memory_bytes: 640
#include<cstdio>
int main(){
	char s[20]={};
	int a,b;
	scanf("%d%d",&a,&b);
	scanf("%s",s);
	int ans=0;
	for(int i=0;i<a;i++){
		if(s[i]<'0' || s[i]>'9')ans++;
	}
	if(s[a]!='-')ans++;
	for(int i=a+1;i<=a+b;i++){
		if(s[i]<'0' || s[i]>'9')ans++;
	}
	
	if(ans==0)printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    long long N;
    cin >> N;
    long long A[200000];
    long long max = 0, ans = 0;
    for(int i = 0; i < N; i++)
    {
        cin >> A[i];
        if(A[i] < max)
            ans += max-A[i];
        else
        {
            max = A[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5124
#include <iostream>

using namespace std;

int dp[305][305];
int SP[305][305];
int C[305][305];
int N,K,M;

int adun(int a,int b){
    a += b;
    if(a >= M){
        a -= M;
    }
    return a;
}

int mult(int a,int b){
    return 1LL * a * b % M;
}

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

    for(int i = 0;i <= 304;i++){
        C[i][i] = 1;
        C[i][0] = 1;
        for(int j = 1;j < i;j++){
            C[i][j] = adun(C[i - 1][j - 1] , C[i - 1][j]);
        }
    }

    dp[0][0] = 1;
    SP[0][0] = 1;
    for(int k = K;k >= 0;k--){
        dp[1][k] = 1;
        SP[1][k] = adun(SP[1][k + 1] , dp[1][k]);
    }
    for(int i = 2;i <= N + 1;i++){
        for(int j = K;j >= 0;j--){
            for(int k = 1;k < i;k++){
                dp[i][j] = adun(dp[i][j] , mult(dp[i - k][j] , mult(C[i - 2][k - 1] , SP[k][j + 1])));
            }
            SP[i][j] = adun(SP[i][j + 1] , dp[i][j]);
        }
    }

    cout << dp[N + 1][0];
    return 0;
}


Measured memory_bytes: 1280
# coding: utf-8
from math import ceil
N, H = map(int, input().split())
li = []
atop = 0
for _ in range(N):
    a, b = map(int, input().split())
    atop = max(atop, a)
    li.append([a, b])
li.sort(key=lambda x: x[1], reverse=True)
# print(li)
ans = ceil(H/atop)
cnt = 0
for i in range(N):
    H -= li[i][1]
    cnt += 1
    ans = min(ans, cnt + max(0, ceil(H/atop)))
print(ans)

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

string c[2];

int main() {
	cin >> c[0] >> c[1];

	bool flag = true;
	for (int i = 0; i < 3; i++) {
		if (c[0][i] != c[1][3 - i - 1 ])flag = false;
	}

	if (flag) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 888
using System;
using System.Linq;
class p
{
  static void Main()
  {
    string[] input = Console.ReadLine().Split(' ');
    int A = int.Parse(input[0]);
    int B = int.Parse(input[1]);
    int C = int.Parse(input[2]);
    int K = int.Parse(Console.ReadLine());
    
    int[] arr = new int[] { A, B, C };
    for (int i = 0; i < K; i++) {
      int index = Array.IndexOf(arr, arr.Max());
      arr[index] *= 2;
    }
    Console.WriteLine(arr.Sum());
  }
}

Measured memory_bytes: 11220
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>
#include <cctype>
#include <map>
#include <limits>
#include <iomanip>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ll long long

int main()
{
	double r;
	cin >> r;

	double result = r * 2 * M_PI;

	cout << result << endl;
	return 0;
}

Measured memory_bytes: 3796
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int n = 1e+9;

int area(int x1, int y1, int x2, int y2, int x3, int y3) {
	return (x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1);
}

void solve(int s) {
	int x1, y1, x2, y2, x3, y3;
	rep(x1, n + 1)
		rep(y1, n + 1)
			rep(x2, n + 1)
				rep(y2, n + 1)
					rep(x3, n + 1)
						rep(y3, n + 1)
							if (area(x1,y1,x2,y2,x3,y3) == s) {
								cout << x1 << ", " << y1 << " | " << x2 << ", " << y2 << " | " << x3 << ", " << y3 << endl;
								return;
							}
}

signed main() {
	/*for (int s = 1; s <= n * n; s++) {
		cout << "s = " << s << ": ";
		solve(s);
		cout << endl;
	}*/
	
	int s;
	cin >> s;
	
	int x2 = (s + n - 1) / n;
	int x3 = (x2 - s % x2) % x2;
	int y2 = (x3 == 0) ? 0 : 1;
	int y3 = (s + x2 - 1) / x2;
	
	cout << 0 << " " << 0 << " " << x2 << " " << y2 << " " << x3 << " " << y3 << endl;
	//cout << "area = " << area(0, 0, x2, y2, x3, y3) << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
     Scanner sc = new Scanner(System.in);
     int n = 0;
     if(sc.hasNextInt())
            n = sc.nextInt();
        int[] dp = new int[3];
     for(int i = 0 ; i < n ; i++)
     {
     int[] ndp = new int[3];
     Arrays.fill(ndp,0);
    int[] x = new int[3];
for(int j = 0 ; j < 3 ; j++)
{
    x[j] = sc.nextInt();
}
     //x[0] = 0;
     for(int j = 0 ; j < 3 ; j++)
     {
         for(int k = 0 ; k < 3 ; k++)
         {
             if(j != k)
             {
                 ndp[k] = Math.max(ndp[k] , dp[j]+x[k]);
             }
         }
     }
     dp = ndp;

     }
      int max =  Math.max(Math.max(dp[0],dp[1]),dp[2]);
          System.out.println(max);

    }
}


Measured memory_bytes: 89124
#include <cmath>
#include <cstdio>

#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <numeric>
#include <string>
#include <array>
#include <iomanip>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(), x.end()

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  ll n, m, d;
  cin >> n >> m >> d;
  double ans;
  if(d == 0) ans = 1/double(n) * double(m-1);
  else ans = double(2*(n-d))/double(n)/double(n) * double(m-1);
  cout << fixed << setprecision(10) << ans << endl;


  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
	int n,m,p,q,r,x,y,t;
	vector<int>::iterator itx,ity,it;
	for(;cin>>n>>m>>p>>q>>r;cout<<x<<endl){
		vector<int> v1,v2;
		v1.push_back(0);
		v1.push_back(r);
		
		for(;m--;v2.clear()){
			cin>>x>>y;
			itx=upper_bound(v1.begin(),v1.end(),x);
			ity=upper_bound(v1.begin(),v1.end(),y);
			
			if( ity-v1.begin()+1 & 1 )v2.push_back(0);
			v2.push_back(0);
			for(it=ity;it!=v1.end();++it)
				v2.push_back(*it - y);
			
			if(v1.end()-itx & 1)v2.push_back(n-y);
			for(it=itx;it!=ity;++it)
				v2.push_back(*it-x+n-y);
			
			it = v1.begin();
			if(ity-v1.begin() & 1)++it;
			for(;it!=itx;++it)
				v2.push_back(*it+n-x);
			
			v1.swap(v2);
		}
		v1.insert( upper_bound(v1.begin(),v1.end(),p-1), 2, p-1);
		v1.insert( lower_bound(v1.begin(),v1.end(),q), q );
		v1.push_back(n);
		it = upper_bound(v1.begin(),v1.end(),p-1);
		if(it-v1.begin() & 1) --it;
		for(x=0;*it<q;++it){
			m=*it;
			++it;
			x+=*it-m;
		}
	}
}

Measured memory_bytes: 1012
#include <bits/stdc++.h>
#define INF 2000000000000000000
#define ll long long
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll mod = pow(10, 9) + 7;
  ll N, M;
  cin >> N >> M;
  vector<ll> S(N), T(M);
  for (ll i = 0; i < N; ++i) {
    cin >> S.at(i);
  }
  for (ll i = 0; i < M; ++i) {
    cin >> T.at(i);
  }
  // S.at(i - 1) == T.at(j - 1)のパターン数
  vector<vector<ll>> dp(N + 2, vector<ll>(M + 2, 0));
  dp.at(0).at(0) = 1;
  vector<vector<ll>> sum(N + 2, vector<ll>(M + 2, 0));
  for (ll i = 0; i < N + 2; ++i) {
    sum.at(i).at(0) = 1;
  }
  for (ll i = 0; i < M + 2; ++i) {
    sum.at(0).at(i) = 1;
  }
  //dp.at(i).at(j)までの和
  for (ll i = 1; i <= N; ++i) {
    for (ll j = 1; j <= M; ++j) {
      sum.at(i).at(j) = sum.at(i).at(j - 1) + sum.at(i - 1).at(j) - sum.at(i - 1).at(j - 1);
      if (sum.at(i).at(j) < 0) {
        sum.at(i).at(j) += mod;
      }
      sum.at(i).at(j) %= mod;
      if (S.at(i - 1) == T.at(j - 1)) {
        dp.at(i).at(j) = sum.at(i - 1).at(j - 1);
        sum.at(i).at(j) += dp.at(i).at(j);
        sum.at(i).at(j) %= mod;
      }
    }
  }
  // for (ll i = 0; i <= N; ++i) {
  //   for (ll j = 0; j <= M; ++j) {
  //     cout << sum.at(i).at(j) << " ";
  //   }
  //   cout << "\n";
  // }
  cout << sum.at(N).at(M) << "\n";
}


Measured memory_bytes: 65936
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
int main()
{
    int n;
    scanf("%d",&n);
    vector<ll> ns(n);
    int i;
    for(i=0;i<n;i++)
        scanf("%lld",&ns[i]);
    ll mi,ma;
    if(ns[n-1] != 2)
    {
        printf("-1\n");
        return 0;
    }
    mi = 2;
    ma = 3;
    for(i=n-2;i>=0;i--)
    {
        if(ns[i] > ma)
        {
            printf("-1\n");
            return 0;
        }
        if(mi%ns[i] != 0)
            mi += ns[i]-mi%ns[i];
        if(ma%ns[i] != 0)
            ma -= ma%ns[i];
        ma += ns[i]-1;
        if(mi > ma)
        {
            printf("-1\n");
            return 0;
        }
    }
    printf("%lld %lld\n",mi,ma);
    return 0;
}


Measured memory_bytes: 1024
n = int(input())
XLs = [list(map(int, input().split())) for i in range(n)]
for i in range(n):
    x = XLs[i][0]
    l = XLs[i][1]
    XLs[i].append(x+l) # 右腕の端の位置の情報を添える

XLs.sort(key=lambda x:x[2]) # 右腕の端の位置でソート

choice = -10**10 # 十分小さく(ロボの左腕の端の座標は最大でも -10*9)
cnt = 0
for i in range(n):
  x = XLs[i][0]
  l = XLs[i][1]
  if choice <= x-l: # 腕がかぶってるか判定
    choice = x+l
    cnt+=1 # 被っていなければ残す = カウント+1
print(cnt)

Measured memory_bytes: 31824
package main

import "fmt"

func main() {
	var N, M int
	fmt.Scan(&N, &M)
	A := make([]int, N)
	S := 0
	for i := range A {
		fmt.Scan(&A[i])
		S += A[i]
	}
	ans := 0
	for i := range A {
		if A[i]*4*M >= S {
			ans++
		}
	}
	if ans >= M {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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

void solve()
{
    	   
 int n,k; cin>>n>>k;
 int a[n]; for(int i=0;i<n;i++)cin>>a[i];
 
 int dp[n];
 dp[0]=0;
 int cnt;
 
 dp[1]=abs(a[1]-a[0]);
 for(int i=2;i<n;i++)
 {
     
     int temp=INT_MAX;
     cnt=1;
     
     while(cnt<=k&&(i-cnt)>=0)
     {
         temp=min(temp,dp[i-cnt]+abs(a[i]-a[i-cnt]));
         cnt++;
     }
     dp[i]=temp;
 }
 cout<<dp[n-1];
  
 
}
 
 
 signed main()
 {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    
    
    
    int T; 
    T=1;
    //cin>>T;
    while(T--)
    {
          solve();
    }
    
    
        return 0;
	
}

Measured memory_bytes: 5144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;++i)
#define MOD 1000000007

int main(){
    string w;
    cin >> w;
    map<char, int> m;
    rep(i, w.size()){
        m[w[i]]++;
    }
    for(auto i=m.begin(); i!=m.end(); i++){
        int tmp = i ->second;
        if(tmp%2==1){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

#define fi first
#define se second
#define pb push_back
#define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,a,b) for(int i = a; i < b; i++)
#define forr(i,a,b) for(int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int N; cin >> N;
	ll res = 0;
	for(ll i = 1; i <= N; i++){
		ll x = N-i+1;
		res += x*(x+1)/2ll;
	}
	forn(i,0,N-1){
		ll u,v; cin >> u >> v;
		if(u > v)swap(u,v);
		res -= u*(N-v+1);
	}
	cout << res << '\n';
	return 0;
}
/*
__builtin_mul_overflow(x,y,&x)
-fsplit-stack
*/


Measured memory_bytes: 3616
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int main() {
  std::string S; std::cin >> S;
  for(int i = 0; i < 3; ++i) if(S[i] == S[i+1]) fin("Bad");
  fin("Good");
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define T 1000
#define M 1000000007
#define E e[x][i]
#define S e[x].size()
using namespace std;
typedef long long ll;
 
ll func(int);
 
int N,s,t;
string n[T];
vector<int> e[T];
 
int main(){
  cin>>N;
  for(int i=0;i<N;i++) cin>>n[i];
  for(int i=0;i<N-1;i++) cin>>s>>t,e[s-1].push_back(t-1);
  cout<<func(0)%M<<endl;
  return 0;
}

ll func(int x){
  ll res=0,res2=1;
  if(!e[x].size()){
    if(n[x]=="E") return 1;
    if(n[x]=="E?") return 2;
    return 0;
  }
  if(n[x][0]=='E'){
    for(int i=0;i<S;i++) res2*=func(E);
    if(n[x]=="E?") res2++;
    return res2%M;
  }
  if(n[x][0]=='A'){
    for(int i=0;i<S;i++) res+=func(E);
    if(n[x]=="A?") res++;
    return res%M;
  }
  if(n[x][0]=='R'){
    for(int i=0;i<S;i++) res2*=(1+func(E));
    if(n[x]=="R") res2--;
    return res2%M;
  }
}

Measured memory_bytes: 1356
#include<iostream>
#include<cstdio>

using namespace std;

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

int hanako[200],taro[200];

int main()
{
	int n,m;
	while(cin >> n >> m,n)
	{
		int h_sum = 0,t_sum = 0;
		REP(i,n)
		{
			cin >> taro[i];
			t_sum += taro[i];
		}
		REP(i,m)
		{
			cin >> hanako[i];
			h_sum += hanako[i];
		}
		int t = -1,h = -1,sum = 10000;
		REP(i,n)
		{
			REP(j,m)
			{
				int t_tmp,h_tmp;
				t_tmp = t_sum - taro[i] + hanako[j];
				h_tmp = h_sum + taro[i] - hanako[j];
				if(h_tmp == t_tmp)
				{
					if(sum > taro[i] + hanako[j])
					{
						sum = taro[i] + hanako[j];
						t = taro[i];
						h = hanako[j];
					}
				}
				
			}
			
		}
		if(t == -1)
			cout << -1 << endl;
		else
			cout << t << ' ' << h << endl;
		
	}
	
	return 0;
}

Measured memory_bytes: 2992
#include <bits/stdc++.h>
#include <array>
#define FOR(i,a,b) for(int i=(a);i<=(b);++i) 
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i) 
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>0;--i)
#define CI cin>> 
#define CO cout<<
#define EN <<endl 
#define all(x) (x).begin(),(x).end() 
using namespace std;
template <typename T> istream & operator >> (istream & is, vector<T> & vec) { for (T& x : vec) is >> x; 	return is; }
using ll = long long;
using VI = vector<int>;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
int a[1000000] = {};

int main() {
	int s; CI s;
	a[s]++;
	for (int i = 2;; i++) {
		if (s % 2) {
			s = 3 * s + 1;
			a[s]++;
		}
		else {
			s = s / 2;
			a[s]++;
		}
		if (a[s] == 2) {
			CO i EN; return 0;
		}
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <string>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <stack>
#include <cstdio>
#include <climits>
#include <tuple>
#include <ctime>
#define FOR(i,a,n) for (int i = a; i < n; i++)
#define IFOR(i,n,a) for (int i = n; i >= a; i--)
#define mp make_pair
#define full(a) a.begin(), a.end()
#define SZ(x) ((int)(x).size())
#define TC(tc) while (tc--)
#define VI vector<int>
#define PII pair<int, int>
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
using namespace std;
const int mod = 1e9 + 7;

int main() 
{
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int a; cin >> a;
	cout << a + (a * a) + (a * a * a);
	
}




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

using u32 = uint32_t;
using u64 = uint64_t;
using i32 = int32_t;
using i64 = int64_t;

struct vtx {
	u32 key;
	u32 val;
};

int main()
{
	std::ios_base::sync_with_stdio(0);
	
	u32 n;

	std::cin >> n;

	struct vtx_comp
	{
		bool operator()(const vtx& a, const vtx& b)
		{
			return a.key < b.key;
		}
	};

	std::set<vtx, vtx_comp> st;

	for(u32 i=1; i<=n; i++)
	{
		u32 x;
		std::cin >> x;
		st.insert(vtx{x, i});
	}

	for(auto it=st.begin(); it!=st.end(); it++)
	{
		std::cout << it->val << " ";
	}

	std::cout << "\n";
	
	return 0;
}

Measured memory_bytes: 5504
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <vector>

#define loop(i, times) for(int i = 0; i < times; i++)
#define seloop(i, start_index, end_index) for(int i = start_index; i < end_index; i++)
#define eqseloop(i, start_index, end_index) for(int i = start_index; i <= end_index; i++)

using namespace std;

struct Town
{
	int prefectures_;	// 都道府県
	long time_;			// 街生成時間
	string id_;			// 認識番号
};

int main()
{
	int n;  cin >> n;
	int m;	cin >> m;
	vector<Town> town_collection;
	town_collection.resize(m + 1);

	// 街のデータ入力
	loop(i, m)
		cin >> town_collection[i].prefectures_ >> town_collection[i].time_;

	// 街が出来た時間でソートするためのコンテナを作る
	vector<vector<pair<int, Town*>>> time_collection;
	time_collection.resize(n + 1);
	loop(i, m)
		time_collection[town_collection[i].prefectures_].push_back(std::make_pair(town_collection[i].time_, &town_collection[i]));

	string p;
	string x;
	for (int prefecture_index = 1; prefecture_index < n + 1; prefecture_index++)
	{	// 街が出来た時間でソートして認識番号を作る
		sort(time_collection[prefecture_index].begin(), time_collection[prefecture_index].end());

		int time_index = 1;
		for (const auto& e : time_collection[prefecture_index])
		{
			p.resize(6, '0');
			p.replace(6 - to_string(prefecture_index).size(), to_string(prefecture_index).size(), to_string(prefecture_index));
			x.resize(6, '0');
			x.replace(6 - to_string(time_index).size(), to_string(time_index).size(), to_string(time_index));
			e.second->id_ = p + x;
			p.clear();
			x.clear();
			time_index++;
		}
	}

	// 結果出力
	for (const auto& e : town_collection)
		cout << e.id_ << endl;
}


Measured memory_bytes: 13952
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<bitset>
#include<queue>
#include<set>
#include<map>
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define ROF(i,b,a) for (int i=(b);i>(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,n-1,-1)

typedef int i32;
typedef long long int i64;
typedef unsigned long long int ui64;
typedef float f32;
typedef double f64;
typedef long double f128;
typedef pair<int,int> Pi;

constexpr int INF = 1e9 + 7;
constexpr int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

int main() {
    int a,b,c,d,e,f; cin>>a>>b>>c>>d>>e>>f;
    int water=0,sugar=0;
    int answ=100*a,anss=0;
    REP(i,31) {
        REP(j,31) {
            water = 100*(a*i+b*j);
            int res = f-water;
            if (res<=0) break;
            res = min(res,water*e/100);
            REP(k,res+1) {
                REP(l,res+1) {
                    sugar = c*k+d*l;
                    if (sugar>res) break;
                    if (sugar*(answ+anss)>(water+sugar)*anss) answ=water,anss=sugar;
                }
            }
        }
    }
    cout<<answ+anss<<" "<<anss<<endl;
}


Measured memory_bytes: 256
package main

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

func main() {
	S := ReadString()
	ans := 0
	for i := 0; i < 1<<len(S); i++ {
		v := 0
		now := 0
		for j := 0; j < len(S); j++ {
			now = now*10 + int(S[j]) - '0'
			if (i>>j)&1 == 1 {
				v += now
				now = 0
			}
		}
		v += now
		ans += v
	}
	fmt.Println(ans / 2)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


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

typedef long long ll;
typedef unsigned long long ull;

int main(void) {
    ll X;
    ll minDistance = LONG_MAX;
    cin >> X;
    vector<bool> expo(X);
    expo[0] = true;
    for(ll b = 2;b <= X;b++) {
        ll x = b * b;
        while(x <= X) {
            expo[x - 1] = true;
            x *= b;
        }
    }
    for(ll x = X;x >= 0;x--) {
        if(expo[x - 1]) {
            cout << x << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256