akhauriyash/Code-Regression huggingface dataset:
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#define re register
using namespace std;
priority_queue<int,vector<int>,less<int> > q;
int n,ans,tot;
inline int read()
{
    int x=0;
    char c=getchar();
    while(c<'0'||c>'9') c=getchar();
    while(c>='0'&&c<='9')
    {
        x=x*10+c-48;
        c=getchar();
    }
    return x;
}
int main()
{
	n=read();
	if(n%2==1) q.push(0);
	int xx;
	for(re int i=1;i<=n;i++)
	{
		xx=read();
		q.push(xx);
	}
	while(q.size())
	{
		ans+=q.top();
		q.pop();
		tot+=q.top();
		q.pop();
	}
	cout<<ans-tot<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);
        int A[] = new int[3];
        for (int i=0; i<3; i++) {
            A[i] =  Integer.parseInt(sc.next());
        }
        sc.close();

        int sum = Arrays.stream(A).sum();
        if (sum>21)
            System.out.println("bust");
        else
            System.out.println("win");
    }
}

Measured memory_bytes: 28116
/*
  ∧,,∧
( 'ω' )つ ＜WA,またお前か！！　
（m9 ＼ 　　
　 ＼　 ＼
　 　 ) ) ＼
　 ／／ ＼ ＼
　 (＿） 　 (＿)
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define rep(x, y) for (int x = 0; x < y; x++)
#define MOD 1000000007

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

ostringstream oss_global;
string s_global = oss_global.str();

int main()
{
    int N;
    cin >> N;
    vector<int> A(N, 0);
    for (int i = 0; i < N; i++)
        cin >> A[i];
    vector<int> B(N, 0);
    for (int i = 0; i < N; i++)
        cin >> B[i];
    vector<int> C(N-1, 0);
    for (int i = 0; i < N-1; i++)
        cin >> C[i];

    int ans = 0;
    int last = -2;
    int food = 0;
    for (int i = 0; i < N; i++) {
        food = A[i] - 1;
        ans += B[food];

        if (food == last + 1)
            ans += C[last];

        last = food;
    }

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


Measured memory_bytes: 256
from collections import deque
n, m = map(int,input().split())
def vertex_node()  -> list:
    v_c = [[] for _ in range(n+1)]
    for i in range(m):
        a,b = map(int,input().split())
        v_c[a].append(b)
        v_c[b].append(a)
    return v_c

def bfs(l) -> list:
    dist = [-1] * (n+1)
    dist[0] = 0
    dist[1] = 0
    d = deque()
    d.append(1)
    while d:
        v = d.popleft()
        for i in l[v]:
                if dist[i] != -1:
                    continue
                dist[i] = v
                d.append(i)
    return dist
if __name__ == "__main__":
    i = vertex_node()
    ans = bfs(i)[2:]
    print("Yes")
    for i in ans:
        print(i)

Measured memory_bytes: 34356
#include <stdio.h>

int main(int argc, const char * argv[]){
    int a,b;
    scanf("%d %d",&a,&b);
    
    if(a > b){
        printf("a > b\n");
    }else if(a < b){
        printf("a < b\n");
    }else{
        printf("a == b\n");
    }
    
    return 0;
}



Measured memory_bytes: 2112
#Har har mahadev
# author : @harsh kanani

n, d = map(int, input().split())
c = 0
for i in range(n):
	x, y = map(int, input().split())
	cal = (x**2 + y**2)**0.5
	if cal<=d:
		c += 1
print(c)
	

Measured memory_bytes: 9564
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int k = stdIn.nextInt();
		int x = stdIn.nextInt();
		if(k*500>=x) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		
		
		
		
		
		
		
		
		
	}

}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
#define MD 1000000007
#define INF 1000000000
typedef long long int ll;
typedef pair<ll,ll> P;
template <typename T> std::string tostr(const T& t){std::ostringstream os; os<<t; return os.str();}
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
 
int main(){
    int n;
    cin>>n;
    vector<int> v(n),v2(n,0);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    int k=0;
    for(int j=0;j<n;j++){
            if(v2[j]==v[j]){
                k++;
            }
    }
     if(k==n){
        cout<<0<<endl;
        return 0;
    }
    ll ans=1;
    while(1){
        int cnt=0,flag=0;
        for(int j=0;j<n;j++){
            if(v2[j]==v[j]&&flag==1){
                break;
            }else if(v2[j]<v[j]){
                v2[j]++;
                flag=1;
            }
        }
        for(int j=0;j<n;j++){
            if(v2[j]==v[j]){
                cnt++;
            }
        }
        if(cnt==n){
            cout<<ans<<endl;
            break;
        }
        ans++;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int x,y;
  cin >> x >> y;
  cout << x+y/2 << endl;
}


Measured memory_bytes: 256
import itertools
n, m, q = map(int, input().split())

abcd = []
for _ in range(q):
    abcd.append(list(map(int, input().split())))

ans = 0
for l in itertools.combinations_with_replacement(range(1, m + 1), n):
    tmp = 0
    for i in range(q):
        a, b, c, d = abcd[i]
        if l[b - 1] - l[a - 1] == c:
            tmp += d
    ans = max(ans, tmp)

print(ans)


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

using namespace std;

int N, lft[140009], rgt[140009], length[140009];
long long D;

typedef vector < pair < int, int > > dpData;

void addPoint (dpData &a, pair < int, int > x)
{
    if (a.empty ()) a.push_back (x);
    else
    {
        auto y = a.back ();
        if (y.first == x.first)
        {
            if (y.second > x.second)
                a.pop_back (), a.push_back (x);
        }
        else
        if (y.second > x.second) a.push_back (x);
    }
}

void combine (dpData &a, dpData &b, int d1, int d2, dpData &c)
{
    c.clear ();
    if (a.empty () || b.empty ()) return ;
    if (a.size () > b.size ())
        swap (a, b), swap (d1, d2);
    dpData c1, c2;
    auto it2 = b.begin ();
    for (auto it : a)
    {
        while (it2 != b.end () && it.second + it2->first + d1 + d2 <= D) it2 ++;
        if (it2 == b.end () || (it.second + it2->first + d1 + d2 > D && it2 != b.begin ())) it2 --;
        if (it.second + it2->first + d1 + d2 <= D)
        {
            if (!c1.empty () && c1.back().second <= it2->second + d2) ;
            else c1.push_back ({it.first + d1, it2->second + d2});
        }
    }
    for (auto it : c1)
        c2.push_back ({it.second, it.first});
    reverse (c2.begin (), c2.end ());
    int i = 0, j = 0;
    while (i < c1.size () || j < c2.size ())
    {
        if (i == c1.size () || (j < c2.size () && c1[i] > c2[j])) addPoint (c, c2[j ++]);
        else addPoint (c, c1[i ++]);
    }
}

dpData dp[140009];

void solve (int nod)
{
    if (lft[nod] == 0)
    {
        dp[nod].clear ();
        dp[nod].push_back ({0, 0});
        return ;
    }
    int x = lft[nod], y = rgt[nod];
    solve (x), solve (y);
    combine (dp[x], dp[y], length[x], length[y], dp[nod]);
}

bool ok (long long currD)
{
    D = currD, solve (1);
    return (!dp[1].empty ());
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N);
for (int i=2; i<=N; i++)
{
    int t;
    scanf ("%d %d", &t, &length[i]);
    if (lft[t] == 0) lft[t] = i;
    else rgt[t] = i;
}
long long p = 0, u = (1LL << 34) - 2, mij, ras = -1;
while (p <= u)
{
    mij = (p + u) >> 1LL;
    if (ok (mij)) ras = mij, u = mij - 1;
    else p = mij + 1;
}
printf ("%lld\n", ras);

return 0;
}


Measured memory_bytes: 19272
N = int(input())
S = input()

r = S.count("R")
g = S.count("G")
b = S.count("B")

cnt = 0
k = 1
while 2*k + 1 <= N:
  for i in range(N - 2*k):
    if S[i] != S[i + k] and S[i + k] != S[i + 2*k] and S[i + 2*k] != S[i]:
      cnt += 1
  k += 1
print(r*g*b - cnt)

Measured memory_bytes: 9208
#include<bits/stdc++.h>
using namespace std;
int main()
  {
     int n; 
     cin>>n; 
     n=n%10;
     if(n==3)
       cout<<"bon";
     else if(n==0||n==1||n==6||n==8)
       cout<<"pon";
     else
       cout<<"hon";
   return 0;
  }
 

Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
#define ioS            ios::sync_with_stdio(false);cin.tie(0);
#define li             long int
#define ll             long li
#define ull            unsigned ll
#define pi             pair<int,int>
#define vi             vector<int>
#define vli            vector<li>
#define vll           vector<ll>
#define vvi            vector<vector<int>>
#define pb             push_back
#define mp             make_pair
#define forn(i,s,n)    for(auto i=s;i<n;++i)               
#define forr(i,s,n)    for(auto i=s;i>=n;--i) 
const ll mx = 1e5;
void solve(int test)
{
    int n;
    cin>>n;
    vi a(n);
    forn(i,0,n) cin>>a[i];
    int count= 0;
    forn(i,0,n)
    {
        forn(j,i+1,n)
        {
            forn(k,j+1,n)
            {
                if(a[i]!=a[j] && a[j]!=a[k] && a[i]!=a[k] )
                {
                    if(a[i]+a[j] > a[k] && a[k]+a[j] > a[i] && a[i]+a[k] > a[j])
                    count++;
                }
            }
        }
    }
    cout<<count<<endl;
}
int32_t main()
{
    ioS    
    int t;
    // cin>>t;
    // forn(i,1,t+1)
        solve(0);
}



Measured memory_bytes: 3652
import java.io.*;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
public class Main {
	static String a;
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = stdIn.nextInt();
		}
		show(a,n);
		insertionSort(a,n);
		
	}
	static void show(int[] a, int n) {
		System.out.print(a[0]);
		for(int i = 1; i < n; i++) {
			System.out.print(" " + a[i]);
		}
		System.out.println();
	}
	static void insertionSort(int[] a, int n) {
		for(int i = 1; i < n; i++) {
			int v = a[i];
			int j = i-1;
			while(j >= 0 && a[j] > v) {
				a[j+1] = a[j];
				j--;
			}
			a[j+1] = v;
			show(a,n);
		}
	}
}

Measured memory_bytes: 24252
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(1000000)
from collections import deque

# スペース区切りの整数の入力
a, b, c, d = map(int, input().split())

t1 = a*c
t2 = a*d
t3 = b*c
t4 = b*d

print(max(t1, t2, t3, t4))
# if b <= 0 and d <= 0:
#     print(a*c)
# elif b < 0 and d > 0:
#     print(b*c)
# elif b >0 and d < 0:
#     print(a*d)
# else:
#     print(b*d)

Measured memory_bytes: 9456
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



const int N = 1e6+10;
int n, f[N][30];
pii mi[30];
char s[N];

int main() {
	scanf("%s", s+1);
	n = strlen(s+1);
	REP(i,1,n) {
		memcpy(f[i],f[i-1],sizeof f[0]);
		REP(j,'a','z') {
			if (s[i]==j) ++f[i][j-'a'];
			else --f[i][j-'a'];
		}
		if (i>1) { 
			REP(j,0,25) if (f[i][j]-mi[j].x>0) { 
				return printf("%d %d\n",mi[j].y+1,i),0;
			}
		}
		REP(j,0,25) mi[j] = min(mi[j], pii(f[i-1][j],i-1));
	}
	puts("-1 -1");
}









Measured memory_bytes: 13696
//String Palindrome

#include<iostream>
#include<string>
using namespace std;

int main (){
    string S,Ans = "Yes";
    cin >> S;
    int n = S.size(),op = 0;
    for(int i = 0;i < n;i++){
        if(S[i]!=S[n-i-1]){
            Ans = "No";
        }
    }
    for(int i = 0;i < (n-1)/2;i++){
        if(S[i]!=S[(n/2-1-i)]){
            Ans = "No";
        }
    }
    for(int i = (n+3)/2;i < n+1;i++){
        if(S[((n+3)/2+op-1)]!=S[n-op-1]){
            Ans = "No";
        }
        op++;
    }
    cout << Ans <<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
using lint =                            long long int;
using plint =                           pair<lint, lint>;
#define vli                             vector<lint>
#define pb                              push_back
#define ALL(x)                          begin(x),end(x)
#define inf                             (1LL<64)-1
#define SZ(x)                           ((lint)(x).size())
#define                                 FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define                                 IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define                                 REP(i, n) FOR(i,0,n)
#define                                 IREP(i, n) IFOR(i,0,n)
#define                                 f_ip   ios_base::sync_with_stdio(false); cin.tie(NULL);
template<typename T>                    istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }

/*
   -------
         |
    **   |
   -------      
   |
   ------------------------------------------------------------------------------------------------------
*/

