akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n, m, a[101], b[101] = { 0 }, ten[101],k;
	cin >> n >> m;
	for (int i = 1; i <= m; i++)
		cin >> ten[i];
	for (int i = 1; i <= m; i++)
	{
		k = 0;
		for (int j = 1; j <= n; j++)
		{
			cin >> a[j];
			if (a[j] == ten[i])
				b[j]++;
			else
				k++;
		}
		b[ten[i]] += k;
//		for (int j = 1; j <= n; j++)
//			cout << ' ' << b[j];
//		cout << endl;
	}
	for (int i = 1; i <= n; i++)
		cout << b[i] << endl;
	return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int (i)=0;(i)<(n);++(i))
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);++(i))
#define EACH(e,v) for(auto& e:v)
#define ALL(v) (v).begin(),(v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort((v).rbegin(),(v).rend())
#define PERM(v) SORT(v);for(bool c##p=1;c##p;c##p=next_permutation(ALL(v)))
#define UNIQUE(v) SORT(v);(v).erase(unique(ALL(v)),(v).end())
template<typename A,typename B> inline bool chmax(A &a,const B &b){if(a<b){a=b;return 1;}return 0;}
template<typename A,typename B> inline bool chmin(A &a,const B &b){if(a>b){a=b;return 1;}return 0;}

const int MOD = (int)1e9 + 7;
const int INF = 1 << 30;
const ll INFF = 1LL << 62;

// 下にy, 右にx
enum {R, U, L, D};
const int dx[] = {1,  0, -1, 0};
const int dy[] = {0, -1,  0, 1};

int N;
vector<int> A;

signed main() {

    cin >> N;

    A.resize(N);
    REP(i, N) cin >> A[i];

    // 商品単価の最低値
    int mn = 1;

    ll res = 0;
    REP(i, N) {
        // A[i] - 1 つかえる
        // 商品の値段は最低 mn
        if (i == 1) mn = 2;
        if (A[i] == mn) ++mn;
        else if (A[i] > mn) {
            res += (A[i] - 1) / mn;
        }
        // cout << A[i] << ' ' << mn << endl;
    }
    cout << res << endl;

}

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

using namespace std;

int n;

