akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

#define calc(x) (x[u][v]-x[u][t-1]-x[s-1][v]+x[s-1][t-1])

using namespace std;

int jn[1001][1001];
int oc[1001][1001];
int ic[1001][1001];

int main()
{
  char c;
  int n, m, k, s, t, u, v;

  while(cin>>m>>n && n+m){
    cin >> k;
    for(int i = 0; i <= m; ++i)
      for(int j = 0; j <= n; ++j)
	jn[i][j] = oc[i][j] = ic[i][j] = 0;

    for(int i = 1; i <= m; ++i){
      s = t = u = 0;
      for(int j = 1; j <= n; ++j){
	cin >> c;
	if(c == 'J') ++s;
	else if(c == 'O') ++t;
	else ++u;

	jn[i][j] += (s+jn[i-1][j]);
	oc[i][j] += (t+oc[i-1][j]);
	ic[i][j] += (u+ic[i-1][j]);
      }
    }

    while(k--){
      cin >> s >> t >> u >> v;
      cout << calc(jn) << " " << calc(oc) << " " << calc(ic) << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 12000
/*
=============================================================

------------------Welcome To My Code-------------------------

---------Ankit Kumar || IIITBH || CSE || 2018-2022-----------

=============================================================
*/

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

#define FASTIO  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long int
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vl(p) vector<p>
#define w while
#define For(i,s,x) for(i=s;i<x;i++)
#define Fore(i,s,x) for(i=s;i<=x;i++)
#define FOR(i,x) for(i=0;i<x;i++)
#define Rof(i,s,x) for(i=s;i>=x;i--)
#define all(v) v.begin(),v.end()
#define it(r,v) for(auto r=v.begin();r!=v.end();r++)
#define pb push_back
#define in insert
#define sz size()
#define F first
#define S second
#define nl cout<<"\n"
#define pr(a) cout<<a<<" "
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define pr3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n"
#define mod 1000000007
map<ll, ll>::iterator itr;
vector<ll>::iterator it, it1;
const double PI = 3.141592653589793238;

int main()
{
	FASTIO;

        ll i,j,k,x,y,z,m,n,a,b,c,c1=0,c2=0,flag=0,sum=0;
	string s,s1,str;
	cin>>x;
	if(x>=30)
        cout<<"Yes";
    else
        cout<<"No";
    nl;



}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr int INF = 2147483647;
constexpr long long INFF = 9223372036854775807;
const int MOD = 1000000007;
signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    int N;cin >> N;
    int T[N],A[N];
    bool flag[N] = {};
    int maxv = 0;
    REP(i,N){
        cin >> T[i]; 
        maxv = max(maxv,T[i]);
        if(i != 0 && T[i-1] != T[i]){
            flag[i] |= 1;
        }
    }
    REP(i,N){
        cin >> A[i];
        if(flag[i] && T[i] > A[i]){
            cout << 0 << endl;
            return 0;
        }
        if(i != 0 && A[i-1] != A[i]){
            flag[i-1] |= 1;
            if(T[i-1] < A[i-1]){
                cout << 0 << endl;
                return 0;
            }
        }
    }
    flag[0] = 1;flag[N-1] = 1;
    if(T[0] > A[0] || A[N-1] > T[N-1]){
        cout << 0 << endl;
        return 0;
    }
    long long ans = 1;
    REP(i,N){
        if(flag[i]) continue;
        ans *= min(T[i],A[i]);
        ans %= MOD;
    }
    bool F = 0;
    REP(i,N){
        if(A[i] == T[i] && T[i] == maxv) F = 1;
    }
    if(!F){
        cout << 0 << endl;
        return 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1152
#include<stdio.h>
int main(){
  int k,n,i,max;
  scanf("%d %d",&k,&n);
  int a[n];
  for(i=0;i<n;i++)scanf("%d",&a[i]);
  for(i=1,max=a[1]-a[0];i<n-1;i++){
    if(max<a[i+1]-a[i])max=a[i+1]-a[i];
  }
  if(max<k-a[n-1]+a[0])max=k-a[n-1]+a[0];
  printf("%d",k-max);
  return 0;
}


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

int main()
{
   int X,Y;cin>>X>>Y;
   bool ok=false;
   for(int i=0;i<=X;++i){
       int j=X-i;
       if(2*i+4*j==Y) ok=true;
   }
   cout<<(ok ? "Yes\n":"No\n");
   
}

Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
int main() {
	int n, a, b;
	cin >> n >> a >> b;
	
	if(n*a > b){
	    std::cout << b << std::endl;
	    
	}else{
	    std::cout << n*a << std::endl;
	    
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unistd.h>
#include <sys/time.h>
#include <stdlib.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> T;
typedef pair<long double , ll> Ps;
typedef pair<ll, bool> Pb;

const ll INF = 1e18;
const ll fact_table = 3200008;
long double Pi = 3.1415926535897932384626;

priority_queue <ll> pql;
priority_queue <P> pqp;
priority_queue <P> bag;
//big priority queue
priority_queue <ll, vector<ll>, greater<ll> > pqls;
priority_queue <P, vector<P>, greater<P> > pqps;
//small priority queue
//top pop

ll dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
ll dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};
char dir[] = "DRUL";
//↓,→,↑,←

#define endl "\n"
#ifdef ENJAPMA
#undef endl
#endif
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)();
#define pc(x) cout << x << ",";
#define rep(i, n) for (ll i = 0; i < (n); i ++)

// const ll mod = 998244353ll;
const ll mod = 1000000007ll;

ll mypow(ll a, ll b, ll mod) {ll x = 1; while (b) {while (!(b & 1)) {(a *= a) %= mod; b >>= 1;}(x *= a) %= mod; b--;} return x;}
void YES(bool cond) { if (cond) { p("YES");} else { p("NO");} return;}
void Yes(bool cond) { if (cond) { p("Yes");} else { p("No");} return;}

ll line_count = 0;

void line(){

    line_count ++;
    string s = (line_count % 2) ? "v-v-v-v-v-v-v-v-v-v" : "^-^-^-^-^-^-^-^-^-^";
    cout << endl << s << endl << endl;
}

/*
ll fact[fact_table + 5],rfact[fact_table + 5];

void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=fact_table; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[fact_table] = mypow(fact[fact_table],mod - 2, mod);
    for(ll i=fact_table; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod ) * rfact[n-r]) % mod;}
*/

bool multicase = false;

ll n, m, k, num, a, b, c, d, e, h, q, ans, sum;
string s;
bool used[500005];

void solve() {
    cin >> k >> n;
    for(ll i=0;i<n;i++){
        cin >> a;
        used[a] = true;
    }
    ll ans = INF;
    for(ll i=0;i<=200;i++){
        ll num1 = k - i, num2 = k + i;
        if(num1 < 0 || !used[num1]){
            ans = num1;
            break;
        }
        if(num2 < 0 || !used[num2]){
            ans = num2;
            break;
        }
    }
    p(ans);

    return;
}

int main() {
    // init();
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll q, testcase = 1;
    if (multicase) {
        cin >> q;
    } else {
        q = 1;
    }
    while (q--) {
        // pu("Case ");pu("#");pu(testcase);pu(": ");
        solve();
        testcase++;
    }
    // solve();
    return 0;
}
















Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define ll long long int 
#define mod 1000000007
#define se second
#define fi first
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	ll n,xx,yy;
	cin>>n>>xx>>yy;
	ll arr[n]={0};
	ll x,y,z;
	for(ll a=1;a<n;a++)
	{
		for(ll b=a+1;b<=n;b++)
		{
			arr[min(b-a,abs(xx-a)+1+abs(yy-b))]++;
		}
	}
	for(int a=1;a<n;a++)
	cout<<arr[a]<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int n,h[100000],x=0,flg=0,i,mx=1000000000;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&h[i]);
	}
	if(n==1) printf("Yes\n");
	else{
		for(i=n-1;i>=0;i--){
			if(mx>=h[i]){
				mx=h[i];
			}
			else if(mx>=h[i]-1){
				mx=h[i]-1;
			}
			else{
				flg=1;
				break;
			}
		}
		if(flg==0) printf("Yes\n");
			else printf("No\n");
	}
	return 0;
}


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

int main(){
  int n;
  cin>>n;
  vector<int> v(n);
  rep(i,n){
    cin>>v.at(i);
  }
  int ans=0;
  rep(i,n-2){
    
    if(v.at(i)<v.at(i+1)&&v.at(i+1)<v.at(i+2)) ans++;
    else if(v.at(i)>v.at(i+1)&&v.at(i+1)>v.at(i+2)) ans++;
  }
  cout<<ans<<endl;
}


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

#define sz(x) (int)(x.size())
#define FOR(i,L,R) for(int i = L; i <= R; i++)
#define int long long

const int N = 2e5 + 2, inf = 1e18;

int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    string s, t;
    cin >> s >> t;

    int n = sz(s);
    int m = sz(t);
    int ans = inf;

    for (int i = 0; i < n; i++) if(i + m - 1 < n) {
        int get = 0;
        for (int j = 0; j < m; j++) {
            get += s[i + j] != t[j];
        }
        ans = min(ans, get);
    }

    cout << ans;
}