vector<vector<int>> V = 
{
    {0,1,2},
    {3,4,5},
    {6,7,8},
    {0,4,8},
    {2,4,6},
    {0,3,6},
    {1,4,7},
    {2,5,8}};            //linearization of matrix  , usef for final check;

void solve()
{
   vector<lint> A(9);
   cin>>A;
   int N;
   cin>>N;
   while(N--){
        int b;
        cin>>b;
        for(auto &x : A) if (x == b)  x = 0;          
   }
   for(auto vec : V){
       bool b = true;
       for(auto x : vec) if ( A[x] ) b = false;                          //if any of the row, column or the two diagonal is marked, then return true from here;
       if(b) 
       {
           puts("YES");
           return ;
       }
   }

   puts("NO");
}

int main()
{   
    //  f_ip
  
    // solve();
   vector<lint> A(9);
   cin>>A;
   int N;
   cin>>N;
   while(N--){
        int b;
        cin>>b;
        for(auto &x : A) if (x == b) x = 0;          
   }
   for(auto vec : V){
       bool b = true;
       for(auto x : vec) if (A[x]) b = false;                          //if any of the row, column or the two diagonal is marked, then return true from here;
       if(b) 
       {
           puts("Yes");
           return 0;
       }
   }
   puts("No");

    // vector<lint> A(9);
    // cin >> A;
    // int N;
    // cin >> N;
    // while (N--) {
    //     int b;
    //     cin >> b;
    //     for (auto &x : A) if (x == b) x = 0;
    // }
    // for (auto vec : V) {
    //     bool b = true;
    //     for (auto x : vec) if (A[x]) b = false;
    //     if (b) {
    //         puts("Yes");
    //         return 0;
    //     }
    // }
    // puts("No");

}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
    class Program
    {
        static void Main(string[] args)
        {
            // get n
            int n = Convert.ToInt32(Console.ReadLine());
            List<restaurant> restaurants = new List<restaurant>();
            // get a int p
            for (int i = 1; i <= n; i++)
            {
                string[] sp = Console.ReadLine().Split(' ');
                restaurants.Add(new restaurant()
                {
                    name = sp[0],
                    point = Convert.ToInt32(sp[1]),
                    inputOrder = i
                });
            }

            var order = restaurants.OrderBy(x => x.name).ThenByDescending(y => y.point).
                Select(z => z.inputOrder).ToList();

            foreach(var x in order)
            {
                Console.WriteLine(x);
            }

        }
        public class restaurant
        {
            public string name = "";
            public int point = -1;
            public int inputOrder = -1;
        }
    }


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