int main() {
  scanf("%d", &n);
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  auto check = [&](int b) {
    map<int, int> s;
    for (int i = 0; i < n - 1; ++i) {
      if (a[i] >= a[i + 1]) {
        while (!s.empty() && s.rbegin()->first >= a[i + 1]) {
          s.erase(--s.end());
        }
        for (int j = a[i + 1] - 1; ~j; --j) {
          ++s[j];
          if (s[j] == b) {
            s.erase(j);
          } else {
            break;
          }
          if (!j) {
            return false;
          }
        }
      }
    }
    return true;
  };
  bool flag = true;
  for (int i = 0; i < n - 1; ++i) {
    if (a[i] >= a[i + 1]) {
      flag = false;
      break;
    }
  }
  if (flag) {
    puts("1");
    return 0;
  }
  int l = 2, r = n + 1;
  while (l < r) {
    int mid = l + r >> 1;
    if (check(mid)) {
      r = mid;
    } else {
      l = mid + 1;
    }
  }
  printf("%d\n", r);
  return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int dp[100001][3];
int a[100001][3];
int solve(int n)
{
    dp[0][0]=a[0][0];
    dp[0][1]=a[0][1];
    dp[0][2]=a[0][2];
    for(int i=1;i<n;i++)
    {
        dp[i][0]=max(dp[i-1][1]+a[i][0],dp[i-1][2]+a[i][0]);
        dp[i][1]=max(dp[i-1][0]+a[i][1],dp[i-1][2]+a[i][1]);
        dp[i][2]=max(dp[i-1][0]+a[i][2],dp[i-1][1]+a[i][2]);
    }
    int mx=max(dp[n-1][0],dp[n-1][1]);
    return max(mx,dp[n-1][2]);
}
int main()
{
        int n;
        cin >> n;
        for(int j=0;j<n;j++)
        {
            for(int k=0;k<3;k++)
            cin >> a[j][k];
        }
        cout << solve(n) << endl;
}

Measured memory_bytes: 5908
import sys; input = sys.stdin.readline
from math import ceil
d, t, s = map(int, input().split())
u, l = ceil(d/t), d//t
if u == l:
    if u <= s: print("Yes")
    else: print("No")
else:
    if d/t <= s: print("Yes")
    else:print("No")

Measured memory_bytes: 62096
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;
vector<int> dx = {0,0,1,-1};
vector<int> dy  = {1,-1,0,0};
 
int main() {
        int h,w;
        cin >> h >> w;
        vector<string> maze(h);
        rep(i,h) cin >> maze[i];
        vector<vector<int>> dis(h+1,vector<int>(w+1,-1));
        auto id = [&](int i,int j){
                return (w + 1) * i + j;
        };
        vector<int> zero;  
        rep(i,h)rep(j,w){
                if(maze[i][j] =='#') zero.push_back(id(i+1,j+1));
        }  

        int ans = 0;
        queue<int> q;
        q.push(0);
        while(!q.empty()){
                int y = q.front() / (w+1);
                int x = q.front() % (w+1);
                q.pop();
                if(x == 0 && y == 0){
                        for(int next:zero){
                                q.push(next);
                                int new_y = next / (w+1);
                                int new_x = next % (w+1);
                                dis[new_y][new_x] = 0;
                        }
                }
                else{
                    rep(i,4){
                            int new_y = y + dy[i];
                            int new_x = x + dx[i];
                            if(1 <= new_y && new_y <= h && 1 <= new_x && new_x <=w){
                                    if(dis[new_y][new_x] >= 0) continue;
                                    dis[new_y][new_x] = dis[y][x] + 1;
                                    ans = max(ans,dis[new_y][new_x]);
                                    q.push(id(new_y,new_x));
                            }
                    }
                }
        }
        cout << ans << endl;
        /*
        rep(i,h+1){
                rep(j,w+1){
                        cout << dis[i][j] << " ";
                }
                cout << endl;
        }
        */

        return 0;
}




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

int main() {
	// your code goes here
	int n,num,sum=0,sum1=0;
	cin>>n;
	for (int i=0;i<n;i++)
	{
		cin>>num;
		sum += num*num;
		sum1 += num;
	}
	cout<<(sum1*sum1 - sum)/2<<endl;
	return 0;
}

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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

int H, W; 
int c1 [305][305];
int c2 [305][305];
int dp [305][305];

int cost(vector<char> s1, vector<char> s2) {
	F0R(i, 305) F0R(j, 305) c1[i][j] = 0, c2[i][j] = 0, dp[i][j] = 1e6;

	// s1 < s2
	F0R(i, H) {
		int total = 0;
		F0R(j, H) if (j + i < H) {
			total += s1[i+j] == s2[j];
			c1[i][j] = total;
		}
	} 

	// s2 < s1
	F0R(j, H) {
		int total = 0;
		F0R(i, H) if (j + i < H) {
			total += s2[i+j] == s1[i];
			c2[j][i] = total;
		}
	}

	F0R(i, H+1) F0R(j, H+1) {
		if (i == 0 || j == 0) dp[i][j] = 0;
		if (j > 0) {
			int movecost = (j > i) ? c1[j-i][i-1] : c2[i-j][j-1];
			dp[i][j] = min(dp[i][j], dp[i][j-1] + movecost);
		}
		if (i > 0) {
			int movecost = (j > i) ? c1[j-i][i-1] : c2[i-j][j-1];
			dp[i][j] = min(dp[i][j], dp[i-1][j] + movecost); 
		}
	}
	return dp[H][H];
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> H >> W;
	vector<vector<char>> stacks (W, vector<char> (H));
	F0R(i, H) F0R(j, W) cin >> stacks[j][i];

	int ans = 0;
	F0R(i, W-1) ans += cost(stacks[i], stacks[i+1]);
	print(ans);
}

Measured memory_bytes: 4856
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Int32;
using static System.Math;

class Program
{

    static void Main(string[] args)
    {
        label:
        ReadLine();
        var row1 = ReadLine().Split().Select(Parse).ToArray();
        var row2 = ReadLine().Split().Select(Parse).ToArray();
        int result = row1[0] + row2.Sum();
        int tmp = result;
        for (int i = 1; i < row1.Length; ++i)
        {
            tmp += row1[i] - row2[i - 1];
            result = Max(result, tmp);
        }
        WriteLine(result);
    }
}


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


void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}

#define ll long long
#define ld long double
#define ull unsigned long long
#define ull unsigned long long
#define mod 1000000007
#define pi (3.1415926)

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))

#define scd(a)  scanf("%lld",&a)
#define scdd(a,b)	scanf("%lld%lld",&a,&b)
#define scddd(a,b,c)	scanf("%lld%lld%lld",&a,&b,&c)
#define ptab(a)	printf("%lld ",a)
#define pdn(a)	printf("%lld\n",a)
#define pddn(a,b)	printf("%lld %lld\n",a,b)
#define pdddn(a,b,c)	printf("%lld %lld %lld\n",a,b,c)

#define forr(n) for(ll i=0;i<n;i++)
#define rev(n) for(ll i=n-1;i>=0;i--)
#define forp(x, y) for(ll i=x;i<y;i++)
#define loop( j, k, in) for (ll i=j ; i<k ; i+=in)

#define in  cin>>
#define out cout<<
#define en "\n"
#define sp " "

