akhauriyash/Code-Regression huggingface dataset:
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		sc.close();

		Map<Integer, Integer> soinsu = bunkai(m);
		long ans = 1;
		for (int k : soinsu.keySet()) {
			int v = soinsu.get(k);
			ans *= nCr(v + n - 1, v);
			ans %= 1000000007;
		}
		System.out.println(ans);
	}

	static Map<Integer, Integer> bunkai(int n) {
		Map<Integer, Integer> soinsu = new HashMap<Integer, Integer>();
		int d = 2;
		while (n > 1) {
			if (n % d == 0) {
				n /= d;
				if (soinsu.containsKey(d)) {
					soinsu.put(d, soinsu.get(d) + 1);
				} else {
					soinsu.put(d, 1);
				}
			} else {
				d++;
			}
		}
		return soinsu;
	}

	static long nCr(long n, long r) {
		long m = 1000000007;
		long val = 1;
		for (int i = 1; i <= r; i++) {
			val = val * (n - i + 1) % m;
			val = val * modinv(i, m) % m;
		}
		return val;
	}

	static long modinv(long a, long m) {
		long b = m;
		long u = 1;
		long v = 0;
		long tmp = 0;

		while (b > 0) {
			long t = a / b;
			a -= t * b;
			tmp = a;
			a = b;
			b = tmp;

			u -= t * v;
			tmp = u;
			u = v;
			v = tmp;
		}

		u %= m;
		if (u < 0) u += m;
		return u;
	}
}


Measured memory_bytes: 23124
// +build ignore
package main

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

func solve(sc *scanner, wr *bufio.Writer) int {
	N := sc.i()
	A := make([]uint64, N)
	for i := 0; i < N; i++ {
		A[i] = uint64(sc.i())
	}
	sort.Slice(A, func(i, j int) bool {
		return A[i] < A[j]
	})
	sum := uint64(1)
	for i := 0; i < N; i++ {
		border := uint64(1000000000000000000) / sum
		if border < A[i] {
			fmt.Println("-1")
			return 0
		}
		sum *= A[i]
		if sum == 0 {
			break
		}
	}
	fmt.Println(sum)

	return 0
}

func main() {
	sc := newScanner(os.Stdin)
	wr := bufio.NewWriter(os.Stdout)
	ret := solve(sc, wr)
	wr.Flush()
	os.Exit(ret)
}

// I/O
type scanner struct {
	sc *bufio.Scanner
}

func newScanner(input io.Reader) *scanner {
	sc := bufio.NewScanner(input)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &scanner{sc}
}

func (s *scanner) s() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *scanner) i() int {
	i, e := strconv.Atoi(s.s())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *scanner) f() float64 {
	f, e := strconv.ParseFloat(s.s(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *scanner) bs() []byte {
	return []byte(s.s())
}

func (s *scanner) is(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.i()
	}
	return res
}

func (s *scanner) fs(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.f()
	}
	return res
}


Measured memory_bytes: 5836
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()
#define reall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))

int main(){

	int x;
	cin >> x;
	int sum = 0, ans = 0;
	while(true){
		sum += x;
		ans++;
		if(sum%360 == 0){
			cout << ans << endl;
			return 0;
		}
	}

	return 0;
}


Measured memory_bytes: 3604
// "header" {{{
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <tuple>

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int> 
#define int long long
#define Fixed fixed << setprecision(10)
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1000000007;

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;

inline double sqrt( const double &x) 
{
	double         xHalf = 0.5 * x;
	int64_t  tmp   = 0x5FE6EB50C7B537AAl - ( *(int64_t*)&x >> 1);
	double         xRes  = * (double*)&tmp;

	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	return xRes * x;
}
// }}}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b,c,d;
	cin >> a;
	d = (a % 10);
	a /= 10;
	c = (a % 10);
	a /= 10;
	b = (a % 10);
	a /= 10;
	if(a + b + c + d == 7) cout << a << '+' << b << '+' << c << '+' << d << "=7\n";
	else if(a + b + c - d == 7) cout << a << '+' << b << '+' << c << '-' << d << "=7\n";
	else if(a + b - c + d == 7) cout << a << '+' << b << '-' << c << '+' << d << "=7\n";
	else if(a + b - c - d == 7) cout << a << '+' << b << '-' << c << '-' << d << "=7\n";
	else if(a - b + c + d == 7) cout << a << '-' << b << '+' << c << '+' << d << "=7\n";
	else if(a - b + c - d == 7) cout << a << '-' << b << '+' << c << '-' << d << "=7\n";
	else if(a - b - c + d == 7) cout << a << '-' << b << '-' << c << '+' << d << "=7\n";
	else if(a - b - c - d == 7) cout << a << '-' << b << '-' << c << '-' << d << "=7\n";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

int main()
{
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;

    int p[a], q[b], ary[x + y + c];

    repi(i, a, 0) cin >> p[i];
    repi(i, b, 0) cin >> q[i];
    repi(i, c, 0) cin >> ary[i];

    sort(p, p + a, greater<int>());
    sort(q, q + b, greater<int>());
    repi(i, x, 0) ary[c + i] = p[i];
    repi(i, y, 0) ary[c + x + i] = q[i];
    sort(ary, ary + x + y + c, greater<int>());

    // repi(i,x+y+c,0){
    //     cout << ary[i] << " ";
    // }
    cout << endl;
    ll sum = 0;
    repi(i, x + y, 0)
    {
        sum += ary[i];
    }
    cout << sum << endl;
    return 0;
}

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

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

    vector<int> w(n);
    for (int i = 0; i < n; i++){
        cin >> w.at(i);
    }

    int min = 1 << 27;
    
    for (int i = 0; i < n - 1; i++){
        int s1, s2;
        s1 = accumulate(w.begin(), next(w.begin(), i + 1), 0);
        s2 = accumulate(next(w.begin(), i + 1), w.end(), 0);

        if (abs(s1 - s2) < min){
            min = abs(s1 - s2);
        }
    }

    cout << min << endl;
}