int main(){
  int K,A,B;
  cin >> K >> A >> B;
  int n = floor(A/K);
  if(K*n >= A || (K*(n+1) >= A && K*(n+1) <= B)){
    cout << "OK" << endl;
  }else{
    cout << "NG" << endl;
  }
}

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

int32_t main()
{
  int n;
  cin>>n;
  int sum=0;
  while(n>=5){
      if(n>=500){
          sum+=1000;
          n-=500;
      }
      else if(n>=5 && n<500){
          sum+=5;
          n-=5;
      }
  }
  cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <cassert>

using namespace std;
using ll = long long;

int main()
{
    string s;
    cin >> s;
    int mid = 0;
    if(s.size() % 2 == 0){
        mid = s.size()/2 -1;
    }else{
        mid = (s.size()-1)/2;
    }
    int ans = 0;
    for(int i = 0; i <= mid ; i++){
        if(s[i] == s[s.size()-1-i]) continue;
        else ans++;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define int long long
#define ll long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES puts("YES\n")
#define Yes puts("Yes\n")
#define NO  puts("NO\n")
#define No  puts("No\n")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }



signed main() {

	string s;
	cin >> s;
	int ans = 0;
	int N = s.length();

	string prev=s.substr(0,1);
	for (int i = 1; i < N;) {
		if (s.substr(i, 1) == prev) {
			if (i == N - 1) break;
			prev = s.substr(i, 2);
			i+=2;
			ans++;
		}
		else {
			prev = s.substr(i, 1);
			i++;
			ans++;
		}
//		cerr << prev << endl;
	}


	cout << ans+1 << endl;

	return 0;
}


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

int main()
{
    int a,b;
    cin>>a>>b;
    if(a<b){
        cout<<"a < b"<<endl;
    }else if(a>b){
        cout<<"a > b"<<endl;
    }else if(a==b){
        cout<<"a == b"<<endl;
    }

    return 0;
}







Measured memory_bytes: 3104
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define INF 0x3f3f3f3
#define LINF 0x3f3f3f3f3f3f3f
#define MAXN 2*int(1e5)+5
#define endl '\n'
#define ll long long
#define f first
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << endl
#define debug2(x, y) cout << "DEBUG " << x << " " << y << endl
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << endl
using namespace std;
const ll mod = 1e9+7;

int main(){
	ll h;
	cin >> h;
	
	ll k = 1, ans = 0;
	while(h >= 1) {
		ans += k;
		k *= 2;
		h /= 2;
	}
	
	cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner scan = new Scanner(System.in);

		int a = scan.nextInt();
		int b = scan.nextInt();

		if (a <= b) {
			System.out.println(a);
		} else {
			System.out.println(a - 1);
		}
	}

	//***********************以下共通関数************************************************
	/**
	 * 文字列を反転して返す
	 * @param pStr 文字列
	 * @return 反転した文字列
	 */
	public static String myReverse(String pStr) {
		if (pStr.length() < 1) {
			return "";
		}

		StringBuffer sb = new StringBuffer(pStr);
		return sb.reverse().toString();
	}

	/**
	 * 余りを求める。
	 * @param a
	 * @param b
	 * @return 余り。余りがマイナスの時はプラスで返す。
	 */
	public static long myMod(long a, long b) {
		long ret = 0;

		ret = a % b;

		if (ret < 0) {
			ret += b;
		}

		return ret;
	}

	/**
	 * 乗数を求める ※mod対応
	 * @param kisu 基数
	 * @param josu 乗数
	 * @param primeNumMod_0 法 mod値 使わない場合は「0」
	 * @return
	 */
	public static long myPowWithMod(long kisu, long josu, long primeNumMod_0) {

		long ans = 1;

		//乗数が0の場合→1
		if (josu == 0)
			return 1;

		if (primeNumMod_0 == 0) {
			//modを使わないとき

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= kisu;
					josu = josu / 2;
				} else {
					//累乗が奇数の時
					ans *= kisu;
					josu--;
				}
			}

			return ans;

		} else {
			//modを使うとき

			//初めに桁を落とす
			kisu = myMod(kisu, primeNumMod_0);

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= myMod(kisu, primeNumMod_0);
					josu = josu / 2;

				} else {
					//累乗が奇数の時
					ans *= myMod(kisu, primeNumMod_0);
					josu--;

				}
			}

			return myMod(ans, primeNumMod_0);

		}

	}

}