ll sum (int n ){return ((n*(n+1)) / 2) ;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int main()
{
    init();
    int n; in n;
    int arr[] = {0,1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout << arr[n];
}



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

int main() {
  char c;
  cin >> c;

  if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'){
    cout << "vowel" << endl;
    }
  else{
    cout << "consonant" << endl;
    }
}
  


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

using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,n,m) for(ll i=n; i>(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define VEC2(x,a,b) vector<vector<ll>> x = vector<vector<ll>>(a,vector<ll>(b,0))
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "; cout<<endl
#define cout(n) cout<<fixed<<setprecision(n)
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll N,M;
  cin>>N>>M;

  while(N!=0&&M!=0){
    vector<ll> w(N+1);
    vector<ll> h(M+1);
    cinv(w,1,N+1);
    cinv(h,1,M+1);
    FOR(i,1,N+1){
      w[i]+=w[i-1];
    }
    FOR(i,1,M+1){
      h[i]+=h[i-1];
    }
    map<ll,ll> mpw;
    map<ll,ll> mph;

    FOR(i,0,N+1){
      FOR(j,i+1,N+1){
        mpw[w[j]-w[i]]++;
        //cout<<w[j]-w[i]<<endl;
      }
    }
    FOR(i,0,M+1){
      FOR(j,i+1,M+1){
        mph[h[j]-h[i]]++;
      }
    }
    ll res=0;
    FORm(i,mpw){
        res+=mph[i->first]*(i->second);
        //cout<<res<<endl;
    }
    cout<<res<<endl;






    cin>>N>>M;
  }

}



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

class MainClass
{
    public static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        List<long> originalValues = Console.ReadLine().Split(' ')
            .Select(x => long.Parse(x)).ToList();

        int negativeCount = originalValues.Count(num => num < 0);

        // 全て正の数にする
        // マイナスが偶数個なら、全てのマイナスを消せる
        List<long> vals = originalValues.Select(num => Math.Abs(num)).ToList();
        if (negativeCount % 2 != 0)
        {
            // マイナスが奇数個なら、かならず１つマイナスが残る→最小値をマイナスにする
            long min = vals.Min();
            vals.RemoveAt(vals.IndexOf(min));
            vals.Add(-min);
        }

        Console.WriteLine(vals.Sum());
    }
}


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

int main(void){
    int s;
    cin >> s;

    int fir = s /100;
    int sec = s %100;

    if(1 <= fir && fir <= 12){
        if(1 <= sec && sec <= 12){
            cout << "AMBIGUOUS";
        }else{
            cout << "MMYY";
        }
    }else{
        if(1 <= sec && sec <= 12){
            cout << "YYMM";
        }else{
            cout << "NA";
        }
    }
    cout << endl;
    return 0;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    int h,w;cin>>h>>w;
    int sh,sw;cin >>sh>>sw;
    int gh,gw;cin >>gh>>gw;
    sh--;sw--;gh--;gw--;
    vector<string>s(h);
    for (int i = 0; i < h; ++i) {
        cin >>s[i];
    }
    deque<pair<int,int>>que;
    que.emplace_back(sh,sw);
    int dx[4]={1,-1,0,0};
    int dy[4]={0,0,1,-1};
    vector<vector<int>>d(h,vector<int>(w,INF));
    d[sh][sw]=0;
    while(!que.empty()){
        auto p=que.front();
        int i=p.first;
        int j=p.second;
        que.pop_front();//h w;
        for (int k = 0; k < 4; ++k) {
            int nh=i+dx[k],nw=j+dy[k];
            if(nh<0||nh>=h||nw<0||nw>=w)continue;
            if(s[nh][nw]=='#')continue;
            if(d[nh][nw]>d[i][j]){
                d[nh][nw]=d[i][j];
                que.emplace_front(nh,nw);
            }
        }
        for (int l =max(i-2,0); l <=min(h-1,i+2); ++l) {
            for (int k =max(j-2,0); k <=min(w-1,j+2); ++k) {
                if(s[l][k]=='#')continue;
                if(l==i&&k==j)continue;
                if(d[l][k]>d[i][j]+1){
                    d[l][k]=d[i][j]+1;
                    que.emplace_back(l,k);
                }
            }
        }
    }
    if(d[gh][gw]==INF)cout <<-1<<endl;
    else cout <<d[gh][gw]<<endl;
}


Measured memory_bytes: 9544
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n , k;
    cin>>n>>k;
    int arr[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    sort(arr , arr+n);
    int count=0;
    for(int i=0;i<k;i++)
        count+=arr[i];
    cout<<count;
}

Measured memory_bytes: 3528
from collections import defaultdict

n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]

cnt = defaultdict(int)
for xi, yi in xy:
    for xj, yj in xy:
        cnt[(xi - xj, yi - yj)] += 1
cnt[(0, 0)] = 0
ans = n - max(cnt.values())
print(ans)


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	for (auto &u : v) os << u << el;
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}
int N;
int main() {
#ifdef DEBUG
	cin >> N;
#endif
	string S;
	while (true) {
		int ok, ng;
		char c;

		//sakini 9 situmon suru
		{
			string T = S + '9';
			cout << "? " << T << el;
			fflush(stdout);
#ifdef DEBUG
			if (stoi(T) <= N && T <= to_string(N) ||
				stoi(T) > N && T > to_string(N) ) {
				c = 'Y';
			} else {
				c = 'N';
			}
#else
			cin >> c;
#endif
		}

		if (c == 'N') {
			ok = 0, ng = 9;
			while (abs(ok-ng) > 1) {
				int m = (ok+ng)/2;
				string T = S + (char)(m + '0');
				cout << "? " << T << el;
				fflush(stdout);
#ifdef DEBUG
				if (stoi(T) <= N && T <= to_string(N) ||
						stoi(T) > N && T > to_string(N) ) {
					c = 'Y';
				} else {
					c = 'N';
				}
#else
				cin >> c;
#endif
				if (c == 'Y') ok = m;
				else ng = m;
			}
			S += (ok + '0');	
			continue;
		}

		ok = 10, ng = -1;
		while (abs(ok-ng) > 1) {
			int m = (ok+ng)/2;
			string T = S + (char)(m + '0');
			if (count(begin(T), end(T), '0') == T.size()) {
				ng = m;
				continue;
			}
			while (T.size() < 15) T += '0';
			cout << "? " << T << el;
			fflush(stdout);
#ifdef DEBUG
			if (stol(T) <= N && T <= to_string(N) ||
				stol(T) > N && T > to_string(N) ) {
				c = 'Y';
			} else {
				c = 'N';
			}
#else
			cin >> c;
#endif
			if (c == 'Y') ok = m;
			else ng = m;
		}
		if (ok == 10) {
			S += '9';
			continue;
		} else {
			S += (ok + '0');
			cout << "! " << S << endl;
			fflush(stdout);
			break;
		}
	}
	return (0);
}

