akhauriyash/Code-Regression huggingface dataset:
/////////////////////////////////////////
///       Please Give Me AC!!!!!      ///
/////////////////////////////////////////

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define forin(in) for(int i=0; i<(int)in.size(); i++) cin>>in[i]
#define forout(out) for(int i=0; i<(int)out.size(); i++) cout<<out[i]<<endl
#define rep(i, n) for(int i=0; i<(n); i++)

int main() {
    int x; cin>> x;
    if(x == 0) cout<< 1 << endl;
    else cout<< 0 << endl;
}

Measured memory_bytes: 3624
/*input
4
1 1 1 1

*/

#include <bits/stdc++.h>

using namespace std;

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

#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define mod 1000000007
#define PI 3.14159265
#define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define out(container) cout << #container << " "; for (auto it : container) cout << it << " "; cout << endl;

template < typename T> int sz(T x) {return x.size();}
template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
    int x = 1 % mod;
    while(b){
        if(b & 1) x = mul(x, a);
        a = mul(a, a);
        b >>= 1;
    }
    return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

bool isPrime (ll n) {
    if(n == 1) return 0;
    if(n == 2 or n == 3) return 1;
    if(n % 2 == 0 or n % 3 == 0) return 0;

    for(ll i = 5; i * i <= n; i += 6) if(n % i == 0 or n % (i + 2) == 0) return 0;
    return 1;
}


int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  vector <int> vec(3);
  cin >> vec[0] >> vec[1] >> vec[2];
  sort(all(vec));
  cout << vec[0] + vec[1] << endl;


  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long min = Integer.MAX_VALUE, max = Integer.MIN_VALUE, sum = 0;
		
		int count = sc.nextInt();
		for(int i = 0; i < count; i++) {
			long t = sc.nextLong();
			if (t > max) {
				max = t;
			}
			if (t < min) {
				min = t;
			}
			sum += t;
		}
		
		System.out.println(min + " " + max + " " + sum);
	}
}



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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> TUP;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*(y/gcd(x,y));
}