Measured memory_bytes: 26992
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = 1e18;

ll f(ll a, ll b){return a+b;}
int other = 0;

struct segment_tree{
    ll n;
    ll seg[1000000];
    //要素数Nのセグメントツリーを構築
    segment_tree(int N){
        n = 1;
        while(n < N) n *= 2;
        fill_n(seg, 2*n-1, other);
    }
    //i番目の要素をxに変更(0番目から数える)
    void update(int i, ll x){
        i += n-1;
        seg[i] = x;
        while(i > 0){
            i = (i-1)/2;
            seg[i] = f(seg[2*i+1], seg[2*i+2]);
        }
    }
    //要素数N以上の最小の２べきnを取得
    ll size(){return n;}
    //query(a, b, 0, 0, n)でa番目からb-1番目までの演算の結果を取得
    ll query(int a, int b, int i, int l, int r){
        if(a >= r || b <= l) return other;
        elif(a <= l && r <= b) return seg[i];
        else{
            int vl = query(a, b, 2*i+1, l, (l+r)/2);
            int vr = query(a, b, 2*i+2, (l+r)/2, r);
            return f(vl, vr);
        }
    }
};

int main(){
    int N;
    cin >> N;
    ll e[N];
    e[0] = 1;
    rep2(i, 1, N-1) e[i] = (2*e[i-1])%MOD2;
    int x[N], y[N];
    vector<P> vecx, vecy, vec;
    rep(i, N){
        cin >> x[i] >> y[i];
        vecx.push_back(P(x[i], i));
        vecy.push_back(P(y[i], i));
    }
    sort(vecx.begin(), vecx.end());
    sort(vecy.begin(), vecy.end());
    rep(i, N){
        int px = vecx[i].second, py = vecy[i].second;
        x[px] = i, y[py] = i;
    }
    rep(i, N) vec.push_back(P(x[i], y[i]));
    sort(vec.begin(), vec.end());
    int X[N], Y[N];
    rep(i, N) X[i] = vec[i].first, Y[i] = vec[i].second;
    segment_tree segl(N), segr(N);
    ll n = segl.size();
    ll ul[N], ur[N], dl[N], dr[N];
    rep(i, N){
        dl[i] = segl.query(0, Y[i], 0, 0, n);
        ul[i] = i - dl[i];
        segl.update(Y[i], 1);
    }
    rep3(i, N-1, 0){
        dr[i] = segr.query(0, Y[i], 0, 0, n);
        ur[i] = N-1-i - dr[i]; 
        segr.update(Y[i], 1);
    }
    ll ans = (N*e[N-1])%MOD2;
    rep(i, N){
        ll a = (e[ul[i]]-1)*(e[dr[i]]-1) % MOD2;
        ll b = (e[ur[i]]-1)*(e[dl[i]]-1) % MOD2;
        ans += a * e[ur[i]+dl[i]];
        ans %= MOD2;
        ans += b * e[ul[i]+dr[i]];
        ans %= MOD2;
        ans += MOD2*MOD2 - a*b;
        ans %= MOD2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 33628
#include <stdio.h>
#define min(p,q)((p)<(q)?(p):(q))

int ans=1e9;
int a[110];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",a+i);
	for(int i=-100;i<=100;i++){
		int s=0;
		for(int j=0;j<n;j++)s+=(i-a[j])*(i-a[j]);
		ans=min(ans,s);
	}
	printf("%d",ans);
}

Measured memory_bytes: 128
inp = lambda cast=int: list(map(cast, input().split()))
printf = lambda s='', *args, **kwargs: print(str(s).format(*args), flush=True, **kwargs)
s, = inp(str)
a, b = int(s[:2]), int(s[2:])
if 0 < a <= 12 and 0 < b <= 12:
    print('AMBIGUOUS')
elif 0 < a <= 12:
    print('MMYY')
elif 0 < b <= 12:
    print('YYMM')
else:
    print('NA')


Measured memory_bytes: 3060
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=2000;
typedef struct Z { int a,b,idx; Z() {} Z(int a,int b,int idx):a(a),b(b),idx(idx) {} } Z;
bool operator<(const Z &p,const Z &q) { return p.b<q.b; }

char a[MAXN+1],b[MAXN+1]; int n;

int l[MAXN],r[MAXN];
Z z[MAXN];



int solve() {
	bool same=true; REP(i,n) if(a[i]!=b[i]) same=false; if(same) return 0;
	bool bone=false; REP(i,n) if(b[i]=='1') bone=true; if(!bone) return -1;
	int ret=INT_MAX;
	REP(rep,2) {
		//printf("%s %s\n",a,b);
		REP(i,n) {
			r[i]=i==0?i:max(i,r[i-1]);
			while(b[r[i]%n]!='1') ++r[i];
		}
		for(int i=n-1;i>=0;--i) {
			l[i]=i==n-1?i:min(i,l[i+1]);
			while(b[(l[i]+n)%n]!='1') --l[i];
		}
		REP(i,n) z[i]=Z(i-l[i],r[i]-i,i); sort(z,z+n);
		REP(off,n) {
			int mx=0,ndiff=0,cur=INT_MAX;
			for(int i=n-1;i>=0;--i) {
				int idx=z[i].idx,nidx=(idx+n-off)%n;
				int now=2*(z[i].b+mx); if(now<cur) cur=now;
				if(a[idx]!=b[nidx]) {
					//printf("\t%d: a=%d b=%d\n",idx,z[i].a,z[i].b);
					++ndiff;
					mx=max(mx,z[i].a-off);
				}
			}
			{ int now=2*mx; if(now<cur) cur=now; }
			assert(cur!=INT_MAX);
			//printf("off=%d: cur=%d ndiff=%d\n",off,cur,ndiff);
			cur+=ndiff+off; if(cur<ret) ret=cur;
		}
		for(int i=0;i<n-i-1;++i) swap(a[i],a[n-i-1]),swap(b[i],b[n-i-1]);
	}
	return ret;
}

void run() {
	scanf("%s%s",a,b); n=strlen(a);
	printf("%d\n",solve());
}

int bf() {
	int ret=INT_MAX;
	REP(A,n) REP(B,n) REP(C,n) REP(D,n) {
		int cur=A+B+C+D; bool ok=true;
		REP(i,n) {
			int at=i; bool any=b[at]=='1';
			REP(j,A) { at=(at+1)%n; if(b[at]=='1') any=true; }
			REP(j,B) { at=(at+n-1)%n; if(b[at]=='1') any=true; }
			REP(j,C) { at=(at+1)%n; if(b[at]=='1') any=true; }
			REP(j,D) { at=(at+n-1)%n; if(b[at]=='1') any=true; }
			if(a[i]==b[at]) continue;
			if(!any) { ok=false; break; }
			++cur;
		}
		if(ok&&cur<ret) ret=cur;
	}
	return ret==INT_MAX?-1:ret;
}

void stress() {
	n=8;
	REP(amask,1<<n) REP(bmask,1<<n) {
		REP(i,n) a[i]=((amask>>i)&1)?'1':'0'; a[n]='\0';
		REP(i,n) b[i]=((bmask>>i)&1)?'1':'0'; b[n]='\0';
		int have=solve();
		int want=bf();
		if(have!=want) { printf("%d %s %s (have=%d want=%d)\n",n,a,b,have,want); } else printf(".");
	}
}

int main() {
	//stress();
	run();
	return 0;
}


Measured memory_bytes: 384
import numpy as np
import sys
read = sys.stdin.read


D = int(input())
CS = np.array(read().split(), np.int32)
C = CS[:26]
S = CS[26:].reshape((-1, 26))
del CS

last = np.zeros((26, ))
ans = []

def getContestType_at_d(d):
    s = -10000000
    for i in range(26):
        tmp = S[d][i] - np.sum(C * (d + 1 - last)) + C[i] * (d + 1 - last[i])
        if s < tmp:
            s = tmp
            t = i

    last[t] += 1

    return t + 1, s

#score = 0
for d in range(D):
    t, _ = getContestType_at_d(d)
    ans.append(t)
    #score += s
    #print('score:', score)


print('\n'.join(map(str, ans)))

Measured memory_bytes: 27728
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var Instance = new Otoshidama();
			Instance.Exec();
		}
	}

	public class Otoshidama
	{
		public void Exec()
		{
			var array = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
			long n = array[0];
			long y = array[1];
			long ten = -1;
			long five = -1;
			long one = -1;

			long max = y / 1000;

			for (var i = 0; i <= n; ++i) {
				for (var j = 0; j <= n; ++j) {
					var k = n - i - j;
					if (k < 0) {
						break;
					}

					long total = 1000 * i + 5000 * j + 10000 * k;
					if (total == y) {
						ten = k;
						five = j;
						one = i;
					}
				}
			}

			string str = $"{ten} {five} {one}";
			Console.WriteLine(str);
			Console.Out.Flush();
			Console.ReadLine();
		}
	}
}