Measured memory_bytes: 656
N = int(input())
P = [0 for i in range(N)]
for i in range(N):
    x,y = map(int,input().split())
    P[i] = [x,y]
ans = 0
def cal(a,b):
    res = (a[0] - b[0])** 2 + (a[1]-b[1])**2
    return res ** 0.5
for i in range(N):
    for j in range(N):
        if i != j :
            ans += cal(P[i],P[j])

ans /= N
print(ans)

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

using namespace std;

int N;
int A[200000];

bool check(int n) {
  map<int, int> D;
  int prev = 0;
  for(int i = 0; i < N; ++i) {
    if(A[i] <= prev) {
      D.erase(D.lower_bound(A[i]), D.end());
      int x = A[i] - 1;
      while(true) {
        if(x < 0) return false;
        ++D[x];
        if(D[x] >= n) {
          D.erase(x); --x;
        } else {
          break;
        }
      }
    }
    prev = A[i];
  }
  return true;
}

bool inc() {
  int prev = 0;
  for(int i = 0; i < N; ++i) {
    if(A[i] <= prev) return false;
    prev = A[i];
  }
  return true;
}

int main() {
  cin >> N;
  for(int i = 0; i < N; ++i) cin >> A[i];
  if(inc()) {
    cout << 1 << endl; return 0;
  }
  int ng = 1, ok = N;
  while(ok - ng > 1) {
    int mid = (ng + ok) / 2;
    if(check(mid)) ok = mid;
    else ng = mid;
  }
  cout << ok << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int  i, K, k, D = 0, Sum = 0, Min = 9;
   for(i = 0;i < 5;i++){
    cin >> K;
    k = K % 10;
    if(k > 0 ){
      D += 1;
      if(k < Min){
        Min = k;
      }
    }
     Sum += K - k;
   }
  if(D > 0){
    Sum += Min + (D * 10) -10;
    }
  cout << Sum <<endl;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    a,b,_,k=map(int,input().split())
    if k<=a:
        print(k)
    elif k>a and k<=a+b:
        print(a)
    else:
        print(a-(k-a-b))
if __name__=='__main__':
    main()

Measured memory_bytes: 61924
object Main extends App {
    val pre_s = io.StdIn.readLine

    val s = pre_s.distinct
    
    var result = "None"
    var has = false
    for (char <- "abcdefghijklmnopqrstuvwxyz" if !has) {
        if (! s.contains(char)) {
            has = true
            result = char.toString
        }
    }

    println(result)
}

Measured memory_bytes: 27372
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define For(i,a,b) for(int i=a;i<b;i++)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define mp make_pair
#define bit(n) (1LL<<(n))
#define F first
#define S second
#define debug(x) cerr << x << endl
#define Complex complex<double>
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

int main() {
    int a,b,c;
    cin >> a >> b >> c;
    cout << c << ' ' << a << ' ' << b;
    


}

/*



 */



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2147483647
#define LINF 9223372036854775807
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;
signed main(){
	
	int n,m;
	string s[111111],t[111111];
	cin>>n>>m;
	rep(i,n)cin>>s[i];
	rep(i,m)cin>>t[i];
	    
	for(int i=0;i<n-m+1;i++){
	    for(int j=0;j<n-m+1;j++){
	        int flag=1;
	        for(int k=i;k<i+m;k++){
	            for(int l=j;l<j+m;l++){
	                if(s[k][l]!=t[k-i][l-j])flag=0;
	            }
	        }
	        if(flag){
	            cout<<"Yes"<<endl;
	            return 0;
	        }
	    }
	}
	cout<<"No"<<endl;

}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(ll i=0;i<n;i++)

int main(){
	ll n,m;cin>>n;
	map<ll,ll> mpa,mpb;
	rep(i,n){
		ll a;cin>>a;
		mpa[a]++;
	}
	cin>>m;
	rep(i,m){
		ll a;cin>>a;
		mpb[a]++;
	}
	for(auto i:mpb){
		if(i.second>mpa[i.first]){
			cout<<"NO"<<"\n";
			return 0;
		}
	}
	cout<<"YES"<<"\n";

}


Measured memory_bytes: 25216
N = int(input())
S = list(input())
ans = 1
#print(S)
x = S.pop(0)
while(True):
    #print(S)
    if S==[]:break
    for i in range(len(S)):
        if S[0]==x:
            del S[0]
        else:
            x = S.pop(0)
            ans+=1
            break
print(ans)

Measured memory_bytes: 4084
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    
    int n; cin >> n;
    int ans = 0;
    
    if(n>=100000) ans = 90909;
    else if(n>=10000) ans = n-9090;
    else if(n>=1000) ans = 909;
    else if(n>=100) ans = n-90;
    else if(n>=10) ans = 9;
    else ans = n;

    cout << ans << ln;
    return 0;
}