//a,b x
int main(){
	ll N; cin>>N;
	ll tmp=N;
	ll sum=0;
	for(int i=9;i>=0;i--){
		sum+=tmp/(ll)pow(10,(double)i);
		tmp%=(ll)pow(10,(double)i);
	}
	if(N%sum==0) cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 256
import heapq

D, G = map(int, input().split())

problems = []
for i in range(D):
    p, c = map(int, input().split())
    total_score = 100 * (i + 1) * p + c
    problems.append([100 * (i + 1), p, c, total_score])

counts = []
for i in range(2**D):
    Bin = str(bin(i))[2:].zfill(D)
    score = 0
    count = 0
    index = -1
    for j, c in enumerate(Bin):
        if int(c):
            score += problems[j][3]
            count += problems[j][1]
        else:
            index = j
    if score >= G:
        heapq.heappush(counts, count)
    elif index != -1:
        div, mod = divmod((G - score), problems[index][0])
        if mod != 0:
            div += 1
        if div < problems[index][1]:
            count += div
            heapq.heappush(counts, count)

print(heapq.heappop(counts))

Measured memory_bytes: 3064
import std.stdio,std.string,std.conv,std.math;

immutable MIN = -1000;
immutable MAX = 1000;

int main(string[] argv)
{
    char[] buf;
	string[] ans;
	while(stdin.readln(buf)){
		if(checkSeak(buf)){
			double[] num;
			foreach(string str;buf.to!string().chomp().split(" ")){
				num ~= str.to!double();
			}
			double x = (num[2] * num[4] - num[1] * num[5]) / (num[0] * num[4] - num[1] * num[3]);
			double y = (num[5] * num[0] - num[2] * num[3]) / (num[0] * num[4] - num[3] * num[1]);
			x = roundD(x,4);
			y = roundD(y,4);
			ans ~= format("%.3f %.3f",x,y).to!string(); 
		}
	}

	foreach(string str;ans){
		writeln(str);
	}

    return 0;
}

 

private bool checkLength(char[] c){
	if(c.split(" ").length == 6){
		return true;
	}
	return false;
}

private bool checkRange(char[] c){
	try{
		foreach(string str;c.to!string().chomp().split(" ")){
			double tmp = str.to!double();
			if (MIN <= tmp && tmp <= MAX){
			}else{
				return false;
			}
		}
	}
	catch(Exception ex){
		//writeln("Cast_Error!");
		return false;
	}

	return true;
}

private bool checkSeak(char[] c){
	if(checkLength(c)){
		//writeln("Length==>OK.");
	}else{
		return false;
	}
	if(checkRange(c)){
		//writeln("Range===>OK.");
	}else{
		return false;
	}

	return true;
}

private double roundD(double d,uint i){
	double result = round(d * pow(10,i-1))/pow(10,i-1);
	if (result == -0) {
		return 0;
	}
	return result;
}

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

vector<vector<int>> a;

ll dfs(vector<bool> used, ll from){
  used[from] = true;
  bool ok = true;
  rep(i, used.size()){
    if(!used[i]) ok = false;
  }
  if(ok)  return 1;

  ok = false;
  ll count = 0;
  rep(i, a[from].size()){
    if(!used[a[from][i]]){
      count += dfs(used, a[from][i]);
      ok = true;
    }
  }
  if(ok)  return count;
  else return 0;
}

int main(){
  int n, m;
  cin >> n >> m;
  a.resize(n);
  rep(i, m){
    int s, t;
    cin >> s >> t;
    s--;
    t--;
    a[s].push_back(t);
    a[t].push_back(s);
  }
  vector<bool> used(n, false);
  ll ans = dfs(used, 0);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
//#include <numeric>
#include <vector>
//#include <map>
#include <algorithm>
//#include <queue>

using namespace std;
#define n_max 10000
#define INF 10001000

#define rep(i, a, n) for(int i = a; i < n; i++)
#define rep2(i, a, n) for(int i = a; i <= n; i++)
#define rrep(i, a, n) for(int i = a; i > n; i--)
#define rrep2(i, a, n) for(int i = a; i >= n; i--)
#define lrep(i, a, n) for(long int i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl

int main()
{
    int ans = 0;
    int k, x;

    cin >> k >> x;

    for(int i = x-k+1; i <= x+k-1; i++) {
        cout << i << " ";
    }
    cout << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int t, x, y;
        cin >> t >> x >> y;
        int d = abs(x) + abs(y);
        if (d <= t && d % 2 == t % 2) continue;

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

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

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

int main(){
  int h, w; cin >> h >> w;
  int n; cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  vector<vector<int>> mp(h, vector<int>(w));
  int r = 0, c = 0;
  bool gr = true, gl = false;
  for(int i = 0; i < n; i++){
    while(a[i]--){
      if(gr){
        mp[r][c++] = i+1;
        if(c >= w){          
          gr = false;
          gl = true;
          r++;
          c = w-1;
        }
      }
      else if(gl){
        mp[r][c--] = i+1;
        if(c < 0){         
          gr = true;
          gl = false;
          r++;
          c = 0;
        }
      }
    }
  }
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      cout << mp[i][j] << " ";
    }
    cout << "\n";
  }   
}

Measured memory_bytes: 3664
import sys
input = lambda: sys.stdin.readline().rstrip()

N = int(input())
T, A = map(int, input().split())

H = list(map(int, input().split()))

ans = [float("inf"), -1]
for i in range(len(H)):
    if abs(T - H[i]*0.006 - A) < ans[0]:
        ans[0] = abs(T - H[i]*0.006 - A)
        ans[1] = i+1

print(ans[1])

Measured memory_bytes: 38512
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from heapq import heappop,heappush

def bfs(sx,sy,W,H):
    queue = []
    heappush(queue,(0,sx,sy))
    dxdy = [(0,1),(0,-1),(1,0),(-1,0)]
    visited = [[ 10**8 for i in range(W)] for j in range(H)]

    while queue != []:
        count,x,y = heappop(queue)
        if visited[y][x] != 10**8:
            continue
        visited[y][x] = count
        for nx,ny in dxdy:
            if 0 <= x + nx < W and 0 <= y + ny < H:
                if visited[y + ny][x + nx] == 10**8:
                    nextValue = Maze[y + ny][x + nx]
                    if ((nx,ny) == (1,0) and nextValue & 1 > 0) or ((nx,ny) == (0,1) and nextValue & 2 > 0) or ((nx,ny) == (-1,0) and Maze[y][x] & 1 > 0) or ((nx,ny) == (0,-1) and Maze[y][x] & 2 > 0 ):
                        continue
                    else:
                        heappush(queue,(count + 1,x+nx,y+ny))
    return visited

while True:
    w,h = map(int,input().split(" "))
    if h == 0 and w == 0:
        break
    Maze = [[0 for j in range(w)] for i in range(h)]
    for i in range(h-1):
        row = list(map(int,input().split()))
        for j in range(len(row)):
            if row[j] == 1:
                Maze[i][j+1] += 1
        col = list(map(int,input().split()))
        for j in range(len(col)):
            if col[j] == 1:
                Maze[i+1][j] += 2
    else:
        i += 1
        row = list(map(int,input().split()))
        for j in range(len(row)):
            if row[j] == 1:
                Maze[i][j+1] += 1

    ret = bfs(0,0,w,h)[h-1][w-1]
    print(ret + 1 if ret != 10**8 else 0) 

Measured memory_bytes: 6832
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size,n=1,init=nil) #nに配列の次元数、sizeに配列の大きさ、initに初期値を投げることでその配列を返す
  if n==1
    return Array.new(size){init}
  else
    return Array.new(n).map{Array.new(size){init}}
  end
end

def cal(x)
  return x.to_s.split("").map(&:to_i).inject(:+)
end
n,a,b=get_i
ans=0
for i in a..n
  if cal(i).between?(a,b)
    ans+=i
  end
end
puts ans

Measured memory_bytes: 3964
n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

cap = [a, b, c, d, e]

min_pos = 0
for p in range(len(cap)):
    if cap[p] < cap[min_pos]:
        min_pos = p