Measured memory_bytes: 256
# C - Many Requirements
# DFSで解く

N, M, Q = map(int, input().split())
A = [0] * Q
B = [0] * Q
C = [0] * Q
D = [0] * Q
for i in range(Q):
    A[i], B[i], C[i], D[i] = map(int, input().split())

def dfs(L):
    global ans
    if len(L)==N+1:
        tmp = 0
        for i in range(Q):
            if L[B[i]] - L[A[i]] == C[i]:
                tmp += D[i]
        ans = max(tmp, ans)
        return
    else:
        for j in range(L[-1], M+1):
            dfs(L+[j])
    return ans

ans = 0
print(dfs([1]))

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

Measured memory_bytes: 3632
//タイトルから察するに、K以下の約数の個数をf(K)としているっぽい気がするなあ。
#include <iostream>
#define int long long
using namespace std;

int n;
int cnt[10000001];

signed main() {
	int i, j;
	
	cin >> n;
	for (i = 1; i <= n; i++) {
		for (j = i; j <= n; j += i) {
			cnt[j]++;
		}
	}
	
	int ans = 0;
	for (i = 1; i <= n; i++) ans += i * cnt[i];
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 81740
#include <iostream>
#include <string>

using namespace std;

int main()
{
  string s;
  cin >> s;
  if((s[1] == s[2]) &&(s[0] == s[1] || s[2] == s[3])) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
/*
[agc034] A - Kenken Race
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

int N, A, B, C, D;
string s;

bool solve() {
    for (int i = 0; i < N - 1; i++) {
        if (s[i] == '#' && s[i + 1] == '#' &&
            ((A < i && i < C) || (B < i && i < D))) {
            return false;
        }
    }

    if (C < D) {
        return true;
    }

    bool can_pass = false;
    int cnt = 0;
    for (int i = B - 1; i <= D + 1; i++) {
        if (s[i] == '.') {
            cnt++;
            if (cnt >= 3) {
                can_pass = true;
                break;
            }
        } else {
            cnt = 0;
        }
    }

    return can_pass;
}

int main() {
    cin >> N >> A >> B >> C >> D;
    A--;
    B--;
    C--;
    D--;
    cin >> s;

    cout << (solve() ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 640
import heapq
N = int(input())
A = list(map(int,input().split()))
L = []
R = []
for i in range(N):
  L.append(A[i])
for i in range(N):
  R.append(-A[3*N-i-1])
SUML = [0]*(N+1)
SUMR = [0]*(N+1)
S = sum(L)
T = sum(R)
SUML[0] = S
SUMR[0] = -T
heapq.heapify(L) #これ必要
heapq.heapify(R)
for i in range(N,2*N):
  a = heapq.heappushpop(L,A[i])
  S = S-a+A[i]
  SUML[i-N+1] = S
for j in range(N,2*N):
  b = heapq.heappushpop(R,-A[3*N-j-1])
  T = T-b-A[3*N-j-1]
  SUMR[j-N+1] = -T
ans = -float('inf')
for i in range(N+1):
  if SUML[i]-SUMR[N-i] >= ans:
    ans = SUML[i]-SUMR[N-i]
print(ans)

Measured memory_bytes: 39260
import java.util.Scanner;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        sc.useDelimiter("\n");
        String[] s = sc.next().split(" ");
        int a = Integer.parseInt(s[0]);
        int b = Integer.parseInt(s[1]);
        while (!(a == 0 && b == 0)) {
            if (a <= b) {
                System.out.println(a + " " + b);
            } else {
                System.out.println(b + " " + a);
            }
            s = sc.next().split(" ");
            a = Integer.parseInt(s[0]);
            b = Integer.parseInt(s[1]);
        }
    }
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vp;
const int inf = 1e9;
const ll INF = 1e18;
const db eps = 1e-10;

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define ep emplace
#define mem(a) memset(a, 0, sizeof(a))
#define copy(a, b) memcpy(a, b, sizeof(b))
#define PA cout << "pass\n"
#define lowbit(x) (x & -x)
#define all(x) x.begin(), x.end()
#define TM cout << db(clock()) / CLOCKS_PER_SEC << '\n'

mt19937 mrand(chrono::high_resolution_clock::now().time_since_epoch().count());

template <class A, class B>
string to_string(pair<A, B> p);

template <class A, class B, class C>
string to_string(tuple<A, B, C> p);

template <class A, class B, class C, class D>
string to_string(tuple<A, B, C, D> 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 <class 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 <class A, class B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <class A, class B, class C>
string to_string(tuple<A, B, C> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <class A, class B, class C, class D>
string to_string(tuple<A, B, C, D> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug(){cerr << endl;}
template<class T, class... U>
void debug(const T& h,const U&... t){
    cerr << to_string(h) << ' ';
    debug(t...);
}

int a, b, n;

int main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(10);
    cin >> a >> b >> n;
    cout << (n + max(a, b) - 1) / max(a, b) << '\n';
    return 0;
}

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

// Shrotening
#define fst first
#define snd second
#define pb push_back
#define mp std::make_pair

// Loop
#define FOR(i,a,b) for(auto i=(a);i<(b);++i)
#define RFOR(i,a,b) for(auto i=(a);i>=(b);--i)

#define REP(i,a) for(long i=0;i<(a);++i)
#define RREP(i,a) for(long i=(a);i>=0;--i)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) std::sort((a).begin(), (a).end())
#define UNIQUE(a) std::sort((a).begin(), a.end()), a.erase(std::unique((a).begin(), a.end()), a.end());
#define SUM(a) std::accumulate((a).begin(), (a).end(), 0);

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef std::pair<int,int> PII;

typedef std::vector<char> VC;
typedef std::vector<int>  VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;
typedef std::vector<PII> VPII;

typedef std::vector< VC > VC2;
typedef std::vector< VI > VI2;
typedef std::vector< VL > VL2;
typedef std::vector< VLL > VLL2;

int n, m;
VI a(1000);
int main() {
    while(std::cin >> n >> m) {
        if(n == 0 && m == 0) break;
        REP(i, n) {
            std::cin >> a[i];
        }

        int ans = 0, cnt = 0;;
        REP(i, n) REP(j, n) {
            if(i == j) continue;
            if(a[i] + a[j] <= m) {
                ans = std::max(ans, a[i] + a[j]);
                ++cnt;
            }
        }
        if(cnt == 0) {
            std::cout << "NONE" << std::endl;
        } else {
            std::cout << ans << std::endl;
        }
    }
}


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

#include <cstdlib>  // abs() for integer 絶対値求めやつ

#include <cmath>    // abs() for float, and fabs()

#include <algorithm>
#include <vector>
#define rep(i,n) for(int i = 0; i< (n);i++)

#define SORT(a) sort((a).begin(),(a).end());

#define che(a,string) cout<<string<<":"<<(a)<<endl;

#define ch(a,string) cout<<string<<":"<<(a)<<" ";

using namespace std;

typedef pair<int,int> P;

int main(){
	int a,b,x;
	cin>>a>>b>>x;
	if((a<=x)&&(a+b>x)){
		cout<<"YES"<<endl;
	  }
	  else{
		  cout<<"NO"<<endl;
		}
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
 using namespace std;
 int main() { 
   int n,l;
   cin>>n>>l;
   int d=300;
   int score;
   for(int i=0;i<n;i++){
     for(int j=i+1;j<n;j++){
       int a=l+i;
       int b=l+j;
       if(a<0){
         a=-a;
       }
       if(b<0){
         b=-b;
       }
       if(a>=b){
         if(b<=d){
           d=b;
           score=l+j;
         }
       }
       else{
         if(a<=d){
           d=a;
           score=l+i;
         }
       }
     }
   }
   int ans=0;
   for(int i=0;i<n;i++){
     ans+=l+i;
   }
   cout<<ans-score<<endl;
   
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
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; }

// 最大公約数(ユークリッドの互除法)
// O(log max(a, b))
ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a%b);
}

// 最小公倍数(最大公約数のライブラリ必須)
// O(log max(a, b))
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

int main(){
    int n;
    cin >> n;
    vector<ll> t(n);
    rep(i, n){
        cin >> t.at(i);
    }
    ll ans = t.at(0);
    rep(i, n){
        ans = lcm(ans, t.at(i));
    }
    cout << ans << endl;
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

vint dist;
int N;
vint G[100000];
void dfs(int v,int p,int d){
    dist[v]=d;
    for(auto u:G[v]){
        if(u!=p)dfs(u,v,d+1);
    }
}

signed main(){
    cin>>N;
    rep(i,N-1){
        int a,b;
        cin>>a>>b;
        a--;b--;
        G[a].pb(b);
        G[b].pb(a);
    }

    dist=vint(N);
    vint distx,disty;
    dfs(0,-1,0);
    int x=0;
    rep(i,N)if(dist[x]<dist[i])x=i;
    dfs(x,-1,0);
    distx=dist;
    int y=0;
    rep(i,N)if(dist[y]<dist[i])y=i;
    dfs(y,-1,0);
    disty=dist;

    rep(i,N){
        printf("%lld\n",(N-1)*2-max(distx[i],disty[i]));
    }
    return 0;
}

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

int main() {
	double a,b,h,m,min;
	long double aang,bang,delta,deltacos,ans;
	cin>>a>>b>>h>>m;
	min=60*h+m;
	aang=0.5*min;
	bang=6*m;
	if(aang>bang) delta=aang-bang;
	else delta=bang-aang;
	deltacos=cos(delta*M_PI/180);
	ans=a*a+b*b-2*a*b*deltacos;
	cout<<setprecision(20)<<sqrt(ans)<<endl;
	return 0;
}

Measured memory_bytes: 4152
#include<bits/stdc++.h>
#define cs const
#define pb push_back
using namespace std;
typedef long long ll;
cs int N = 1e3 + 50, M = 2e4;
int n, a[N], b[N]; bool isp[M];
ll mp[N][N]; int prm[M], pc;
void Sieve(){
	for(int i=2; i<M&&pc<n+n; i++){
		if(!isp[i]) prm[++pc]=i;
		for(int j=1; j<=pc; j++){
			if(prm[j]*i>=M) break;
			isp[prm[j]*i]=true; if(i%prm[j]==0) break;
		}
	}
}
ll gcd(ll x, ll y){ return !y ? x : gcd(y, x % y); }
ll lcm(ll x, ll y){
	if(!x||!y) return x+y; 
	return x / gcd(x,y) * y;
}
int main(){
	scanf("%d",&n); Sieve();
	if(n==2) return cout<<"4 7\n23 10",0;
	int l=1, r=pc; 
	for(int i=1; i<=n; i++)
	a[i]=(i&1)?prm[l++]:prm[r--];
	for(int i=1; i<=n; i++)
	b[i]=(i&1)?prm[l++]:prm[r--];
	for(int i=1; i<=n; i++)
	for(int j=1; j<=n; j++) if((i+j)&1^1){
		int x=(i+j)>>1, y=(j+(n-i+1))>>1;
		mp[i][j]=(ll)a[x]*b[y];
	} for(int i=1; i<=n; i++)
	for(int j=1; j<=n; j++) if((i+j)&1){
		ll x=lcm(mp[i][j-1],mp[i-1][j]);
		ll y=lcm(mp[i+1][j],mp[i][j+1]); 
		mp[i][j]=lcm(x,y)+1; 
	} 
	for(int i=1; i<=n; i++,puts(""))
	for(int j=1; j<=n; j++) cout<<mp[i][j]<<" ";
	return 0;
}

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

public class Main {

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

  public void run() {

    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      final int n = Integer.parseInt(br.readLine());
      String op;
      String[] words;
      Tree tree = new Tree();

      for(int i=0,k=0; i<n; i++,k=0){
        words = br.readLine().split(" ");
        op  = words[k++];
        if ( op.equals("insert") ) { 
          tree.insert(Integer.parseInt(words[k++]));
        }
        else {
          tree.dispRoundPath();
        }
      }

    }
    catch(IOException e) {
      System.out.println("IOException!");
    }
  }
}

class Tree {

  static final BTreeNode NIL = new BTreeNode(-1);
  BTreeNode root;
  StringBuilder buf;

  public Tree() {
    root = NIL;
    buf = new StringBuilder();
  }

  public void insert(int val) {
    BTreeNode y = NIL;
    BTreeNode x = root;
    BTreeNode z = new BTreeNode(val);

    while( !x.equals(NIL) ) {
      y = x;
      if( z.key < x.key )
        x = x.left;
      else
        x = x.right;
    }
    z.parent = y;

    if( y.equals(NIL) ){
      root = z;
    }
    else if( z.key < y.key )
      y.left = z;
    else
      y.right = z;
  } 
  void preParse(BTreeNode u) {
    if( !u.equals(NIL) ) {
      buf.append(" ").append(u.key);
      preParse(u.left);
      preParse(u.right);
    }
  }
  void inParse(BTreeNode u) {
    if( !u.equals(NIL) ) {
      inParse(u.left);
      buf.append(" ").append(u.key);
      inParse(u.right);
    }
  }

  void dispRoundPath() {

    inParse(root);
    buf.append("\n");
    preParse(root);
    buf.append("\n");

    System.out.print(buf);
    buf.setLength(0);
  }
}

class BTreeNode {
  int key;
  BTreeNode parent,left,right;

  public BTreeNode(int key) {
    this.key = key;
    this.parent =
    this.left =
    this.right = Tree.NIL;
  }

  @Override
  public boolean equals(Object o) {
    if(o == this) return true;
    if(o == null) return false;
    if(!(o instanceof BTreeNode)) return false;

    BTreeNode node = (BTreeNode)o;
    if(!(this.key == node.key)) return false;

    return true;
  }
}


Measured memory_bytes: 127024
n = int(input())
d, x = map(int, input().split())

ans = x
for _ in range(n):
    a = int(input())
    cnt = 1
    
    tmp = a + 1
    if tmp <= d: cnt += 1
      
    while True:
        tmp += a
        if tmp <= d: cnt += 1
        else: break
        
    ans += cnt

print(ans)

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

//define
#define ALL(a) a.begin(),a.end()
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define debug(x) if(1)cout<<#x<<":"<<x<<endl;
#define DEBUG(x) if(1)cout<<#x<<":"<<x<<endl;
#define ll long long

//constant
const int MOD = 1000000009;
const int INF = INT_MAX / 3;

//typedef
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

int main() {
	long long int w, h;
	cin >> w >> h;
	vector<long long int> p(w), q(h);
	REP(i, w)
		cin >> p[i];
	REP(i, h)
		cin >> q[i];
	sort(ALL(p));
	sort(ALL(q));
	long long int sum = 0;
	long long line = 0;
	int colum = 0;
	int row = 0;
	int iw = 0;
	int ih = 0;
	for (;iw!= w || ih!=h;) {
		
		if (iw != w && ih != h) {
			if (p[iw] < q[ih]) {
				sum += p[iw] * (h + 1 - row);
				iw++;
				colum++;
				line += h + 1 - row;

			}
			else {
				sum += q[ih] * (w + 1 - colum);
				row++;
				ih++;
				line += w + 1 - colum;

			}

		}
		else if (iw == w) {
			sum += q[ih];
			line += 1;
			ih++;


		}
		else {
			sum += p[iw];
			iw++;
			line += 1;

		}




	}
	cout << sum << endl;
	


}


Measured memory_bytes: 1792
n=int(input())
l=[0]*10000000
for i in range(1,100):
    for j in range(1,100):
        for k in range(1,100):
            k1=((i*i)+(j*j)+(k*k)+(i*j)+(j*k)+(i*k))
            l[k1]+=1
for i in range(1,n+1):
    print(l[i])

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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

const llong inf = 1100100100100100ll;
const llong mod = 1e9+7;

int main() {
	llong x, y;
	cin >> x >> y;

	cout << x + y/2 << endl;

	return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  if(a % 3 == 0 || b % 3 == 0 || (a + b) % 3 ==0){
    cout << "Possible" <<endl;
  }
  else{
    cout << "Impossible" <<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch ChristmasEveEve | diff ChristmasEveEve.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address ChristmasEveEve.cpp && ./a.out

/*
 
 2/3/2019
 
 10:31-10:35 AC
 
 */

const int MAX_N=1e6+1;
LL A[MAX_N];
int N;

void solve() {
  sort(A,A+N),reverse(A,A+N);
  LL res=accumulate(A,A+N,0LL);
  res-=A[0]/2;
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N;
  REP(i,N) cin>>A[i];
  solve();
  
  return 0;
}


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

using namespace std;
#define fordebug int hoge;cin>>hoge;
#define DEKAI 1000000007
#define INF (1<<28)
#define lp(i,n) for(int i=0;i<n;i++)
#define lps(i,j,n) for(int i=j;i<n;i++)
#define int long long

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;


NodePointer listSearch(int key){
  NodePointer x=nil->next;
  while(1){
  	if(x==nil) break;
  	if(x->key==key) break;
  	x=x->next;
  }
  return x;
}

void init(){
  nil = (NodePointer)malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
	if(t==nil) return;
	t->prev->next=t->next;
	t->next->prev=t->prev;
	free(t);
	return;
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
	deleteNode(nil->prev);
}

void delkey(int key){
  deleteNode(listSearch(key));
}


void insert(int key){
  NodePointer x;
  x = (NodePointer)malloc(sizeof(struct node));
  x->key = key;
  x->next=nil->next;
  nil->next->prev=x;
  nil->next=x;
  x->prev=nil;
}

signed main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  cin>>n;
  init();
  for ( i = 0; i < n; i++ ){
 	 //printList();	
    scanf("%s", com);
    if(strlen(com)<=6) scanf("%d",&key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
		if ( com[6] == 'F' ) deleteFirst();
		else if ( com[6] == 'L' ) deleteLast();
      } else {
		delkey(key); nd++; 
      }
      size--;
    }
  }

  printList();
  return 0;
}


