akhauriyash/Code-Regression huggingface dataset:
n = gets.to_i
l = gets.split.map(&:to_i).sort
count = 0
for i in 0..(n - 3) do
  for j in (i + 1)..(n - 2) do
    for k in (j + 1)..(n - 1) do
      if l[i] < l[j] && l[j] < l[k] && l[i] + l[j] > l[k]
        count += 1
      end
    end
  end
end
puts count


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

int main(){
    long long int n;
    cin >> n;
    long long int i, a, b;
    long long int ans;
    
    int long long x;
    x = (int)sqrt(n);
    
    for(i=x; i>0; i--){
        if(n % i == 0){
            a = n / i;
            b = i;
            break;
        }
    }
    
    ans = (a-1) + (b-1);
    cout << ans << endl;
    
    
    return 0;
}
    
    

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

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

  int A;
  map<int, int> mp;
  rep(i, N) {
    cin >> A;
    if (A % 4 == 0)
      mp[4]++;
    else if (A % 2 == 0)
      mp[2]++;
  }

  if (N / 2 <= mp[4] || N <= mp[2] + 2 * mp[4])
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3640
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    X = input().strip()
    stack = list()
    for s in X:
        if s == "S" or len(stack) < 1:
            stack.append(s)
        elif s == "T" and stack[-1] == "T":
            stack.append(s)
        else:
            stack.pop()
    return len(stack)


if __name__ == "__main__":
    print(main())

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

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

const int amax = 100000;
int num[100005];

int main(){
    int N;
    cin >> N;
    rep(i, N){
        int a;
        cin >> a;
        if(a != 0) num[a-1]++;
        num[a]++;
        if(a != 100000-1) num[a+1]++;
    }

    sort(num, num+amax, greater<int>());

    cout << num[0] << endl;

    return 0;
}