if n % cap[min_pos] == 0:
    print(4 + n // cap[min_pos])
else:
    print(5 + n // cap[min_pos])


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A,B,H,M;
    cin >> A >> B >> H >> M;
    double PI = acos(-1);
    double alpha = 2.0*PI*H/12+2*PI/12*M/60,beta = 2.0*PI*M/60;
    cerr << alpha << " " << beta << "\n";
    cout << fixed << setprecision(10) << sqrt(A*A+B*B-2*A*B*cos(alpha-beta)) << "\n";
}

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

using namespace std;

int main() {
	/*
	int n;
	cin >> n;
	vector<vector<int>> f(n, vector<int>(6));
	for(int j = 0; j < n; j++)
		for (int i = 0; i < 6; i++) cin >> f[j][i];

	// 相手のカードもわかる 6 + 6 + 1 = 13のため
	bool win = true;


	// 自分が出し終わるあとの数字が相手に残っている
	*/

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

	int rmin = 10000;
	int lmin = 10000;

	bool all = true;
	int r = a[0];
	for (int i = 0; i < n; i++) {
		if (r != a[i]) {
			all = false;
		}
		if (a[i] == 0) rmin = min(rmin, w[i]);
		else lmin = min(lmin, w[i]);
	}

	if (all) cout << 0 << endl;
	else cout << rmin + lmin << endl;

}


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

#define INF 1LL << 60
#define MOD 1000000007;
#define pb push_back

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPR(i, b, e) for (int i = (b); i <= (e); i++)
#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUGA(a) cout << #a << ": " << endl; for (const auto& v: (a)) cout << v << endl

int N, K;

int main() {
    cin.tie(0);
    cin >> N >> K;

    cout << N - K + 1 << endl;

    return 0;
}


Measured memory_bytes: 256
N = int(input())
L = list(map(int, input().split()))

L.sort()
# print(input_L.sort())
length = len(L)
count = 0

# print(L)
if N <= 2:
    print("0")

else:
    for i in range(0, length - 2):
        for j in range(i + 1, length - 1):
            for k in range(j + 1, length):
                if (L[i] + L[j] > L[k] and L[i] != L[j] and L[j] != L[k] and L[k] != L[i]):
                    # print(i, j, k)
                    count += 1

    print(count)


Measured memory_bytes: 9192
number = 4
fare = [int(input()) for a in range(number)]

fare_min = 0

fare_0_0 = fare[0] + fare[2] #A + C
fare_0_1 = fare[0] + fare[3] #A + D
fare_1_0 = fare[1] + fare[2] #B + C
fare_1_1 = fare[1] + fare[3] #B + D

if fare_min < fare_0_0:
    fare_min = fare_0_0
if fare_min > fare_0_1:
    fare_min = fare_0_1
if fare_min > fare_1_0:
    fare_min = fare_1_0
if fare_min > fare_1_1:
    fare_min = fare_1_1
print(fare_min)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    if(k % 2 == 0){
        cout << a - b << endl;
    }else{
        cout << b - a << endl;
    }
    
}

Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>

using namespace std;

vector<pair<int,int>> bridges;
vector<int> graph[100000];
int ord[100000],low[100000];
bool visited[100000];

int visit_time = 0;

void dfs(int v,int p){
  visited[v] = true;
  ord[v] = visit_time;
  low[v] = ord[v];
  visit_time++;
  for(int i=0;i<graph[v].size();++i){
    if(!visited[graph[v][i]]){
      dfs(graph[v][i],v);
      low[v] = min(low[v],low[graph[v][i]]);
      if(ord[v] < low[graph[v][i]]){
        int s = v, t = graph[v][i];
        if(s > t) swap(s,t);
        bridges.emplace_back(s,t);
      }
    }else if(graph[v][i]!=p){
      low[v] = min(low[v],ord[graph[v][i]]);
    }
  }

}

int main(){
  int N , M ;
  cin >> N >> M;
  for(int i=0;i<M;++i){
    int s,t;
    cin >> s >> t;
    graph[s].push_back(t);   
    graph[t].push_back(s);
  }
  
  for(int i=0;i<N;++i){
    if(!visited[i]) dfs(i,-1);
  }
  
  sort(bridges.begin(),bridges.end());
  for(const auto &b:bridges){
    cout << b.first << " " << b.second << endl;
  }
  return 0;
}

Measured memory_bytes: 6988
/*
　　　　　　 ＿＿
　　　　　／＞　　 フ
　　　　　|   _　 _l  
　 　　　／` ミ＿x ノ   Zzz..
　　 　 /　 　 　 |   コード見ちゃだめ！！
　　　 /　 ヽ　　  ﾉ
　 　 │　　|　|  |   
　／￣|　　 |　|  |
　| (￣ヽ＿_ヽ_)_ _)
　＼二つ
*/

#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) reverse((a).begin(),(a).end())
#define REP(i, n) for(int i = 0; i < n; i++)
const int MOD = 1e9+7;
typedef long long ll;