Measured memory_bytes: 34464
import sys
import math
i=0
S=input()
n=int(len(S))
if S==S[::-1]:
    i=i+1
foreS=S[:int((n-1)/2)]
backS=S[int((n+1)/2):]
if foreS==foreS[::-1]:
    i=i+1
if backS==backS[::-1]:
    i=i+1
if i==3:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <iomanip>
#include <limits>
#include <cmath>
#include <numeric>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const long long INF = 1LL << 60;

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

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

int main() {
	string N;
	cin >> N;
	long long zero = 0, one = 0;
	for (long long  i = 0; i < N.length(); ++i) {
		if (N[i] == '0') {
			++zero;
		}
		else {
			++one;
		}
	}
	chmin(zero, one);
	cout << zero * 2 << endl;
}

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

int main(void){
    string S;
    cin >> S;
    int counter = 0; // 最後も0ならYes
    for(int i=1; i<=S.length(); i++){
        // 奇数文字目(S自体は0スタートなので注意)
        if(i%2==1){
            if(S[i-1] == 'L') counter += 1;
        }
        // 偶数文字目
        else{
            if(S[i-1] == 'R') counter += 1;
        }
    }

    if(counter == 0) cout << "Yes";
    else cout << "No";

    return 0;
}

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

using namespace std;