Measured memory_bytes: 3616
//written by NewbieChd
#include <cstdio>
#include <cctype>
using namespace std;

const int BUF = 1000000;
char buf[BUF], *p1, *p2;
inline char getChar() { return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, BUF, stdin), p1 == p2) ? EOF : *p1++; }
inline int read() {
    register int f = 0;
    char c;
    while (!isdigit(c = getChar())) {}
    do
        f = f * 10 + (c ^ 48);
    while (isdigit(c = getChar()));
    return f;
}

const int maxN = 100003;

int main() {
    int m = read(), n = 1 << m, k = read(), i;
    if (k >= n) {
        printf("-1\n");
        return 0;
    }
    if (!k) {
        for (i = 0; i < n; ++i)
            printf("%d ", i);
        for (i = n - 1; ~i; --i)
            printf("%d ", i);
        return 0;
    }
    if (m == 1 && k == 1) {
        printf("-1\n");
        return 0;
    }
    for (i = 0; i < n; ++i)
        if (i != k)
            printf("%d ", i);
    printf("%d ", k);
    for (i = n - 1; ~i; --i)
        if (i != k)
            printf("%d ", i);
    printf("%d ", k);
    return 0;
}


Measured memory_bytes: 1792
def main():

    K, T = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort(reverse = True)
    if K % 2 == 1 and A[0] > (K+1)//2:
        return (A[0] - (K+1)//2) * 2
    elif K % 2 == 0 and A[0] > K  // 2:
        if A[0] - K // 2 == 1:
            return 1
        else:
            return 1 + (A[0] - K // 2 - 1) * 2
    else:
        return 0

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

Measured memory_bytes: 3064
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	private static Scanner scanner;
	private static PrintWriter writer;

	private static int nod;
	// private static int[] numbers;
	private static String numbers = new String();
	private static Set<BigDecimal> allNumbers = new HashSet<>();

	public static void main(String[] args) {
		scanner = new Scanner(System.in);
		writer = new PrintWriter(System.out, true);
		writer.flush();

		// ????????°???????????????
		nod = scanner.nextInt();

		// ??°??????????????????
		for (int i = 0; i < nod; i++) {
			int number = scanner.nextInt();
			numbers += Integer.toString(number);
		}

		// 0????????????????????£???????????????????????????????????????????????£?????????????????????????????£?????????????????????
		String res = "0";
		for (int i = 0;; i++) {
			String str = String.valueOf(i);
			int startIndex = 0;
			String scanStr = numbers;
			for (int j = 0; j < str.length(); j++) {
				if (!numbers.contains(str)) {
					res = String.valueOf(i);
					writer.println(res);
					scanner.close();
					writer.close();
					return;
				}
			}
		}

		// // ??°???????????¢?????§??????????????????????????????????????????????????????
		// for (int start = 0; start <= nod - 1; start++) {
		// for (int end = start + 1; end <= nod; end++) {
		// // System.out.println(numbers.substring(start, end));
		// allNumbers.add(new BigDecimal(numbers.substring(start, end)));
		// }
		// }
		//
		// // ??°???????°????????????????????????????
		// // TreeSet?????¨????????????????????£????????§????????§???????????????
		// List<BigDecimal> sorted = new ArrayList<>(allNumbers);
		// Collections.sort(sorted);
		//
		// // [????°????+1]=????°????+1?????????????????§??????
		// // YES????????????????????¨?????????????????????????????°break??????return ????°????+1
		// // Iterator<Integer> iterator = allNumbers.iterator();
		// Object[] array = sorted.toArray();
		// BigDecimal result = null;
		// for (int i = 0; i < allNumbers.size(); i++) {
		// if (!allNumbers.contains(BigDecimal.ZERO)) {
		// result = BigDecimal.ZERO;
		// break;
		// }
		// if (i == allNumbers.size()) {
		// result = new
		// BigDecimal(String.valueOf(array[i])).add(BigDecimal.ONE);
		// break;
		// }
		// BigDecimal value = new BigDecimal(String.valueOf(array[i]));
		// BigDecimal nextValue = new BigDecimal(String.valueOf(array[i + 1]));
		// if (!value.add(BigDecimal.ONE).equals(nextValue)) {
		// result = value.add(BigDecimal.ONE);
		// break;
		// }
		// }
	}

}

Measured memory_bytes: 34656
#include <stdio.h>
int main(){
  int a,b,count,check=0;
  scanf("%d",&a);
  int c[a];
  int d[a];
  d[0] = 0;
  scanf("%d",&b);
  for(int i=0; i<a; i++){
    scanf("%d",&c[i]);
  }
  
  for(int i=0; i<=a; i++){
    if(i==0){
      check=0;
    } else{
      check = d[i-1]+c[i-1];
      d[i] = check;
     }
    
    if(check<=b){
      count++;
    }
  }
  printf("%d",count);
  return 0;
}
  
  

Measured memory_bytes: 128
x1, x2, x3, x4, x5 = map(int, input().split())

if x1 == 0:
    print(1)
elif x2 == 0:
    print(2)
elif x3 == 0:
    print(3)
elif x4 == 0:
    print(4)
else:
    print(5)

Measured memory_bytes: 9172
l = map(long, raw_input().split())

height = []
for i in range(l[0]):
    height.append(long(input()))
    
height.sort()

diff = 1000000000000L
for x in range(len(height)-l[1]+1):
  if diff > height[x+l[1]-1] - height[x]:
    diff = height[x+l[1]-1] - height[x]
    
print diff

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

int main(){
  int N,i,j,tmp,A_score=0,B_score=0;
  cin >> N;
  vector<int> A(N+1);
  for(i=0;i<N;i++){
    cin >> A[i];
  }

  sort(A.begin(),A.end(),greater<int>());

  if(N%2 == 0){
    for(i=0;i<N/2;i++){
      A_score += A[2*i];
      B_score += A[2*i+1];
    }
  }
  else{
    for(i=0;i<(N+1)/2;i++){
      A_score += A[2*i];
      B_score += A[2*i+1];
    }
  }

  cout << (A_score-B_score) << endl;
  return 0;
}


Measured memory_bytes: 256
from sys import stdin
from sys import setrecursionlimit
from collections import Counter, deque, defaultdict
from math import floor
from bisect import bisect_left
setrecursionlimit(1000000)

INF = int(1e10)
MOD = int(1e9 + 7)

def input():
    return stdin.readline()[:-1]


def main():
    from builtins import int, map
    X = int(input())
    now = 100

    count = 0
    while now < X:
        count += 1
        now = floor(now * 1.01)

    print(count)


if __name__ == '__main__':
    main()

Measured memory_bytes: 68212
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define p(s) cout<<(s)<<endl
#define REP(i,n,N) for(int i=n;i<N;i++)
#define RREP(i,n,N) for(int i=N-1;i>=n;i--)
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
#define F first
#define S second
typedef long long ll;
using namespace std;
const int inf=1e9+7;

int N;
vector<int> vt;
int ans;
int dp[100010];
int main(){
    cin>>N;
    REP(i,0,N+1){
        dp[i] = inf;
    }
    int now=1;
    vt.push_back(1);
    for(int i=6;i<=N;i*=6){
        vt.push_back(i);
        //p(i);
    }
    for(int i=9;i<=N;i*=9){
        vt.push_back(i);
        //p(i);
    }
    sort(vt.begin(),vt.end());
    ans = N;
    dp[0]=0;
    REP(i,0,N){
        for(auto v:vt) if(i+v<=N)dp[i+v] = min(dp[i+v], dp[i]+1);
    }
    p(dp[N]);
    return 0;
}


Measured memory_bytes: 640
#include<iostream>

using namespace std;
typedef long long ll;
const int N= 2e5+10;

ll a[N];
ll c[N];
 
int main(){
//	freopen("in.txt","r",stdin);
	int n,k;
	scanf("%d%d",&n,&k);
	for(int i = 1 ; i <= n ; i ++) scanf("%lld",&a[i]);
	if(k>=n){
		for(int i = 1 ; i <= n ; i ++) printf("%d ",n);
		return 0;	
	}
	bool f=false;
	while(!f&&k--){
		int cnt=0;
		for(int i = 0 ; i <= n ; i ++) c[i]=0;
		for(int i = 1 ; i <= n ; i ++){
			int l=max(1ll,i-a[i]);
			int r=min(1ll*n,i+a[i]);
			c[l]++;
			c[r+1]--;
		} 
		for(int i = 1 ; i <= n ; i ++) c[i]+=c[i-1];
		for(int i = 1 ; i <= n ; i ++){
			a[i]=c[i];
			if(a[i]==n) cnt++;
		}
		if(cnt==n) f=true;
	}
	for(int i = 1 ; i <= n ; i ++) printf("%d ",a[i]);

	return 0;
}

Measured memory_bytes: 6240
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define ll2(x, y) ll x, y; cin >> x >> y;
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

ll p[70000];
ll j[70000];

signed main(void){
  int i;
  for(int testcase = 0;testcase >= 0;testcase++){
    int(n);
    if(!n)break;

    scn(n, p);
    scn(n - 1, j);

    ll res = 0, sum = 0;
    rep(i, n)sum += p[i];
    res = sum * (ll)n;

    sort(j, j + n - 1);

    per(i, n - 1){
      sum += j[i];
      res = max(res, sum * (i + 1));
    }
    pri(res);


//*/

//*/ break;
  }
  return 0;
}

Measured memory_bytes: 4160
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
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 main() {
    int n; cin >> n;

    int s = n;
    if (n % 2 == 0) s++;

    vector<pii> v;
    for (int i = 1; i < n; i++) {
        for (int j = i+1; j <= n; j++) {
            if (i + j == s) continue;
            v.emplace_back(i, j);
        }
    }

    cout << v.size() << endl;
    for (auto x: v) {
        cout << x.first << " " << x.second << endl;
    }
}


Measured memory_bytes: 384
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <tuple>
#include <climits>
using namespace std;

int inf = INT_MAX;
//int inf = LLONG_MAX;

int res = 0;
string s;

int main()
{
    cin >> s;

    int len = s.size();

    s = s + 'n';

    int p = 0;

    while (p < len - 1 && len >= 2)
    {
        if (s[p] != s[p + 1])
        {
            s = s.substr(0, p) + s.substr(p + 2);
            len -= 2;
            res += 2;
            if (p != 0)
            {
                p--;
            }
        }
        else
        {
            p++;
        }
    }

    cout << res;
    return 0;
}

Measured memory_bytes: 696
if __name__ == '__main__':
    b, c = map(int, input().split())

    min = 9999
    for i in range(b):
        a = [int(i) for i in input().split()]
        if  a[1]<= c and a[0] < min:
            min = a[0]

    if min == 9999:
        print("TLE")
    else:
        print(min)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod = 1e9 + 7;
int main(){
    int s;
    cin >> s;
    vector<ll> f(s + 1);
    f[0] = 1;
    for(int i = 3; i <= s; i++){
        f[i] = f[i - 1] + f[i - 3];
        f[i] %= mod;
    }
    cout << f[s] << endl;
    return 0;
}

Measured memory_bytes: 3628
S = list(input())
l = len(S)
ans = 0
for i in range(1<<(l-1)):
    X = S[:]
    for j in range((l-1)):
        if i >> j & 1:
            X.insert(l-j-1,'+')
    X = ''.join(X)
    ans += sum(list(map(int,X.split('+'))))
print(ans)

Measured memory_bytes: 89900
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int x,y;
	cin>>x>>y;
	bool yn=0;
	for(int i=0;i<=x;i++)
		if(2*i+4*(x-i)==y)
			yn=1;
	if(yn)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
 } 