int main(){
    int a,b;
    cin>>a>>b;
    int now=1;
    if(a>0 && b>0) cout<<"Positive"<<endl;
    else if(a<=0 && b>=0) cout<<"Zero"<<endl;
    else if(a>=0 &&b<=0) cout<<"Zero"<<endl;
    else if((a-b)%2==0) cout<<"Negative"<<endl;
    else cout<<"Positive"<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<map>
using namespace std;
map<int,int>m;
int n,k;
int main()
{
    while(scanf("%d%d",&n,&k)!=EOF){
        m.clear();
        for(int i=0;i<k;i++){
            int x;
            scanf("%d",&x);
            m[x]++;
        }
        for(int i=n;i<1000000;i++){
            int x=i;
            bool flag=true;
            while(x){
                if(m[x%10]){
                    flag=false;
                    break;
                }
                x/=10;
            }
            if(flag){
                printf("%d\n",i);
                break;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	
	
	int a=0,b=0,maio=0;

	scanf("%i %i",&a,&b);

	maio = a + (a - 1);

	if(maio < b + b - 1){
		maio = b + (b - 1);
	}
	if(maio < a + b){
		maio = a + b; 
	}

	printf("%i\n",maio);

	return 0; 
}

Measured memory_bytes: 128
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

public class Main {

    void run() {
        Scanner sc = new Scanner(System.in);
        HashSet<Integer> sqs = new HashSet<>();
        for (int i = 1; i <= 1000; i++) {
            sqs.add(i * i);
        }

        int n = sc.nextInt(), d = sc.nextInt();
        int[][] ins = new int[n][d];

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                ins[i][j] = sc.nextInt();
            }
        }

        int ans = 0;
        for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) {
            int sum = 0;
            for (int k = 0; k < d; k++) {
                sum += (ins[i][k] - ins[j][k]) * (ins[i][k] - ins[j][k]);
            }
            if (sqs.contains(sum))ans++;
        }
        System.out.println(ans);
    }

    void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }

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


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define endl '\n'
#define all(v) (v).begin(),(v).end()
#define int long long
#define P pair<int,int>

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);

    int a,b,c;
    cin >> a >> b >> c;

    int x = a;
    int y = b;
    int z = c;

    int cnt = 0;
    bool flag = false;
    while(true){
        int x1 = x, y1 = y, z1 = z;
        if((x % 2) or (y % 2) or (z % 2)) break;
        x = (y1 / 2) + (z1 / 2);
        y = (x1 / 2) + (z1 / 2);
        z = (x1 / 2) + (y1 / 2);
        cnt++;
        if(x == a and y == b and z == c) {
            flag = true;
            break;
        }
    }
    if(flag) cout << -1 << endl;
    else cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdio>

using namespace std;
int a,b,c;
int main(){
	cin>>a>>b>>c;
	if((a*100+b*10+c)%4==0)cout<<"YES";
	else cout<<"NO";
	return 0;
}

Measured memory_bytes: 256
N, K, Q = [int(x) for x in input().split()]

seikai = [0] * N

for _ in range(Q):
    a = int(input())
    seikai[a-1] += 1

for i in range(N):
    if K - (Q - seikai[i]) > 0:
        print("Yes")
    else:
        print("No")


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair

int n;
ll res = 1, a;

void solve()
{
	cin >> n;
	bool checkzero = false;
	for (size_t i = 0; i < n; i++)
	{
		cin >> a;
		if (!checkzero)
		{
			if (log10(a) + log10(res) > 18)
			{
				res = -1;
				checkzero = true;
			} else {
				res *= a;
				if (res > 1000000000000000000)
				{
					res = -1;
					checkzero = true;
				}
			}
		}
		else
		{
			if (a == 0)
			{
				res = 0;
				return;
			}
		}
	}
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	solve();
	cout << res << endl;
}

Measured memory_bytes: 3956
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

int solve(int k) {
	vector<int> v(k, 0);
	int p = 7;
	int res = 1;
	while (true) {
		int t = p % k;
		if (t == 0) {
			return res;
		}
		if (v[t]) {
			return -1;
		}
		v[t]++;
		p = t * 10 + 7;
		res++;
	}
}

int main() {
	int k;
	cin >> k;
	cout << solve(k) << endl;
}

Measured memory_bytes: 7188
#include <bits/stdc++.h>
using namespace std;
#define all(n) begin(n), end(n)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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 (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    ll N, K;
    const int D = 45;
    cin >> N >> K;
    vector<ll> A(N);
    vector<bitset<D>> B(N);
    for (size_t i = 0; i < N; i++)
    {
        cin >> A[i];
        B[i] = A[i];
    }
    vll C(D);
    for (size_t i = 0; i < N; i++)
    {
        for (size_t j = 0; j < D; j++)
        {
            if (B[i][j])
                C[j]++;
        }
    }
    ll ans = 0, mul = 1, now = 0;
    for (size_t i = 0; i < D-1; i++)
    {
        mul *= 2;
    }

    for (int i = D - 1; i >= 0; i--)
    {
        if (now + mul > K)
        {

            ans += mul * C[i];
                        mul/=2;
             continue;
        }
           
        if (C[i] < N - C[i] and now + mul <= K) //1のやつが0より少ない、つまり1にしたほうが嬉しいやつ
        {
            now += mul;
            ans += mul * (N - C[i]);
        }
        else
        {
            ans += mul * C[i];
        }

        mul /= 2;
    }

    cout << max(ans, accumulate(all(A), 0LL));
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
using namespace __gnu_pbds;  
using namespace std;

