akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef priority_queue<int> pqi;
typedef priority_queue<ll> pqll;
typedef priority_queue<vi> pqvi;
typedef priority_queue<vll> pqvll;
typedef priority_queue<int, vi, greater<int>> pqi_G;
typedef priority_queue<ll, vll, greater<ll>> pqll_G;
typedef priority_queue<vi, vvi, greater<vi>> pqvi_G;
typedef priority_queue<vll, vvll, greater<vll>> pqvll_G;

string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << -1 << endl;}

int main() {
  string s;
  cin >> s;
  int cnt = 0;
  for (int i = 0; i < 4; i++) {
    if (s.at(i) == '+') cnt++;
    else cnt--;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef  long long  ll;
typedef long double db;
#define pb push_back
#define mp make_pair
#define ub(v,val) upper_bound(v.begin(),v.end(),val)-v.begin()
#define lb(v,val) lower_bound(v.begin(),v.end(),val)-v.begin()
#define sortv(vec) sort(vec.begin(),vec.end())
#define rev(p) reverse(p.begin(),p.end());
#define v vector
#define PI 3.1415926535
#define len length()
#define repc(i,s,e) for(ll i=s;i<e;i++)
#define fi first
#define se second
#define mset(a,val) memset(a,val,sizeof(a));
#define mt make_tuple
#define repr(i,n) for( i=n-1;i>=0;i--)
#define rep(i,n) for( i=0;i<n;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int M = 1e9 + 7;
int INF = 1e6;




int main() {
	// your code goes here
	IOS;

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll i, j, t, k, x, y, z,  N;
	ll n, m;
	cin >> n >> k;
	ll a[n];
	rep(i, n) cin >> a[i];
	for (i = 1; i < n - k + 1; i++) {
		db prod2 = db(a[i - 1 + k] ) / db(a[i - 1]);
		if (prod2 > 1)
			cout << "Yes\n";
		else cout << "No\n";


	}



	return 0;
}

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

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 [int(x) for x in sys.stdin.readline().split()]
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 main():
    n = I()
    a = LI()

    r = []
    while a:
        l = len(a)
        nf = False
        for i in range(l-1,-1,-1):
            if a[i] == i+1:
                r.append(i+1)
                a = a[:i] + a[i+1:]
                nf = True
                break
        if not nf:
            return -1

    return '\n'.join(map(str, r[::-1]))


print(main())




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

int main()
{
  int64_t N,D,x,y,ret=0;
  cin>>N>>D;
  for(int i=0;i<N;i++)
  {
      cin>>x>>y;
      if(x*x+y*y<=D*D)
      ret++;
  }
  cout<<ret<<endl;
    return 0;
}


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

#define all(x)  x.begin(), x.end()
#define mp      make_pair

static const int INF = 0x3f3f3f3f;

int solve(string a, string b) {
        int n = a.size();
        int left = 0, right = 0;
        for (int i = 0; i < n; i ++) {
                if (b[i] == '0') left ++;
                else break;
        }
        for (int i = n - 1; i >= 0; i --) {
                if (b[i] == '0') right ++;
                else break;
        }
        vector<int> one;
        for (int i = 0; i < n; i ++) if (b[i] == '1') one.push_back(i);
        int op = 0;
        vector<pair<int, int>> dis(n);
        for (int i = 0; i < n; i ++) {
                if (one[op] == i) { 
                        dis[i] = mp(0, 0);
                        op ++;
                } else if (op == 0) dis[i] = mp(i + 1 + right, one[op] - i);
                else if (op == one.size()) dis[i] = mp(i - one[op - 1], n - i + left);
                else dis[i] = mp(i - one[op - 1], one[op] - i);
        }
        int ans = INF;
        for (int shift = 0; shift <= n; shift ++) {
                int flip_cnt = 0;
                vector<bool> flip(n, false);
                for (int i = 0; i < n; i ++) {
                        if (a[i] != b[(i - shift + n) % n]) {
                                flip_cnt ++;
                                flip[i] = true;
                        }
                }
                vector<pair<int, int>> dis_modified;
                for (int i = 0; i < n; i ++) if (flip[i]) { 
                        dis_modified.emplace_back(max(dis[i].first - shift, 0), dis[i].second);
                }
                sort(all(dis_modified));
                reverse(all(dis_modified));
                int sum = INF;
                int ma = 0;
                for (int i = 0; i < dis_modified.size(); i ++) {
                        sum = min(sum, dis_modified[i].first + ma);
                        ma = max(ma, dis_modified[i].second);
                }
                sum = min(sum, ma);
                int res = shift + flip_cnt + 2 * sum;
                ans = min(ans, res);
        }
        return ans;
}
int main() {
        string a, b;
        cin >> a >> b;
        int n = a.size();
        if (b == string(n, '0')) {
                cout << (a == string(n, '0') ? 0 : -1) << endl;
                return 0;
        }
        int ans = solve(a, b);
        reverse(all(a));
        reverse(all(b));
        ans = min(ans, solve(a, b));
        cout << ans << endl;
        return 0;
}


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

int main() {
    int a;
    int Min = 10;
    int ans = 0;
    for (int i = 0; i < 5; i++)
    {
        cin >> a;
        if(a%10 != 0){
            Min = min(Min,a%10);
            a += 10-a%10;
        }
        ans += a;
    }
    if(Min!=10) ans += Min-10;
    cout << ans << endl;
}
    

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
	int i;
	char s[10000];
	scanf("%s",s);
	for (i=0;i<strlen(s);i++) {
		if (s[i]=='A'&&s[i+1]=='C') {
			printf("Yes\n");return 0;
		}
	}
	printf("No\n");return 0;
} 

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main()
{
	int n,m,k,d,pd[105]={0};
	cin>>n>>k;
	for (int i=1;i<=k;i++)
	{
		cin>>m;
		for(int j=1;j<=m;j++)
		{
			cin>>d;
			pd[d] = 1;
		}
	}
	int sum=0;
	for (int i=1;i<=n;i++)
	{
		if (pd[i]==0) sum++;
	}
	cout<<sum;
 } 

Measured memory_bytes: 3596
def eval(x)
  v = 0
  has3 = has5 = has7 = false
  for i in 0...x.size
    t = x[i]
    if t == 3
      has3 = true
    elsif t == 5
      has5 = true
    elsif t == 7
      has7 = true
    end
    v += t * (10**i)
  end
  return ((v <= $n && has3 && has5 && has7) ? 1 : 0)
end

$n = gets.to_i
a = [0,3,5,7]
r = 0
for d0 in a
  next if d0 == 0
  for d1 in a
    next if d1 == 0
    for d2 in a
      next if d2 == 0
      for d3 in a
        if d3 == 0
          r += eval([d0,d1,d2])
        else
          for d4 in a
            if d4 == 0
              r += eval([d0,d1,d2,d3])
            else
              for d5 in a
                if d5 == 0
                  r += eval([d0,d1,d2,d3,d4])
                else
                  for d6 in a
                    if d6 == 0
                      r += eval([d0,d1,d2,d3,d4,d5])
                    else
                      for d7 in a
                        if d7 == 0
                          r += eval([d0,d1,d2,d3,d4,d5,d6])
                        else
                          for d8 in a
                            if d8 == 0
                              r += eval([d0,d1,d2,d3,d4,d5,d6,d7])
                            else
                              r += eval([d0,d1,d2,d3,d4,d5,d6,d7,d8])
                            end
                          end
                        end
                      end
                    end
                  end
                end
              end
            end
          end
        end
      end
    end
  end
end
print r


Measured memory_bytes: 3964
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;}
template <typename T> ostream& operator<<(ostream& out, vector <T>& a)  {for (auto& i : a) out << i << " "; return out;}
template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;}
template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    string a;
    cin >> a;
    int cnt = 0;
    forn (i, 0, sz(a))
        if (a[i] == 'A') {
            cnt++;
            break;
        }
    forn (i, 0, sz(a))
        if (a[i] == 'B') {
            cnt++;
            break;
        }
    if (cnt == 2)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}

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