Measured memory_bytes: 3636
#include<stdio.h>
int main()
{
    int m=0,n=0,d,sum;
    scanf("%d %d",&m,&n);
    d=m+n;
    if(d>23)
    {
        sum=d-24;
        printf("%d\n",sum);
    }

        else

        printf("%d\n",d);

    return 0;

}


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

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {

			var inputArray = retreiveLongArray();
			var inputCount = 2;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			var N = (int)inputArray[0];
			var K = (int)inputArray[1];
			var S = retreiveStringArray()[0];

			var renzoku = new List<int>();

	

			var previous = '1';//先頭に疑似的な逆立ちを加える
			var streak = 0;

			for (int i = 0; i < N; i++) {

				if (S[i]==previous) {
					streak++;
				}
				else {
					renzoku.Add(streak);
					streak = 1;
					previous = S[i];
				}

				if (i==N-1) {
					renzoku.Add(streak);
					if (S[i]=='0') {
						renzoku.Add(0);//最後の要素に疑似的な逆立ちを加える
					}
				}
			}

			//すべてさかだちにできる場合
			if ((renzoku.Count()-1)/2 <= K ) {
				Console.WriteLine(N);
				return;
			}

			//累積和を求める
			var ruisekiwas = new List<int>();

			for (int i = 0; i < renzoku.Count; i++) {
				if (i==0) {
					ruisekiwas.Add(renzoku[i]);
				}
				else {
					ruisekiwas.Add(ruisekiwas[i - 1] + renzoku[i]);
				}
			}

			var max = 0;
			var n = 0;
			while (n + K*2 <= ruisekiwas.Count) {

				var start = n == 0 ? 0 : ruisekiwas[n - 1];
				var end = ruisekiwas[n + K * 2];
				var wa = end - start;
				max = Math.Max(max, wa);
				n += 2;
			}


			//答えの出力
			var ans = max;
			Console.WriteLine(ans);

		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}
	}
}


