akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll, ll> Pll;
typedef pair<int, Pii > P1;

#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define mp1(a,b,c) P1(a,P(b,c))
#define get_arsize(a) (sizeof(a)/sizeof(a[0]))

const ll MOD = 1000000007;
const double EPS = 1e-10;
const int MAX = 200000;

ll getdiff(ll a, ll b) {
  ll first = a * a * (a * a + a * b + b * b);
  ll last = b * b * b * (a + b);
  return (a-b) * (first + last);
}

int main() {
  //init();
  ll x;
  cin >> x;
  for(int i = 0; i <= 100000; ++i) {
    for(int j = i; j <= 100000; ++j) {
      ll diff = getdiff(i, j);
      ll diff2 = getdiff(-i, j);
      ll diff3 = getdiff(i, -j);
      ll diff4 = getdiff(-i, -j);
      if(diff == x) {
        cout << i << " " << j << endl;
        return 0;
      }
      if(diff2 == x) {
        cout << -i << " " << j << endl;
        return 0;
      }
      if(diff3 == x) {
        cout << i << " " << -j << endl;
        return 0;
      }
      if(diff4 == x) {
        cout << -i << " " << -j << endl;
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 3616
//in the name of god
#include <bits/stdc++.h>
using namespace std;
#define MAX_N (int)1e5+20
#define INF 1e9+20
#define pb push_back
#define F first
#define S second
typedef long long LL;
typedef pair<int,int> pii;
const int delta=(int)1e9+7;
vector<int>v;
int n,k,ans;
void f(int a=1,int b=0){
	if(b==n){
		v.pb(a);
		return;
	}
	f(a+k,b+1);
	f(2*a,b+1);
}
int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin>>n>>k;
	f();
	sort(v.begin(),v.end());
	ans=v[0];
	cout<<ans;
	return cout<<endl,0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
 
int main(){
    string S;
    cin>>S;
    if(*S.begin()=='A'){
        
        ll cnt=0;
        ll id=0;
        rep(i,2,S.size()-1){
            if(S[i]=='C'){
                cnt++;
                if(cnt==1)id=i;
            }
        }
        
        ll flg=1;
        rep(i,0,S.size()){
            if(i==0||i==id)continue;
            
            if (islower(S[i]))flg*=1;
            else flg*=0;

        }

        if(cnt==1&&flg==1){cout<<"AC"<<endl;return 0;}
    }
    cout<<"WA"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <map>
#define MAXN 200010
using namespace std;
typedef long long ll;
int N;
ll A[MAXN];
map <ll, int> M;
inline void _read(int &x)
{
	x = 0;
	register int y = 1;
	char t = getchar();
	while (!isdigit(t) && t != '-') t = getchar();
	if (t == '-')
	{
		y = -1;
		t = getchar();
	}
	while (isdigit(t))
	{
		x = x * 10 + t - '0';
		t = getchar();
	}
	x *= y;
}
inline void _read(ll &x)
{
	x = 0;
	register ll y = 1;
	char t = getchar();
	while (!isdigit(t) && t != '-') t = getchar();
	if (t == '-')
	{
		y = -1;
		t = getchar();
	}
	while (isdigit(t))
	{
		x = x * 10 + t - '0';
		t = getchar();
	}
	x *= y;
}
int main()
{
	_read(N);
	for (int i = 1; i <= N; ++i) _read(A[i]);
	M[0] = 1;
	ll ans = 0;
	for (int i = 1; i <= N; ++i)
	{
		A[i] += A[i - 1];
		ans += M[A[i]];
		M[A[i]] += 1;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
using ull = unsigned long long;
using ul = unsigned;
using ll = long long;
#define mod 10e+7+7
#define rep(i,a,b) for (int i =a;i<b;++i)
using namespace std;
void solve();
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin); 
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
#endif
	int t=1;
	//cin>>t;
	while(t--)
	{
	solve();
	 cout<<"\n";
	}
	
	cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
	return 0;

}
void solve()
{
	int n,k;
	cin>>n>>k;
	int h[n];
	rep(i,0,n)
	cin>>h[i];
	int dp[n];
	dp[0]=0;
	dp[1]=abs(h[1]-h[0]);
	for(int i=2;i<n;i++)
	{
		int min =INT_MAX;
		int j=1;
		while(j<=k&&i-j>=0)
		{
			if((dp[i-j]+abs(h[i]-h[i-j]))<min)
				min=dp[i-j]+abs(h[i]-h[i-j]);
			j++;
			//cout<<min<<" ";
		}
		//cout<<endl;
		dp[i]=min;
		//cout<<dp[0]<<" "<<endl;;
	}
	cout<<dp[n-1];
}

Measured memory_bytes: 4500
#include<bits/stdc++.h>
using namespace std;
int ans;
void shuru()
{
    
    string s,k;
    cin>>s>>k;
    s+=k;
    for(int i=0;i<s.length();i++)
        ans=ans*10+s[i]-'0';
}
int main()
{
    shuru();
    if((int)sqrt(ans)==sqrt(ans))cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool e[26];
int main() {
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
        e[s[i] - 'a'] = true;
    }
    for (char x = 'a'; x <= 'z'; x++) {
        if (!e[x - 'a']) {
            cout << x << endl;
            return 0;
        }
    }
    cout << "None" << endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;


int main()
{
	string a;
	cin >> a;
	if(a == "ABC")
	{
		cout << "ARC";
	}
	else
	{
		cout << "ABC";
	}
}



Measured memory_bytes: 3596
import sys

alpha = 'abcdefghijklmnopqrstuvwxyz'
dic = {c:0 for c in alpha}

t = sys.stdin.read()

for s in t:
    s = s.lower()
    if s in alpha:
        dic[s] += 1

for i in sorted(dic):
    print("{} : {}".format(i,dic[i]))

Measured memory_bytes: 7584
#include "bits/stdc++.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define repf(i, x, n) for (int i = (int)(x); i < (int)(n); i++)
#define repfr(i, x, n) for (int i = (int)(x)-1; i >= (int)(n); i--)
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#define INF 1e9
using ll = int64_t;
#define waru 1000000007

void Main() {
  string s;
  std::cin >> s;
  rep(i, sz(s)) {
    if (i % 2 == 0) {
      std::cout << s[i];
    }
  }

  return;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 592
#include <algorithm>
#include <cmath>
#include <iostream>

int pow2(int i) {
	return std::pow(i, (double) 2);
}

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

	int in[3];
	for (int i = 0; i < n; i++) {
		std::cin >> in[0] >> in[1] >> in[2];
		std::sort(in, in + 3);
		if (pow2(in[2]) == pow2(in[0]) + pow2(in[1]))
			std::cout << "YES" << std::endl;
		else
			std::cout << "NO" << std::endl;
	}
}

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

int main() {
  int N;
  cin>>N;
  for(int i=0;i<N;i++){
    string S;
    cin>>S;
    if(S=="Y"){
      cout<<"Four"<<endl;
      break;
    }
    if(i==N-1){
      cout<<"Three"<<endl;
    }
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		if (a % 3 == 0){
			System.out.println("Possible");
		}
		else if (b % 3 == 0){
			System.out.println("Possible");
		}
		else if ((a+b) % 3 == 0){
			System.out.println("Possible");
		}
		else{
			System.out.println("Impossible");
		}
		
		sc.close();
	}
}


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

vector<long long> divisor(long long N) {
  vector<long long> res;
  for (long long i = 1; i * i <= N; i++) {
    if (N % i == 0) {
      res.push_back(i);
      if (i * i != N) res.push_back(N / i);
    }
  }
  sort(res.begin(), res.end());
  return res;
}

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

  vector<long long> A = divisor(N - 1);
  vector<long long> B = divisor(N);

  set<long long> s;
  for (long long x : A) s.insert(x);
  for (long long x : B) s.insert(x);

  int ans = 0;
  for (long long x : s) {
    if (x == 1) continue;
    long long now = N;
    while (now >= x) {
      if (now % x == 0) now /= x;
      else now %= x;
    }
    if (now == 1) ans++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 640
W, H = map(int,input().split())
arr = [input() for j in range(W)]
ans = 'Yes'

for i in range(0, W):
    for j in range(0, H):
        t = 0
        if arr[i][j] == '#':
            for k in (-1, 1):
                if (-1 < i+k < W):
                    if arr[i+k][j] == '#':
                        t = 1
                        break
                        
                if (-1 < j+k < W):
                    if arr[i][j+k] == '#':
                        t = 1
                        break
            if t == 0:
                ans = 'No'
                break
                
print(ans)
          

Measured memory_bytes: 3064
b1,b2,b3=map(int,input().split())
if (b1==1 and b2==0 and b3==0):
    print("Close")
elif (b1==0 and b2==1 and b3==0):
     print("Close")
elif(b1==0 and b2==0 and b3==0):
    print("Close")
elif(b1==1 and b2==1 and b3==0):
    print("Open")
elif(b1==0 and b2==0 and b3==1):
    print("Open")


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	int n;
	cin>>n;
	vector<int> a(n),b(n),c(n);
	for(int& x:a) cin>>x;
	for(int& x:b) cin>>x;
	for(int& x:c) cin>>x;
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	sort(c.begin(),c.end());
	vector<ll> way(n,0);
	for(int i=0,j=-1;i<n;++i){
		while(j+1<n&&a[j+1]<b[i]) j++;
		way[i]=j+1;
	}
	ll sum=0,res=0;
	for(int i=0,j=-1;i<n;++i){
		while(j+1<n&&b[j+1]<c[i]) sum+=way[++j];
		res+=sum;
	}
	cout<<res<<'\n';
}



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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    vector<ll> c(n);
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
        p[i]--;
    }
    for (int i = 0; i < n; ++i) {
        cin >> c[i];
    }

    ll res = -LINF;
    for (int i = 0; i < n; ++i) {
        int index = i;
        ll sum = 0;
        int size = 0;
        while(1){
            index = p[index];
            sum += c[index];
            size++;
            if (index == i) break;
        }

        index = i;
        ll sum_rem = 0;
        for (int j = 0; j < size; ++j) {
            if (j == k) break;

            index = p[index];
            sum_rem += c[index];
            res = max(res, sum_rem + (k - j - 1) / size * max(0LL, sum));
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 3672
//
//  main.cpp
//  ABC124
//
//  Created by hiroaki on 2019/05/07.
//  Copyright © 2019年 hiroaki. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>


//pair sort firstに揃う

#define int long long
#define pb(n) push_back(n)
#define Rap(n,i) for(int (i)=0;(i)<(n);(i)++)
#define Pr(n) cout<<n<<endl;
#define PairV vector<pair<int , int> >
#define F first
#define S second
#define Vector1  vector<int>
#define vector2 vector<vector<int> >
#define index(v,x) find((v).begin(), (v).end(), (x))-(v).begin()
#define ctoi(c) (int)(c-'0')
#define incin(n) int (n); cin>>(n);
#define stcin(s) string (s); cin>>(s);
#define all(v) (v).begin() , (v).end()
#define PI 3.14
#define Rad2Deg  57.29578
#define INF 1000000000000

using namespace std;

int MD(pair<int,int> a,pair<int,int> b){//ManhattanDisRance
    return abs(a.first-b.first) + abs(a.second-b.second);
}
int MOD(int a,int b){
    return abs(a%b);
}

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

    stcin(n);
    int sum = 0;
    Rap(n.size(),i){
        sum += ctoi(n[i]);
    }
    if(atoi(n.c_str())%sum==0){
        Pr("Yes");
    }else{
        Pr("No");
    }
    return 0;
}


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


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

	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif

	int n;
	cin >> n;
	long long int a[n+1];
	long long int s=0;
	for(int i=0;i<n;i++){
		cin >> a[i+1];
		s+=a[i+1];
	}
	long long int dp[n+1][n+1][2];
	for(int l=1;l<=n;l++){
		if(l==1){
			for(int i=1;i<=n;i++){
				dp[i][i][0]=a[i];
				dp[i][i][1]=0;
			}
		}
		else{
			for(int i=1;i+l-1<=n;i++){
				dp[i][i+l-1][0]=max(a[i]+dp[i+1][i+l-1][1],dp[i][i+l-2][1]+a[i+l-1]);
				dp[i][i+l-1][1]=min(dp[i+1][i+l-1][0],dp[i][i+l-2][0]);
			}
		}
	}
	cout << 2*dp[1][n][0]-s;



	
	




	

}


Measured memory_bytes: 140672
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sqr(x) ((x)*(x))
#define mp make_pair
#define uint unsigned
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){
	int x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(int a){
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
	write(a); puts("");
}
#define int ll
const int N=310;
int answ,n,ans[N];char s[N][N],t[N][N];
signed main(){
	n=read();
	for(int i=1;i<=n;i++)scanf("%s",s[i]+1);
	for(int i=0;i<n;i++)ans[i]=1;
	for(int i=1;i<=n;i++)for(int j=1;j<=n;j++){
		for(int k=0;k<n;k++){
			ll x=i+k,y=j-k+n+n;
			for(;x>n;x-=n);
			for(;y>n;y-=n);
			ans[(i-j+k+n*10)%n]&=s[i][j]==s[x][y];
		}
	}
	for(int i=0;i<n;i++)answ+=ans[i]*n;
	writeln(answ);
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>

int main() {
  int cnt[1000000];
  for (int i = 0; i < 1000000; ++i) cnt[i] = 0;
  for (int i = 2; i < 1000000; ++i) {
    bool is_prime = true;
    for (int j = 2; j*j <= i; ++j) {
      if ((i % j) == 0) {
        is_prime = false;
        break;
      }
    }
    cnt[i] = cnt[i-1];
    if (is_prime)
      ++cnt[i];
  }
  int n;
  while(std::scanf("%d",&n) != EOF) {
    std::cout << cnt[n] << std::endl;
  }
  return 0;
}

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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const ll INF = 1e18;
const ll inf = 1e9;


void solve()
{
  string S;
  cin >> S;
  int l = S.size();
  string ans="AC";
  if (S[0]!='A') {
    ans="WA";
  }
  int c=0;
  for (int i=1; i<l; i++) {
    if (isupper(S[i])) {
      if (i==1||i==l-1||S[i]!='C') ans="WA";
      c++;
    }
  }
  if (c!=1) ans="WA";

  cout << ans << endl;
}

int main()
{
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll = long long;
int main() {
  string a,b;
  cin>>a>>b;
  ll c=a.size();
  string d="Yes";
  for(ll i=0;i<c;i++){
    if(a.at(i)!=b.at(i)){
      d="No";
      break;
    }
  }
  cout<<d<<endl;
  
}


Measured memory_bytes: 3628
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)
	switch s {
	case "a", "e", "i", "o", "u":
		fmt.Println("vowel")
	default:
		fmt.Println("consonant")
	}
}

func Min(x, y int64) int64 {
	if x < y {
		return x
	}
	return y
}

func Max(x, y int64) int64 {
	if x > y {
		return x
	}
	return y
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
#define INF (1e9)

const string YES = "Yes";
const string NO = "No";

int main() {
  ll X;
  cin >> X;
  ll Y;
  cin >> Y;

  if (Y % 2 == 0 and X * 2 <= Y and Y <= X * 4)
    cout << YES << endl;
  else
    cout << NO << endl;
}


Measured memory_bytes: 3636
Dice = Struct.new(:top, :south, :east, :west, :north, :bottom) do
  def self.init(labels)
    labels = labels.dup.freeze
    raise ArgumentError, "length of labels should be 6" unless labels.count == 6

    new(*labels)
  end

  def rotate(direction)
    case direction
    when ?N then rotate_northward
    when ?S then rotate_southward
    when ?E then rotate_eastward
    when ?W then rotate_westward
    when ?R then rotate_right
    when ?L then rotate_left
    else raise ArgumentError, "direction should be N, S, E, W, L or R, but #{direction} was given."
    end
  end

  def labels
    [top, south, east, west, north, bottom]
  end

  def rotate_westward
    a,b,c,d,e,f = labels
    self.class.init([c,b,f,a,e,d])
  end

  def rotate_eastward
    c,b,f,a,e,d = labels
    self.class.init([a,b,c,d,e,f])
  end

  def rotate_southward
    a,b,c,d,e,f = labels
    self.class.init([e,a,c,d,f,b])
  end

  def rotate_northward
    e,a,c,d,f,b = labels
    self.class.init([a,b,c,d,e,f])
  end

  def rotate_left
    a,b,c,d,e,f = labels
    self.class.init([a,d,b,e,c,f])
  end

  def rotate_right
    a,d,b,e,c,f = labels
    self.class.init([a,b,c,d,e,f])
  end

  def same?(other)
    self.all_state.include?(other)
  end

  def [](index)
    raise ArgumentError, "index should be in 1 to 6" unless (1..6).include?(index)

    labels[index-1]
  end

  def all_state
    ('WNWNWN'.chars.flat_map{|c|[c,*[?R]*4]}).reduce([self]){|dices, inst|
      dices + [dices[-1].rotate(inst)]
    }
  end
end

puts gets.to_i.times.map {
  labels = gets.split.map(&:to_i)
  dice = Dice.init(labels)
}.combination(2).any?{|a, b| a.same?(b) } ? 'No' : 'Yes'



Measured memory_bytes: 7448
# A,Bそれぞれの最大値は40 * 10である
# dp[i][j] = Aがiグラム、Bがjグラム含まれた薬品の最小コスト

import sys
readline = sys.stdin.readline

N,Ma,Mb = map(int,readline().split())
INF = 10 ** 10
dp = [[INF] * (401) for i in range(401)]
dp[0][0] = 0

for _ in range(N):
  a,b,c = map(int,readline().split())
  for i in range(len(dp) - 1, -1, -1):
    for j in range(len(dp[i]) - 1, -1, -1):
      if dp[i][j] == INF:
        continue
      dp[i + a][j + b] = min(dp[i + a][j + b], dp[i][j] + c)

ans = INF
import math
for i in range(1, len(dp)):
  for j in range(1, len(dp)):
    g = math.gcd(i,j)
    if i // g == Ma and j // g == Mb:
      if ans > dp[i][j]:
        ans = dp[i][j]
      
if ans == INF:
  print(-1)
else:
  print(ans)

Measured memory_bytes: 10884
tail -1 |
sed 's/ /\n/g' |
while read a; do
    # bc <<< "obase=2;$a" | sed 's/^.*1\(0*\)$/\1/' | tr -d '\n' | wc -c
    c=0
    while (( $(( a % 2 == 0 )) )); do
        a=$(( a / 2 ))
        c=$(( c + 1 ))
    done
    echo $c
done |
awk '
BEGIN { ans = 100000 }
{ ans = ans < $1 ? ans : $1 }
END {print ans}'  # take minimum


Measured memory_bytes: 804
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
    private static int row, col;
    private static char[][] chars;
    private static int[][] dis;
    private static int sx, sy;
    private static int[] x_mov = {-1, 0, 1, 0}, y_mov = {0, -1, 0, 1};
    private static class Pair {
        private int x;
        private int y;
        private Pair(int x, int y) {this.x = x; this.y = y;}
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        row = in.nextInt();
        col = in.nextInt();
        int n = in.nextInt();
        chars = new char[row][];
        dis = new int[row][col];
        for (int i = 0; i < row; i++) {
            chars[i] = in.next().toCharArray();
        }
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < col; j++) {
                if (chars[i][j] == 'S') {sx = i; sy = j;}
            }
        }
        int answer = 0;
        for (int i = 1; i <= n; i++) {
            answer += bfs(sx, sy, i);
        }
        System.out.println(answer);
    }
    private static int bfs(int x, int y, int health) {
        Queue<Pair> q = new LinkedList<>();
        int INF = 1000000;
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < col; j++) {
                if (i == x && j == y) dis[i][j] = 0;
                else dis[i][j] = INF;
            }
        }
        q.add(new Pair(x, y));
        while (!q.isEmpty()) {
            Pair start = q.peek(); q.poll();
            if (Character.isDigit(chars[start.x][start.y]) && Character.getNumericValue(chars[start.x][start.y]) == health) {
                sx = start.x; sy = start.y;
                break;
            }
            for (int i = 0; i < 4; i++) {
                int nx = start.x + x_mov[i], ny = start.y + y_mov[i];
                if (0 <= nx && nx < row && 0 <= ny && ny < col &&
                        chars[nx][ny] != 'X' && dis[nx][ny] == INF) {
                    q.add(new Pair(nx, ny));
                    dis[nx][ny] = dis[start.x][start.y] + 1;
                }
            }
        }
        return dis[sx][sy];
    }
}

Measured memory_bytes: 107344
a,b,k=map(int,input().split())
for i in range(k):
    if i%2==0:
        if a%2==1:
            a-=1
        b+=a//2
        a=a//2
    else:
        if b%2==1:
            b-=1
        a+=b//2
        b=b//2
print(a,b)


Measured memory_bytes: 2940
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

int main() {
    ll a, b;
    cin >> a >> b;
    if (abs(a + b) % 2 == 0) {
        cout << (a + b) / 2 << "\n";
    } else {
        cout << "IMPOSSIBLE"
             << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
while True:
    x=input().split(" ")
    a=int(x[0])
    op=x[1]
    b=int(x[2])
    if op == "+":
        print(a + b)
    elif op == "-":
        print(a - b)
    elif op == "*":
        print(a * b)
    elif op == "/":
        print(a // b)
    elif op == "?":
        break


Measured memory_bytes: 5596
#include <bits/stdc++.h>
#define mem(s,t) memset(s,t,sizeof(s))
#define pb(s) push_back(s)
#define inf 0x3f3f3f3f
#define mn 100010
typedef long long ll;
using namespace std;
struct node{
	node(){}
	node(int i,int n):i(i),n(n){}
	int i,n;
	bool operator<(const node& t)const{return n<t.n;}
};
int P[200010];
int main()
{
	int n,k;scanf("%d%d",&n,&k);
	for(int i=0;i<n;++i)scanf("%d",P+i);
	int lis=1;
	priority_queue<node> qa,qi;
	for(int i=0;i<k;++i){
		if(i&&P[i]>P[i-1])++lis;
		else lis=1;
		qa.push(node(i,P[i]));
		qi.push(node(i,-P[i]));
	}
	int ans=1;
	bool ok=1;
	if(lis>=k)ok=0;
	for(int i=k;i<n;++i){
		while(!qa.empty()&&qa.top().i<=i-k)qa.pop();
		while(!qi.empty()&&qi.top().i<=i-k)qi.pop();
		if(P[i]>P[i-1])++lis;
		else lis=1;
		if(P[i-k]<-1*qi.top().n&&P[i]>qa.top().n);
		else if(lis>=k){
			if(ok)ok=0,++ans;
		}
		else ++ans;
		qa.push(node(i,P[i]));
		qi.push(node(i,-P[i]));
	}
	printf("%d\n",ans);
    return 0;
}



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

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> t(s.size());
    for (int i = 0; i < s.size(); i++) t[i] = s[i] - 'A';
    for (int i = 0; i < s.size(); i++) t[i] = (t[i] + n) % 26;
    for (int i = 0; i < s.size(); i++) cout << (char)(t[i] + 'A');
    cout << endl;
}

Measured memory_bytes: 384
data = input()
S = [c for c in data]
S_inverse = list(reversed(S))

N = len(S)

if S != S_inverse:
    print("No")
    exit(0)

if S[: int((N - 1) / 2)] != S_inverse[int((N + 3) / 2 - 1):]:
    print("No")
    exit(0)

if S[int((N + 3) / 2 - 1):] != S_inverse[:int((N - 1) / 2)]:
    print("No")
    exit(0)

print("Yes")


Measured memory_bytes: 3064
/*▄███████▀▀▀▀▀▀███████▄
░▐████▀▒ЗАПУСКАЕМ▒▀██████▄
░███▀▒▒▒▒▒ДЯДЮ▒▒▒▒▒▒▀█████
░▐██▒▒▒▒▒БОГДАНА▒▒▒▒▒████▌
░▐█▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒████▌
░░█▒▄▀▀▀▀▀▄▒▒▄▀▀▀▀▀▄▒▐███▌
░░░▐░░░▄▄░░▌▐░░░▄▄░░▌▐███▌
░▄▀▌░░░▀▀░░▌▐░░░▀▀░░▌▒▀▒█▌
░▌▒▀▄░░░░▄▀▒▒▀▄░░░▄▀▒▒▄▀▒▌
░▀▄▐▒▀▀▀▀▒▒▒▒▒▒▀▀▀▒▒▒▒▒▒█
░░░▀▌▒▄██▄▄▄▄████▄▒▒▒▒█▀
░░░░▄█████████████  █▒▒▐▌
░░░▀███▀▀████▀█████▀▒▌
░░░░░▌▒▒▒▄▒▒▒▄▒▒▒▒▒▒▐
░░░░░▌▒▒▒▒▀▀▀▒▒▒▒▒▒▒▐*/
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
#pragma GCC optimize("fast-math")
#include <iostream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <tuple>
#include <math.h>
#include <set>
#include <stack>
#include <bitset>
#include <map>
#include <queue>
#include <random>
#include <unordered_set>
#include <unordered_map>
#define DEBUG
#define fi first
#define se second
#define pqueue priority_queue
#define pb(x) push_back(x)
// #define endl '\n'
#define all(x) x.begin(), x.end()
#define int long long
#define mk(a, b) make_pair(a, b)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<vector<ll> > vvi;
typedef vector<ull> vull;
typedef vector<ll> vll;
// typedef tuple<ll, ll, ll> tiii;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector< vector<ll> > vvi;
typedef vector<char> vc;

const ll INF = 1e9;
const ll INFLL = 1e18;
const ll MOD = 1e9 + 7;
// const ll MAXN = 3e5;
const ld eps = 1e-6;
const ld eps2 = 1e-9;
const ll MOD2 = 998244353;
const ll dosz = 5e5;
const ll SZ = (1<<18);
const ld PI = atan2l(0, -1);


void fast_io(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#ifdef DEBUG
        // freopen("a.in", "r",stdin);
#else
       // freopen("tickets.in", "r", stdin);
       // freopen("tickets.out", "w", stdout);
#endif
}

static const int maxn = 2e5;
vi g[maxn];

void solve(){
    int n, m;
    cin >> n >>m;
    vi h(n);
    for(int &i:h)
        cin >> i;
    for(int i=0; i<m; i++){
        int a, b;
        cin >> a >> b;
        a--, b--;
        g[a].pb(b);
        g[b].pb(a);
    }
    int ans = 0;
    for(int i=0; i<n; i++){
        int add = 1;
        for(int j:g[i])
            if(h[j]>=h[i])
                add = 0;
        ans += add;
    }
    cout << ans << endl;
} 

signed main() {
    fast_io();
    ll q = 1;
    // cout << fixed;
    // cin >> q;
    while(q--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 12176
def multitoint(stringnum):
    [sei,sho]=stringnum.split('.')
    if len(sho)<=5:
        sho+='0'*(5-len(sho))
    return int(sei+sho)




n=int(raw_input())
for i in range(n):
    [x1,y1,x2,y2,x3,y3,x4,y4]=[multitoint(x) for x in raw_input().split()]
    [X1,Y1]=[x2-x1,y2-y1]
    [X2,Y2]=[x4-x3,y4-y3]
    ans="NO"
    if X2*Y1==X1*Y2:
        if X2*Y1!=0:
            ans="YES"
        else:
            if (X1==X2 or Y1==Y2):
                ans="YES"
    print ans

Measured memory_bytes: 6452
//Dragon_warrior7(IITK)
// #pragma GCC optimize("O0") 
// #pragma GCC optimize ("Ofast")
// #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize ("-ffloat-store")
#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 umap unordered_map
#define uset unordered_set
#define ll long long
//#define lll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 1000000000000000000
#define pll pair<ll, ll> 
//#define ull unsigned ll
#define vll vector<ll>
#define vpll vector<pll> 
#define rub cerr << "\n------------------------------------\n"
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
#define fo(i,a,b) for(int i=a;i<b;i++)
#define Lets_be_precise cout<<fixed<<setprecision(10)
//typedef  tree < int ,  null_type ,  greater<int> ,  rb_tree_tag ,  tree_order_statistics_node_update > oset;
// const int mod=1e9+7;
// ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// ll modInverse(ll a){return power(a,mod-2);}
ll n,m,a,b,c,k,temp,x,y;
const int MAXN=100000+11;
void read(vector<ll> &v)
{for (int i = 0; i < v.size(); i++)cin>>v[i];}
inline ll max(ll a,ll b)
{return ((a>b)?a:b);}
inline ll min(ll a,ll b)
{return ((a>b)?b:a);}
inline ll int gcd(ll int a ,ll int b)
{if(b==0) return a;a%=b;return gcd(b,a);}
//#define cerr if(false)cerr//uncomment to remove cerr from program...
void solveforthiscase(const int & test)
{//deb(test);
string s;
cin>>s;
if(s[0]=='7')
{
    cout<<"Yes\n";
    return ;
}
if(s[1]=='7')
{
    cout<<"Yes\n";
    return ;
}
if(s[2]=='7')
{
    cout<<"Yes\n";
    return ;
}
cout<<"No\n";
















return ;
}

int main()
{
	ios_base::sync_with_stdio(false);
	Lets_be_precise;
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
// 	cin>>test;
    for(int i=1;i<=test;i++)
    {
        solveforthiscase(i);
    }
}

Measured memory_bytes: 3600
n=int(input())
l=list(map(int,input().split()))
mae=[0]*n
usi=[0]*n
ma=0
for i in range(n):
    ma+=l[i]
    mae[i]=ma
us=0
for i in range(n-1,-1,-1):
    us+=l[i]
    usi[i]=us
ans=10000000000000000000
for i in range(0,n-1):
    ans=min(ans,abs(mae[i]-usi[i+1]))
    
print(ans)


Measured memory_bytes: 78416
import scala.io.StdIn

object Main extends App {
  val n = StdIn.readLine.toInt
  val seq = Iterator.continually(StdIn.readLine)
    .take(2)
    .map(_.split(" ").map(_.toInt))
    .toArray
  val seq1 = seq(0).scanLeft(0)( (acc, e) => acc + e)
  val seq2 = seq(1).scanRight(0)( (e,acc) => acc + e)
  val ans = (0 until n).map(i => seq1(i+1) + seq2(i)).max

  println(ans)
}

Measured memory_bytes: 25420
#include <iostream>
#include <string>
#include <unistd.h>
#include <cmath>
#include <vector>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    string s,t; cin >> s >> t;
    //DPtable
    const int maxlen = 3000+10;
    vector<vector<int> >dp(maxlen, vector<int>(maxlen));
    rep(i, s.size()){
        rep(j, t.size()){
            if(s[i] == t[j]){
                dp[i+1][j+1] = dp[i][j] + 1;
            }else{
                dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
            }
        }
    }
    //restor
    string ans; 
    int i = s.size(), j = t.size();
    while(i>0 && j>0){
        if(dp[i][j] == dp[i][j-1])  --j;
        else if(dp[i][j] == dp[i-1][j]) --i;
        else{
            ans += s[i-1];
            --i;    --j;
        }
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}


Measured memory_bytes: 35712
def end():
    print(0)
    exit()


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

b = [0] * ((n + 1) // 2)

if n % 2 == 0:
    for x in a:
        if x % 2 == 0:
            end()
        b[x // 2] += 1
    for y in b:
        if y != 2:
            end()
else:
    for x in a:
        if x % 2 != 0:
            end()
        b[x // 2] += 1
    for y in b[1:]:
        if y != 2:
            end()
        if b[0] != 1:
            end()

print((2 ** (n // 2) % (10 ** 9 + 7)))


Measured memory_bytes: 13880
n,m=map(int,input().split())
a=[list(map(int,input().split(" "))) for i in range(n)]

for i in range(n):
    print(*a[i],sum(a[i]))

c=[0]*m
for i in range(m):
    for j in range(n):
        c[i]=a[j][i]+c[i]
print(*c,sum(c))


Measured memory_bytes: 6224
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>

using namespace std;
typedef long long ll;
ll MOD=1e9+7L;
ll ans;
ll f[25000000];

int S;
vector<ll> d,dd;

ll mod_pow(ll x,ll n){
  ll ret=1L;
  while(n){
    if(n%2){
     ret=(ret*x)%MOD;
    }
    n/=2L;
    x=(x*x)%MOD;
  }
  return ret;
}

void divisor(int n){
  for(int i=1; i<=sqrt(n); i++){
    if(n%i==0){
      int a=i;
      int b=n/i;
      d.push_back(a);
      if(a!=b) d.push_back(b);
    }
  }
}

int digit(int n){
  if(n/10==0) return 1;
  if(n/100==0) return 2;
  if(n/1000==0) return 3;
  if(n/10000==0) return 4;
  if(n/100000==0) return 5;
  if(n/1000000==0) return 6;
  if(n/10000000==0) return 7;
  if(n/100000000==0) return 8;
  return 0;
}

int cnt(){
  int ret=0;
  int s=1,t=1,sum=f[s];
  while(t<25000000){
    if(sum>=S){
      if(sum==S){
        if(f[s]<8) ret++;
      } 
      sum-=f[s];
      s++;
    }
    if(sum<S){
      t++; sum+=f[t];
    }
  }
  return ret;
}

int main() {

cin.tie(0);
ios::sync_with_stdio(false);

cin>>S;
divisor(S);

for(int i=0; i<d.size(); i++){
  if(d[i]>=8){
    ll n=S/d[i];
    ll add=9*mod_pow(10,d[i]-1)-n+1+MOD;
    if(add) ans=(ans+add)%MOD;
  }
}

int m=S/8;

for(int i=1; i<=sqrt(S); i++){
    if(S%i==0){
      int a=i;
      int b=S/i;
      if(a<=m) dd.push_back(a);
      if(a!=b) if(b<=m) dd.push_back(b);
    }
}

ans=(ans+m-dd.size()+MOD)%MOD;

for(int i=1; i<25000000; i++){
  f[i]=digit(i);
}

ans=(ans+cnt())%MOD;

cout<<ans<<endl;

}


Measured memory_bytes: 195584
n=int(input())
v=list(map(int,input().split()))
from collections import Counter
a=Counter(v[0::2]).most_common()
b=Counter(v[1::2]).most_common()
a.append([0,0])
b.append([0,0])
if a[0][0]!=b[0][0]:
    print(n-(a[0][1]+b[0][1]))
else:
    print(min(n-(b[0][1]+a[1][1]),n-(a[0][1]+b[1][1])))

Measured memory_bytes: 65004
use std::cmp;

pub struct Scanner{
    line : Vec<String> ,
    idx : usize
}

impl  Scanner{
   #[allow(dead_code)]
   fn new() -> Scanner{
       return Scanner{ line: vec![], idx : 0}
   }
   #[allow(dead_code)]
   fn next<T: std::str::FromStr> (&mut self) -> T{
       if self.idx == self.line.len() {
           let mut buffer = String::new();
           std::io::stdin().read_line(&mut buffer).ok();

           let a : Vec<&str>  = buffer.trim().split(' ').collect();
           self.line = a.iter().map(|&s| String::from(s)).collect();
           self.idx = 0;
       }
       let ret : T = self.line[self.idx].parse::<T>().ok().expect("Parse error.");
       self.idx += 1;
       ret
   }
}


fn main() {
    let mut scan = Scanner::new();
    let k:usize  = scan.next();
    let n:usize  = scan.next();

    let mut a: Vec<usize>= Vec::with_capacity(k);
    for _ in 0..n {
        a.push(scan.next());
    }

    let mut min :usize = a[n - 1] - a[0];
    for i in (1..n) {
        min = cmp::min(min, k - a[i] + a[i - 1]);
    }
    println!("{}", min);
}


Measured memory_bytes: 19312
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cstring>
int main()
{
	int N;
	std::cin >> N;
	std::vector<int> P(N);
	for (int i = 0; i < N; ++i) {
		std::cin >> P[i];
	}
	std::vector<int> Q(N);
	for (int i = 0; i < N; ++i) {
		std::cin >> Q[i];
	}

	int all = 1;
	for (int i = N; i > 1; --i) {
		all *= i;
	}

	int order_P = 0;
	{
		int remain = all;

		std::vector<int> arr(N);
		for (int i = 0; i < N; ++i) {
			arr[i] = i + 1;
		}

		for (int i = 0; i < N; ++i) {
			int index = 1;
			for (auto itr = arr.begin(); itr != arr.end(); ++itr,++index) {
				if (P[i] == *itr) {
					remain /= (int)arr.size();
					order_P += remain*(index - 1);
					arr.erase(itr);
					break;
				}
			}
		}
	}

	int order_Q = 0;
	{
		int remain = all;

		std::vector<int> arr(N);
		for (int i = 0; i < N; ++i) {
			arr[i] = i + 1;
		}

		for (int i = 0; i < N; ++i) {
			int index = 1;
			for (auto itr = arr.begin(); itr != arr.end(); ++itr, ++index) {
				if (Q[i] == *itr) {
					remain /= (int)arr.size();
					order_Q += remain * (index - 1);
					arr.erase(itr);
					break;
				}
			}
		}
	}

	if (order_P >= order_Q) {
		std::cout << order_P - order_Q << std::endl;
	}
	else
	{
		std::cout << order_Q - order_P << std::endl;

	}
	return 0;
}

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

int main(){
    double N,K;
    cin >> N >> K;
    double possibility = 0;
    rep(i,N){
        double score = i + 1;
        double pos = 1 / N;
        while(score < K){
            pos *= 0.5;
            score *= 2;
        }
        possibility += pos;
    }
    cout << fixed << setprecision(10);
    cout << possibility << endl;
}


Measured memory_bytes: 256
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"
#include "stack"
#include "queue"
#include "cmath"
#include "set"

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<vector<ll> > mat;

int main()
{
  int n;
  cin >> n;
  string s[200100];
  for (int i = 0; i < n; i++)
  {
    cin >> s[i];
  }
  sort(s, s + n);
  vector<pair<string, int> > p(0);
  int check = 1;
  for (int i = 1; i < n; i++)
  {
    if (s[i] == s[i - 1])
    {
      check++;
    }
    else
    {
      p.push_back(make_pair(s[i - 1], check));
      check = 1;
    }
  }
  p.push_back(make_pair(s[n - 1], check));
  int MAX = 0;
  for (pair<string, int> q:p)
  {
    MAX = max(MAX, q.second);
  }
  for (pair<string, int> q:p)
  {
    if (q.second == MAX)
    {
      cout << q.first << "\n";
    }
  }
}

Measured memory_bytes: 17908
#include <iostream>

using namespace std;

int main(){
    int N,K;
    cin >> N>>K;
    int A[101]={0};
    int ct=0;
    while(K--){
        int x;
        cin>>x;
        for(int i=0;i<x;i++){
            int y;
            cin>>y;
            A[y]=A[y]+1;;
        }
    }
    for(int i=1; i<=N;i++){
        if(A[i]==0)
            ct++;
    }
    cout<<ct<<endl;
}

Measured memory_bytes: 3664
#!/usr/bin/env python

def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    for i in range(k, n):
        if a[i-k] < a[i]:
            print("Yes")
        else:
            print("No")

if __name__ == '__main__':
    main()


Measured memory_bytes: 31560
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>  
#include <functional>
#define ll long long int
#define ld long double
#define pb push_back
#define pll pair<ll,ll>
#define pint pair<int,int>
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define mod 1000000007
#define MAX 1000000000000000000
#define endl '\n'
#define mp make_pair
#define INF 1000000000
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ff first
#define ss second
#define ps(x,y) fixed<<setprecision(y)<<x
#define setbits(x) __builtin_popcountll(x)			//counts no of ones in binary representation
#define w(t) 	int t; cin>>t; while(t--)
#define pi 3.141592653589793238
#define sortt(v)  sort(v.begin(),v.end())
#define lb(v,x) std::lower_bound(v.begin(),v.end(),x)
#define ub(v,x) std::upper_bound(v.begin(),v.end(),x)

using namespace std;
 

int main() {
	fast;
	ll n,m,b,c,d;
	string s,t;
	cin>>n;
	ll a[n];
	forn(i,n){
		cin>>a[i];
		if(a[i]==0){
			cout<<0;
			return 0;
		}
	}
	ll ans=1;
	bool flag=1;
	forn(i,n){
		ll temp=MAX/ans;
		if(a[i]>temp){
			flag=0;
			break;
		}
		ans*=a[i];
	}
	if(!flag)	cout<<-1;
	else	cout<<ans;
}




 

Measured memory_bytes: 4432
/*input
7
994 518 941 851 647 2 581
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i,j,k)     for(int i = j ; i < k ; ++i)
#define RREP(i,j,k)    for(int i = j ; i >=k ; --i)
#define A    first
#define B    second
#define mp   make_pair
#define pb   emplace_back
#define PII pair<int , int>
#define MEM(i,j)   memset(i , j , sizeof i)
#define ALL(i)     i.begin() , i.end()
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie(0) , cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define int long long
#define MAX 3030
#define INF 0x3f3f3f3f

int n , x[MAX];
int32_t main(){
    IOS;
    cin >> n;
    REP(i , 1 , n + 1) cin >> x[i];
    int ans = 0;
    REP(i , 1 , n + 1) ans += x[i] - 1;
    cout << ans << endl;
    return 0;
}

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

int main(){
    int h, m, s, S;
    cin >> S;
    h = S/3600;
    S = S - h*3600;
    m = S/60;
    S = S - m*60;
    s = S;
    cout << h << ":" << m << ":" << s << endl;
    
}


Measured memory_bytes: 3104
import sys
input = sys.stdin.readline
import numpy as np
N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
import collections
c = collections.Counter(A)
d = sorted(c.values(), reverse=True)
ans = 0
while len(d) > K:
    ans += d.pop()
print(ans)

Measured memory_bytes: 41936
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<int,int>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
  string s;
  cin>>s;
  int res,n=s.size();
  res=n;
  for(int i=0;i<n-1;i++)if(i+1<n&&s[i]!=s[i+1])chmin(res,max(i+1,n-i-1));
  cout<<res<<"\n";
}


Measured memory_bytes: 512
#include<cstdio>
#include<cstring>
using namespace std;

char g[10]; int y, m, d;

int main(){
	for(;;){
		scanf("%s", g);
		if(strcmp(g, "#") == 0) break;
		scanf("%d %d %d", &y, &m, &d);
		if(y > 31 || (y == 31 && m > 4)){
			printf("? %d %d %d\n", y - 30, m, d);
		}else{
			printf("HEISEI %d %d %d\n", y, m, d);
		}
	}
	return 0;
}


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

using namespace std;

int main() {
   ios_base::sync_with_stdio(false); cin.tie(nullptr);
   int N; int64_t S; cin >> N >> S;
   vector<int64_t> X(N), P(N);
   for (int i = 0; i < N; ++i) cin >> X[i] >> P[i];
   int64_t ans = 0;
   auto go = [&](int64_t X) {
      ans += abs(X - S);
      S = X;
   };
   function<void(int, int)> solve = [&](int l, int r) {
      if (X[l] > S) return go(X[r]);
      if (X[r] < S) return go(X[l]);
      if (P[l] >= P[r]) {
         P[l] += P[r];
         solve(l, r-1);
         return go(X[r]);
      } else {
         P[r] += P[l];
         solve(l+1, r);
         return go(X[l]);
      }
   };
   solve(0, N-1);
   cout << ans << '\n';
   return 0;
}


Measured memory_bytes: 9952
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <math.h>
#include <array>
#include <list>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> tup;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vp;
int tmpmin=1e9;
int main(int argc,char const* argv[])
{
  int n,m,X,Y;
  cin >> n >> m >> X >> Y;
  vi x;
  vi y;
  for(int i=0;i<n;i++)
    {
      int tmpx;
      cin >> tmpx;
      x.push_back(tmpx);
    }
  sort(x.begin(),x.end(),greater<int>());
  for(int i=0;i<m;i++)
    {
      int tmpy;
      cin >> tmpy;
      y.push_back(tmpy);
    }
  sort(y.begin(),y.end());
  for(int z=X+1;z<=Y;z++)
    {
      if(z>x[0] && z<=y[0])
	{
	  cout << "No War" << endl;
	  return 0;
	}
    }
  cout << "War" << endl;
  
}


Measured memory_bytes: 256
def modpow(x,p,mod):
    ret=1
    for i in range(64):
        if (1<<i)&p:
            ret=ret*x%mod
        x=x*x%mod
    return ret

def inverse_table(n,mod):
    table=[]
    for i in range(0,n+1):
        table.append(modpow(i,mod-2,mod))
    return table

def factorial_table(n,mod):
    table=[1]
    for i in range(1,n+1):
        table.append(table[-1]*i%mod)
    return table

def inverse_factorial_table(n,it,mod):
    table=[1]
    for i in range(1,n+1):
        table.append(table[-1]*it[i]%mod)
    return table

it=inverse_table(10**5,1000000007)
ft=factorial_table(10**5,1000000007)
ift=inverse_factorial_table(10**5,it,1000000007)
def c(n,k,it,ft,mod):
    return ft[n]*ift[k]*ift[(n-k)]%mod
n,k=map(int,input().split())
a=sorted(map(int,input().split()))
hoge=[]
while True:
    hoge.append(c(n-1,k-1,it,ft,1000000007))
    if n-1==k-1:
        break
    n-=1
ans=0
for i in range(len(hoge)):
    ans-=hoge[i]*a[i]%1000000007
    ans+=hoge[i]*a[-i-1]%1000000007
    ans%=1000000007
print(ans)



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

class Main {
    static int ans=0;
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());

        int n = Integer.parseInt(st.nextToken());
        int m = Integer.parseInt(st.nextToken());

        HashMap<Integer, List<Integer>> graph = new HashMap<>();

        for (int i=0; i<m; i++){
            st = new StringTokenizer(br.readLine());
            int a = Integer.parseInt(st.nextToken());
            int b = Integer.parseInt(st.nextToken());
            List<Integer> alist = graph.getOrDefault(a,new LinkedList());
            List<Integer> blist = graph.getOrDefault(b,new LinkedList());
            alist.add(b);
            blist.add(a);
            graph.put(a,alist);
            graph.put(b,blist);
        }
        HashSet<Integer> vis = new HashSet<>();
        dfs(1, n, vis, graph);
        System.out.println(ans);
    }

    public static void dfs(int cur, int n, HashSet<Integer> vis, HashMap<Integer, List<Integer>> graph){
        vis.add(cur);
        if (vis.size()==n){
            ans++;
            return;
        }
        for (int neigh: graph.get(cur)){
            if (!vis.contains(neigh)){
                HashSet<Integer> clone= new HashSet<>(vis);
                dfs(neigh, n, clone, graph);
            }
        }

    }



}


Measured memory_bytes: 25492