akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstring>
#include<climits>
#include<iomanip>
#include<cmath>
#include<vector>
using namespace std;
double dp[3001][3001];
double solve(vector<double> &v,int n,int head)
{
    if(head==0) return 1;
    if(n==0) return 0;
    if(dp[n][head]>-0.9)
    {
        return dp[n][head];
    }
    return dp[n][head]=(v[n]*solve(v,n-1,head-1)+(1-v[n])*solve(v,n-1,head));
}
int main()
{
    int n;cin>>n;
    vector<double> v(n+1);
    for(int i=1;i<=n;i++)
    {
        cin>>v[i];
    }
    memset(dp,-1,sizeof(dp));
    cout<<fixed<<setprecision(10)<<solve(v,n,((n+1)/2));;
    return 0;
}

Measured memory_bytes: 74360
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n)  { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x)         { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};

int main() {
	int n, t;
	cin >> n >> t;
	vector<ll> cost(n);
	REP(i, n)
		cin >> cost[i];
	ll ma=0;
	ll ma2 = 0;
	vector<ll> sub(n);
	for (int i = n - 1;i >= 0;i--) {
		ma = max(ma, cost[i]);
		sub[i] = ma - cost[i];
		ma2 = max(ma2, sub[i]);
	}
	int ans = 0;
	REP(i, n)
		if (sub[i] == ma2)
			ans++;
	cout << ans << endl;
}

Measured memory_bytes: 1920
#include<stdio.h>
int solve(long long int x,long long int y,long long int n){
  long long int i,large,f,tf=0;

  if(n%2==0)
    tf=1;

  if(y<n/2){
    large=y;
    f=0;
  }
  else{
    large=(n-1-y);
    f=1;
  }
  if(large <= x && n-1-large >= x){
    //if(tf==1 && f==1) return ( (n-y-1)%3+1 );
    return large%3+1;
  }

  if(x<n/2){
    large=x;
    f=0;
  }
  else{
    large=(n-1-x);
    f=1;
  }

  if(large <= y && n-1-large >= y){
    //  if(tf==1 && f==1) return ( (n-x-1)%3+1 );
    return large%3+1;
  }

  return 0;
}

main(){
  long long int n,k,i;
  long long int x,y;
  long long int dx,dy;
  int fl;
  int ans[1001];
  scanf("%lld",&n);
  scanf("%lld",&k);
  if((n*n)%2==0)
    fl=0;
  else
    fl=1;
  for(i=0;i<k;i++){
    scanf("%lld %lld",&x,&y);
    ans[i]=solve(x-1,y-1,n);
  }
  for(i=0;i<k;i++)
    printf("%d\n",ans[i]);

  return 0;
}

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


int main()
{
 

    long n;
    cin>>n;

    //a+b-2：距離
    //n=a*b：分解
    
    long min_wk=10000000000000;
    for(long i=1;i*i<=n;i++){
        if(n%i==0)
          min_wk=min(min_wk,i+n/i-2);
    }

    cout<<min_wk;
    
    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
x = gets.split.map(&:to_f)
y = gets.split.map(&:to_f)

(1..3).each do |p|
  d = 0.0
  n.times do |i|
    d += ((x[i] - y[i]).abs)**p
  end
  puts d**(1.0/p)
end

chebyshev = []
n.times do |i|
  chebyshev.push (x[i] - y[i]).abs
end

puts chebyshev.max

Measured memory_bytes: 8844
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
typedef long long ll;
typedef pair<int, int> P;
 
int main(){
  string s;
  cin >> s;

  if(s=="AAA" || s=="BBB")  cout << "No" << endl;
  else                      cout << "Yes" << endl;

  return 0;
}

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

using namespace std;

int main()
{
    int N;
    cin >> N;
    if(N < 10){
        if(N == 3){
            cout<<"bon"<<endl;
        }else if(N==0||N==1||N==6||N==8){
            cout<<"pon"<<endl;
        }else{
            cout<<"hon"<<endl;
        }
    }else if(N < 100){
        if(N%10 == 3){
            cout<<"bon"<<endl;
        }else if(N%10==0||N%10==1||N%10==6||N%10==8){
            cout<<"pon"<<endl;
        }else{
            cout<<"hon"<<endl;
        }
    }else if(N < 1000){
        if(N%100%10 == 3){
            cout<<"bon"<<endl;
        }else if(N%100%10==0||N%100%10==1||N%100%10==6||N%100%10==8){
            cout<<"pon"<<endl;
        }else{
            cout<<"hon"<<endl;
        }
    }
    return 0;
}


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

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

    vector<int> A(N+10);

    for(int i = 1;i <= N;i++){
        cin >> A.at(i);
    }

    int j = 1;
    int ans = 0;
    
    while(true){
        if(j != 2){
            j = A.at(j);
            ans++;
        }else{
            break;
        }

        if(ans > N){
            ans = -1;
            break;
        }
    }

    cout << ans << endl;    
}

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

char str[10];
int num[10];

bool cmp(const int &x, const int &y);

int main(){
	scanf("%s", str);
	for(int i = 0; i < 4; i++) num[i + 1] = str[i] - 'A';
	sort(num + 1, num + 4 + 1, cmp);
	if(num[1] == num[2] && num[2] != num[3] && num[3] == num[4]) printf("Yes\n");
	else printf("No\n");
	return 0;
}

bool cmp(const int &x, const int &y){return x < y;}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> P;
#define pb push_back
#define ft first
#define sd second
#define mp make_pair
#define fr(i,n) for(int i=0;i<(n);i++)
#define Fr(i,n) for(int i=0;i++<(n);)
#define ifr(i,n) for(int i=(n)-1;i>=0;i--)
#define iFr(i,n) for(int i=(n);i>0;i--)

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if((a<c&&c<b)||(a>c&&c>b)) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