Measured memory_bytes: 256
n=int(input())
l=[tuple(int(i) for i in input().split()) for j in range(n)]
ll=[]
s=set(l)
sp=set()
sm=set()
sy=set()
for i,j in l:
    sp.add(i+j)
    sm.add(i-j)
    sy.add(j)
for i in range(8):
    tmp=[]
    for j in range(8):
        if (i,j) in s:
            tmp=[]
            break
        if i+j in sp or i-j in sm:
            continue
        if j in sy:
            continue
        tmp.append((i,j))
    if tmp:
        ll.append(tmp)

ln=[]
m=1
for i in range(8-n):
    ln.append(len(ll[i]))
    m*=len(ll[i])


def base(X):
    X_dumy = X
    out = ''
    for i in ln:
        out += str(X_dumy%i)
        X_dumy = int(X_dumy/i)
    return out

import copy
for i in range(m):
    s=base(i)
    b=False
    cp=copy.deepcopy(sp)
    cm=copy.deepcopy(sm)
    cy=copy.deepcopy(sy)
    tmp=copy.deepcopy(l)
    for j in range(8-n):
        p,q=ll[j][int(s[j])]
        if p+q in cp or p-q in cm or q in cy:
            b=True
            break
        else:
            tmp.append((p,q))
            cp.add(p+q)
            cm.add(p-q)
            cy.add(q)
    if b:
        continue
    else:
        tmp.sort()
        for x,y in tmp:
            s="."*y+"Q"+"."*(7-y)
            print(s)



Measured memory_bytes: 6356
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#define int long long
int main()
{   char s[500005];
    scanf("%s",s);
    int l=strlen(s);
    long long a[l+2];
    for(int i=0;i<l+2;i++)a[i]=0;
    long long left=0,right=0,x=0;
    long long ans=0;
    for(int i=0;i<l;i++){
        if(s[i]=='<'){
            a[i]=left;
            left++;
        }else{
            a[i]=left;
            left=0;
        }
        if(i==l-1&&s[i]=='<'){
            a[l]=left;
        }
    }
    for(int i=l-1;i>=0;i--){
        if(s[i]=='>'){
            a[i+1]=right;
            right++;
            if(i==0){
                a[i]=right;
            }
        }else{
            a[i+1]=right>a[i+1]?right:a[i+1];
            right=0;
        }
        
        
    }
    //printf("%s\n",s);
    for(int i=0;i<l+1;i++){
        ans+=a[i];
        //printf("%d ",a[i]);
    }
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 4608
# -*- coding: utf-8 -*-
N,M = map(int, input().split())

dict_path = {i+1: [] for i in range(N)}

for _ in range(M):
  A,B = map(int, input().split())
  dict_path[A].append(B)
  dict_path[B].append(A)

list_bfs = [1]
list_flg = [0 for _ in range(N+1)]
list_flg[1] = 1

while len(list_bfs)>0:
  list_tmp = []
  for i in list_bfs:
    for j in dict_path[i]:
      if list_flg[j]==0:
        list_tmp.append(j)
        list_flg[j] = i
  list_bfs = list_tmp

print('Yes')
for i in list_flg[2:]:
  print(i)

Measured memory_bytes: 41976
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, a, b) for (int i = (a); i < (int)(b); i++)
typedef vector<int> VI;
typedef vector<VI> VVI;


string Main(int N, string S, string T)
{
    string ans;
    REP(i, N) {
        ans.push_back(S[i]);
        ans.push_back(T[i]);
    }
    return ans;
}

int main(void){
    int N;
    cin >> N;
    string S, T;
    cin >> S >> T;
    cout << Main(N, S, T) << endl;
    return 0;
}

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

using namespace std;

#define PI 3.14159265359

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, h, m;
    cin >> a >> b >> h >> m;
    double n1 = h * 60 + m;
    double arat = n1 / 720;
    double brat = n1 / 60;
    int tmp1 = arat, tmp2 = brat;
    arat = arat - tmp1;
    brat = brat - tmp2;
    double arad = 2 * PI * arat;
    double brad = 2 * PI * brat;
    double c;
    double rad;
    if (abs(arad - brad) * 2 > 2 * PI) {
        if (arad * 2 > 2 * PI) rad = 2 * PI - arad + brad;
        else if (brad * 2 > 2 * PI) rad = 2 * PI - brad + arad;
        c = sqrt(a * a + b * b - 2 * a * b * cos(rad));
    } else {
        rad = abs(arad - brad);
        c = sqrt(a * a + b * b - 2 * a * b * cos(rad));
    }
    printf("%.20f\n", c);
    return 0;
}

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