Measured memory_bytes: 20728
#include <iostream>

int gcd(int x, int y)
{
    int t;

    while (y != 0) {
        t = x % y;  x = y;  y = t;
    }
    return x;
}


int main() {
    int N;
    char S[4001];
    int R = 0;
    int G = 0;
    int B = 0;
    int temp_R = 0,temp_G = 0,temp_B = 0;
    int temp2_R = 0,temp2_G = 0,temp2_B = 0;
    long long int SUM = 0;

    scanf("%d",&N);
    scanf("%s",&S);

    for(int i = 0;  i< N; ++i) {
        if(S[i]=='R'){
            R++;
        }
        else if(S[i]=='G'){
            G++;
        }
        else{
            B++;
        }
    }



    for(int i = 0; i <= N - 3; ++i){
        if(S[i]=='R'){
            temp_R++;
        }
        else if(S[i]=='G'){
            temp_G++;
        }
        else{
            temp_B++;
        }
        temp2_B=0;
        temp2_G=0;
        temp2_R=0;

        for(int j = i + 1; j <= N - 2;++j){

            if(S[j]=='R'){
                temp2_R++;
            }
            else if(S[j]=='G'){
                temp2_G++;
            }
            else{
                temp2_B++;
            }

            if(S[i] != S[j]){
                if(S[i] != 'R' && S[j] != 'R'){
                    if(j+j-i <= N-1 && S[j+j-i] =='R'){
                        SUM += R - temp_R - temp2_R - 1;
                    }
                    else{
                        SUM += R - temp_R - temp2_R;
                    }
                }
                else if(S[i] != 'G' && S[j] != 'G'){
                    if(j+j-i <= N-1 && S[j+j-i] =='G'){
                        SUM += G - temp_G - temp2_G - 1;
                    }
                    else{
                        SUM += G - temp_G - temp2_G;
                    }

                }
                else{
                    if(j+j-i <= N-1 && S[j+j-i] =='B'){
                        SUM += B - temp_B - temp2_B - 1;
                    }
                    else{
                        SUM += B - temp_B - temp2_B;
                    }
                }
            }
        }
    }
    printf("%lld",SUM);
    return 0;
}