typedef vector<string> vs;

int main(void) {
    int H, W;
    cin >> H >> W;

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

    for (i=0; i<H; i++)
        if (i & 1) {
            cout << '#' << a[i].substr(1, W-1) << "\n";
        } else {
            cout << string(W-1, '#') << ".\n";
        }

    cout << endl;
    for (i=0; i<H; i++)
        if (i & 1) {
            cout << "." << string(W-1, '#') << endl;
        } else {
            cout << a[i].substr(0, W-1) << "#\n";
        }

    return 0;
}


Measured memory_bytes: 1152
a = input().split()
kind = int(a[0])
g = int(a[1])

lst=[]

for x in range (kind):
    b = int(input ())
    lst.append(b)
mini = 1000
sm = 0
for x in lst:
    sm = sm + x
    if x < mini:
        mini = x

left = g - sm
answer = left//mini
print (kind + answer)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N,L,i;
    string S[101];
    cin>>N>>L;
    for (i=0;i<N;i++)
        cin>>S[i];
    sort(S,S+N);
    for (i=0;i<N;i++)
        cout<<S[i];
    return 0;
}


Measured memory_bytes: 3660
import java.util.Scanner

object Main {

  def read(): (Int, IndexedSeq[Int]) = {
    val sc: Scanner = new Scanner(System.in)
    val n = sc.nextInt
    val arr = (1 to n).map { _ =>
      sc.nextInt
    }
    sc.close()
    (n, arr)
  }