int main() {
  string S,T;
  cin >> S >> T;
  string ans = S;
  for (int i=0; i<S.size(); i++) {
    if (ans[i] == '?') {
      ans[i] = 'z';
    }
  }
  string term;
  bool can = false;
  if (S.size() < T.size()) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  
  for (int i=0; i<=S.size()-T.size(); i++) {
    term = S;
    for (int j=i; j<i+T.size(); j++) {
      if (S[j] != T[j-i] && S[j] != '?') {
        break;
      }
      term[j] = T[j-i];
      if (j == i+T.size()-1) {
        can = true;
        for (int k=0; k<S.size(); k++) {
          if (term[k] == '?') {
            term[k] = 'a';
          }
        }
        ans = min(ans,term);
      }
    }
  }
  if (can) {
    cout << ans << endl;
  }
  else {
    cout << "UNRESTORABLE" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
//ALDS1-1-B: Greatest Common Divisor
//2019.05.24

#include <stdio.h>

int main(void){
  int x, y;
  int tmp;
  int gcd;

  scanf("%d %d\n", &x, &y);
  if (x < y) {
    tmp = x;
    x = y;
    y = tmp;
  }

  while(1){
    tmp = y;
    y = x%y;
    x = tmp;
    if (y == 0) {
      gcd = x;
      printf("%d\n", gcd);
      break;
    }
  }

  return 0;
}



Measured memory_bytes: 2104
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
using System.Globalization;
using System.Runtime.CompilerServices;
using Library;

namespace Program
{
    public static class ABC147B
    {
        static public int numberOfRandomCases = 0;
        static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker)
        {
        }
        static public void Solve()
        {
            var S = NS;
            var cnt = 0;
            for (var i = 0; i < S.Length / 2; i++)
            {
                if (S[i] != S[S.Length - i - 1]) ++cnt;
            }
            Console.WriteLine(cnt);
        }
        static class Console_
        {
            static Queue<string> param = new Queue<string>();
            public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); }
        }
        class Printer : StreamWriter
        {
            public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
            public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; }
            public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; }
        }
        static public void Main(string[] args) { if (args.Length == 0) { Console.SetOut(new Printer(Console.OpenStandardOutput())); } var t = new Thread(Solve, 134217728); t.Start(); t.Join(); Console.Out.Flush(); }
        static long NN => long.Parse(Console_.NextString());
        static double ND => double.Parse(Console_.NextString());
        static string NS => Console_.NextString();
        static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
        static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
        static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
        static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift);
        static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred);
        static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n);
        static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c);
        static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } }
        static IEnumerator<uint> _xsi = _xsc();
        static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } }
    }
}
namespace Library {
}


Measured memory_bytes: 14560
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

string tos(int x) {
	string res;
	
	if(x == 0) return "0";
	
	for(int i = 0; x; i++){
		res.push_back(x%10 + '0');
		x /= 10;
	}
	
	reverse(res.begin(), res.end());
	// cout<<res<<endl;
	return res;
}
signed main(){
	cout<<fixed<<setprecision(10);
	
	int A, B;
	long double b;
	string y;
	int x;
	
	cin>>A>>y;
	
	
	
	if(y.size() == 4)B = (y[0] - '0') * 100 + (y[2] - '0') * 10 + (y[3] - '0') * 1;
	if(y.size() == 3)B = (y[0] - '0') * 100 + (y[2] - '0') * 10 ;
	if(y.size() == 1)B = (y[0] - '0') * 100 ;
	
	x = A * B;
	
	if(A == 0 || B == 0) {
		cout<<0<<endl;
		return 0;
	}
	// cout
	
	string n = tos(x);
	
	// cout<<n<<" x = "<<x<<endl;
	
	if(n.size() <= 2) {
		cout<<0<<endl;
		return 0;
	}
	
	for(int i = 0; i + 2 < n.size(); i++){
		cout<<n[i];
	}
	cout<<endl;
	
	return 0;
}

Measured memory_bytes: 3660
/************************************************************
	> File Name: c.cpp
	> Author: TSwiftie
	> Mail: 2224273204@qq.com 
	> Created Time: Mon 27 Apr 2020 06:43:49 PM CST
************************************************************/

#pragma GCC optimize(2)
#include <bits/stdc++.h>
#include <ext/rope>
#define lowbit(x) (x&-x)
#define SZ(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define lc (o<<1)
#define rc (o<<1|1)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long LL;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<LL> vll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int INF = 0x3f3f3f3f;
const LL INF_ll = 0x3f3f3f3f3f3f3f3fLL;
const double PI = acos(-1.0);
const double EPS = 1e-8;
map<string,bool>vis;
string str;
signed main(void){
	IOS;
	int n;
	cin >> n;
	for(int i = 1;i <= n;i++){
		cin >> str;
		vis[str] = true;
	}
	cout << vis.size() << endl;
	return 0;
}


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

typedef long long ll;
typedef pair<ll, ll> P;


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>=(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 100100100100100100;
const ll MOD = 1000000007;
const ll TREE_SIZE = 100100;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);

class Unionfind {
    public:
        vector<ll> par, siz, rank;
        Unionfind();
        ll root(ll x);
        void merge(ll x, ll y);
        bool issame(ll x, ll y);
        ll size(ll x);
};