if n == 1:
    if a != b:
        print(0)

    elif a == b:
        print(1)

    exit(0)

if a > b:
    print(0)
    exit(0)

num = n - (b - a)

count = 0

print((b - a) * (n - 2) + 1)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.begin(), a.end(), greater<int>()
#define ROT(a) a.begin(), a.begin() + 1, a.end()
#define RROT(a) a.begin(), a.end() - 1, a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9 + 7;
const int MAX = 10000000;
template <typename T1, typename T2>
inline bool chmin(T1& a, T2 b)
{
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T1, typename T2>
inline bool chmax(T1& a, T2 b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
T gcd(T a, T b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
//cout << 'H' << endl;
/*--------------------------------------------*/
ll modpow(ll x, ll n, ll mod)
{
    if (n == 0)
        return 1;
    ll res = modpow(x * x % mod, n / 2, mod);
    if (n & 1)
        res = res * x % mod;
    return res;
}
int main()
{
    //cout << fixed << setprecision(10)
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    cin >> s;
    int N = sz(s);

    vector<int> l(N);
    l[0] = s[0] - '0';

    vector<int> r(N);
    r[N - 1] = s[N - 1] - '0';

    rep(i, N - 1)
    {
        l[i + 1] = (modpow(10, N - i - 1, 2019) * l[i] + s[i + 1] - '0') % 2019;

        //cout << l[i] << endl;
    }
    map<int, int> mp;
    rep(i, N)
    {
        //mp[l[i]]++;
    }

    for (int i = N - 2; i >= 0; i--) {
        {
            r[i] = (r[i + 1] + modpow(10, N - i - 1, 2019) * (s[i] - '0')) % 2019;
            //cout << r[i] << endl;
        }
    }
    //  map<int, int> mpr;
    rep(i, N)
    {
        mp[r[i]]++;
    }
    mp[0]++;

    ll ans = 0;
    for (auto i : mp) {
        //cout << i.first << ' ' << i.second << endl;
        if (i.second > 1) {
            ans += (i.second - 1) * i.second / 2;
        }
    }

    cout << ans << endl;
}


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

int main() {
  vector<int>vec(4,0);
  for(int i=0; i<6; i++){
    int K;
    cin >> K;
    vec[K-1]++;
  }
  for(int i=0; i<4; i++){
    if(vec[i] == 3){
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}


Measured memory_bytes: 3592
import math

S = list(input())

S1 = S[0:math.floor(len(S)/2)]
S2 = S[math.ceil(len(S)/2):len(S)]

#print(S1)
#print(S2)
count = 0
for i in range(len(S)//2):
    s1_word = S1[i]
    s2_word = S2[len(S)//2 - i-1]
    if s1_word != s2_word:
        count += 1
    
print(count)



Measured memory_bytes: 3060
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String Str=sc.next();
int M=Str.length();
String Tr=sc.next();
int N=Tr.length();
int[] ord=new int[M];
for(int i=0;i<M;i++){
if(Str.charAt(i)=='a')ord[i]=0;
if(Str.charAt(i)=='b')ord[i]=1;
if(Str.charAt(i)=='c')ord[i]=2;
if(Str.charAt(i)=='d')ord[i]=3;
if(Str.charAt(i)=='e')ord[i]=4;
if(Str.charAt(i)=='f')ord[i]=5;
if(Str.charAt(i)=='g')ord[i]=6;
if(Str.charAt(i)=='h')ord[i]=7;
if(Str.charAt(i)=='i')ord[i]=8;
if(Str.charAt(i)=='j')ord[i]=9;
if(Str.charAt(i)=='k')ord[i]=10;
if(Str.charAt(i)=='l')ord[i]=11;
if(Str.charAt(i)=='m')ord[i]=12;
if(Str.charAt(i)=='n')ord[i]=13;
if(Str.charAt(i)=='o')ord[i]=14;
if(Str.charAt(i)=='p')ord[i]=15;
if(Str.charAt(i)=='q')ord[i]=16;
if(Str.charAt(i)=='r')ord[i]=17;
if(Str.charAt(i)=='s')ord[i]=18;
if(Str.charAt(i)=='t')ord[i]=19;
if(Str.charAt(i)=='u')ord[i]=20;
if(Str.charAt(i)=='v')ord[i]=21;
if(Str.charAt(i)=='w')ord[i]=22;
if(Str.charAt(i)=='x')ord[i]=23;
if(Str.charAt(i)=='y')ord[i]=24;
if(Str.charAt(i)=='z')ord[i]=25;
}
Arrays.sort(ord);
int[] order=new int[N];
for(int i=0;i<N;i++){
if(Tr.charAt(i)=='a')order[i]=0;
if(Tr.charAt(i)=='b')order[i]=1;
if(Tr.charAt(i)=='c')order[i]=2;
if(Tr.charAt(i)=='d')order[i]=3;
if(Tr.charAt(i)=='e')order[i]=4;
if(Tr.charAt(i)=='f')order[i]=5;
if(Tr.charAt(i)=='g')order[i]=6;
if(Tr.charAt(i)=='h')order[i]=7;
if(Tr.charAt(i)=='i')order[i]=8;
if(Tr.charAt(i)=='j')order[i]=9;
if(Tr.charAt(i)=='k')order[i]=10;
if(Tr.charAt(i)=='l')order[i]=11;
if(Tr.charAt(i)=='m')order[i]=12;
if(Tr.charAt(i)=='n')order[i]=13;
if(Tr.charAt(i)=='o')order[i]=14;
if(Tr.charAt(i)=='p')order[i]=15;
if(Tr.charAt(i)=='q')order[i]=16;
if(Tr.charAt(i)=='r')order[i]=17;
if(Tr.charAt(i)=='s')order[i]=18;
if(Tr.charAt(i)=='t')order[i]=19;
if(Tr.charAt(i)=='u')order[i]=20;
if(Tr.charAt(i)=='v')order[i]=21;
if(Tr.charAt(i)=='w')order[i]=22;
if(Tr.charAt(i)=='x')order[i]=23;
if(Tr.charAt(i)=='y')order[i]=24;
if(Tr.charAt(i)=='z')order[i]=25;
}
order = Arrays.stream(order).boxed()
            .sorted(Comparator.reverseOrder())
            .mapToInt(Integer::intValue)
            .toArray();
int count=Math.min(N,M);
for(int i=0;i<count;i++){
if(ord[i]<order[i]){
    System.out.println("Yes");break;
}else if(order[i]==ord[i]){}else{
    System.out.println("No");break;
    }
if(i==count-1){
    if(M>=N){System.out.println("No");}else{System.out.println("Yes");}

}
}

}
}

Measured memory_bytes: 27220
import copy

total_problem = int(input())
time_list = list(map(int, input().split()))
total_drinks = int(input())

drinks = []

for i in range(total_drinks):
  drinks.append(list(map(int, input().split())))

output_list = []
for i in range(total_drinks):
  output_list = copy.deepcopy(time_list)

  output_list[drinks[i][0] - 1] = drinks[i][1]
  print(sum(output_list))




Measured memory_bytes: 3444
#include <algorithm>  //min, max, sort, unique, fill
#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>  //pair, swap,
#include <vector>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using VI = vector<ll>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) for (ll i = 0; i < (n); i++)

static const ll kIntMax = numeric_limits<ll>::infinity();
static const double kFloatMax = numeric_limits<double>::infinity();

vector<ll> vi;

int main() {
  ll n;
  cin >> n;
  VI x(n, 0);

  REP(i, n) cin >> x[i];
  VI y(x);
  sort(x.begin(), x.end());

  REP(i, n) {
    if (y[i] <= x[n / 2 - 1])
      cout << x[n / 2] << endl;
    else
      cout << x[n / 2 - 1] << endl;
  }

  return 0;
}


Measured memory_bytes: 5376
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <unordered_map>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <memory>
#include <iomanip>
#include <type_traits>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//constexpr long long MOD = 1e9 + 7;
//constexpr long long MAX = 1000000;

//long long MOD = 998244353;
constexpr ll INF = 1e17;
constexpr double PI = 3.141592653589793;
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; }

ll h, w;
vector<ll> dx = { -1, 0, 1, 0 };
vector<ll> dy = { 0, -1, 0, 1 };


bool isInField(ll x, ll y) {
    bool f = x >= 0 && x < w && y >= 0 && y < h;
    return f;
}

bool compare_first(pair<ll, ll> x, pair<ll, ll> y)
{
    if (x.first != y.first) {
        return x.first < y.first;
    }
    else {
        return x.second < y.second;
    }
}

bool compare_second(pair<ll, ll> x, pair<ll, ll> y)
{
    if (x.second != y.second) {
        return x.second < y.second;
    }
    else {
        return x.first < y.first;
    }
}

struct {
    bool operator()(pair<string, int> x, pair<string, int> y) const
    {
        return x.second <= y.second && x.first < y.first;
    }
} compare_map;

const ll MAX = 500000000;
const ll MOD = 1000000007;


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

    int n;
    cin >> n;
    vector<int> a(n + 10);
    vector<ll> count(n + 10);

    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        a[i]--;
        count[a[i]]++;
    }
    
    ll sum = 0;
    for (int i = 0; i < n; i++)
    {
        sum += count[i] * (count[i] - 1);
    }

    sum /= 2;

    for (int i = 0; i < n; i++)
    {
        ll t = sum - (count[a[i]] * (count[a[i]] - 1) / 2);
        t += (count[a[i]] - 1) * (count[a[i]] - 2) / 2;
        cout << t << "\n";
    }

    return 0;
}



Measured memory_bytes: 4992
import sys,math,collections,itertools
input = sys.stdin.readline

N = int(input())
A=sorted(list(map(int,input().split())))
B = A[-1::-1]

GCA = [0]
GCB = [0]
for i in range(N):
    GCA.append(math.gcd(GCA[-1],A[i]))
    GCB.append(math.gcd(GCB[-1],B[i]))
GCB = GCB[-1::-1]

m=[]
for i in range(N):
    m.append(math.gcd(GCA[i],GCB[i+1]))
print(max(m))


Measured memory_bytes: 26396
# ABC 106, B - 105
n = int(input())

total = 0
for i in range(1, n+1):
    count = 0
    if i % 2 != 0:
        for j in range(1, i+1):
            if i % j == 0:
                count += 1
        if count == 8:
            total += 1
print(total)


Measured memory_bytes: 2940
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <map>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef unsigned long long ll;
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; }

ll divi=1e18;

int main(){
    ll n, sum=1, one=1;
    cin >> n;
    vector<ll> v(n);

    rep(i,(int)n){
        cin >> v[i];
        if(v[i]==0) {
            cout << 0 << endl;
            return 0;
        }
    }

    for(unsigned int i=0; i<n; ++i){
        ll tmp=v[i];

        if( divi/tmp < sum-one ){
            cout << -1 << endl;
            return 0;
        }
        sum*=tmp;
    }

    if(sum>divi) cout << -1 << endl;
    else cout << sum << endl;

    return 0;
}


Measured memory_bytes: 3972
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
#define ll long long
#define MOD 1000000007
typedef vector<int> vi;
typedef pair<int,int> pi;
#define inf 1e18
#define For(i,a,b) for (int i = a; i < b; i++)
#define Rep(i,a,b) for (int i = a; i <= b; i++)
#define ps(x,y) fixed << setprecision(y) << x 
#define pb push_back 
#define mp make_pair 
 
int32_t main()
{
    fast;
    string s; cin >> s;
    int a, b, c, d;
    a = s[0] - '0', b = s[1] - '0', c = s[2] - '0', d = s[3] - '0';
    if (a -b -c - d ==7) printf ("%d-%d-%d-%d=7\n " ,a ,b ,c , d );
    else if (a -b - c + d ==7) printf ("%d-%d-%d+%d=7\n " ,a ,b ,c , d );
    else if (a - b +c - d ==7) printf ("%d-%d+%d-%d=7\n " ,a ,b ,c , d );
    else if (a - b + c + d ==7) printf ("%d-%d+%d+%d=7\n " ,a ,b ,c , d );
    else if ( a +b -c - d ==7) printf ("%d+%d-%d-%d=7\n " ,a ,b ,c , d );
    else if ( a +b - c + d ==7) printf ("%d+%d-%d+%d=7\n " ,a ,b ,c , d );
    else if ( a + b +c - d ==7) printf ("%d+%d+%d-%d=7\n " ,a ,b ,c , d );
    else if ( a + b + c + d ==7) printf ("%d+%d+%d+%d=7\n " ,a ,b ,c , d );
    
    return 0;
}

Measured memory_bytes: 3676
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <set>
#include <utility>
using namespace std;

int main() {
  int N, L; cin >> N >> L;
  string S[110];
  for (int i = 0; i < N; i++)
    cin >> S[i];
  sort(S, S+N);
  for (int i = 0; i < N; i++)
    cout << S[i];
  cout << endl;
}


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

int main(){
  string a,b,ans="";
  cin >> a >> b;
  if (a=="H"&&b=="H") ans = "H";
  if (a=="D"&&b=="H") ans = "D";
  if (a=="H"&&b=="D") ans = "D";
  if (a=="D"&&b=="D") ans = "H";
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
ll h,w;
char c[110][110];
ll dp[110][110];
int main(){
    cin>>h>>w;
    rep(i,h)rep(j,w)cin>>c[i][j];
    rep(i,h)rep(j,w)dp[i][j]=1e17;
    dp[0][0]=(c[0][0]=='#');
    rep(i,h)rep(j,w){
        if(i+1<h)dp[i+1][j] = min(dp[i+1][j],dp[i][j]+(c[i][j]=='.'&&c[i+1][j]=='#'));
        if(j+1<w)dp[i][j+1] = min(dp[i][j+1],dp[i][j]+(c[i][j]=='.'&&c[i][j+1]=='#'));
    }
    cout<<dp[h-1][w-1]<<endl;
}

Measured memory_bytes: 384
n = int(input())
x = list(map(int, input().split()))

y = sorted([(a, i) for i, a in enumerate(x)])
x1 = y[n // 2 - 1][0]
x2 = y[n // 2][0]

for i in range(n):
    j = y[i][1]
    x[j] = (x[j], i)

for i in range(n):
    if x[i][1] < n // 2:
        print(x2)
    else:
        print(x1)

Measured memory_bytes: 58756
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}

int a,b,c,d;

int get(int x){
	return (b / x - (a - 1) / x);
}

int32_t main(){
	fastio();
	cin >> a >> b >> c >> d;
	int ans = get(c) + get(d) - get((c * d) / __gcd(c,d));
	ans = (b - a + 1) - ans;
	cout << ans;	
}

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

int main(){
  long long n,k;
  cin >> n >> k;
  vector<long long>a(n);
  for(int i=0;i<n;i++)
  cin >> a.at(i);
  const long long mod=1000000007;
  vector<pair<int,int>>tnt(n,pair<long long,long long>(0,0));
  for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
          if(a.at(i)>a.at(j)){
            if(i<j) tnt.at(i).first++;
            else tnt.at(i).second++;
          }
      }
  }
  //for(int i=0;i<n;i++)
    //cout << tnt.at(i).first << '$' << tnt.at(i).second << endl;
  long long ans=0;
  for(int i=0;i<n;i++){
    ans=((ans+k*(k+1)/2%mod*tnt.at(i).first%mod)+k*(k-1)/2%mod*tnt.at(i).second%mod)%mod;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main()
{
    int n;
    cin >> n;
    vector<int>a(n);
    for (auto &e : a)
        cin >> e;
    
    sort(a.begin(), a.end());
    cout << a[0] << ' ' << a[n - 1] << ' ' << accumulate(a.begin(), a.end(), 0LL) << endl;
}



Measured memory_bytes: 3200
n = int(input())
E = [[]]*n

for i in range(n):
    inputs = list(map(int, input().split()))
    if inputs[1]>0:
        for e in inputs[2:]:
            E[i] = E[i] + [e-1]

visited = [-1]*n
dist = [-1]*n
dist[0] = 0

from collections import deque

d = deque()
d.append(0)
visited[0] = 1

while len(d):
    nd = d.popleft()
    #print(nd, E[nd])
    for e in E[nd]:
        #print(e)
        if visited[e]<0:
            d.append(e)
            dist[e] = dist[nd] + 1
            visited[e] = 1
    #print(d, visited, dist, len(d))
            

for i in range(n):
    print(i+1, dist[i])


Measured memory_bytes: 6032
A,B=map(int, input().split())
t=0
if B==1:
  t=0
elif A>=B:
  t=1
if (B-A)%(A-1)>0:
  t=1+(B-A)//(A-1)+1
else:
  t=1+(B-A)//(A-1)
print(t)

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,K;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K;
	cout<<((N-1)+(K-2))/(K-1)<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n;
  string s, t;
  cin >> n >> s >> t;

  rep(i, 0, n) {
    string ss = s.substr(i);
    string tt = t.substr(0, n - i);
    if (ss == tt) {
      cout << n + i << endl;
      return 0;
    }
  }

  cout << n * 2 << endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)
from collections import defaultdict,Counter
def saiki(cnts):
  hitomozi = []
  d = defaultdict(lambda: [])
  heads = defaultdict(lambda: 0)
  for s,c in cnts:
    if len(s)==1:
      hitomozi.append(s[0])
    else:
      for k,v in c.items():
        if v>0:
          heads[k] += 1
      t = s[-1]
      c[t] -= 1
      s.pop(-1)
      d[t].append([s,c])
  for h in hitomozi:
    ans[0] += heads[h]
  for v in d.values():
    if len(v)<=1:
      continue
    if len(v)==2:
      s1,c1 = v[0]
      s2,c2 = v[1]
      l1,l2 = len(s1),len(s2)
      if l1==1:
        if l2>1 and c2[s1[0]]>0:
          ans[0] += 1
        continue
      else:
        if l2==1:
          if c1[s2[0]]>0:
            ans[0] += 1
          continue
        elif (l1>l2 and s2==s1[l1-l2:]) or (l2>l1 and s1==s2[l2-l1:]):
          ans[0] += 1
          continue
    saiki(v)
  return 

N = int(input())
S = [list(input()) for _ in range(N)]
ans = [0]
cnts = []
for s in S:
  cnts.append([s,Counter(s)])
saiki(cnts)
print(ans[0])

Measured memory_bytes: 307052
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll 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));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);