using namespace std;

int main()
{
    int prod;
    scanf("%d", &prod);
    for (int i = 9; i >= 1; i--)
        if (prod % i == 0 && (prod / i) <= 9)
            puts("Yes"), exit(0);
    puts("No");
    return 0;
}

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

using namespace std;

namespace {

}

int main()
{
	std::string s;

	int A = 0, B = 0;

	cin >> A >> B;

	int start = A + B;

	if (start > 23){
		start -= 24;
	}

	cout << start;

	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

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

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n, m; cin >> n >> m;
  vector<int> edge(n, 0);
  REP(i, m) {
    int a, b; cin >> a >> b; --a; --b;
    ++edge[a]; ++edge[b];
  }
  REP(i, n) cout << edge[i] << '\n';
  return 0;
}


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

int main(){
    ll a,b;
    cin >> a >> b;
    cout << (a-1)*(b-1) << endl;
    
    return 0;
}








Measured memory_bytes: 256
open System
open System.Collections.Generic

[<AutoOpen>]
module Cin =
    let read f = stdin.ReadLine() |> f
    let reada f = stdin.ReadLine().Split() |> Array.map f
    let readChars() = read string |> Seq.toArray
    let readInts() = readChars() |> Array.map (fun x -> Convert.ToInt32(x.ToString()))

[<AutoOpen>]
module Cout =
    let writer = new IO.StreamWriter(new IO.BufferedStream(Console.OpenStandardOutput()))
    let print (s: string) = writer.Write s
    let println (s: string) = writer.WriteLine s
    let inline puts (s: ^a) = string s |> println

// -----------------------------------------------------------------------------------------------------

