akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <vector>
#include <algorithm>
#define ll long long
const int M=1e9+7;
#define test int t; cin>>t; while(t--)
#define f for(int i=0;i<n;i++)
#define f1 for(int i=1;i<n-1;i++)
#define read(x) ll x; cin>>x;
#define TIME  cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";

using namespace std;
/*ll gcd(ll a , ll b){return b==0?a:gcd(b,a%b);}
int combi(int n, int k)
{
    int C[k+1];
    memset(C, 0, sizeof(C));

    C[0] = 1;

    for (int i = 1; i <= n; i++)
    {
        for (int j = min(i, k); j > 0; j--)
            C[j] = C[j] + C[j-1];
    }
    return C[k];
}
int factorial(int n)
{
    return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
}
ll power(ll x,ll n)
{
    if(n==0) return 1;
    if(n&1) return x*power(x,n/2)*power(x,n/2);
    else
        return power(x,n/2)*power(x,n/2);
}*/

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

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

ll mod(ll x)
{
    return ((x%M + M)%M);
}
ll add_mod(ll a,ll b)
{
    return mod(mod(a) + mod(b));
}
ll mul_mod(ll a,ll b)
{
    return mod(mod(a) * mod(b));
}  //modular

/*void transpose(vector<vector<ll> >& arr,ll x) {
     for (ll j = 0; j <= x; j++) // transpose
               {
                   for (ll c = j; c <= x; c++)
                   {
                       swap(arr[j][c],arr[c][j]);
                   }
               }

}*/  //transpose

int main(){

  // ios_base::sync_with_stdio(false);
    //cin.tie(nullptr);
    int n; cin>>n;
    vector<pair<int,int> > v;
    for(int i=0;i<n;i++)
    {
        int x,y; cin>>x>>y;
        v.push_back(make_pair(x,y));
    }
    int k=0;
    for(int i=0;i<n;i++)
    {
        if(v[i].first==v[i].second) {
            k++;
        }
         if(v[i].first!=v[i].second) {
            k = 0;
        }
        if(k>3 || k==3) {
            break;
        }
    }
    if(k>3 || k==3) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    TIME
}

Measured memory_bytes: 3820
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
bool three(vector<int>V,int n){
    if(n==4)return true;
    bool f=false;
    for(int i=0;i<9;i++){
        if(V[i]>=3){
            V[i]-=3;
            f|=three(V,n+1);
            V[i]+=3;
        }
    }
    for(int i=0;i<7;i++){
        if(V[i]&&V[i+1]&&V[i+2]){
            V[i]--;V[i+1]--;V[i+2]--;
            f|=three(V,n+1);
            V[i]++;V[i+1]++;V[i+2]++;
        }
    }
    return f;


}
bool two(vector<int>V){
    bool f=false;
    for(int i=0;i<9;i++)if(V[i]>=5)return false;
    for(int i=0;i<9;i++){
        if(V[i]>=2){
            V[i]-=2;
            f|=three(V,0);
            V[i]+=2;

        }
    }
    return f;
}
int main(){
    string str;
    while(cin>>str){
        vector<int>V(9);
        bool Flag=false;
        for(int i=0;i<13;i++){
            V[str[i]-'0'-1]++;
        }
        for(int i=0;i<9;i++){
            V[i]++;
            if(two(V)){
                if(Flag)cout<<" ";
                cout<<i+1;
                Flag=true;
            }
            V[i]--;
        }
        if(!Flag)cout<<0;
        cout<<endl;
    }
}

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

template<typename T1, typename T2> void cmax(T1 &a, T2 b) { if (a < b) a = b; }
template<typename T1, typename T2> void cmin(T1 &a, T2 b) { if (a > b) a = b; }

signed main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  long N;
  cin >> N;
  vector<long> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);

  long ans = 0, mx = LONG_MIN;
  for (auto a : A) {
    if (a < mx) ans += mx - a;
    cmax(mx, a);
  }
  cout << ans << "\n";
}

Measured memory_bytes: 4736
use proconio::input;

fn f(h: i64, w: i64) -> i64 {
    let mut res = 1_000_000_000_000;

    // a|b|c
    // a|b|c
    // a|b|c
    for i in 1..w - 1 {
        let j = (w - i) / 2;
        let s_a = i * h;
        let s_b = j * h;
        let s_c = h * w - s_a - s_b;
        let s_max = std::cmp::max(s_a, std::cmp::max(s_b, s_c));
        let s_min = std::cmp::min(s_a, std::cmp::min(s_b, s_c));
        res = std::cmp::min(res, s_max - s_min);
    }

    // a|bb
    // a+--
    // a|cc
    for i in 1..w {
        let j = h / 2;
        let s_a = i * h;
        let s_b = j * (w - i);
        let s_c = h * w - s_a - s_b;
        let s_max = std::cmp::max(s_a, std::cmp::max(s_b, s_c));
        let s_min = std::cmp::min(s_a, std::cmp::min(s_b, s_c));
        res = std::cmp::min(res, s_max - s_min);
    }

    res
}

fn main() {
    input! {
        h: i64,
        w: i64
    };
    let ans = std::cmp::min(f(h, w), f(w, h));
    println!("{}", ans);
}


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


int main(){
	int N; cin >> N;
	LL m = 10000000010, M = 0;
	for(int i = 0; i < N; ++i) {
		LL tmp; cin >> tmp;
		m = min(m, tmp);
		M = max(M, tmp);
	}
	cout << M - m << endl;
}










Measured memory_bytes: 3636
#include<iostream>
#include<set>

using namespace std;


int main()
{
    int n, ans, a;
    while(cin >> ans >> n) {
        while(n--) {
            cin >> a;
            ans -= a;
        }
        if(ans < 0)
            cout << "-1" << endl;
        else
            cout << ans << endl;
    }
    return 0;
}


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

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

  cout << s[0] << s.size() - 2 << s[s.size() - 1] << endl;
  return 0;
}

Measured memory_bytes: 3600
#include <stdio.h>