int main(){
    ll H,W; cin>>H>>W;
    ll cnt=0;
    rep(i,H){
        string tmp; cin>>tmp;
        rep(j,W){
            if(tmp[j]=='#') cnt++;
        }
    }
    if(cnt==H+W-1) cout<<"Possible"<<endl;
    else cout<<"Impossible"<<endl;
}



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

const int INF = 1e8;

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

string D = "DRUL";

const int var = 4;

int trans(char c) {
	switch (c)
	{
	case 'R': return 0;
	case 'D': return 1;
	case 'L': return 2;
	case 'U': return 3;
	default: break;
	}
	exit(EXIT_FAILURE);
}
struct node {
	node *fail;
	vector<node*> next;
	vector<int> ok;
	node() : fail(nullptr), next(var, nullptr) {}
};

node* getnext(node* p, char c) {
	while (p->next[trans(c)] == nullptr) p = p->fail;
	return p->next[trans(c)];
}

class Aho_Corasick {
	vector<int> unite(const vector<int>& a, const vector<int>& b) {
		vector<int> res;
		set_union(a.begin(), a.end(), b.begin(), b.end(), back_inserter(res));
		return res;
	}
	int K;
public:
	node *root;
	Aho_Corasick(const vector<string>& Ts) : K(Ts.size()), root(new node) {
		node *now;
		root->fail = root;
		for (int i = 0; i < K; i++) {
			auto &T = Ts[i];
			now = root;
			for (auto c : T) {
				if (now->next[trans(c)] == nullptr) {
					now->next[trans(c)] = new node;
				}
				now = now->next[trans(c)];
			}
			now->ok.push_back(i);
		}
		queue<node*> q;
		for (int i = 0; i < var; i++) {
			if (root->next[i] == nullptr) {
				root->next[i] = root;
			}
			else {
				root->next[i]->fail = root;
				q.push(root->next[i]);
			}
		}
		while (!q.empty()) {
			now = q.front(); q.pop();
			for (int i = 0; i < var; i++) {
				if (now->next[i] != nullptr) {
					node *nx = now->fail;
					while (nx->next[i] == nullptr) {
						nx = nx->fail;
					}
					now->next[i]->fail = nx->next[i];
					now->next[i]->ok = unite(now->next[i]->ok, nx->next[i]->ok);
					q.push(now->next[i]);
				}
			}
		}
	}
};