Measured memory_bytes: 13396
n,m,r = map(int,input().split())
rl = list(map(int,input().split()))

d = [[float("inf") for i in range(n)] for j in range(n)]
for _ in range(m):
    a,b,c = map(int,input().split())
    d[a-1][b-1] = c
    d[b-1][a-1] = c


#d[i][j]は2頂点間i, j間の移動コストを格納, Vは頂点数
def warshall_floyd(d, V): 
    for k in range(V):
        for i in range(V):
            for j in range(V):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])

    return d #d[i][j]に頂点i, j間の最短距離を格納

d = warshall_floyd(d, n)
import itertools
ans = float("inf")
for balls in itertools.permutations(rl):
    a = 0
    for i in range(r-1):
        a += d[balls[i]-1][balls[i+1]-1]
    ans = min(ans, a)

print(ans)

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

int main()
{
    int i, n;
    int sc_t = 0, sc_h = 0;
    string w_t, w_h;

    cin >> n;
    for(i = 0; i < n; i++){
        cin >> w_t >> w_h;
        if(w_t > w_h){
            sc_t = sc_t + 3;
        }else if(w_t < w_h){
            sc_h = sc_h + 3;
        }else{
            sc_t = sc_t + 1;
            sc_h = sc_h + 1;
        }
    }
    cout << sc_t << " " << sc_h << endl;

    return 0;
}