int main() {
    ll n, m;
    cin >> n >> m;
    vector<ll> ans(m+1);
    vector<P> br;
    Unionfind tree;

    rep(i, m) {
        ll a, b;
        cin >> a >> b;
        br.push_back(make_pair(a,b));
    }

    ans[m] = n*(n-1)/2;
    for(ll i = m-1; i > 0; i--) {
        // 見る橋はbr[i], ans[i]に答え代入
        if(tree.issame(br[i].first, br[i].second)) ans[i] = ans[i+1];
        else {
            ans[i] = ans[i+1]-tree.size(br[i].first)*tree.size(br[i].second);
            tree.merge(br[i].first, br[i].second);
        }
    }

    frep(i, 1, m) {
        cout << ans[i] << endl;
    }

    return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count));
}

ll my_gcd(ll a, ll b) {
    if(b == 0) return a;
    return my_gcd(b, a%b);
}

ll inv(ll a) {
    return a_n(a, MOD-2);
}


Unionfind::Unionfind() {
    par.resize(TREE_SIZE);
    siz.resize(TREE_SIZE);
    rank.resize(TREE_SIZE);
    rep(i, TREE_SIZE) {
        par[i] = i;
        siz[i] = 1;
        rank[i] = 0;
    }
}
ll Unionfind::root(ll x) {
    if(par[x] == x) return x;
    else {
        return par[x] = root(par[x]);
    }
}
void Unionfind::merge(ll x, ll y) {
    x = root(x);
    y = root(y);
    if(x == y) return;
    if(rank[x] < rank[y]) {
        par[x] = y;
        siz[y] += siz[x];
    }
    else {
        par[y] = x;
        siz[x] += siz[y];
        if(rank[x] == rank[y]) rank[x]++;
    }
}
bool Unionfind::issame(ll x, ll y) {
    return root(x) == root(y);
}
ll Unionfind::size(ll x) {
    return siz[root(x)];
}

Measured memory_bytes: 6128
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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(void){  
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  string s;
  cin >> s;
  ll pcnt = 0, gcnt = 0;
  REP(i, s.size()){
    if(s[i] == 'p') pcnt++;
    else gcnt++;
  }

  ll possible_pcnt = s.size()/2;
  
  cout << max((possible_pcnt-pcnt), 0LL) << endl;
  
  return 0;
}


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

// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")

#define fr(i, a, b) for(int i = (a); i <= (b); ++i)
#define rf(i, a, b) for(int i = (a); i >= (b); --i)
#define fe(x, y) for(auto& x : y)

#define fi first
#define se second
#define pb push_back

#define pw(x) (1LL << (x))
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

using namespace std;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define fbo find_by_order
#define ook order_of_key

mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

template<typename T>
bool umn(T& a, T b) { return a > b ? a = b, 1 : 0; }
template<typename T>
bool umx(T& a, T b) { return a < b ? a = b, 1 : 0; }

const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 2e9;
const ll INF = 2e18;
const ld eps = 1e-9;

int main() {
#ifndef LOCAL
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
#endif
    int n;
    ll p = 1;
    bool bad = 0;
    cin >> n;
    fr(i, 1, n) {
        ll x;
        cin >> x;
        if(x == 0) {
            cout << "0\n";
            return 0;
        }
        if(!bad && x <= ll(1e18) / p) {
            p *= x;
        } else {
            bad = 1;
        }
        if(p > ll(1e18)) {
            bad = 1;
        }
    }
    if(bad) {
        cout << "-1\n";
    } else {
        cout << p << "\n";
    }
}

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

using namespace std;

#define ll long long

int A, B, C, X, ans = 0;

int main(){
    cin >> A >> B >> C >> X;

    for(int i = 0; i <= A; i++){
        for(int j = 0; j <= B; j++){
            for(int k = 0; k <= C; k++){
                int buff = 500*i + 100 * j + 50 * k;
                if(buff == X) ans++;
            }
        }
    }

    cout << ans << endl;
}


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

int main() {
    string s;
    cin >> s;

    if (s.at(0) != 'A') {
        cout << "WA" << endl;
        return 0;
    }

    int cnt = 0, idx;
    for (int i = 2, n = s.size() - 2; i <= n; i++)
        if (s.at(i) == 'C') {
            cnt++;
            idx = i;
        }

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

    for (int i = 1, n = s.size(); i < n; i++)
        if (i != idx) {
            char c = s.at(i);
            if (!('a' <= c && c <= 'z')) {
                cout << "WA" << endl;
                return 0;
            }
        }

    cout << "AC" << endl;
}

Measured memory_bytes: 3632
#include <stdio.h>
#define N 100

int main(){
  int i,j,s,length,count=0,flag;
  int A[N];
  
  scanf("%d", &length);
  for( i=0 ; i<length ; i++ ){
    scanf("%d", &A[i]);
  }
  
  flag = 1;
  while(flag){
    flag = 0;
    for( j=0 ; j<length ; j++ ){
      if( A[j]<A[j-1] ){
	s = A[j];
	A[j] = A[j-1];
	A[j-1] = s;
	count++;
	flag = 1;
      }
    }
  }
  
  for( i=0 ; i<length ; i++ ){
    printf("%d", A[i]);
    if( i!=length-1 )
      printf(" ");
  }
  printf("\n");
  printf("%d\n", count);
  return 0;
}

Measured memory_bytes: 604
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int x;
    cin>>x;
    int sum=0;
    int i;
    for(i=1;i<=x;i++){
        sum += i;
        if(sum>=x)break;
    }
    cout<<i<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <random>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using Pt = pair<int, int>;