using T = tuple<int, int, node*>;

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int n, m, p;
	while (cin >> n >> m, n | m) {
		vector<string> S(n);
		int sx = 0, sy = 0, gx = 0, gy = 0;
		for (int i = 0; i < n; i++) {
			cin >> S[i];
			for (int j = 0; j < (int)S[i].size(); j++) {
				if (S[i][j] == 'S') {
					sx = i;
					sy = j;
				}
				else if (S[i][j] == 'G') {
					gx = i;
					gy = j;
				}
			}
		}
		cin >> p;
		vector<string> pts(p);
		for (int i = 0; i < p; i++) {
			cin >> pts[i];
		}
		Aho_Corasick aho(pts);
		vector<vector<unordered_map<node*, int>>> f(n, vector<unordered_map<node*, int>>(m));
		queue<T> q;
		q.push(make_tuple(sx, sy, aho.root));
		f[sx][sy][aho.root] = 0;
		while (!q.empty()) {
			auto p = q.front(); q.pop();
			for (int i = 0; i < 4; i++) {
				int tx = get<0>(p) + dx[i], ty = get<1>(p) + dy[i];
				node *t = getnext(get<2>(p), D[i]);
				if (0 <= tx && tx < n && 0 <= ty && ty < m && S[tx][ty] != '#' && t->ok.empty() && f[tx][ty].count(t) == 0) {
					q.push(make_tuple(tx, ty, t));
					f[tx][ty][t] = f[get<0>(p)][get<1>(p)][get<2>(p)] + 1;
				}
			}
		}
		int res = INF;
		for (auto p : f[gx][gy]) {
			res = min(res, p.second);
		}
		cout << (res != INF ? res : -1) << endl;
	}
	return 0;
}