int main(void){
    int a,b,c,k=0;

    scanf("%i %i %i",&a,&b,&c);
    
    if(a!=b && b!=c && c!=a) {
        k=3;
    }else if((a!=b)||(b!=c)||(c!=a)){
        k=2;
    }else {
        k=1;
    }

    printf("%i", k);

}

Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
const int maxn=1e5+5;
int h[maxn],minn[maxn];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&h[i]);
    memset(minn,0x3f,sizeof(minn));
    minn[1]=0;
    for(int i=1;i<=n;i++)
    {
        minn[i+1]=min(minn[i+1],minn[i]+abs(h[i]-h[i+1]));
        minn[i+2]=min(minn[i+2],minn[i]+abs(h[i]-h[i+2]));
    }
    printf("%d\n",minn[n]);
    return 0;
}


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

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

    vector<double> x(N);
    vector<string> u(N);
    for( int i = 0; i < N; ++i )
        cin >> x[i] >> u[i];

    double ans = 0.0;
    for( int i = 0; i < N; ++i ){
        if( u[i] == "JPY" ) ans += x[i];
        else ans += 380000.0 * x[i];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int N = Integer.parseInt(sc.next());
        
        int n = N;
        int sum = 0;
        while(n > 0){
            sum += n % 10;
            n /= 10;
        }
        
        if(N % sum == 0){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23764
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <bitset>

using namespace std;
#define bitmax 1000
/*
	不明なスイッチ
	ICPC(国際ソケット・コネクタ会社)本社ビルの中には、M個の電球があり、
	それらはN個のスイッチによって制御されている。各電球はただ一つのスイッチによって
	点灯させたり消滅させたりできる。各スイッチは複数の電球を操作できることもある。
	あるスイッチを操作するとき、そのスイッチによって制御されている全ての電球の状態が変化する。
	あなたはスイッチと電球の対応を記録してある表をなくしてしまい、それを復元したいと思っていた。

	以下の手順によって電球とスイッチの対応関係を復元することに決めた。

	・最初に全てのスイッチがオフになっており、全ての電球が消灯している
	・S1によってあらわされるいくつかのスイッチを操作する
	・B1によってあらわされる電球の状態を確認する
	・S2によってあらわされるいくつかのスイッチを操作する
	・B2によってあらわされる電球の状態を確認する
	・...
	・SQによってあらわされるいくつかのスイッチを操作する
	・BQによってあらわされる電球の状態を確認する

	いくつかのスイッチを操作して電球の状態を確認したあとは、
	スイッチと電球の状態は次の操作までそのままにしておく。

	操作を行ったスイッチと確認を行った電球に関する情報を用いて、
	スイッチと電球の対応関係を復元することができるだろうか？

	入力
	入力は複数のデータセットからなる。データセットの個数は50以下であり、
	ファイルサイズは10MB以下である。各データセットは以下の形式に従う。

	各データセットの一行目には3個の整数N,M,Qが含まれ
	( 1 <= N <= 36 ), ( 1 <= M <= 1000 ), ( 0 <= Q <= 1000 )
	、それぞれスイッチの個数、
	電球の個数、操作の回数を表す。それ以降のQ行は操作を行ったスイッチと
	状態の確認を行った電球に関する情報をあらわす。そのi番目には
	二つのデータS_iとB_iが含まれ、長さはそれぞれNとMである。
	各S_iは操作を行ったスイッチの集まりを表す。S_ijは0または1のいずれかであり、
	それぞれj番目のスイッチが操作されなかったこと、操作されたことを示す。
	各B_iは電球の状態を示す。B_ijは0または1のいずれかであり、それぞれj番目の電球が
	消灯しているか点灯しているかを表す。

	与えられる情報には、スイッチと電球の対応関係に矛盾が無いことを仮定してよい。

	入力の終わりは3つの0によってあらわされる。

	出力
	各データセットについて、スイッチと電球の対応関係を、
	M個の数字からなるbase-36形式で出力せよ。この問題におけるbase-36形式において、
	0-9と10-35の値はそれぞれ'0'-'9','A'-'Z'の文字によって表現される。
	対応関係におけるi番目の文字は、i番目の電球を制御しているスイッチの番号を示す。
	i番目の電球を制御しているスイッチを決定できない場合には、スイッチの番号の代わりに
	'?'をi番目の文字として出力せよ。

*/

/*
	方針
	ビット演算を用いる
	各電球について、つながっている可能性のあるスイッチに対応するビットを立てる
	スイッチの状態を変えても電球の状態に変化がない場合に可能性が消える
	→　ある状態とその次の状態の排他的論理和を取る

*/
string revstr( string s ) {
	string ret;
	for(int i = s.length() - 1; i >= 0; i--) {
		ret += s[i];
	}
	return ret;
}

int main(void){
	//FILE* fp_in = freopen("data.txt", "r", stdin);

	vector< char > ans;
	for(int i = 0; i < 10; i++)
		ans.push_back( '0' + i );
	for(int i = 0; i < 26; i++)
		ans.push_back( 'A' + i );

	while(1) {
		int N, M, Q;
		vector< bitset< bitmax > > S;
		vector< bitset< bitmax > > B;
		vector< bitset< bitmax > > P;

		cin >> N >> M >> Q;
		if( N == 0 && M == 0 && Q == 0 ) break;

		for(int i = 0; i < M; i++) {
			bitset< bitmax > P_i;
			P_i.reset();
			for(int j = 0; j < N; j++)
				P_i.set(j);
			P.push_back( P_i );
		}

		//データ取得
		for(int i = 0; i < Q; i++) {
			string S_i, B_i;
			cin >> S_i >> B_i;
			bitset< bitmax > Si( S_i );
			bitset< bitmax > Bi( B_i );
			S.push_back( Si );
			B.push_back( Bi );
			if( i > 0 ) S[i] ^= S[i-1]; 	//現在点灯しているスイッチ
			for(int j = 0; j < M; j++) {
				if( B[i][j] ) {	//電球が点灯した場合
					P[j] &= S[i];
				} else {
					P[j] &= ~S[i];
				}
			}
		}

		string str;
		for(int i = 0; i < P.size(); i++) {
			if( P[i].count() == 1 ) {
				for(int j = 0; j < N; j++) {
					if( P[i][j] ) str += ans[N - 1 - j];
				}
			} else {
				str += '?';
			}
		}
		cout << revstr(str) << endl;
		
	}

    return 0;
}

Measured memory_bytes: 1620
input = require("fs").readFileSync("/dev/stdin", "utf8");
ans = 0;
input = input.split("");
ACGT = ['A','C','G','T'];
kar = 0;
for(i = 0; i < input.length; i++){
    t = true;
    for(j = 0; j < 4; j++){
        if(input[i] === ACGT[j]){
            kar++;
            t = false;
            break;
        }
    }
    if(t){
        ans = Math.max(kar,ans);
        kar = 0;
    }
}
console.log(ans);

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

int Max(int &a,int b){return a=max(a,b);}

int LCS(string &a,string &b){
  int n = a.size();
  int m = b.size();
  vector <vector<int> > dp(n+1,vector<int>(m+1));

  for(int i=0;i<=n;i++)
    for(int j=0;j<=m;j++){
      if(i<n && j<m && a[i] == b[j]) Max(dp[i+1][j+1],dp[i][j]+1);
      if(i<n)Max(dp[i+1][j],dp[i][j]);
      if(j<m)Max(dp[i][j+1],dp[i][j]);

    }
  return dp[n][m];
}

int main(){
  int q;
  cin>>q;
  while(q--){
    string a,b;
    cin>>a>>b;
    cout<<LCS(a,b)<<endl;
  }
  return 0;
}

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

int main(){

	std::string str;
	while (std::cin >> str){
		if (str == "-")break;

		int m;
		std::cin >> m;

		for (int i = 0; i < m; i++){
			int h;
			std::cin >> h;
			std::string str2;
			str2 = str.substr(0, h);
			str.erase(0, h);
			str += str2;
		}

		std::cout << str << std::endl;
	}
	return 0;
}

Measured memory_bytes: 1232
# Wrote in Mar 4, 2020 18:28 by reetok
require 'time'
def inp(type=:to_i,spst=" ")
  return eval("gets.chomp.split(#{spst}).map(&:#{type})")
end
def inpf() return self.inp(:to_f," ") end
def inps() return self.inp(:to_s," ") end
def r_up(a, b) (a/b).ceil end
def r_down(a, b) (a/b).floor end
def sum(a) a.inject(:+) end
def big(a,b) return (a>b)? a:b end
def small(a,b) return (a<b)? a:b end
def minp(n,datatype=:to_i)
  t = []
  n.times do
    t.push(eval("gets.chomp.#{datatype.to_s}"))
  end
end
def yes() puts "Yes" end
def no() puts "No" end
def ynju(bool,yes="Yes",no="No") puts (bool ? yes : no) end
class Integer
  def divisor_list
    devisors = [1]
    2.upto(self/2) do |i|
      devisors << i if self%i == 0
    end
    devisors << self
    return devisors.uniq.sort
  end
end
class Array
  def upper(a) #aより上
    self.sort.select{|n|n>=a}
  end
  def downer(a) #aより下
    self.sort.select{|n|n<=a}
  end
end
#---------------



a,b,c = inp

puts c.divisor_list.upper(a).downer(b).size


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

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

		int n = Integer.parseInt(br.readLine());
		int debt = 100000;
		int add_debt =0; //additional debt
		double rate = 0.00005;

		while( n > 0 ){
		    add_debt = (int)Math.ceil(debt * rate);
		    debt += add_debt*1000;
		    n--;
		}
		System.out.println(debt);
	}
}