  def solve(n: Int, arr: IndexedSeq[Int]): Double = {
    val sorted = arr.sorted
    sorted.foldLeft(sorted.head: Double) { (stock, item) =>
      (stock + item) / 2
    }
  }


  def main(args: Array[String]): Unit = {
    val (a, s) = read()
    println(solve(a, s))
  }

}


Measured memory_bytes: 27464
#include <bits/stdc++.h>
using namespace std;
struct edge {
  int x;
  int y;
  int weight;
  bool operator<(const edge& another) const {
    return weight < another.weight;
  }
  bool operator>(const edge& another) const {
    return weight > another.weight;
  }
};

vector<int> data(100010,-1);//n=データ数

int root(int x){
  if(data[x] == -1)return x;
  else return data[x] = root(data[x]);
}

bool same(int x,int y){
  if(root(x) == root(y))return 1;
  else return 0;
}

int unite(int x,int y){
  if(!same(x,y))data[root(x)] = y;
  return 0;
}

vector<edge> Kruskal(vector<edge> E){
  vector<edge> answer;
  priority_queue<edge,vector<edge>,greater<edge> > pque;
  for(int i = 0;i < data.size();i++)data[i] = -1;
  for(int i = 0;i < E.size();i++)pque.push(E[i]);
  while(pque.size()){
    if(!same(pque.top().x,pque.top().y)){
      answer.push_back(pque.top());
      unite(pque.top().x,pque.top().y);
    }
    pque.pop();
  }
  return answer;
}