typedef tree<long long, null_type, less<long long>, rb_tree_tag, 
             tree_order_statistics_node_update> 
    new_data_set; 
    
//defines
typedef long long ll;
typedef long double ld;

ll a,b,c,n,m,k;

ll t=1;

void solve()
{
    string s;
   cin>>s;
   c=0;
   for(ll i=0;i<3;i++)
   {
       if(s[i]=='R')c++;
       else if(s[i]=='S' and c>0)break;
   }
   cout<<c;
 if(t>0)cout<<"\n";
}



int32_t main()
{
#ifdef ONPC
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  //cin>>t;
    while(t--)
    {
        solve();
    }
  //cout<<sum;
        
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll n; cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    set<ll> st(a.begin(), a.end());
    if (a.size() == st.size()) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

int v[3005][3005];
long long dp[3005][3005][4];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int r, c, k;
    cin >> r >> c >> k;
    for (int i=0; i<k; i++) {
        int ri, ci, vi;
        cin >> ri >> ci >> vi;
        ri--, ci--;
        v[ri][ci] = vi;
    }

    dp[0][0][1] = v[0][0];
    for (int i=0; i<r; i++)
        for (int j=0; j<c; j++)
            for (int k=0; k<4; k++) {
                dp[i][j+1][k] = max(dp[i][j+1][k], dp[i][j][k]);
                if (k < 3) dp[i][j+1][k+1] = max(dp[i][j+1][k+1], dp[i][j][k] + v[i][j+1]);
                dp[i+1][j][0] = max(dp[i+1][j][0], dp[i][j][k]);
                dp[i+1][j][1] = max(dp[i+1][j][1], dp[i][j][k] + v[i+1][j]);
            }
    cout << *max_element(dp[r-1][c-1], dp[r-1][c-1] + 4) << "\n";

    return 0;
}


Measured memory_bytes: 320508
#include <bits/stdc++.h>
using namespace std;
long long solve() {
  int n,w;
  cin>>n>>w;
  long long wt[n], val[n];
  for(int i = 0; i<n; ++i) {
    cin>>wt[i]>>val[i];
    // cout<<wt[i]<<" "<<val[i]<<endl;
  }
  long long dp[w+1][n+1];
  for(int i = 0; i<=n; ++i) {
    dp[0][i] = 0;
  }
  for(int i = 0; i<=w; ++i) {
    dp[i][0] = 0;
  }
  for(int i = 1; i<=w; ++i) {
    for(int j = 1; j<=n; ++j) {
      dp[i][j] = i-wt[j-1]>=0 ? max(val[j-1]+dp[i-wt[j-1]][j-1], dp[i][j-1]) : dp[i][j-1];
    }
  }
  return dp[w][n];
} 
int main() {
  cout<<solve()<<endl;
  return 0;
}

Measured memory_bytes: 82424
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int main(){
  
    ll a,b,c;
    cin>>a>>b>>c;
    if(a+b>=c){
        cout<<b+c<<endl;
    }else {
        ll ans=2*b+(c-b>=a?a+1:c-b);
        
        cout<<ans<<endl;
    }
 
    
  
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <math.h>
#include <array>
#include <list>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef tuple<ll,ll,ll> tup;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> P;
int prerank[100005];
vector<ll> uncom;
struct UnionFind
{
  vector<ll> par;
  vector<ll> rank;
  vector<ll> size;
  UnionFind(int N) : par(N)
  {
    par.resize(N);
    rank.resize(N);
    size.resize(N);
    for(int i=0;i<N;i++) par[i]=i,rank[i]=0,size[i]=1;
  }
  int root(int x)
  {
    if(par[x]==x) return par[x];
    return par[x]=root(par[x]);
  }
  void unite(int x,int y)
  {
    int rx=root(x);
    int ry=root(y);
    if(rx==ry) return;
    if(rank[rx]<rank[ry])swap(rx,ry);
    if(rank[rx]==rank[ry]) rank[rx]++;
    par[ry]=rx;
    size[rx]+=size[ry];
    return;
  }
  bool same(int x,int y)
  {
    int rx=root(x);
    int ry=root(y);
    return rx==ry;
  }
  int retrank(int x)
  {
    return rank[x];
  }
  int retsize(int x)
  {
    int rootx=root(x);
    return size[rootx];
  }
};
int main(void)
{
  ll N,M;
  memset(prerank,0,sizeof(prerank));
  cin >> N >> M;
  UnionFind uf(N);
  vector<pair<ll,ll> > bridges;
  for(int i=0;i<M;i++)
    {
      ll a,b;
      cin >> a >> b;
      a--,b--;
      bridges.push_back(P(a,b));
    }
  reverse(bridges.begin(),bridges.end());
  uncom.push_back(N*(N-1)/2);
  ll tmp=N*(N-1)/2;
  for(int i=0;i<M-1;i++)
    {
      if(uf.root(bridges[i].first)!=uf.root(bridges[i].second))
	{
	  tmp-=((uf.retsize(bridges[i].first))*(uf.retsize(bridges[i].second)));
	  uf.unite(bridges[i].first,bridges[i].second);
	}
      else
	{
	  uf.unite(bridges[i].first,bridges[i].second);
	}
      uncom.push_back(tmp);
    }		      //prerank[i]=uf.retrank(bridges[i].first);
       	      
  reverse(uncom.begin(),uncom.end());
  for(int i=0;i<M;i++)
    {
      cout << uncom[i] << endl;
    }
  return 0;
}



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

static const int MAX = 10000;
static const int NIL = -1;

struct Node{
    int p, l, r;
};

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u, int d){
    if(u == NIL) return;
    D[u] = d;
    setDepth(T[u].l, d+1);
    setDepth(T[u].r, d+1);
}