int A(){
    int N;

    scanf("%d",&N);

    while(N){
        if(N % 10 == 7){
            printf("Yes");
            return 0;
        }

        N = N / 10;
    }
    printf("No");

    return 0;
}

int B(){
    long long int N;
    long long int SUM = 0;

    scanf("%lld",&N);
    for(long long int i = 1; i <= N; ++i){
        if(i % 3 == 0 || i % 5 == 0){
        }
        else{
            SUM += i;
        }
    }
    printf("%lld",SUM);
    return 0;
}

int C(){
    long long int K;
    long long int SUM = 0;
    scanf("%lld",&K);
    int s = 0;
    int t = 0;

    for(int i = 1; i <= K; ++i) {
        for (int j = 1; j <= K; ++j) {
            s = gcd(i,j);
            for (int k = 1; k <= K; ++k) {


                SUM +=gcd(s,k);;
            }
        }
    }

    printf("%lld",SUM);
    return 0;
}


Measured memory_bytes: 3844
// 20151003
// ?¨??§????????????\????????¶?????????
// ?????° 1: ??????????????????????????????????????§??\???????????¨ 201 ???????????????????????????????????????




#include<stdio.h>




int main() {
  char keta;
  int a, b;
  int wa;
  int i;
  int count = 0;




  /* ??????????????¨????´? */
  while (scanf("%d %d", &a, &b) != EOF) {
    /* ??\????????°??¨?????????????????¶?´??????? */
    if (count >= 200) {
      break;
    }
    if (a > 1000000 && b > 1000000) {
      break;
    }
    /**** ????????? ****/
    keta = 0;
    wa = a + b;
    count = count + 1;
    while (wa != 0) {
      wa = wa / 10;
      keta = keta + 1;
    }
    /***** ?????¨??? *****/
    printf("%d\n", keta);
  }




  /* ?????? */
  return 0;
}