int main() {
  int v,e,s,t,w,ans=0;
  cin >> v >> e;
  vector<edge> edges;
  for(int i = 0;i < e;i++){
    edge E;
    cin >> E.x >> E.y >> E.weight;
    edges.push_back(E);
  }
  edges = Kruskal(edges);
  for(int i = 0;i < edges.size();i++)ans+=edges[i].weight;
  cout << ans <<endl;
}


Measured memory_bytes: 7916
import sys

inf_val = 10**10

m, n = map(int, sys.stdin.readline().split())
numbers = map(int, sys.stdin.readline().split())

dp = [inf_val]*(m+1)
dp[0] = 0

for x in numbers:
    for y in xrange(x, m+1):
        dp[y] =  min(dp[y-x]+1, dp[y])

print dp[m]

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

const int MAX = 1e5 + 5;

#define dbg(a) cout << "-> " << __LINE__ << ": " << #a << " = " << a << endl

int solve (int x) {
	int ret = 0;
	for (int i = 1; i <= x; i++) {
		if (i > x) {
			return ret;
		}
		x -= i;
		++ret;
	}
	return ret;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	long long n;
	cin >> n;
	int lim = int(sqrt(n + 1)), ans = 0;
	for (int i = 2; i <= lim and i <= n; i++) {
		int cnt = 0;
		while (n % i == 0) {
			n /= i;
			++cnt;
		}
		ans += solve(cnt);
	}
	if (n != 1) {
		++ans;
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<ll, ll, ll> T;

int N;
map<int, int> mp;
void Factoring(int n){
    
	int a = 2;
    while (n >= a * a) {
        if (n % a == 0) {
            ++mp[a];
            n /= a;
        } else {
            a++;
        }
    }
    ++mp[n];
    
	return;
}

int main(void){
    
    scanf("%d", &N);
    
    for(int i = 2; i <= N; ++i) Factoring(i);
    
    ll ans = 1;
    for(int i = 0; i < mp.size(); ++i) ans *= mp[i] + 1, ans %= MOD;
    printf("%lld\n", ans);
    
    return 0;
}

Measured memory_bytes: 256
N = int(input())
H = [int(i) for i in input().split()]
"""
def dfs(cur, cost):
    if cur == N - 1: return cost
    elif cur < N - 2:
        return min(dfs(cur + 1, cost + abs(H[cur] - H[cur + 1])), dfs(cur + 2, cost + abs(H[cur] - H[cur + 2])))
    else:
        return dfs(cur + 1, cost + abs(H[cur] - H[cur + 1]))
print(dfs(0, 0))
"""

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

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

    }
    else if(b<a && a>c)
    {
        if(b<c)
            printf("%d %d %d\n",b,c,a);
        else
            printf("%d %d %d\n",c,b,a);

    }
    else if(c<a && a>b)
    {
        if(c<b)
            printf("%d %d %d\n",c,b,a);
            else
            printf("%d %d %d\n",b,c,a);
    }

    return 0;
}



Measured memory_bytes: 2056
/**
 *  author: chaitanya
 *  created: 05:38:10 PM, 13 September 2020
 **/
#include <bits/stdc++.h>
using namespace std;

#define intll 1
#define interactive 0

#ifdef chaitanya
#include "/home/chaitanya/.templates/header.h"
#else
#define debug(x...)
#endif

#if !interactive
#define IOS                         \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0);                      \
  cin.exceptions(cin.failbit);
#define endl "\n"
#else
#define IOS
#endif

#if intll
#define int long long int
#endif

#define ll long long
#define sz(a) (int)((a).size())
#define all(a) a.begin(), a.end()
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define F first
#define S second

const int N = 300009;
const int mod = 1000000007;

void pre() {}

int32_t main() {
  IOS;
  int s;
  cin >> s;
  vi dp(2001, 0);
  dp[0] = 1;
  for (int i = 1; i < 2001; i++) {
    for (int j = 3; j <= i; j++) {
      dp[i] += dp[i - j];
      dp[i] %= mod;
    }
  }
  // debug(dp);


  cout << dp[s] << endl;

  return 0;
}

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