int setHeight(int u){
    int h1=0, h2=0;
    if(T[u].l != NIL) h1 = setHeight(T[u].l) + 1;
    if(T[u].r != NIL) h2 = setHeight(T[u].r) + 1;

    return H[u] = max(h1, h2);
}

int getSibling(int u){
    if(T[u].p == NIL) return NIL;
    if(T[T[u].p].l != u && T[T[u].p].l != NIL) return T[T[u].p].l;
    if(T[T[u].p].r != u && T[T[u].p].r != NIL) return T[T[u].p].r;
    return NIL;
}

void print(int u){
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].p << ", ";
    cout << "sibling = " << getSibling(u) << ", ";
    int deg = 0;
    if(T[u].l != NIL) ++deg;
    if(T[u].r != NIL) ++deg;
    cout << "degree = " << deg << ", ";
    cout << "depth = " << D[u] << ", ";
    cout << "height = " << H[u] << ", ";

    if(T[u].p == NIL){
        cout << "root" << endl;
    }else if(T[u].l == NIL && T[u].r == NIL){
        cout << "leaf" << endl;
    }else{
        cout << "internal node" << endl;
    }
}

int main(){
    cin >> n;

    for(int i=0; i<n; ++i) T[i].p = NIL;

    int v, l, r;
    for(int i=0; i<n; ++i){
        cin >> v >> l >> r;
        T[v].l = l;
        T[v].r = r;
        if(l != NIL) T[l].p = v;
        if(r != NIL) T[r].p = v;
    }

    int root;
    for(int i=0; i<n; ++i) if(T[i].p == NIL) root = i;

    setDepth(root, 0);
    setHeight(root);

    for(int i=0; i<n; ++i) print(i);
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,n;
  cin>>a>>b>>n;
  for(int i=0;i<=a;i++){
    for(int j=0;j<=b;j++){
      if(n==a*b-i*j-(a-i)*(b-j)){
        cout<<"Yes";
        return 0;
      }
    }
  }
  cout<<"No";
}

Measured memory_bytes: 256
//defalt
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
typedef pair<int, int> P_i;
typedef pair<double,double> P_d;
#define rep(i,n) for(int i=0;i<(n);++i)
#define alrep(i,j,n) for(int i=0;i<(n);++i)for(int j=i+1;j<(n);++j)
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
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; }
const int MOD=1e9+7;
const long long INF = 1LL << 60;

signed main(){
  int N;
  string s1,s2;
  cin >> N >> s1 >> s2;
  stringstream ss;
  rep(i,N){
    ss << s1[i] << s2[i];
  }
  cout << ss.str() << endl;
  return 0;
}


Measured memory_bytes: 256
H, W = gets.split.map(&:to_i)
ary = H.times.map{gets.chomp.chars}
ret = Array.new(H).map{Array.new(W, 0)}
H.times do |i|
    W.times do |j|
        if ary[i][j] == '#'
            ret[i][j] = '#'
        else
            cnt = 0
            cnt += 1 if i > 0 && j > 0     && ary[i-1][j-1] == '#'  
            cnt += 1 if i > 0              && ary[i-1][j-0] == '#'  
            cnt += 1 if i > 0 && j < W-1   && ary[i-1][j+1] == '#'  
            cnt += 1 if j > 0              && ary[i-0][j-1] == '#'  
            cnt += 1 if j < W-1            && ary[i-0][j+1] == '#'  
            cnt += 1 if i < H-1 && j > 0   && ary[i+1][j-1] == '#'  
            cnt += 1 if i < H-1            && ary[i+1][j-0] == '#'  
            cnt += 1 if i < H-1 && j < W-1 && ary[i+1][j+1] == '#'  
            ret[i][j] = cnt
        end
    end
end
ret.each do |line|
    puts line.join
end

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

int n, m;
const int maxn = 1e5 + 10;
vector<int> g[maxn];
vector<pair<int, int>> e;

bool v[maxn], ve[maxn];
int rev[maxn];

int dfs(int x) {
  v[x] = true;
  int r = 0;
  for (int t : g[x]) {
    if (ve[t]) {
      continue;
    }
    ve[t] = true;
    r ^= 1;
    auto edge = e[t];
    if (x == edge.second) rev[t] = 1;
    int y = x == edge.first ? edge.second : edge.first;
    if (v[y]) {
      continue;
    }
    if (dfs(y)) {
      r ^= 1;
      rev[t] ^= 1;
    }
  }
  return r;
}