Measured memory_bytes: 7540
#include<cstdio>
typedef long long lger;
inline lger read(){
    lger x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') {x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
lger n,num[100050],sum;
int main(){
	n=read();
	for(int i=1;i<=n;i++){num[i]=read();sum+=num[i];}
	if(sum%(n*(n+1)/2)!=0){puts("NO"); return 0;}
	lger round=sum/(n*(n+1)/2);
	lger flag=0;
	if((round-num[1]+num[n])%n!=0||round-num[1]+num[n]<0){puts("NO"); return 0;}
	else flag+=(round-num[1]+num[n])/n;
	for(int i=2;i<=n;i++)
		if((round-num[i]+num[i-1])%n!=0||round-num[i]+num[i-1]<0){
			puts("NO"); return 0;
		}
		else flag+=(round-num[i]+num[i-1])/n;
	puts(flag==round?"YES":"NO");
	return 0;
}


Measured memory_bytes: 896
//code fes 2017 qual C b similar arrays
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)

int main(){
  int n,a[100]={};
  cin>>n;
  int ans=1;
  rep(i,n){
    ans*=3;
  }
  int x=1;//積が奇数になる数
  rep(i,n){
    cin>>a[i];
    if(i){
      if(a[i]%2==0){
        x*=2;
      }
    }
  }
  if(a[0]%2==0){
    ans=ans-2*x;
  }
  else{
    ans=ans-x;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int a[16][16];
ll score[1<<16];
ll dp[1<<16];

int main(){
	int n;scanf("%d",&n);
	rep(i,n)rep(j,n)scanf("%d",&a[i][j]);
	rep(i,1<<n){
		rep(j,n)for(int k=j+1;k<n;k++){
			if((i>>j&1)&&(i>>k&1))score[i]+=a[j][k];
		}
	}
	rep(i,1<<n){
		int d=((1<<n)-1)&~i;
		for(int j=d;j>0;j=(j-1)&d){
			dp[i|j]=max(dp[i|j],dp[i]+score[j]);
		}
	}
	cout<<dp[(1<<n)-1]<<endl;
}

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

int main(){
    char t;
    char a = 'a';
    string s;
    cin >> s;
    sort(s.begin(),s.end());
    for(int i = 0; i < s.size(); i++){
        t = s[i];
        if(a == t) a++;
    }
    if(a > 'z'){
        cout << "None" << endl;
    }else{
        cout << a << endl;
    }
}

Measured memory_bytes: 512
n=int(input())
b=[int(n)  for n in input().split() ]
ans=0

for i in range(n):
  if i==0:
    ans+=b[0]
  else:
    if i < n-1:
      ans+=min(b[i] ,b[i-1])
    if i == n-1:
      ans+=b[i-1]
print(ans)

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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)


int main() {
	cin.sync_with_stdio(false);
	int N;
	char S[100];
	cin >> N;
	rep(i, N) {
		cin >> S[i];
	}
	int t[100] = {};
	rep(i, N) {
		if (S[i] == '(')t[i]++;
		else t[i]--;
	}
	rep(i, N) {
		if (S[i] == ')') {
			for(int j=i;j>=0;j--) {
				if (S[j] == '('&&t[j]!=0) {
					t[i]++;
					t[j]--;
					break;
				}
			}
		}
	}
	int r = 0, l = 0;
	rep(i, N) {
		if (t[i] == 1)r++;
		if (t[i] == -1)l++;
	}
	rep(i, l) {
		cout << "(";
	}
	rep(i, N) {
		cout << S[i];
	}
	rep(i, r) {
		cout << ")";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<deque>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<limits>
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
using namespace std;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define rep(I,N) up(I,0,N-1)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
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;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                                      ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<"\n";}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<"\n";}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<"\n";}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<"\n";}
inline void                                              out(ld p){printf("%.12Lf\n",p);}
template<class T>inline void outml(T p){for_each(all(p),out<decltype(p[0])>);}//ml=multi line
template<class T>inline void outol(T V){auto n=V.size();rep(i,n)cout<<V[i]<<" \n"[i==n-1];}//ol=one line
long n,a;
cpp_int s=1;
inline void solve(void){
  in(n);
  rep(i,n){
    in(a);
    if (a == 1) {
        continue;
    }
    if (a == 0) {
        s = 0;
        break;
    }
    if (s != static_cast<cpp_int>(-1)) {
        s*=a;
    }
    if (s > static_cast<cpp_int>(1e18)) {
        s = static_cast<cpp_int>(-1);
    }
  }
  out(s);
}
int main(void){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 3716
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    ll n, m, k;
    cin >> n >> m >> k;
    ll a[n] = {};
    rep(i,n) cin >> a[i];
    ll b[m];
    rep(i,m)cin >> b[i];

    ll ans = 0;

    ll sum[n+1] = {};
    srep(i,1,n+1){
        sum[i] = sum[i-1] + a[i-1];
    }

    ll now = k;
    rep(i,m+1){
        ll tmp = upper_bound(sum,sum+n+1,now) - sum - 1;
        ans = max(ans, tmp+i);
        if(i == m)break;
        now -= b[i];
        if(now < 0)break;
    }

    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 8276
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring> 
#include<cassert>
#include<cmath>
#include<sstream>
#include<fstream>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<bitset>
using namespace std;
int len[2005];
char s[2005][10005];
bitset<10005> can[2005];
pair<int,int> dp[10005][2005];
int main(){
	int n,k;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>s[i];
		len[i]=strlen(s[i]);
	}
	for(int i=0;i<n;i++){
		can[i].reset();
	}
	can[n]=1;
	for(int i=n-1;i>=0;i--){
		can[i]=can[i+1]|(can[i+1]<<len[i]);
	}
	int cnt=0,ii=0;
	for(int i=0;i<n;i++){
		if(can[i+1][k-len[i]]) dp[0][cnt++]=make_pair(i,0);
	}
	string res;
	for(int i=1;i<=k;i++){
		char mi='z';
		int cnt2=0;
		for(int j=0;j<cnt;j++){
			mi=min(s[dp[i-1][j].first][dp[i-1][j].second],mi);
		}
		res+=mi;
		int miid=1e9;
		for(int j=0;j<cnt;j++){
			int fi=dp[i-1][j].first,se=dp[i-1][j].second;
			if(s[fi][se]==mi){
				if(se+1==len[fi]) miid=min(miid,fi);
				else{
					dp[i][cnt2++]=make_pair(fi,se+1);
				}
			}
		}
		for(int j=miid+1;j<n;j++){
			if(k-len[j]-i>=0&&can[j+1][k-len[j]-i]) dp[i][cnt2++]=make_pair(j,0);
		}
		cnt=cnt2;
	}
	cout<<res;
}