int main()
{
	int N, K;
	cin >> N >> K;
	vl A(N);
	for (auto& x : A)
		cin >> x;
	sort(A.begin(), A.end());
	if (K == 0)
	{
		cout << A.back() << endl;
		return 0;
	}

	int LMax = A.back() + 1;
	int LMin = 0;
	while (LMin < LMax)
	{
		int L = (LMax + LMin) / 2;
		ll k = 0;
		for (int i = 0; i < N; ++i)
		{
			k += (A[i] - 1) / L;
		}
		if (k <= K)
		{
			LMax = L;
		}
		else
		{
			LMin = L;
		}
		if (LMin + 1 == LMax)
		{
			cout << LMax << endl;
			return 0;
		}

	}

}


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

int main () {
  int a , b , c , d ;
  cin >> a >> b >> c >> d ;
  
  if ( d <= a ) {
    cout << 0 << endl ; 
  } else if ( c <= a && a <=d && d <= b ) {
    cout << d - a << endl ;
  } else if ( c <= a && b <= d ) {
    cout << b - a << endl ;
  } else if ( a <= c && d <= b ) {
    cout << d - c << endl ;
  } else if ( a <= c && c <= b && b <= d ) {
    cout << b - c << endl ;
  } else {
    cout << 0 << endl ;
  }
}

Measured memory_bytes: 256
import sys
from heapq import *
from math import ceil
input = sys.stdin.readline
N = int(input())
H = []
for a in list(map(int, input().split())):
    heappush(H,-a)
off = 0
while True:
    x = heappop(H)
    a = -x+off
    if a<=N-1: print(off); exit()
    cnt = ceil(max(a-(N-1), 0)/(N+1))
    a -= cnt*(N+1)
    heappush(H,off-a)
    off += cnt

Measured memory_bytes: 74892
n=int(input())
hoge={}
for i in range(n):
  tmp=input()
  if(tmp in  hoge):
    hoge[tmp]+=1
  else:
    hoge[tmp]=1
    
key_max=max(hoge.values())
keys = [k for k, v in hoge.items() if v ==key_max]
hoge=sorted(keys)
for i in range(len(hoge)):
  print(hoge[i])

Measured memory_bytes: 35652
S = list(input())
T = list(input())
N = len(S)

abc = 'abcdefghijklmnopqrstuvwxyz'
sviewed = {c:False for c in abc}
spair = {}

tviewed = {c:False for c in abc}
tpair = {}

for i in range(N):
  si = S[i]
  ti = T[i]
  if sviewed[si] == True:
    if spair[si] != ti:
      print('No')
      exit()
  else:
    sviewed[si] = True
    spair[si] = ti
    
  if tviewed[ti] == True:
    if tpair[ti] != si:
      print('No')
      exit()
  else:
    tviewed[ti] = True
    tpair[ti] = si
    
print('Yes')


Measured memory_bytes: 6704
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <iostream>
#include <cmath>
#define ll long long
#define EPS 1e-5
#define FOR(i,x,y) for(int i = x; i <= y; ++i)
#define rFOR(i,x,y) for(int i = x; i >= y; --i)
#define MS(x,y) memset(x,y,sizeof x)
using namespace std;

const int MAXN = 2019;

int h,w;
char str[MAXN];
int a[MAXN][MAXN];
int b[MAXN][MAXN];
int up[MAXN],lef[MAXN],rig[MAXN];

int ck(int i,int j){
    return a[i][j] ^ a[i][j + 1] ^ a[i + 1][j] ^ a[i + 1][j + 1];
}

int main(){
    scanf("%d%d",&h,&w);
    MS(b,0);
    FOR(i,0,h - 1){
        scanf("%s",str);
        FOR(j,0,w - 1) a[i][j] = (str[j] == '#');
    }
    FOR(i,0,h - 2)
        FOR(j,0,w - 2)
            b[i + 1][j + 1] = ck(i,j);
    int ans = 0;
    MS(up,0);
    int pre;
    FOR(i,0,w){
        lef[i] = 0;
        rig[i] = w;
    }
    FOR(i,1,h){
        pre = 0;
        FOR(j,0,w){
            if(b[i - 1][j]){
                up[j] = 1;
                lef[j] = 0;
                rig[j] = w;
                pre = j;
            }
            else{
                up[j] = up[j] + 1;
                lef[j] = max(pre,lef[j]);
            }
        }
        pre = w;
        rFOR(j,w,0){
            if(b[i - 1][j]) pre = j;
            else rig[j] = min(pre,rig[j]);
            ans =  max(ans,(rig[j] - lef[j]) * up[j]);
            
        }
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 32000
#include <stdio.h>
int main(void)
{
	int a,b,w,h;
	while(1){scanf("%d %d",&w ,&h);

	if (w==0 && h==0){break;
	   }
	for(b=1; b<=w; b++){
	   for(a=1; a<=h; a++){
		if( b==1 || b==w )
	   	   putchar('#');
		else if( a==1 || a==h )
		   putchar('#');
		else
		   putchar('.');
	     }
	     putchar('\n');
	     }
	     putchar('\n');
	
	}
	return 0;
}


Measured memory_bytes: 2044