Measured memory_bytes: 1208
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

N = I()
c = LS2()

w = [0]*N
r = [0]*N
for i in range(N):
    if i == 0:
        if c[i] == 'W':
            w[i] = 1
        else:
            r[i] = 1
    else:
        if c[i] == 'W':
            w[i] = w[i-1]+1
            r[i] = r[i-1]
        else:
            w[i] = w[i-1]
            r[i] = r[i-1]+1
a = w[-1]
b = r[-1]
if b == 0:
    print(0)
    exit()
for i in range(N):
    if w[i] == b-r[i]:
        print(w[i])
        exit()


Measured memory_bytes: 76408
#include <iostream>
using namespace std;
int main(){
      int ws[23],sum,num,dp[50003];
      cin >> sum >> num;
      for (int i = 0;i<num;i++)
            cin >> ws[i];
      for (int i = 0;i <= sum ; i ++ )
            dp[i] = i;
      for(int i = 1;i < num ;i++){
            for(int j = ws[i];j <= sum;j++)
                  dp[j] = min(dp[j],dp[j-ws[i]]+1);
      }
      cout << dp[sum]<<endl;
}

Measured memory_bytes: 1352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll n;
  string s;
  cin >> n >> s;
  map<char,ll> cnt;
  for(ll i=0;i<n;i++) cnt[s[i]]++;
  if(cnt['R']>cnt['B']) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int digitSum(int n){
    int res = 0;
    while(n != 0){
        res += n%10;
        n /= 10;
    }

    return res;
}