int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0, u, v; i < m ; ++i) {
    scanf("%d%d", &u, &v);
    g[u].push_back(e.size());
    g[v].push_back(e.size());
    e.emplace_back(u, v);
  }
  if (dfs(1)) {
    puts("-1");
    return 0;
  }
  for (int i = 0; i < m; ++i) {
    if (rev[i])
      swap(e[i].first, e[i].second);
    printf("%d %d\n", e[i].first, e[i].second);
  }

  return 0;
}



Measured memory_bytes: 14452
#include<stdio.h>
#include<math.h>
#define pi 3.14159265358979

int main(void){
    double A,B,H,M,rad;
    scanf("%lf %lf %lf %lf",&A,&B,&H,&M);
    rad=H*pi/6+M*pi/360-M*pi/30;
    double ans=sqrt(A*A+B*B-2*A*B*cos(rad));
    printf("%.9lf\n",ans);
    return 0;
}

Measured memory_bytes: 2604
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int r,c,s;
int a[10][10];
bool ok = false;

void dfs(int d){
    if(d == -1) return;
    bool found = false;

    // printf(" ----d %d\n",d);
    // rep(i,r){
    //     rep(j,c) printf(" %d",a[i][j]);
    //     printf("\n");
    // }

    rep(i,r){
        rep(j,c){
            int z = 0;
            for(int k=j; k<c; ++k){
                z += a[i][k];
                if(z>s) found = true;
            }
        }

        if(found){
            rep(j,c){
                a[i][j] = -a[i][j];
                dfs(d-1);
                a[i][j] = -a[i][j];
            }
            break;
        }
    }

    if(!found){
        rep(i,c){
            rep(j,r){
                int z = 0;
                for(int k=j; k<r; ++k){
                    z += a[k][i];
                    if(z>s) found = true;
                }
            }

            if(found){
                rep(j,r){
                    a[j][i] = -a[j][i];
                    dfs(d-1);
                    a[j][i] = -a[j][i];
                }
                break;
            }
        }
    }

    if(!found) ok = true;
}

int main(){
    int K;
    cin >>r >>c >>K >>s;
    rep(i,r)rep(j,c) cin >>a[i][j];

    dfs(K);
    cout << (ok?"Yes":"No") << endl;
    return 0;
}



Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

int N, W;
vi M, V;
vector<vl> dp;

void input_init(void) {
	cin >> N >> W;
	M.resize(N);
	V.resize(N);
	for (int i = 0; i < N; ++i)
		cin >> M[i] >> V[i];
	dp.resize(N, vl(W + 1, (ll)0));
}

void solve(void) {
	dp[0][M[0]] = (ll)V[0];
	for (int i = 1; i < N; ++i) {
		for (int j = 0; j <= W; ++j) {
			// i を選ばない
			dp[i][j] = max(dp[i][j], dp[i - 1][j]);
			// i を選ぶ
			if (j + M[i] <= W) {
				ll val = dp[i - 1][j] + (ll)V[i];
				dp[i][j + M[i]] = max(val, dp[i][j + M[i]]);
			}
		}
	}
}

int main(void) {
	input_init();
	solve();
	ll ans = (ll)0;
	for (int i = 0; i <= W; ++i)
		ans = max(dp[N - 1][i], ans);
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 79488
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; 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 VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

ll mod = 1e9+7;

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

    ll n; // ll : long long の省略. ↑で定義
    cin >> n;

    vll a(n); // vll : vector<ll> の省略.
    REP(i, n){
        cin >> a[i]; // vector の要素へのアクセスは at 関数を使わなくても大カッコでいける.
    }

    VSORTR(a); // VSORTR(v) : sort(v.rbegin(), v.rend()) の省略. これで降順ソートは一発.

    ll sumA = 0, sumB = 0; // Alice と Bob が獲得する点数.

    // 今, a には数字が大きい方から順に並んでおり, これを Alice と Bob が頭から順番に取っていく.
    // →→→偶奇で場合分けするとよい！
    REP(i, n){
        if(i % 2 == 0) sumA += a[i]; // i = 0, 2, 4, ... のとき Alice が獲得する.
        else sumB += a[i]; // i = 1, 3, 5, ... のとき Bob が獲得する.
    }
    cout << sumA - sumB << endl;
    return 0;
}

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

int main()
{
  int H, W;
  cin >> H >> W;
  char S[H][W];
  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W; j++)
    {
      cin >> S[i][j];
    }
  }

  int maxcnt = 0;
  int temp;

  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W; j++)
    {
      if (S[i][j] == '#')
        continue;
      temp = 1;
      for (int ii = i - 1; ii >= 0; ii--)
      {
        if (S[ii][j] == '#')
          break;
        temp++;
      }
      for (int ii = i + 1; ii <= H - 1; ii++)
      {
        if (S[ii][j] == '#')
          break;
        temp++;
      }
      for (int jj = j - 1; jj >= 0; jj--)
      {
        if (S[i][jj] == '#')
          break;
        temp++;
      }
      for (int jj = j + 1; jj <= W - 1; jj++)
      {
        if (S[i][jj] == '#')
          break;
        temp++;
      }
      maxcnt = max(maxcnt, temp);
      if (maxcnt == W + H - 1)
        break;
    }
  }
  cout << maxcnt << endl;
}