Measured memory_bytes: 640
def slove():
    import sys
    input = sys.stdin.readline
    a, b = list(map(int, input().rstrip('\n').split()))
    if a % 2 == 0 and b % 2 == 0:
        print(b ^ ((b - a) // 2 % 2))
    elif a % 2 == 1 and b % 2 == 1:
        print(a ^ ((b - a) // 2 % 2))
    elif a % 2 == 0 and b % 2 == 1:
        print((b - a + 1) // 2 % 2)
    elif a % 2 == 1 and b % 2 == 0:
        print(a ^ b ^ (b - a - 1) // 2 % 2)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38484
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <cmath>

#define	MOD 1000000007;
#define PI 3.14159265358979323846;
using namespace std;
typedef long long ll;
ll mod = 1000000007;

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

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

	int minValue = INT32_MAX;
	int sum = 0;
	for (int j = -100; j <= 100; j++)
	{
		sum = 0;
		for (int i = 0; i < N; i++)
		{
			int x = a[i] - j;
			sum += x * x;
		}
		minValue = min(minValue, sum);
	}

	cout << minValue << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <typeinfo>
#include <set>
#include <bitset>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
using namespace std;
typedef long long ll;



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

Measured memory_bytes: 3572
import scala.io.StdIn._

object Main extends App {

  val Array(n,d) = readLine().split(" ").map(_.toInt)
  val xy = Array.fill(n)(readLine().split(" ").map(_.toLong))

  def solve() = {
    xy.map { l =>
      Math.sqrt(l(0) * l(0) + l(1) * l(1))
    }.count(_ <= d)
  }

  println(solve())

}



Measured memory_bytes: 66380
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) ((v).begin(),(v).end())
using namespace std;

int main(){
    int n;
    cin >> n;
    int b[n-1];
    rep(i,n-1) cin >> b[i];
    
    int sum = b[0] + b[n-2];
    for(int i=1; i<n-1; i++){
        sum += min(b[i], b[i-1]);
    }

    cout << sum << endl;


    return 0;
}

Measured memory_bytes: 256
W, H, N = map(int, input().split())
X = []
Y = []
A = []
for i in range(N):
    x, y, a = map(int, input().split())
    X.append(x)
    Y.append(y)
    A.append(a)

## 長方形のマスを塗りつぶしていって残ったマス目を数えるイメージ
# 0: 白, 1: 黒
square = []
for i in range(H):
    horizonatlArea = []
    for j in range(W):
        horizonatlArea.append(0)
    square.append(horizonatlArea)

# Aの要素の番号に応じてsquareに1を埋めていく
for n in range(N):
    if A[n] == 1:
        for i in range(X[n]):
            for j in range(H):
                square[j][i] = 1
    elif A[n] == 2:
        for i in range(X[n], W):
            for j in range(H):
                square[j][i] = 1
    elif A[n] == 3:
        for i in range(W):
            for j in range(Y[n]):
                square[j][i] = 1
    elif A[n] == 4:
        for i in range(W):
            for j in range(Y[n], H):
                square[j][i] = 1

# square内の要素の数を数えて出力
cnt = 0
for j in range(H):
    cnt += square[j].count(0)

print(cnt)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> ii;
typedef tuple<int,int,int> iii;
#define ll long long
#define iiMPQ priority_queue<ii,vector<ii>,greater<ii> >
#define MPQ priority_queue<int,vector<int>,greater<int> >
#define PQ priority_queue<int>
#define iiPQ priority_queue<ii>
#define US unordered_set<int>
#define UMS unordered_multiset<int>
#define UM unordered_map<int>
#define iiUS unordered_set<ii>
#define ST stack<int>
#define MS multiset<int>
#define scan1(n) cin>>n
#define scan2(a,b) cin>>a>>b
#define scan3(a,b,c) cin>>a>>b>>c
#define print(n) cout<<n
#define println(n) cout<<n<<"\n"
#define vi vector<int>
#define vii vector<ii>
#define viii vector<iii>
#define fi first
#define se second
#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,s,e) for(int i=s;i<e;++i)
#define REPS(i,s,e,st) for(int i=s;i<e;i+=st)
#define rep(i,n) for(int i=n-1;i>=0;--i)
#define repr(i,s,e) for(int i=s;i>=e;--i)
#define reps(i,s,e,st) for(int i=s;i>=e;i-=st)
#define SET(arr,k) memset(arr,k,sizeof arr)
#define speed ios::sync_with_stdio(0); cin.tie(0);
#define mp make_pair
#define pb push_back
#define Qu queue
#define Vt vector
#define Dq deque
#define prints(n) cout << n << " ";


void m1(){
  int x; cin >> x;
  if(x >= 30 ) cout << "Yes";
  else cout<< "No";
}
/* 
void m2(){
  int t; scan1(t);
  while(t--) m1();
}
*/
 
signed main(){
  speed;
  //freopen("in.txt","r",stdin);
  m1();
  //m2();
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i < n; i ++)
#define rep1(i, n) for (int i=1; i <= n; i ++)
#define _min(x, y) x = min(x, y)
#define _max(x, y) x = max(x, y)
using namespace std;


int main() {
  long long N, K; cin >> N >> K;
  vector<long long> A;
  vector<long long> F;
  rep(i, N) {
    long long a; cin >> a;
    A.push_back(a);
  }
  rep(i, N) {
    long long f; cin >> f;
    F.push_back(f);
  }
  sort(A.begin(), A.end());
  sort(F.begin(), F.end());
  reverse(F.begin(), F.end());

  long long e = 0;
  rep(i, N) {
    _max(e, A[i] * F[i]);
  }
  long long s = -1;
  long long ans = e;
  while (s + 1 < e) {
    long long use = 0;
    long long _ans = (e + s) / 2;
    // cout << _ans << endl;
    rep(j, N) {
      if (A[j] * F[j] >= _ans) {
        use += max(0ll, A[j] - (_ans / F[j]));
        // cout << " ";
      }
      // cout << (long long)(_ans / F[j]) << " " << A[j] << " " << F[j] << " " <<use << endl;
    }
    //cout << endl;
    if (use <= K) {
      e = _ans;
    } else {
      s = _ans;
    }
  }
  cout << e << endl;
  return 0;
}


Measured memory_bytes: 5872
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define MAXN 2000
#define INF 0x3FFFFFFF
using namespace std;
typedef pair<int,int> PII;
char A[MAXN+5],B[MAXN+5];
vector<PII> need;
int n;
int seq1[MAXN+5],seq2[MAXN+5];
int psm1[MAXN+5],psm2[MAXN+5];
int sm1[MAXN+5],sm2[MAXN+5];
int maxr[MAXN+5];
void prepare()
{
	for(int i=0;i<n;i++)
		seq2[i]=B[i]-'0';
	for(int i=0;i<n;i++)
	{
		int len=-1;
		for(int j=0;j<n;j++)
			if(seq2[(i+j)%n]==1)
			{
				len=j;
				break;
			}
		psm1[i]=len;
		len=-1;
		for(int j=0;j<n;j++)
			if(seq2[(i-j+n)%n]==1)
			{
				len=j;
				break;
			}
		psm2[i]=len;
	}
}
int solve()
{
	int ret=INF;
	sort(need.begin(),need.end());
	maxr[need.size()]=0;
	for(int i=need.size()-1;i>=0;i--)
		maxr[i]=max(maxr[i+1],need[i].second);
	ret=2*maxr[0];
	for(int i=0;i<(int)need.size();i++)
		ret=min(ret,need[i].first*2+maxr[i+1]*2);
	return ret;
}
int main()
{
	scanf("%s %s",A,B);
	n=strlen(A);
	prepare();
	int ans=INF;
	for(int mv=0;mv<n;mv++)
	{
		int cnt=0;need.clear();
		for(int i=0;i<n;i++)
		{
			seq1[(mv+i)%n]=A[i]-'0';
			if(psm1[i]-mv<=0&&psm1[i]>=0)
				sm1[(mv+i)%n]=sm2[(mv+i)%n]=0;
			else
				sm1[(mv+i)%n]=psm1[i]-mv,sm2[(mv+i)%n]=psm2[i];
		}
		bool legal=true;
		for(int i=0;i<n;i++)
			if(seq1[i]!=seq2[i]&&sm1[i]<0)
			{
				legal=false;
				break;
			}
		if(legal==false)	continue;
		for(int i=0;i<n;i++)
			if(seq1[i]!=seq2[i])
				cnt++,need.push_back(PII(sm2[i],sm1[i]));
		ans=min(ans,solve()+mv+cnt);
	}
	for(int mv=0;mv<n;mv++)
	{
		int cnt=0;need.clear();
		for(int i=0;i<n;i++)
		{
			seq1[(i-mv+n)%n]=A[i]-'0';
			if(psm2[i]-mv<=0&&psm2[i]>=0)
				sm1[(i-mv+n)%n]=sm2[(i-mv+n)%n]=0;
			else
				sm1[(i-mv+n)%n]=psm1[i],sm2[(i-mv+n)%n]=psm2[i]-mv;
		}
		bool legal=true;
		for(int i=0;i<n;i++)
			if(seq1[i]!=seq2[i]&&sm1[i]<0)
			{
				legal=false;
				break;
			}
		if(legal==false)	continue;
		for(int i=0;i<n;i++)
			if(seq1[i]!=seq2[i])
				cnt++,need.push_back(PII(sm2[i],sm1[i]));
		ans=min(ans,solve()+mv+cnt);
	}
	if(ans!=INF)
		printf("%d\n",ans);
	else
		printf("-1\n");
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    int n;
    cin >> n;
    if(n%10 == 3){
        cout << "bon" << endl;
    }else if(n%10==0 or n%10==1 or n%10==6 or n%10==8){
        cout << "pon" << endl;
    }else{
        cout << "hon" << endl;
    }
    return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>

using namespace std;
typedef long long ll;

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

/*迷路
const int INF = 50;

typedef pair<int,int> P;
char field[52][52];
int d[51][51];
int r,c;
int sx,sy;
int gx,gy;

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

int bfs(){
    queue<P> que;
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            d[i+1][j+1] = INF;
        }
    }
    que.push(P(sy,sx));
    d[sy][sx]=0;
while(que.size()){
    P p=que.front();
    que.pop();
    if(p.second==gx&&p.first==gy) break;
    for(int i=0;i<4;i++){
        int nx=p.second+dx[i];
        int ny=p.first+dy[i];

        if(1<=nx&&nx<=c&&1<=ny&&ny<=r&&field[ny][nx]!='#'&&d[ny][nx]==INF){
            que.push(P(ny,nx));
            d[ny][nx] = d[p.first][p.second] + 1;
        }
    }
}
return d[gy][gx];
}
*/

int main(){
    int n;
    cin>>n;
    int w[n];
     int sum = 0;
    for(int i = 0;i<n;i++){
        cin>>w[i];
        sum+=w[i];
    }
   int sum2 = 0;
   int d = 10000;
    for(int i = 0; i<n;i++){
        sum-=w[i];
        sum2+=w[i];
        if(abs(sum - sum2)<d)
        d = abs(sum-sum2);
    }
    cout<<d<<endl;
    return 0;
}


Measured memory_bytes: 256
N, T = map( int, input().split())
S = list( map( int, input().split()))
S.append(10**10)
ans = 0
now = 0
for i in range(1,N+1):
    ans += min( S[i] - now, T)
    # if S[i] - now >= T:
    #     ans += T
    # else:
    #     ans += S[i] - now
    now = S[i]
print(ans)

Measured memory_bytes: 25196
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string.h>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
int main(void)
{
    string s;
    cin >> s;
    lli min = 1111111111;
    for (int i = 0; i < s.length() - 2; i++)
    {
        int tmp1 = s[i]-'0'; 
        int tmp2 = s[i + 1]-'0';
        int tmp3 = s[i + 2]-'0';
        lli tmpi = 100*tmp1+10*tmp2+tmp3;
        if (abs(tmpi - 753) < min)
        {
            min = abs(tmpi - 753);
        }
    }
    cout << min << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
    ll N;
    cin >> N;
    ll i;
    ll ta,xa,ya,tb,xb,yb;
    ta=0;
    xa=0;
    ya=0;
    ll b;
    for(i=0;i<N;i++){
      cin >> tb >> xb >> yb;
      b=abs(xb-xa)+abs(yb-ya);
      if(tb-ta<b||b%2!=(tb-ta)%2){
        cout << "No";
        return 0;
      }
      ta=tb,xa=xb,ya=yb;
    }
    cout << "Yes";
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
using namespace std;

const int maxn = 2e5;
const long long inf = 1e18;
int n, a[maxn];
long long b[maxn], c[maxn];
set<long long> s;

int main(void) {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
  }
  long long sum;

  s.clear();
  s.insert(a[0]);
  sum = a[0];
  for (int i = 1; i < n; ++i) {
    sum += a[i];
    auto u = s.lower_bound(sum / 2);
    if (u != s.end()) {
      b[i] = max(b[i], min(*u, sum - *u));
    }
    if (u != s.begin()) {
      --u;
      b[i] = max(b[i], min(*u, sum - *u));
    }
    s.insert(sum);
  }

  s.clear();
  s.insert(a[n - 1]);
  sum = a[n - 1];
  for (int i = n - 2; i >= 0; --i) {
    sum += a[i];
    auto u = s.lower_bound(sum / 2);
    if (u != s.end()) {
      c[i] = max(c[i], min(*u, sum - *u));
    }
    if (u != s.begin()) {
      --u;
      c[i] = max(c[i], min(*u, sum - *u));
    }
    s.insert(sum);
  }

  long long sum2 = 0, ans = inf;
  for (int i = 0; i < n; ++i) {
    sum2 += a[i];
    if (i >= 1 && i + 2 < n) {
      ans = min(ans, max(max(b[i], sum2 - b[i]),
                         max(c[i + 1], sum - sum2 - c[i + 1])) -
                min(min(b[i], sum2 - b[i]),
                    min(c[i + 1], sum - sum2 - c[i + 1])));
    }
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 13568
#include<bits/stdc++.h>
#define f(i,a,b) for(register int i=a;i<=b;++i)
#define ff(i,a,b) for(register int i=a;i>=b;--i)
#define debug(x) cerr << #x << " : " << x << " " << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
const ll mod = 998244353;
const ll mod1 = 2e18 + 7;
const double tiaohe = 0.57721566490153286060651209;
const int inf = 0x3f3f3f3f;
ll oula(ll x) { ll res = x;f(i, 2, x / i) { if (x % i == 0) { res = res / i * (i - 1);while (x % i == 0) x /= i; } }if (x > 1) res = res / x * (x - 1);return res; }
ll quickmod(ll a, ll n, ll m) { ll s = 1;while (n) { if (n & 1) { s = s * a % m; }a = (a*a) % m;n = n / 2; }return s; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
void ex_gcd(ll a, ll b, ll &x, ll &y, ll &d) { if (!b) { d = a, x = 1, y = 0; } else { ex_gcd(b, a % b, y, x, d);y -= x * (a / b); } }
ll inv(ll t, ll p) { ll d, x, y;ex_gcd(t, p, x, y, d);return d == 1 ? (x % p + p) % p : -1; }
//double a = log(n) +tiaohe + 1.0 / (2 * n);
double eqa = (1 + sqrt(5.0)) / 2.0;
const int N = 6e5 + 5;
int t;

int main()
{
	//freopen("in.txt", "r", stdin);
	int n;
	cin >> n;
	int tmp = n % 1000;
	int ans = (1000 - tmp) % 1000;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
    int n,k,s,d=1e9;
    cin >> n >> k >> s;
    if(s==d) d = 1;
    rep(i,k) cout << s << ' ';
    rep(i,n-k) cout << d << ' ';
    cout << endl;
}


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		sc.close();
		int r = 1;
		for(int i=0;i<n;i++){
			// 操作A
			int a = r * 2;
			// 操作B
			int b = r + k;
			// 小さい方をセット
			if(a<b) r = a;
			else r = b;
		}
		System.out.println(r);
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cassert>
#include <string>
#include <memory.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <map>
#include <cctype>
#include <iomanip>
#include <sstream>
#include <cctype>
#include <fstream>
#include <cmath>
using namespace std;

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define ITER(c) __typeof((c).begin())
#define PB(e) push_back(e)
#define FOREACH(i, c) for(ITER(c) i = (c).begin(); i != (c).end(); ++i)
#define MP(a, b) make_pair(a, b)
#define PARITY(n) ((n) & 1)

typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1000 * 1000 * 1000 + 7;
const double EPS = 1e-10;

const int maxn = 14;
const int maxl = 21;

int dp[1<<maxn][maxn][maxl];
int next_str[maxn][maxl][maxn];
int next_len[maxn][maxl][maxn];
int cost[maxn][maxl][maxn];

string needed_str(const string &s1, const string &s2){
  for(int i = min(s1.size(), s2.size()); i > 0; i--){
    if(s1.substr(s1.size()-i, i) == s2.substr(0, i)) return s2.substr(i);
  }
  return s2;
}

void set_next(int &strID, int &len, const string &str, const vector<string> &vs){
  int best = 0;
  REP(i, vs.size()) {
    for(int j = min(str.size(), vs[i].size()); j > 0; j--){
      if(str.substr(str.size() - j, j) == vs[i].substr(0, j) && best < j){
	strID = i;
	len = best = j;
      }
    }
  }
}

void init_table(const vector<string> &vs){
  REP(i, vs.size())REP(j, vs[i].size() + 1){
    string s1 = vs[i].substr(0, j);
    REP(k, vs.size()){
      string s2 = needed_str(s1, vs[k]);
      cost[i][j][k] = s2.size();
      set_next(next_str[i][j][k], next_len[i][j][k], s1 + s2, vs);
    }
  }
}

vector<string> erase_substr(vector<string> vs){
  int n = vs.size();
  REP(i, n)REP(j,n)if(i != j){
    if(vs[i] == vs[j]){
      if(i < j) vs[j] = "";
    }else if(vs[i].find(vs[j]) != string::npos){
      vs[j] = "";
    }
  }
  vector<string> res;
  REP(i, n)if(vs[i] != "") res.PB(vs[i]);
  return res;
}

int main(){
  int N;
  
  while(cin >> N && N){
    vector<string> vs;
    REP(i, N){
      string s;
      cin >> s;
      vs.PB(s);
    }
    
    vs = erase_substr(vs);
    init_table(vs);
    
    
    N = vs.size();
    fill(&dp[0][0][0], &dp[0][0][0] + (1 << maxn) * maxn * maxl, INF);
    dp[0][0][0] = 0;
    
    REP(mask, 1 << N)REP(i, N)REP(j, vs[i].size() + 1){
      if(dp[mask][i][j] == INF) continue;
      REP(k, N){
        int nstr = dp[mask][i][j] + cost[i][j][k];
        int &str = dp[mask | (1 << k)][next_str[i][j][k]][next_len[i][j][k]];
	if(str > nstr) str = nstr;
      }
    }
    
    int res = INF;
    REP(i, N)REP(j, vs[i].size() + 1){
      int s = dp[(1 << N) - 1][i][j];
      if(s != -1) res = min(res, s);
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 20092
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define ull unsigned long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
using namespace std;

int main() 
{
	int S;
	cin >> S;
	int x = S/3600;
	int y = S/60-x*3600/60;
	cout << x << ":" << y << ":" << S-x*3600-60*y << endl;
}


Measured memory_bytes: 3084
#include <iostream>
#include <vector>

using namespace std;

#define max(A,B) (((A)>(B)) ? (A) : (B))
#define min(A,B) (((A)<(B)) ? (A) : (B))
#define abs(A) (((A)<0) ? (-(A)):(A))
#define celi(A,B) (((A)+(B)-1) / (B))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define M 300300
int vm[M], hm[M];
vector<pair<int, int>> cand;
void solve(int tc) {
	int h, w, m, x, y;
	cin >> h >> w >> m;
	rep1(i, h) hm[i] = 0;
	rep1(i, w) vm[i] = 0;
	rep(i, m) {
		cin >> x >> y;
		cand.push_back(make_pair(x,y));
		hm[x]++;
		vm[y]++;
	}
	x = y = 0;
	rep1(i, h) x = max(x, hm[i]);
	rep1(i, w) y = max(y, vm[i]);

	int xcnt = 0, ycnt = 0, cnt = 0;
	rep1(i, h) if (hm[i] == x) xcnt++;
	rep1(i, w) if (vm[i] == y) ycnt++;

	cnt = xcnt * ycnt;
	rep(i, cand.size()) {
		pair<int, int> p = cand[i];
		if (hm[p.first] == x && vm[p.second] == y) cnt--;
	}
	if (cnt == 0) x--;
	cout << x + y << endl;
}
signed main() {
	int T = 1, tc;
	//	cin >> T;
	for (tc = 1; tc <= T; tc++) solve(tc);
}

Measured memory_bytes: 9748
import sys

n, m = map(int, input().split())

toshi = [list(map(int, input().split())) for i in range(m)]

toshi_flag = [0] * n

for i in range(len(toshi)):
    for j in range(len(toshi[i])):
        toshi_flag[toshi[i][j] - 1] += 1

for item in toshi_flag:
    print("{}".format(item))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
mt19937_64 llrand(random_device{}());
 
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define cl(x, v) memset((x), (v), sizeof(x))
#define db(x) cerr << #x << " == " << x << endl
#define dbs(x) cerr << x << endl
#define _ << ", " <<
#define gcd(x, y) __gcd((x), (y))
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
typedef vector<int> vi;
typedef vector<vi> vii;
 
const ld EPS = 1e-9, PI = acos(-1.);
const ll LINF = 0x3f3f3f3f3f3f3f3f, LMOD = 1011112131415161719ll;
const int INF = 0x3f3f3f3f, MOD = 1e9+7;
const int N = 2e5+5;
 
typedef long long type;
struct line { type b, m; };
 
int nh, pos;
line hull[N];
 
bool check(line s, line t, line u) {
    return (s.b - t.b)*(u.m - s.m) < (s.b - u.b)*(t.m - s.m);
}
 
void update (line s) {
    if (nh == 1 and hull[nh-1].b == s.b) nh--;
    if (nh > 0  and hull[nh-1].m >= s.m) return;
    while (nh >= 2 and !check(hull[nh-2], hull[nh-1], s)) nh--;
    pos = min(pos, nh);
    hull[nh++] = s;
}
 
type eval (int id, type x) { return hull[id].b + hull[id].m * x; }
 
type query(type x) {
    int lo = 0, hi = nh-1;
    while (lo < hi) {
        int mid = (lo+hi)/2;
        if (eval(mid, x) > eval(mid+1, x)) hi = mid;
        else lo = mid+1;
    }
    return eval(lo, x);
}

 
ll n, c, h[N], dp[N];
 
int main () {
    scanf("%lld%lld", &n, &c);
 
    for (int i = 0; i < n; i++) {
        scanf("%lld", &h[i]);
        ll q = -query(h[i]) + h[i]*h[i];
        if (i > 0) dp[i] = -query(h[i]) + h[i]*h[i];
 
        line l;
        l.b = -(h[i]*h[i] + c + dp[i]);
        l.m = -(-2*h[i]);
        update(l);
    }
 
    printf("%lld\n", dp[n-1]);
 
    return 0;
}

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

void Command(list<int> &X, string &c){
	if(c == "insert"){
		int d;
		cin >> d;
		X.push_front(d);
	}else if(c == "delete"){
		int d;
		cin >> d;
		list<int>::iterator itr = X.begin();
		while(*itr != d && itr != X.end()){
			itr++;
		}
		if(itr != X.end()){
			X.erase(itr);
		}
	}else if(c == "deleteFirst"){
		X.pop_front();
	}else if(c == "deleteLast"){
		X.pop_back();
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	list<int> X;
	for(int i = 0; i < n; i++){
		string c;
		cin >> c;
		Command(X, c);
	}
	list<int>::iterator it  = X.begin();
	list<int>::iterator end = X.end();
	end--;
	while(it != end){
		cout << *it << ' ';
		it++;
	}
	cout << *end << endl;
	return 0;
}

Measured memory_bytes: 32480
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    S = iss()
    if 1 <= int(S[:2]) <= 12 and 1 <= int(S[2:]) <= 12:
        print('AMBIGUOUS')
    elif 1 <= int(S[:2]) <= 12:
        print('MMYY')
    elif 1 <= int(S[2:]) <= 12:
        print('YYMM')
    else:
        print('NA')


if __name__ == '__main__':
    main()


Measured memory_bytes: 10180
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

class THuman
{
public:
	void Move(int Distance);
	void Turn(int Degree);
	double GetIntegerPartX();
	double GetIntegerPartY();
	THuman();
private:
	double FX;
	double FY;
	int FDegree;
};

void THuman::Move(int Distance)
{
	FX += Distance * sin(FDegree * M_PI / 180);
	FY += Distance * cos(FDegree * M_PI / 180);
}

void THuman::Turn(int Degree)
{
	FDegree += Degree;
}

double THuman::GetIntegerPartX()
{
	double GaussX, FractionalX;
	FractionalX = modf(FX, &GaussX);
	return GaussX;
}

double THuman::GetIntegerPartY()
{
	double GaussY, FractionalY;
	FractionalY = modf(FY, &GaussY);
	return GaussY;
}

THuman::THuman()
{
	FX = 0;
	FY = 0;
	FDegree = 0;
}

int main()
{
	THuman Human;
	while(true){
		int Distance;
		int Degree;
		char Dummy;
		cin >> Distance >> Dummy >> Degree;
		if(Distance == 0 && Degree == 0) break;
		Human.Move(Distance);
		Human.Turn(Degree);
	}
	cout << fixed << setprecision(0) << Human.GetIntegerPartX() << endl << Human.GetIntegerPartY() << endl;
	return 0;
}

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

int main()
{
    int N;
    cin>>N;
    string S;
    cin>>S;

    vector<int> A(N);
    for (int i=0; i<N; i++)
    {
        switch (S[i])
        {
        case 'R': A[i] = 0; break;
        case 'G': A[i] = 1; break;
        case 'B': A[i] = 2; break;
        }
    }

    long long ans = 0;
    for (int i=0; i<N; i++)
    {
        int X[3] = {};
        int Y[3] = {};
        for (int j=0; j<i; j++)
            X[(A[j]-A[i]+3)%3]++;
        for (int j=i+1; j<N; j++)
            Y[(A[j]-A[i]+3)%3]++;
        ans += X[1]*Y[2]+X[2]*Y[1];
        for (int j=1; 0<=i-j && i+j<N; j++)
            if (A[i-j]!=A[i] && A[i+j]!=A[i] && A[i-j]!=A[i+j])
                ans--;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,re;
    cin>>a>>b;
    re=b*2;
    if(a>re){
        cout<<(a-re)<<endl;
    }
    else{
        cout<<0<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(auto i = (N) - 1; i >= 0; i -= 1)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define vrep(v,it) for(auto it = v.begin(); it != v.end(); it++)
#define vrepr(v,it) for(auto it = v.rbegin(); it != v.rend(); it++)
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define rand mtrand
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cout << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,...) do { cout << #v << " = "; array_out(v , ##__VA_ARGS__);cout << endl;} while(0)
#else
  #define trc(...)
  #define trca(...)
#endif
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = 0x1FFFFFFFFFFFFFFFLL;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(15);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}

random_device seed_gen; mt19937_64 mtrand(seed_gen());
constexpr int MOD = 1000000007;
//////////////////////////////////////////

int main(){
  ini(N,L);
  vector<string> v(N);
  in(v);
  sort(all(v));
  rep(i,N) cout << v[i];
  out();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;
typedef pair<int,int> pii;
typedef pair<int,pii> pip;

int n,par[100010],rnk[100010];

void init(){
    for(int i=0;i<n;i++){
        par[i]=i;
    }
}
int find(int x){
    if(par[x]!=x)return par[x]=find(par[x]);
    return x;
}
void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y)return;
    if(rnk[x]<rnk[y]){
        par[x]=y;
    }else{
        par[y]=x;
        if(rnk[x]==rnk[y])rnk[x]++;
    }
}
bool same(int x,int y){
    return find(x)==find(y);
}

int main(){
    cin>>n;
    pii x[n],y[n];
    for(int i=0;i<n;i++){
        int tx,ty;
        cin>>tx>>ty;
        x[i]=make_pair(tx,i);
        y[i]=make_pair(ty,i);
    }
    sort(x,x+n);
    sort(y,y+n);
    vector<pip> d;
    for(int i=0;i<n-1;i++){
        d.push_back(make_pair(x[i+1].first-x[i].first,make_pair(x[i].second,x[i+1].second)));
        d.push_back(make_pair(y[i+1].first-y[i].first,make_pair(y[i].second,y[i+1].second)));
    }
    sort(d.begin(),d.end());
    init();
    ll ans=0LL;
    for(auto i:d){
        int u=i.second.first;
        int v=i.second.second;
        if(!same(u,v)){
            unite(u,v);
            ans+=i.first;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 6516
#include<bits/stdc++.h>
#define pb push_back
#define mod int(1e9+7)
#define N int(1e5+100)
#define pi 3.141592653589793238
#define ll unsigned long long int
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define si second
using namespace std;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int r;
	cin>>r;
	printf("%.3f\n",(2*pi*r));
   return 0;
}


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

using namespace std;

#define fto(i, s, e) for(int i = s; i <= e; ++i)
#define fto1(i, s, e) for(int i = s; i < e; ++i)
#define fdto(i, s, e) for(int i = s; i >= e; --i)
#define fit(var, it) for(__typeof(var.begin()) it = var.begin(); it != var.end(); ++it)
#define frit(var, it) for(__typeof(var.rbegin()) it = var.rbegin(); it != var.rend(); ++it)

#define newl '\n'
#define debugt cerr << 0.001*clock() << newl
#define debug1(x, i) cout << #x << '[' << i << "] = " << x[i] << newl
#define debug(v, l, r) fto(_i, l, r) debug1(v, _i)
#define debug2(x, i, j) cout << #x << '[' << i << "][" << j << "] = " << x[i][j] << newl
#define debug3(x, i, j, k) cout << #x << '[' << i << "][" << j << "][" << k << "] = " << x[i][j][k] << newl

#define ll long long
#define ii pair<int, int>
#define ff first
#define ss second
#define pb push_back
#define glen(v) int((v).size())

template<typename T1, typename T2> ostream& operator<< (ostream &os, pair<T1, T2> const &v) {
	return os << '(' << v.ff << ", " << v.ss << ')';
}

#define eps 1e-15
#define oo 1000000007
#define OO 1000000000000000003LL
#define maxn 3003

int n;
double ans;
double a[maxn];
double f[maxn][maxn];

int main() {
	#ifndef ONLINE_JUDGE
		//freopen("main.inp", "r", stdin);
		//freopen("main.out", "w", stdout);
	#endif
	//ios_base::sync_with_stdio(0); cin.tie(0);

	scanf("%d", &n);

	fto (i, 1, n) scanf("%lf", &a[i]);

	f[1][1] = a[1];
	f[1][0] = 1 - a[1];

	fto (i, 2, n) {
		fto (j, 1, i) {
			f[i][j] = f[i-1][j-1] * a[i];
		}

		fto1 (j, 0, i) {
			f[i][j] += f[i-1][j] * (1 - a[i]);
		}
	}

	fto (i, n/2+1, n) ans += f[n][i];

	printf("%.9f\n", ans);

	return 0;
}


Measured memory_bytes: 68992
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define rep0(i,n) rep(i,0,n)
#define rep1(i,n) rep(i,1,n+1)
#define repR(i,s,n) for(ll i = (n-1); i >= (s); i--)
#define repR0(i,n) repR(i,0,n)
#define repR1(i,n) repR(i,1,n+1)

#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR;
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR;
#define fcout cout << fixed << setprecision(18)

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

int a[100];
int cells[100][100]; // r * c

class Graph {
public:
  ll to, cost;
};

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

  vector<Graph> G[N];

  rep0(i, N - 1) {
    ll a, b, c;
    cin >> a >> b >> c;
    Graph g;
    a--; b--;
    g.to = b, g.cost = c;
    G[a].push_back(g);
    g.to = a;
    G[b].push_back(g);
  }

  int Q, K;
  cin >> Q >> K;
  K--;

  queue<int> q;
  vector<ll> D(N, -1);
  q.push(K);
  D[K] = 0;
  while (!q.empty()) {
    int t = q.front();
    q.pop();
    rep0(i, G[t].size()) {
      ll n = G[t][i].to;
      ll c = G[t][i].cost;
      if (D[n] == -1) {
        D[n] = D[t] + c;
        q.push(n);
      }
    }
  }

  rep0(i, Q) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    cout << D[x] + D[y] << BR;
  }
  return 0;
}

Measured memory_bytes: 10032
#include <cstdio>
#include <cstdint>
#include <cstdlib>
#include <vector>
#include <algorithm>

intmax_t f(const std::vector<intmax_t>& A, intmax_t m) {
  intmax_t res = 0;
  for (auto& ai: A)
    res += std::abs(ai-m);
  return res;
}

int main() {
  size_t N;
  scanf("%zu", &N);

  std::vector<intmax_t> A(N);
  for (size_t i = 0; i < N; ++i) {
    scanf("%jd", &A[i]);
    A[i] -= i-1;
  }

  std::sort(A.begin(), A.end());

  printf("%jd\n", std::min(f(A, A[N/2-1]), f(A, A[N/2])));
}


Measured memory_bytes: 1792
def main():
    S  = input()
    last = int(S[len(S)-1])
    if last == 2 or last == 4 or last == 5 or last == 7 or last == 9:
        print('hon')
    if last == 0 or last == 1 or last == 6 or last == 8:
        print('pon')
    if last == 3:
        print('bon')

if __name__ == '__main__':
    main()

Measured memory_bytes: 9184
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	ll N, M;cin >> N >> M;
	if (N * 2 >= M) { cout << M / 2 << endl; return 0; }
	cout << (N * 2 + M) / 4 << endl;
}

Measured memory_bytes: 380
N = input()

if len(N) == N.count("9"):
    print(9*len(N))
    exit()

if len(N) -1 == N.count("9"):
    if N[0] == str(9):
        print(9 * (len(N)-1) + 8)
        exit()
        
    sd = 0
    N = int(N)
    while N > 0:
        sd += N % 10
        N //= 10
    print(sd)
    exit()

if N[0] == 1:
    print(9 * (len(N) - 1) + 8)
else:
    print(int(N[0])-1 + 9 * (len(N) - 1))


Measured memory_bytes: 3064
#include<iostream>

using namespace std;

int main(){
  int N,X,L[110],D[110],z=0;
  cin >> N >> X;
  for(int i=0;i<N;i++){
    cin >> L[i];}
    D[0]=0;

    for(int i=1;i<N+1;i++){
      D[i] = D[i-1]+L[i-1];
    }
    for(int i=0;i<N+1;i++){
      if(D[i]<=X){
        z = z+1;
      }
    }
    cout << z << endl;
  return 0;
}


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


int main() {
  int N;
  int L[3000];
  int total = 0;
  
  cin >> N;
  
  for (int i = 0; i < N; ++i) cin >> L[i];
  sort(L, L + N, greater<int>());
  for (int a = 0; a < N - 2; ++a) {
    for (int b = a + 1; b < N - 1; ++b) {
      for (int c = b + 1; c < N; ++c) {
        
        if (L[b] + L[c] > L[a]){
          total += 1;
          
        }
      }
    }
  }
  cout << total << endl;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    m = list(map(int, input().split()))
    ans = 1
    if min(m) == 0:
        print(0)
    else:
        m.sort(reverse=True)
        for i in m:
            ans *= i
            if ans > 1000000000000000000:
                ans = -1
                break
        print(ans) 
if __name__ == "__main__":
    main()

Measured memory_bytes: 21756
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#define FAST ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn = (int)1e6 + 5;
const int mod = (int)1e9 + 9;
using namespace std;

ll x[maxn];
int v[maxn];
ll c[maxn], cc[maxn];
ll cmx[maxn], ccmx[maxn];

int main()
{
	//input
	int n; ll C; scanf("%d %lld", &n, &C);
	for(int i = 1; i <= n; i++) scanf("%lld %d", &x[i], &v[i]);
	//solve
	for(int i = 1; i <= n; i++){
		c[i] = c[i-1] + v[i] - (x[i] - x[i-1]);
		cmx[i] = max(cmx[i-1], c[i]);
	}
	x[n+1] = C;
	for(int i = n; i >= 1; i--){
		cc[n-i+1] = cc[n-i] + v[i] - (x[i+1] - x[i]);
		ccmx[n-i+1] = max(ccmx[n-i], cc[n-i+1]); 
	}
	ll ans = 0;
	for(int i = 0; i <= n; i++){
		ans = max(ans, c[i] - x[i] + ccmx[n-i]);
		ans = max(ans, cc[i] - (C - x[n-i+1]) + cmx[n-i]);
	}
	//output
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 15360
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
using namespace std;
int n; double X1[100], X2[100], Y1[100], Y2[100];
int x[200][200]; vector<pair<double, int> >X, Y;
pair<int, int>X3[200], Y3[200];
int main() {
	int cnt = 0;
	while (true) {
		cin >> n; cnt++; X.clear(); Y.clear(); if (n == 0)break;
		for (int i = 0; i < 40000; i++) { x[i / 200][i % 200] = 0; X3[i / 200] = make_pair(-1, -1); Y3[i / 200] = make_pair(-1, -1); }
		for (int i = 0; i < n; i++) {
			double L1, L2, L3; cin >> L1 >> L2 >> L3;
			X1[i] = L1 - L3, X2[i] = L1 + L3; Y1[i] = L2 - L3, Y2[i] = L2 + L3;
			X.push_back(make_pair(X1[i], i)); X.push_back(make_pair(X2[i], i));
			Y.push_back(make_pair(Y1[i], i)); Y.push_back(make_pair(Y2[i], i));
		}
		sort(X.begin(), X.end()); sort(Y.begin(), Y.end());
		for (int i = 0; i < 2 * n; i++) {
			int H = X[i].second; if (X3[H].first == -1) { X3[H].first = i; } else { X3[H].second = i; }
			int I = Y[i].second; if (Y3[I].first == -1) { Y3[I].first = i; } else { Y3[I].second = i; }
		}
		for (int i = 0; i < n; i++) {
			for (int j = X3[i].first; j < X3[i].second; j++) {
				for (int k = Y3[i].first; k < Y3[i].second; k++)x[j][k] = 1;
			}
		}
		double cnt2 = 0.0;
		for (int i = 0; i < 2 * n - 1; i++) {
			for (int j = 0; j < 2 * n - 1; j++) {
				if (x[i][j] == 0)continue;
				cnt2 += (X[i + 1].first - X[i].first)*(Y[j + 1].first - Y[j].first);
			}
		}
		cout << cnt << ' ' << fixed << setprecision(2) << cnt2 << endl;
	}
	return 0;
}

Measured memory_bytes: 1472
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;

int main(){
  int n;

  while( cin >> n ){
    if(n == -1)break;
    vector<int>ve;
    while(1){
      ve.push_back(n%4);
      n/=4;
      if(n == 0)break;
    }
    for(int i = ve.size()-1 ; i >= 0 ; i-- )cout << ve[i];
    cout << endl;
  } 
}

Measured memory_bytes: 1212
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const int INF=1e9;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n,k;
ll h[100010],dp[100010];


int main(int argc, char const *argv[]) {
  std::cin >> n >> k;
  rep(i,n) std::cin >> h[i];
  rep(i,100010) dp[i]=INF;
  dp[0]=0;

  for(int i=0; i<n; i++){
    for(int j=1; j<=k; j++){
      chmin(dp[i+j],dp[i]+abs(h[i]-h[j+i]));
    }
  }
  std::cout << dp[n-1] << '\n';
  return 0;
}


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

int main() {
    int n; cin >> n;
    vector<int> a(n+1);
    vector<int> b(n);
    rep(i,n+1) cin >> a[i];
    rep(i,n) cin >> b[i];
    
    ll ans = 0;
    for(int i = 0; i < n; i++){
        int left = min(a[i],b[i]);
        ans += left;
        a[i] -= left;
        b[i] -= left;
        
        int right = min(a[i+1],b[i]);
        ans += right;
        a[i+1] -= right;
        b[i] -= right;
    }
    cout << ans;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
typedef vector<int> vi;
//const int MAX=;

int main(){
	string s,t;
	cin>>s>>t;
	//sをi-1文字目まで、tをj-1文字目まで使った最長
	int dp[3002][3002];
	int sl=s.size();
	int tl=t.size();
	rep(i,sl)dp[i][0]={};
	rep(j,tl)dp[0][j]={};
	
	rep1(i,sl)rep1(j,tl){
		if(s[i-1]==t[j-1])dp[i][j]=dp[i-1][j-1]+1;
		else dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
	}
	
	string u;
	int i=sl,j=tl;
	while(i && j){
		if(s[i-1]==t[j-1]){
			u.push_back(s[i-1]);
			i--;j--;
		}
		else if(dp[i][j-1]>dp[i-1][j])j--;
		else i--;
	}
	reverse(u.begin(),u.end());
	cout<<u;
}

Measured memory_bytes: 35456
n,m,l = map(int,input().split())
A = [[int(i) for i in input().split()] for _ in range(n)]
B = [[int(i) for i in input().split()] for _ in range(m)]

res = [
    [sum([
        a*b for a,b in zip(A[i],list(zip(*B))[j])
    ])
    for j in range(l)]
for i in range(n)]

for r in res:
    print(*r)


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

struct drink_data {
  long long yen;
  int num;
};
bool operator < (const drink_data &l, const drink_data &r) {
  return l.yen > r.yen;
}

int main() {
  int n, m;
  priority_queue<drink_data> q;
  cin >> n >> m;
  for ( int i = 0; i < n; i++ ) {
    long long a;
    int b;
    cin >> a >> b;
    q.push({a, b});
  }

  long long ans = 0;
  while ( m-- > 0 ) {
    drink_data now_data = q.top();
    ans += now_data.yen;
    now_data.num--;
    q.pop();
    if ( now_data.num != 0 ) { q.push(now_data); }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5264
n = int(input())
ans = [0,0,0,0]
for i in range(n):
    s = input()
    if s == "AC":
        ans[0] += 1
    elif s == "WA":
        ans[1] += 1
    elif s == "TLE":
        ans[2] += 1
    else:
        ans[3] += 1
print("AC x",ans[0])
print("WA x",ans[1])
print("TLE x",ans[2])
print("RE x",ans[3])

Measured memory_bytes: 9204
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
	string s;
	int k;
	cin >> s;
	cin >> k;
	set<string> st;
	REP(i,s.size()){
		for(int j = 1; j <= k; j++){
			if(i + j <= s.size()) st.insert(s.substr(i,j));
		}
	}
	auto itr = st.begin();
	REP(i,k - 1){
		itr++;
	}
	cout << *itr << endl;
}

Measured memory_bytes: 1664
import sys
sys.setrecursionlimit(10**9)

def dfs(now_node,parent_node,dist):
  depth[now_node]=dist
  for next_node,w in graph[now_node]:
    if next_node==parent_node:
      continue
    dfs(next_node,now_node,dist+w)

n=int(input())
graph=[[] for _ in range(n+1)]
for _ in range(n-1):
  a,b,c=map(int,input().split())
  graph[a].append((b,c))
  graph[b].append((a,c))
  
q,k=map(int,input().split())
depth=[-1]*(n+1)
dfs(k,0,0)
for _ in range(q):
  x,y=map(int,input().split())
  print(depth[x]+depth[y])

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

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

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

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

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

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

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

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

#[allow(unused_mut)]
#[allow(non_snake_case)]
fn main() {
    input!{
        N: isize,
        M: isize,
        AB: [(isize, isize); N],
    }

    AB.sort_by(|a, b| a.0.cmp(&b.0));

    let mut count = M;
    let mut sum = 0;
    for (money, num) in AB.into_iter() {
        if count - num > 0 {
            count -= num;
            sum += money * num;
        } else {
            sum += money * count;
            break
        }
    }

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


Measured memory_bytes: 6396