Measured memory_bytes: 600
const int LG = 21;
const int FN = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <bits/stdc++.h>

using namespace std;

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

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(FN);
    __ufact.resize(FN);
    __rev.resize(FN);
    __rev[1] = 1;
    for (int i = 2; i < FN; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < FN; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (k < 0 || k > n) return 0;
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

const int N = 430000;
vector<int> graph[N];
int in[N];
int par[N];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n - 1 + m; i++)
    {
        int a, b;
        cin >> a >> b;
        graph[a].push_back(b);
        in[b]++;
    }
    vector<int> q = {};
    for (int i = 1; i <= n; i++)
    {
        if (in[i] == 0)
        {
            par[i] = 0;
            q.push_back(i);
        }
    }
    for (int i = 0; i < q.size(); i++)
    {
        int v = q[i];
        for (auto u : graph[v])
        {
            in[u]--;
            if (in[u] == 0)
            {
                q.push_back(u);
                par[u] = v;
            }
        }
    }
    for (int i = 1; i <= n; i++) cout << par[i] << "\n";
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/


Measured memory_bytes: 16632
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
    int N;
    int ans = 0;
    cin >> N;
    int d[100];
    for (int i = 0; i < N;i++){
        cin >> d[i];
    }
    sort(d, d + N);
    for (int i = 0; i < N;i++){
        if (d[i] != d[i+1] && i != N){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import heapq

N,C=map(int, input().split())

inl = [tuple(map(int, input().split())) for i in range(N)]
inl.sort()

heap = []
res = 0

st = set()
for s,t,c in inl:
    nx = set()
    for t1, c1 in st:
        if t1 == s and c == c1:
            # do nothing
            nx.add((t,c))
        elif t1 >= s:
            nx.add((t1,c1))
    nx.add((t,c))
    st = nx
    res = max(len(nx), res)

print(res)


Measured memory_bytes: 17888
#include<bits/stdc++.h>
using namespace std;
int main(){
    while(1){
        int n,f;
        cin >> n >> f;
        if(n==0&&f==0)return 0;
        int count=0;
        for(int i=1; i<=n; i++){
            for(int j=i+1; j<=n; j++){
                for(int k=j+1; k<=n; k++){
                    if(i+j+k==f) count++;     
                               }
            }
        }
        cout << count << endl;
    }
}


Measured memory_bytes: 3096
#include<iostream>
int main(){
	while(1){
		int a;
		std::cin>>a;
		if(a==0)break;
		int b=0,c=0,d=0;
		for(int i=1;i<13;i++){
			int n,m;
			std::cin>>n>>m;
			int h=n-m;
			b+=h;
			if(a<=b&&c==0)d=i,c=1;
		}
		if(c==0)std::cout<<"NA"<<std::endl;
		else std::cout<<d<<std::endl;
	}
	return 0;
}

Measured memory_bytes: 1160
//C
#include <cassert>
#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 <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

//C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#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 <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Others
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
const int dx[8] = { -1,0,1,-1,1,-1,0,1 };
const int dy[8] = { 1,1,1,0,0,-1,-1,-1 };


//LOVE NyantakoGG	https://www.youtube.com/channel/UC6XdFs8T6Ei54O0FYl3PVVA


using namespace std;



int main() {
	int N;
	cin >> N;
	for (int i = 0; i < 10000000; i++) {
		if ((1 << i) > N) {
			cout << (1 << (i - 1)) << endl;
			break;
		}
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=1000001;
int n,m,ans,ban[maxn],x,vis[maxn],E,T,lim[maxn];
struct heapy
{
    priority_queue<int>q1,q2;
    int sz;
    void add(int x){q1.push(-x);++sz;}
    void del(int x){q2.push(-x);--sz;}
    int top()
    {
        if(q1.empty())return 1e9;
        while(!q2.empty()&&q1.top()==q2.top())q1.pop(),q2.pop();
        return -q1.top();
    }
}l,r;
int f[maxn],a[maxn];
signed main()
{
    cin>>n>>E>>T;
    for(int i=1;i<=n;i++)cin>>a[i];
    n++;a[n]=E;
    for(int i=1,j=1;i<=n;i++)
    {
        while(a[j]-a[i]<=T/2&&j<=n)lim[j]=i,j++;
    }
  //  for(int i=1;i<=n;i++)cout<<lim[i]<<" ";cout<<endl;
    f[1]=a[1];r.add(f[1]-a[1]+T);
  //  cout<<1<<" "<<f[1]<<endl;
    for(int i=1,j=1;i<=n;i++)
    {
        while(j<lim[i]&&j<=n)
            r.del(f[j]-a[j]+T),l.add(f[j]-3*a[j]),j++;
      //  cout<<i<<" "<<l.top()<<" "<<r.top()<<endl;
        f[i+1]=min(l.top()+3*a[i],r.top()+a[i])+a[i+1]-a[i];
      //  cout<<f[i+1]-a[i+1]+a[i]<<" "<<f[i+1]<<endl;
        r.add(f[i+1]-a[i+1]+T);
    }
    cout<<f[n];
}
/*
8 20 6
1 2 3 5 7 9 11 18
简单地贪了一发之后感觉没有指望，又简单地dp了一发之后发现不对劲，所以在外面套一个二分。
一次dfs一定是走进一个子树，回来，走进另一个子树，再回来。
fij表示i子树内，起点到i距离不超过j的最近终点距离，每次匹配一次，这转移就并不困难了。

*/

Measured memory_bytes: 6780
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size,n=1,init=nil) #nに配列の次元数、sizeに配列の大きさ、initに初期値を投げることでその配列を返す
  if n==1
    return Array.new(size){init}
  else
    return Array.new(n).map{Array.new(size){init}}
  end
end

def inverse(x)
  p=1
  b=x
  mod=10**9+7
  (mod-2).to_s(2).reverse.split("").each do|i|
    p=(p*b)%mod if i=="1"
    b=(b*b)%mod
  end
  return p
end
def p(a,b)
  mod=10**9+7
  return (a..b).inject(1){|x,y| (x*y)%mod}
end
def C(n,r)
  mod=10**9+7
  return (p(r+1,n)*inverse(p(1,n-r)%mod))%mod
end

x,y=get_i
if ((x+y)%3).zero?
  n=((1.0/3.0).to_f*(2*y-x)).to_i
  m=((1.0/3.0).to_f*(2*x-y)).to_i
  if n<0 or m<0
    puts 0
  else
    puts C(n+m,n)% (10**9+7)
  end
else
  puts 0
end

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

#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) begin(x), end(x)
#define uniq(x) (x).erase(unique(all(x)), end(x))
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr long double PI = 3.1415926535897932384626433832795028L;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N;
int X[110];
signed main() {
    cin >> N;
    rep(i, N) { cin >> X[i]; }
    int ans = LLONG_MAX;
    rep(i, 101) {
        int cur = 0;
        rep(j, N) { cur += (X[j] - i) * (X[j] - i); }
        chmin(ans, cur);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import numpy as np

N = int(input())
A = tuple(map(int, input().split()))

dp = np.zeros((N + 1, N + 1), dtype=np.int64)
for m in range(1, N + 1):
    if (N - m) % 2:
        dp[m][:N - m + 1] = np.minimum(dp[m - 1][1:N - m + 2] - A[:N - m + 1],
                                       dp[m - 1][:N - m + 1] - A[m - 1:])
    else:
        dp[m][:N - m + 1] = np.maximum(dp[m - 1][1:N - m + 2] + A[:N - m + 1],
                                       dp[m - 1][:N - m + 1] + A[m - 1:])

print(dp[N][0])


Measured memory_bytes: 84304
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define RFOR(i,a,b) for(int i=(b-1); i>=(a); i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
using ll = long long;
using D = double;
using LD = long double;
using P = pair<int, int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
    int n; cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    sort(ALL(a));
    ll p = 1;
    rep(i,n){
        if(a[i] == 0){
            cout << 0 << endl;
            return 0;
        }
        else{
            if(a[i] > 1000000000000000000 / p){
                cout << "-1" << endl;
                return 0;
            }

            else{
                p *= a[i];
            }
        }
    }
    cout << p << endl;
}


Measured memory_bytes: 4052
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=998244353;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
pair<llint,llint>enz(pair<llint,llint>ans,pair<llint,llint>bgen){
	pair<llint,llint>ata;
	ata.fir=ans.fir*bgen.sec+(ans.sec-ans.fir)*bgen.fir;
	ata.sec=ans.fir*bgen.fir+ans.sec*bgen.sec;
	ata.fir%=mod;ata.sec%=mod;
	return ata;
}
llint fib(llint in){
	pair<llint,llint>ans=mp(0,1);//0,1
	//0,1項目
	pair<llint,llint>bgen=mp(1,1);//1,2項
	for(int h=0;h<60;h++){
		if((1LL<<h)&in){ans=enz(ans,bgen);}//ans<-bgen
		bgen=enz(bgen,bgen);
	}
	//cerr<<"fib in="<<in<<"num="<<ans.fir<<endl;
	return ans.fir;
}
int countt=0;
llint gya(llint in){
	if(in%mod==0){countt++;return 1;}
	in%=mod;
	llint ans=1,bgen=in;
	for(int h=0;h<30;h++){
		if((mod-2)&(1LL<<h)){ans*=bgen;ans%=mod;}
		bgen*=bgen;bgen%=mod;
	}
	return ans;
}
int main(void){
	llint n,m;cin>>n>>m;n--;
	llint ans=fib(n+n+m);
	llint gen=1;
	for(llint i=0;i<n;i++){
		if(countt==0){ans-=gen;}
		//cerr<<gen<<endl;
		gen*=gya(i+1);gen%=mod;
		gen*=gya(n+n+m-i-1);gen%=mod;
		if((n+n+m-i-i-2)%mod>0){gen*=(n+n+m-i-i-2)%mod;gen%=mod;}else{countt--;}
		if((n+n+m-i-i-1)%mod>0){gen*=(n+n+m-i-i-1)%mod;gen%=mod;}else{countt--;}
		
	}
	ans%=mod;ans+=mod;ans%=mod;
	cout<<ans<<endl;
	return 0;
}



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

using namespace std;
using ll = long long int;

void chmax(ll &A, ll B) { A = max(A, B); }

struct Edge {
    Edge() {}
    Edge(int to_, int tm_, int lim_, int cost_) : to(to_), tm(tm_), lim(lim_), cost(cost_) {}
    int to, tm, lim, cost;
};
using Graph = vector< vector<Edge> >;

ll N, T, dp[650][10010];
int euler[650], dir[650];
Edge euler_edge[650];
int idx = 0;

void dfs(Graph &G, int cur, int par=-1) {
    euler[idx++] = cur;
    for(auto e : G[cur]) {
        int to = e.to;
        if(to == par) continue;
        euler_edge[idx] = e;
        dir[idx] = 0;
        dfs(G, to, cur);
        euler_edge[idx] = e;
        dir[idx] = 1;
        euler[idx++] = cur;
    }
}

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

    Graph G(N);
    for(int i=0; i<N-1; i++) {
        int a, b, t, m, v; cin >> a >> b >> t >> m >> v;
        a--; b--;
        G[a].push_back(Edge{b, t, m, v});
        G[b].push_back(Edge{a, t, m, v});
    }
    dfs(G, 0);

    /*
    for(int i=0; i<idx; i++) {
        printf("%d (%d), ", euler[i], euler_edge[i].cost);
    }
    cout << endl;
    */

    vector<int> pre(N, -1);
    fill(dp[0], dp[650], -(1LL << 60));
    // for(int i=0; i<idx; i++) dp[i][0] = 0;
    dp[0][0] = pre[0] = 0;
    for(int i=1; i<idx; i++) {
        int prev_idx = pre[ euler[i] ];

        int tm = euler_edge[i].tm;
        int lim = euler_edge[i].lim;
        int cost = euler_edge[i].cost;

        for(int t=0; t<=T; t++) {
            if(prev_idx >= 0) chmax(dp[i][t], dp[prev_idx][t]);
        }

        if(dir[i] == 1) {
            // 帰り
            for(int t=0; t<=T; t++) {
                chmax(dp[i][t], dp[i-1][t]);
            }
        }
        else {
            // 行き
            if(lim % 2 == 1) {
                ll take_tm = (lim + 1) * tm, take_cost = lim * cost;
                for(int t=take_tm; t<=T; t++) {
                    chmax(dp[i][t], dp[i-1][t - take_tm] + take_cost);
                }
                lim--;
            }

            if(lim == 0) {
                ll take_tm = 2 * tm;
                for(int t=take_tm; t<=T; t++) {
                    chmax(dp[i][t], dp[i-1][t - take_tm]);
                }
            }
            else {
                lim -= 2;
                for(int m=2; lim>0; m*=2) {
                    ll x = min(lim, m); lim -= x;
                    ll take_tm = x * tm, take_cost = x * cost;
                    for(int t=T; t>=take_tm; t--) {
                        chmax(dp[i-1][t], dp[i-1][t - take_tm] + take_cost);
                    }
                }

                ll take_tm = 2 * tm, take_cost = 2 * cost;
                for(int t=take_tm; t<=T; t++) {
                    chmax(dp[i][t], dp[i-1][t - take_tm] + take_cost);
                }
            }
        }

        /*
        for(int t=0; t<=T; t++) {
            if(dp[i][t] < 0) cout << "-INF" << " ";
            else cout << dp[i][t] << " ";
        }
        cout << endl;
        */
        
        pre[ euler[i] ] = i;
    }
    cout << *max_element(dp[idx-1], dp[idx-1] + T + 1) << endl;
    return 0;
}


Measured memory_bytes: 53996
package main

import (
	"fmt"
)

func main() {
	var n int
	var s string
	fmt.Scan(&n, &s)

	dp := [5010][5010]int{}
	for i := n - 1; i >= 0; i-- {
		for j := n - 1; j >= 0; j-- {
			if s[i] == s[j] {
				dp[i][j] = dp[i+1][j+1] + 1
			}
		}
	}

	ans := 0
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			c := dp[i][j]
			if i >= j || j <= i+c-1 {
				continue
			}
			ans = max(ans, c)
		}
	}

	fmt.Println(ans)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}


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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> vec;
  for (int i = 1; i <= N; i++) {
    int z;
    cin >> z;
    z--;
    vec.push_back(z);
  }

  int now = 0, c = 0;

  for (;;) {
    if (now == 1) {
      cout << c << endl;
      return 0;
    }
    if (c >= N) {
      cout << -1 << endl;
      return 0;
    }
    c++;
    now = vec[now];
  }
}

Measured memory_bytes: 892