Measured memory_bytes: 178688
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*

fun main(args: Array<String>) {
    val sc = FastScanner(System.`in`)
    val n = sc.nextInt()
    val map = mutableMapOf<String, Int>()
    for (i in 0 until n) {
        val s = sc.nextLine()
        if (!map.containsKey(s)) {
            map[s] = 0
        }
        map[s] = map[s]!! + 1
    }
    val max = map.values.max()!!
    val lst = map.keys.filter { map[it] == max }.toMutableList()
    lst.sort()
    for (s in lst) {
        println(s)
    }
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

Measured memory_bytes: 86148
N, M, X, Y = list(map(int,input().split()))
x = list(map(int,input().split()))
y = list(map(int,input().split()))
x_max = max(x)
y_min = min(y)
ans = 'War'
for i in range(-100,101):
    if (X < i <= Y ) and (x_max < i <= y_min):
        ans = 'No War'
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<ld> vld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)

int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vvi G(N);
    for (int m = 0; m < M; ++m) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    
    bool bAllEven = true;
    int i4 = 0, i6 = 0;
    for (int n = 0; n < N; ++n) {
        size_t m = G[n].size();
        if (m%2 != 0) {
            bAllEven = false;
            break;
        }
        if (m == 4) {
            ++i4;
        } else if (m >= 6) {
            ++i6;
        }
    }
    
    if (!bAllEven) {
        cout << "No" << endl;
        return 0;
    }
    
    if (i6 >= 1 || i4 >= 3) {
        cout << "Yes" << endl;
        return 0;
    } else if (i4 == 2) {
        int v1 = -1, v2 = -1;
        for (int n = 0; n < N; ++n) {
            if (G[n].size() == 4) {
                if (v1 == -1) {
                    v1 = n;
                } else {
                    v2 = n;
                }
            }
        }
        bool bGood = false;
        for (int i = 0; i < 4; ++i) {
            int prev = v1;
            int cur = G[v1][i];
            while (1) {
                if (cur == v1) {
                    bGood = true;
                    break;
                } else if (cur == v2) {
                    break;
                }
                
                int next = G[cur][0] + G[cur][1] - prev;
                prev = cur;
                cur = next;
            }
        }
        if (bGood) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 5760
use std::cmp::max;
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

    #[allow(unused_macros)]
    macro_rules! to_mut {
        ($($var: ident),*) => {
            $(
                #[allow(unused_mut)]
                let mut $var = $var;
            )*
        };
    }

fn main() {
    input!{
        a: usize,
        b: usize
    }

    to_mut!(a, b);
    let mut result = 0;
    if a > b {
        result += a;
        a -= 1;
    } else {
        result += b;
        b -= 1;
    }
    result += max(a, b);
    println!("{}", result);
}


Measured memory_bytes: 4352
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		String s1 = scn.next();
      	s1 = s1.toUpperCase();
		String[] list1 = s1.split("");
      	String s2 = scn.next();
      	s2 = s2.toUpperCase();
		String[] list2 = s2.split("");
      	String s3 = scn.next();
      	s3 = s3.toUpperCase();
		String[] list3 = s3.split("");
      	System.out.println(list1[0]+list2[0]+list3[0]);
	}
}

Measured memory_bytes: 39260