Measured memory_bytes: 4096
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class DTriangles {
public:
    static constexpr int kStressIterations = 0;

    static void generateTest(std::ostream& test) {
    }

    void solve(std::istream& cin, std::ostream& cout) {
        int n;
        cin >> n;
        vector<int> l(n);

        REP(i, n) {
            cin >> l[i];
        }
        sort(l.begin(), l.end());

        int res = 0;
        REP(i, n - 2) {
            FOR(j, i + 1, n - 2) {
                int x = l[i] - l[j];
                int v = l[i] + l[j];
                int pos1 = upper_bound(l.begin(), l.end(), x) - l.begin();
                int pos2 = lower_bound(l.begin(), l.end(), v) - l.begin();
                int num = pos2 - max(pos1, j + 1);
                if (num < 0) continue;
                res += num;
            }
        }
        cout << res << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    DTriangles solver;
    solver.solve(in, out);
    return 0;
}


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

using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vvvd = vector<vector<vector<double>>>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pint = pair<int, int>;
using Graph = vvi;

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

bool cmp(pint a, pint b) {return a.second < b.second;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int m;

ll solve(string n) {
    int L = n.size();

    vvvll dp(L + 1, vector<vector<ll>>(2, vector<ll>(L + 1, 0)));
    dp[0][0][0] = 1;

    for(int i = 0; i < L; i++) {
        int D = n[i] - '0';
        for(int j = 0; j < 2; j++) {
            for(int k = 0; k < L; k++) {

                for(int d = 0; d <= (j ? 9 : D); d++) {
                    if(d != 0) {
                        dp[i+1][j || (d < D)][k + 1] += dp[i][j][k];
                    } else {
                        dp[i+1][j || (d < D)][k] += dp[i][j][k];
                    }
                }

            }
        }
    }

    return dp[L][0][m] + dp[L][1][m];
}

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

    cout << solve(n) << endl;

    return 0;
}

Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using u64 = uint_fast64_t;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; }
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; }
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() { cout << "\n"; }
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll N,E,T; cin >> N >> E >> T;
    vector<ll> x(N+1);
    rep(i,N) cin >> x[i+1];

    vector<ll> dp(N+1);
    int cur = 0;
    ll val = 1e18;
    for (int i = 1; i <= N; i++) {
        while (cur < i-1 and T < (x[i]-x[cur+1])*2) {
            chmin(val,dp[cur]-x[cur+1]*2);
            cur++;
        }
        dp[i] = min(val+x[i]*2,dp[cur]+T);
    }

    cout << dp[N]+E << ln;
}


Measured memory_bytes: 4752
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  cin >> s >> t;
  int count=0;
  if(s.size()+1==t.size()){
    for(int i=0;i<s.size();i++){
      if(s.at(i)==t.at(i))count++;
      if(count==s.size()){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 3624
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()

    def f(n):
        if n < 4:
            return n
        return (n-1) % 3 + f((n-1)//3-1) + 2

    return f(n)


print(main())





Measured memory_bytes: 9040
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n; cin >> n;
  vector<int> a(n),p(n),q(n);
  for(int i = 0; i < n; i++){
    a.at(i) = i+1;
    cin >> p.at(i);
  }
  for(int i = 0; i < n; i++)
    cin >> q.at(i);
  if(p == q){
    cout << 0;
    return 0;
  }
  int x = 0,y = 0;
  int i = 1;
  do{
    if(a == p) x =i;
    else if(a == q) y = i;
    i++;
  }while(next_permutation(a.begin(),a.end()));
  cout << abs(x - y);
}

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

double solve(vector<vector<double>>&dp,double* p, int n, int m){
    int i,j;
    for(i=1;i<=n;i++){
        for(j=1;j<=m;j++){
            dp[i][j] = (p[i-1])*dp[i-1][j-1] + (1-p[i-1])*dp[i-1][j];
        }
    }
    return dp[n][m];
}

int main() {
	int n;
	cin>>n;
	double p[n];
	int i,j;
	for(i=0;i<n;i++)cin>>p[i];
	
	vector<vector<double>> dp;
	int m = (n/2)+1;
	for(i=0;i<=n;i++){
	    vector<double> v;
	    for(j=0;j<=m;j++){
	        v.push_back(0);
	    }
	    dp.push_back(v);
	}
	
	dp[0][0] = 1;
	
	for(i=1;i<=n;i++){
	    dp[i][0] = 1;
	}
	
	for(j=1;j<=m;j++){
	    dp[0][j] = 0;
	}
	
// 	for(auto x:dp){
// 	    for(auto y:x){
// 	        cout<<y<<" ";
// 	    }
// 	    cout<<endl;
// 	}
//     cout<<endl;
	
	cout<<fixed<<setprecision(10)<<solve(dp,p,n,m)<<endl;
	
// 	cout<<endl;
	
// 	for(auto x:dp){
// 	    for(auto y:x){
// 	        cout<<y<<" ";
// 	    }
// 	    cout<<endl;
// 	}
//     cout<<endl;
	
	return 0;
}


Measured memory_bytes: 35584