Measured memory_bytes: 9252
from bisect import *
from collections import *
from itertools import *
import functools
import sys
import math
from decimal import *
from copy import *
from heapq import *
from fractions import *
getcontext().prec = 30
MAX = sys.maxsize
MAXN = 1000010
MOD = 10**9+7
spf = [i for i in range(MAXN)]
spf[0]=spf[1] = -1
def sieve():
    for i in range(2,MAXN,2):
        spf[i] = 2
    for i in range(3,int(MAXN**0.5)+1):
        if spf[i]==i:
            for j in range(i*i,MAXN,i):
                if spf[j]==j:
                    spf[j]=i
def fib(n,m):
    if n == 0:
        return [0, 1]
    else:
        a, b = fib(n // 2)
        c = ((a%m) * ((b%m) * 2 - (a%m)))%m
        d = ((a%m) * (a%m))%m + ((b)%m * (b)%m)%m
        if n % 2 == 0:
            return [c, d]
        else:
            return [d, c + d]
 
def charIN(x= ' '):
    return(sys.stdin.readline().strip().split(x))
 
def arrIN(x = ' '):
    return list(map(int,sys.stdin.readline().strip().split(x)))
 
def ncr(n,r):
    num=den=1
    for i in range(r):
        num = (num*(n-i))%MOD
        den = (den*(i+1))%MOD
 
    return (num*(pow(den,MOD-2,MOD)))%MOD
 
def flush():
    return sys.stdout.flush()




'''*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*'''
n = int(input())
a = arrIN()

pre = list(accumulate(a))

ans = 0
for i in range(n-1):
    ans+=(a[i]*(pre[n-1]-pre[i]))
    ans%=MOD
print(ans)

Measured memory_bytes: 156000
#include <iostream>

using namespace std;

int main(){
    int n;
    int mod = 1000000007;
    long long a=0, b=0 , tmp;

    cin >> n;
    for(int i=0; i<n; i++){
        cin >> tmp;
        tmp %= mod;
        a += tmp;
        b += tmp*tmp;
        b %= mod;
        a %= mod;
    }
    

    a = a*a%mod;
    a -= b;
    if(a < 0){
        a += mod;
    }
    a *= (mod + 1)/2;
    cout << a%mod << endl;
}


Measured memory_bytes: 3576
#pragma region RegionDefs
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,l,r) for(int i=(l),i##_len=(r);i<i##_len;++i)
#define all(x) begin(x),end(x)
using namespace std;
const int INF = 1e9;
template<class T=int> using V = vector<T>;
template<class T=int> using PQ = priority_queue<T>;
template<class T=int> using PQG = priority_queue<T, V<T>, greater<T>>;
typedef long long ll;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail)
{
    cin >> head;
    in(move(tail)...);
}
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define INS(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
template<class T>bool chmax(T &a, const T &b) {if (a<b) {a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if (a>b) {a=b; return 1;} return 0;}
#define y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#define YN(e) cout << ((e) ? "YES" : "NO") << endl
#define yn(e) cout << ((e) ? "Yes" : "No") << endl
#pragma endregion RegionDefs

void solve()
{
    string s, t; cin >> s >> t;
    rep(i, s.size())
        if (s[i] != t[i])
        {
            cout << "No" << endl;
            return;
        }
    cout << "Yes" << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> T gcd(T a, T b){return !b?a:gcd(b,a%b);}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 666666;
int n,x[N],l[N],f[N],val[N],g[N];Pii a[N];
int main() {
	read(n);
	rep(i,1,n){
		read(x[i]);read(l[i]);a[i]=Pii(x[i]+l[i],l[i]);
	//	read(x[i]);read(l[i]);val[i]=x[i]+l[i];
	}
	sort(a+1,a+n+1);
	rep(i,1,n)x[i]=a[i].fi-a[i].se,l[i]=a[i].se,val[i]=x[i]+l[i];
	rep(i,1,n){
		f[i]=1+g[upper_bound(val+1,val+n+1,x[i]-l[i])-val-1];
		g[i]=max(g[i-1],f[i]);
	}
	cout<<g[n];
	return 0;
}


Measured memory_bytes: 13312
N, K = map(int, input().split())

ans = 0
i = 1
cnt = 0
c = N
while c != 0:
    if c * i >= K:
        ans += 1 / ((2 ** cnt) * N)
        c -= 1
    else:
        i *= 2
        cnt += 1

print(ans)

Measured memory_bytes: 3060
#include<map>
#include<cstdio>

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

using namespace std;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
struct P{ int x,y; P(){} P(int X,int Y):x(X),y(Y){} };

map<int,int> dp[24];
int adj[24][4][23],deg[24][4],house_num;

int dfs(int id,int picked){
	if(dp[id].find(picked)!=dp[id].end()) return dp[id][picked];

	if(picked==(1<<(house_num+1))-1){
		rep(k,4) rep(a,deg[id][k]) if(adj[id][k][a]==house_num) return 1;
		return 0;
	}

	int ans=0;
	rep(k,4) rep(a,deg[id][k]) {
		int next_id=adj[id][k][a];
		if((picked&(1<<next_id))==0){
			ans+=dfs(next_id,picked|(1<<next_id));
			break;
		}
	}

	if(dp[id].size()<30000) dp[id][picked]=ans;
	return ans;
}

int main(){
	for(int n,m;scanf("%d%d",&n,&m),n;){
		int field[10][10],charch_x,charch_y,f[10][10];
		house_num=0;
		rep(i,m) rep(j,n) {
			scanf("%d",field[i]+j);
			if(field[i][j]==1) f[i][j]=house_num++;
			if(field[i][j]==2) charch_x=j,charch_y=i;
		}
		f[charch_y][charch_x]=house_num;

		rep(i,m) rep(j,n) if(field[i][j]!=0) {
			int id=f[i][j];
			dp[id].clear();
			rep(k,4){
				deg[id][k]=0;
				int x=j+dx[k],y=i+dy[k];
				while(0<=y && y<m && 0<=x && x<n){
					if(field[y][x]!=0) adj[id][k][deg[id][k]++]=f[y][x];
					x+=dx[k],y+=dy[k];
				}
			}
		}

		printf("%d\n",dfs(house_num,1<<house_num));
	}

	return 0;
}

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

#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
#define repp(i, start, to) for (li i = (li)(start); i < ((li)(to)); i++)

li a[10100];
li b[10100];
li n;

inline bool check() {
	cin >> n;
	li sa = 0;
	rep(i, n) {
		cin >> a[i];
		sa += a[i];
	}
	li sb = 0;
	rep(i, n) {
		cin >> b[i];
		sb += b[i];
	}
	if (sa > sb) {
		return false;
	}
	li num = sb - sa;

	li num1 = num;
	rep(i, n) {
		if (a[i] < b[i]) {
			li cnt = (b[i] - a[i] + 1) / 2;
			a[i] += cnt * 2;
			num1 -= cnt;
		}
	}
	if (num1 < 0) {
		return false;
	}
	a[0] += num1 * 2;
	li num2 = num;
	rep(i, n) {
		if (a[i] > b[i]) {
			num2 -= (a[i] - b[i]);
		}
	}
	return num2 == 0;
}

int main() {
	cout << (check() ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007LL
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vvvi = vector<vvi>; // intの2次元の型に vvi という別名をつける
const ll llMAX=9223372036854775807LL; 
const ll llMIN=-9223372036854775808LL;

void myprint1D(vi &data)
{
  REP(i,data.size())
    cout<<data[i]<<endl;
}

//配列を[y][x]で表示
void myprint2D_T(vvi &data)
{
  REP(i,data.size())
    myprint1D(data[i]);
}

//配列を[x][y]で表示
void myprint2D(vvi &data)
{
  ll l1=data.size();
  ll l2=data[0].size();
  REP(j,l2){
    REP(i,l1)
      cout<<data[i][j]<<" ";
    cout<<endl;
  }
}

//print(a,b...)って使い方
void print1(ll a){cout<<a<<endl;}
void print2(ll a,ll b){cout<<a<<" "<<b<<endl;}
void print3(ll a,ll b,ll c){cout<<a<<" "<<b<<" "<<c<<endl;}
void print4(ll a,ll b,ll c,ll d){cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;}
void print5(ll a,ll b,ll c,ll d,ll e){cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<endl;}


////////////////2つの要素をまとめてソート、前の変数が優先。flag=0で小さい順、1で大きい順
void mysort2(vi &a,vi &b,ll flag){
  if (a.size()>0){
    vector<pair<ll, ll>> p(a.size());
    REP(i,a.size()){
      p[i].first=a[i];
      p[i].second=b[i];
    }
    sort(p.begin(),p.end());
    if (flag==1){
      reverse(p.begin(),p.end());
    }
    REP(i,a.size()){
      a[i]=p[i].first;
      b[i]=p[i].second;
    }
  }
  return;
}
////////////////2同時ソートここまで


//////////////////3つの要素をまとめてソート、前の変数が優先。flag=0で小さい順、1で大きい順
void mysort3(vi &a,vi &b,vi &c,ll flag){
  if (a.size()>0){
    vector<pair<ll, pair<ll,ll>>> p(a.size());
    REP(i,a.size()){
      p[i].first=a[i];
      p[i].second.first=b[i];
	  p[i].second.second=c[i];
    }
    sort(p.begin(),p.end());
    if (flag==1){
      reverse(p.begin(),p.end());
    }
    REP(i,a.size()){
      a[i]=p[i].first;
      b[i]=p[i].second.first;
      c[i]=p[i].second.second;
    }
  }
  return;
}
////////////////3同時ソートここまで











ll n,k;

int main(){
  cin >> n;
  vi x(n),y(n),idxx(n),ans(n);
  REP(i,n)idxx[i]=i;
  REP(i,n){
    cin>>(x[i])>>(y[i]);
    x[i]--;
    y[i]--;
  }
  mysort3(x,y,idxx,0);

  vi gid(n),up(n),dw(n);
  vi rgmax(n+1);
  REP(i,n){
    gid[i]=i;
    up[i]=i;//含む
    dw[i]=i;//含む
  }

  ll tmpmax=y[n-1];
  rgmax[n]=0;
  for(ll i=n-1;i>=0;i--){
    if (tmpmax<y[i]){
      tmpmax=y[i];
    }
    rgmax[i]=tmpmax;
  }
  //myprint1D(rgmax);


  for(ll i=0;i<n;i++){
    ll yorimigimax=rgmax[i+1];
    if (y[i]<yorimigimax){
      ll ymgid=gid[yorimigimax];
      for(ll j=y[i];j<dw[ymgid];j++){
        gid[j]=ymgid;
      }
      dw[ymgid]=min(dw[ymgid],y[i]);
    }
  }


  //myprint1D(gid);
  for(ll i=0;i<n;i++){
    ans[i]=gid[y[i]];
  }
  vi nums(n);
  for(ll i=0;i<n;i++){
    nums[ans[i]]++;
  }
  vi fans(n);
  for(ll i=0;i<n;i++){
    fans[idxx[i]]=nums[ans[i]];
  }

  myprint1D(fans);



  //cout<<ans<<endl;




  
  return 0;
}

Measured memory_bytes: 18816
n = int(input())
v_list = list(map(int, input().split()))

dict_even = {}
for v in v_list[::2]:
    if v not in dict_even:
        dict_even[v] = 1
    else:
        dict_even[v] += 1

dict_odd = {}
for v in v_list[1::2]:
    if v not in dict_odd:
        dict_odd[v] = 1
    else:
        dict_odd[v] += 1

even1 = sorted(dict_even.items(), reverse=True, key=lambda x: x[1])[0]
odd1 = sorted(dict_odd.items(), reverse=True, key=lambda x: x[1])[0]
if even1[0] != odd1[0]:
    print(n - even1[1] - odd1[1])
else:
    if len(dict_even.items()) == len(dict_odd.items()) == 1:
        print(n // 2)
    elif len(dict_even.items()) == 1:
        odd2 = sorted(dict_odd.items(), reverse=True, key=lambda x: x[1])[1]
        print(n // 2 - odd2[1])
    elif len(dict_odd.items()) == 1:
        even2 = sorted(dict_even.items(), reverse=True, key=lambda x: x[1])[1]
        print(n // 2 - even2[1])
    else:
        even2 = sorted(dict_even.items(), reverse=True, key=lambda x: x[1])[1]
        odd2 = sorted(dict_odd.items(), reverse=True, key=lambda x: x[1])[1]
        print(min(n - even1[1] - odd2[1], n - even2[1] - odd1[1]))


Measured memory_bytes: 19808
// first second push_back unordered return continue break vector visited check flag bool while iterator begin end lower_bound upper_bound temp true false ll_MAX ll_MIN insert erase clear pop push compare ll64_MAX ll64_MIN  reverse replace stringstream string::npos length substr front priority_queue

#ifndef ONLINE_JUDGE
#include "debug.h"
#else
#include <bits/stdc++.h>
using namespace std;
#define debug(...) 42
#endif

#define endl '\n'
#define ll long long
#define rint register int
#define minpq priority_queue <int, vector<int>, greater<int> >
#define maxpq  priority_queue <int>

#define re register
#define pb(x) push_back(x);
#define ce(x) cout << x << '\n';

using db = long double;
using pll = pair < ll, ll >;
#define scan(a, n) 		for(int i = 0; i < n; i++)cin >> a[i];

#define rep(i,x,n,inc) for(i=x ; i<n ; i+=inc)
#define repr(i,x,n,inc) for( i=x ; i>n ; i+=inc)
#define all(a)      (a).begin(),(a).end()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define hell 1000000007
#define infl LLONG_MAX

#define conutBits(n)	__builtin_popcount(n)
#define Foxen(i,s) for (i=s.begin(); i!=s.end(); i++)
#define Fill(s,v) memset(s,v,sizeof(s))
#define cout_p(x, p) cout << fixed << setprecision((p)) << x << endl     //print with precision

#define tc(tt) \
    ll tt;    \
    cin >> tt; \
    for (ll _tt = 0; _tt < tt; _tt++) // testcase 

int32_t main() {
	ios::sync_with_stdio(0); 		cin.tie(0); cout.tie(0);

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ll t, i, x, j, y, 	z, k, n;
	std::vector<ll> v;
	cin >> n;
	rep(i, 0, n, 1) {
		cin >> x;
		v.push_back(x);
	}
	sort(all(v));
	reverse(all(v));

	z = v[0];
	j = 1, t = 2;
	// k=n-1;
	rep(i, 1, n - 1, 1) {
		if (t == 0)	{
			j++;
			t = 2;
		}
		z += v[j];
		// cerr << v[j] << " ";
		t--;
	}
	// ce("")

	ce(z)
}



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

using namespace std;

bool dfs(int& depth, int& ans, set<int> L);

int N, K;
size_t n_digits;
string s_N;

int main()
{
	cin >> N >> K;
	s_N = to_string(N);
	n_digits = s_N.length();
	int ans = 0;
	int depth = 0;
	set<int> L{ 0,1,2,3,4,5,6,7,8,9 };
	priority_queue<int, vector<int>, greater<int>> pq_L;
	for (int i = 0; i < K; i++)
	{
		int d;
		cin >> d;
		L.erase(d);
	}
	for (auto itr = L.begin(); itr != L.end(); itr++)
	{
		pq_L.push(*itr);
	}
	if (!dfs(depth, ans, L))
	{
		if (pq_L.top() != 0)
		{
			for (int i = 0; i <= n_digits; i++)
			{
				cout << pq_L.top();
			}
			cout << endl;
		}
		else
		{
			pq_L.pop(); cout << pq_L.top();
			for (int i = 1; i <= n_digits; i++)
			{
				cout << 0;
			}
			cout << endl;
		}
	}
	else cout << ans << endl;
	return 0;
}

bool dfs(int& depth, int& ans, set<int> L)
{
	depth++;
	for (auto itr = L.begin(); itr != L.end(); itr++)
	{
		ans += *itr * (int)pow(10, n_digits - depth);
		if (n_digits > depth)
		{
			if (dfs(depth, ans, L) == true) return true;
		}
		else
		{
			if (ans >= N) return true;
		}
		ans -= *itr * (int)pow(10, n_digits - depth);
	}
	depth--;
	return false;
}

Measured memory_bytes: 256
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.util.Map;
import java.util.PriorityQueue;
import java.math.BigInteger;
    
public class Main{

static final InputStream in=System.in;
static final PrintWriter out=new PrintWriter(System.out);
static final int INF=Integer.MAX_VALUE/2;
static final long LINF=Long.MAX_VALUE/2;
static String str;

public static void main(String[] args) throws IOException{
InputReader ir=new InputReader(in);
while(true){
int n=ir.nextInt();
if(n==0) break;
int[] d={1,2,4,5,3,6};
int ans=1;
while(n-->0){
String command=ir.next();
int top=d[0];
int front=d[1];
int left=d[2];
int back=d[3];
int right=d[4];
int bottom=d[5];
if("North".equals(command)){
d[3]=top; d[0]=front; d[1]=bottom; d[5]=back;
}
else if("East".equals(command)){
d[4]=top; d[5]=right; d[2]=bottom; d[0]=left;
}
else if("West".equals(command)){
d[2]=top; d[0]=right; d[4]=bottom; d[5]=left;
}
else if("South".equals(command)){
d[1]=top; d[5]=front; d[3]=bottom; d[0]=back;
}
else if("Right".equals(command)){
d[2]=front; d[3]=left; d[4]=back; d[1]=right;
}
else{
d[4]=front; d[1]=left; d[2]=back; d[3]=right;
}
ans+=d[0];
}
out.println(ans);
}
out.flush();
}

public static boolean isPalindrome(int s,int e){
for(int i=0;i<=(e-s)/2;i++) if(str.charAt(s+i)!=str.charAt(e-i)) return false;
return true;
}

static class InputReader {
private InputStream in;
private byte[] buffer=new byte[1024];
private int curbuf;
private int lenbuf;

public InputReader(InputStream in) {this.in=in;}
  
public int readByte() {
if(lenbuf==-1) throw new InputMismatchException();
if(curbuf>=lenbuf){
curbuf= 0;
try{
lenbuf=in.read(buffer);
}
catch (IOException e) {
throw new InputMismatchException();
}
if(lenbuf<=0)
return -1;
}
return buffer[curbuf++];
}

public boolean isSpaceChar(int c){return !(c>=33&&c<=126);}

private int skip() {int b; while((b = readByte())!=-1&&isSpaceChar(b)); return b;}

public String next() {
int b=skip();
StringBuilder sb=new StringBuilder();
while(!isSpaceChar(b)){
sb.appendCodePoint(b);
b=readByte();
}
return sb.toString();
}
 
public int nextInt() {
int c=readByte();
while (isSpaceChar(c)) c=readByte();
boolean minus=false;
if (c=='-') {
minus=true;
c=readByte();
}
int res=0;
do{
if(c<'0'||c>'9') throw new InputMismatchException();
res=res*10+c-'0';
c=readByte();
}while(!isSpaceChar(c));
return (minus)?-res:res;
}

public long nextLong() {
int c=readByte();
while (isSpaceChar(c)) c=readByte();
boolean minus=false;
if (c=='-') {
minus=true;
c=readByte();
}
long res = 0;
do{
if(c<'0'||c>'9') throw new InputMismatchException();
res=res*10+c-'0';
c=readByte();
}while(!isSpaceChar(c));
return (minus)?-res:res;
}

public int[] toIntArray(int n){
int[] a=new int[n];
for(int i=0;i<n;i++) a[i]=nextInt();
return a;
}
}
}

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

int main() {
    int A,B,C,ans=0;
    cin >> A >> B >> C;
    ans=max({A,B,C});
    if(ans==A){
        cout << A*10+B+C; return 0;
    }
    if(ans==B){
        cout << B*10+A+C; return 0;
    }
    if(ans==C){
        cout << C*10+B+A; 
    }
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MAX(a,b) ((a)<(b) ? (b) : (a))

int
get_(int num) {
  int ret = num * 100;
  ret += num / 10 % 10 * 10;
  ret += num / 100;
  return ret;
}

int main() {
  int s,e;
  
  cin >> s >> e;
  
  {
    int s_ = get_(s / 100);
    if ( s_ < s ) s = get_(s / 100 + 1);
    else s = s_;\
  }
  {
    int e_ = get_(e / 100);
    if ( e < e_ ) e = get_(e / 100 - 1);
    else e = e_;
  }
  
  s /= 100;
  e /= 100;
  cout << MAX(0, e-s+1) << endl;
}


Measured memory_bytes: 256
def resolve():
    import itertools
    N, M = map(int, input().split())
    S = []
    K = []
    ans = 0
    for _ in range(M):
        s = list(map(int, input().split()))
        K.append(s[0])
        S.append(s[1:])
    P = list(map(int, input().split()))
    for i in itertools.product([0,1], repeat=N):
        count = 0
        for j in range(M):
            ichi = 0
            for q in range(K[j]):
                ichi += i[S[j][q]-1]
            if ichi%2 == P[j]:
                count += 1
        if count == M:
            ans += 1
    print(ans)
resolve()

Measured memory_bytes: 9104
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl
#define YORN(f) cout<<((f)?"YES":"NO")<<endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main()
{
    int x, y;
    cin >> x >> y;

    int gx = 0, gy = 0;
    if (x == 2) {
        gx = 2;
    }
    if (x == 4 || x == 6 || x == 9 || x == 11) {
        gx = 1;
    }
    if (y == 2) {
        gy = 2;
    }
    if (y == 4 || y == 6 || y == 9 || y == 11) {
        gy = 1;
    }

    yorn(gx == gy);
    
    return 0;
}

Measured memory_bytes: 3680
n = gets.chomp.to_i

ax = []
ay = []
ah = []
gx, gy, gh = -1, -1, -1
n.times do
  x, y, h = gets.chomp.split(" ").map(&:to_i)
  ax << x
  ay << y
  ah << h
  gx, gy, gh = x, y, h if h > 0
end

ans = []
0.upto(100) do |cx|
  0.upto(100) do |cy|
    ch = gh + (gx - cx).abs + (gy - cy).abs
    ch = [ch, 0].max
    flag = true
    n.times do |i|
      x = ax[i]
      y = ay[i]
      h = ah[i]
      hh = ch - (x - cx).abs - (y - cy).abs
      hh = [hh, 0].max
      if h != hh
        flag = false
      end
    end
    if flag
      ans << [cx, cy, ch]
    end
  end
end

if ans.length == 1
  puts ans[0].join(" ")
end

Measured memory_bytes: 1788
def main(T):
    ans = list(T)
    for i, s in enumerate(T):
        if s == '?':
            ans[i] = 'D'
    print(''.join(ans))
    # for i, s in enumerate(T):
    #     if s == '?':
    #         if T[i+1] != 'P':
    #             ans[i] = 'P'
    #         else:
    #             ans[i] = 'D'
    # print(''.join(ans))


if __name__ == '__main__':
    T = input()
    main(T)

Measured memory_bytes: 10836
#include<bits/stdc++.h>
#define N 200005
#define int long long
#define pb push_back
#define x first
#define y second
#define all(v) v.begin(),v.end()
#define coffee prince
#define sz(a) (int)a.size()
using namespace std;

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k<=a){
        cout<<k;
    }
    else if(k<=(a+b)){
        cout<<a;
    }
    else{
        cout<< a - (k-(a+b));
    }
        return 0;
}


Measured memory_bytes: 3648
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	vector<int> x, y;
	vector<int> a(N); rep(i, 0, N) {
		cin >> a[i];
		if (i % 2 == 0)x.emplace_back(a[i]);
		else y.emplace_back(a[i]);
	}
	if (N % 2 == 1) {
		reverse(all(x));
		x.insert(x.end(), y.begin(), y.end());
		cout << x[0]; rep(i, 1, x.size()) { cout << " " << x[i]; } cout << endl;
	}
	else {
		reverse(all(x));
		x.insert(x.end(), y.begin(), y.end());
		reverse(all(x));
		cout << x[0]; rep(i, 1, x.size()) { cout << " " << x[i]; } cout << endl;
	}

	return 0;
}

Measured memory_bytes: 4332
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);

        long n = stdIn.nextLong();
        long a = stdIn.nextLong();
        long b = stdIn.nextLong();

        if(n%(a+b) < a){
            System.out.println((n/(a+b)*a)+(n%(a+b)));
        }else{
            System.out.println((n/(a+b)*a)+a);
        }
    }
}

Measured memory_bytes: 23636
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int A, N; cin >> N >> A;
    cout << (A < N%500 ? "No" : "Yes") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)    for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define rrep(i, n)   for(int i=(n-1); i>=0; --i)
#define all(v)       v.begin(), v.end()
#define rall(v)      v.rbegin(), v.rend()
#define int          long long
template<typename T>
using vv  = vector<vector<T>>;
using vi  = vector<int>;
using vvi = vector<vector<int>>;
using P   = pair<int, int>;
using ll  = long long;
constexpr ll INF = 1LL << 60;

signed main(){

    int n;
    cin >> n;
    string s = "";

    while(1){
        if(n < 1){
            break;
        }
        int x = n % 26;
        n /= 26;
        if(x == 0){
            x = 26;
            n--;
        }
        //cout << "n : " << n << " x : " << x << endl;
        s += (char) ('a' + x-1);
    }
    reverse(all(s));
    cout << s << endl;

    return 0;
}



Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define DEBUG
#define PI 3.141592653589793238462643383279
 
#define _GLIBCXX_DEBUG
#ifdef DEBUG
#define s(...) show(__VA_ARGS__);
#define sl(...) show(__VA_ARGS__);cout<<endl;
#else
#define s(...)
#define sl(...)
#endif
void show() {}
template <class Head,class... Args>void show(Head t,Args... args){std::cout<<t<<" ";show(args...);}
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define REP1(i, n) for(ll i = 1; i <= n; i++)
#define REPR1(i, n) for(ll i = n; i >= 1; i--)
#define FOR1(i, m, n) for(ll i = m; i <= n; i++)
const ll INF = LLONG_MAX;
const ull MOD = 1000000007;
#define VEC(type,A,N) vector<type> A(N)
#define VECi(type,A,N,i) vector<type> A(N,i)
#define VEC2(type,A,N,M) vector<vector<type>> A(N,vector<type>(M))
#define VEC2i(type,A,N,M,i) vector<vector<type>> A(N,vector<type>(M,i))
#define ALL(v) v.begin(), v.end()
ll frac(ll k){
    int s = 1;
    for (ll i=1; i<=k; ++i)s *= i;
    return s;
}
ll gcd(ll a, ll b){
   if (a%b==0)return(b);
   else return(gcd(b, a%b));
}
ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}
ll antidiv(ll N,ll C,ll D){
    return N-floor(N/C)-floor(N/D)+floor(N/lcm(C,D));
}
vector<ll> yakusuu(ll N){
    vector<ll> ret;
    for (ll i = 1; i * i <= N; i++) {
        if (N % i == 0) {
            ret.push_back(i);
            if (i * i != N) ret.push_back(N / i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}
ll digitPoor(ll n)
{
    assert(INT_MAX == 2147483647);
    assert(n >= 0);

    if (n < 10)         return 1;
    if (n < 100)        return 2;
    if (n < 1000)       return 3;
    if (n < 10000)      return 4;
    if (n < 100000)     return 5;
    if (n < 1000000)    return 6;
    if (n < 10000000)   return 7;
    if (n < 100000000)  return 8;
    if (n < 1000000000) return 9;
    return 10;
}
struct p{
  ll x;
  bool b;
};
int main(){
    ll S;
    cin>>S;

    cout<<S+S*S+S*S*S;
    //cout<<fixed<<setprecision(32)<<m;
    //sort(ALL(C),[](auto& a, auto& b) {return a[2] < b[2];});
    //if(equal(D.begin(), D.end()-1, K.begin()))cout<<"Yes";else cout<<"No";
    cout<<endl;
    return 0;
}


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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		Console.WriteLine(B / X - A / X + (A % X == 0 ? 1 : 0));
	}
	long A,B,X;
	public Sol(){
		var d = rla();
		A = d[0]; B = d[1]; X = d[2];
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 13140
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

vector<lint> ALL(51);
vector<lint> P(51);

lint solve(lint n,lint x){
    if(x==0)return 0;
    if(n==0)return 1;
    if(x==1)return 0;
    if(ALL[n]==x)return P[n];
    if(x<=ALL[n-1]+1)return solve(n-1,x-1);
    if(x==ALL[n-1]+2)return solve(n-1,x-2)+1;
    return solve(n-1,ALL[n-1])+1+solve(n-1,x-ALL[n-1]-2);
}

//AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC
int main(){
    P[0]=1;
    ALL[0]=1;
    for(int i=1;i<=50;i++){
        ALL[i]=ALL[i-1]*2+3;
        P[i]=P[i-1]*2+1;
    }
    lint n,x;cin>>n>>x;
    cout<<solve(n,x)<<endl;
}


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

using namespace std;

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vvvvll = vector<vector<vector<vector<ll>>>>;
using pl4 = pair<ll,ll>;
using str = string;
using vpl4 = vector<pair<ll,ll>>;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define llin(x) ll (x);cin >>(x);
#define stin(x) str (x);cin >>(x);
#define vllin(x,n) vll (x)(n);FOR(i,0,n-1){cin >>(x)[i];}
#define vllin2(a,b,n) vll (a)(n);vll (b)(n);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i];}
#define vllin3(a,b,c,n) vll (a)(n);vll (b)(n);vll (c)(n);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i]>>(c)[i];}
#define vlling(x,n) (x).assign(n,0);FOR(i,0,n-1){cin >>(x)[i];}
#define vlling2(a,b,n) (a).assign(n,0);(b).assign(n,0);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i];}
#define vlling3(a,b,c,n) (a).assign(n,0);(b).assign(n,0);(c).assign(n,0);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i]>>(c)[i];}
#define vpl4in(x,n) vpl4 (x)((n),mp(0,0));FOR(i,0,n-1){cin >>x[i].fi>>x[i].se;}
#define FOR(i,a,b) for(ll i = a ; i <= b ; i++)
#define rFOR(i,b,a) for(ll i = a; i >= b ; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout<<(x);
#define sal(x) cout<<(x)<<endl;
#define says(x) cout<<(x)<<(' ');
#define sas cout<<(' ');
#define sayR(x) cout<<fixed<<setprecision(10)<<(x);
#define salR(x) cout<<fixed<<setprecision(10)<<(x)<<endl;
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;
#define Imp(a) cout <<((a)?"Possible":"Impossible")<<endl;
#define IMP(a) cout <<((a)?"POSSIBLE":"IMPOSSIBLE")<<endl;
#define pow(a,b) ll(pow(a,b))

ll MOD=1000000007;

signed main(){
    stin(s);
    FOR(i,0,s.sz-1){
        if((i%2==0&&s[i]=='L')|(i%2==1&&s[i]=='R')){
            sal("No")
            return 0;
        }
    }
    sal("Yes")
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N, H; cin >> N >> H;
    vector B(N,0);
    int am = 0;
    rep(i,N) {
        int a, b; cin >> a >> b;
        B.at(i) = b;
        am = max(am, a);
    }
    sort(B.begin(), B.end());

    ll res = 0;
    while (H > am && am < B.back()) {
        H -= B.back(); B.pop_back();
        res++;
    }
    res += ((ll)H + am - 1) / am;
    cout << res << endl;
}


Measured memory_bytes: 3760
N = int(input())
T, A = map(int, input().split())
l = list(map(int, input().split()))
deltatemperature = []

for height in l:
  deltatemperature.append(abs(T- height* 0.006- A))
  
m = min(deltatemperature)
mindex = deltatemperature.index(m)
print(mindex+ 1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef unsigned long long ll;
const long long INF = 1LL << 60;

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

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

    ll before = 1;
    rep(i, N) {
        ll T;
        cin >> T;
        // ll tmp = before * T;
        // cout << tmp << endl;
        before = before * (T / gcd(before, T));
    }

    cout << before << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#define ll long long
#define INF 1e+7
#define MOD 1000000007
using namespace std;



int main(){
    ll ans=0;
    
    int N;
    cin >> N;
    
    int soinsu[100]={};
    
    for(int i=2; i<=N; i++){
        int j=i;
        while(j>1){
            for(int k=2; k<=j; k++){
                if(j%k==0){
                    soinsu[k]++;
                    j/=k;
                    break;
                }
            }
        }
    }
    

    ll two=0;
    ll four=0;
    ll fourteen=0;
    ll four_fourteen=0;
    ll two_twentyfour=0;
    ll twentyfour=0;
    for(int i=0; i<100; i++){
        if(soinsu[i]==2 || soinsu[i]==3){
            two++;
        }else if(soinsu[i]>=4){
            four++;
        }
        
        if(soinsu[i]>=4 && soinsu[i]<14){
            four_fourteen++;
        }else if(soinsu[i]>=14){
            fourteen++;
        }
           
        if(soinsu[i]>=74){
            ans++;
        }
        
        if(soinsu[i]>=2 && soinsu[i]<24){
            two_twentyfour++;
        }else if(soinsu[i]>=24){
            twentyfour++;
        }
    }
    
    if(four >= 3){
        ans += four*(four-1)*(four-2)/2;
    }
    
    if(two>=1 && four>=2){
        ans += two * (four*(four-1)/2);
    }
    
    
    if(four_fourteen>=1 && fourteen>=1){
        ans += four_fourteen*fourteen;
    }
    if(fourteen>=2){
        ans += fourteen*(fourteen-1);
    }
    
    if(two_twentyfour>=1 && twentyfour>=1){
        ans+=two_twentyfour*twentyfour;
    }
    if(twentyfour>=2){
        ans += twentyfour*(twentyfour-1);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, i, check = 0;
  cin >> N;
  
  for (i = 0; i < N; i++){
    string s;
    cin >> s;
    if (s == "Y")
      check++;
  }
  if(check > 0)
    cout << "Four" << endl;
  else
    cout << "Three" << endl;
}

Measured memory_bytes: 256
from collections import Counter

a = input()
a_list = list(map(int, input().split()))
 
# 要素数の数え上げと取り出し
num_counter = Counter(a_list)
num_keys = sorted(num_counter.keys(), reverse=True)

big = 0
small = 0

for i in num_keys:
  x = num_counter[i]
  if x >= 4:
    if big == 0:
      big = small = i
    elif big != 0 and small == 0:
      small = i
  elif x == 3 or x == 2:
    if big == 0:
      big = i
    elif big != 0 and small == 0:
      small = i
  if big != 0 and small != 0:
    break
print(big * small)

Measured memory_bytes: 18600