int main(){
    int N; cin >> N;
    int ans = 10000000;
    for(int a=1; a<N; a++){
        int b = N-a;

        int tmp = digitSum(a)+digitSum(b);
        ans = min(ans, tmp);
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
import math

KN = list(map(int, input().split()))
A = list(map(int, input().split()))

path = 0
lastPosition = 0

for i in range(KN[1]):
    if (i == 0):
        path = KN[0] + A[0] - A[KN[1] - 1]
        lastPosition = A[0]
    else:
        currentPosition = A[i]
        if (path < currentPosition - lastPosition):
            path = currentPosition - lastPosition
        lastPosition = currentPosition

print(KN[0] - path)

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

class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String n = br.readLine();
        int person = Integer.parseInt(n);
        long[] hi = new long[person];
        String[] str = br.readLine().split(" ");

        for (int i = 0; i < person; i++) {
            hi[i] = Long.parseLong(str[i]);
        }

        long sum = 0;
        for (int i = 1; i < person; i++) {
            if (hi[i - 1] > hi[i]) {
                long diff = (hi[i - 1] - hi[i]);
                sum += diff;
                hi[i] += diff;
            }
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 63388
n = int(input())
a = list(map(int, input().split()))
a = list(sorted(set(a)))
if len(a) == 1:
    print(a[0])
    exit()

flag = True
while flag:
    if a[0] != 0:
        for i in range(1, len(a)):
            a[i] = (a[i] % a[0])
    else:
        for i in range(2, len(a)):
            a[i] = (a[i] % a[1])
    a = list(sorted(set(a)))
    if len(a) == 2 and a[0] == 0:
        break
print(a[1])

Measured memory_bytes: 14432
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

N, M = rl()
E = defaultdict(list)
for i in range(M):
	u, v = rl()
	E[u-1].append(v-1)
S, T = rl()
S -= 1
T -= 1

queue = deque()
queue.append((S,0,0))
visited = set()
while queue:
	n, r, d = queue.popleft()
	if n == T and r == 0:
		print(d//3)
		exit()
	nr = (r+1)%3
	for m in E[n]:
		if (m, nr) in visited: continue
		visited.add((m, nr))
		queue.append((m, nr, d+1))
print(-1)

Measured memory_bytes: 124972
//
// Created by Hideaki Imamura on 2020-03-12.
//
# include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair <ll, ll> l_l;
typedef pair<int, int> i_i;

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

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

# define EPS (1e-7)
# define INF (1e9)
# define PI (acos(-1))
//const ll mod = 1000000007;

int N, a[200010];

int main() {
    cin >> N;
    for (int i = 0; i < N; ++i) cin >> a[i];

    int ans = 0;
    int cur = 1;
    for (int i = 0; i < N; ++i) {
        if (a[i] == cur) {
            cur++;
        } else {
            ans++;
        }
    }
    if (ans == N) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
import heapq
T=int(input())
for _ in range(T):
  ans=0
  N=int(input())
  Ls=[[] for _ in range(N)]
  #RsはK=Nのとき、達成不可。
  Rs=[[] for _ in range(N)]
  for _ in range(N):
    K,L,R=map(int,input().split())
    ans+=max(L,R)
    if L>R:
      Ls[K-1].append(L-R)
    if L<R:
      if K==N:
        ans-=R-L
        continue
      Rs[N-K].append(R-L)
  #先に左から
  dat=[]
  heapq.heapify(dat)
  for i in range(N):
    if not Ls[i]:
      continue
    for l in Ls[i]:
      heapq.heappush(dat,l)
    while len(dat)>i+1:
      ans-=heapq.heappop(dat)
  #次に右を
  dat=[]
  heapq.heapify(dat)
  for i in range(1,N):
    if not Rs[i]:
      continue
    for l in Rs[i]:
      heapq.heappush(dat,l)
    while len(dat)>i:
      ans-=heapq.heappop(dat)
  print(ans)
      
    
    

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

int main() {
  string s,t;cin>>s>>t;
  sort(all(s));
  sort(all(t));
  reverse(all(t));
  if(s<t)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

#define REP(i, start, count) for(int i=(start); i<(int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

typedef long long ll;
typedef unsigned long long ull;

template<class T> inline T digits(T x) {
    T count = 0;

    while (x != 0) {
        x /= 10;
        count++;
    }

    return count;
}

int N;

int main(void) {
    cin >> N;
    int count = 0;
    for (int i = 1; i <= N; ++i) {
        if (digits(i) % 2 == 1) count++;
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
/*input
2
10 -10
*/

#include <bits/stdc++.h>
using namespace std;

int main() {

	int n;
	cin >> n;
	long long a[n], b[n], c[n];
	for(int i = 0; i < n; i ++) cin >> a[i];
	b[0] = a[0];
	for(int i = 1; i < n; i ++) b[i] = a[i] + b[i-1];
	c[n-1] = a[n-1];	
	for(int i = n-2; i >= 0; i --) c[i] = c[i+1] + a[i]; 
	//for(int i = 0; i < n; i ++) cout << a[i] << " " << b[i] << " " << c[i] << endl;
	long long ans = LONG_LONG_MAX;
	for(int i = 0; i < n - 1; i ++) ans = min(ans, abs(b[i] - c[i+1]));
	cout << ans << endl;
	return 0;
}

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

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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

using namespace std;
using ll = long long;
using P = pair<int, int>;

//constexpr ll mod = 998244353;
constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

vector<int> graph[100005];
vector<P> range;
vector<int> sorted;
vector<bool> used;
vector<int> ans;

void dfs(int u) {
  used[u] = true;
  for(auto e: graph[u]) {
    if (!used[e]) {
      dfs(e);
    }
  }
  sorted.push_back(u);
}

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

  int n; cin >> n;
  rep(i, n-1) {
    int a, b; cin >> a >> b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }

  used.resize(n+1);
  range.resize(n+1, P(INT_MIN, INT_MAX));

  int k; cin >> k;
  int root;
  rep(i, k) {
    int v, p; cin >> v >> p;
    range[v].first = p;
    range[v].second = p;
    root = v;
  }

  dfs(root);

  for(int i=1; i<=n; i++) {
    used[i] = false;
  }

  for(auto c: sorted) {
    if (c == root) continue;
    used[c] = true;
    int p;
    for(auto e: graph[c]) {
      if (!used[e]) p = e;
    }
    if (range[c] == P(INT_MIN, INT_MAX)) {
      continue;
    }
    if (range[p] == P(INT_MIN, INT_MAX)) {
      range[p].first = range[c].first-1;
      range[p].second = range[c].second+1;
    } else {
      if ((range[p].first - range[c].first)%2==0) {
        cout << "No" << endl;
        return 0;
      }
      chmax(range[p].first, range[c].first-1);
      chmin(range[p].second, range[c].second+1);
      if (range[p].first > range[p].second) {
        cout << "No" << endl;
        return 0;
      }
    }
  }

  for(int i=1; i<=n; i++) {
    used[i] = false;
  }

  cout << "Yes" << endl;
  reverse(sorted.begin(), sorted.end());
  ans.resize(n+1);
  for(auto p: sorted) {
    used[p] = true;
    ans[p] = range[p].first;
    for(auto e: graph[p]) {
      if (used[e]) continue;
      chmax(range[e].first, range[p].first-1);
      chmin(range[e].second, range[p].second+1);
    }
  }

  for(int i=1; i<=n; i++) {
    cout << ans[i] << '\n';
  }
}

Measured memory_bytes: 12792
n = int(input())
a = list(map(int,input().split()))
a = sorted(a)
#print(a)
ans = 1
if a.count(0):
    print(0)
    exit()
for i in range(n):
    ans *= a[i]
    if ans > 10**18:
        print(-1)
        exit()
print(ans)


Measured memory_bytes: 21608
h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]


def dfs(x, y):
    if a[x][y] == '#':
        a[x][y] = '.'
    if x + 1 < h and a[x + 1][y] == '#':
        dfs(x + 1, y)
    elif y + 1 < w and a[x][y + 1] == '#':
        dfs(x, y + 1)


dfs(0, 0)
for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            print('Impossible')
            exit()
print('Possible')


Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll ac(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }

int main()
{
	int N, c = 1, ans = 0;
	cin >> N;
	vector<int> P(N), tP(N + 1);
	rep(i, 0, N)cin >> P[i], tP[P[i] - 1] = i;
	tP[N] = -1;
	rep(i, 0, N) {
		if (tP[i] < tP[i + 1])c++;
		else {
			ans = max(ans, c);
			c = 1;
		}
	}
	printf("%d\n", N - ans);
	return 0;
}


Measured memory_bytes: 4836
#include<stdio.h>
#include<math.h>
int main(){
    double a, b, c, angleC;
    scanf("%lf %lf %lf", &a, &b, &angleC);
    printf("%lf\n", 0.5 * a * b * sin(angleC * M_PI / 180.0));
    c = sqrt(a*a + b*b - 2*a*b* cos(angleC * M_PI / 180.0));
    printf("%lf\n", a + b + c);
    printf("%lf\n", b * sin(angleC * M_PI / 180.0));
return 0;
}



Measured memory_bytes: 2064
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
using namespace std;
typedef long long llong;

int main() {
    int N;
    cin >> N;
    map<llong, llong> m;

    bool flag = true;
    for(int i=0; i<N; ++i) {
        llong A;
        cin >> A;
        m[A] = 1;
        // if(m.find(A)!=m.end()) {
        //     m[A] = 1;
        // }
        // else {
        //     flag = false;
        //     break;
        // }
    }
    if(m.size()==N) cout << "YES" << endl;
    else cout << "NO" << endl;

    // if(flag) cout << "YES" << endl;
    // else cout << "NO" << endl;

}

Measured memory_bytes: 12800
#include <stdio.h>
 
int main()
{ 
  int x,y,r,s;
 
  scanf("%d%d", &x,&y);
 
 
 
  
  if(x<y){
    s = x;
    x = y;
    y = s;
  }
 
 
  r = x % y;
  while(r!=0){
    x = y;
    y = r;
    r = x % y;
  }
 
 
  printf("%d\n", y);
 
  return 0;
}



Measured memory_bytes: 2144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;

int rgcd(int a,int b){
	if(a<b) return rgcd(b,a);
	int r;
	while(r=a%b){
		a=b;
		b=r;
	}
	return b;
}

int main(){
	int k;cin>>k;
	ll ans=0;
	for(int i=1;i<=k;i++){
		for(int j=1;j<=k;j++){
			for(int l=1;l<=k;l++){
				ans+=rgcd(rgcd(i,j),l);
			}
		}
	}
	cout<<ans<<endl;
}

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

#define rep(i,n) for(ll i=0;i<n;i++)
#define repm(i,m,n) for(ll i=m;i<n;i++)
#define max(a,b) (((a)>(b))?(a):(b))
#define min(a,b) (((a)<(b))?(a):(b))
#define YesNo(a) (a)?cout<<"Yes"<<endl:cout<<"No"<<endl
#define YESNO(a) (a)?cout<<"YES"<<endl:cout<<"NO"<<endl
#define INF (2e9)
#define PI (acos(-1))
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007

typedef long long ll;

int a[3][3];
int b[10];
int n;

vector<vector<bool>> isHit(3, vector<bool>(3, false));

int main(){
  rep(i,3) rep(j,3) cin >> a[i][j];
  cin >> n;
  rep(i,n) cin >> b[i];

  rep(i,n) rep(j,3) rep(k,3){
    if(b[i] == a[j][k]) isHit[j][k] = true;
  }

  rep(i,3){
    bool isBingo = true;
    rep(j,3) if(isBingo) isBingo = isHit[i][j];
    if(isBingo){
      YesNo(isBingo);
      return 0;
    }
  }
  rep(i,3){
    bool isBingo = true;
    rep(j,3) if(isBingo) isBingo = isHit[j][i];
    if(isBingo){
      YesNo(isBingo);
      return 0;
    }
  }

  bool isBingo = true;
  rep(i,3) if(isBingo) isBingo = isHit[i][i];
  if(isBingo){
    YesNo(isBingo);
    return 0;
  }
  isBingo = true;
  rep(i,3) if(isBingo) isBingo = isHit[2-i][i];
  if(isBingo){
    YesNo(isBingo);
    return 0;
  }

  cout << "No" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int gcd(int x, int y){
    int v,r;
    if(x<y){
        v=x;
        x=y;
        y=v;
    }
    
    while(y>0){
        r=x%y;
        x=y;
        y=r;
    }
    
    return x;
}

int main(){
    int a,b;
    scanf("%d%d", &a, &b);
    printf("%d\n", gcd(a,b));
    
    return 0;
}


Measured memory_bytes: 2076
N = int(input())

S = input()

result = 0
E_ = 0
W_ = 0
for i in range(1, N):
    if S[i] == "E":
        E_ += 1

result = E_ + W_

for i in range(1, N):
    if S[i] == "E":
        E_ -= 1

    if S[i - 1] == "W":
        W_ += 1

    result = min(result, E_ + W_)


print(result)

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

using namespace std;

#define MOD 1000000007
#define pb push_back
#define LSB(x) ((x)&(-x))
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef vector<vd> vvd;
typedef pair<int, int> pii;
typedef pair<int, string> pis;
typedef pair<string, int> psi;
typedef map<int,int> mpii;
typedef set<int> seti;
typedef set<double> setd;
typedef multiset<int> mseti;
typedef deque<int> dqi;
typedef deque<double> dqd;
typedef unordered_map<int, int> umii;
typedef unordered_map<ll, ll> umll;
typedef unordered_set<int> usi;
typedef unordered_set<ll> usl;

int n, k;
vi ht, dp;

void solve() {
    dp[1]=0;
    for(int i = 2; i <=n; i++) {
        //int best = INT32_MAX-1e5;
        for(int j = 1; j <= k; j++) {
            if(i-j < 1) continue;
            dp[i] = min(dp[i], dp[i-j]+abs(ht[i-j]-ht[i]));
        }
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> k;
    ht.resize(n+1);
    dp.resize(n+1, INT32_MAX-1e5);
    for(int i = 1; i < n+1; i++) {
        cin >> ht[i];
    }
    solve();
    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int main()
{
	int a;
	long long b;
	cin >> a >> b;
	int arr[a];
	long long count[a], ans = 0;
	memset(count, 0, sizeof(count));
	for(int i=0; i<a; i++)
		cin >> arr[i];
	for(int i=0; i<a; i++)
	for(int j=0; j<a; j++)
		if(arr[j] < arr[i])
		{
			count[i] ++;
			if(j > i) ans += b;
			ans %= mod;
		}
	long long temp = (long long)b * (b - 1) / 2;
	temp %= mod;
	for(int i=0; i<a; i++)
	{
		ans += (long long) count[i] * temp;
		ans %= mod;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256