#define ll long long
#define ull unsigned long long

using namespace std;

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

	std::vector<int> v(32, 0);
	v[0] = 1;
	v[1] = 1;
	v[2] = 1;
	v[3] = 2;
	v[4] = 1;
	v[5] = 2;
	v[6] = 1;
	v[7] = 5;
	v[8] = 2;
	v[9] = 2;
	v[10] = 1;
	v[11] = 5;
	v[12] = 1;
	v[13] = 2;
	v[14] = 1;
	v[15] = 14;
	v[16] = 1;
	v[17] = 5;
	v[18] = 1;
	v[19] = 5;
	v[20] = 2;
	v[21] = 2;
	v[22] = 1;
	v[23] = 15;
	v[24] = 2;
	v[25] = 2;
	v[26] = 5;
	v[27] = 4;
	v[28] = 1;
	v[29] = 4;
	v[30] = 1;
	v[31] = 51;

	cout << v[K-1] << endl;


	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define D(x) cout<<"D:"<<#x<<'='<<x<<endl;
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
template<typename tn> inline tn next(void)
{
	tn k;
	cin>>k;
	return k;
}
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v)
{
	for(int i = 0; (unsigned)i < v.size(); i++) os<<v[i]<<' ';
	return os;
}
int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n, a, b;
	cin>>n>>a>>b;
	ll g = n/(a+b);
	cout<<g*a+min(a, n-g*(a+b))<<endl;
	return ~~(0-0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using intpair=pair<int,int>;
using llpair=pair<ll,ll>;
using llvec=vector<ll>;
using llmat=vector<vector<ll>>;
#define PI 3.141592653589793
#define llmattp(name,a,b,num) name(a,vector<ll>(b,num))
#define INTINF 1<<30
#define LLINF 1LL<<60
#define ABS(x) ( (x)>0 ? (x) : -(x) )

template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

ll gcd(ll a, ll b) { //最大公約数
	if(a==0||b==0) return 0;
	if(a<b) swap(a,b);
	ll tmp = a%b;
	while(tmp!=0) {
		a = b;
		b = tmp;
		tmp = a%b;
	}
	return b;
}

ll factorial(ll x) { //階乗
	ll f=1;
	for(ll i=2; i<x; i++) {
		f*=i;
	}
	return f;
}

ll nPr(ll n, ll r) {
	ll result=1;
	for(ll i=r+1; i<=n; i++) result*=i;
	return result;
}

ll nCr(ll n, ll r) {
	if (n == r) { return 1; }
	if (r > n) { return 0; }

	if (r > n / 2) { r = n - r; }

	if (n == 0) { return 0; }
	if (r == 0) { return 1; }
	if (r == 1) { return n; }

	double result = 1;
	for (double i = 1; i <= r; i++) {
		result *= (n - i + 1) / i;
	}

	return (ll)result;
}

bool IsPrime(ll num) { //素数判定
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

	double sqrtNum = sqrt(num);
	for (ll i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}

ll GreaterBinarySearch(ll *array, ll key, ll max, ll min) {
	if(array[max]<array[min]) {
		return NULL;
	} else {
		ll mid = max + (min-max)/2;
		if(array[mid]<key) {
			return GreaterBinarySearch(array,key,max,mid-1);
		} if(array[mid]>key) {
			return GreaterBinarySearch(array,key,mid+1,min);
		} else {
			return mid;
		}
	}
}

int DigitNum(ll n) { //桁数
	int digit=0;
	ll wari=1LL;
	while(n/wari) {
		digit++;
		wari*=10;
	}
	return digit;
}

void PrimeFact(ll x) { // 素因数分解 出力部を適切に書き換え
	int i=2;
	while(x%2&&i*i<=x) {
		cout<<2<<endl;
		x/=2;
	}
	i++;
	while(i*i<=x) {
		if(x%i) {
			i+=2;
			continue;
		}
		cout<<i<<endl;
		x/=i;
	}
}

bool Palind(string s) { //回文判定
	return s == string(s.rbegin(), s.rend());
}

int main() {
	int X,Y,A,B,C; cin>>X>>Y>>A>>B>>C;
	intpair apple[A+B+C];
	for(int i=0; i<A; i++) {
		cin>>apple[i].first;
		apple[i].second=2;
	}
	for(int i=0; i<B; i++) {
		cin>>apple[i+A].first;
		apple[i+A].second=1;
	}
	for(int i=0; i<C; i++) {
		cin>>apple[i+A+B].first;
		apple[i+A+B].second=0;
	}
	sort(apple,apple+A+B+C,greater<intpair>());

	int limit[2]={Y,X};
	int ate[2]; for(int i=0; i<2; i++) ate[i]=0; // 0;B 1;A
	int allate=0;
	ll score=0LL;
	for(int i=0; ; i++) {
		if(apple[i].second>0) {
			int num=apple[i].second-1;
			if(ate[num]==limit[num]) continue;
			score+=apple[i].first;
			allate++;
			ate[num]++;
			if(allate==X+Y) break;
		}
		else {
			score+=apple[i].first;
			allate++;
			if(allate==X+Y) break;
		}
	}

	cout<<score<<endl;
}


Measured memory_bytes: 2688
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	//min(a,b)...a,bの小さいほう
	//max(a,b)...     大きいほう
	//int a;
	//int b;
	//int c;
	//int d;
	int e;
	//int num;
	string s;
	string o;
	string p;
	cin >> s;
	cin >> o;
	cin >> p;
	//std::cin >> a >> b >> c;
	cout << s[0] << o[1] << p[2] << "\n";
	std::cin >> e;
}

Measured memory_bytes: 256
H,W,K = map(int,input().split())
c = [list( input()) for _ in range(H)]

ans = 0
for maskR in range(1 << H):
  for maskC in range(1 << W):
    blk = 0
    
    for i in range(H):
      for j in range(W):
        if ((maskR >> i) & 1) == 0 and ((maskC >> j) & 1) == 0 and c[i][j] == '#':
          blk += 1
    if blk == K:
      ans += 1
    
print(ans)

Measured memory_bytes: 9208
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

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

	rep(i,q){
		int a, b;
		cin >> a >> b;
		a-=2; b-=2;

		if(n == 1){
			cout << min(a,b) + 2 << endl;
			continue;
		}

		while(a != b){
			if(a > b){
				a = a / n - 1;
			}else{
				b = b / n - 1;
			}
		}
		cout << a + 2 << endl;
	}
}


