akhauriyash/Code-Regression huggingface dataset:
MOD = 10**9 + 7
import sys
from functools import reduce
input = sys.stdin.readline
N,K = map(int,input().split())
A = list(map(int,input().split()))

def solve(N,K,A):
    prod = lambda x,y : ((x*y) % MOD)
    if N == K:
        return reduce(prod,A,1) % MOD
    A.sort()
    minus = [a for a in A if a < 0][::-1]
    plus = [a for a in A if a > 0][::-1]


    if K % 2 == 1 and len(plus) == 0:
        if 0 in A:
            return 0
        else:
            ans = reduce(prod,minus[:K],1)
            return ans % MOD

    ans = 1
    if K % 2 == 1:
        ans *= plus[0]
        plus2 = [p*q for p,q in zip(plus[1::2],plus[2::2])]
        minus2 = [p*q for p,q in zip(minus[::-1][::2],minus[::-1][1::2])]
        cand = sorted((plus2 + minus2),reverse=True)
        if len(cand) < K//2:
            return 0
        ans *= reduce(prod,cand[:K//2],1)
        ans %= MOD
    else:
        plus2 = [p*q for p,q in zip(plus[::2],plus[1::2])]
        minus2 = [p*q for p,q in zip(minus[::-1][::2],minus[::-1][1::2])]
        cand = sorted((plus2 + minus2),reverse=True)
        if len(cand) < K//2:
            return 0
        ans *= reduce(prod,cand[:K//2],1)
        ans %= MOD
    return ans

print(solve(N,K,A))

exit()

import random
from itertools import combinations
def ans(N,K,A):
    ans = -10**10
    for itr in combinations(range(N),K):
        t = 1
        for i in itr:
            t *= A[i]
        ans = max(ans,t)
    return ans % MOD

for i in range(100):
    N = 5 
    K = random.randint(1,N)
    A = [random.randint(-10,10) for i in range(N)]
    if solve(N,K,A) != ans(N,K,A):
        print(N,K,A)
        print(solve(N,K,A),ans(N,K,A))
        exit()



Measured memory_bytes: 108224
def isdiv3 n
  if n % 3 == 0
    true
  else
    false
  end
end

def isinclude3 n
  while n != 0
    if n % 10 == 3
      return true
    else
      n /= 10
    end
  end
end

n = gets.to_i
for i in 1..n
  if isdiv3(i) || isinclude3(i)
    print " " + i.to_s
  end
end
print "\n"



Measured memory_bytes: 6856
#include <stdio.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include<math.h>
#include<bitset>
#include<iomanip>
#include<queue>
using namespace std;

int main() {
	int N,ans=0; cin >> N;
	vector<int> V(N), C(N);
	for (int i = 0; i < N; i++)cin >> V[i];
	for (int i = 0; i < N; i++)cin >> C[i];
	for (int i = 0; i < N; i++) {
		if (V[i] > C[i])ans += V[i] - C[i];
	}
	cout << ans << endl;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int H,W,ans;
char mp[2005][2005];
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Left[2005][2005],Right[2005][2005],Up[2005][2005],Down[2005][2005];
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> H >> W;
	for(int i = 1; i <= H; i++) cin >> mp[i]+1;
	for(int i = 1; i <= H; i++)
		for(int j = 1; j <= W; j++){
			if(mp[i][j]=='.'){
				Left[i][j] = Left[i][j-1]+1;
				Up[i][j] = Up[i-1][j]+1;
			}
		}
	for(int i = H; i > 0; i--)
		for(int j = W; j > 0; j--){
			if(mp[i][j]=='.'){
				Right[i][j] = Right[i][j+1]+1;
				Down[i][j] = Down[i+1][j]+1;
			}
		}
	for(int i = 1; i <= H; i++)
		for(int j = 1; j <= W; j++)
			if(mp[i][j]=='.'){
				ans = max(ans,Left[i][j-1]+Right[i][j+1]+Up[i-1][j]+Down[i+1][j]+1);
			}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 66944
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define ll long long

ll n;
char x[212345];
int f[212345];

int minus[212345];
int plus[212345];


int popc(int d){
  int sum=0;
  int tmp=d;
  while(tmp){
    if(tmp & 1) sum++;
    tmp >>= 1;}
  return sum;
}


void compf(void){
  for(int i=1;i<200000;i++){
    int p = popc(i);
    f[i]=f[i%p]+1;}
}

int main(){
  //printf("dd\n");
  scanf("%lld",&n);
  scanf("%s",x);
  compf();

  ll p=0;
  for(int i=0;i<n;i++){
    if(x[i]=='1') p++;}
  if(p==0){
    for(int i=0;i<n;i++){
      printf("1\n");}
    return 0;}
  

  ll summ=0,sump=0;

  ll tmp=1;
  /*
  for(int j=n-1;j>=0;j--){
    tmp%=p;
    a0[j]=tmp;
    tmp = tmp*2;}*/
  tmp=1;
  if(p!=1){
  for(int j=n-1;j>=0;j--){
    tmp%=p-1;
    minus[j]=tmp;
    tmp = tmp*2;}}
  
  tmp=1;
  for(int j=n-1;j>=0;j--){
    tmp%=p+1;
    plus[j]=tmp;
    tmp = tmp*2;}
  for(int j=n-1;j>=0;j--){
    if(x[j]=='1'){
      //sum0 = (sum0+a0[j])%p;
      if(p!=1) summ = (summ+minus[j])%(p-1);
      sump = (sump+plus[j])%(p+1);}
    }
    

  for(int i=0;i<n;i++){
    if(x[i]=='0'){
      ll tmp2 = (sump+plus[i])%(p+1);
      printf("%d\n",f[tmp2]+1);}
    else{
      if(p==1){
	printf("0\n");}
      else{
      ll tmp3 = (summ+(p-1)-minus[i])%(p-1);
      printf("%d\n",f[tmp3]+1);}}
  }

  //printf("%d\n",);;
  
  
  return 0;
}


Measured memory_bytes: 4260
#include <iostream>
#include <algorithm>
//#include <cstdio>
//#include <map>
//#include <cmath>
#include <vector>


using namespace std;


struct inter{ //interval
    int l,r;
};
bool  cmp(inter a,inter b){
    return a.r<b.r;
}
int main() {
    int n;
    cin >> n;
    vector<inter>num(n);
    int rob, arm;
    for (int i = 0; i < n; ++i) {
        cin >> rob >> arm;
        num[i].l = rob - arm;
        num[i].r = rob + arm;
    }
    sort(num.begin(),num.end(),cmp);
    int ans = 1;
    int temp = num[0].r;
    for (auto i:num) {
        if (i.l >= temp) {
            temp = i.r;
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
n = int(input())

a=list(map(int,input().split()))
a.sort()

from collections import Counter as cnt
aaa = dict(cnt(a))

ma = max(a)
dp = [True for i in range(ma+1)]

for i in a:
    if dp[i]:
        mul = i*2
        while mul<=ma:
            dp[mul] =False
            mul += i

mans = 0
for i,v in aaa.items():
    if dp[i] & (v == 1) :
        mans+=1

print(mans)

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

using namespace std;
#define int long long
#define double long double
#define rep(i, n) for(int i=0;i<(n);++i)
#define INF (1ll<<60)
#define FI first
#define SE second
typedef pair<int, int> pii;
#define l_b lower_bound
#define u_b upper_bound


signed main() {
    int N, M;
    cin >> N >> M;
    if (N != 1 && M != 1) {
        cout << (N - 2) * (M - 2) << endl;
        return 0;
    }
    if (N == 1 && M == 1) {
        cout << 1 << endl;
        return 0;
    }
    cout << max(N, M) - 2 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <cmath>
#include <cstring>
#include <assert.h>
#include <utility>
#include <tuple>
#include <array>
#include <bitset>

using int64 = long long;

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    
    int N;
    std::cin >> N;

    std::map<int, int> counter;
    int d = 0;
    for (int i = 0; i < N; i++) {
        int a;
        std::cin >> a;
        counter[a]++;

        d = std::max(d, a);
    }

    // std::cerr << "b" << std::endl;

    for (int x = d; x > (d + 1) / 2; x--) {
        // std::cerr << "x: " << x << " " << counter[x] << std::endl;
        if (counter[x] < 2) {
            std::cout << "Impossible" << std::endl;
            return 0;
        }
    }
    // std::cerr << "a" << std::endl;

    if ((d % 2 == 0 and counter[(d + 1) / 2] == 1) or
        (d % 2 == 1 and counter[(d + 1) / 2] == 2)) {
        std::cout << "Possible" << std::endl;
    } else {
        std::cout << "Impossible" << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x,y,z) max((x),max((y),(z)))
#define tmin(x,y,z) min((x),min((y),(z)))
typedef long long ll;ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y) {if (y == 0) return x;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x / GCD(x, y) * y;}
//cout << fixed << setprecision(10);

int main(){
  ll k, x;
  cin >> k >> x;
  if(500*k>=x)
  cout<<  "Yes" <<endl;
  else
  cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
using namespace std;
//using namespace __gnu_pbds;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long 
#define rep(i,n) for(int i=0;i<n;i++)
#define repa(i,arr,n) for(int i=arr;i<=n;i++)
#define repd(i,arr,n) for(int i=arr;i>=n;i--)
#define trav(arr,x) for(auto& arr:x)
#define all(c) c.begin(), c.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(arr) arr.size()
#define pi 3.14159265358979323846
#define MAX 500003
#define vi vector<int>
#define pii pair<int,int>
#define pqueue priority_queue<int>
#define pdqueue priority_queue<int,vi,greater<int> >
//#define endl "\n"
 
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
const int mod=998244353;
int power(int a,int b)
{
    int ans=1;
    while(b)
    {
        if(b&1)
        {
            ans=(ans*a);
        }
        a=(a*a);
        b>>=1;
    }
    return ans;
}

int32_t main()
{
    fast;
    int n,m,k,ans=0;
    cin>>n>>m>>k;
    string str[10];

    rep(i,n)
    {
        cin>>str[i];
    }

    rep(i,(1<<n))
    {
        rep(j,(1<<m))
        {
            string temp[10];
            rep(ii,n)
            {
                temp[ii]=str[ii];
            }
            int r=i,c=j;

            rep(ii,n)
            {
                if(r&(1<<ii))
                {
                    rep(jj,m) temp[ii][jj]='0';
                }
            }

            rep(jj,m)
            {
                if(c&(1<<jj))
                {
                    rep(ii,n) temp[ii][jj]='0';
                }
            }
            int cnt=0;
            rep(ii,n)
            {
                rep(jj,m)
                {
                    if(temp[ii][jj]=='#') cnt++;
                }
            }
            if(cnt==k) ans++;
        }
    }
    cout<<ans<<endl;
}   


Measured memory_bytes: 3640
fun main(args: Array<String>) {
  val a = readLine()!!.split(' ').map(String::toInt)
  val gu = a[0]*60 + a[1]
  val sl = a[2]*60 + a[3]
  var ans = sl - gu - a[4]
  if(ans < 0) ans = ans + 1440 else ans
  println(ans)
}


Measured memory_bytes: 36316
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for(auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main() {
    map<char, int> m;
    string s;
    cin >> s;
    rep(i, (int)s.size()) {
        m[s[i]]++;
    }
    for(char c = 'a'; c <= 'z'; c++) {
        if(m[c] == 0) {
            cout << c << endl;
            return 0;
        }
    }
    cout << "None" << endl;
    return 0;
}

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

int main(){
    int64_t N,cou = 0;
    cin >> N;
    for (int i = 1; i <= N; i++){
        if ((i % 3 != 0) && (i % 5 != 0)){
            cou += i;
        }
    }
    cout << cou << endl;
}

Measured memory_bytes: 3588
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>

using namespace std;

typedef long long ll;

inline ll read()
{
	ll x=0;char ch=getchar();
	while(ch<'0' || '9'<ch)ch=getchar();
	while('0'<=ch && ch<='9')x=x*10+(ch^48),ch=getchar();
	return x;
}

const int N=1e5+9;
const int md=1e9+7;

ll n,x[N],a[2],p[2],sp[2];
ll f[N][2],sumf[N][2];

int main()
{
	n=read();
	a[0]=read();a[1]=read();

	for(int i=1;i<=n;i++)
		x[i]=read();
	x[0]=-1e18;

	p[0]=p[1]=sp[0]=sp[1]=0;
	f[0][0]=f[0][1]=sumf[0][0]=sumf[0][1]=1;
	for(int i=1;i<n;i++)
	{
		for(int j=0;j<=1;j++)
		{
			while(p[j]<i && x[i+1]-x[p[j]]>=a[j])
				p[j]++;
			f[i][j]=sumf[p[j]-1][j^1];
		}
		for(int j=0;j<=1;j++)
		{
			if(x[i+1]-x[i]<a[j])
				for(;sp[j]<i;sp[j]++)
					f[sp[j]][j]=sumf[sp[j]][j]=0;
			sumf[i][j]=(sumf[i-1][j]+f[i][j])%md;
		}
	}

	printf("%lld\n",(sumf[n-1][0]+sumf[n-1][1])%md);
	return 0;
}


Measured memory_bytes: 4728
#include <iostream>
#include<stdio.h>
#include<cmath>
using namespace std;
int main()
{
    int N,s=1,temp=0;
    int a[100000];
    int b[100000]={0};
    const int c=1e9+7;
    scanf("%d",&N);
    for(int i=0;i<N;i++)
    {
        scanf("%d",&a[i]);
        if(N%2==0)
       {
           if((a[i]%2==0&&a[i])||a[i]==0) {printf("0\n");temp=0;break;}
           else
           {
               b[a[i]]++;
        if(b[a[i]]>2) {printf("0\n");temp=0;break;}
        else if(b[a[i]]==1) {s=(s*2)%c; temp=1;}
           }
       }
        else
        {
            if(a[i]%2!=0) printf("0\n");
        b[a[i]]++;
        if(b[a[i]]>2||b[0]>1) { printf("0\n");temp=0;break;}
        else if(b[a[i]]==1&&a[i]) {s=(s*2)%c; temp=1;}
        else if(b[a[i]]==1&&a[i]==0) {s=s%c;temp=1;}
        }
    }
    if(temp==1)
    printf("%d\n",s);
    return 0;
}

Measured memory_bytes: 1024
// INCLUDES
#include <bits/stdc++.h>
#include<assert.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
//DEFINES
#define MAX 1000001
#define pii pair<int, int>
#define c1 __builtin_popcount
#define F first
#define S second
#define all(s) begin(s),end(s)
#define MIN3POS(a, b, c) (a) =< (b) ? ((a) =< (c) ? 1 : 3) : ((b) =< (c) ? 2 : 3)
#define MAX3POS(a,b,c) (a) >= (b) ? ((a) >= (c) ? 1 : 3) : ((b) >= (c) ? 2:3)
#define endl '\n'
#define int long long
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define FOR(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define IOS   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//NAMESPACES
using namespace __gnu_pbds; 
using namespace std;
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    os << "["; 
    for (int i = 0; i < v.size(); ++i) { 
        cout << v[i]; 
        if (i != v.size() - 1) 
            os << ", "; 
    } 
    os << "]"; 
    return os; 
} 
template <typename T> 
ostream& operator<<(ostream& os, const set<T>& v) 
{ 
    os << "["; 
    for (auto it : v) { 
        os << it; 
        if (it != *v.rbegin()) 
            os << ", "; 
    } 
    os << "]"; 
    return os; 
} 
  template <typename T, typename S> 
ostream& operator<<(ostream& os, const map<T, S>& v) 
{ 
    for (auto it : v)  
        cout << it.first << " : " 
           << it.second << "\n"; 
      
    return os; 
} 
template <typename T, typename S> 
ostream& operator<<(ostream& os, const pair<T, S>& v) 
{ 
    os << "("; 
    cout << v.first << ", " 
       << v.second << ")"; 
    return os; 
} 
  
// D

void solve(){
    int n;
    cin>>n;
vector<char> ans;
while(n) {
    n--;
    ans.push_back('a' + n%26);
    n/=26;
}
reverse(all(ans));
for(auto val : ans) cout<<val;
}
int32_t main()
{
IOS
int t=1;
// cin>>t;
while(t--) {
    solve();
}

return 0;
}
// Use emplace back in place of pushback
// Use tie function , for object destructuring

Measured memory_bytes: 3612
#include "bits/stdc++.h"
using namespace std;
int main() {
	long long N;
	cin >> N;
	long long A, B, C, D, E;
	cin >> A >> B >> C >> D >> E;
	long long num = min({ A,B,C,D,E });
	long long groups = N / num;
	if (N % num != 0) groups++;
	cout << 5 + (groups - 1) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <numeric> //lcm


#define ERROR() cout << "ERROR!!" << endl; return 0;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)

#define debug(vec) for(auto v : vec) cout << v << " "; cout << endl;

#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cout << v << " "; cout << endl; } 

using namespace std;

typedef long long ll;

const long long int INF = 1000000000; //<10^10
//const ll MOD = 998244353;
const ll MOD = 1000000007;

inline bool maxch(int &a, int b) { if (a < b) {a = b; return true;} else return false;}

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

	int sum = 0;
	vector<int> x(n);
	rep(i, n) {
	  int _x;
	  cin >> _x;
		sum += _x;
		x[i] = _x;
	}
	int p = sum / n;
	int ans1 = 0, ans2 = 0;
	rep(i, n) {
		ans1 += (x[i] - p)* (x[i] - p);
		ans2 += (x[i] - p-1)* (x[i] - p-1);
	}

  cout << ((ans1 < ans2) ? ans1 : ans2) << endl;
	
}




Measured memory_bytes: 256
import sys
N = int(input())
D = [False] * N

for i in range(N):
    d1, d2 = map(int, input().split())
    if d1 == d2:
        D[i] = True

i = 0
while i < N:
    if D[i]:
        cnt = 0
        while i <N and D[i]:
            cnt += 1
            i += 1
        if cnt >=3:
            print('Yes')
            sys.exit(0)
    else:
        i += 1

print("No")


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

const int N = 2e3 + 11;
int a[N][N];
int b[N][N];

int f(int *a, int x) {
	for(int i = 0; i < N; i ++)
		if(a[i] == x) return i;
}
int rf(int *a, int x) {
	for(int i = N - 1; i >= 0; i --)
		if(a[i] == x) return i;
}

bool check(int n, int m, int limit) {
	int mi = 1e9L, ma = 0;
	memset(b, -1, sizeof(b));
	for(int i = 1; i <= n; i ++)
		for(int j = 1; j <= m; j ++) {
			mi = min(mi, a[i][j]);
			ma = max(ma, a[i][j]);
		}
	for(int i = 1; i <= n; i ++)
		for(int j = 1; j <= m; j ++) {
			if(a[i][j] < ma - limit && a[i][j] > mi + limit)
				return false;
			else if(a[i][j] < ma - limit)
				b[i][j] = 0;
			else if(a[i][j] > mi + limit)
				b[i][j] = 1;
		}
	for(int t = 0; t < 2; t ++) {
		vector <pair <int, int>> v;
		for(int i = 1; i <= n; i ++) {
			int c[2] = {(int)count(b[i] + 1, b[i] + m + 1, t),
				(int)count(b[i] + 1, b[i] + m + 1, 1 - t)};
			if(c[0] && c[1]) {
				int l = rf(b[i], t);
				int r = f(b[i], 1 - t) - 1;
				if(l > r) goto end;
				v.push_back({l, r});
			} else if(c[0]) {
				int l = rf(b[i], t);
				v.push_back({l, m});
			} else if(c[1]) {
				int r = f(b[i], 1 - t) - 1;
				v.push_back({0, r});
			} else
				v.push_back({0, m});
		}

		for(int _ = 0; _ < 2; _ ++) {
			bool f = true;
			int s = -1;
			for(auto p : v) {
				if(s == -1)
					s = p.first;
				else {
					while(s < p.first)
						s ++;
					if(s > p.second)
						f = false;
				}
			}
			if(f) return true;
			for(auto &p : v)
				p = {m - p.second, m - p.first};
		}

		end: ;
	}
	return false;
}

int main() {
	int n, m; cin >> n >> m;
	for(int i = 1; i <= n; i ++)
		for(int j = 1; j <= m; j ++)
			scanf("%d", &a[i][j]);
	int l = 0, r = 1e9L + 11;
	while(l + 1 < r) {
		int mid = (l + r) / 2;
		if(check(n, m, mid - 1))
			r = mid;
		else
			l = mid;
	}
	cout << l << '\n';
	return 0;
}

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

#define ll long long
#define sd(x) scanf("%d", &(x))
#define pii pair<int, int>
#define F first
#define S second
#define all(c) ((c).begin()), ((c).end())
#define sz(x) ((int)(x).size())
#define ld long double

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<", "<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"{";
	for(int i = 0;i < (int)v.size(); i++){
		if(i)os<<", ";
		os<<v[i];
	}
	os<<"}";
	return os;
}

#ifdef LOCAL
#define cerr cout
#else
#endif

#define TRACE

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

struct dsu{
    int n;
    vector<int> par;
    dsu(int n) : n(n), par(n){
        iota(par.begin(), par.end(), 0);
    }
    int root(int x){
        return x == par[x] ? x : (par[x] = root(par[x]));
    }
    bool merge(int x, int y){
        x = root(x); y = root(y);
        if(x == y) return 0;
        par[x] = y;
        return 1;
    }
};

const int N = 15;
double f[1 << N], dp[1 << N];
int x[N], y[N];
int a[N];
double Dist(int i, int j){
    return sqrt((x[i] - x[j]) * (ll) (x[i] - x[j]) + (y[i] - y[j]) * (ll) (y[i] - y[j]));
}

int main(){
    int n; sd(n);
    for(int i = 0; i < n; i++){
        sd(x[i]); sd(y[i]); sd(a[i]);
    }
    for(int mask = 1; mask < (1 << n); mask++){
        vector<pair<double, pii>> edges;
        dsu D(n);
        double val = 0;
        for(int i = 0; i < n; i++){
            if(mask >> i & 1){
                val += a[i];
                for(int j = 0; j < i; j++) if(mask >> j & 1) edges.push_back({Dist(i, j), {i, j}});
            }
        }
        sort(all(edges));
        for(auto it : edges){
            if(D.merge(it.S.F, it.S.S)) val -= it.F;
        }
        f[mask] = val / __builtin_popcount(mask);
    }
    dp[0] = 1 << 30;
    for(int mask = 1; mask < (1 << n); mask++){
        for(int submask = mask; submask; submask = (submask - 1) & mask){
            dp[mask] = max(dp[mask], min(f[submask], dp[mask ^ submask]));
        }
    }
    printf("%.10lf\n", dp[(1 << n) - 1]);
}

Measured memory_bytes: 768
#include <iostream>


using namespace std;


int main()
{
	int x, y;

	while(1){
		cin >> x >> y;
		if(x == 0 && y == 0)
			break;

		for(int i = 0; i < x; i++){
			for(int j = 0; j < y; j++){
				if((i + j) % 2)
					cout << ".";
				else
					cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 3108
import numpy as np
import math
H,W,K = map(int,input().split())
m = []
for i in range(H):
    m.append(list(input()))
m = np.array(m)
bcell = m=="#"

ans = 0
for i in range(2**H):
    r_pattern = np.array(list(format(i, f'0{H}b')))=='1'
    for j in range(2**W):
        c_pattern = np.array(list(format(j, f'0{W}b')))=='1'
        mask = r_pattern.reshape(H,1) & c_pattern.reshape(1,W)
        
        b_cell_num = np.sum(bcell&mask)
        if b_cell_num ==K:
            ans +=1
print(ans)

Measured memory_bytes: 27320
n, m, *AB = map(int, open(0).read().split())

C, D = set(), set()
for a, b in zip(AB[::2], AB[1::2]):
  if a == 1:
    C.add(b)
  if b == n:
    D.add(a)

if len(C & D):
  print('POSSIBLE')
else:
  print('IMPOSSIBLE')

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

int main() {
	string g;
	while (cin >> g, g != "#") {
		int y, m, d;
		cin >> y >> m >> d;
		if (10000 * y + m * 100 + d < 310501) cout << g << ' ' << y << ' ' << m << ' ' << d;
		else cout << '?' << ' ' << y - 30 << ' ' << m << ' ' << d;
		cout << endl;
	}
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
 
// infty
#define ULLINF (ULLONG_MAX)
#define LLINF  (LLONG_MAX)
#define IINF   (INT_MAX)
#define INF    (1<<29)
 
// math
#define Sq(x) ((x)*(x))
 
// container utility
#define ALL(x) (x).begin(), (x).end()
#define MP make_pair
#define PB push_back
#define EACH(it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();it++)
 
// rep
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
 
// typedef
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef vector<VI> VVI;
 
typedef long long ll;
 
// pair util
#define FST first
#define SND second
 
// range validator
#define CK(n,a,b) (a<=n && n<b)
 
// conversion
template<class T> inline string toStr(T a) { ostringstream oss_; oss_ << a; return oss_.str(); }
inline int toInt(string s) { return atoi(s.c_str()); }
 
// prime
bool isPrime(int a) { for(int i=2; i*i <=a; i++) if(a%i == 0) return false; return true; }
 
int const dx[] = {-1,0,1,0,-1,1,1,-1};
int const dy[] = {0,-1,0,1,-1,-1,1,1};
 
//////////////////////////////////////////////////////////////
 
 
int main() {
   
  string s;
  while(cin >> s) {
     
    int const N = s.size();
     
    if(N%2) {
      cout << "NA" << endl;
      continue;
    }
     
    string output;
     
    for(int i=0; i<N; i+=2) {
      int a = s[i]-'0'-1; if(!CK(a, 0, 6)) { cout << "NA" << endl; goto EXIT; }
      int b = s[i+1]-'0'-1; if(!CK(b, 0, 5)) { cout << "NA" << endl; goto EXIT; }
       
      char ch = (char)('a' + a*5+b);
      if(!CK(ch,'a','z'+1)) {
    if(b == 1 && a == 5) ch = '.';
    else if(b == 2 && a == 5) ch = '?';
    else if(b == 3 && a == 5) ch = '!';
    else if(b == 4 && a == 5) ch = ' ';
      }
      output += ch;
    }
    cout << output << endl;
     
  EXIT:;
  }
   
  return 0;
}

Measured memory_bytes: 1188
//Use valgrind once if the submission doesn't go through. It can detect uninitialized variables and see where they could be an issue.
#include <bits/stdc++.h>
using namespace std;

int main(){

	ios_base::sync_with_stdio(false);
    	cin.tie(NULL);

	int x,y;
	cin>>x>>y;
	if(y&1)
	{
		cout<<"No"<<endl;
	}
	else
	{
		y>>=1;
		int a=y-x,b=x-a;
		if(a>=0&&b>=0)
		{
			cout<<"Yes"<<endl;
		}
		else
		{
			cout<<"No"<<endl;
		}
	}
}


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

int main(){
	string s;
	int ans;
	cin>>s;
	for(int i=0;i<8;i++){
		ans=s[0]-'0';
		for(int j=0;j<3;j++){
			if(i&(1<<j))
				ans+=s[j+1]-'0';
			else
				ans-=s[j+1]-'0';
		}
		if(ans==7){
			cout<<s[0];
			for(int j=0;j<3;j++){
				if(i&(1<<j))
					cout<<"+"<<s[j+1];
				else
					cout<<"-"<<s[j+1];
			}
			cout<<"=7";
			return 0;	
		}
	}
}


Measured memory_bytes: 3604
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>  // std::setprecision()
#include <set>
using namespace std;
using ll = long long;
#define rep(i,a,b) for(ll i=(a); i<(b); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define pai 3.14159265358979323846
ll gcd(ll a, ll b){if (a%b == 0)  return(b);else  return(gcd(b, a%b));}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
/* map<string,int> */
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
/* 辞書順 next_permutation(a.begin(),a.end()) */
 
int main() {
    ll n,t,a;
    cin >> n >> t >>a;
    vector <ll> h(n);
    double mi = pow(10,5);
    ll count =0;
    rep(i,0,n) {
        cin >> h[i];
        // cout << (double)abs(a-(t - (double)h[i] * 0.006)) << endl;
        if (mi >(double)abs(a-(t - (double)h[i] * 0.006))) {
            mi = (double)abs(a-(t - (double)h[i] * 0.006));
            count = i+1;
        }
    }
    cout << count << endl;
}

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

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

#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (int i = (m); i < (int)(n); i++)

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

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

int main() {
    ll N, Q, a, t, p, x, l, r;
    cin >> N >> Q;
    fenwick_tree<ll> fw(N);
    REP(i, N) {
        cin >> a;
        fw.add(i, a);
    }
    REP(i, Q) {
        cin >> t;
        if (t == 0) {
            cin >> p >> x;
            fw.add(p, x);
        } else {
            cin >> l >> r;
            cout << fw.sum(l, r) << endl;
        }
    }
}

Measured memory_bytes: 8244
#include <stdio.h>
#include <math.h>

int sosu(int);

int main(){
  int n,i,c=0;
  int A[10000];
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%d",&A[i]);
    }
  for(i=0;i<n;i++){
    c+=sosu(A[i]);
  }
  printf("%d\n",c);
  return 0;
}

int sosu(int x){
  if(x<=1)return 0;
  else if(x==2)return 1;
  else if(x%2==0)return 0;
  double sq=pow(x,0.5);
  int i;
  for(i=3;i<=sq;i+=2){
    if(x%i==0){
      return 0;
    }
  }
  return 1;
}



Measured memory_bytes: 2040
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll A;
  int B, b;
  scanf("%lld %d.%d", &A, &B, &b);
  cout << A*(B*100+b)/100 << endl;
  return 0;
}


Measured memory_bytes: 3784
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC70
{
    class Program
    {
        public static long calc(long a, long b)
        {
            if (b == 0)
            {
                return a;
            }
            return calc(b, a % b);
        }

        public static long lcm(long a, long b)
        {
            return a / calc(a, b) * b;
        }

        static void Main(string[] args)
        {

            var n = int.Parse(Console.ReadLine());
            var t = new long[n];
            for (int i = 0; i < n; i++)
            {
                t[i] = long.Parse(Console.ReadLine());
            }
            for (int i = 0; i < n - 1; i++)
            {
                t[i + 1] = lcm(t[i], t[i + 1]);
            }

            Console.WriteLine(t[n - 1]);
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// --------------------------------------------------------
#define FOR(i,l,r) for (int i = (l); i < (r); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define MIN(c) *min_element(ALL(c))
#define MAX(c) *max_element(ALL(c))
#define SUM(c) accumulate(ALL(c), 0)
#define SUMLL(c) accumulate(ALL(c), 0LL)
#define SZ(c) ((int)(c).size())
#define debug(x) cerr << #x << " = " << (x) << '\n';
using P = pair<int,int>;
using VP = vector<P>;
using VVP = vector<VP>;
using VS = vector<string>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<ll>;
using VVLL = vector<VLL>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
const int INF = 1 << 30;
// const ll INF = 1LL << 62;
// --------------------------------------------------------


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);

    int N; cin >> N;
    VI X(N), Y(N); REP(i,N) cin >> X[i] >> Y[i];

    double ans = 0.0;
    int num = 0;
    FOR(i, 0, N - 1) FOR(j, i + 1, N) {
        ans += sqrt(pow(X[i] - X[j], 2) + pow(Y[i] - Y[j], 2));
        num++;
    }
    ans = (ans * (N - 1)) / num;
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 3832
#pragma comment(linker, "/STACK:64000000")
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <sstream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define y1 stupid_cmath
#define left stupid_left
#define right stupid_right
#define vi vector <int>
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))

const int inf = (int)1e9;
const int mod = inf + 7;
const double eps = 1e-9;
const double pi = acos(-1.0);

int n, a[100100];

int main(){

    cin >> n;
    for (int i = 0; i < 2 * n; i++) {
        cin >> a[i];
    }

    sort(a, a + 2 * n);

    int ans = 0;
    for (int i = 0; i < 2 * n; i += 2) ans += a[i];

    cout << ans << endl;



    return 0;
}


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

using namespace std;

int main(){
    long long int x, m ,n;
    cin>>n>>x>>m;
    long long int ans=x%m;
    long long int no=x%m;
    if(n<=m){
        for(int i=1; i<n; i++)
        {
            no=(no*no)%m;
            ans+=no;
        }
    }
    else
    {
        long long int prefixsum[100002]={0};
        unordered_map<long long int, long long int> map;
        map[no]=1;
        prefixsum[0]=0;
        prefixsum[1]=no;
        for(long int i=1; i<n; i++){
            no=(no*no)%m;
            if(map[no]>0){
                long long int length=i+1-map[no];
                ans=prefixsum[map[no]-1];
                // cout<<n/length<<" "<<prefixsum[map[no]+n%length]<<" "<<prefixsum[map[no]-1]<<endl       ;
                ans=ans+(n-map[no])/length*(prefixsum[i]-prefixsum[map[no]-1])+(prefixsum[map[no]+(n-map[no])%length]-prefixsum[map[no]-1]);
                break;
            }
            else
            {
                prefixsum[i+1]=prefixsum[i]+no;
                map[no]=i+1;
            }
            // cout<<no<<" ";
        }
    }
    cout<<ans;
}


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

int main() {
  int n;
  cin >> n;
  int s=0;
  for(int x=1; x<=n; x+=2){
    int k=0;
    for(int i=1; i<=n; i++){
      if (x%i==0) k++;
    }
    if (k==8) s++;
  }
  cout << s << endl;
}

Measured memory_bytes: 3604
using System;
using System.Collections.Generic;

//namespace _6_A

class Program
{
    static void Main(string[] args)
    {
        //???????????????3????????????????????????????????????
        string readData = Console.ReadLine();
        string readLine = Console.ReadLine();



        //readData???int??????????????????
        int n = int.Parse(readData);



        int[] ary = new int[n];
        //???????????¨???????????????
        string[] readLineValues = readLine.Split(' ');
        for (int i = 0; i < n; i++)
        {
            ary[i] = int.Parse(readLineValues[i]);
        }
        for (int i = n - 1; i >= 0; i--)
        {
            if (i == 0)
            {
                Console.WriteLine(ary[i]);
            }
            else
            {
                Console.Write(ary[i] + (" "));
            }
        }
        
    }
    
}

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

#define mx 105
#define md 1000000007

using namespace std;

char c[mx][mx];
int w, h, dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0}, ans;
struct P{int x, y, cs;};
queue<P> qu;
bool used[1005][1005] = {};

int main(){
  scanf("%d%d", &h, &w);
  for(int i = 0; i < h; i++){
    scanf("%s", c[i]);
    for(int j = 0; j < w; j++) {
      if(c[i][j] == '.') ans++;
    }
  }
  P goal = {h-1, w-1, 0};
  qu.push((P){0, 0, 1});
  used[0][0] = true;
  while(!qu.empty()){
    auto tmp = qu.front(); qu.pop();
    if(tmp.x == goal.x && tmp.y == goal.y){
      printf("%d\n", ans - tmp.cs);
      return 0;
    }
    for(int i = 0; i < 4; i++) {
      int x = tmp.x + dx[i], y = tmp.y + dy[i];
      if(0 <= x && x < h && 0 <= y && y < w && c[x][y] != '#' && !used[x][y]){
        used[x][y] = true;
        qu.push((P){x, y, tmp.cs + 1});
      }
    }
  }
  puts("-1");
}


Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<queue>
#include<map>
#include<vector>
#include <cstdlib>
#include<algorithm>
#include <cstdio>
#include <cctype>
using namespace std;
const long long INF=10000000000000LL;
typedef long long ll;
typedef pair<ll,ll> P;
ll N,M,K=1,C;
ll A,B,W;
ll T,a,b;
double v[55],D[55];
ll ans=0;
int l;
bool h;
//bool D[100005];
ll S[50][50]={};
char str1[100005],str2[4][100005];
map<string,int> m;

int main(){
	cin>>N;
	str2[0][0]='S';
	str2[0][1]='S';
	str2[1][0]='S';
	str2[1][1]='W';
	str2[2][0]='W';
	str2[2][1]='S';
	str2[3][0]='W';
	str2[3][1]='W';
	for(int i=0;i<N;++i){
		cin>>str1[i];
	}
	str1[N]=str1[0];
	for(int i=0;i<4;++i){
		l=0;
		for(int j=1;j<N+1;++j){
			if(str2[i][j]=='S'){
				if(str1[j]=='o')str2[i][j+1]=str2[i][j-1];
				if(str1[j]=='x'&&str2[i][j-1]=='S')str2[i][j+1]='W';
				if(str1[j]=='x'&&str2[i][j-1]=='W')str2[i][j+1]='S';
			}
			if(str2[i][j]=='W'){
				if(str1[j]=='x')str2[i][j+1]=str2[i][j-1];
				if(str1[j]=='o'&&str2[i][j-1]=='S')str2[i][j+1]='W';
				if(str1[j]=='o'&&str2[i][j-1]=='W')str2[i][j+1]='S';
			}

		}
		//for(int j=0;j<N+2;++j)cout<<str2[i][j];
		//cout<<endl;
		if(str2[i][0]==str2[i][N]&&str2[i][1]==str2[i][N+1]){
			for(int j=0;j<N;++j)cout<<str2[i][j];
			cout<<endl;
			h=true;
			break;
		}
	}
	if(!h)cout<<-1<<endl;
	return 0;
}


Measured memory_bytes: 896
import java.util.*;


class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int [] in = new int[n];
        for(int i=0;i<n;i++) in[i] = sc.nextInt();
        int mx = Integer.MIN_VALUE;
        int mn=in[0];
        for(int i = 1; i<n;i++)
        {
            if(mx<in[i]-mn)
            {
                mx = in[i]-mn;
            }
            if(mn>in[i]) mn = in[i];
        }
        System.out.println(mx);
    }
}   





Measured memory_bytes: 100556
N, M = map(int, input().split())
L_max = -1
R_min = N
for _ in range(M):
	l, r = map(int, input().split())
	L_max = max(L_max, l)
	R_min = min(R_min, r)
	

print(max(R_min - L_max + 1, 0))


Measured memory_bytes: 3060
N, C = map(int, input().split())
x = []
v = []
for _ in range(N):
    xi, vi = map(int, input().split())
    x.append(xi)
    v.append(vi)
vsp = [0] * (N + 1)
vsn = [0] * (N + 1)
dprp = [0] * (N + 1)
dprn = [0] * (N + 1)
dpsp = [0] * (N + 1)
dpsn = [0] * (N + 1)
for i in range(N):
    vsp[i + 1] = vsp[i] + v[i]
    vsn[i + 1] = vsn[i] + v[N - 1 - i]
    dprp[i + 1] = max(dprp[i], vsp[i + 1] - 2 * x[i])
    dpsp[i + 1] = max(dpsp[i], vsp[i + 1] - x[i])
    dprn[i + 1] = max(dprn[i], vsn[i + 1] - 2 * (C - x[N - 1 - i]))
    dpsn[i + 1] = max(dpsn[i], vsn[i + 1] - (C - x[N - 1 - i]))
ans = 0
for i in range(N + 1):
    ans = max(ans, dprp[i] + dpsn[N - i], dprn[i] + dpsp[N - i])
print(ans)


Measured memory_bytes: 33108
#include"iostream"
using namespace std;
int search(int a[], int n, int key);
int main()
{
	int m, n,i,k=0;
	cin >> m;
	int* s = new int[m];
	for (i = 0; i < m; ++i)
		cin >> s[i];
	cin >> n;
	int* t = new int[n];
	for (i = 0; i < n; ++i)
	{
		cin >> t[i];
		if (search(s, m, t[i]))++k;
	}
	cout << k << endl;
	return 0;
}
int search(int a[], int n, int key)
{
	int left = 0, right = n - 1;
	int mid;
	while(left<=right)
	{
		mid = (left + right) / 2;
		if (a[mid] == key)break;
		else if (a[mid] > key)right = mid-1;
		else left = mid+1;
	}
	return left <= right;
}


Measured memory_bytes: 3676
n = int(input())
li = list(map(int,input().split()))
if 0 in li:
    print(0)
    exit()

ans = li[0]
for i,l in enumerate(li):
    if i == 0:
        continue
    else:
        #print(l,'l')
        ans *= l
        if ans > 10**18:
            print(-1)
            exit()
        #print(ans)
if ans > 10**18:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 21644
#include <iostream>
#include <stack>
#include <string>

using namespace std;

int main()
{
	while (true)
	{
		string target;
		getline(cin, target);
		if (target == ".") break;
		stack<char> hako;
		bool flag = true;
		for (int i = 0; i < target.size(); i++)
		{
			if (target[i] == '(')
			{
				hako.push('(');
			}
			else if(target[i] == '['){
				hako.push('[');
			}
			else if (target[i] == ')')
			{
				if (!hako.empty() && hako.top() == '(')
				{
					hako.pop();
				}
				else {
					cout << "no" << endl;
					flag = false;
					break;
				}
			}
			else if (target[i] == ']')
			{
				if (!hako.empty() && hako.top() == '[')
				{
					hako.pop();
				}
				else {
					cout << "no" << endl;
					flag = false;
					break;
				}
			}
		}
		if (hako.empty() && flag)
		{
			cout << "yes" << endl;
		}
		else if(flag){
			cout << "no" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3116
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include<cstring>
#include <climits>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

#define INF INT_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)


long dp[51][51][2551];


void show_dp(int N,int M, int S){
	
	REP(i,N){
		REP(j,M){
			REP(k,S){
				cout<<dp[i][j][k]<<"|";
			}
			cout<<endl;
		}
		cout<<"---------------------------------"<<endl;
	}
}



int main(){
	
	int N,A,M,S;
	vector<int> data;
	
	memset(dp,0,sizeof(dp));

	cin>>N>>A;
	
	data.resize(N);
	int max = 0;
	REP(i,N){
		cin>>data[i];
		if(max < data[i])max = data[i];
	}
	

	S = max * N;
	
	dp[0][0][0] = 1;
	for(int i = 1; i <= N; i++){
		for(int j = 0; j <= N; j++){
			for(int k = 0; k <= S; k++){

				if(k < data[i-1]){	
					dp[i][j][k] = dp[i-1][j][k];
				}
				else if(j > 0){
					dp[i][j][k] = dp[i-1][j][k] + dp[i-1][j-1][k - data[i-1]];
				}
			}
		}
	}
//	show_dp(N+1,N+1,S+1);
	
	long sum = 0;
	for(int i = 1; i <= N;i++){
		sum += dp[N][i][i*A];
	}
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 52096
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int A[N], B[N], C[N];
  for (int i = 0; i < N; i++) cin >> A[i];
  for (int i = 0; i < N; i++) cin >> B[i];
  for (int i = 0; i < N; i++) cin >> C[i];
  sort(A, A + N);
  sort(B, B + N);
  sort(C, C + N);
  long long tmp[N + 1];
  tmp[0] = 0;
  for (int i = 0; i < N; i++) tmp[i + 1] = lower_bound(A, A + N, B[i]) - A;
  for (int i = 1; i <= N; i++) tmp[i] += tmp[i - 1];
  long long ans = 0;
  for (int i = 0; i < N; i++) ans += tmp[lower_bound(B, B + N, C[i]) - B];
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 5576
#include <bits/stdc++.h>
using namespace std;
const int dx[]={0,1,0,-1,1,-1,-1,1};
const int dy[]={-1,0,1,0,1,1,-1,-1};
const int INF = 1<<30;
const double EPS = 1e-8;
#define PB push_back
#define mk make_pair
#define fi first
#define se second
#define ll long long
#define reps(i,j,k) for(int i = (j); i < (k); i++)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
typedef pair<int,int> Pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
string s;
int INDEX;
int number();
int factor();
int term();
int expr();
int number(){
    int n = s[INDEX] - '0';
    INDEX++;
    while(isdigit(s[INDEX])){
        n = n*10 + s[INDEX] - '0';
        INDEX++;
    }
    return n;
}
int factor(){
    if(isdigit(s[INDEX])) return number();
    INDEX++;
    int ret = expr();
    INDEX++;
    return ret;
}
int term(){
    int val = factor();
    while(s[INDEX] == '*' || s[INDEX] == '/'){
        char op = s[INDEX];
        INDEX++;
        int tmp = factor();
        if(op == '*') val *= tmp;
        else val /= tmp;
    }
    return val;
}
int expr(){
    int val = term();
    while(s[INDEX] == '+' || s[INDEX] == '-'){
        char op = s[INDEX];
        INDEX++;
        int tmp = term();
        if(op == '+')val += tmp;
        else val -= tmp;
    }
    return val;
}
int main(){
    int N;
    cin >> N;
    while(N--){
        INDEX = 0;
        cin >> s;
        cout << expr() << "\n";
    }
    return 0;
}

Measured memory_bytes: 1204
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let s: String = read();

    let count = s.chars().filter(|&c| c == 'o').count();
    let ans = if count + 15 - s.len() >= 8 {
        "YES"
    } else {
        "NO"
    };

    println!("{}", ans);
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


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

public class Main{
    public static void main(String args[])throws IOException{
      try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
        String str = br.readLine();
        int total = Integer.parseInt(str);
        int result = 0;
        
        List<Integer> money_list = new ArrayList<>(Arrays.asList(100, 101, 102, 103, 104, 105));
        
        // for algorithm
        boolean[][] dp = new boolean[money_list.size()+1][total+1];
        
        for(int i = 0; i < money_list.size()+1; i++){
          Arrays.fill(dp[i], false);        
        }

        dp[0][0] = true;

        //algorithm
        for(int i = 0; i < money_list.size(); i++){
          for(int j = 0; j <= total; j++){
            if(dp[i][j]){
              dp[i+1][j] = true;
            }
            
            if(j >= money_list.get(i)){
              if(dp[i][j-money_list.get(i)]){
                dp[i+1][j] = true;
                dp[i][j] = true;
              }
            }

          }
        }

        for(int i = 1; i < money_list.size()+1; i++){
          if(dp[i][total]){
            result = 1;
          }
        }

        System.out.println(result);

      }
    }
}

Measured memory_bytes: 23124
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
  int A, B;
  cin >> A >> B;
  int ans[] = {2*A -1, A+B, 2*B - 1};
  cout << max({ans[0], ans[1], ans[2]}) << endl;
  return 0;
}

Measured memory_bytes: 256