module Permutation =

    /// 引数が破壊的に更新されることに注意
    let nextPermutation (arr: 'a array): bool =
        let swap i j =
            let tmp = arr.[i]
            arr.[i] <- arr.[j]
            arr.[j] <- tmp

        let mutable r = Array.length arr - 1
        while r > 0 && arr.[r - 1] >= arr.[r] do
            r <- r - 1
        if r <= 0 then
            false
        else
            let mutable l = Array.length arr - 1
            while (arr.[l] <= arr.[r - 1]) do
                l <- l - 1
            if l < r then failwith "nextPermutation: Bug Found!"
            swap l (r - 1)
            let mutable l = Array.length arr - 1
            while r < l do
                swap r l
                r <- r + 1
                l <- l - 1
            true

    /// 順列を列挙
    /// O (n!)
    let permutations (arr: 'a array): seq<'a array> =
        seq {
            yield arr
            let mutable arr = arr |> Array.copy
            while nextPermutation arr do
                yield arr
                arr <- arr |> Array.copy
        }

// -----------------------------------------------------------------------------------------------------

let main() =
    let n = read int
    let perms = Permutation.permutations [| 0 .. n - 1 |]
    let xys = Array.zeroCreate n
    for i in 0 .. n - 1 do
        let [| x; y |] = reada int
        xys.[i] <- x, y
    seq {
        for perm in perms do
            let mutable tot = 0.
            for i in 0 .. n - 2 do
                let x1, y1 = xys.[perm.[i]]
                let x2, y2 = xys.[perm.[i + 1]]

                let dist =
                    pown (x1 - x2) 2 + (pown (y1 - y2) 2)
                    |> float
                    |> sqrt
                tot <- tot + dist
            yield tot
    }
    |> Seq.average
    |> puts
    ()

// -----------------------------------------------------------------------------------------------------
main()
writer.Dispose()


Measured memory_bytes: 19040
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//-------------------------------------------------------
int DP[3001*3001];  
void Calc(){
	string S = res();
	string T = res();
	for(int i=0;i<=S.length();i++){
		for(int j=0;j<=T.length();j++){
			int ans = 0; 
			if(i != 0){
				ans = max(ans,DP[(i-1)*3001+j]);
			}
			if(j != 0){
				ans = max(ans,DP[i*3001+j-1]);
			}
			if(i != 0 && j != 0 && S[i-1] == T[j-1]){
				ans = max(ans,DP[(i-1)*3001+j-1]+1);
			}
			DP[i*3001+j] = ans;
		}
	}
	stack<char> sp;
	int X = S.length();
	int Y = T.length();
	while(X != 0 && Y != 0){
		if(DP[X*3001+Y] == DP[X*3001+Y-1]){
			Y--;
		}
		else if(DP[X*3001+Y] == DP[(X-1)*3001+Y]){
			X--;
		}
		else{
			sp.push(S[X-1]);
			X--;
			Y--;
		}
	}
	while(!sp.empty()){
		cout << sp.top();
		sp.pop();
	}
	cout << endl;
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
    詰まった時に、別の分野の問題として考え直す（これdpでは？、グラフとしてみればいいのでは？）
    多くの問題はパターンマッチだが、パターンに落とし込むまでが難しく、そのための訓練としてわからない問題をあれこれ色々な角度から考察してみるのではないか
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */



// パスカルの三角形を使った実装
ll C[55][55]; // C[n][k] -> nCk

void comb_table(int N){
    for(int i=0; i<=N; i++){
        for(int j=0; j<=i; j++){
            if(j==0 || j==i) C[i][j] = 1LL;
            else C[i][j] = (C[i-1][j-1]+C[i-1][j]);
        }
    }
}

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

    comb_table(50);
    int n, a, b; cin >> n >> a >> b;
    vector<ll> v(n);
    ll maxv=0;
    rep(i, n) { cin >> v[i]; chmax(maxv, v[i]); }

    sort(v.rbegin(), v.rend());
    double ans=0;
    rep(i, a) ans+=v[i];
    ans/=(double)a;

    if(maxv==v[a-1]){
        int cnt=0;
        ll res=0;
        rep(i, n) if(v[i]==maxv) ++cnt;
        repr(i, a, min(b, cnt)+1) res+=C[cnt][i];
        cout << setprecision(10);
        cout << ans << endl;
        cout << res << endl;
    }
    else{
        int cnt1=0, cnt2=0;
        rep(i, n) if(v[i]==v[a-1]) {
            ++cnt1;
            if(i<a) ++cnt2;
        }
        ll res=C[cnt1][cnt2];
        cout << setprecision(10);
        cout << ans << endl;
        cout << res << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
using namespace std;
typedef long long ll;
const int MAXN = 1e5+7;
const int INF = 0x3f3f3f3f;
ll f[5000*5000+5];
int n;
int a[3][4];
double x[4];
void add(int w,int c){
	if(c<=0)return;
	for(int i=0;i<=5000*5000-w;i++)
		f[i+w]=max(f[i+w],f[i]+c);
}
int main(){
	ios::sync_with_stdio(false);
	int n,ga,gb,sa,sb,ba,bb;
	cin>>n>>ga>>sa>>ba>>gb>>sb>>bb;
	memset(f,0,sizeof f);
	add(ga,gb-ga);add(sa,sb-sa);add(ba,bb-ba);
	n=n+f[n];
	memset(f,0,sizeof f);
	add(gb,ga-gb);add(sb,sa-sb);add(bb,ba-bb);
	cout<<n+f[n]<<endl;
	return 0;
}

Measured memory_bytes: 196216
function main(input) {
	const args = input.split('\n');
	const A=parseInt(args[0],10),
		  B=parseInt(args[1],10),
		  C=parseInt(args[2],10),
		  X=parseInt(args[3],10);

	var count = 0;

    for (var a = 0; a <= A; ++a) {
        for (var b = 0; b <= B; ++b) {
            for (var c = 0; c <= C; ++c) {
                var sum = (a * 500) + (b * 100) + (c * 50);
                if (sum === X) ++count;
            }
        }
    }
    console.log(count);
}
   
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 32424
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int N;

bool ok(int ind, vector<ll> &A){
    ll cur = A[ind];
    rep(i, N){
        if(i == ind) continue;
        if(cur * 2 >= A[i]){
            cur += A[i];
        }
        else{
            return false;
        }
    }
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code

    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    
    sort(all(A));
    
    int l = -1, r = N - 1; // NG, OK
    
    while(r - l > 1){
        int mid = (l + r) / 2;
        if(ok(mid, A)){
            r = mid;
        }
        else{
            l = mid;
        }
    }
    
    output(N - r);
    
    
    return 0;
}

Measured memory_bytes: 1024
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0:
        cnt+=1
        temp //= i
      arr.append([i, cnt])

  if temp!=1:
    arr.append([temp, 1])

  if arr==[]:
    arr.append([n, 1])

  return arr

def main():
  n = int(input())
  lst = factorization(n)

  ans = 0
  for a, b in lst:
    if a == 1:
      continue

    i = 1
    while i <= b:
      b -= i
      i += 1
      ans += 1

  print(ans)

main()


Measured memory_bytes: 9484
#include<cstdio>
#include<iostream>
#include<map>
#include<set>
#include<vector>
#include<cstring>
#include<cassert>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<limits>
#include<ctime>
#include<stack>
#include<bits/stdc++.h>
#include<string>
#include<stdlib.h>
#include<stdio.h>
typedef long long ll;

using namespace std;

int main(){
	int n;
	cin>>n;
	if(n==1){
		cout<<0;
	}
	if(n==0){
		cout<<1;
	}
}

Measured memory_bytes: 3592
B = (1 << 10).times.map{|v| 10.times.count{|i| v[i] > 0 }}

N = gets.to_i
F = N.times.map{ gets.chomp.tr(' ','').to_i(2) }
P = N.times.map{ gets.split.map(&:to_i) }

def revenue(state)
  N.times.inject(0) do |s, i|
    s + P[i][B[F[i] & state]]
  end
end

puts (1 ... 1 << 10).map{|s| revenue(s) }.max


Measured memory_bytes: 3964
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define erep(i,N) for(int i = N; i >= 0; i--)
const ll INF = 1000000000000000000;
//input
int N,K;


//processing
ll A = INF;


//dpTable
//int dp[100050];

int main(){
    cin >> N >> K;
    vector<ll> h(N);
    rep (i,N) cin >> h.at(i);
    sort(h.begin(),h.end());
    for (int i = 0; i < N - K + 1; i++){
        A = min(A,h.at(i + K - 1) - h.at(i));
    }
    cout << A << endl;
    return 0;
}

Measured memory_bytes: 4032
#include <iostream>
#include <string>
#include <cmath>

int main()
{
  std::string s, t;
  std::cin >> s >> t;

  int ss = s.size();
  int ts = t.size();

  int len = std::abs( ss - ts );
  if( ss > ts ) {
    for( int i = 0; i < len; i++ ) {
      t = "0" + t;
    }
  }
  else {
    for( int i = 0; i < len; i++ ) {
      s = "0" + s;
    }
  }

  std::string a;
  if( s > t ) {
    a = "GREATER";
  }
  if( s < t ) {
    a = "LESS";
  }
  if( s == t ) {
    a = "EQUAL";
  }

  std::cout << a << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <set>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

#define INF 100000000
#define MOD 1000000007
#define writeln(n) cout<<n<<endl
//setprecision(10);
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

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;
}

llong pownew(llong m, llong n) {
    if (n == 0) { return 1; }
    if (n % 2 == 0) { return pow(m*m, n/2); }
    return pow(m, n-1) * m;
}

bool isprime(int p) {
    if (p == 1) return false;
    for (int i = 2; i < p; i++) {
        if (p%i == 0) return false;
    }
    return true;
}

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

const int inf=100000000;

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

llong extgcd(llong a,llong b,llong& x,llong& y){
    llong d=a;
    if(b!=0){
        d=extgcd(b,a%b,y,x);
        y-=(a/b)*x;
    }
    else{
        x=1;y=0;
    }
    return d;
}

llong  mod_inverse(llong  a,llong m){
    long long int x,y;
    extgcd(a,m,x,y);
    return (m+x%m)%m;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    set<pair <int,int>> E;
    int n,m; cin>>n>>m;
    string ans="IMPOSSIBLE";
    REP(i,m)
    {
        int a,b;
        cin>>a>>b; a--; b--;
        E.insert({a,b});
        E.insert({b,a});
    }
    REP(i,n)
    {
    if(E.count({0,i})&&E.count({i,n-1})) ans="POSSIBLE";
    }
    cout<<ans<<endl;
    return  0;
}


Measured memory_bytes: 19072
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
using namespace std;
typedef double D;
typedef complex<D> P;
const D EPS = 1e-8;
const D PI = acos(-1);

int n,r,q,r2;
P p[30];
int cur;

inline D dot(const P &x, const P &y){return real(conj(x)*y);}

inline P rotate(const P &v, const D &s){
  return P(real(v)*cos(s) - imag(v)*sin(s), real(v)*sin(s) + imag(v)*cos(s) );
}

inline D arg(const P &a,const P &b,const P &c){return acos(dot(b-a,c-a)/(abs(b-a)*abs(c-a)));}

inline D rot_seta(const int &end){
  D dis = norm(p[end]-p[cur]);
  D seta = acos( (r2 - dis)/(r2) );
  P nxt = rotate(p[cur],-seta);
  return arg(p[cur],p[end],nxt);
}

int main(){
  while(scanf("%d%d%d",&n,&r,&q), n){
    r2 = 2*r*r;
    rep(i,n){
      D x,y;
      scanf("%lf%lf",&x,&y);
      p[i] = P(x,y);
      if(abs(abs(p[i])-r)<EPS)cur = i;
    }
    
    vector<int> nxt(n,-1);
    
    rep(i,q){
      int id = -1;
      D min_s = PI;
      if(nxt[cur]>=0)id = nxt[cur];
      else{
	rep(j,n){
	  if(cur==j)continue;
	  D s = rot_seta(j);
	  if(id<0 || s+EPS < min_s)id = j, min_s = s;
	}
	nxt[cur] = id;
      }

      D seta = rot_seta(id);
      rep(i,n){
	if(i==cur)continue;
	p[i] = rotate(p[i]-p[cur],seta) + p[cur];
      }
      printf("%.9lf %.9lf\n",p[id].real(), p[id].imag());
      cur = id;
    }
  }
}

Measured memory_bytes: 1336
#include <iostream>
#include<vector>
#include<queue>
#include<string>
#include<list>
#include<algorithm>
using namespace std;
int c = 0;
void swap(int *x, int *y) {
	int temp;   
	temp = *x;
	*x = *y;
	*y = temp;
}
void selection_sort(int array[], int array_size) {
	int i, j, min_index;

	for (i = 0; i < array_size - 1; i++) {
		min_index = i;   
		for (j = i + 1; j < array_size; j++) {
			if (array[j] < array[min_index]) { min_index = j; }
		}
		if (min_index != i)
			++c;
		swap(&array[min_index], &array[i]);   
	}
}

int main(void) {
	int array[100];
	int i; int n; cin >> n;
	for (int i = 0; i < n; i++)
		cin >> array[i];
	selection_sort(array, n);
	for (i = 0; i < n; i++) {
		if (i) {
			cout << " " << array[i];
		}
		else
			cout << array[i]
		; }
	cout << endl; cout << c << endl;
}


Measured memory_bytes: 3120
N = int(input())
problem = [int(input()) for _ in range(N)]
memo = [[-1] * (sum(problem) + 1)] * N
def dsf(i, sum):
    if i == N:
        if sum % 10 == 0:
            return 0
        else:
            return sum
    if memo[i][sum] != -1: return memo[i][sum]
    else:
        memo[i][sum] = max(dsf(i + 1, sum), dsf(i + 1, sum - problem[i]))
        return memo[i][sum]

if sum(problem) % 10 != 0:
    print(sum(problem))
else:
    print(dsf(0, sum(problem)))

Measured memory_bytes: 3064
n = int(input())
a = list(map(int, input().split()))
plus = {}  # i + A[i]
minus = {}  # i - A[i]
for i in range(n):
    try:
        plus[i + a[i]] += 1
    except:
        plus[i + a[i]] = 1
    
    if i - a[i] > 0:
        try:
            minus[i - a[i]] += 1
        except:
            minus[i - a[i]] = 1

ans = 0
for key in plus.keys() & minus.keys():
    ans += plus[key] * minus[key]
print(ans)


Measured memory_bytes: 157664
import static java.lang.System.out;
import java.util.Scanner;
import java.util.Arrays;
public class Main{
   public static void main(String[] args){
      Scanner sc = new Scanner(System.in); 
      int a = sc.nextInt();
      int b= sc.nextInt();
      int c = sc.nextInt();
      if(a==b){
         out.println(c);
      }else if(b==c){
         out.println(a);
      }else{
         out.println(b);
      }

   } 
}

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

int main() {
  ll n, m;
  cin >> n >> m;
  ll k = floor(0.5 * (floor(0.5 * m) - n));
  ll ans;
  if (k < 0) ans = m / 2;
  else ans = k + n;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3708
import java.util.*;

public class Main {
  public static void main(String[] args ) throws Exception {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B =  sc.nextInt();
    int C=sc.nextInt();
    int count= 0;
    for(int i=1;i<=C;i++){
      if(A*i<=B){
      count++;
      }
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 23124
n = int(input())
a = list(map(int, input().split()))
a_even = [i for i in a if i % 2 == 0]
flag = True
for i in a_even:
    if i % 3 == 0 or i % 5 == 0:
        pass
    else:
        flag = False
if flag:
    print("APPROVED")
else:
    print("DENIED")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

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

int main() {

    string S, T;
    cin >> S >> T;

    for (int i = 0; i < S.length(); i++) {
        if (T == (S.substr(i) + S.substr(0, i))) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    
    cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define SUM(x) accumulate(rng(x),0LL)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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; }

int dp[100050];

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

  vi list6;
  vi list9;
  int a6 = 6;
  int a9 = 9;
  while (a6 <= n) {
    list6.pb(a6);
    a6 *= 6;
  }
  while (a9 <= n) {
    list9.pb(a9);
    a9 *= 9;
  }

  rep(i,100050) dp[i] = INF;
  dp[0] = 0;
  for (int i = 0; i <= n; ++i) {
    if (dp[i] != INF) {
      chmin(dp[i+1], dp[i] + 1);
      for (auto a6 : list6) {
        if (i+a6 > n) continue;
        chmin(dp[i+a6], dp[i] + 1);
      }
      for (auto a9 : list9) {
        if (i+a9 > n) continue;
        chmin(dp[i+a9], dp[i] + 1);
      }
    }
  }

  cout << dp[n] << endl;
  return 0;
}

Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
#include <time.h>
#include <iterator>
//#include "util.h"

using namespace std;
typedef unsigned uint;
typedef long long lint;
typedef unsigned long long ulint;



//呪文
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { cout << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { cout << "{ }"; return ostr; } cout << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { cout << "{ }"; return ostr; }	cout << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { cout << "{ }"; return ostr; } cout << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
//template <typename T> void print(T* v, int N) { if (N == 0) cout << "{ }"; cout << "{" << v[0]; for (int i = 1; i < N; i++) cout << ", " << v[i]; cout << "}"; }
#define PI 3.14159265358979323846
#define EPS 1e-8
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(), (x).end()



class DisjointSet {
private:
	vector<unsigned> par;
	vector<unsigned> rank;
	size_t sz;		// 集合の個数
public:

	DisjointSet() : sz(0) { }

	DisjointSet(size_t n) :
		par(n, -1), rank(n, 0), sz(n) {
		for (size_t i = 0; i < n; i++) par[i] = i;
	}

	size_t size() { return sz; }

	void makeset() {
		par.push_back(par.size());
		rank.push_back(0);
		sz++;
	}
	void makeset(size_t n) {
		for (size_t i = 0; i < n; i++) makeset();
	}

	size_t find(size_t x) {
		if (par[x] == x)
			return x;
		else
			return par[x] = find(par[x]);
	}

	void unite(size_t x, size_t y) {
		x = find(x);
		y = find(y);
		if (x == y) return;

		if (rank[x] < rank[y])
			par[x] = y;
		else {
			par[y] = x;
			if (rank[x] == rank[y]) rank[x]++;
		}
		sz--;
	}

	bool same(size_t x, size_t y) {
		return find(x) == find(y);
	}
};

typedef pair<int, int> edge;

int problemC()
{
	int N, M;
	cin >> N >> M;

	int a, b;
	vector<edge> edges;

	for (int i = 0; i < M; i++) {
		cin >> a >> b;
		edges.push_back(edge(a - 1, b - 1));
	}

	int ans = 0;
	// i : off にする辺
	for (int i = 0; i < M; i++) {
		DisjointSet ds(N);
		for (int j = 0; j < M; j++) {
			if (i == j) continue;
			ds.unite(edges[j].first, edges[j].second);
		}
		if (ds.size() != 1) ans++;
	}

	cout << ans << endl;

	return 0;
}

int main()
{
	//clock_t start, end;
	//start = clock();

	problemC();

	//end = clock();
	//printf("%d msec.\n", end - start);

	return 0;
}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int a,b,c,d;;
	cin >> a >>b >>c >>d;
	
	if(abs(c-a) <=d){
		puts("Yes");
		return 0;
	}
	
	VI z={a,b,c};
	sort(all(z));
	
	if(z[1] - z[0] >d || z[2]-z[1] >d) puts("No");
	else puts("Yes");
	return 0;
}


Measured memory_bytes: 256
import math

[n,m] = [int(x) for x in input().split(" ")]
an = [int(x) for x in input().split(" ")]
an.sort(reverse=True)

log2_an = [math.ceil(math.log2(x) + 1) for x in an]
max_log2 = log2_an[0]
rest_ticket = m

for i in range(max_log2):
    cnt = log2_an.count(log2_an[0])
    if(cnt <= rest_ticket):
        for j in range(cnt):
            an[j] = an[j] / 2
            log2_an[j] -= 1
    else:
        for j in range(rest_ticket):
            an[j] = an[j] / 2
        break
    rest_ticket -= cnt
    an.sort(reverse=True)

discounted_an = [math.floor(x) for x in an]
print(sum(discounted_an))

Measured memory_bytes: 14252
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<algorithm>
#include<iostream>
#include<cstring>
#include<fstream>
#include<bitset>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#define INF 0X3F3F3F3F
#define N 100505
#define M 200005
#define LL long long
#define FF(i,a,b) for(int i=a;i<=b;++i)
#define RR(i,a,b) for(int i=a;i>=b;--i)
#define FJ(i,a,b) for(int i=a;i<b;++i)
#define SC(x) scanf("%d",&x)
#define SCC(x,y) scanf("%d%d",&x,&y)
#define SCCC(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define SS(x) scanf("%s",x)
#define PR(x) printf("%d\n",x)
#define CL(a, x) memset(a, x, sizeof(a))
#define _q fd[rt]
#define _l fd[rt<<1]
#define _r fd[rt<<1|1]
#define MID int mid=((l+r)>>1)
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
#define PB push_back
#define SZ size
#define PII pair<int,int>
#define PLL pair<long long,long long>
#define MP make_pair
#define IN freopen("in.txt","r",stdin)
#define OUT freopen("out.txt","w",stdout)
using namespace std;
const int MOD=1000000007;
const double PI=acos(-1.0);
const double EPS=1e-8;
int n, nx, ny;
LL x[N], y[N];
int main(){
    //IN;
    SCC(nx, ny);
    FF(i, 1, nx)scanf("%lld", &x[i]);
    FF(i, 1, ny)scanf("%lld", &y[i]);
    sort(x + 1, x + 1 + nx);
    sort(y + 1, y + 1 + ny);
    LL Y = 0;
    FF(i, 1, ny - 1){
        Y = (Y + 1LL * i * (ny - i) % MOD * (y[i + 1] - y[i])) % MOD;
    }
    LL s = 0;
    FF(i, 1, nx - 1){
        s = (s + Y * i % MOD * (nx - i) % MOD * (x[i + 1] - x[i])) % MOD;
    }
    printf("%lld\n", s);
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x) 
#define REP(i, n) for (int i = 0; i < n; ++i) 
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)

int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    int N; cin >> N;
    int f[N] = {0};
    int d = 0;
    FOR(i,0,N-1){ 
        int a; cin >> a;
        ++f[a];
        d = max(d,a);
    }
    int c = (d+1)/2;

    //cout << c << " " << d << endl;
    bool rip = 0;
    FOR(i,1,c-1) rip |= (f[i] > 0);
    FOR(i,c,d) rip |= (f[i] == 0);
    rip |= ((d&1) == 0 ? (f[c] != 1) : (f[c] != 2));

    cout << (rip ? "Impossible" : "Possible");
}



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

int main() {
    string a, b;
    cin >> a >> b;

    if (a.size() > b.size()) {
        cout << "GREATER" << endl;
        return 0;
    } else if (a.size() < b.size()) {
        cout << "LESS" << endl;
        return 0;
    } else {
        rep(i,a.size()) {
            if (a[i] > b[i]) {
                cout << "GREATER" << endl;
                return 0;
            } else if (a[i] < b[i]) {
                cout << "LESS" << endl;
                return 0;
            }
        }
    }

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


Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;
int main(){
  int n;
  int a[100];
  int out;
  scanf("%d\n",&n );
  for(int i=0;i<n;i++){
    scanf("%d\n",&a[i] );
  }
  sort(a,a+n);
   out=a[n-1]-a[0];
  printf("%d\n",out );
}


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

public class Main{
  public static void main(String[] args)throws Exception{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    try{
      String[] S = br.readLine().split(" ");
      int A = Integer.parseInt(S[0]);
      int B = Integer.parseInt(S[1]);
      int M = Integer.parseInt(S[2]);

      String[] T = br.readLine().split(" ");
      String[] U = br.readLine().split(" ");

      int[] ref= new int[A];
      int min_ref = 100000000;
      for(int i = 0; i < A; i++){
        ref[i] = Integer.parseInt(T[i]);
        min_ref = Math.min(ref[i], min_ref);
      }

      int[] mic= new int[B];
      int min_mic = 100000000;
      for(int i = 0; i < B; i++){
        mic[i] = Integer.parseInt(U[i]);
        min_mic = Math.min(mic[i], min_mic);
      }

      int min = min_ref + min_mic;

      for(int i = 0; i < M; i++){
        S = br.readLine().split(" ");
        int X = Integer.parseInt(S[0])-1;
        int Y = Integer.parseInt(S[1])-1;
        int Z = Integer.parseInt(S[2]);
        min = Math.min(min, ref[X]+mic[Y]-Z);
      }
      System.out.println(min);
    }catch(Exception e){
    }
  }
}

Measured memory_bytes: 66040
#include<stdio.h>

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

	return gcd(b%a,a);
}

int main()
{
	int n,sum=0;

	scanf("%d",&n);

	for(int a=1;a<=n;a++)
	{
		for(int b=1;b<=n;b++)
		{
			for(int c=1;c<=n;c++)
			{
				int temp_gcd=gcd(a,b);
				sum+=gcd(temp_gcd,c);
			}
		}
	}

	printf("%d",sum);

	return 0;
}


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


int main(){
	int N,K;
	cin>>N>>K;
	vector<pair<int,int>> d_t;
	
	for(int i=0;i<N;i++){
		int t,d;
		cin>>t>>d;
		d_t.push_back(make_pair(d,t));
	}
	sort(d_t.begin(),d_t.end(),greater<pair<int,int>>());
	vector<long long> ans(1,0);
	map<int,bool> mp;
	vector<pair<int,int>> NG;
	int sz = 0;
	for(int i=0;i<K;i++){
		ans[0]+=d_t[i].first;
		if(mp[d_t[i].second]){
			NG.push_back(d_t[i]);
		}
		else{
			mp[d_t[i].second]=true;
			sz++;
		}
	}

	ans[0]+=(long long)sz*sz;
	if(NG.size()==0){
		cout<<ans[0]<<endl;
		return 0;
	}
	reverse(NG.begin(),NG.end());
	int x = 0;
	for(int i=K;i<N;i++){
		if(mp[d_t[i].second]==false){
			long long a = ans[ans.size()-1];
			a+=(long long)2*sz+1;
			a-=NG[x].first;
			a+=d_t[i].first;
			ans.push_back(a);
			mp[d_t[i].second]=true;
			sz++;
			x++;
		}
		if(x==NG.size())break;
	}
	cout<<*max_element(ans.begin(),ans.end())<<endl;
	return 0;
}

Measured memory_bytes: 4468
n=int(input())
a=list(map(int,input().split()))
b=[0]*(10**5)
mod=10**9+7
for i in range(n):
    b[a[i]]+=1
if n%2==0 and a.count(0)!=0:
    print(0)
    exit()
f=1
for i in range(n-1,-1,-2):
    if i==0:
        if b[i]!=1:
            f=0
            break
    elif b[i]!=2:
        f=0
        break
if f: 
    print(2**(n//2)%mod)
else: 
    print(0)

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

int main()
{
    long long N,A[100010],ans=1,l=10000000000000000000;
    cin>>N;

    for(int i=0;i<N;i++){
        cin>>A[i];
        if(A[i]==0){
            cout<<0<<endl;
            return 0;
        }
    }

    for(int i=0;i<N;i++){
        if(1000000000000000000/ans<A[i]){
            cout<<-1<<endl;
            return 0;
        }
        ans*=A[i];
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 4400
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;

public class Main {

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

		while (true) {
			ArrayList<Integer> a = new ArrayList<>();

			String str[] = br.readLine().split(" ");
			int a0 = Integer.parseInt(str[0]);
			int l = Integer.parseInt(str[1]);

			if (a0 == 0 && l == 0)
				break;

			a.add(a0);
			boolean flag = false;
			for (int i = 0;; i++) {
				int next = getA(a.get(i), l);
				if (a.contains(next)) {
					System.out.println(a.indexOf(next) + " " + next + " " + (a.size() - a.indexOf(next)));
					break;
				}
				a.add(next);
			}
		}
	}

	static int getA(int a, int l) {
		String s = String.valueOf(a);

		while (s.length() < l)
			s = "0" + s;

		char[] num1 = s.toCharArray();
		char[] num2 = s.toCharArray();

		Arrays.sort(num1);

		for (int i = 0; i < l; i++)
			num2[i] = num1[l - 1 - i];

		int max = Integer.parseInt(String.valueOf(num2));
		int min = Integer.parseInt(String.valueOf(num1));

		return max - min;
	}
}


Measured memory_bytes: 26012
import java.util.*;

/**
 *
 */
public class Main {
    public static final int MOD = 1_000_000_007;

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

        String L = sc.next();

        System.out.println(solveEditorial(L));
    }

    /**
     * 解説のDPによる解法
     * @param L
     * @return
     */
    private static long solveEditorial(String L) {
        int N = L.length();

        // dp[i][j]: i桁まで確認, j=0: i桁が一致 / j=1: 未満であることが既に確定
        long[][] dp = new long[100002][2];
        dp[0][0] = 1;

        for (int i=0; i<N; i++) {
            // if a+b == 0
            if (L.charAt(i) == '0') {
                dp[i+1][0] = dp[i][0];
                dp[i+1][1] = dp[i][1];
            } else {
                dp[i+1][1] = (dp[i][0] + dp[i][1])%MOD;
            }

            // if a+b == 1
            if (L.charAt(i) == '0') {
                dp[i+1][1] += dp[i][1]*2 % MOD;
                dp[i+1][1] = dp[i+1][1] % MOD;
            } else {
                dp[i+1][0] += dp[i][0]*2 % MOD;
                dp[i+1][0] = dp[i+1][0] %MOD;
                dp[i+1][1] += dp[i][1]*2 % MOD;
                dp[i+1][1] = dp[i+1][1] %MOD;
            }
        }

        return (dp[N][0] + dp[N][1])%MOD;
    }
}


Measured memory_bytes: 28312
#include <stdio.h>          // printf(), scanf()
#define MAX_N 500000

typedef struct node_tbl
{
	int key;
	int parent;
	int left;
	int right;
} node;

const int nil = -1;
node t[MAX_N + 1];
int root;
int room;
int ix;

int
tree_minimum(int u)
{
	while (t[u].left != nil)
		u = t[u].left;

	return u;
}

int
find(int u, int k)
{
	while (u != nil && k != t[u].key)
	{
		if (k < t[u].key)
			u = t[u].left;
		else
			u = t[u].right;
	}

	return u;
}

int
tree_successor(int u)
{
	if (t[u].right != nil)
		return tree_minimum(t[u].right);

	int y = t[u].parent;
	while (y != nil && u == t[y].right)
	{
		u = y;
		y = t[y].parent;
	}

	return y;
}

void
delete(int z)
{
	int y; /* ????????????????±? */
	int x; /* y?????? */

	/* ??????????????????????±??????? */
	if (t[z].left == nil || t[z].right == nil)
		y = z;
	else
		y = tree_successor(z);

	/* y??????x????±??????? */
	if (t[y].left != nil)
		x = t[y].left;
	else
		x = t[y].right;

	if (x != nil)
		t[x].parent = t[y].parent;

	if (t[y].parent == nil)
		root = x;
	else
	{
		if (y == t[t[y].parent].left)
			t[t[y].parent].left = x;
		else
			t[t[y].parent].right = x;
	}

	if (y != z)
		t[z].key = t[y].key;

	t[y].right = room;
	room = y;
}

void
insert(int k)
{
	int z;

	int y = nil;
	int x = root;
	if (room == nil)
		z = ix++;
	else
	{
		z = room;
		room = t[room].right;
	}

	t[z].key = k;
	t[z].left = nil;
	t[z].right = nil;

	while (x != nil)
	{
		y = x;
		if (t[z].key < t[x].key)
			x = t[x].left;
		else
			x = t[x].right;
	}

	t[z].parent = y;
	if (y == nil)
		root = z;
	else
	{
		if (t[z].key < t[y].key)
			t[y].left = z;
		else
			t[y].right = z;
	}
}

void
inorder(int u)
{
	if (u == nil)
		return;

	inorder(t[u].left);
	printf(" %d", t[u].key);
	inorder(t[u].right);
}

void
preorder(int u)
{
	if (u == nil)
		return;

	printf(" %d", t[u].key);
	preorder(t[u].left);
	preorder(t[u].right);
}

int
main(int argc, char** argv)
{
	char command[8];
	int n;
	int x;
	int i;

	root = nil;
	room = -1;
	ix = 0;
	scanf("%d", &n);
	for (i = 0; i < n; ++i)
	{
		scanf("%s", command);
		switch (command[0])
		{
		case 'd':
			scanf("%d", &x);
			delete(find(root, x));
			break;

		case 'f':
			scanf("%d", &x);
			printf("%s\n", find(root, x) != nil ? "yes" : "no");
			break;

		case 'i':
			scanf("%d", &x);
			insert(x);
			break;

		case 'p':
		default:
			inorder(root);
			printf("\n");

			preorder(root);
			printf("\n");
			break;
		}
	}

	return 0;
}



Measured memory_bytes: 7932
n = int(input())
h = list(map(int, input().split()))

ans = 0
ans_tmp = 0
current = h[0]
for i in range(1, n):
    if current >= h[i]:
        ans_tmp += 1
    else:
        ans = max(ans, ans_tmp)
        ans_tmp = 0
    current = h[i]

ans = max(ans, ans_tmp)

print(ans)


Measured memory_bytes: 63856
/**
 * @brief AtCoder Beginner Contest 116<br>
 * B - Collatz Problem
 *
 * @see https://atcoder.jp/contests/abc116/tasks/abc116_b
 */
#include <iostream>
#include <set>
using namespace std;

int main() {
  int s;
  set<int> results;
  scanf("%d", &s);

  results.insert(s);
  for (int i{2}; i <= 1000000; ++i) {
    s = s % 2 == 0 ? s / 2 : 3 * s + 1;
    auto ret = results.insert(s);
    if (!ret.second) {
      printf("%d\n", i);
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef vector<int> vec;
typedef vector<vec> mat;
#define N 3
int po[N*N+10];
int m2i(mat m){
  int res=0;
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++)
      res+=m[i][j]*po[i*N+j];
  return res;
}
mat i2m(int x){
  mat res(N,vec(N));;
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++)
      res[i][j]=(x%po[i*N+j+1])/po[i*N+j];
  return res;
}

signed main(){
  po[0]=1;
  for(int i=0;i<N*N;i++) po[i+1]=po[i]*10;
  mat p(N,vec(N));
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++)
      cin>>p[i][j];
  mat e(p);
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++)
      e[i][j]=i*N+j+1;
  e[N-1][N-1]=0;
  int ans=m2i(e);
  //cout<<ans<<endl;
  queue<int> q;
  map<int,int> m;
  q.push(m2i(p));
  m[m2i(p)]=0;
  int ax[]={1,0,-1,0};
  int ay[]={0,1,0,-1};
  while(!q.empty()){
    int x=q.front();q.pop();
    if(x==ans) break;
    //cout<<x<<endl;
    p=i2m(x);
    int zy,zx;
    for(int i=0;i<N;i++)
      for(int j=0;j<N;j++)
	if(p[i][j]==0) zy=i,zx=j;
    //cout<<zy<<" "<<zx<<endl;
    for(int k=0;k<4;k++){
      int ny=zy+ay[k],nx=zx+ax[k];
      if(ny<0||N<=ny||nx<0||N<=nx) continue;
      swap(p[zy][zx],p[ny][nx]);
      int t=m2i(p);
      //cout<<t<<endl;
      if(!m.count(t)){
	m[t]=m[x]+1;
	q.push(t);
      }
      swap(p[zy][zx],p[ny][nx]);
    }
  }
  cout<<m[ans]<<endl;
  return 0;
}

Measured memory_bytes: 14528
l,r=list(map(int,input().split()))
f=True
C=2019
if (r-l)<2019:
    for i in range(l,r+1):
        if C==0:
            break
        for t in range(i+1,r+1):
            if t*i%2019<C:
                C=t*i%2019
                if C==0:
                    break
else:
    C=0
print(C)

Measured memory_bytes: 3060
from collections import deque

N, M = [int(x) for x in input().split()]
k = [None] * M
s = [None] * M
for i in range(M):
    lst = input().split()
    k[i] = int(lst[0])
    s[i] = [int(x) - 1 for x in lst[1:]]  # index調整
p = [int(x) for x in input().split()]

# BFS
que = deque([[]]) # 探索候補キュー
ans = 0
while len(que) > 0:
    sw = que.popleft()  # 各スイッチの状態
    if len(sw) >= N:
        all_on = True
        for i in range(M):  # 各電球がONしているか確認
            light = 0
            for j in s[i]:  # 各スイッチの値の和
                light = (light + sw[j]) % 2
            if light != p[i]:
                all_on = False
                break
        ans += int(all_on)
    else:
        que.append(sw + [0])
        que.append(sw + [1])

print(ans)

Measured memory_bytes: 3436