Measured memory_bytes: 1280
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int[] results = {a + b, a * b, a - b};
        Arrays.sort(results);
        System.out.println(results[2]);
    }
}


Measured memory_bytes: 22612
#include <iostream>
#include <vector>
#include <cmath>
#include <climits>
#include <algorithm>
#include <utility>
#include <list>
#include <tuple>
#include <map>
#include <stack>
#include <queue>
#include <string>

using std::cout;
using std::cin;
using std::cerr;
using std::endl;
using std::vector;

int evaluation(const vector<int>& c, const vector<vector<int>>& s, const vector<int>& last, int day, int t) {
    int result = s[day - 1][t - 1];
    for (int i = 0, size = c.size(); i < size; i++) {
        result -= c[i] * (day - last[i]);
    }
    return result;
}

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

    vector<int> c(26);
    vector<vector<int>> s(d, vector<int>(26));
    vector<int> t(d);
    vector<int> last(26, 0);

    for (auto&& v : c) {
        cin >> v;
    }
    for (auto&& vec : s) {
        for (auto&& v : vec) {
            cin >> v;
        }
    }
    for (auto&& v : t) {
        cin >> v;
    }

    int score = 0;
    for (int i = 0; i < d; i++) {
        last[t[i] - 1] = i + 1;
        score += evaluation(c, s, last, i + 1, t[i]);
        cout << score << endl;
    }
    return 0;
}

Measured memory_bytes: 3660
#include<stdio.h>
 
main(){
  int S[10000],T[500],n,q,i,j,count=0;
   
  scanf("%d",&n);
  for(i=0 ; i<n ; i++) scanf("%d",&S[i]);
   
  scanf("%d",&q);
  for(j=0 ; j<q ; j++){
    scanf("%d",&T[j]);
    for(i=0 ; i<n ; i++){   
      if(T[j] == S[i]){
    count++;
    break;
      }
    }
  }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 636
n,m=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(n)]
c=[list(map(int,input().split())) for _ in range(m)]
#print(a,c)

for i in range(n):
    k=0
    ans=1
    num=10**9
    for j in range(m):
        k=abs(a[i][0]-c[j][0])+abs(a[i][1]-c[j][1])
        #print(abs(a[i][0]-c[j][0]),abs(a[i][1]-c[j][1]),k)
    
        if num>k:
            num=k
            ans=j+1
            #print(ans,num)
    else:
        print(ans)
        

#print(ans,num)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

  int n;
  cin >> n;

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

  vector<bool> table(1000000001, false);

  int ans = 0;
  for (int i = 0; i < n; i++) {
    int num = a[i];

    if (!table[num]) {
      ++ans;
      table[num] = true;
    } else {
      --ans;
      table[num] = false;
    }
  }

  cout << ans << endl;

  return 0;
}

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

int solve(int n)
{
	int ret = 0;

	while (n != 1)
	{
		if (n % 2 == 0)
		{
			n /= 2;
		}
		else if (n % 2 == 1)
		{
			n = n * 3 + 1;
		}
		ret++;
	}

	return ret;
}

signed main()
{
	int n;

	while (true)
	{
		cin >> n;
		if (n == 0) break;
		printf("%d\n", solve(n));
	}
}

Measured memory_bytes: 1144
import java.util.Scanner;

class Main {
  public static void main(String args[]) {
        Scanner scanner1 = new Scanner(System.in);
       
        int N = scanner1.nextInt();
        int M = scanner1.nextInt();
        int C = scanner1.nextInt();
        
        int B[] = new int[M];
        int A[][] = new int[N][M];
        
        for(int i = 0;i < M;i++){
        	B[i] = scanner1.nextInt();
        }
        for(int i = 0;i < N;i++){
        	for(int j = 0;j < M;j++){
        		A[i][j] = scanner1.nextInt();
        	}
        }
        
        int count = 0;
        int sum = 0;
        for(int i = 0;i < N;i++){
        	sum = 0;
        	for(int j = 0;j < M;j++){
        		sum = sum + A[i][j]*B[j];
        	}
        	sum = sum+C;
        	if(sum > 0){
        		count++;
        	}
        }
        System.out.println(count);
  }
}

Measured memory_bytes: 23892